Tree — leaves
Leaf geometry and primitives.
-
class Function : public Leaf
- #include <function.h>
A function geometry primitive/ leaf node.
This is analogs to an F-rep. Functions can be defined in cartesian, cylindrical, or spherical coordinates.
The function is defined by a string that is a math expression. The node uses the exprtk library and therefore can use any operations defined within its parser. The string can contain the following variables:
Cartesian coordinates: x, y, and z
Cylindrical coordinates: rho, phic, and z
Spherical coordinates: r, theta, and phis
Note
phic corresponds to phi in cylindrical and phis to phi in spherical
Note
This node can be evaluated in O(n) time, where N is the number of tokens in the expressions.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
Function()
Constructor for any empty function.
-
Function(const std::function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis)> &function, glm::vec3 min = glm::vec3(-10.0), glm::vec3 max = glm::vec3(10.0))
Constructs a Function node using a native C++ std::function callback.
- Parameters:
function – The callback returning the scalar distance field value.
min – The minimum bounds of the geometry function.
max – The maximum bounds of the geometry function.
-
Function(const std::string &function, glm::vec3 min = glm::vec3(-10.0), glm::vec3 max = glm::vec3(10.0))
Constructor for string-based mathematical expressions.
- Parameters:
function – The mathematical string expression to evaluate.
min – The minimum bounds of the geometry function.
max – The maximum bounds of the geometry function.
-
virtual void prepare(const glm::vec3 &voxel_size, double bandwidth) final
Validates & compiles the function, prepares parser.
Private Members
-
std::shared_ptr<ExpressionEvaluator> m_evaluator
-
std::function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis)> m_function
-
double m_phic
-
double m_phis
-
bool m_prepared = false
-
double m_r
-
double m_rho
-
std::string m_string_function
The function to evaluate as a string.
-
double m_theta
-
bool m_use_string_evaluator = true
-
double m_x
The variables for each thread.
-
double m_y
-
double m_z
-
class Mesh : public Leaf
- #include <mesh.h>
A mesh geometry primitive/ leaf node.
The mesh is loaded from a file and converted into a signed distance field using OpenVDB.
Mesh files are loaded into triangles/ vertices using the Assimp library. Then, the triangles are converted into a signed distance field using OpenVDB. When querried though the evaluate() function, the distance to the mesh is returned. The material() function returns the material of the mesh as supplied. The OpenVDB grid used here differs from the one used in the Voxel class. The Voxel class uses a grid of material values, while the Mesh class uses a grid of signed distance values.
Note
The Mesh class is only available if the Assimp and OpenVDB libraries are available.
Note
This node can be evaluated in O(1) time.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
openvdb::FloatGrid::Ptr getGrid()
Returns the raw OpenVDB signed distance grid.
- Returns:
The raw OpenVDB grid
-
Mesh() = default
-
Mesh(const std::string &path, bool center = false, bool disable_validation = false)
Constructor.
- Parameters:
path – The path to the mesh file to load
center – If true, the mesh will be centered at the origin after loading
disable_validation – If true, the mesh will not be validated for errors. This is useful for meshes where we know its ok if the mesh is not watertight or has self-intersections.
-
Mesh(const std::string &path, const glm::vec3 &sample_size, bool center = false, bool disable_validation = false)
-
Mesh(const std::string &path, double override_voxel_size, bool disable_validation = false)
Constructor.
- Parameters:
path – The path to the mesh file to load
override_voxel_size – The explicit voxel size to use when voxelizing the mesh into an SDF, bypassing the minimum bound heuristic
disable_validation – If true, the mesh will not be validated for errors
-
Mesh(double sdf_shim, std::string path)
Constructor.
- Parameters:
mesh – The mesh to load
-
virtual void prepare(const glm::vec3 &voxel_size, double bandwidth) final
Loads the mesh from file into signed distance field once before evaluation.
Private Types
-
typedef openvdb::FloatGrid GridType
The type of grid used by OpenVDB.
Private Functions
-
void load_from_file(bool center = false, bool disable_validation = false)
Loads the mesh from file into memory.
- Parameters:
center – If true, the mesh will be centered at the origin after loading
disable_validation – If true, the mesh will not be validated for errors
-
virtual void prepare_bounding_box() override
Private Members
-
std::string m_file_path
The path to the mesh file to load.
-
bool m_is_loaded = false
Whether the mesh has been loaded into the signed distance field grid.
-
std::shared_ptr<SurfaceMesh> m_mesh
-
double m_override_voxel_size = 0.0
The explicit voxel size to use when voxelizing the mesh, bypassing the minimum bound heuristic.
-
glm::vec3 m_sample_size = glm::vec3(std::numeric_limits<float>::infinity())
-
double m_sdf_shim = 0.0
-
bool m_use_override_voxel_size = false
If true, use m_override_voxel_size instead of the heuristic minimum bound in prepare().
-
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.
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class RectPrism : public Leaf
- #include <rect_prism.h>
A rectangular prism leaf node/ geometric primitive.
This node is a rectangular prism with a center point, size, and material id. The size is the side lengths in X, Y, and Z. The material id is the index of the material in the material list. The evaluate() and material() functions are compared against an equation.
Note
This node can be evaluated in O(1) time.
Note
This node is a leaf node, and therefore cannot have any children.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
virtual void prepare_bounding_box() override
Prepares the bounding box for the rectangular prism.
Public Static Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class Sphere : public Leaf
- #include <sphere.h>
A sphere leaf node/ geometric primitive.
This node is a sphere with a center point, radius, and material id. The material id is the index of the material in the material list. The evaluate() and material() functions are compared against an equation.
Note
This node can be evaluated in O(1) time.
Note
This node is a leaf node, and therefore cannot have any children.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
Sphere(double x, double y, double z, double radius)
Private Functions
-
virtual void prepare_bounding_box() override
See also
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class Strut : public Leaf
- #include <strut.h>
A leaf node that represents a strut.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
Strut(glm::vec3 start, glm::vec3 end, double radius)
Constructor.
- Parameters:
start – The start of the strut.
end – The end of the strut.
radius – The radius of the strut.
material – The material of the strut.
Private Functions
-
virtual void prepare_bounding_box() override
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class CAD : public Leaf
- #include <cad.h>
A CAD geometry primitive/ leaf node.
The CAD is loaded from a file into memory for sampling.
Note
The node supports .STEP and .igs files.
Public Functions
-
CAD() = default
-
CAD(const std::string &path, bool use_fast_mode = true)
Constructor.
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
Private Functions
-
CAD() = default
-
class Cylinder : public Leaf
- #include <cylinder.h>
A cylinder leaf node/ geometric primitive.
This node is a cylinder with a center point, radius, height, and material id. The cylinder is aligned along the Z-axis, standing upright, and centered at (0,0,0). The evaluate() function returns the signed distance to the surface.
Note
This node can be evaluated in O(1) time.
Note
This node is a leaf node, and therefore cannot have any children.
Public Functions
-
Cylinder()
Default constructor. Creates a Cylinder with a center of (0,0,0), radius of 1, height of 1, and material id of 1.
-
Cylinder(glm::vec3 center, double radius, double height)
Constructor.
Creates a Cylinder with a center, radius, height, and material id.
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
Private Functions
-
virtual void prepare_bounding_box() override
-
Cylinder()
-
class Cone : public Leaf
- #include <cone.h>
A cone leaf node/ geometric primitive.
Public Functions
-
Cone() = default
Default constructor.
-
Cone(double angle, double height)
Constructor.
Creates a Cone with an angle and height.
- Parameters:
angle – The aperture half-angle in radians.
height – The height of the cone.
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
Private Functions
-
virtual void prepare_bounding_box() override
See also
-
Cone() = default
-
class Torus : public Leaf
- #include <torus.h>
A torus leaf node/ geometric primitive.
This node is a torus with a major and minor radius. See this for more information: https://wiki.povray.org/uploaded/2/29/RefImgMimxrtor.gif The major radius is the distance from the center of the torus to the center of the tube. The minor radius is the radius of the tube.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
Torus() = default
Default constructor.
Private Functions
-
virtual void prepare_bounding_box() override
See also
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class GraphLattice : public Leaf
- #include <graph_lattice.h>
A leaf node representing a lattice structure constructed from a list of edges.
Struts are created for each edge and grouped into an internal bounding volume hierarchy.
Public Types
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
GraphLattice(const std::vector<std::pair<glm::vec3, glm::vec3>> &edges, double radius)
-
GraphLattice(LatticeType type, glm::vec3 size, double radius)
-
virtual void prepare(const glm::vec3 &voxel_size, double bandwidth) final
See also
Public Static Functions
-
static std::vector<std::pair<glm::vec3, glm::vec3>> BCC_GenerateEdges(glm::vec3 size)
Generates edge definitions for a Body Centered Cubic (BCC) lattice unit cell.
- Parameters:
size – The dimensions of the unit cell in X, Y, and Z.
- Returns:
A list of start and end point pairs defining the struts.
-
static std::vector<std::pair<glm::vec3, glm::vec3>> Cubic_GenerateEdges(glm::vec3 size)
Generates edge definitions for a simple Cubic lattice unit cell.
- Parameters:
size – The dimensions of the unit cell in X, Y, and Z.
- Returns:
A list of start and end point pairs defining the struts.
-
static std::vector<std::pair<glm::vec3, glm::vec3>> FCC_GenerateEdges(glm::vec3 size)
Generates edge definitions for a Face Centered Cubic (FCC) lattice unit cell.
- Parameters:
size – The dimensions of the unit cell in X, Y, and Z.
- Returns:
A list of start and end point pairs defining the struts.
-
static std::vector<std::pair<glm::vec3, glm::vec3>> KelvinCell_GenerateEdges(glm::vec3 size)
Generates edge definitions for a Kelvin Cell lattice unit cell.
- Parameters:
size – The dimensions of the unit cell in X, Y, and Z.
- Returns:
A list of start and end point pairs defining the struts.
-
virtual std::optional<double> evaluate(double x, double y, double z) final
-
class Text : public Leaf
- #include <text.h>
A text leaf node which generates a 3D text object by extruding the text along the Z-axis.
Generates a 3D text object from a given string by creating a planar CAD outline and extruding it.
Note
Uses a default font (Arial). The CAD part is built during initialization.
Public Types
-
enum class FontAspect
Values:
-
enumerator Regular
-
enumerator Bold
-
enumerator Italic
-
enumerator BoldItalic
-
enumerator Regular
-
enum class HorizontalAlignment
Horizontal text alignment options.
Values:
-
enum class VerticalAlignment
Vertical text alignment options.
Values:
-
enumerator Bottom
The anchor lies on the last line of the text.
-
enumerator Center
The anchor lies on the center of the text.
-
enumerator Top
The anchor lies on the line preceding the first line of the text.
-
enumerator TopFirstLine
The anchor lies on the first line of the text.
-
enumerator Bottom
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) override
See also
-
virtual void prepare(const glm::vec3 &voxel_size, double bandwidth) override
See also
-
Text() = default
Default constructor.
-
Text(std::string text, double height, double depth, FontAspect aspect = FontAspect::Regular, std::string font = "Consolas", HorizontalAlignment h_align = HorizontalAlignment::Center, VerticalAlignment v_align = VerticalAlignment::Center)
Constructor.
Creates a Text node with a given text, height, depth, and material id.
- Parameters:
text – The text content used for generating the 3D object.
height – The height of the text.
depth – The extrusion depth of the text.
material – The material id of the text node (default is 1).
h_align – The horizontal alignment of the text (default is Left).
v_align – The vertical alignment of the text (default is Bottom).
Private Functions
-
void make_text_cad_part(const std::string &text, double height, double depth)
Builds the CAD part for the text node.
- Parameters:
text – The text string.
height – The height of the text.
depth – The extrusion depth.
-
virtual void prepare_bounding_box() override
Private Members
-
FontAspect m_aspect
-
double m_depth
-
std::string m_font = "Consolas"
-
HorizontalAlignment m_h_align = HorizontalAlignment::Left
-
double m_height
-
std::string m_string
-
VerticalAlignment m_v_align = VerticalAlignment::Bottom
-
enum class FontAspect
-
class SignedDistanceField : public Leaf
- #include <signed_distance_field.h>
Represents a signed distance field using OpenVDB.
This is
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) override
See also
-
virtual void prepare(const glm::vec3 &voxel_size, double bandwidth) override
See also
-
virtual void prepare_bounding_box() override
See also
-
void save_openvdb_grid(const std::string &file_path) const
Saves the underlying OpenVDB grid to a VDB file.
- Parameters:
file_path – The path where the VDB file will be saved.
-
SignedDistanceField()
Create an empty SignedDistanceField.
This constructor initializes an empty SignedDistanceField.
-
SignedDistanceField(const openvdb::BoolGrid::Ptr &occupancy_grid)
Create a SignedDistanceField from an occupancy grid.
This constructor computes the signed distance field from a given occupancy grid. The occupancy grid is expected to be a BoolGrid where occupied voxels are set to true.
- Parameters:
occupancy_grid – The occupancy grid from which to compute the signed distance field
-
SignedDistanceField(const openvdb::FloatGrid::Ptr &grid)
Create an SignedDistanceField from an OpenVDB FloatGrid.
This constructor initializes the SignedDistanceField with an existing OpenVDB FloatGrid. The FloatGrid is expected to represent a signed distance field where positive values indicate distances to the surface and negative values indicate distances inside the surface. Zero values indicate the surface itself.
- Parameters:
grid – The OpenVDB FloatGrid to use as the signed distance field
material – The material of the SDF, default is 1
-
SignedDistanceField(const std::string &vdb_file_path, const std::string &grid_name = "occupancy")
Create a SignedDistanceField from a VDB file.
This constructor loads a signed distance field from a specified VDB file path. The VDB file is expected to contain either a BooleanGrid representing an occupancy grid or a FloatGrid representing the signed distance field. We auto-detect the grid type based the type of grid stored in the file. If the grid is a BooleanGrid, it will be converted to a signed distance field. If it’s already a FloatGrid, it will be used directly as the signed distance field. The grid name can be specified, and it defaults to “occupancy”.
- Parameters:
vdb_file_path – The file path to the VDB file containing the grid
grid_name – The name of the grid to load from the VDB file, default is “occupancy”
Private Types
-
typedef openvdb::FloatGrid GridType
Private Functions
-
void init_from_bool_grid(const openvdb::BoolGrid::Ptr &occupancy_grid)
Initialize the grid from a BoolGrid (occupancy grid).
Converts the BoolGrid to a level set SDF and stores in m_grid.
- Parameters:
occupancy_grid – The BoolGrid representing occupied voxels
-
void init_from_float_grid(const openvdb::FloatGrid::Ptr &grid)
Initialize the grid from a FloatGrid.
Sets m_grid from the provided FloatGrid, marks it as a level set, and names it “surface”.
- Parameters:
grid – The FloatGrid to use as the signed distance field
-
void load_from_vdb_file(const std::string &vdb_file_path, const std::string &grid_name)
Load a grid from a VDB file and initialize appropriately.
Opens the VDB file, finds the named grid, determines if it’s a FloatGrid or BoolGrid, and calls the appropriate init function.
- Parameters:
vdb_file_path – Path to the VDB file
grid_name – Name of the grid to load from the file
-
virtual std::optional<double> evaluate(double x, double y, double z) override
-
class PolygonExtrude : public Leaf
- #include <polygon_extrude.h>
An extruded polygon leaf node / geometric primitive.
This node takes a planar polygon defined by a series of 3D points and extrudes it along its computed normal (right-hand rule) by a given height. The polygon must be planar; the constructor validates this and throws if the points are not coplanar. The extrusion can be symmetric (half the height on each side of the polygon plane) or one-directional (full height in the normal direction). A negative height extrudes in the opposite direction of the normal.
Note
This node can be evaluated in O(n) time where n is the number of polygon vertices.
Note
This node is a leaf node, and therefore cannot have any children.
Public Functions
-
virtual std::optional<double> evaluate(double x, double y, double z) final
See also
-
PolygonExtrude()
Default constructor. Creates a unit square in the XY plane, extruded 1 unit in +Z.
-
PolygonExtrude(const std::vector<glm::vec3> &vertices, double height, bool symmetric = false)
Constructor.
Creates an extruded polygon from a list of coplanar 3D vertices.
- Parameters:
vertices – The vertices of the planar polygon (minimum 3, must be coplanar).
height – The extrusion distance along the polygon normal.
symmetric – If true, extrudes height/2 on each side of the polygon plane.
- Throws:
std::runtime_error – if fewer than 3 vertices, points are collinear, or not coplanar.
-
virtual void prepare_bounding_box() override
See also
Private Functions
-
void initialize()
Initializes internal precomputed data from the stored vertices, height, and symmetric flag.
-
double polygon_sdf_2d(double pu, double pv) const
Computes the 2D signed distance from a point (in local UV space) to the polygon boundary.
- Parameters:
pu – The u coordinate of the point in the local polygon plane.
pv – The v coordinate of the point in the local polygon plane.
- Returns:
Negative if inside the polygon, positive if outside, zero on the boundary.
Private Members
-
double m_extrude_max
The maximum extrusion distance along the normal from the polygon plane.
-
double m_extrude_min
The minimum extrusion distance along the normal from the polygon plane.
-
double m_height
The extrusion height.
-
glm::dvec3 m_normal
The polygon plane normal (right-hand rule from vertex winding).
-
glm::dvec3 m_origin
A point on the polygon plane (first vertex), used as origin for local frame.
-
bool m_symmetric
Whether the extrusion is symmetric about the polygon plane.
-
glm::dvec3 m_u_axis
Local U axis in the polygon plane.
-
glm::dvec3 m_v_axis
Local V axis in the polygon plane.
-
std::vector<glm::vec3> m_vertices
The original 3D vertices of the polygon.
-
std::vector<glm::dvec2> m_vertices_2d
The polygon vertices projected into the local 2D (u, v) coordinate frame.
-
virtual std::optional<double> evaluate(double x, double y, double z) final