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(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
namespace Samplers

Functions

void EvaluateFill(std::shared_ptr<Node> &node, double *out, glm::vec3 start, int nx, int ny, int nz, glm::vec3 voxel_size)
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)
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 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

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

Functions

glm::vec3 AdjustPrimaryColors(vec3 color)

A workaround to handle an edge case where primary colors dither incorrectly.

It adjusts the primary colors with a nonce to avoid this issue.

Parameters:

color – The color to adjust

Returns:

The adjusted color

void AdjustVoxel(Node::ColorGridType::Accessor &acc, openvdb::Coord coord, vec3 error)

Given a grid and coordinates, adjust the voxel at the coordinates by the error This function ensures that the voxel is within valid bounds (0-255).

Parameters:
  • grid – The grid to adjust

  • coord – The coordinates of the voxel to adjust

  • error – The error to adjust the voxel by

Node::GridType::Ptr CovnertColorGridToIndexGrid(const Node::ColorGridType::Ptr &color_grid, const Node::GridType::Ptr &alpha_grid, const std::vector<glm::vec4> &rgba_palette, vec3 dims)

Given a dithered color grid and color palette, convert the color grid to an index grid.

Parameters:
  • color_grid – The dithered color grid

  • alpha_grid – The alpha grid that corresponds to the color grid

  • rgba_palette – The color palette that the color grid was dithered to

  • dims – The dimensions of the grid

Node::ColorGridType::Ptr DitherIntoPalette(const Node::ColorGridType::Ptr &color_grid, const Node::GridType::Ptr &alpha_grid, const std::vector<glm::vec4> &rgba_palette, vec3 dims, bool use_full_volumetric_dithering = true)

Given a full color grid and color palette, dither the grid to use the palette.

This function uses the an adapted 3D Floyd-Steinberg dithering algorithm.

Parameters:
  • grid – The color grid to dither

  • alpha_grid – The alpha grid that corresponds to the color grid

  • palette – The color palette to dither to

  • dims – The dimensions of the grid