Geogram Version 1.9.7
A programming library of geometric algorithms
Loading...
Searching...
No Matches
mesh_CSG_utils.h
1/*
2 * Copyright (c) 2000-2025 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_GEOGRAM_MESH_MESH_CSG_UTILS_H
41#define H_GEOGRAM_MESH_MESH_CSG_UTILS_H
42
44#include <geogram/mesh/mesh.h>
45#include <string>
46#include <filesystem>
47#include <memory>
48
49namespace GEOCSG {
50
51 using namespace GEO;
52
53 /**********************************************************************/
54 /**** Values, ArgList ****/
55 /**********************************************************************/
56
61 struct Value {
62 enum Type {NONE, NUMBER, BOOLEAN, ARRAY1D, ARRAY2D, STRING, PATH};
63
64 Value();
65 Value(double x);
66 Value(int x);
67 Value(bool x);
68 Value(const std::string& x);
69 Value(const std::filesystem::path& x);
70 std::string to_string() const;
71
72 Type type;
73 bool boolean_val;
74 double number_val;
75 vector<vector<double> > array_val;
76 std::string string_val;
77 };
78
83 class ArgList {
84 public:
85 typedef std::pair<std::string, Value> Arg;
86
87 void clear() {
88 args_.clear();
89 }
90
91 index_t size() const {
92 return args_.size();
93 }
94
95 const std::string& ith_arg_name(index_t i) const {
96 geo_debug_assert(i < size());
97 return args_[i].first;
98 }
99
100 const Value& ith_arg_val(index_t i) const {
101 geo_debug_assert(i < size());
102 return args_[i].second;
103 }
104
105 void add_arg(const std::string& name, const Value& value);
106 bool has_arg(const std::string& name) const;
107 const Value& get_arg(const std::string& name) const;
108 double get_arg(const std::string& name,double default_val) const;
109 int get_arg(const std::string& name, int default_val) const;
110 bool get_arg(const std::string& name, bool default_val) const;
111 vec2 get_arg(const std::string& name, vec2 default_val) const;
112 vec3 get_arg(const std::string& name, vec3 default_val) const;
113 vec4 get_arg(const std::string& name, vec4 default_val) const;
114 mat4 get_arg(const std::string& name, const mat4& default_val) const;
115 std::string get_arg(
116 const std::string& name, const std::string& default_val
117 ) const;
118 std::string get_arg(
119 const std::string& name, const char* default_val
120 ) const {
121 return get_arg(name, std::string(default_val));
122 }
123 private:
124 vector<Arg> args_;
125 };
126
127 /**********************************************************************/
128 /**** General sweeping function ****/
129 /**********************************************************************/
130
134 enum SweepCapping {
135 SWEEP_CAP,
136 SWEEP_POLE,
137 SWEEP_PERIODIC
138 };
139
161 void GEOGRAM_API sweep(
162 std::shared_ptr<Mesh>& M, index_t nv,
163 std::function<vec3(index_t, index_t)> sweep_path,
164 SweepCapping capping = SWEEP_CAP
165 );
166
172 void GEOGRAM_API keep_z0_only(std::shared_ptr<Mesh>& M);
173
174 /**********************************************************************/
175 /**** Call OpenSCAD for help (and cache result) ****/
176 /**********************************************************************/
177
182 void GEOGRAM_API OpenSCAD_cache_invalidate();
183
190 void GEOGRAM_API OpenSCAD_cache_ignore_time();
191
192 std::shared_ptr<Mesh> GEOGRAM_API call_OpenSCAD(
193 const std::filesystem::path& path, const std::string& command,
194 const ArgList& args, bool TWO_D=false
195 );
196
197 std::string GEOGRAM_API load_OpenSCAD(const std::filesystem::path& filename);
198
199 /**********************************************************************/
200 /**** Functions to estimate number of fragments and slices, ****/
201 /**** taken from OpenSCAD ****/
202 /**********************************************************************/
203
207 int GEOGRAM_API get_fragments_from_r_and_twist(
208 double r, double twist, double fn, double fs, double fa
209 );
210
214 inline int get_fragments_from_r(
215 double r, double fn, double fs, double fa
216 ) {
217 return get_fragments_from_r_and_twist(r, 360.0, fn, fs, fa);
218 }
219
223 int GEOGRAM_API get_linear_extrusion_slices(
224 std::shared_ptr<Mesh> M, double height, vec2 scale, double twist,
225 double fn, double fs, double fa
226 );
227
228}
229
230#endif
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:196
A parsed argument list in a .csg file.
Vector with aligned memory allocation.
Definition memory.h:660
index_t size() const
Gets the number of elements.
Definition memory.h:706
Common include file, providing basic definitions. Should be included before anything else by all head...
The class that represents a mesh.
Global Vorpaline namespace.
Definition basic.h:55
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition geometry.h:65
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
A parsed value in a .csg file.