Tree — composition

Transforms, boolean CSG, and other composition operators.

Transforms and warps

class Rotate : public Unary
#include <rotate.h>

Rotates a child node around a point.

The rotation is specified by a pitch, yaw and roll angles and a point around which the rotation is performed.

The rotation is performed in the following order: roll, yaw, pitch. The rotation is performed around the point (0, 0, 0) by default, but can be changed by specifying a different point in the constructor. To affect a rotation on child geometry, the sample point in evaluate() or material() is transformed by the inverse of the rotation matrix.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) override

See also

Node::evaluate

virtual std::vector<uint8_t> material_list() override

Rotate() = default

Default constructor. Defaults to no rotation.

Rotate(double pitch, double yaw, double roll, glm::vec3 around, const std::shared_ptr<Node> &child)

Constructor with child.

Parameters:
  • pitch – Pitch angle in degrees

  • yaw – Yaw angle in degrees

  • roll – Roll angle in degrees

  • aroundPoint around which the rotation is performed

  • child – Child node

Rotate(double pitch, double yaw, double roll, glm::vec3 around = glm::vec3(0, 0, 0))

Constructor.

Parameters:
  • pitch – Pitch angle in degrees

  • yaw – Yaw angle in degrees

  • roll – Roll angle in degrees

  • aroundPoint around which the rotation is performed. Defaults to (0, 0, 0)

Private Members

glm::vec3 m_around = glm::vec3(0.0f, 0.0f, 0.0f)

Point around which the rotation is performed.

glm::quat m_inverse_rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f)
glm::quat m_rotation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f))

Rotation stored in a 4D quaternion.

class Scale : public Unary
#include <scale.h>

Scale a child by a factor in each dimension.

This node is unary, therefore can only have one child.

The Scale class is a node that scales a node by a factor in each dimension. This node is unary, therefore can only have one child. The scale is actually applied when evaluate() is called and performs the inverse of the scaling on the supplied point.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) override

See also

Node::evaluate()

virtual std::vector<uint8_t> material_list() override

Scale() = default

Default constructor. Sets the scale to 1.0 in each dimension.

Scale(double x, double y, double z)

Constructor.

Sets the scale to the supplied values.

Parameters:
  • x – The scale in the x dimension.

  • y – The scale in the y dimension.

  • z – The scale in the z dimension.

Scale(double x, double y, double z, const std::shared_ptr<Node> &child)

Constructor with child.

Sets the scale to the supplied values.

Parameters:
  • x – The scale in the x dimension.

  • y – The scale in the y dimension.

  • z – The scale in the z dimension.

  • child – The child node.

Private Members

double m_x = 1.0

The scale in the x dimension.

double m_y = 1.0

The scale in the y dimension.

double m_z = 1.0

The scale in the z dimension.

class Translate : public Unary
#include <translate.h>

Translate a child in cartesian space by a given amount.

This node is unary, so it may only have one child.

This node performs the inverse translation on the coordinates sampled in material() and evaluate().

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) override

See also

Node::evaluate()

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.

Translate() = default

Default constructor. Sets the translation to 0, 0, 0.

Translate(double x, double y, double z)

Constructor.

Sets the translation to the given values.

Parameters:
  • x – The amount to translate in the x direction.

  • y – The amount to translate in the y direction.

  • z – The amount to translate in the z direction.

Translate(double x, double y, double z, const std::shared_ptr<Node> &child)

Constructor.

Sets the translation to the given values and sets the child.

Parameters:
  • x – The amount to translate in the x direction.

  • y – The amount to translate in the y direction.

  • z – The amount to translate in the z direction.

  • child – The child to set.

Private Members

double m_x = 0

The amount to translate in the x direction.

double m_y = 0

The amount to translate in the y direction.

double m_z = 0

The amount to translate in the z direction.

class Offset : public Unary
#include <offset.h>

Shifts the signed distance reported by its child by a constant offset.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) override

See also

Node::evaluate()

virtual std::vector<uint8_t> material_list() override

Offset() = default

Default constructor with zero offset.

explicit Offset(double offset)

Constructor with offset.

Offset(double offset, const std::shared_ptr<Node> &child)

Constructor with offset and child.

virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override

See also

Node::prepare()

Private Members

double m_offset = 0.0
class Shell : public Unary
#include <shell.h>

Computes an inward shell of a child node by subtracting an inward offset from the original.

The shell is obtained as Difference(child, Offset(child)).

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override
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.

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.

virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override

See also

Node::prepare()

Shell() = default
explicit Shell(double thickness)

Constructor with shell thickness. Thickness must be positive.

Shell(double thickness, const std::shared_ptr<Node> &child)

Constructor with shell thickness and child.

Private Functions

void build_subtree()

Private Members

std::shared_ptr<Node> m_shell_diff
double m_thickness = 0.0
class ConformalMap : public Binary
#include <conformal_map.h>

Maps a pattern node onto the surface of a base node by warping coordinates.

Builds a local frame from the base surface, transports the anchor frame to the query by shortest rotation, and computes (u,v) from a rotation vector (axis*angle). Angle->length is auto-calibrated at the anchor to preserve expected pattern scale without precompute.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override
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

ConformalMap() = default
ConformalMap(const std::shared_ptr<Node> &base, const std::shared_ptr<Node> &pattern)
ConformalMap(const std::shared_ptr<Node> &base, const std::shared_ptr<Node> &pattern, const glm::vec3 &ref_dir)
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.

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.

virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override

See also

Node::prepare()

inline void setArcScale(float s)
inline void setArcScale(float su, float sv)

Private Functions

void compute_anchor()
glm::vec3 map_to_pattern_coords(double x, double y, double z)

Private Members

glm::vec3 m_anchor = {0, 0, 0}
float m_arc_scale_u = 1.0f
float m_arc_scale_v = 1.0f
glm::vec3 m_Na = {0, 0, 1}
glm::vec3 m_ref_dir = {0, 0, 1}
glm::vec3 m_Ua = {1, 0, 0}
glm::vec3 m_Va = {0, 1, 0}
class Map : public Leaf
#include <map.h>

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override
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.

Map(const std::string &surface_path, const std::string &closed_mesh_path)
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.

Private Members

std::shared_ptr<BBoxUnion> m_bbox_union
std::shared_ptr<SurfaceParamerterizer> m_paramerterizer

N-ary composition

class Sum : public N_ary
#include <sum.h>

A sum node.

The sum is taken as the sum of all child SDFs.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) final

See also

Node::evaluate()

virtual std::vector<uint8_t> material_list() override

Sum() = default

Default constructor.

Sum(double iso_value)

Constructor.

Parameters:

iso_value – The iso value of the sum.

Sum(double iso_value, const std::vector<std::shared_ptr<Node>> &children)

Constructor.

Parameters:
  • iso_value – The iso value of the sum.

  • children – The children of the sum.

Private Members

double m_iso_value = 0.0
class Tile : public Unary
#include <tile.h>

A tile is a unary operator that repeats a geometry as a pattern in a grid.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

Note

Node::tile will tile child distribution in a grid the same way it tiles geometry

virtual double evaluate(double x, double y, double z) override

See also

Node::evaluate

virtual std::vector<uint8_t> material_list() override

virtual void prepare(const glm::vec3 &voxel_size, double interior_bandwidth, double exterior_bandwidth) override

See also

Node::prepare

Tile() = default

Default Constructor.

Note

The cell dimensions will be calculated from the child node when prepare is called

Tile(const std::shared_ptr<Node> &child)

Constructor.

Note

The cell dimensions will be calculated from the child node

Parameters:

child – The child node

Tile(double cell_x, double cell_y, double cell_z)

Constructor.

Note

The child node’s size will be ignored and the supplied cell dimensions will be used instead

Parameters:
  • cell_x – The x dimension of a cell the grid

  • cell_y – The y dimension of a cell the grid

  • cell_z – The z dimension of a cell the grid

Tile(double cell_x, double cell_y, double cell_z, const std::shared_ptr<Node> &child)

Constructor.

Parameters:
  • cell_x – The x dimension of a cell the grid

  • cell_y – The y dimension of a cell the grid

  • cell_z – The z dimension of a cell the grid

  • child – The child node

Private Functions

std::tuple<double, double, double> world_to_cell_coords(double x, double y, double z) const

Converts world coordinates to cell coordinates.

This takes the modulus of the world coordinates

Parameters:
  • x – coord in world space

  • y – coord in world space

  • z – coord in world space

Returns:

a tuple of x,y,z coordinates in cell space

Private Members

double m_cell_x = -1

The x dimension of a cell the grid.

double m_cell_y = -1

The y dimension of a cell the grid.

double m_cell_z = -1

The z dimension of a cell the grid.

Boolean CSG

class Difference : public Binary
#include <difference.h>

A difference binary node.

The difference is taken as the left child minus the right child.

Supports an optional smooth blending radius k. When k > 0, the difference uses smooth subtraction to produce rounded transitions.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

Difference() = default

Default constructor.

Difference(const std::shared_ptr<Node> &left, const std::shared_ptr<Node> &right)
explicit Difference(double k)

Constructor for smooth difference.

Parameters:

k – The smoothing radius. When k > 0, produces a smooth subtraction.

Difference(double k, const std::shared_ptr<Node> &left, const std::shared_ptr<Node> &right)

Constructor for smooth difference with children.

Parameters:
  • k – The smoothing radius.

  • left – The left child node.

  • right – The right child node.

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) final

See also

Node::evaluate()

virtual std::vector<uint8_t> material_list() override

Private Members

double m_smooth_k = 0.0

The smoothing radius for smooth difference. 0 = sharp (default).

class Intersection : public N_ary
#include <intersection.h>

Intersection of two or more nodes.

Supports an optional smooth blending radius k. When k > 0, the intersection uses smooth intersection to produce rounded transitions.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) final

See also

Node::evaluate()

Intersection(bool intersect_distribution, const std::vector<std::shared_ptr<Node>> &children)

Constructor with children.

Parameters:
  • intersect_distribution – If true, the distribution will be intersected. If false, the distribution will be summed.

  • children – The children nodes

Intersection(bool intersect_distribution = false)

Default constructor.

Intersection(double k, bool intersect_distribution, const std::vector<std::shared_ptr<Node>> &children)

Constructor for smooth intersection with children.

Parameters:
  • k – The smoothing radius.

  • intersect_distribution – If true, the distribution will be intersected.

  • children – The children nodes.

Intersection(double k, bool intersect_distribution = false)

Constructor for smooth intersection.

Parameters:
  • k – The smoothing radius. When k > 0, produces a smooth blend.

  • intersect_distribution – If true, the distribution will be intersected.

virtual std::vector<uint8_t> material_list() override

Private Members

bool m_intersect_distribution = false
double m_smooth_k = 0.0

The smoothing radius for smooth intersection. 0 = sharp (default).

class Union : public N_ary
#include <union.h>

A union of two or more nodes.

This is equivalent to the summing of the children.

Supports an optional smooth blending radius k. When k > 0, the union uses a quadratic smooth-min to produce rounded transitions between children.

Public Functions

virtual std::pair<glm::vec3, glm::vec3> bounding_box() override

virtual std::shared_ptr<Node> clone() override

See also

Node::clone()

virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z) override

virtual double evaluate(double x, double y, double z) final

See also

Node::evaluate()

virtual std::vector<uint8_t> material_list() override

Union(bool should_union_distribution, const std::vector<std::shared_ptr<Node>> &children)
explicit Union(bool should_union_distribution = false)

Default constructor.

Union(double k, bool should_union_distribution, const std::vector<std::shared_ptr<Node>> &children)

Constructor for smooth union with children.

Parameters:
  • k – The smoothing radius.

  • should_union_distribution – If true, the distribution will be unioned.

  • children – The children nodes.

Union(double k, bool should_union_distribution = false)

Constructor for smooth union.

Parameters:
  • k – The smoothing radius. When k > 0, produces a smooth blend between children.

  • should_union_distribution – If true, the distribution will be unioned.

Private Members

double m_smooth_k = 0.0

The smoothing radius for smooth union. 0 = sharp (default).

bool m_union_distribution = false
class BBoxUnion : public N_ary
#include <bbox_union.h>

Public Functions

virtual bool addChild(std::shared_ptr<Node> child) override

Trys to add a child to the node, if the node is full then it returns false.

Parameters:

child – The child to add to the node

Returns:

True if the child was added, false otherwise

BBoxUnion()
BBoxUnion(std::vector<std::shared_ptr<Node>> children)
virtual std::pair<glm::vec3, glm::vec3> bounding_box() override
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.

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.

Private Members

std::shared_ptr<AABBVCADTree> m_aabb_tree