libvcad_compilers — compiler classes#

class CompilerBase#
#include <compiler_base.h>

Subclassed by ColorInkjetCompiler, GCVFCompiler, MaterialInkjetCompiler, MyersonCompiler, SimulationCompiler, SlicerProjectCompiler, VatCompiler

Public Functions

void cancel()#
virtual void compile() = 0#
CompilerBase() = default#
void set_progress_callback(const std::function<void(double)> &progress_callback)#
virtual std::vector<std::string> supported_attributes() const = 0#
virtual ~CompilerBase() = default#

Protected Functions

bool is_cancelled() const#
void report_progress(double progress)#
void reset_cancel()#
void throw_if_cancelled() const#
void validate_attributes(const std::shared_ptr<Node> &root) const#

Protected Attributes

std::atomic<bool> m_cancelled = {false}#
std::function<void(double)> m_progress_callback = nullptr#
class MaterialInkjetCompiler : public CompilerBase#
#include <material_inkjet_compiler.h>

Public Functions

virtual void compile() override#
std::unordered_map<uint8_t, size_t> material_voxel_counts() const#
MaterialInkjetCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_directory, const std::string &file_prefix, const std::shared_ptr<MaterialDefs> &material_defs, double liquid_keep_out_distance = 0.0)#
std::tuple<size_t, size_t, size_t> resolution() const#
void set_fallback_material_id(uint8_t material_id)#

Sets the fallback material ID used for voxels where VOLUME_FRACTIONS is undefined.

Only used when strict mode is off.

Parameters:

material_id – The fallback material ID (default is 0, the void material).

void set_strict_mode(bool strict)#

Enables or disables strict mode.

When strict mode is on, the compiler throws a std::runtime_error if any inside voxel is missing the required VOLUME_FRACTIONS attribute. When off (default), the fallback material is used instead.

virtual std::vector<std::string> supported_attributes() const override#

Private Members

uint8_t m_fallback_material_id = 0#
std::string m_file_prefix#
double m_liquid_keep_out_distance#
std::shared_ptr<MaterialDefs> m_material_defs#
std::unordered_map<uint8_t, size_t> m_material_voxel_counts#
std::string m_output_directory#
std::shared_ptr<Node> m_root#
bool m_strict_mode = false#
glm::vec3 m_voxel_size#
size_t m_x_resolution = 0#
size_t m_y_resolution = 0#
size_t m_z_resolution = 0#
class ColorInkjetCompiler : public CompilerBase#
#include <color_inkjet_compiler.h>

Public Functions

ColorInkjetCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_directory, const std::string &file_prefix, const std::string &icc_profile = "default")#
virtual void compile() override#
std::tuple<size_t, size_t, size_t> resolution() const#
void set_fallback_color(glm::vec4 color)#

Sets the fallback RGBA color used for voxels where COLOR_RGBA is undefined.

Each component is in [0, 1]. Only used when strict mode is off.

Parameters:

color – The fallback sRGBA color (default is fully transparent: 0,0,0,0).

void set_strict_mode(bool strict)#

Enables or disables strict mode.

When strict mode is on, the compiler throws a std::runtime_error if any inside voxel is missing the required COLOR_RGBA attribute. When off (default), the fallback color is used instead.

virtual std::vector<std::string> supported_attributes() const override#

Private Members

glm::vec4 m_fallback_color = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)#
std::string m_file_prefix#
std::string m_icc_profile#
std::string m_output_directory#
std::shared_ptr<Node> m_root#
bool m_strict_mode = false#
glm::vec3 m_voxel_size#
size_t m_x_resolution = 0#
size_t m_y_resolution = 0#
size_t m_z_resolution = 0#
class VatCompiler : public CompilerBase#
#include <vat_compiler.h>

Generates grayscale BMP slice stacks for vat-photo style printers.

This compiler consumes the scalar INTENSITY attribute in [0, 1] and maps it directly to 8-bit grayscale output. It can either sample the model bounding box or a fixed printer-volume XY canvas with the model centered in XY.

Public Functions

virtual void compile() override#
std::tuple<size_t, size_t, size_t> resolution() const#

Returns the compiled slice resolution as (x, y, z_layers).

void set_fallback_intensity(double intensity)#

Sets the fallback intensity used when INTENSITY is undefined.

The stored value is clamped into [0, 1].

void set_strict_mode(bool strict)#

Enables or disables strict mode for missing INTENSITY samples.

virtual std::vector<std::string> supported_attributes() const override#
VatCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_directory, const std::string &file_prefix)#

Samples only the model bounding box.

VatCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, glm::vec3 printer_volume, const std::string &output_directory, const std::string &file_prefix)#

Samples a fixed printer-volume XY domain with centered XY placement.

Private Functions

double resolve_intensity(const glm::vec3 &voxel_pos, const std::optional<AttributeSamples> &samples) const#
glm::vec3 world_position(long x, long y, long z, const glm::vec3 &bbox_min, const glm::vec3 &center_offset) const#

Private Members

double m_fallback_intensity = 1.0#
std::string m_file_prefix#
std::string m_output_directory#
glm::vec3 m_printer_volume = glm::vec3(0.0f)#
std::shared_ptr<Node> m_root#
bool m_strict_mode = false#
bool m_use_printer_volume = false#
glm::vec3 m_voxel_size#
size_t m_x_resolution = 0#
size_t m_y_resolution = 0#
size_t m_z_resolution = 0#
class SlicerProjectCompiler : public CompilerBase#
#include <slicer_project_compiler.h>

Compiles an OpenVCAD node tree into a PrusaSlicer-compatible 3MF project.

The compiler supports two modes of attribute handling, selected automatically based on the attribute registry:

Settings Mesh (Mode 1): Attributes that map to a PrusaSlicer per-volume metadata key (e.g. infill_density -> fill_density). Regions are carved from the geometry and each region receives the appropriate metadata value. No printer/filament profiles are needed.

Virtual Extrusion (Mode 2): Attributes that must be controlled via G-code (e.g. temperature). The geometry is segmented into synthetic extruders and toolchange G-code is injected into the printer profile. Requires printer and filament profile paths.

Attributes present on the tree that are not in the registry are printed to the console and ignored. If no supported attributes are found, a std::runtime_error is thrown.

Public Functions

virtual void compile() override#
SlicerProjectCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_file_path, size_t num_regions = 10, const std::string &printer_profile_path = "", const std::string &filament_profile_path = "")#

Constructor.

Parameters:
  • root – Root node of the prepared tree.

  • voxel_size – Sampling resolution.

  • output_file_path – Path for the output .3mf file.

  • num_regions – Number of sub-ranges per attribute dimension. Defaults to 10.

  • printer_profile_path – Path to PrusaSlicer printer profile (.ini). Required only when virtual extrusion attributes are present. Defaults to “” (none).

  • filament_profile_path – Path to PrusaSlicer filament profile (.ini). Required only when virtual extrusion attributes are present. Defaults to “” (none).

virtual std::vector<std::string> supported_attributes() const override#

Returns all attribute names the compiler knows how to handle.

This is a discovery API — it returns every attribute the registry supports (settings-mesh keys, virtual-extrusion primaries, and companion attributes). The compiler does not require all of them to be present on the tree; it operates on whichever supported attributes it finds.

Private Functions

size_t add_extruder(int primary_value, const std::unordered_map<std::string, int> &companion_values)#

Registers an extruder (temperature + companion values) and returns its index.

Reuses existing entries with matching primary value.

std::string build_model_config(const std::unordered_map<std::string, std::pair<double, double>> &min_max_map, std::shared_ptr<SurfaceMesh> &main_mesh)#

Builds the Slic3r_PE_model.config XML string.

Generates segmented meshes, creates volume elements with settings-mesh metadata and/or extruder assignments.

Parameters:
  • min_max_map – Global attribute min/max ranges.

  • main_mesh – [out] The merged surface mesh.

Returns:

The XML string for the model config attachment.

std::string build_project_config()#

Builds the Slic3r_PE.config string (patched printer profile with toolchange G-code).

Returns:

The formatted project config string.

void classify_attributes(const std::vector<std::string> &tree_attributes)#

Classifies tree attributes into settings-mesh, virtual-extrusion, companion, or unsupported.

std::unordered_map<std::string, std::pair<double, double>> compute_attribute_ranges()#

Computes min/max ranges for every segmented attribute from the sampled voxel array.

double compute_companion_average(const std::string &primary_attribute, double range_min, double range_max, const std::string &companion_attribute) const#

Computes the average value of a companion attribute within samples whose primary attribute falls in [range_min, range_max].

vtkSmartPointer<vtkImageData> compute_filtered_image_data(const std::unordered_map<std::string, std::pair<double, double>> &attribute_ranges_map)#

Filters the sampled SDF to only include voxels whose attributes fall within the given sub-ranges.

std::string derive_object_name() const#

Derives an object name from the output file path.

Private Members

std::vector<ExtruderEntry> m_extruders#
std::string m_filament_profile_path#
glm::vec3 m_max_coord = {0.0f}#
glm::vec3 m_min_coord = {0.0f}#
size_t m_num_regions#
std::string m_output_file_path#
std::string m_printer_profile_path#
std::shared_ptr<Node> m_root#
std::vector<std::pair<std::optional<double>, std::optional<AttributeSamples>>> m_sample_array#
std::vector<std::string> m_segmented_attributes#
std::vector<const SettingsMeshDescriptor*> m_settings_mesh_active#
size_t m_size_x = 0#
size_t m_size_y = 0#
size_t m_size_z = 0#
bool m_uses_virtual_extrusion = false#
std::vector<const VirtualExtrusionDescriptor*> m_virtual_extrusion_active#
glm::vec3 m_voxel_size#

Private Static Functions

static std::string expand_gcode_template(const VirtualExtrusionDescriptor &descriptor, int primary_value, const std::unordered_map<std::string, int> &companion_values)#

Expands a G-code template for a specific region.

Parameters:
  • descriptor – The virtual-extrusion descriptor.

  • primary_value – Mid-range value of the primary attribute.

  • companion_valuesMap of companion name -> averaged int value.

Returns:

The fully expanded G-code string.

struct ExtruderEntry#

Public Members

std::unordered_map<std::string, int> companion_values#
int primary_value#