|
Geogram Version 1.10.1
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, bool center=false) |
| std::shared_ptr< Mesh > | square (double size=1.0, bool center=false) |
| virtual std::shared_ptr< Mesh > | circle (double r=1.0, index_t nu=0) |
| virtual std::shared_ptr< Mesh > | cube (vec3 size, bool center=false) |
| std::shared_ptr< Mesh > | cube (double size=1.0, bool center=false) |
| virtual std::shared_ptr< Mesh > | sphere (double r=1.0) |
| virtual std::shared_ptr< Mesh > | cylinder (double h, double r1, double r2, bool center=false) |
| 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. | |
| template<typename... Types> | |
| std::shared_ptr< Mesh > | union_instr (Types...args) |
| 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. | |
| template<typename... Types> | |
| std::shared_ptr< Mesh > | intersection (Types...args) |
| Computes the mutual intersection between meshes. | |
| virtual std::shared_ptr< Mesh > | difference (const CSGScope &scope) |
| Computes the intersection between two meshes. | |
| template<typename... Types> | |
| std::shared_ptr< Mesh > | difference (Types...args) |
| Computes the difference between 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_translate (const ArgList &args) override |
| void | eval_rotate (const ArgList &args) override |
| void | eval_scale (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 |
| std::shared_ptr< Mesh > | translate (const vec3 &T, const CSGScope &scope) |
| Commodity function for translating a CSGScope using OpenSCAD syntax. | |
| std::shared_ptr< Mesh > | rotate (double angle, const CSGScope &scope) |
| Commodity function for 2D-rotating a CSGScope using OpenSCAD syntax. | |
| std::shared_ptr< Mesh > | rotate (double angle, const vec3 &axis, const CSGScope &scope) |
| Commodity function for rotating a CSGScope using OpenSCAD syntax. | |
| std::shared_ptr< Mesh > | rotate (const vec3 &angles, const CSGScope &scope) |
| Commodity function for rotating a CSGScope using OpenSCAD syntax. | |
| std::shared_ptr< Mesh > | scale (double sx, double sy, double sz, const CSGScope &scope) |
| Commodity function for scaling a CSGScope using OpenSCAD syntax. | |
| 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. | |
Public Member Functions inherited from GEO::AbstractCSGBuilder | |
| 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 mat4 | translation_matrix (const vec3 &T) |
| Builds a translation matrix. | |
| static mat4 | scaling_matrix (double sx, double sy, double sz) |
| Builds a scaling matrix. | |
| static mat4 | rotation_matrix (double angle, vec3 axis={0.0, 0.0, 0.0}) |
| Builds a rotation matrix. | |
| static mat4 | rotation_matrix (const vec3 &angles) |
| Builds a rotation matrix. | |
| 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 () |
Protected Member Functions inherited from GEO::AbstractCSGBuilder | |
| 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_ |
Protected Attributes inherited from GEO::AbstractCSGBuilder | |
| 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 | |
Public Types inherited from GEO::AbstractCSGBuilder | |
| typedef GEOCSG::ArgList | ArgList |
| typedef GEOCSG::Value | Value |
Static Public Attributes inherited from GEO::AbstractCSGBuilder | |
| static constexpr double | DEFAULT_FA = 12.0 |
| static constexpr double | DEFAULT_FS = 2.0 |
| static constexpr double | DEFAULT_FN = 0.0 |
Protected Types inherited from GEO::AbstractCSGBuilder | |
| 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 358 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().
Definition at line 379 of file mesh_CSG_builder.h.
|
inlineprotected |
Gets the current path.
Definition at line 850 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 |
|
inline |
Computes the difference between meshes.
If args contains more than two meshes, it computes the difference between the first mesh and the union of the rest.
| [in] | args | the list of meshes as the function parameters (this function takes an arbitrary number of parameters). |
args Definition at line 487 of file mesh_CSG_builder.h.
|
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.
|
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 810 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 |
scope
|
inline |
Computes the mutual intersection between meshes.
| [in] | args | the list of meshes to be intersected as the function parameters (this function takes an arbitrary number of parameters). |
args Definition at line 463 of file mesh_CSG_builder.h.
|
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 942 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 938 of file mesh_CSG_builder.h.
|
inline |
Commodity function for rotating a CSGScope using OpenSCAD syntax.
| [in] | angles | rotation angles along the three axes in degrees |
| [in] | scope | a scope with the list of meshes to be transformed |
scope Definition at line 718 of file mesh_CSG_builder.h.
Commodity function for 2D-rotating a CSGScope using OpenSCAD syntax.
| [in] | angle | rotation angle in degrees |
| [in] | scope | a scope with the list of meshes to be transformed |
scope Definition at line 691 of file mesh_CSG_builder.h.
|
inline |
Commodity function for rotating a CSGScope using OpenSCAD syntax.
if angle is 0, then axis corresponds to the three rotation angles around x,y and z
| [in] | angle | rotation angle in degrees |
| [in] | axis | rotation axis |
| [in] | scope | a scope with the list of meshes to be transformed |
scope Definition at line 705 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 |
Builds a rotation matrix.
| [in] | angles | rotation angles around each axis in degrees |
Definition at line 660 of file mesh_CSG_builder.h.
|
inlinestatic |
Builds a rotation matrix.
| [in] | axis | rotation axis |
| [in] | angle | rotation angle in degrees |
Definition at line 637 of file mesh_CSG_builder.h.
|
inline |
Commodity function for scaling a CSGScope using OpenSCAD syntax.
| [in] | sx,sy,sz | scaling factors along each axis |
| [in] | scope | a scope with the list of meshes to be transformed |
scope Definition at line 729 of file mesh_CSG_builder.h.
|
inlinestatic |
Builds a scaling matrix.
| [in] | sx,sy,sz | scaling along each axis |
Definition at line 624 of file mesh_CSG_builder.h.
|
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 743 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 752 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 777 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 790 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 765 of file mesh_CSG_builder.h.
Definition at line 367 of file mesh_CSG_builder.h.
|
inlineprotected |
Definition at line 933 of file mesh_CSG_builder.h.
|
inline |
Commodity function for translating a CSGScope using OpenSCAD syntax.
| [in] | T | translation vector |
| [in] | scope | a scope with the list of meshes to be transformed |
scope Definition at line 680 of file mesh_CSG_builder.h.
Builds a translation matrix.
| [in] | T | the translation matrix |
Definition at line 612 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. One can use a CSGScope object, or a curly-braced list of meshes (list of shared_ptr to meshes in fact). |
scope.
|
inline |
Computes the union of two or more meshes.
| [in] | args | the list of meshes to be unioned, as the function parameters (this function takes an arbitrary number of parameters). |
args. Definition at line 442 of file mesh_CSG_builder.h.
|
friend |
Definition at line 960 of file mesh_CSG_builder.h.
|
protected |
Definition at line 953 of file mesh_CSG_builder.h.
|
protected |
Definition at line 951 of file mesh_CSG_builder.h.
|
protected |
Definition at line 950 of file mesh_CSG_builder.h.
|
protected |
Definition at line 956 of file mesh_CSG_builder.h.
|
protected |
Definition at line 954 of file mesh_CSG_builder.h.
|
protected |
Definition at line 949 of file mesh_CSG_builder.h.
|
protected |
Definition at line 955 of file mesh_CSG_builder.h.
|
protected |
Definition at line 957 of file mesh_CSG_builder.h.
|
protected |
Definition at line 958 of file mesh_CSG_builder.h.
|
protected |
Definition at line 952 of file mesh_CSG_builder.h.
|
protected |
Definition at line 948 of file mesh_CSG_builder.h.