40#ifndef H_GEO_MESH_ALGO_MESH_CSG_H
41#define H_GEO_MESH_ALGO_MESH_CSG_H
137 static constexpr double DEFAULT_FA = 12.0;
140 static constexpr double DEFAULT_FS = 2.0;
143 static constexpr double DEFAULT_FN = 0.0;
154 double h=1.0,
double r1=1.0,
double r2=1.0,
bool center=
true
157 const std::string& filename,
const std::string& layer=
"",
162 const std::string& filename,
bool center,
bool invert
205 return union_instr(scope);
282 fn_ = std::max(fn, 0.0);
292 fs_ = std::max(fs,0.01);
302 fa_ = std::max(fa,0.01);
321 detect_intersecting_neighbors_ = x;
334 simplify_coplanar_facets_ = x;
335 coplanar_angle_tolerance_ = angle_tolerance;
374 file_path_.push_back(path);
383 file_path_.push_back(
".");
388 bool find_file(std::string& filename);
390 void do_CSG(
CSGMesh_var mesh,
const std::string& boolean_expr);
402 bool keep_border_only=
false
411 const std::string& filename,
const std::string& layer=
"",
451 std::vector<std::string> file_path_;
452 bool detect_intersecting_neighbors_;
454 bool simplify_coplanar_facets_;
455 double coplanar_angle_tolerance_;
469 CSGMesh_var compile_file(
const std::string& input_filename);
470 CSGMesh_var compile_string(
const std::string& source);
478 builder_.set_verbose(x);
498 enum Type {NONE, NUMBER, BOOLEAN, ARRAY1D, ARRAY2D, STRING};
504 Value(
const std::string& x);
505 std::string to_string()
const;
511 std::string string_val;
520 typedef std::pair<std::string, Value> Arg;
526 const std::string& ith_arg_name(
index_t i)
const {
528 return args_[i].first;
533 return args_[i].second;
536 void add_arg(
const std::string& name,
const Value& value);
537 bool has_arg(
const std::string& name)
const;
538 const Value& get_arg(
const std::string& name)
const;
539 double get_arg(
const std::string& name,
double default_value)
const;
540 int get_arg(
const std::string& name,
int default_value)
const;
541 bool get_arg(
const std::string& name,
bool default_value)
const;
542 vec2 get_arg(
const std::string& name,
vec2 default_value)
const;
543 vec3 get_arg(
const std::string& name,
vec3 default_value)
const;
544 vec4 get_arg(
const std::string& name,
vec4 default_value)
const;
546 const std::string& name,
const mat4& default_value
549 const std::string& name,
const std::string& default_value
591 bool is_object(
const std::string&
id)
const;
592 bool is_instruction(
const std::string&
id)
const;
609 std::string to_string()
const;
671 std::string filename_;
673 Token lookahead_token_;
680 std::map<std::string, object_funptr> object_funcs_;
681 std::map<std::string, instruction_funptr> instruction_funcs_;
#define geo_assert(x)
Verifies that a condition is met.
#define geo_debug_assert(x)
Verifies that a condition is met.
Common include file, providing basic definitions. Should be included before anything else by all head...
Axis-aligned bounding box.
Implements CSG objects and instructions.
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.
CSGMesh_var difference(const CSGScope &scope)
Computes the intersection between two meshes.
void set_delaunay(bool x)
If set, compute constrained Delaunay triangulation in the intersected triangles. If there are interse...
CSGMesh_var intersection(const CSGScope &scope)
Computes the intersection between two or more meshes.
CSGMesh_var color(vec4 color, const CSGScope &scope)
Groups several meshes into a single one and sets their color.
void set_fn(double fn)
Sets the number of fragments.
void post_process(CSGMesh_var mesh)
Post-processes the result of a previous intersection.
bool verbose() const
Tests wheter verbose mode is set.
CSGMesh_var group(const CSGScope &scope)
synonym for union.
void set_fast_union(bool x)
Sets fast union mode.
void set_fa(double fa)
Sets the minimum angle for a fragment.
void add_file_path(const std::string &path)
Adds a path to the file path.
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 ...
void set_simplify_coplanar_facets(bool x, double angle_tolerance=0.0)
Specifies whether coplanar facets should be simplified.
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.
Image * load_dat_image(const std::string &file_name)
Loads an ascii data file as an image.
void triangulate(CSGMesh_var mesh, const std::string &boolean_expr, bool keep_border_only=false)
Triangulates a 2D mesh.
void set_fs(double fs)
Sets the minimum size for a fragment.
CSGMesh_var multmatrix(const mat4 &M, const CSGScope &scope)
Groups several meshes into a single one and transforms them.
void set_verbose(bool x)
Displays (lots of) additional information.
CSGMesh_var rotate_extrude(const CSGScope &scope, double angle=360.0)
Computes a 3D extrusion from a 2D shape.
void reset_file_path()
Resets the file path to its default value, with only the current directory ".".
CSGMesh_var append(const CSGScope &scope)
Appends all meshes in scope into a unique mesh, without testing for intersections.
CSGMesh_var projection(const CSGScope &scope, bool cut)
Creates a 2D mesh from 3D mesh.
CSGMesh_var union_instr(const CSGScope &scope)
Computes the union of two or more meshes.
CSGMesh_var hull(const CSGScope &scope)
Computes the convex hull of several meshes.
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.
void reset_defaults()
Resets defaults value for fn, fs, fa.
A parsed argument list in a .csg file.
Creates meshes from OpenSCAD .csg files.
void syntax_error(const char *msg, const Token &tok)
Throws an exception with an error message.
Token next_token_internal()
Function to actually get the next token from the stream.
bool is_modifier(int toktype) const
Checks if a token corresponds to an instruction or object modifier.
void next_token_check(char c)
Checks that the next token is a given character.
int line() const
Gets the currently parsed line source.
Token lookahead_token()
Gets the next token without any side effect.
void set_verbose(bool x)
Displays (lots of) additional information.
CSGBuilder & builder()
Gets the CSGbuilder.
void syntax_error(const char *msg)
Throws an exception with an error message.
Token next_token()
Gets the next token.
int lines() const
Gets the total number of lines of the currently parsed source.
A Mesh with reference counting and bounding box.
bool bbox_initialized() const
Tests whether the bounding box was initialized.
void append_mesh(const CSGMesh *other, index_t operand=index_t(-1))
Appends a mesh to this mesh.
const Box3d & bbox() const
Gets the bounding box.
bool may_have_intersections_with(const CSGMesh *other) const
Tests whether this mesh may have an intersection with another mesh.
void update_bbox()
Computes the bounding box.
Base class for reference-counted objects.
Tracks the progress of a task.
A smart pointer with reference-counted copy semantics.
Vector with aligned memory allocation.
Types and functions for memory manipulation.
The class that represents a mesh.
Global Vorpaline namespace.
SmartPointer< CSGMesh > CSGMesh_var
A smart pointer to a CSGMesh.
std::vector< CSGMesh_var > CSGScope
A list of CSGMesh.
bool bboxes_overlap(const Box &B1, const Box &B2)
Tests whether two Boxes have a non-empty intersection.
geo_index_t index_t
The type for storing and manipulating indices.
Pointers with automatic reference counting.
A parsed value in a .csg file.