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
165 const std::string& text,
167 const std::string& font =
"",
168 const std::string& halign =
"left",
169 const std::string& valign =
"baseline",
170 double spacing = 1.0,
171 const std::string& direction =
"ltr",
172 const std::string& language =
"en",
173 const std::string& script =
"latin"
217 return union_instr(scope);
294 fn_ = std::max(fn, 0.0);
304 fs_ = std::max(fs,0.01);
314 fa_ = std::max(fa,0.01);
333 detect_intersecting_neighbors_ = x;
346 simplify_coplanar_facets_ = x;
347 coplanar_angle_tolerance_ = angle_tolerance;
368 if(!verbose_ && fine_verbose_) {
369 fine_verbose_ =
false;
380 if(fine_verbose_ && !verbose_) {
401 file_path_.push_back(path);
411 file_path_.push_back(path);
419 file_path_.pop_back();
428 file_path_.push_back(
".");
442 triangulate(mesh,
"union");
457 bool find_file(std::string& filename);
459 void do_CSG(
CSGMesh_var mesh,
const std::string& boolean_expr);
472 bool keep_border_only=
false
481 const std::string& filename,
const std::string& layer=
"",
522 std::vector<std::string> file_path_;
523 bool detect_intersecting_neighbors_;
525 bool simplify_coplanar_facets_;
526 double coplanar_angle_tolerance_;
542 CSGMesh_var compile_file(
const std::string& input_filename);
543 CSGMesh_var compile_string(
const std::string& source);
551 builder_.set_verbose(x);
560 builder_.set_fine_verbose(x);
580 enum Type {NONE, NUMBER, BOOLEAN, ARRAY1D, ARRAY2D, STRING};
586 Value(
const std::string& x);
587 std::string to_string()
const;
593 std::string string_val;
602 typedef std::pair<std::string, Value> Arg;
608 const std::string& ith_arg_name(
index_t i)
const {
610 return args_[i].first;
615 return args_[i].second;
618 void add_arg(
const std::string& name,
const Value& value);
619 bool has_arg(
const std::string& name)
const;
620 const Value& get_arg(
const std::string& name)
const;
621 double get_arg(
const std::string& name,
double default_value)
const;
622 int get_arg(
const std::string& name,
int default_value)
const;
623 bool get_arg(
const std::string& name,
bool default_value)
const;
624 vec2 get_arg(
const std::string& name,
vec2 default_value)
const;
625 vec3 get_arg(
const std::string& name,
vec3 default_value)
const;
626 vec4 get_arg(
const std::string& name,
vec4 default_value)
const;
628 const std::string& name,
const mat4& default_value
631 const std::string& name,
const std::string& default_value
634 const std::string& name,
const char* default_value
636 return get_arg(name, std::string(default_value));
679 bool is_object(
const std::string&
id)
const;
680 bool is_instruction(
const std::string&
id)
const;
697 std::string to_string()
const;
759 std::string filename_;
761 Token lookahead_token_;
768 std::map<std::string, object_funptr> object_funcs_;
769 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.
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.
void pop_file_path()
Removes the latest pushed file path.
void push_file_path(const std::string &path)
Adds a path to the file path.
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 triangulate_2D_contours(CSGMesh_var mesh)
Triangulates a 2D mesh composed of vertices and segments.
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_fine_verbose(bool x)
Displays (even more) additional information.
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.
void set_noop(bool x)
Sets noop mode.
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.
void set_fine_verbose(bool x)
Displays (even more) additional information.
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.
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 append_mesh(const CSGMesh *other, index_t operand=NO_INDEX)
Appends a mesh to this 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.
Common include file, providing basic definitions. Should be included before anything else by all head...
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.