Geogram Version 1.10.1
A programming library of geometric algorithms
Loading...
Searching...
No Matches
mesh_CSG_builder.h
1/*
2 * Copyright (c) 2000-2023 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef H_GEO_MESH_CSG_BUILDER_H
41#define H_GEO_MESH_CSG_BUILDER_H
42
44#include <geogram/mesh/mesh_CSG_utils.h>
45#include <memory>
46#include <functional>
47#include <stack>
48
49namespace GEO {
50
62 class GEOGRAM_API AbstractCSGBuilder {
63 public:
65 typedef GEOCSG::Value Value;
66
68 static constexpr double DEFAULT_FA = 12.0;
69
71 static constexpr double DEFAULT_FS = 2.0;
72
74 static constexpr double DEFAULT_FN = 0.0;
75
80
85
86 /****** Parameters ******/
87
93
102 void set_fn(double fn) {
103 fn_ = std::max(fn, 0.0);
104 }
105
112 void set_fs(double fs) {
113 fs_ = std::max(fs,0.01);
114 }
115
122 void set_fa(double fa) {
123 fa_ = std::max(fa,0.01);
124 }
125
131 void set_verbose(bool x) {
132 verbose_ = x;
133 if(verbose_) {
134 warnings_ = true;
135 }
136 }
137
143 void set_detailed_verbose(bool x) {
144 detailed_verbose_ = x;
145 if(detailed_verbose_ && !verbose_) {
146 verbose_ = true;
147 }
148 }
149
155 bool verbose() const {
156 return verbose_;
157 }
158
159
166 void add_file_path(const std::filesystem::path& path) {
167 file_path_.push_back(path);
168 }
169
175 file_path_.clear();
176 file_path_.push_back(std::filesystem::current_path());
177 }
178
185 void push_file_path(const std::filesystem::path& path) {
186 file_path_.push_back(path);
187 }
188
193 geo_assert(file_path_.size() != 0);
194 file_path_.pop_back();
195 }
196
197 /**** Abstract API - objects ******/
198
199 virtual void add_object(
200 const std::string& object, const ArgList& args
201 );
202
203 virtual void begin_instruction();
204
205 virtual void end_instruction(
206 const std::string& instruction, const ArgList& args
207 );
208
209
210 bool is_object(const std::string& id) const {
211 return (object_funcs_.find(id) != object_funcs_.end());
212 }
213
214 bool is_instruction(const std::string& id) const {
215 return (instruction_funcs_.find(id) != instruction_funcs_.end());
216 }
217
218 protected:
219
220 /****** Objects ******************************************/
221
222 virtual void add_square(const ArgList& args);
223 virtual void add_circle(const ArgList& args);
224 virtual void add_cube(const ArgList& args);
225 virtual void add_sphere(const ArgList& args);
226 virtual void add_cylinder(const ArgList& args);
227 virtual void add_polyhedron(const ArgList& args);
228 virtual void add_polygon(const ArgList& args);
229 virtual void add_import(const ArgList& args);
230 virtual void add_surface(const ArgList& args);
231 virtual void add_text(const ArgList& args);
232
233 /****** Instructions ************************************/
234
235 virtual void eval_multmatrix(const ArgList& args);
236 virtual void eval_translate(const ArgList& args);
237 virtual void eval_rotate(const ArgList& args);
238 virtual void eval_scale(const ArgList& args);
239 virtual void eval_resize(const ArgList& args);
240 virtual void eval_union(const ArgList& args);
241 virtual void eval_intersection(const ArgList& args);
242 virtual void eval_difference(const ArgList& args);
243 virtual void eval_group(const ArgList& args);
244 virtual void eval_color(const ArgList& args);
245 virtual void eval_hull(const ArgList& args);
246 virtual void eval_linear_extrude(const ArgList& args);
247 virtual void eval_rotate_extrude(const ArgList& args);
248 virtual void eval_projection(const ArgList& args);
249 virtual void eval_minkowski(const ArgList& args);
250 virtual void eval_render(const ArgList& args);
251
252 /**************************/
253
254 [[noreturn]] void error(const char* str) {
255 throw(std::logic_error(str));
256 }
257
258 [[noreturn]] void error(const std::string& str) {
259 throw(std::logic_error(str.c_str()));
260 }
261
262 double fn_;
263 double fs_;
264 double fa_;
265
266 std::vector<std::filesystem::path> file_path_;
267 bool warnings_;
268 bool verbose_;
269 bool detailed_verbose_;
270
271 typedef std::function<void(const ArgList& args)> csg_builder_func;
272 std::map<std::string, csg_builder_func> object_funcs_;
273 std::map<std::string, csg_builder_func> instruction_funcs_;
274 };
275
276 /***********************************************************************/
277
283 class CSGScope {
284 public:
289 }
290
295 CSGScope(std::shared_ptr<Mesh> M) {
296 emplace_back(M);
297 }
298
304 const std::initializer_list<std::shared_ptr<Mesh>>& Ms
305 ) : meshes_(Ms) {
306 }
307
308 void push_back(std::shared_ptr<Mesh> M) {
309 meshes_.push_back(M);
310 }
311
312 void emplace_back(std::shared_ptr<Mesh> M) {
313 meshes_.emplace_back(M);
314 }
315
316 void pop_back() {
317 meshes_.pop_back();
318 }
319
320 index_t size() const {
321 return index_t(meshes_.size());
322 }
323
324 const std::shared_ptr<Mesh>& operator[](index_t i) const {
325 geo_debug_assert(i < size());
326 return meshes_[i];
327 }
328
329 auto begin() { return meshes_.begin(); }
330 auto end() { return meshes_.end(); }
331 auto begin() const { return meshes_.begin(); }
332 auto end() const { return meshes_.end(); }
333 auto rbegin() { return meshes_.rbegin(); }
334 auto rend() { return meshes_.rend(); }
335 auto rbegin() const { return meshes_.rbegin(); }
336 auto rend() const { return meshes_.rend(); }
337
338 void append(std::shared_ptr<Mesh> M) {
339 emplace_back(M);
340 }
341
342 template <typename...Types> void append(
343 std::shared_ptr<Mesh> head, Types... tail
344 ) {
345 append(head);
346 append(tail...);
347 }
348
349 private:
350 std::vector<std::shared_ptr<Mesh>> meshes_;
351 };
352
358 class GEOGRAM_API CSGBuilder : public AbstractCSGBuilder {
359 public:
360 CSGBuilder();
361 ~CSGBuilder() override;
362
363 /****** Objects **********/
364
365 virtual std::shared_ptr<Mesh> square(vec2 size, bool center=false);
366
367 std::shared_ptr<Mesh> square(double size=1.0, bool center=false) {
368 return square(vec2(size,size), center);
369 }
370
375 virtual std::shared_ptr<Mesh> circle(double r=1.0, index_t nu=0);
376
377 virtual std::shared_ptr<Mesh> cube(vec3 size, bool center=false);
378
379 std::shared_ptr<Mesh> cube(double size=1.0, bool center=false) {
380 return cube(vec3(size,size,size), center);
381 }
382
383 virtual std::shared_ptr<Mesh> sphere(double r=1.0);
384
385 virtual std::shared_ptr<Mesh> cylinder(
386 double h, double r1, double r2, bool center=false
387 );
388
389 virtual std::shared_ptr<Mesh> import(
390 const std::filesystem::path& filename, const std::string& layer="",
391 index_t timestamp=0,
392 vec2 origin = vec2(0.0, 0.0), vec2 scale = vec2(1.0,1.0)
393 );
394
395 virtual std::shared_ptr<Mesh> surface(
396 const std::filesystem::path& filename, bool center, bool invert
397 );
398
399 virtual std::shared_ptr<Mesh> text(
400 const std::string& text,
401 double size = 10.0,
402 const std::string& font = "",
403 const std::string& halign = "left",
404 const std::string& valign = "baseline",
405 double spacing = 1.0,
406 const std::string& direction = "ltr",
407 const std::string& language = "en",
408 const std::string& script = "latin"
409 );
410
411
412 /****** Instructions ****/
413
423 virtual std::shared_ptr<Mesh> multmatrix(
424 const mat4& M, const CSGScope& scope
425 );
426
433 virtual std::shared_ptr<Mesh> union_instr(const CSGScope& scope);
434
442 template <typename...Types> std::shared_ptr<Mesh> union_instr(Types...args) {
443 CSGScope scope;
444 scope.append(args...);
445 return union_instr(scope);
446 }
447
453 virtual std::shared_ptr<Mesh> intersection(const CSGScope& scope);
454
462 template <typename...Types> std::shared_ptr<Mesh>
463 intersection(Types...args) {
464 CSGScope scope;
465 scope.append(args...);
466 return intersection(scope);
467 }
468
475 virtual std::shared_ptr<Mesh> difference(const CSGScope& scope);
476
486 template <typename...Types> std::shared_ptr<Mesh>
487 difference(Types...args) {
488 CSGScope scope;
489 scope.append(args...);
490 return difference(scope);
491 }
492
499 virtual std::shared_ptr<Mesh> group(const CSGScope& scope);
500
507 virtual std::shared_ptr<Mesh> color(vec4 color, const CSGScope& scope);
508
513 virtual std::shared_ptr<Mesh> hull(const CSGScope& scope);
514
526 virtual std::shared_ptr<Mesh> linear_extrude(
527 const CSGScope& scope,
528 double height = 1.0,
529 bool center = false,
530 vec2 scale = vec2(1.0,1.0),
531 index_t slices = 0,
532 double twist = 0.0
533 );
534
541 virtual std::shared_ptr<Mesh> rotate_extrude(
542 const CSGScope& scope, double angle = 360.0
543 );
544
551 virtual std::shared_ptr<Mesh> projection(const CSGScope& scope, bool cut);
552
556 virtual std::shared_ptr<Mesh> minkowski(const CSGScope& scope);
557
563 virtual std::shared_ptr<Mesh> append(const CSGScope& scope);
564
565 /****** AbstractCSGBuilder API ********************************/
566
567 void add_object(const std::string& object, const ArgList& args) override;
568 void begin_instruction() override;
569 void end_instruction(
570 const std::string& instruction, const ArgList& args
571 ) override;
572
573 /****** Objects (AbstractCSGBuilder API) *********************/
574
575 void add_square(const ArgList& args) override;
576 void add_circle(const ArgList& args) override;
577 void add_cube(const ArgList& args) override;
578 void add_sphere(const ArgList& args) override;
579 void add_cylinder(const ArgList& args) override;
580 void add_polyhedron(const ArgList& args) override;
581 void add_polygon(const ArgList& args) override;
582 void add_import(const ArgList& args) override;
583 void add_surface(const ArgList& args) override;
584 void add_text(const ArgList& args) override;
585
586 /****** Instructions (AbstractCSGBuilder API) ****************/
587
588 void eval_multmatrix(const ArgList& args) override;
589 void eval_translate(const ArgList& args) override;
590 void eval_rotate(const ArgList& args) override;
591 void eval_scale(const ArgList& args) override;
592 void eval_resize(const ArgList& args) override;
593 void eval_union(const ArgList& args) override;
594 void eval_intersection(const ArgList& args) override;
595 void eval_difference(const ArgList& args) override;
596 void eval_group(const ArgList& args) override;
597 void eval_color(const ArgList& args) override;
598 void eval_hull(const ArgList& args) override;
599 void eval_linear_extrude(const ArgList& args) override;
600 void eval_rotate_extrude(const ArgList& args) override;
601 void eval_projection(const ArgList& args) override;
602 void eval_minkowski(const ArgList& args) override;
603 void eval_render(const ArgList& args) override;
604
605 /****** Commodity functions **********************************/
606
612 static mat4 translation_matrix(const vec3& T) {
613 return mat4{{1, 0, 0, T.x},
614 {0, 1, 0, T.y},
615 {0, 0, 1, T.z},
616 {0, 0, 0, 1 }};
617 }
618
624 static mat4 scaling_matrix(double sx, double sy, double sz) {
625 return mat4{{sx, 0, 0, 0},
626 {0, sy, 0, 0},
627 {0, 0, sz, 0},
628 {0, 0, 0, 1}};
629 }
630
637 static mat4 rotation_matrix(double angle, vec3 axis = {0.0, 0.0, 0.0}) {
638 if(axis.x == 0.0 && axis.y == 0.0 && axis.z == 0.0) {
639 axis.z = 1.0; // special case, OpenSCAD convention
640 }
641 vec3 N = normalize(axis);
642 double x = N.x;
643 double y = N.y;
644 double z = N.z;
645 angle = angle * M_PI / 180;
646 double s = sin(angle);
647 double c = cos(angle);
648 double t = 1.0-c;
649 return mat4{{t*x*x + c, t*x*y - s*z, t*x*z + s*y, 0.0},
650 {t*x*y + s*z, t*y*y + c, t*y*z - s*x, 0.0},
651 {t*x*z - s*y, t*y*z + s*x, t*z*z + c, 0.0},
652 {0.0, 0.0, 0.0, 1.0}};
653 }
654
660 static mat4 rotation_matrix(const vec3& angles) {
661 double a = angles[0] * M_PI / 180.0;
662 double b = angles[1] * M_PI / 180.0;
663 double c = angles[2] * M_PI / 180.0;
664 double sa = sin(a); double ca = cos(a);
665 double sb = sin(b); double cb = cos(b);
666 double sc = sin(c); double cc = cos(c);
667 return mat4{{cc*cb, cc*sb*sa - sc*ca, cc*sb*ca + sc*sa, 0.0},
668 {sc*cb, sc*sb*sa + cc*ca, sc*sb*ca - cc*sa, 0.0},
669 { -sb, cb*sa, cb*ca, 0.0},
670 { 0.0, 0.0, 0.0, 1.0}};
671 }
672
680 std::shared_ptr<Mesh> translate(const vec3& T, const CSGScope& scope) {
681 return multmatrix(translation_matrix(T),scope);
682 }
683
691 std::shared_ptr<Mesh> rotate(double angle, const CSGScope& scope) {
692 return multmatrix(rotation_matrix(angle),scope);
693 }
694
705 std::shared_ptr<Mesh> rotate(
706 double angle, const vec3& axis, const CSGScope& scope
707 ) {
708 return multmatrix(rotation_matrix(angle,axis),scope);
709 }
710
718 std::shared_ptr<Mesh> rotate(const vec3& angles, const CSGScope& scope) {
719 return multmatrix(rotation_matrix(angles),scope);
720 }
721
729 std::shared_ptr<Mesh> scale(
730 double sx, double sy, double sz, const CSGScope& scope
731 ) {
732 return multmatrix(scaling_matrix(sx,sy,sz),scope);
733 }
734
735 /**************************/
736
743 void set_delaunay(bool x) {
744 delaunay_ = x;
745 }
746
753 detect_intersecting_neighbors_ = x;
754 }
755
765 void set_simplify_coplanar_facets(bool x, double angle_tolerance=0.0) {
766 simplify_coplanar_facets_ = x;
767 coplanar_angle_tolerance_ = angle_tolerance;
768 }
769
777 void set_fast_union(bool x) {
778 fast_union_ = x;
779 }
780
781
782 /***** misc ********/
783
790 void set_noop(bool x) {
791 noop_ = x;
792 }
793
794
801 static Box3d get_bbox(const std::shared_ptr<Mesh>& mesh);
802
810 static std::pair<vec3, vec3> get_bbox_bounds(
811 const std::shared_ptr<Mesh>& mesh
812 ) {
813 Box3d result = get_bbox(mesh);
814 return std::make_pair(vec3(result.xyz_min), vec3(result.xyz_max));
815 }
816
817 protected:
818
819 std::shared_ptr<Mesh> surface_with_OpenSCAD(
820 const std::filesystem::path& filename, bool center, bool invert
821 );
822
823 std::shared_ptr<Mesh> text_with_OpenSCAD(
824 const std::string& text,
825 double size = 10.0,
826 const std::string& font = "",
827 const std::string& halign = "left",
828 const std::string& valign = "baseline",
829 double spacing = 1.0,
830 const std::string& direction = "ltr",
831 const std::string& language = "en",
832 const std::string& script = "latin"
833 );
834
835 /**** Lower-level functions ****/
836
844 bool find_file(std::filesystem::path& filename);
845
850 const std::filesystem::path& current_path() {
851 geo_assert(file_path_.size() != 0);
852 return *(file_path_.rbegin());
853 }
854
860 std::shared_ptr<Mesh> import_with_openSCAD(
861 const std::filesystem::path& filename, const std::string& layer="",
862 index_t timestamp=0
863 );
864
880 virtual void do_CSG(
881 std::shared_ptr<Mesh>& mesh, const std::string& boolean_expr
882 );
883
907 virtual void triangulate(
908 std::shared_ptr<Mesh>& mesh, const std::string& boolean_expr
909 );
910
916 virtual void triangulate(std::shared_ptr<Mesh>& mesh);
917
924 void keep_z0_only(std::shared_ptr<Mesh>& M);
925
931 virtual void finalize_mesh(std::shared_ptr<Mesh>& mesh);
932
933 CSGScope& top_scope() {
934 geo_debug_assert(!scope_stack_.empty());
935 return scope_stack_.top();
936 }
937
938 void push_scope() {
939 scope_stack_.emplace();
940 }
941
942 void pop_scope() {
943 geo_debug_assert(!scope_stack_.empty());
944 scope_stack_.pop();
945 }
946
947 protected:
948 double STL_epsilon_;
949 index_t max_arity_;
950 bool detect_intersecting_neighbors_;
951 bool delaunay_;
952 bool simplify_coplanar_facets_;
953 double coplanar_angle_tolerance_;
954 bool fast_union_;
955 bool noop_;
956 std::shared_ptr<Mesh> empty_mesh_;
957 std::shared_ptr<Mesh> result_;
958 std::stack<CSGScope> scope_stack_;
959
960 friend class CSGCompiler;
961 };
962
963}
964
965#endif
#define geo_assert(x)
Verifies that a condition is met.
Definition assert.h:149
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:196
A parsed argument list in a .csg file.
Base class for implementing CSG objects and instructions.
AbstractCSGBuilder()
AbstractCSGBuilder constructor.
void set_detailed_verbose(bool x)
Displays (even more) additional information.
void reset_defaults()
Resets defaults value for fn, fs, fa.
void reset_file_path()
Resets the file path to its default value, with only the current directory ".".
bool verbose() const
Tests wheter verbose mode is set.
void set_verbose(bool x)
Displays (lots of) additional information.
void set_fa(double fa)
Sets the minimum angle for a fragment.
void push_file_path(const std::filesystem::path &path)
Adds a path to the file path.
void set_fn(double fn)
Sets the number of fragments.
void pop_file_path()
Removes the latest pushed file path.
virtual ~AbstractCSGBuilder()
AbstractCSGBuilder destructor.
void set_fs(double fs)
Sets the minimum size for a fragment.
void add_file_path(const std::filesystem::path &path)
Adds a path to the file path.
Axis-aligned bounding box.
Definition geometry.h:689
Implements CSG objects and instructions.
std::shared_ptr< Mesh > rotate(double angle, const vec3 &axis, const CSGScope &scope)
Commodity function for rotating a CSGScope using OpenSCAD syntax.
static mat4 scaling_matrix(double sx, double sy, double sz)
Builds a scaling matrix.
void set_delaunay(bool x)
If set, compute constrained Delaunay triangulation in the intersected triangles. If there are interse...
virtual std::shared_ptr< Mesh > rotate_extrude(const CSGScope &scope, double angle=360.0)
Computes a 3D extrusion from a 2D shape.
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.
std::shared_ptr< Mesh > union_instr(Types...args)
Computes the union of two or more meshes.
virtual void do_CSG(std::shared_ptr< Mesh > &mesh, const std::string &boolean_expr)
Apply a CSG operation to a mesh.
virtual std::shared_ptr< Mesh > intersection(const CSGScope &scope)
Computes the intersection between two or more meshes.
virtual std::shared_ptr< Mesh > projection(const CSGScope &scope, bool cut)
Creates a 2D mesh from 3D mesh.
bool find_file(std::filesystem::path &filename)
Finds a file in the path.
virtual std::shared_ptr< Mesh > union_instr(const CSGScope &scope)
Computes the union of two or more meshes.
virtual void triangulate(std::shared_ptr< Mesh > &mesh)
Triangulates a 2D mesh.
static mat4 translation_matrix(const vec3 &T)
Builds a translation matrix.
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_fast_union(bool x)
Sets fast union mode.
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.
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.
std::shared_ptr< Mesh > rotate(double angle, const CSGScope &scope)
Commodity function for 2D-rotating a CSGScope using OpenSCAD syntax.
std::shared_ptr< Mesh > intersection(Types...args)
Computes the mutual intersection between meshes.
virtual std::shared_ptr< Mesh > hull(const CSGScope &scope)
Computes the convex hull of several meshes.
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.
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(const vec3 &angles, const CSGScope &scope)
Commodity function for rotating a CSGScope using OpenSCAD syntax.
virtual std::shared_ptr< Mesh > minkowski(const CSGScope &scope)
Computes the Minkowski sum of meshes.
void set_noop(bool x)
Sets noop mode.
std::shared_ptr< Mesh > difference(Types...args)
Computes the difference between meshes.
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 std::shared_ptr< Mesh > circle(double r=1.0, index_t nu=0)
virtual std::shared_ptr< Mesh > append(const CSGScope &scope)
Appends all meshes in scope into a unique mesh, without testing for intersections.
virtual void finalize_mesh(std::shared_ptr< Mesh > &mesh)
Derived classes may override this function and compute some cached information, e....
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 > group(const CSGScope &scope)
synonym for union.
virtual std::shared_ptr< Mesh > multmatrix(const mat4 &M, const CSGScope &scope)
Groups several meshes into a single one and transforms them.
static mat4 rotation_matrix(double angle, vec3 axis={0.0, 0.0, 0.0})
Builds a rotation matrix.
static std::pair< vec3, vec3 > get_bbox_bounds(const std::shared_ptr< Mesh > &mesh)
Computes the bounding box of a mesh.
virtual void triangulate(std::shared_ptr< Mesh > &mesh, const std::string &boolean_expr)
Triangulates a 2D mesh.
virtual std::shared_ptr< Mesh > difference(const CSGScope &scope)
Computes the intersection between two meshes.
const std::filesystem::path & current_path()
Gets the current path.
A Scope corresponds to a set of primitive between curly braces in OpenSCAD, arguments of an operation...
CSGScope(const std::initializer_list< std::shared_ptr< Mesh > > &Ms)
Constructs a CSGScope from a list of meshes.
CSGScope()
Constructs an empty CSGScope.
CSGScope(std::shared_ptr< Mesh > M)
Constructs a CSGScope that contains a single mesh.
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
Definition basic.h:55
void get_bbox(const Mesh &M, double *xyzmin, double *xyzmax)
Gets the bounding box of a mesh.
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:340
#define M_PI
Value of the constant PI if not defined by the system.
Definition numeric.h:59
A parsed value in a .csg file.