Geogram Version 1.9.7
A programming library of geometric algorithms
|
Implements CSG objects and instructions. More...
#include <geogram/mesh/mesh_CSG_builder.h>
Public Member Functions | |
virtual std::shared_ptr< Mesh > | square (vec2 size=vec2(1.0, 1.0), bool center=true) |
virtual std::shared_ptr< Mesh > | circle (double r=1.0, index_t nu=0) |
virtual std::shared_ptr< Mesh > | cube (vec3 size=vec3(1.0, 1.0, 1.0), bool center=true) |
virtual std::shared_ptr< Mesh > | sphere (double r=1.0) |
virtual std::shared_ptr< Mesh > | cylinder (double h=1.0, double r1=1.0, double r2=1.0, bool center=true) |
virtual std::shared_ptr< Mesh > | import (const std::filesystem::path &filename, const std::string &layer="", index_t timestamp=0, vec2 origin=vec2(0.0, 0.0), vec2 scale=vec2(1.0, 1.0)) |
virtual std::shared_ptr< Mesh > | surface (const std::filesystem::path &filename, bool center, bool invert) |
virtual std::shared_ptr< Mesh > | text (const std::string &text, double size=10.0, const std::string &font="", const std::string &halign="left", const std::string &valign="baseline", double spacing=1.0, const std::string &direction="ltr", const std::string &language="en", const std::string &script="latin") |
virtual std::shared_ptr< Mesh > | multmatrix (const mat4 &M, const CSGScope &scope) |
Groups several meshes into a single one and transforms them. | |
virtual std::shared_ptr< Mesh > | union_instr (const CSGScope &scope) |
Computes the union of two or more meshes. | |
virtual std::shared_ptr< Mesh > | intersection (const CSGScope &scope) |
Computes the intersection between two or more meshes. | |
virtual std::shared_ptr< Mesh > | difference (const CSGScope &scope) |
Computes the intersection between two meshes. | |
virtual std::shared_ptr< Mesh > | group (const CSGScope &scope) |
synonym for union. | |
virtual std::shared_ptr< Mesh > | color (vec4 color, const CSGScope &scope) |
Groups several meshes into a single one and sets their color. | |
virtual std::shared_ptr< Mesh > | hull (const CSGScope &scope) |
Computes the convex hull of several meshes. | |
virtual std::shared_ptr< Mesh > | linear_extrude (const CSGScope &scope, double height=1.0, bool center=false, vec2 scale=vec2(1.0, 1.0), index_t slices=0, double twist=0.0) |
Computes a 3D extrusion from a 2D shape. | |
virtual std::shared_ptr< Mesh > | rotate_extrude (const CSGScope &scope, double angle=360.0) |
Computes a 3D extrusion from a 2D shape. | |
virtual std::shared_ptr< Mesh > | projection (const CSGScope &scope, bool cut) |
Creates a 2D mesh from 3D mesh. | |
virtual std::shared_ptr< Mesh > | minkowski (const CSGScope &scope) |
Computes the Minkowski sum of meshes. | |
virtual std::shared_ptr< Mesh > | append (const CSGScope &scope) |
Appends all meshes in scope into a unique mesh, without testing for intersections. | |
void | add_object (const std::string &object, const ArgList &args) override |
void | begin_instruction () override |
void | end_instruction (const std::string &instruction, const ArgList &args) override |
void | add_square (const ArgList &args) override |
void | add_circle (const ArgList &args) override |
void | add_cube (const ArgList &args) override |
void | add_sphere (const ArgList &args) override |
void | add_cylinder (const ArgList &args) override |
void | add_polyhedron (const ArgList &args) override |
void | add_polygon (const ArgList &args) override |
void | add_import (const ArgList &args) override |
void | add_surface (const ArgList &args) override |
void | add_text (const ArgList &args) override |
void | eval_multmatrix (const ArgList &args) override |
void | eval_resize (const ArgList &args) override |
void | eval_union (const ArgList &args) override |
void | eval_intersection (const ArgList &args) override |
void | eval_difference (const ArgList &args) override |
void | eval_group (const ArgList &args) override |
void | eval_color (const ArgList &args) override |
void | eval_hull (const ArgList &args) override |
void | eval_linear_extrude (const ArgList &args) override |
void | eval_rotate_extrude (const ArgList &args) override |
void | eval_projection (const ArgList &args) override |
void | eval_minkowski (const ArgList &args) override |
void | eval_render (const ArgList &args) override |
void | set_delaunay (bool x) |
If set, compute constrained Delaunay triangulation in the intersected triangles. If there are intersections in coplanar facets, it guarantees uniqueness of their triangulation. Default is set. | |
void | set_detect_intersecting_neighbors (bool x) |
detect and compute intersections between facets that share a facet or an edge. Set to false if input is a set of conformal meshes. Default is set. | |
void | set_simplify_coplanar_facets (bool x, double angle_tolerance=0.0) |
Specifies whether coplanar facets should be simplified. | |
void | set_fast_union (bool x) |
Sets fast union mode. | |
void | set_noop (bool x) |
Sets noop mode. | |
![]() | |
AbstractCSGBuilder () | |
AbstractCSGBuilder constructor. | |
virtual | ~AbstractCSGBuilder () |
AbstractCSGBuilder destructor. | |
void | reset_defaults () |
Resets defaults value for fn, fs, fa. | |
void | set_fn (double fn) |
Sets the number of fragments. | |
void | set_fs (double fs) |
Sets the minimum size for a fragment. | |
void | set_fa (double fa) |
Sets the minimum angle for a fragment. | |
void | set_verbose (bool x) |
Displays (lots of) additional information. | |
void | set_detailed_verbose (bool x) |
Displays (even more) additional information. | |
bool | verbose () const |
Tests wheter verbose mode is set. | |
void | add_file_path (const std::filesystem::path &path) |
Adds a path to the file path. | |
void | reset_file_path () |
Resets the file path to its default value, with only the current directory ".". | |
void | push_file_path (const std::filesystem::path &path) |
Adds a path to the file path. | |
void | pop_file_path () |
Removes the latest pushed file path. | |
bool | is_object (const std::string &id) const |
bool | is_instruction (const std::string &id) const |
Static Public Member Functions | |
static Box3d | get_bbox (const std::shared_ptr< Mesh > &mesh) |
Computes the bounding box of a mesh. | |
static std::pair< vec3, vec3 > | get_bbox_bounds (const std::shared_ptr< Mesh > &mesh) |
Computes the bounding box of a mesh. | |
Protected Member Functions | |
std::shared_ptr< Mesh > | surface_with_OpenSCAD (const std::filesystem::path &filename, bool center, bool invert) |
std::shared_ptr< Mesh > | text_with_OpenSCAD (const std::string &text, double size=10.0, const std::string &font="", const std::string &halign="left", const std::string &valign="baseline", double spacing=1.0, const std::string &direction="ltr", const std::string &language="en", const std::string &script="latin") |
bool | find_file (std::filesystem::path &filename) |
Finds a file in the path. | |
const std::filesystem::path & | current_path () |
Gets the current path. | |
std::shared_ptr< Mesh > | import_with_openSCAD (const std::filesystem::path &filename, const std::string &layer="", index_t timestamp=0) |
For the file formats that are not supported by geogram, get help from OpenSCAD to convert them. | |
virtual void | do_CSG (std::shared_ptr< Mesh > &mesh, const std::string &boolean_expr) |
Apply a CSG operation to a mesh. | |
virtual void | triangulate (std::shared_ptr< Mesh > &mesh, const std::string &boolean_expr) |
Triangulates a 2D mesh. | |
virtual void | triangulate (std::shared_ptr< Mesh > &mesh) |
Triangulates a 2D mesh. | |
void | keep_z0_only (std::shared_ptr< Mesh > &M) |
keeps only triangles and vertices embedded in the z=0 plane, and makes the mesh 2D. | |
virtual void | finalize_mesh (std::shared_ptr< Mesh > &mesh) |
Derived classes may override this function and compute some cached information, e.g. bounding boxes, stored in the mesh. | |
CSGScope & | top_scope () |
void | push_scope () |
void | pop_scope () |
![]() | |
void | error (const char *str) |
void | error (const std::string &str) |
Protected Attributes | |
double | STL_epsilon_ |
index_t | max_arity_ |
bool | detect_intersecting_neighbors_ |
bool | delaunay_ |
bool | simplify_coplanar_facets_ |
double | coplanar_angle_tolerance_ |
bool | fast_union_ |
bool | noop_ |
std::shared_ptr< Mesh > | empty_mesh_ |
std::shared_ptr< Mesh > | result_ |
std::stack< CSGScope > | scope_stack_ |
![]() | |
double | fn_ |
double | fs_ |
double | fa_ |
std::vector< std::filesystem::path > | file_path_ |
bool | warnings_ |
bool | verbose_ |
bool | detailed_verbose_ |
std::map< std::string, csg_builder_func > | object_funcs_ |
std::map< std::string, csg_builder_func > | instruction_funcs_ |
Friends | |
class | CSGCompiler |
Additional Inherited Members | |
![]() | |
typedef GEOCSG::ArgList | ArgList |
typedef GEOCSG::Value | Value |
![]() | |
static constexpr double | DEFAULT_FA = 12.0 |
static constexpr double | DEFAULT_FS = 2.0 |
static constexpr double | DEFAULT_FN = 0.0 |
![]() | |
typedef std::function< void(const ArgList &args)> | csg_builder_func |
Implements CSG objects and instructions.
Can be used to construct volumes in C++ with a syntax very similar to OpenSCAD .csg files.
Definition at line 288 of file mesh_CSG_builder.h.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
Appends all meshes in scope into a unique mesh, without testing for intersections.
Prepares operand bits for a subsequent CSG operation.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
[in] | nu | number of fragments. If left unspecified, then it is deduced from radius and/or $fn variable. |
|
virtual |
Groups several meshes into a single one and sets their color.
[in] | color | the color, as r,g,b,a. |
ignored for now, just behaves as group().
|
inlineprotected |
Gets the current path.
Definition at line 598 of file mesh_CSG_builder.h.
Computes the intersection between two meshes.
If scope
contains more than two meshes, it computes the difference between the first mesh and the union of the rest.
[in] | scope | the meshes |
|
protectedvirtual |
Apply a CSG operation to a mesh.
Default implementation works in 2D (based on triangulate()) and does nothing in 3D (to be overriden by user). Each triangle has an "operand bit" indicating to which input operand it belongs to, set to (1u << operand_id).
[in,out] | mesh | the mesh |
[in] | boolean_expr | the operation to be applied
|
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
overridevirtual |
Reimplemented from GEO::AbstractCSGBuilder.
|
protected |
Finds a file in the path.
[in,out] | filename | the file to be found. On exit, the complete path to the file if found |
true | if the file could be found |
false | otherwise |
Computes the bounding box of a mesh.
[in] | mesh | the mesh |
|
inlinestatic |
Computes the bounding box of a mesh.
[in] | mesh | the mesh |
Definition at line 558 of file mesh_CSG_builder.h.
synonym for union.
Maybe there's something I did not understand in OpenSCAD, but I do not see the difference between group and union.
Computes the convex hull of several meshes.
[in] | scope | the meshes |
|
protected |
For the file formats that are not supported by geogram, get help from OpenSCAD to convert them.
Converts STEP files.
Computes the intersection between two or more meshes.
[in] | scope | the meshes |
|
protected |
keeps only triangles and vertices embedded in the z=0 plane, and makes the mesh 2D.
This also computes the border and re-triangulates it.
[in,out] | M | a shared pointer to the mesh |
|
virtual |
Computes a 3D extrusion from a 2D shape.
[in] | scope | one or more 2D shapes |
[in] | height | total height of the extrusion |
[in] | center | if set, z will go from -height/2 to height/2, else from 0 to height |
[in] | scale | scaling factor to be applied to x and y coordinates when reaching height |
[in] | slices | number of slices along the z axis |
[in] | twist | rotation to be applied when sweeping, in degrees |
|
virtual |
Groups several meshes into a single one and transforms them.
[in] | M | the transformation matrix. It follows the same convention as OpenSCAD, that is, not the OpenGL convention. For instance, a translation matrix has the translation vector as its third column. |
[in] | scope | one or several meshes to be merged. |
|
inlineprotected |
Definition at line 690 of file mesh_CSG_builder.h.
|
virtual |
Creates a 2D mesh from 3D mesh.
[in] | cut | if set, computes the boundary of the intersection between the object and the X,Y plane, else computes the boundary of the projection. |
|
inlineprotected |
Definition at line 686 of file mesh_CSG_builder.h.
|
virtual |
Computes a 3D extrusion from a 2D shape.
[in] | scope | one or more 2D shapes. Everything should be on the same side of the Y axis, preferably the positive side. |
[in] | angle | optional angle |
|
inline |
If set, compute constrained Delaunay triangulation in the intersected triangles. If there are intersections in coplanar facets, it guarantees uniqueness of their triangulation. Default is set.
Definition at line 491 of file mesh_CSG_builder.h.
|
inline |
detect and compute intersections between facets that share a facet or an edge. Set to false if input is a set of conformal meshes. Default is set.
Definition at line 500 of file mesh_CSG_builder.h.
|
inline |
Sets fast union mode.
In fast union mode, all intersections are computed and the external shell is kept. It may give incorrect result if an object is floating inside another one (completely included).
[in] | x | true if fast union mode should be used, false otherwise. |
Definition at line 525 of file mesh_CSG_builder.h.
|
inline |
Sets noop mode.
In noop mode, all CSG operations (union, intersection, difference) are replaced with append. Useful for debugging CSG trees.
[in] | x | whether noop mode should be set |
Definition at line 538 of file mesh_CSG_builder.h.
|
inline |
Specifies whether coplanar facets should be simplified.
[in] | x | if set, coplanar facets are simplified, else they are kept as is (faster but generates many triangles). Default is set. |
[in] | angle_tolerance | (in degree) the pairs of adjacent facets with normals that make an angle smaller than this threshold as considered to be coplanar. |
Definition at line 513 of file mesh_CSG_builder.h.
|
inlineprotected |
Definition at line 681 of file mesh_CSG_builder.h.
|
protectedvirtual |
Triangulates a 2D mesh.
This sets all edge operand bits to 1 and then computes a union using the other flavor of triangulate()
|
protectedvirtual |
Triangulates a 2D mesh.
Computes a constrained Delaunay triangulation from the edges of the mesh, then classifies the triangles using a boolean expression. Each edge has an "operand bit" indicating to which input operand it belongs to, set to (1u << operand_id). Used to implement CSG operations in 2D.
[in,out] | mesh | the input is a set of vertices and edges. The output has a set of triangles inside the polygons defined by the edges. |
[in] | boolean_expr | optional operation to be applied, can be one of
|
Computes the union of two or more meshes.
[in] | scope | the meshes |
|
friend |
Definition at line 708 of file mesh_CSG_builder.h.
|
protected |
Definition at line 701 of file mesh_CSG_builder.h.
|
protected |
Definition at line 699 of file mesh_CSG_builder.h.
|
protected |
Definition at line 698 of file mesh_CSG_builder.h.
|
protected |
Definition at line 704 of file mesh_CSG_builder.h.
|
protected |
Definition at line 702 of file mesh_CSG_builder.h.
|
protected |
Definition at line 697 of file mesh_CSG_builder.h.
|
protected |
Definition at line 703 of file mesh_CSG_builder.h.
|
protected |
Definition at line 705 of file mesh_CSG_builder.h.
|
protected |
Definition at line 706 of file mesh_CSG_builder.h.
|
protected |
Definition at line 700 of file mesh_CSG_builder.h.
|
protected |
Definition at line 696 of file mesh_CSG_builder.h.