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 <surface_mesh.h>
A triangle mesh stored in OpenVCAD’s canonical vertex/index representation.
SurfaceMesh stores vertices, indexed triangles, and a bounding box. It can be constructed from explicit mesh data, files, VTK data, implicit trees, and SDF data. Sampling/query accelerators are intentionally handled outside this class.
Public Functions
-
std::pair<glm::vec3, glm::vec3> bounding_box() const#
Returns the bounding box of the mesh.
- Returns:
The minimum and maximum mesh coordinates.
-
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#
Converts the mesh into an OpenVDB signed-distance field.
- Parameters:
voxel_size – The target voxel size.
exterior_band_width – Exterior narrow-band width in world units.
interior_band_width – Interior narrow-band width in world units.
- Returns:
The generated OpenVDB float grid.
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.
-
SurfaceMesh()#
Default constructor creating an empty mesh.
-
SurfaceMesh(const openvdb::FloatGrid::Ptr &sdf_grid, bool disable_validation = false)#
Constructor that extracts a zero-isosurface from an OpenVDB float grid.
- Parameters:
sdf_grid – The signed-distance OpenVDB grid.
disable_validation – If true, bypass CGAL validation on input.
Constructor that extracts a zero-isosurface from a float VDB volume.
- Parameters:
sdf_volume – The signed-distance volume wrapper.
disable_validation – If true, bypass CGAL validation on input.
Constructor that samples an OpenVCAD tree and extracts its zero-isosurface.
- Parameters:
root – The tree root to sample.
voxel_size – Uniform voxel size used for the temporary SDF.
disable_validation – If true, bypass CGAL validation on input.
-
SurfaceMesh(const std::string &file_path, bool disable_validation = false)#
Constructor that loads a mesh from a file.
- Parameters:
file_path – The path to the mesh file to load.
disable_validation – If true, bypass CGAL validation 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 indexed triangular faces of the mesh.
disable_validation – If true, bypass CGAL validation on input.
-
SurfaceMesh(vtkSmartPointer<vtkImageData> sdf_image, bool disable_validation = false)#
Constructor that extracts a zero-isosurface from signed-distance image data.
- Parameters:
sdf_image – The vtkImageData containing signed-distance samples.
disable_validation – If true, bypass CGAL validation on input.
-
SurfaceMesh(vtkSmartPointer<vtkPolyData> poly_data, bool disable_validation = false)#
Constructor that creates a mesh from VTK polydata.
- Parameters:
poly_data – The vtkPolyData geometry element.
disable_validation – If true, bypass CGAL validation 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 file to write.
-
void write_stl(const std::string &output_file_name)#
Writes the mesh to a binary STL file.
- Parameters:
output_file_name – The file to write.
Private Functions
-
void initialize_from_file(const std::string &file_path, bool disable_validation)#
-
void initialize_from_float_grid(const openvdb::FloatGrid::Ptr &sdf_grid, bool disable_validation)#
-
void initialize_from_image_data(vtkSmartPointer<vtkImageData> sdf_image, bool disable_validation, bool allow_empty = false)#
-
void initialize_from_mesh_data(std::vector<glm::vec3> vertices, std::vector<Indexed_Triangle> triangles, bool disable_validation, bool allow_empty = false)#
-
void initialize_from_poly_data(vtkSmartPointer<vtkPolyData> poly_data, bool disable_validation, bool allow_empty = false)#
Private Members
-
glm::vec3 m_max = glm::vec3(0.0f)#
-
glm::vec3 m_min = glm::vec3(0.0f)#
-
std::vector<Indexed_Triangle> m_triangles#
-
std::vector<glm::vec3> m_vertices#
Private Static Functions
-
static std::pair<glm::vec3, glm::vec3> compute_bounding_box(const std::vector<glm::vec3> &vertices)#
-
static vtkSmartPointer<vtkPolyData> contour_sdf_image(vtkSmartPointer<vtkImageData> sdf_image)#
-
static vtkSmartPointer<vtkImageData> create_sdf_image_from_grid(const openvdb::FloatGrid::Ptr &sdf_grid)#
-
static std::tuple<std::vector<glm::vec3>, std::vector<Indexed_Triangle>, glm::vec3, glm::vec3> load_mesh_from_file(const std::string &file_path)#
-
static vtkSmartPointer<vtkPolyData> normalize_poly_data(vtkSmartPointer<vtkPolyData> poly_data)#
-
static std::shared_ptr<CGAL::Surface_mesh<SC_Point>> to_cgal_mesh(const std::vector<glm::vec3> &vertices, const std::vector<Indexed_Triangle> &triangles)#
-
static void validate_mesh(const std::vector<glm::vec3> &vertices, const std::vector<Indexed_Triangle> &triangles)#
Friends
- friend class MeshSampler
-
std::pair<glm::vec3, glm::vec3> bounding_box() const#
-
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, bool disable_validation = false)#
Compiles the internal BRep shape parameters to a primitive meshed output state.
- Parameters:
deflection – Geometry constraints mapping generation scaling.
disable_validation – If true, bypass CGAL closure validation on the generated mesh.
- 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 TetrahedralMesh#
- #include <tetrahedral_mesh.h>
Pure geometric tetrahedral mesh generated from an implicit OpenVCAD tree.
The mesh stores explicit node positions and tetrahedral connectivity. It contains no solver-specific or attribute-export logic.
Public Types
-
using Element = std::array<size_t, 4>#
Public Functions
-
inline std::pair<glm::vec3, glm::vec3> bounding_box() const#
Returns the prepared bounding box used for meshing.
-
inline const std::vector<glm::vec3> &cell_centroids() const#
Returns the centroid of each tetrahedral element.
-
inline const std::vector<glm::vec3> &nodes() const#
Returns the mesh node coordinates.
-
inline size_t number_of_elements() const#
Returns the number of tetrahedral elements.
-
inline size_t number_of_nodes() const#
Returns the number of mesh nodes.
-
TetrahedralMesh() = default#
Public Static Functions
Builds a tetrahedral mesh from an implicit tree using adaptive cell sizing.
Builds a tetrahedral mesh from an implicit tree using fixed cell sizing.
Private Members
-
std::pair<glm::vec3, glm::vec3> m_bounding_box#
-
std::vector<glm::vec3> m_cell_centroids#
-
std::vector<glm::vec3> m_nodes#
-
struct AdaptiveSettings#
- #include <tetrahedral_mesh.h>
Settings for an adaptive tetrahedral mesh.
-
struct FixedSettings#
- #include <tetrahedral_mesh.h>
Settings for a fixed-size tetrahedral mesh.
-
using Element = std::array<size_t, 4>#
-
class HexahedralMesh#
- #include <hexahedral_mesh.h>
Pure geometric structured hexahedral mesh generated from an implicit OpenVCAD tree.
The mesh stores explicit node positions and hexahedral connectivity. It contains no solver-specific or attribute-export logic.
Public Types
-
using Element = std::array<size_t, 8>#
Public Functions
-
inline std::pair<glm::vec3, glm::vec3> bounding_box() const#
Returns the prepared bounding box used for meshing.
-
inline const std::vector<glm::vec3> &cell_centroids() const#
Returns the centroid of each hexahedral element.
-
HexahedralMesh() = default#
-
HexahedralMesh(const std::vector<glm::vec3> &nodes, const std::vector<Element> &elements, const std::vector<glm::vec3> &cell_centroids, const std::pair<glm::vec3, glm::vec3> &bounding_box, const glm::vec3 &voxel_size)#
-
inline const std::vector<glm::vec3> &nodes() const#
Returns the mesh node coordinates.
-
inline size_t number_of_elements() const#
Returns the number of hexahedral elements.
-
inline size_t number_of_nodes() const#
Returns the number of mesh nodes.
-
inline glm::vec3 voxel_size() const#
Returns the voxel size used for structured meshing.
Public Static Functions
Builds a structured hexahedral mesh from an implicit tree.
-
using Element = std::array<size_t, 8>#
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#