libvcad_compilers — compiler classes#

class CompilerBase#
#include <compiler_base.h>

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

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#

Enums

enum class ColorInkjetExportMode#

Values:

enumerator stochastic#
enumerator dithered_3d#
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", ColorInkjetExportMode export_mode = ColorInkjetExportMode::stochastic, ColorPipelineOptions color_pipeline_options = ColorPipelineOptions())#
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 Functions

void compile_dithered_3d()#
void compile_stochastic()#

Private Members

ColorPipelineOptions m_color_pipeline_options#
ColorInkjetExportMode m_export_mode = ColorInkjetExportMode::stochastic#
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_base.h>

Shared base for slicer project compilers.

This base owns the prepared OpenVCAD tree, output path, sampled voxel grid, and common helpers used by concrete slicer project dialects. Instantiate PrusaSlicerProjectCompiler or FullSpectrumSlicerProjectCompiler instead.

Subclassed by FullSpectrumSlicerProjectCompiler, PrusaSlicerProjectCompiler

Public Functions

virtual void compile() override = 0#
virtual std::vector<std::string> supported_attributes() const override = 0#
~SlicerProjectCompiler() override = default#

Protected Functions

std::string derive_object_name() const#

Derives an object name from the output file path.

void sample_tree()#

Samples the root tree and populates shared grid state.

SlicerProjectCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_file_path)#

Protected Attributes

glm::vec3 m_max_coord = {0.0f}#
glm::vec3 m_min_coord = {0.0f}#
std::string m_output_file_path#
std::shared_ptr<Node> m_root#
std::vector<std::pair<std::optional<double>, std::optional<AttributeSamples>>> m_sample_array#
size_t m_size_x = 0#
size_t m_size_y = 0#
size_t m_size_z = 0#
glm::vec3 m_voxel_size#
class PrusaSlicerProjectCompiler : public SlicerProjectCompiler#
#include <slicer_project_prusa.h>

Compiles slicer attributes into a PrusaSlicer-compatible 3MF project.

Supports settings-mesh metadata, virtual-extrusion G-code, and PrusaSlicer ColorMix workflows in the Slic3r/Prusa project dialect.

Public Functions

virtual void compile() override#
PrusaSlicerProjectCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_file_path, const PrusaSlicerProjectSettings &settings)#
PrusaSlicerProjectCompiler(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 = "")#
virtual std::vector<std::string> supported_attributes() const override#

Private Functions

size_t add_extruder(int primary_value, const std::unordered_map<std::string, int> &companion_values)#
std::string build_color_mix_config_json(const std::vector<PrusaColorMixPaletteEntry> &palette) const#
std::string build_color_mix_model_config(const std::vector<PrusaColorMixMeshRegion> &regions, std::shared_ptr<SurfaceMesh> &main_mesh) const#
std::string build_color_mix_project_config(const PrusaColorMixSettings &color_mix_settings) const#
PrusaColorMixSettings build_color_mix_settings(bool use_volume_fractions) const#
std::string build_model_config(const std::unordered_map<std::string, std::pair<double, double>> &min_max_map, std::shared_ptr<SurfaceMesh> &main_mesh)#
std::string build_project_config()#
void classify_attributes(const std::vector<std::string> &tree_attributes)#
void compile_color_mix(bool use_volume_fractions)#
std::unordered_map<std::string, std::pair<double, double>> compute_attribute_ranges()#
vtkSmartPointer<vtkImageData> compute_band_sdf_image(const std::unordered_map<std::string, std::pair<double, double>> &attribute_ranges_map)#
double compute_companion_average(const std::string &primary_attribute, double range_min, double range_max, const std::string &companion_attribute) const#

Private Members

std::vector<ExtruderEntry> m_extruders#
std::string m_filament_profile_path#
size_t m_num_regions#
std::string m_printer_profile_path#
std::vector<std::string> m_segmented_attributes#
PrusaSlicerProjectSettings m_settings#
std::vector<const SettingsMeshDescriptor*> m_settings_mesh_active#
bool m_uses_virtual_extrusion = false#
std::vector<const VirtualExtrusionDescriptor*> m_virtual_extrusion_active#

Private Static Functions

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

Public Members

std::unordered_map<std::string, int> companion_values#
int primary_value#
struct PrusaSlicerProjectSettings#
#include <slicer_project_prusa.h>

Options for PrusaSlicer settings-mesh, virtual-extrusion, and ColorMix export.

Public Members

std::vector<PrusaColorMixPhysicalFilament> color_mix_filaments#
PrusaColorMixRecipePreset color_mix_recipe_preset = PrusaColorMixRecipePreset::Expanded#
double direct_physical_delta_e = 1.0#
bool enable_color_mix = false#
std::string filament_profile_path#
std::string material_defs_path#
size_t max_palette_size = 32#
size_t max_recipe_components = 3#
int min_component_percent = 15#
size_t num_regions = 10#
std::string printer_profile_path#
double region_overlap_mm = 0.2#
size_t total_physical_extruders = 5#
std::vector<PrusaColorMixMaterialMapping> volume_fraction_materials#
class FullSpectrumSlicerProjectCompiler : public SlicerProjectCompiler#
#include <slicer_project_full_spectrum.h>

Compiles COLOR_RGB or VOLUME_FRACTIONS into an Orca FullSpectrum project.

Writes the Bambu/Orca component-based 3MF dialect with physical and virtual FullSpectrum mixed-filament assignments.

Public Functions

virtual void compile() override#
FullSpectrumSlicerProjectCompiler(const std::shared_ptr<Node> &root, glm::vec3 voxel_size, const std::string &output_file_path, const FullSpectrumSlicerProjectSettings &settings)#
virtual std::vector<std::string> supported_attributes() const override#

Private Functions

std::vector<FullSpectrumPaletteEntry> build_full_spectrum_palette() const#
std::string build_full_spectrum_project_config(const std::vector<FullSpectrumPaletteEntry> &palette) const#
std::vector<FullSpectrumMeshRegion> build_full_spectrum_regions(const std::vector<FullSpectrumPaletteEntry> &palette)#
std::vector<FullSpectrumPaletteEntry> build_full_spectrum_volume_fraction_palette() const#
vtkSmartPointer<vtkImageData> compute_full_spectrum_region_sdf_image(const std::vector<FullSpectrumPaletteEntry> &palette, size_t region_index) const#
void validate_full_spectrum_settings() const#

Private Members

FullSpectrumSlicerProjectSettings m_settings#
struct FullSpectrumMeshRegion#

Public Members

int extruder_id = 0#
std::shared_ptr<SurfaceMesh> mesh#
std::string name#
struct FullSpectrumPaletteEntry#

Public Members

int extruder_id = 0#
std::vector<double> fraction_weights#
FullSpectrumLab preview_lab#
FullSpectrumRecipe recipe#
size_t sample_count = 0#
FullSpectrumRgb8 target_color#
FullSpectrumLab target_lab#
struct FullSpectrumSlicerProjectFilament#
#include <slicer_project_full_spectrum.h>

Physical filament slot description for Orca FullSpectrum export.

Public Members

std::string color_hex#
std::string filament_id#
std::string filament_profile_path#
std::string filament_settings_id#
double nozzle_diameter_mm = 0.4#
unsigned int slot = 0#
struct FullSpectrumSlicerProjectMaterialMapping#
#include <slicer_project_full_spectrum.h>

Maps a VCAD volume-fraction material to a physical filament slot.

Public Members

uint8_t material_id = 0#
std::string material_name#
unsigned int slot = 0#
struct FullSpectrumSlicerProjectSettings#
#include <slicer_project_full_spectrum.h>

Options for COLOR_RGB or VOLUME_FRACTIONS to Orca FullSpectrum project export.

Public Members

std::string base_project_settings_path#
double direct_physical_delta_e = 1.0#
std::string material_defs_path#
size_t max_palette_size = 32#
size_t max_recipe_components = 5#
int min_component_percent = 15#
std::string orca_default_filament_profile_path#
std::string orca_machine_profile_path#
std::string orca_process_profile_path#
std::vector<std::string> orca_profile_search_paths#
std::vector<FullSpectrumSlicerProjectFilament> physical_filaments#
double region_overlap_mm = 0.2#
std::vector<FullSpectrumSlicerProjectMaterialMapping> volume_fraction_materials#