8#include <pybind11/embed.h>
9#include <pybind11/numpy.h>
10#include <unordered_map>
14namespace py = pybind11;
16namespace VoxelGridHelpers {
17 template <
typename T, std::
size_t N>
18 Eigen::Vector<T, N> pyTupleToEigenVector(
const py::tuple &tuple);
19 double covertUnitNameToCm(
const std::string& unitName);
20 int dimensionStringToIndex(
const std::string& dimension);
38 explicit VoxelGrid(std::string filename,
bool is_python_environment =
false);
121 Eigen::Vector3i dim_vox_;
122 Eigen::Vector3d spacing_;
123 Eigen::Vector3d dim_space_;
124 int numOfVoxels_ = 0;
126 std::vector<Voxel> voxels_;
127 std::string filename_;
129 bool is_python_environment_;
132 void initializeVoxels();
135 int voxelNumber(
const Eigen::Vector3i& voxel_index)
const;
137 void handleOutOfBounds(
const Eigen::Vector3d& position)
const;
139 void setVoxelProperties(
const py::array_t<uint8_t>& array,
const py::object &header);
141 static py::array_t<uint8_t> getNumPyArrayFromImg(
const py::object& img);
142 void setDimVox(
const py::array_t<uint8_t>& array);
143 void setUnits(
const py::object& header);
144 void setSpacing(
const py::object& header);
145 void setNumOfVoxels();
147 void setVoxelMaterialIDs(
const py::array_t<uint8_t>& array);
Class which represents a voxel grid.
Eigen::Vector3d getDimSpace() const
Gets the spatial dimensions of the voxel grid.
bool withinGrid(const Eigen::Vector3d &position) const
Checks if a spatial position is within the voxel grid.
void addExit()
Adds to the number of photons that have exited the voxel grid.
VoxelGrid(std::string filename, bool is_python_environment=false)
Constructor for the VoxelGrid class.
Eigen::Vector3d getVoxelPosition(const Eigen::Vector3i &voxel_index)
Gets the spatial position of the voxel at (i, j, k).
std::unordered_map< int, VectorValue > getEnergyDepositedInMaterials()
Gets the total energy deposited in the voxel grid by material.
double getTotalEnergyDeposited()
Gets the total energy deposited in the voxel grid.
std::vector< std::string > getMaterialNames() const
Gets vector of material names in voxel grid.
void setVoxel(const Eigen::Vector3i &voxel_index, Voxel &value)
Sets the voxel at (i, j, k) to specified voxel.
int getNumExits() const
Gets the number of photons that have exited the voxel grid.
Eigen::Vector3i getVoxelIndex(const Eigen::Vector3d &position) const
Gets the voxel index of a spatial position.
Voxel & getVoxel(const Eigen::Vector3i &voxel_index)
Gets the voxel at (i, j, k).
Struct which represents a voxel.