@@ -93,49 +93,15 @@ public static CSG optimize(
93
93
double maxEdgeLength ,
94
94
int maxIter ,
95
95
double creaseEdgeAngle ) {
96
- try {
97
-
98
- Path tmpDir = Files .createTempDirectory ("jcsgmeshopt" );
99
- Path stlFile = Paths .get (tmpDir .toAbsolutePath ().toString (),
100
- "csg.stl" );
101
-
102
- System .out .println ("mesh-ext: csg file: " + stlFile );
103
-
104
- Files .write (stlFile , csg .toStlString ().getBytes ());
105
-
106
- String code = read ("optimize-and-repair.lua" );
107
-
108
- String pathVariable = stlFile .toAbsolutePath ().toString ();//
109
-
110
- if (System .getProperty ("os.name" ).toLowerCase ().contains ("windows" )) {
111
- pathVariable = pathVariable .replace ("\\ " , "\\ \\ " );
112
- }
113
-
114
- code = code .replace ("$filename$" , "\" "
115
- + pathVariable + "\" " );
116
- code = code .replace ("$removeDoublesTOL$" , "" + tol );
117
- code = code .replace ("$creaseEdgeAngle$" , "" + creaseEdgeAngle );
118
- code = code .replace ("$resolveTOL$" , "" + maxTol );
119
- code = code .replace ("$minEdgeLength$" , "" + minEdgeLength );
120
- code = code .replace ("$maxEdgeLength$" , "" + maxEdgeLength );
121
- code = code .replace ("$maxAdjIter$" , "" + maxIter );
122
-
123
- // code = code.replace("$edgeApprox$", "" + edgeApprox);
124
- // code = code.replace("$edgeTriangleQuality$", "" + edgeTriangleQuality);
125
- Shell .execute (tmpDir .toFile (), code ).print ().waitFor ();
126
-
127
- return STL .file (stlFile );
128
-
129
- } catch (IOException e ) {
130
- e .printStackTrace (System .err );
131
- throw new RuntimeException (
132
- "optimization failed due to io exception" , e );
133
- }
96
+ return optimize (
97
+ "adjust-edge-length" ,
98
+ csg , tol , maxTol , minEdgeLength , maxEdgeLength ,
99
+ -1 , -1 , maxIter , creaseEdgeAngle );
134
100
}
135
101
136
102
/**
137
103
* Optimizes and repairs the specified csg mesh object.
138
- *
104
+ *
139
105
* <b>Note: </b>the size of the
140
106
* object during optimization can have a high impact on the overall
141
107
* optimization quality. Therefore, this method allows the specification of
@@ -164,8 +130,8 @@ public static CSG optimize(
164
130
}
165
131
166
132
/**
167
- * Optimizes and repairs the specified csg mesh object.
168
- *
133
+ * Optimizes and repairs the specified csg mesh object.
134
+ *
169
135
* <b>Note: </b>the size of the
170
136
* object during optimization can have a high impact on the overall
171
137
* optimization quality. Therefore, this method allows the specification of
@@ -184,18 +150,119 @@ public static CSG optimize(
184
150
* @return optimized csg mesh object
185
151
*/
186
152
public static CSG optimize (CSG csg ,
187
- double size ,
188
- double tol ,
153
+ double size ,
154
+ double tol ,
155
+ double maxTol ,
156
+ double minEdgeLength ,
157
+ double maxEdgeLength ,
158
+ int maxIter ,
159
+ double creaseEdgeAngle ) {
160
+ return scaleMinDimensionTo (csg , size ,
161
+ (csgObj ) -> optimize (csgObj , tol , maxTol ,
162
+ minEdgeLength , maxEdgeLength ));
163
+ }
164
+
165
+ /**
166
+ * Optimizes and repairs the specified csg mesh object.
167
+ *
168
+ * <b>Note: </b>the size of the
169
+ * object during optimization can have a high impact on the overall
170
+ * optimization quality. Therefore, this method allows the specification of
171
+ * the size at which the optimization is performed. After the optimization
172
+ * the object is returned at original size.
173
+ *
174
+ * @param csg csg to optimize
175
+ * @param size object size at which to perform the optimization (minimum
176
+ * dimension)
177
+ * @param tol default tolerance
178
+ * @param maxTol maximum tolerance
179
+ * @param minEdgeLength minimum edge length
180
+ * @param maxEdgeLength maximum edge length
181
+ * @param maxIter number of iterations for edge length adjustment
182
+ * @param creaseEdgeAngle angle threashold for crease edge marker
183
+ * @return optimized csg mesh object
184
+ */
185
+ public static CSG optimize (CSG csg , double size , double tol ,
186
+ double maxTol ,
187
+ double minEdgeLength ,
188
+ double maxEdgeLength ,
189
+ double edgeApprox ,
190
+ double edgeTriangleQuality ,
191
+ int maxIter ,
192
+ double creaseEdgeAngle ) {
193
+ return scaleMinDimensionTo (csg , size ,
194
+ (csgObj ) -> optimize ("adjust-edge-length-extended" , csgObj , tol , maxTol ,
195
+ minEdgeLength , maxEdgeLength ,edgeApprox ,edgeTriangleQuality ,maxIter ,creaseEdgeAngle ));
196
+ }
197
+
198
+ /**
199
+ * Optimizes and repairs the specified csg mesh object.
200
+ *
201
+ * @param csg csg to optimize
202
+ * @param tol default tolerance
203
+ * @param maxTol maximum tolerance
204
+ * @param minEdgeLength minimum edge length
205
+ * @param maxEdgeLength maximum edge length
206
+ * @param maxIter number of iterations for edge length adjustment
207
+ * @param creaseEdgeAngle angle threashold for crease edge marker
208
+ * @return optimized csg mesh object
209
+ */
210
+ private static CSG optimize (
211
+ String optType ,
212
+ CSG csg , double tol ,
189
213
double maxTol ,
190
214
double minEdgeLength ,
191
215
double maxEdgeLength ,
216
+ double edgeApprox ,
217
+ double edgeTriangleQuality ,
192
218
int maxIter ,
193
219
double creaseEdgeAngle ) {
194
- return scaleMinDimensionTo (csg , size ,
195
- (csgObj ) -> optimize (csgObj , tol , maxTol ,
196
- minEdgeLength , maxEdgeLength ));
220
+ try {
221
+
222
+ Path tmpDir = Files .createTempDirectory ("jcsgmeshopt" );
223
+ Path stlFile = Paths .get (tmpDir .toAbsolutePath ().toString (),
224
+ "csg.stl" );
225
+
226
+ System .out .println ("mesh-ext: csg file: " + stlFile );
227
+
228
+ Files .write (stlFile , csg .toStlString ().getBytes ());
229
+
230
+ String code = read ("optimize-and-repair.lua" );
231
+
232
+ String pathVariable = stlFile .toAbsolutePath ().toString ();//
233
+
234
+ if (System .getProperty ("os.name" ).toLowerCase ().contains ("windows" )) {
235
+ pathVariable = pathVariable .replace ("\\ " , "\\ \\ " );
236
+ }
237
+
238
+ code = code .replace ("$optType$" , "\" "
239
+ + optType + "\" " );
240
+ code = code .replace ("$fileName$" , "\" "
241
+ + pathVariable + "\" " );
242
+ code = code .replace ("$removeDoublesTOL$" , "" + tol );
243
+ code = code .replace ("$creaseEdgeAngle$" , "" + creaseEdgeAngle );
244
+ code = code .replace ("$resolveTOL$" , "" + maxTol );
245
+ code = code .replace ("$minEdgeLength$" , "" + minEdgeLength );
246
+ code = code .replace ("$maxEdgeLength$" , "" + maxEdgeLength );
247
+ code = code .replace ("$maxAdjIter$" , "" + maxIter );
248
+
249
+ code = code .replace ("$edgeApprox$" , "" + edgeApprox );
250
+ code = code .replace ("$edgeTriangleQuality$" , "" + edgeTriangleQuality );
251
+
252
+ // code = code.replace("$edgeApprox$", "" + edgeApprox);
253
+ // code = code.replace("$edgeTriangleQuality$", "" + edgeTriangleQuality);
254
+ Shell .execute (tmpDir .toFile (), code ).print ().waitFor ();
255
+
256
+ return STL .file (stlFile );
257
+
258
+ } catch (IOException e ) {
259
+ e .printStackTrace (System .err );
260
+ throw new RuntimeException (
261
+ "optimization failed due to io exception" , e );
262
+ }
197
263
}
198
264
265
+
199
266
/**
200
267
* Scales the minimum CSG dimension to the specified value, invokes the
201
268
* specified function and rescales the specified CSG object to its original
0 commit comments