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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual 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, uint8_t material = 1, glm::vec3 min = glm::vec3(-10.0), glm::vec3 max = glm::vec3(10.0))
-
Function(const std::string &function, uint8_t material = 1, glm::vec3 min = glm::vec3(-10.0), glm::vec3 max = glm::vec3(10.0))
Constructor.
- Parameters:
function – The function to evaluate
material – The material of the function
-
virtual std::vector<uint8_t> material_list() override
See also
Private Functions
-
void prepare_expression()
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
-
uint8_t m_material_id = 1
The material of the 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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) override
See also
-
openvdb::FloatGrid::Ptr getGrid()
Returns the raw OpenVDB signed distance grid.
- Returns:
The raw OpenVDB grid
-
virtual std::vector<uint8_t> material_list() override
See also
-
Mesh() = default
-
Mesh(const std::string &path, const glm::vec3 &sample_size, uint8_t material = 1, bool disable_validation = false)
-
Mesh(const std::string &path, double override_voxel_size, uint8_t material = 1, bool disable_validation = false)
Constructor.
- Parameters:
path – The path to the mesh file to load
material – The material of the mesh
disable_validation – If true, the mesh will not be validated for errors
override_voxel_size – The explicit voxel size to use when voxelizing the mesh into an SDF, bypassing the minimum bound heuristic
-
Mesh(const std::string &path, uint8_t material = 1, bool disable_validation = false)
Constructor.
- Parameters:
path – The path to the mesh file to load
material – The material of the mesh
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(double sdf_shim, std::string path)
Constructor.
- Parameters:
mesh – The mesh to load
material – The material of the mesh
Private Types
-
typedef openvdb::FloatGrid GridType
The type of grid used by OpenVDB.
Private Functions
-
void load_from_file(bool disable_validation = false)
Loads the mesh from file into memory.
- Parameters:
disable_validation – If true, the mesh will not be validated for errors
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.
-
uint8_t m_material
The material of the mesh.
-
vec3 m_max = vec3(0)
-
std::shared_ptr<SurfaceMesh> m_mesh
-
vec3 m_min
The minimum and maximum bounds of the mesh.
-
double m_override_voxel_size = 0.0
The explicit voxel size to use when voxelizing the mesh, bypassing the minimum bound heuristic.
-
double m_sdf_shim = 0.0
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
-
class PointMap : public Leaf
- #include <point_map.h>
A leaf node that represents simulation results that are imported.
This class is used to import simulation results from external files and map a multi-material distribution them as a design The simulation results must be stored in a tetrahedral mesh saved as a .inp file and a displacement field saved as a .csv file This class assumes nodal displacements are stored in the displacement field file and that the indices of the nodes in the tetrahedral mesh correspond to the indices of the nodes in the displacement field file. The displacement field file must have the following format (where xyz is the coordinates of the node and uvw is the displacement vector): x1, y1, z1, u1, v1, w1 x2, y2, z2, u2, v2, w2 … The tetrahedral mesh file must be an Abaqus .inp file using C3D4 elements. The point map can be used to evaluate functions at any point in space by interpolating the simulation results. However, the material distribution is only available within the tetrahedral mesh. Likewise, the signed distance returned by the evaluate() function is simple point membership. Mapping functions are defined using the exprtk library and are similar to the f_grade() node. When sampling a point in space, the following variables are available in math expressions:
x, y, z: The coordinates of the point
rho, phic, r: The cylindrical coordinates of the point
theta, phis: The spherical coordinates of the point
dx, dy, dz: The displacement vector at the point
len: The length of the displacement vector Similar to f_grade(), each function defined must also have a corresponding material id defined with it. When sampled using distribution() the volume fractions/ probability density is returned as evaluated by the functions. The point map can be used in probability mode where the material() function uses the material distribution as a probability masses and returns a random material id based on the distribution. Threshold mode is also available where the material() function returns the material id with the highest probability mass.
Note
This class only supports tetrahedral meshes using displacement or stress fields
Public Functions
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
PointMap() = default
Destructor.
-
PointMap(const std::string &mesh_path, const std::string &tet_mesh_path, const std::string &displacement_field_path, std::vector<std::string> functions, std::vector<uint8_t> materials, bool prob_mode = true)
Constructor.
- Parameters:
mesh_path – Path to the triangular surface mesh file
tet_mesh_path – Path to the tetrahedral mesh file
displacement_field_path – Path to the displacement field file
functions – List of functions to evaluate
materials – List of materials
prob_mode – Whether the point map is in probability mode
Private Functions
-
template<typename T>
inline T compute_value(double x, double y, double z) Computes the displacement at a point in space.
If the point is not on a node, the displacement is interpolated
- Parameters:
x – X coordinate of the point
y – Y coordinate of the point
z – Z coordinate of the point
- Returns:
The displacement at the point, interpolated if necessary
-
bool is_displacment_map(const std::string &point_map_filename)
-
void LoadTetrahedronsFromFileAsDisplacement(const std::string &inp_filename, const std::string &point_map_filename)
Loads the displacement field from a file into this object.
- Parameters:
inp_filename – Path to the inp file
point_map_filename – Path to the displacement field file
-
void LoadTetrahedronsFromFileAsStress(const std::string &inp_filename, const std::string &point_map_filename)
-
void prepare_evaluators()
Private Members
-
std::shared_ptr<void> m_aabb_tree
-
std::string m_displacement_field_path
-
double m_dx
-
double m_dy
-
double m_dz
-
std::vector<std::shared_ptr<ExpressionEvaluator>> m_evaluators
-
std::vector<std::string> m_function_strings
-
double m_len
-
bool m_loaded_displacement = false
-
std::vector<uint8_t> m_materials
-
std::string m_mesh_path
-
double m_phic
-
double m_phis
-
bool m_prepared = false
-
bool m_prob_mode = true
-
double m_r
-
double m_rho
-
double m_stress
-
std::string m_tet_mesh_path
-
double m_theta
-
double m_x
-
double m_y
-
double m_z
Private Static Functions
-
static std::vector<std::string> Split(const std::string &s, char delimiter)
Splits a string by a delimiter.
- Parameters:
s – The string to split
delimiter – The delimiter to split by
- Returns:
A vector of strings
-
template<typename T>
struct ValuedPoint A struct to store a point with its displacement.
-
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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
-
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::unordered_map<uint8_t, float> distribution(double x, double y, double z) final
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() final
See also
-
Sphere()
Default constructor. Creates a Sphere with a center of (0, 0, 0), radius of 1, and material id of 1.
-
virtual std::unordered_map<uint8_t, float> distribution(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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
-
class Voxels : public Leaf
- #include <voxels.h>
A leaf node/ geometric primitive that contains a voxel grid that can be loaded from disk or generated from an equation.
Voxels are stored in a OpenVDB grid. The grid is populated from a PNG stack, existing VDB grid file, or an equation. The grid can be also saved to disk. The input grid is assumed to be material values stored a integers.
Note
This node can be evaluated in O(1) time. TODO Add support for loading/ processing of medical imagery files directly TODO Add support for loading VDB files that contain geometry instead of material values (i.e. a signed distance field)
Public Functions
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) override
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
void populate_with_equation(std::string equation, vec3 min, vec3 max, vec3 voxel_size)
Populates the grid with a VDB file.
- Parameters:
file_path – The path to the VDB file
min – The minimum coordinate of the grid
voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
-
void populate_with_png_stack(std::string dir, vec3 min, vec3 voxel_size)
Populates the grid with a PNG stack given a directory.
The PNG files are assumed to be named in order (i.e. 001.png, 002.png. etc.). The material values are converted to OpenVCAD material values using the material definitions.
- Parameters:
dir – The directory containing the PNG files
min – The minimum coordinate of the grid
voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
-
void save_to_file(std::string file_path) const
Saves the grid to a VDB file.
Constructor.
Note
this constructor will automatically call the correct load function based on the file extension TODO: Move the load functions to called in a custom prepare() function
- Parameters:
file_path – The path to the file to load the voxel grid from
voxel_size – The size of each voxel in the grid. This resolution does not need to match what you sample, and can be asymmetric.
min – The minimum coordinate of the grid
material_defs – A pointer to the material definitions. This is needed to convert the material values in the grid into OpenVCAD material values. This is only needed when loading a grid from a PNG stack
-
Voxels(vec3 voxel_size, vec3 min)
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.
min – The minimum coordinate of the grid
Private Types
-
typedef openvdb::FloatGrid GridType
Private Functions
-
void load_vdb(const std::string &file_path)
Loads a VDB file.
- Parameters:
file_path – The path to the VDB file
Private Members
-
std::string m_file_path
The path to the file that the grid was loaded from.
-
std::shared_ptr<MaterialDefs> m_material_defs
A pointer to the material definitions. This is needed to convert the material values in the grid into OpenVCAD material values. This is only needed when loading a grid from a PNG stack.
-
std::map<uint8_t, uint8_t> m_material_list
-
vec3 m_max
-
vec3 m_min
The minimum coordinate of the grid.
-
vec3 m_voxel_size
The size of each voxel in the grid.
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
-
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, uint8_t material = 1)
Constructor.
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) override
See also
-
virtual std::vector<uint8_t> material_list() override
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(vec3 center, double radius, double height, uint8_t material = 1)
Constructor.
Creates a Cylinder with a center, radius, height, and material id.
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
Cylinder()
-
class GraphLattice : public Leaf
- #include <graph_lattice.h>
Public Types
Public Functions
-
virtual std::shared_ptr<Node> clone() override
Clones the node and returns a new instance of the node.
Note
This may be called before or after prepare() is called, however it is always more efficient to call it after. This is because the prepare() function must be called on all clones of the node separately. If you call prepare() first and then clone the node, the clone() operation will copy from memory instead of re-reading from disk.
- Returns:
A new instance of the node
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
Returns the material distribution at the given point.
- Parameters:
x – The x coordinate of the point to evaluate.
y – The y coordinate of the point to evaluate.
z – The z coordinate of the point to evaluate.
- Returns:
A list of pairs each containing the material ID and the probability distribution of that material.
-
virtual double evaluate(double x, double y, double z) override
Evaluates the node at the given point.
- Parameters:
x – The x coordinate of the point to evaluate.
y – The y coordinate of the point to evaluate.
z – The z coordinate of the point to evaluate.
- Returns:
The distance to the surface at the given point.
-
GraphLattice(const std::vector<std::pair<glm::vec3, glm::vec3>> &edges, double radius, uint8_t material)
-
GraphLattice(LatticeType type, glm::vec3 size, double radius, uint8_t material)
-
virtual std::vector<uint8_t> material_list() override
Returns a list of all the materials used by the node and its children.
- Returns:
A list of all the material IDs used by the node and its children.
Public Static Functions
Private Functions
-
void build_lattice()
-
virtual std::shared_ptr<Node> clone() override
-
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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) override
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override
See also
-
Text() = default
Default constructor.
-
Text(std::string text, double height, double depth, uint8_t material = 1, 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
Private Members
-
FontAspect m_aspect
-
double m_depth
-
std::string m_font = "Consolas"
-
HorizontalAlignment m_h_align = HorizontalAlignment::Left
-
double m_height
-
uint8_t m_material = 1
-
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::unordered_map<uint8_t, float> distribution(double x, double y, double z) override
See also
-
virtual double evaluate(double x, double y, double z) override
See also
-
virtual std::vector<uint8_t> material_list() override
See also
-
virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override
See also
-
void save_openvdb_grid(const std::string &file_path) const
-
SignedDistanceField(const openvdb::BoolGrid::Ptr &occupancy_grid, uint8_t material = 1)
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
material – The material of the SDF, default is 1
-
SignedDistanceField(const openvdb::FloatGrid::Ptr &grid, uint8_t material = 1)
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(uint8_t material = 1)
Create an empty SignedDistanceField.
This constructor initializes an empty SignedDistanceField.
-
virtual std::unordered_map<uint8_t, float> distribution(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::unordered_map<uint8_t, float> distribution(double x, double y, double z) final
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() 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, uint8_t material = 1)
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.
material – The material id of the PolygonExtrude.
- Throws:
std::runtime_error – if fewer than 3 vertices, points are collinear, or not coplanar.
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.
-
uint8_t m_material_id
The material id.
-
bool m_symmetric
Whether the extrusion is symmetric about the polygon plane.
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) final