Utilities#

class MaterialDefs#
#include <material_defs.h>

Class representing material definitions that translates between material names, colors, and ids.

Public Functions

glm::vec4 color(const std::string &name) const#

Returns the color of the material given the name.

Parameters:

name – The name of the material

glm::vec4 color(uint8_t material) const#

Returns the color of the material given the id.

Parameters:

material – The id of the material

bool contains(const std::string &name) const#

Returns true if the material exists.

Parameters:

name – The name of the material

nlohmann::json get_raw_settings(const std::string &name) const#
uint8_t id(const std::string &name) const#

Returns the id of the material given the name.

Parameters:

name – The name of the material

uint8_t id(glm::vec4 color) const#

Returns the id of the material given the color.

Parameters:

color – The color of the material

MaterialDefs()#

Default constructor. Initializes empty definition with only void space.

MaterialDefs(const std::string &path)#

Constructor that takes a string.

Parameters:

path – The path to the material configuration file

std::string name(uint8_t material) const#

Returns the name of the material given the id.

Parameters:

material – The id of the material

size_t num_materials() const#

Returns the number of materials.

Returns:

The number of materials

std::vector<glm::vec4> palette() const#

Returns a list of colors that are in the floating point range [0, 1].

Returns:

A list of 4-component colors (RGBA) that are in the floating point range [0, 1]

std::vector<glm::vec4> prescaled_color_list() const#

Returns a list of colors that are prescaled to the range [0, 255].

Returns:

A list of 4-component colors (RGBA) that are prescaled to the range [0, 255]

void update_color(uint8_t id, glm::vec4 color)#

Updates the color of the material given the id.

Parameters:
  • id – The id of the material

  • color – The new color of the material (RGBA)

Private Members

std::vector<glm::vec4> m_id_to_color_lookup#
nlohmann::json m_materials#
namespace MaterialExceptions#
struct MaterialNotFound : public std::exception#
#include <material_defs.h>

Public Functions

inline MaterialNotFound(const std::string &message)#
inline const char *what()#

Public Members

std::string m_message#
class ColorMap#
#include <color_map.h>

Public Functions

void add_color(double value, const glm::vec3 &color)#
ColorMap() = default#
glm::vec3 get_color(double value) const#

Public Static Functions

static ColorMap create_grayscale()#
static ColorMap create_inferno()#
static ColorMap create_plasma()#
static ColorMap create_viridis()#

Private Members

std::map<double, glm::vec3> m_color_points#
class TreeSampler#
#include <tree_sampler.h>

Public Types

typedef std::function<void(int)> ProgressCallback#

Public Functions

std::vector<float> as_float_array(const std::string &attribute, ProgressCallback progress = nullptr)#
std::vector<uint8_t> as_rgba_array(const std::string &attribute, const std::shared_ptr<ColorMap> &color_map, bool blend = true, ProgressCallback progress = nullptr)#
std::vector<std::pair<std::optional<double>, std::optional<AttributeSamples>>> as_sample_array(const ProgressCallback &progress = nullptr)#
std::vector<float> as_signed_distance_array(const ProgressCallback &progress = nullptr)#
std::vector<glm::vec3> as_vec3_array(const std::string &attribute, ProgressCallback progress = nullptr)#
std::vector<glm::vec4> as_vec4_array(const std::string &attribute, ProgressCallback progress = nullptr)#
void clear_double_attribute_range_override()#
std::pair<double, double> get_double_attribute_min_max() const#
std::tuple<size_t, size_t, size_t> sample_dimensions()#
std::vector<Node::TreeSample> sample_points(const std::vector<glm::vec3> &points, ProgressCallback progress = nullptr)#
std::vector<glm::vec3> sample_points_to_colors(std::vector<glm::vec3> &points, const std::string &attribute, const std::shared_ptr<ColorMap> &color_map, bool blend = true, ProgressCallback progress = nullptr)#
std::vector<float> sample_points_to_float_array(std::vector<glm::vec3> &points, const std::string &attribute, ProgressCallback progress = nullptr)#
std::vector<glm::vec3> sample_points_to_vec3_array(std::vector<glm::vec3> &points, const std::string &attribute, ProgressCallback progress = nullptr)#
std::vector<glm::vec4> sample_points_to_vec4_array(std::vector<glm::vec3> &points, const std::string &attribute, ProgressCallback progress = nullptr)#
void set_double_attribute_range_override(double min_value, double max_value)#
void set_undefined_attribute_pattern_enabled(bool enabled)#

Enable or disable the undefined-attribute stripe pattern.

When enabled (the default), voxels/points inside geometry that are missing the selected attribute are rendered with a subtle world-space stripe pattern instead of plain gray.

TreeSampler(const std::shared_ptr<Node> &root, const glm::vec3 &voxel_size, const std::shared_ptr<MaterialDefs> &material_defs = nullptr)#

Private Functions

glm::vec4 color_for_sample(Attribute::Value sample, const std::shared_ptr<ColorMap> &color_map) const#
void compute_sample_dimensions()#
void compute_voxel_min_max(const std::string &attribute)#
void sample_signed_distance_field(const ProgressCallback &progress = nullptr)#
void sample_voxel_grid(const ProgressCallback &progress = nullptr)#

Private Members

std::vector<SampleResult> m_attribute_samples#
glm::vec3 m_bbox_max#
glm::vec3 m_bbox_min#
tbb::task_group_context m_context#
double m_dbl_attribute_max = std::numeric_limits<double>::min()#
double m_dbl_attribute_min = std::numeric_limits<double>::max()#
double m_dbl_attribute_override_max = 1.0#
double m_dbl_attribute_override_min = 0.0#
bool m_has_dbl_attribute_range_override = false#
std::shared_ptr<MaterialDefs> m_material_defs#
std::shared_ptr<SampleResult> m_points_samples#
std::shared_ptr<Node> m_root#
std::vector<std::pair<std::optional<double>, std::optional<AttributeSamples>>> m_sample_array#
bool m_show_undefined_attribute_pattern = true#
std::vector<float> m_signed_distance_field#
size_t m_size_x#
size_t m_size_y#
size_t m_size_z#
tbb::enumerable_thread_specific<std::shared_ptr<Node>> m_thread_local_roots#
bool m_use_blending = true#
glm::vec3 m_voxel_size#

Private Static Functions

static glm::vec4 BlendDistribution(const Attribute::VolumeFractionMapPtr &distribution, const std::shared_ptr<MaterialDefs> &material_defs)#
static std::optional<Attribute::Value> FuzzySampleAttribute(const std::shared_ptr<Node> &root, const glm::vec3 &p, const glm::vec3 &voxel_size, const std::string &attribute)#
static glm::vec4 UndefinedStripeColor(const glm::vec3 &world_pos, float stripe_period, float alpha)#
static void UpdateProgress(size_t &local_count, std::atomic<size_t> &global_count, const size_t &total_voxels, const ProgressCallback &progress, std::mutex &progress_mutex)#
struct SampleResult#

Public Members

bool inside = false#
std::optional<AttributeSamples> samples#
std::optional<double> sdf#
class ExpressionEvaluator#
#include <expression_evaluator.h>

A class to evaluate mathematical expressions.

This class uses the exprtk library to evaluate mathematical expressions. The class can compile a function and evaluate it with a set of variables. The variables are passed in as a map of variable names to pointers to double values.

Note

This class is thread NOT safe.

Public Functions

bool compile(const std::string &function, const std::unordered_map<std::string, double*> &variables)#

compiles a function with a set of variables

Parameters:
  • function – The function to compile

  • variables – A map of variable names to pointers to double values

Returns:

True if the function compiled successfully, false otherwise

std::string error()#
double evaluate()#

Evaluates the compiled function.

Returns:

The result of the function

ExpressionEvaluator()#

Default constructor.

double *getVariable(const std::string &name)#
void setVariable(const std::string &name, double value)#

Private Members

bool m_compiled = false#
exprtk::expression<double> m_expression#
std::string m_function#
exprtk::parser<double> m_parser#
exprtk::symbol_table<double> m_symbol_table#
std::unordered_map<std::string, double*> m_variables#
namespace MathUtils#

A namespace for mathematical utility functions.

Functions

std::pair<glm::vec3, glm::vec3> CombinedBBox(std::vector<std::pair<glm::vec3, glm::vec3>> bboxes)#

Computes the bounding box of a list of bounding boxes.

Note

If any of the bounding boxes are infinite, they are ignored

Note

If no bounding boxes are finite, the function returns an infinite bounding box

Note

If the vector is empty, the function returns [0,0,0] to [0,0,0]

Parameters:

bboxes – The list of bounding boxes

Returns:

The combined bounding box TODO: this function is used in the composition nodes. However it might be smarter to use a tighter bounding box depending on the operation (e.g. intersection, union, etc.)

int compute_new_material(const std::unordered_map<uint8_t, float> &probabilities, bool prob_mode)#

Computes the new material based on the probabilities.

Parameters:
  • probabilities – A map of material IDs to probabilities

  • prob_mode – Whether to use probability mode or threshold mode

Returns:

The new material ID

void FilterNearlyCollinearPoints(std::vector<Point_2> &points, double epsilon)#
std::pair<glm::vec3, glm::vec3> IntersectedBBox(std::vector<std::pair<glm::vec3, glm::vec3>> bboxes)#

Computes the intersected bounding box of a list of bounding boxes.

Parameters:

bboxes – The list of bounding boxes

Returns:

The intersected bounding box

bool IsNearlyCollinear(const glm::vec2 &point1, const glm::vec2 &point2, const glm::vec2 &point3, double epsilon)#

Checks if three 2D points are nearly collinear.

Uses the area of the triangle formed by the points to determine collinearity

Parameters:
  • point1 – The first point

  • point2 – The second point

  • point3 – The third point

  • epsilon – The epsilon value

Returns:

True if the points are nearly collinear, false otherwise

bool IsNearlyCollinear(const Point_2 &point1, const Point_2 &point2, const Point_2 &point3, double epsilon)#
template<typename T>
T tet_interpolate(const glm::vec4 &bary_coords, const T &a, const T &b, const T &c, const T &d)#

Interpolates a value using barycentric coordinates.

Parameters:
  • bary_coords – The barycentric coordinates

  • a – The value at the first vertex

  • b – The value at the second vertex

  • c – The value at the third vertex

  • d – The value at the fourth vertex

Returns:

The interpolated value

float tet_volume(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c, const glm::vec3 &d)#

Computes the volume of a tetrahedron.

Parameters:
  • a – The first vertex of the tetrahedron

  • b – The second vertex of the tetrahedron

  • c – The third vertex of the tetrahedron

  • d – The fourth vertex of the tetrahedron

Returns:

The volume of the tetrahedron

class Random#
#include <random.h>

Public Functions

double random_double(double min, double max)#
int random_int(int min, int max)#
void reseed(int seed)#

Public Static Functions

static Random *getInstance()#
static uint8_t Weighted3ComponentSample(double a, double b, double c)#
static uint8_t Weighted5ComponentSample(double a, double b, double c, double d, double e)#
static size_t WeightedMaterialSample(const std::unordered_map<uint8_t, double> &materials_with_weights)#
static size_t WeightedMaterialSample(const std::unordered_map<uint8_t, float> &materials_with_weights)#
static size_t WeightedSample(const std::vector<double> &weights)#

Private Functions

Random()#

Private Static Attributes

static Random *m_instance#

Functions

inline std::string report_version()#

Defines

GLM_ENABLE_EXPERIMENTAL#
template<typename Key, typename Value>
class LRUCache#
#include <lru_cache.h>

A simple, thread-local Least Recently Used (LRU) cache for storing generic values keyed by 3D integer coordinates.

This is used by nodes like Convolve that need to sample a neighborhood of points. By caching the results, we avoid making redundant, expensive sample() calls to child nodes. Because TreeSampler clones roots per thread, this cache does not need internal mutexes.

Public Functions

inline void clear()#

Clears all entries from the cache.

inline std::optional<Value> get(const Key &key)#

Retrieves a value from the cache.

Parameters:

key – The key to look up.

Returns:

An optional containing the value if found, or std::nullopt if not.

inline explicit LRUCache(size_t capacity)#

Constructs the cache with a specified maximum capacity.

Parameters:

capacity – The maximum number of items the cache can hold before evicting the oldest.

inline void put(const Key &key, const Value &value)#

Inserts a value into the cache.

Parameters:
  • key – The key to associate with the value.

  • value – The value to cache.

inline size_t size() const#

Returns the current number of items in the cache.

Private Members

std::list<std::pair<Key, Value>> m_cache_list#
std::unordered_map<Key, typename std::list<std::pair<Key, Value>>::iterator> m_cache_map#
size_t m_capacity#

Defines

STBIWDEF#

Typedefs

typedef void stbi_write_func(void *context, void *data, int size)#

Functions

void stbi_flip_vertically_on_write(int flip_boolean)#
int stbi_write_bmp(char const *filename, int w, int h, int comp, const void *data)#
int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data)#
int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data)#
int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const float *data)#
int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality)#
int stbi_write_jpg_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data, int quality)#
int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes)#
int stbi_write_png_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data, int stride_in_bytes)#
int stbi_write_tga(char const *filename, int w, int h, int comp, const void *data)#
int stbi_write_tga_to_func(stbi_write_func *func, void *context, int w, int h, int comp, const void *data)#

Variables

int stbi_write_force_png_filter#
int stbi_write_png_compression_level#
int stbi_write_tga_with_rle#
namespace VolumetricDithering#