Geogram
Version 1.9.1
A programming library of geometric algorithms
|
Implements CSG objects and instructions. More...
#include <geogram/mesh/mesh_CSG.h>
Public Member Functions | |
CSGMesh_var | square (vec2 size=vec2(1.0, 1.0), bool center=true) |
CSGMesh_var | circle (double r=1.0) |
CSGMesh_var | cube (vec3 size=vec3(1.0, 1.0, 1.0), bool center=true) |
CSGMesh_var | sphere (double r=1.0) |
CSGMesh_var | cylinder (double h=1.0, double r1=1.0, double r2=1.0, bool center=true) |
CSGMesh_var | import (const std::string &filename, const std::string &layer="", index_t timestamp=0, vec2 origin=vec2(0.0, 0.0), vec2 scale=vec2(1.0, 1.0)) |
CSGMesh_var | surface (const std::string &filename, bool center, bool invert) |
CSGMesh_var | multmatrix (const mat4 &M, const CSGScope &scope) |
Groups several meshes into a single one and transforms them. More... | |
CSGMesh_var | union_instr (const CSGScope &scope) |
Computes the union of two or more meshes. More... | |
CSGMesh_var | intersection (const CSGScope &scope) |
Computes the intersection between two or more meshes. More... | |
CSGMesh_var | difference (const CSGScope &scope) |
Computes the intersection between two meshes. More... | |
CSGMesh_var | group (const CSGScope &scope) |
synonym for union. More... | |
CSGMesh_var | color (vec4 color, const CSGScope &scope) |
Groups several meshes into a single one and sets their color. More... | |
CSGMesh_var | hull (const CSGScope &scope) |
Computes the convex hull of several meshes. More... | |
CSGMesh_var | linear_extrude (const CSGScope &scope, double height=1.0, bool center=true, vec2 scale=vec2(1.0, 1.0), index_t slices=0, double twist=0.0) |
Computes a 3D extrusion from a 2D shape. More... | |
CSGMesh_var | rotate_extrude (const CSGScope &scope, double angle=360.0) |
Computes a 3D extrusion from a 2D shape. More... | |
CSGMesh_var | projection (const CSGScope &scope, bool cut) |
Creates a 2D mesh from 3D mesh. More... | |
CSGMesh_var | append (const CSGScope &scope) |
Appends all meshes in scope into a unique mesh, without testing for intersections. | |
void | reset_defaults () |
Resets defaults value for fn, fs, fa. More... | |
void | set_fn (double fn) |
Sets the number of fragments. More... | |
void | set_fs (double fs) |
Sets the minimum size for a fragment. More... | |
void | set_fa (double fa) |
Sets the minimum angle for a fragment. More... | |
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. More... | |
void | set_fast_union (bool x) |
Sets fast union mode. More... | |
void | set_verbose (bool x) |
Displays (lots of) additional information. More... | |
bool | verbose () const |
Tests wheter verbose mode is set. More... | |
void | add_file_path (const std::string &path) |
Adds a path to the file path. More... | |
void | reset_file_path () |
Resets the file path to its default value, with only the current directory ".". | |
Static Public Attributes | |
static constexpr double | DEFAULT_FA = 12.0 |
static constexpr double | DEFAULT_FS = 2.0 |
static constexpr double | DEFAULT_FN = 0.0 |
Protected Member Functions | |
bool | find_file (std::string &filename) |
void | do_CSG (CSGMesh_var mesh, const std::string &boolean_expr) |
void | triangulate (CSGMesh_var mesh, const std::string &boolean_expr, bool keep_border_only=false) |
Triangulates a 2D mesh. More... | |
CSGMesh_var | import_with_openSCAD (const std::string &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. More... | |
Image * | load_dat_image (const std::string &file_name) |
Loads an ascii data file as an image. More... | |
void | post_process (CSGMesh_var mesh) |
Post-processes the result of a previous intersection. More... | |
index_t | get_fragments_from_r (double r, double twist=360.0) |
Computes the number of fragments, that is, edges in a polygonal approximation of a circle. More... | |
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 134 of file mesh_CSG.h.
|
inline |
Adds a path to the file path.
The file path is where import() searches files. The default file path contains the current directory "."
[in] | path | the file path to be added, without trailing '/' |
Definition at line 373 of file mesh_CSG.h.
CSGMesh_var GEO::CSGBuilder::color | ( | vec4 | color, |
const CSGScope & | scope | ||
) |
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().
CSGMesh_var GEO::CSGBuilder::difference | ( | const CSGScope & | scope | ) |
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 |
|
protected |
|
inline |
synonym for union.
Maybe there's something I did not understand in OpenSCAD, but I do not see the difference between group and union.
Definition at line 204 of file mesh_CSG.h.
CSGMesh_var GEO::CSGBuilder::hull | ( | const CSGScope & | scope | ) |
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.
CSGMesh_var GEO::CSGBuilder::intersection | ( | const CSGScope & | scope | ) |
Computes the intersection between two or more meshes.
[in] | scope | the meshes |
CSGMesh_var GEO::CSGBuilder::linear_extrude | ( | const CSGScope & | scope, |
double | height = 1.0 , |
||
bool | center = true , |
||
vec2 | scale = vec2(1.0, 1.0) , |
||
index_t | slices = 0 , |
||
double | twist = 0.0 |
||
) |
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 |
|
protected |
Loads an ascii data file as an image.
[in] | file_name | the name of the file, containing a matrix in the octave file format |
CSGMesh_var GEO::CSGBuilder::multmatrix | ( | const mat4 & | M, |
const CSGScope & | scope | ||
) |
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. |
|
protected |
Post-processes the result of a previous intersection.
After converting exact coordinates to doubles, some problems may occur. This function tentatively fixes this problems. TODO: correct snap-rounding.
[in] | mesh | the mesh to be processed |
CSGMesh_var GEO::CSGBuilder::projection | ( | const CSGScope & | scope, |
bool | cut | ||
) |
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. |
void GEO::CSGBuilder::reset_defaults | ( | ) |
CSGMesh_var GEO::CSGBuilder::rotate_extrude | ( | const CSGScope & | scope, |
double | angle = 360.0 |
||
) |
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 |
Sets the minimum angle for a fragment.
[in] | fa | minimum angle for a fragment, in degrees. |
This determines the number of edges in a polygonal approximation of a circle.
Definition at line 301 of file mesh_CSG.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 345 of file mesh_CSG.h.
|
inline |
Sets the number of fragments.
This corresponds to the number of edges in a polygonal approximation of a circle. If left to 0, it is automatically computed from fs and fa
[in] | fn | the number of fragments. |
Definition at line 281 of file mesh_CSG.h.
|
inline |
Sets the minimum size for a fragment.
[in] | fs | minimum size for a fragment. |
This determines the number of edges in a polygonal approximation of a circle.
Definition at line 291 of file mesh_CSG.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 333 of file mesh_CSG.h.
|
inline |
Displays (lots of) additional information.
[in] | x | whether additional information should be displayed. Default is off |
Definition at line 354 of file mesh_CSG.h.
|
protected |
Triangulates a 2D mesh.
[in,out] | mesh | the input is a set of vertices and edges. The output has a set of triangles inside. |
[in] | keep_border_only | if set, then triangles are discarded. It useful to compute 2D boolean operations, where only the border is kept. |
CSGMesh_var GEO::CSGBuilder::union_instr | ( | const CSGScope & | scope | ) |
Computes the union of two or more meshes.
[in] | scope | the meshes |
|
inline |
Tests wheter verbose mode is set.
true | if additional information will be displayed. |
false | otherwise. |
Definition at line 363 of file mesh_CSG.h.
|
staticconstexpr |
Definition at line 137 of file mesh_CSG.h.
|
staticconstexpr |
Definition at line 143 of file mesh_CSG.h.
|
staticconstexpr |
Definition at line 140 of file mesh_CSG.h.