Compilers — writers

class CrossSectionSlicer
#include <cross_section_slicer.h>

A class for slicing a VCAD design into cross-sections.

This class provides methods to slice a VCAD design into cross-sections. This includes slicing the geometry and materials of the design into 2D polygons.

Public Functions

CrossSectionSlicer(std::shared_ptr<Node> root, glm::vec3 min, glm::vec3 max, glm::vec3 voxel_size)

Constructor.

Parameters:
  • root – The root node of the VCAD design tree.

  • min – The minimum corner of the bounding box of the design.

  • max – The maximum corner of the bounding box of the design.

  • voxel_size – The size of the voxels used to discretize the design.

std::vector<Polygon2> slice_geometry(double z_height, double stitching_tolerance = 1e-12, double colinear_tolerance = 1e-12)

Slice the geometry of the design at a given z-height.

Parameters:
  • z_height – The z-height to slice the geometry at.

  • stitching_tolerance – The tolerance to use when stitching the iso-lines into polygons.

  • colinear_tolerance – The tolerance to use when simplifying the polygons by removing co-linear points

Returns:

A vector of polygons representing the geometry at the given z-height.

std::vector<std::tuple<double, double, std::vector<Polygon2>>> slice_material(double z_height, uint8_t material_chan, const std::vector<std::pair<double, double>> ranges, double stitching_tolerance = 1e-12, double colinear_tolerance = 1e-12)

Slice the material of the design at a given z-height.

This method slices the material of the design at a given z-height and returns the ranges of the material values. This returns the outlines of regions of the material concentration.

Parameters:
  • z_height – The z-height to slice the material at.

  • material_chan – The material channel to slice.

  • ranges – The ranges of the material values to slice.

  • stitching_tolerance – The tolerance to use when stitching the iso-lines into polygons.

  • colinear_tolerance – The tolerance to use when simplifying the polygons by removing co-linear points

Returns:

A vector of tuples containing the ranges of the material values and the polygons representing the material at the given z-height.

Private Functions

void takeCrossSectionAndInsertIntoArrangement(std::function<double(double, double, double)> &geometry_evaluator, std::function<std::unordered_map<uint8_t, float>(double, double, double)> &distribution_evaluator, size_t channel, double z_height, double iso_value, Arrangement2 &arrangement, double stitching_tolerance, double colinear_tolerance)

Take a cross-section of the geometry and insert it into an arrangement.

Parameters:
  • gradient_evaluator – The function to evaluate the gradient at a given point.

  • z_height – The z-height to take the cross-section at.

  • iso_value – The iso-value to take the cross-section at.

  • arrangement – The arrangement to insert the cross-section into.

  • stitching_tolerance – The tolerance to use when stitching the iso-lines into polygons.

  • colinear_tolerance – The tolerance to use when simplifying the polygons by removing co-linear points

Private Members

glm::vec3 m_max
glm::vec3 m_min
std::shared_ptr<Node> m_root
glm::vec3 m_voxel_size

Private Static Functions

static void ClassifyFaces(const std::vector<Polygon2> &faces, const std::vector<Polygon2> &geometry, const std::function<double(double, double, double)> &exact_gradient_evaluator, double z_height, std::vector<std::tuple<double, double, std::vector<Polygon2>>> &ranges)

Classify the faces as inside, outside, and into a range.

Parameters:
  • faces – The faces to classify.

  • geometry – The geometry to classify the faces against.

  • exact_gradient_evaluator – The function to evaluate the gradient at a given point. This method should be exact but (likely) slower.

  • z_height – The z-height to classify the faces at.

  • ranges – The ranges to classify the faces into.

static std::vector<Polygon2> CorrectPolygonOrientation(const std::vector<Polygon2> polygons)

Correct the orientation of the polygons to ensure they follow the even-odd rule.

This method corrects the orientation of the polygons to ensure they follow the even-odd rule. This is necessary for the polygons to be used in the arrangement.

Parameters:

polygons – The polygons to correct the orientation of.

Returns:

The corrected polygons.

static Point_2 FindPointInPolygon(const Polygon2 &polygon)

Find a point inside a polygon.

This method finds a point inside a polygon by first checking the centroid. If that fails, it checks random points until it finds one inside the polygon.

Throws:

std::runtime_error – if a point cannot be found inside the polygon after 10,000 attempts

Parameters:

polygon – The polygon to find a point inside.

Returns:

A point inside the polygon.

static bool IsExtraGeometry(const Polygon2 &face, const std::vector<Polygon2> &org_geometry)

Check if a face is extra geometry.

This method checks if a face is extra geometry by checking if the face is inside any of the polygons in the geometry.

Parameters:
  • face – The face to check.

  • org_geometry – The geometry to check if the face is inside.

Returns:

True if the face is extra geometry, false otherwise.

static bool IsFaceInsideGeometry(const Polygon2 &face, const std::vector<Polygon2> &org_geometry)

Check if a face is inside the geometry.

This method checks if a face is inside the geometry by checking if the face is inside any of the polygons in the geometry.

Parameters:
  • face – The face to check.

  • org_geometry – The geometry to check if the face is inside.

Returns:

True if the face is inside the geometry, false otherwise.

static bool PointInsideAnyPolygon(const Point_2 &point, const std::vector<Polygon2> &polygons)
class InpWriter
#include <inp_writer.h>

Public Functions

InpWriter()
void write(const std::string &path, const std::shared_ptr<Node> root, vec3 voxel_size, const std::string &config_path, bool use_volumetric_dither)
struct IndexedPoint

Public Members

long long index
double x
double y
double z
class VTPCompiler
#include <vtp_compiler.h>

Public Functions

std::tuple<double, double, double> compute_vtp_parameters(glm::vec3 start_pt, glm::vec3 end_pt) const
std::tuple<double, double, double> compute_vtp_parameters(glm::vec3 start_pt, glm::vec3 end_pt, const std::unordered_map<uint8_t, float> &distribution) const
std::tuple<double, double, double> compute_vtp_parameters(glm::vec3 start_pt, glm::vec3 end_pt, double v_star, double h_star) const
std::pair<double, double> resolve_v_star_h_star(const std::unordered_map<uint8_t, float> &distribution) const
VTPCompiler(const std::shared_ptr<Node> &root, const std::shared_ptr<MaterialDefs> &material_defs, double nozzle_diameter, double filament_diameter, double alpha, double edot, double layer_height)

Private Members

double m_alpha
double m_edot
double m_filament_diameter
double m_layer_height
std::shared_ptr<MaterialDefs> m_material_defs
double m_nozzle_diameter
std::shared_ptr<Node> m_root