Graphite  Version 3
An experimental 3D geometry processing program
GEO::CSGBuilder Class Reference

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...
 
Imageload_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...
 

Detailed Description

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.

Member Function Documentation

◆ add_file_path()

void GEO::CSGBuilder::add_file_path ( const std::string &  path)
inline

Adds a path to the file path.

The file path is where import() searches files. The default file path contains the current directory "."

Parameters
[in]paththe file path to be added, without trailing '/'

Definition at line 373 of file mesh_CSG.h.

◆ color()

CSGMesh_var GEO::CSGBuilder::color ( vec4  color,
const CSGScope scope 
)

Groups several meshes into a single one and sets their color.

Parameters
[in]colorthe color, as r,g,b,a.

ignored for now, just behaves as group().

◆ difference()

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.

Parameters
[in]scopethe meshes

◆ get_fragments_from_r()

index_t GEO::CSGBuilder::get_fragments_from_r ( double  r,
double  twist = 360.0 
)
protected

Computes the number of fragments, that is, edges in a polygonal approximation of a circle.

Parameters
[in]rthe radius of the circle
[in]twistthe portion of the circle that will be drawn, in degrees

Uses fn,fs,fa

See also
set_fn(), set_fs(), set_fa()

◆ group()

CSGMesh_var GEO::CSGBuilder::group ( const CSGScope scope)
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.

◆ hull()

CSGMesh_var GEO::CSGBuilder::hull ( const CSGScope scope)

Computes the convex hull of several meshes.

Parameters
[in]scopethe meshes

◆ import_with_openSCAD()

CSGMesh_var GEO::CSGBuilder::import_with_openSCAD ( const std::string &  filename,
const std::string &  layer = "",
index_t  timestamp = 0 
)
protected

For the file formats that are not supported by geogram, get help from OpenSCAD to convert them.

Converts STEP files.

◆ intersection()

CSGMesh_var GEO::CSGBuilder::intersection ( const CSGScope scope)

Computes the intersection between two or more meshes.

Parameters
[in]scopethe meshes

◆ linear_extrude()

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.

Parameters
[in]scopeone or more 2D shapes
[in]heighttotal height of the extrusion
[in]centerif set, z will go from -height/2 to height/2, else from 0 to height
[in]scalescaling factor to be applied to x and y coordinates when reaching height
[in]slicesnumber of slices along the z axis
[in]twistrotation to be applied when sweeping, in degrees

◆ load_dat_image()

Image* GEO::CSGBuilder::load_dat_image ( const std::string &  file_name)
protected

Loads an ascii data file as an image.

Parameters
[in]file_namethe name of the file, containing a matrix in the octave file format
Returns
a pointer to the created image. Color encoding is Image::GRAY and component encoding is Image::FLOAT64.

◆ multmatrix()

CSGMesh_var GEO::CSGBuilder::multmatrix ( const mat4 M,
const CSGScope scope 
)

Groups several meshes into a single one and transforms them.

Parameters
[in]Mthe 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]scopeone or several meshes to be merged.

◆ post_process()

void GEO::CSGBuilder::post_process ( CSGMesh_var  mesh)
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.

Parameters
[in]meshthe mesh to be processed

◆ projection()

CSGMesh_var GEO::CSGBuilder::projection ( const CSGScope scope,
bool  cut 
)

Creates a 2D mesh from 3D mesh.

Parameters
[in]cutif set, computes the boundary of the intersection between the object and the X,Y plane, else computes the boundary of the projection.

◆ reset_defaults()

void GEO::CSGBuilder::reset_defaults ( )

Resets defaults value for fn, fs, fa.

See also
set_fn(), set_fs(), set_fa()

◆ rotate_extrude()

CSGMesh_var GEO::CSGBuilder::rotate_extrude ( const CSGScope scope,
double  angle = 360.0 
)

Computes a 3D extrusion from a 2D shape.

Parameters
[in]scopeone or more 2D shapes. Everything should be on the same side of the Y axis, preferably the positive side.
[in]angleoptional angle

◆ set_fa()

void GEO::CSGBuilder::set_fa ( double  fa)
inline

Sets the minimum angle for a fragment.

Parameters
[in]faminimum 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.

◆ set_fast_union()

void GEO::CSGBuilder::set_fast_union ( bool  x)
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).

Parameters
[in]xtrue if fast union mode should be used, false otherwise.

Definition at line 345 of file mesh_CSG.h.

◆ set_fn()

void GEO::CSGBuilder::set_fn ( double  fn)
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

Parameters
[in]fnthe number of fragments.
See also
set_fs(), set_fa()

Definition at line 281 of file mesh_CSG.h.

◆ set_fs()

void GEO::CSGBuilder::set_fs ( double  fs)
inline

Sets the minimum size for a fragment.

Parameters
[in]fsminimum 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.

◆ set_simplify_coplanar_facets()

void GEO::CSGBuilder::set_simplify_coplanar_facets ( bool  x,
double  angle_tolerance = 0.0 
)
inline

Specifies whether coplanar facets should be simplified.

Parameters
[in]xif 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.

◆ set_verbose()

void GEO::CSGBuilder::set_verbose ( bool  x)
inline

Displays (lots of) additional information.

Parameters
[in]xwhether additional information should be displayed. Default is off

Definition at line 354 of file mesh_CSG.h.

◆ triangulate()

void GEO::CSGBuilder::triangulate ( CSGMesh_var  mesh,
const std::string &  boolean_expr,
bool  keep_border_only = false 
)
protected

Triangulates a 2D mesh.

Parameters
[in,out]meshthe input is a set of vertices and edges. The output has a set of triangles inside.
[in]keep_border_onlyif set, then triangles are discarded. It useful to compute 2D boolean operations, where only the border is kept.

◆ union_instr()

CSGMesh_var GEO::CSGBuilder::union_instr ( const CSGScope scope)

Computes the union of two or more meshes.

Parameters
[in]scopethe meshes

◆ verbose()

bool GEO::CSGBuilder::verbose ( ) const
inline

Tests wheter verbose mode is set.

Return values
trueif additional information will be displayed.
falseotherwise.

Definition at line 363 of file mesh_CSG.h.

Member Data Documentation

◆ DEFAULT_FA

constexpr double GEO::CSGBuilder::DEFAULT_FA = 12.0
staticconstexpr
See also
set_fa()

Definition at line 137 of file mesh_CSG.h.

◆ DEFAULT_FN

constexpr double GEO::CSGBuilder::DEFAULT_FN = 0.0
staticconstexpr
See also
set_fn()

Definition at line 143 of file mesh_CSG.h.

◆ DEFAULT_FS

constexpr double GEO::CSGBuilder::DEFAULT_FS = 2.0
staticconstexpr
See also
set_fs()

Definition at line 140 of file mesh_CSG.h.


The documentation for this class was generated from the following file: