Geometry — 3D
Typedefs
-
typedef CGAL::Exact_predicates_exact_constructions_kernel EX_K
-
typedef CGAL::Simple_cartesian<double> SC_Kernel
-
typedef openvdb::FloatGrid SDF_Grid
-
struct Indexed_Triangle
- #include <primitives.h>
Triangle representation capturing integer-based references mapping shared indices into a global vertex pool.
-
class SurfaceMesh
- #include <SurfaceMesh.h>
A class for storing and manipulating triangle meshes.
Public Types
-
typedef CGAL::AABB_traits_3<SC_Kernel, AABBPrimitive> MeshAABBTraits
-
typedef CGAL::AABB_tree<MeshAABBTraits> MeshAABBTree
Public Functions
-
std::pair<glm::vec3, glm::vec3> bounding_box() const
Returns the bounding box of the mesh.
- Returns:
The bounding box of the mesh
-
void center()
Centers the mesh around the origin.
-
SDF_Grid::Ptr compute_sdf(glm::vec3 voxel_size, float exterior_band_width = 3.0f, float interior_band_width = 3.0f) const
Returns the center of the mesh.
- Parameters:
voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
exterior_band_width – The width of the exterior band of the SDF
interior_band_width – The width of the interior band of the SDF
- Returns:
The center of the mesh
Merges another mesh into this mesh.
This performs a simple concatenation of vertices and triangles. It may result in non-manifold geometry or duplicate vertices
- Parameters:
mesh_to_merge – The mesh to merge into this mesh
-
double signed_distance(double x, double y, double z) const
Calculates the signed distance from a point to the surface of the mesh.
- Parameters:
x – Search point X.
y – Search point Y.
z – Search point Z.
- Returns:
The Euclidean distance with continuous sign evaluating internal / external classification.
-
SurfaceMesh()
Default constructor.
-
SurfaceMesh(std::string file_path, bool disable_validation = false)
Constructor that loads a mesh from a file.
- Parameters:
file_path – The path to the file to load
disable_validation – If true, bypass CGAL mesh error checking on input.
-
SurfaceMesh(std::vector<glm::vec3> vertices, std::vector<Indexed_Triangle> triangles, bool disable_validation = false)
Constructor that creates a mesh from vertices and triangles.
- Parameters:
vertices – The vertices of the mesh
triangles – The triangles of the mesh
disable_validation – If true, bypass CGAL mesh error checking on input.
-
SurfaceMesh(vtkSmartPointer<vtkPolyData> poly_data, bool disable_validation = false)
Constructor that creates a mesh from a VTK polydata representation.
- Parameters:
poly_data – The un-structured vtkPolyData geometry element.
disable_validation – If true, bypass CGAL mesh error checking on input.
-
void translate(glm::vec3 translation)
Translates the mesh by a given translation vector.
- Parameters:
translation – The translation vector to apply to the mesh (mm)
-
std::vector<Indexed_Triangle> triangles() const
Returns the triangles of the mesh.
- Returns:
The triangles of the mesh
-
std::vector<glm::vec3> vertices() const
Returns the vertices of the mesh.
- Returns:
The vertices of the mesh
-
void write_3mf(const std::string &output_file_name)
Writes the mesh to a 3MF file.
- Parameters:
output_file_name – The name of the file to write to
-
void write_stl(const std::string &output_file_name)
Writes the mesh to a binary STL file.
- Parameters:
output_file_name – The name of the file to write to
Private Functions
-
void check_mesh_for_errors() const
Validates mesh integrity utilizing CGAL validation checking closedness and self intersections.
-
void prepare_fast_queries()
Sets up the internal AABB Tree used for signed distance calculations.
Private Members
-
std::shared_ptr<Point_inside> m_inside_tester
Evaluation object mapping inside-outside queries.
-
glm::vec3 m_max
The maximum coordinate of the mesh.
-
glm::vec3 m_min
The minimum coordinate of the mesh.
-
std::shared_ptr<MeshAABBTree> m_tree
Reusable cache containing the bounding box hierarchy mapping traits.
-
std::vector<Indexed_Triangle> m_triangles
The triangles of the mesh.
-
std::vector<glm::vec3> m_vertices
The vertices of the mesh.
Private Static Functions
-
static std::tuple<std::vector<glm::vec3>, std::vector<Indexed_Triangle>, glm::vec3, glm::vec3> LoadMeshFromFile(std::string file_path)
Loads a mesh from a file.
- Parameters:
file_path – The path to the file to load
- Returns:
A tuple containing the vertices, triangles, minimum coordinate, and maximum coordinate of the mesh
-
static std::shared_ptr<CGALMesh> ToCGALMesh(std::vector<glm::vec3> vertices, std::vector<Indexed_Triangle> triangles)
Builds a CGAL-native surface map utilizing loaded vertex/indices arrays.
- Parameters:
vertices – The array of positions.
triangles – The indexed triangular polygons.
- Returns:
A shared memory mapped instance of the CGAL elements.
-
struct TriangleMeshDataAdapter
An adapter for OpenVDB to use with mesh triangle/ vertex data.
Public Functions
-
inline void addTriangle(openvdb::Vec3I triangle)
Add a triangle from the mesh to the adapter.
Note
triangles are stored as a Vec3I, where each element is the index of a vertex in the vertex array
- Parameters:
triangle – The triangle to add
-
inline void addVertex(openvdb::Vec3f vertex)
Add a vertex from the mesh to the adapter.
- Parameters:
vertex – The vertex to add
-
inline void getIndexSpacePoint(size_t n, size_t v, openvdb::Vec3d &pos) const
Return position pos in local grid index space for polygon n and vertex v.
- Parameters:
n – The polygon index
v – The vertex index
pos – The position of the vertex in local grid index space
-
inline size_t pointCount() const
Total number of points (vertices in this case).
- Returns:
The number of points
-
inline size_t polygonCount() const
Total number of polygons (triangles in this case).
- Returns:
The number of polygons
-
inline TriangleMeshDataAdapter(glm::vec3 voxel_size, long long vertex_count, long long triangle_count)
Constructor.
- Parameters:
voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
vertex_count – The number of vertices in the mesh- used to preallocate memory
triangle_count – The number of triangles in the mesh- used to preallocate memory
-
inline size_t vertexCount(size_t n) const
Vertex count for polygon n (always 3 in this case because of triangles).
- Parameters:
n – The polygon index
Private Members
-
double m_inv_min_voxel_size
The inverse of the minimum voxel size.
-
std::vector<openvdb::Vec3I> m_triangles
The triangles of the mesh.
-
std::vector<openvdb::Vec3f> m_vertices
The vertices of the mesh.
-
glm::vec3 m_voxel_size
The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
-
int tri_index = 0
The index of the next triangle to add.
-
int vert_index = 0
The index of the next vertex to add.
-
inline void addTriangle(openvdb::Vec3I triangle)
-
typedef CGAL::AABB_traits_3<SC_Kernel, AABBPrimitive> MeshAABBTraits
-
class CADPart
- #include <cad_part.h>
A CAD geometry primitive.
The CAD is loaded from a file into memory and provides a signed distance adapter to the surface.
Note
This class supports STEP and IGES file formats.
Public Functions
-
std::pair<glm::vec3, glm::vec3> bounding_box()
Finds boundaries encompassing the TopoDs representations of the current CAD state.
- Returns:
Defined coordinate constraints mapping [min, max].
-
CADPart() = default
-
CADPart(TopoDS_Shape part)
Initializes a CADPart shape utilizing an OpenCascade TopoDS_Shape.
- Parameters:
part – Evaluated Brep mapping to the part.
-
std::shared_ptr<CADPart> clone()
Generates a discrete copy of the CAD evaluation elements and the geometric surface state.
- Returns:
A cloned CADPart pointer mapping.
-
void export_as_stl(const std::string &path, double deflection = 0.1)
Exports the internal CAD shape bounding representations to an STL mesh wrapper.
- Parameters:
path – Destination output file matching .stl.
deflection – Geometric threshold limit targeting precision bounding deviations.
-
void set_fast_mode(bool fast_mode, glm::vec3 voxel_size, double interior_bandwidth, double exterior_bandwidth, double deflection = 0.1)
Converts explicit solid classification evaluations to an accelerated 3D grid based SDF volume mapping.
- Parameters:
fast_mode – Boolean to enable fast grid evaluation mapping.
voxel_size – The local unit block size when generating internal meshes.
interior_bandwidth – Offset internal bound mapping to compute.
exterior_bandwidth – Offset external bound region expansion to compute.
deflection – Triangle tolerance parameter targeting generation of mesh bounds.
-
double signed_distance_to_surface(double x, double y, double z)
Returns the signed distance to the surface of the CAD geometry.
- Parameters:
x – The x coordinate
y – The y coordinate
z – The z coordinate
-
std::shared_ptr<SurfaceMesh> to_surface_mesh(double deflection = 0.1)
Compiles the internal BRep shape parameters to a primitive meshed output state.
- Parameters:
deflection – Geometry constraints mapping generation scaling.
- Returns:
Converted geometry component class type format to SurfaceMesh.
Private Types
-
typedef openvdb::FloatGrid GridType
The type of grid used by OpenVDB.
Private Functions
-
void compute_bbox()
Generates local Bnd_box parameters from the base CAD shape definition array bounds.
-
void prepare_classification()
Prepares standard inside classification elements for the underlying part structure limits.
-
void prepare_fast_classification(glm::vec3 voxel_size, double interior_bandwidth, double exterior_bandwidth, double deflection = 0.1)
Formats accelerated grid memory block samplers caching classification bounds using an implicit volume conversion.
Private Members
-
BRepClass3d_SolidClassifier m_classifier
The explicit solid shape volume mapper.
-
bool m_fast_mode = false
Toggles state flags enabling rapid sampling parameters utilizing discrete blocks over true geometry projection evaluation matrices.
-
glm::vec3 m_max
Evaluation limit mapping the upper coordinate bounds marking shape scope regions.
-
glm::vec3 m_min
Evaluation limit mapping the lower coordinate block geometry limits.
-
TopoDS_Shape m_part
Base representation shape generated from initial files.
-
openvdb::tools::GridSampler<GridType, openvdb::tools::BoxSampler>::Ptr m_sampler
Sampling structure mapped linearly over grid data mapping boolean interpolation boundaries.
-
TopoDS_Shape m_shell
Unused shell container wrapping representation evaluation definitions.
-
std::pair<glm::vec3, glm::vec3> bounding_box()
Typedefs
-
template<typename T>
using AABB_tetrahedron_traits = CGAL::AABB_traits_3<SC_Kernel, TetrahedronPrimitive<T>> Define the AABB traits for the TetrahedronPrimitive.
-
template<typename T>
using AABBTree = CGAL::AABB_tree<AABB_tetrahedron_traits<T>> Define the AABB tree for the TetrahedronPrimitive.
-
template<typename T>
class Tetrahedron - #include <tetrahedron.h>
A class that represents a tetrahedron in 3D space.
This class is used to represent a tetrahedron in 3D space. The tetrahedron is defined by four points in 3D space. The class also stores a value (template) associated with each point in the tetrahedron. Methods are provided to interpolate given a point in space within the tetrahedron.
Public Functions
-
inline glm::vec3 a() const
Get the first point of the tetrahedron.
-
inline glm::vec3 b() const
Get the second point of the tetrahedron.
-
inline glm::vec3 barycenter() const
Compute the barycenter of the tetrahedron.
- Returns:
The barycenter or center of mass of the tetrahedron
-
inline glm::vec4 barycentric_coordinates(const glm::vec3 &point) const
Compute the barycentric coordinates of a point in space within the tetrahedron.
- Parameters:
point – The point in space to compute the barycentric coordinates for
- Returns:
The barycentric coordinates of the point
-
inline std::pair<glm::vec3, glm::vec3> bounding_box() const
Compute the bounding box of the tetrahedron.
- Returns:
A pair of the minimum and maximum points of the bounding box
-
inline glm::vec3 c() const
Get the third point of the tetrahedron.
-
inline glm::vec3 d() const
Get the fourth point of the tetrahedron.
-
inline bool is_point_inside(const glm::vec3 &point) const
Check if a point is inside the tetrahedron.
Note
depends on barycentric_coordinates()
- Parameters:
point – The point to check
- Returns:
True if the point is inside the tetrahedron, false otherwise
-
inline glm::vec3 max_point() const
Compute the maximum point of the tetrahedron.
- Returns:
The maximum point of the tetrahedron
-
inline glm::vec3 min_point() const
Compute the minimum point of the tetrahedron.
- Returns:
The minimum point of the tetrahedron
-
inline T sample(const glm::vec3 &point) const
Interpolate a value at a point in space within the tetrahedron.
- Parameters:
point – The point in space to interpolate the value at
- Returns:
The interpolated value at the point
-
inline void set_a(const glm::vec3 &a)
Set the first point of the tetrahedron.
-
inline void set_b(const glm::vec3 &b)
Set the second point of the tetrahedron.
-
inline void set_c(const glm::vec3 &c)
Set the third point of the tetrahedron.
-
inline void set_d(const glm::vec3 &d)
Set the fourth point of the tetrahedron.
-
Tetrahedron() = default
Constructor.
-
inline Tetrahedron(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, const glm::vec3 &d, const T &a_val, const T &b_val, const T &c_val, const T &d_val)
Constructor.
- Parameters:
a – The first point of the tetrahedron
b – The second point of the tetrahedron
c – The third point of the tetrahedron
d – The fourth point of the tetrahedron
a_val – The value associated with the first point
b_val – The value associated with the second point
c_val – The value associated with the third point
d_val – The value associated with the fourth point
-
inline double volume() const
Compute the volume of the tetrahedron.
- Returns:
The volume of the tetrahedron in mm^3
-
inline glm::vec3 a() const
-
template<typename T>
class TetrahedronPrimitive - #include <tetrahedron.h>
A geometric primitive formatting generalized 3D block layouts extracting values into CGAL traits representations.
Public Types
-
typedef const Tetrahedron<T> *Id
Public Functions
-
inline Datum datum() const
Computes CGAL aligned block matching external spatial bounds containing inner mesh features.
- Returns:
Extracted block constraint metrics wrapping nodes.
-
inline Id id() const
Fetch mapping linking evaluation targets back to origin objects.
- Returns:
Sourced instance reference pointing underlying representations.
-
inline Point reference_point() const
Fetches the geometric core mass center evaluating origins.
- Returns:
Localized vertex structure evaluation parameters.
-
inline TetrahedronPrimitive(Tetrahedron<T> *tet)
Initializer assigning core tetra evaluations handling values attached.
- Parameters:
tet – Wrapped object mapping primitive bounds.
Public Members
-
Tetrahedron<T> *m_ptr
-
typedef const Tetrahedron<T> *Id
-
class HexahedralMesh
- #include <hexahedral_mesh.h>
Generates a 3D structural mesh block mapped using structured hexahedrons (voxels) over evaluated shape distributions.
Public Functions
-
std::pair<glm::vec3, glm::vec3> bounding_box()
Finds boundaries encompassing the generated shape constraints.
- Returns:
Defined coordinate constraints mapping [min, max].
-
void compute()
Calculate elements traversing internal density structures converting to distinct Hexahedrons.
-
inline std::vector<std::tuple<size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t>> elements() const
Fetch ordered topological element connectivities indexing building hex volumes.
- Returns:
Tuple list defining indexed corner points mapping volume cubes.
Initializes mesh generation targeted referencing a geometry definition.
- Parameters:
node – Base target node topology mapping distributions.
x_vox – Resolution blocks along the X axis.
y_vox – Resolution blocks along the Y axis.
z_vox – Resolution blocks along the Z axis.
-
inline std::unordered_map<uint8_t, std::vector<size_t>> material_assignments() const
Fetch assigned materials indexing groups matching elements over distributed sets.
- Returns:
Map referencing internal indexing to generated hex blocks.
-
inline std::vector<glm::vec3> nodes() const
Fetch calculated mesh elements points globally structured.
- Returns:
Vector mapped vertex components.
Private Functions
-
std::string getHashKey(double x, double y, double z)
-
size_t insert_node(double x, double y, double z)
Private Members
-
std::vector<std::tuple<size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t>> m_elements
-
std::unordered_map<uint8_t, std::vector<size_t>> m_material_assignments
-
std::unordered_map<std::string, size_t> m_node_map
-
std::vector<glm::vec3> m_nodes
-
size_t m_x_voxels
-
size_t m_y_voxels
-
size_t m_z_voxels
-
struct IndexedPoint
-
std::pair<glm::vec3, glm::vec3> bounding_box()
Lookup tables mapping edge and triangle topologies required for traditional Marching Cubes isosurface extraction implementations.
-
class DICOMVolume
- #include <dicom_volume.h>
A grid-based volume generated from a directory of medical DICOM slice images representing spatial density (Hounsfield units).
Public Functions
-
std::pair<glm::vec3, glm::vec3> bounding_box() const
Returns the bounds encompassing the internal OpenVDB storage limits.
- Returns:
Defined coordinate constraints mapping [min, max].
-
std::shared_ptr<DICOMVolume> clone()
Generates a discrete copy of the DICOM volume evaluation elements.
- Returns:
A cloned DICOMVolume mapping pointer.
-
DICOMVolume() = default
Default constructor.
-
DICOMVolume(const std::string &directory, double rescale_slope = -std::numeric_limits<double>::infinity(), double rescale_intercept = -std::numeric_limits<double>::infinity(), double slice_thickness = -std::numeric_limits<double>::infinity(), double x_pixel_spacing = -std::numeric_limits<double>::infinity(), double y_pixel_spacing = -std::numeric_limits<double>::infinity())
Construct a DICOM volume from the given directory.
- Parameters:
directory – The directory containing the DICOM stack.
-
double sample(double x, double y, double z) const
Sample the volume at the given world coordinates.
Note
The coordinates are in world space, not voxel space. This will use interpolation to sample the volume.
- Parameters:
x – The x-coordinate in mm.
y – The y-coordinate in mm.
z – The z-coordinate in mm.
- Returns:
The Hounsfield value at the given coordinates.
-
void set(double hounsfield_value, size_t x, size_t y, size_t z)
Set the Hounsfield value at the given voxel coordinates.
Note
This will set the value directly in the volume grid. This are in grid indices, not world space.
- Parameters:
hounsfield_value – The Hounsfield value to set.
x – The x-coordinate in voxel space.
y – The y-coordinate in voxel space.
z – The z-coordinate in voxel space.
Private Types
-
using GridType = openvdb::DoubleGrid
Private Functions
-
std::vector<std::vector<double>> load_dicom_image(const std::string &file_path)
Load a single DICOM image from the given file path and return the pixel data as a 2D vector.
-
void load_dicom_stack(const std::string &directory)
Load a DICOM stack from the given directory into an OpenVDB volume.
- Parameters:
directory – The directory containing the DICOM stack.
Private Members
-
double m_rescale_intercept = -std::numeric_limits<double>::infinity()
-
double m_rescale_slope = -std::numeric_limits<double>::infinity()
-
double m_x_size = 0
-
double m_x_spacing = -std::numeric_limits<double>::infinity()
-
double m_y_size = 0
-
double m_y_spacing = -std::numeric_limits<double>::infinity()
-
double m_z_size = 0
-
double m_z_spacing = -std::numeric_limits<double>::infinity()
Private Static Functions
-
static DICOM_Meta_Data GetDICOMMetaData(const std::string &file_path)
Get the metadata for a DICOM image from the given file path.
-
static double GetRescaledValue(Uint16 pixel_value, double rescale_slope, double rescale_intercept)
-
struct DICOM_Meta_Data
Public Members
-
bool found_rescale_intercept = false
-
bool found_rescale_slope = false
-
bool found_thickness = false
-
bool found_width_and_height = false
-
bool found_xy_spacing = false
-
size_t height = 0
-
double rescale_intercept = 0.0
-
double rescale_slope = 1.0
-
double slice_thickness = 1
-
size_t width = 0
-
double x_pixel_spacing = -1
-
double y_pixel_spacing = -1
-
bool found_rescale_intercept = false
-
std::pair<glm::vec3, glm::vec3> bounding_box() const
Typedefs
-
using AABB_node_traits = CGAL::AABB_traits<SC_Kernel, NodeBBoxPrimitive>
Define the AABB traits for the NodeBBoxPrimitive.
-
using NodeAABBTree = CGAL::AABB_tree<AABB_node_traits>
Define the AABB tree for the NodeBBoxPrimitive.
-
struct NodeBBoxPrimitive
- #include <node_bbox_primitive.h>
A geometric primitive wrapper converting internal OpenVCAD Node bounds to CGAL AABB tree compatible formats.
Public Types
Public Functions
-
inline Datum datum() const
Generates local coordinate constraints matching the Node topology block.
- Returns:
Formatted CGAL bounding box matching extraction sizes.
-
inline Id id() const
Fetch the associated source node instance.
- Returns:
Pointer reference mapping the original source Node.
Initializes a generic primitive shell extracting evaluation constraints from a base Node.
- Parameters:
node – Target geometry entity to bound.
-
inline Datum datum() const
Typedefs
-
using AABB_vcad_node_traits = CGAL::AABB_traits_3<SC_Kernel, VCADNodeBBoxPrimitive>
-
using AABBVCADTree = CGAL::AABB_tree<AABB_vcad_node_traits>
-
struct VCADNodeBBoxPrimitive
- #include <vcad_node_bbox_primitive.h>
A geometric primitive wrapper converting internal OpenVCAD Node bounds with an expanded padding bandwidth to CGAL AABB tree compatible formats.
Public Functions
-
inline Datum datum() const
Generates local coordinate constraints matching the Node topology block expanded by the bandwidth.
- Returns:
Formatted CGAL bounding box matching extraction sizes.
-
inline Id id() const
Fetch the associated source node instance.
- Returns:
Pointer reference mapping the original source Node.
-
inline Point reference_point() const
Computes the centered evaluation point representing the primitive origin offset.
- Returns:
Point matching geometric centroid layout.
Initializes a generic primitive shell extracting evaluation constraints from a base Node with an expanded bandwidth.
- Parameters:
node – Target geometry entity to bound.
bandwidth – Padding threshold adjusting external bound scales.
-
inline Datum datum() const