Tree — material
Material grading, blending, and convolution nodes.
-
class Convolution : public Unary
- #include <convolution.h>
A node that applies a convolution kernel to the material of the child node.
The convolution kernel is a 3D matrix of integers. When evaluated, the kernel is multiplied by the neighbors of the current voxel. The result is then used to determine the new material of the voxel using a weighted stochastic process. The weights are determined by the values of the kernel. The voxel sizes is needed to determine the neighbors of the current voxel, but in theory does not have to match the voxel size of the sample space if you are fine with down sampling on the convolution.
Note
The kernel must be odd in all dimensions.
Note
The node runs in O(kx * ky * kz) time, where kx, ky, and kz are the dimensions of the kernel.
Note
This node is unary and must have a single child.
Public Types
-
typedef std::vector<std::vector<std::vector<size_t>>> Kernel
A 3D matrix of integers is the kernel.
Public Functions
-
Convolution()
Default constructor, uses.
Constructor with child.
- Parameters:
kernel – The convolution kernel
child – The child node
-
virtual std::unordered_map<uint8_t, float> distribution(double x, double y, double z)
See also
-
virtual double evaluate(double x, double y, double z) final
See also
-
virtual std::vector<uint8_t> material_list() override
/see Node::material_list
Public Static Functions
-
static Kernel DefaultFlatKernel(int x, int y, int z)
Creates a kernel that averages all values.
This means all values are one including the center value.
- Parameters:
x – The x dimension of the kernel
y – The y dimension of the kernel
z – The z dimension of the kernel
- Returns:
The kernel
-
static Kernel DefaultPassKernel(int x, int y, int z)
Creates a kernel that passes all values through.
This means all values are zero except for the center value which is one.
- Parameters:
x – The x dimension of the kernel
y – The y dimension of the kernel
z – The z dimension of the kernel
- Returns:
The kernel
Private Functions
-
std::unordered_map<uint8_t, float> compute_convolved_distribution(double x, double y, double z)
-
int computeNewMaterial(std::unordered_map<uint8_t, float> &distribution)
Computes the new material of the voxel using a weighted stochastic process.
- Parameters:
distribution – a pointer to he distribution of materials, essentially the probability of each material. A sort of histogram. This is always MAX_MATERIALS size
- Returns:
The new material id
-
typedef std::vector<std::vector<std::vector<size_t>>> Kernel
-
class FGrade : public Unary
- #include <f_grade.h>
A node that applies grading functions to a child.
The grading functions are probability density functions that must all sum to 1 for any given point. The functions are evaluated and the material is chosen based on the discrete probability of the location in space. The syntax for the expressions must follow the same format as the Function class
See also
Function. The node has two mode:
Probability mode: The probability of each material is computed at a location in space and the material is chosen based on a stochastic process.
Threshold mode: The probability of each material is computed at a location in space and the material is chosen based on the highest.
Note
This node is unary and must have a single child.
Note
This node runs in O(n) time where n is tokens in the longest expression
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
-
FGrade()
Default constructor.
Constructor.
- Parameters:
functions – A list of function pointers that are probability density functions
materials – A list of materials that correspond to the expressions
prob_mode – If true, the node will run in probability mode. If false, the node will run in threshold mode.
child – The optional child node
Constructor.
- Parameters:
functions – A list of expressions that are probability density functions
materials – A list of materials that correspond to the expressions
prob_mode – If true, the node will run in probability mode. If false, the node will run in threshold mode.
child – The optional child node
-
virtual std::vector<uint8_t> material_list() override
See also
Private Functions
-
void prepare_evaluators()
Private Members
-
double m_d
-
std::vector<std::shared_ptr<ExpressionEvaluator>> m_evaluators
-
std::vector<std::string> m_function_strings
The expressions.
-
std::vector<std::function<double(double x, double y, double z, double rho, double phic, double r, double theta, double phis, double d)>> m_functions
-
std::vector<uint8_t> m_materials
The materials.
-
double m_phic
-
double m_phis
-
bool m_prepared = false
-
bool m_prob_mode = true
The mode.
-
double m_r
-
double m_rho
-
double m_theta
-
bool m_use_string_evaluators = true
-
double m_x
-
double m_y
-
double m_z
-
class Blend : public Unary
- #include <blend.h>
Public Functions
-
Blend(double radius)
-
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.
-
Blend(double radius)