Skip to content

Commit 9ccc59c

Browse files
committed
uses newest ug-dist, offers a repair-only methods for manual post-processing
1 parent ec1e337 commit 9ccc59c

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/build/
44
/.gradle/
55
JCSG-MeshExtensions.iml
6+

gradle/project-info.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// -----------------------------------------------------------------------------
44
ext.publishing.artifactId = project.name.toLowerCase()
55
ext.publishing.groupId = 'eu.mihosoft.jcsg.ext.mesh'
6-
ext.publishing.versionId = '0.4.2'
6+
ext.publishing.versionId = '0.5.0'
77

88
ext.publishing.developerName = 'Michael Hoffer'
99
ext.publishing.developerAlias = 'miho'

src/main/java/eu/mihosoft/jcsg/ext/mesh/MeshTools.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,73 @@ private static CSG optimize(
249249
code = code.replace("$edgeApprox$", "" + edgeApprox);
250250
code = code.replace("$edgeTriangleQuality$", "" + edgeTriangleQuality);
251251

252-
// code = code.replace("$edgeApprox$", "" + edgeApprox);
253-
// code = code.replace("$edgeTriangleQuality$", "" + edgeTriangleQuality);
252+
Shell.execute(tmpDir.toFile(), code).print().waitFor();
253+
254+
return STL.file(stlFile);
255+
256+
} catch (IOException e) {
257+
e.printStackTrace(System.err);
258+
throw new RuntimeException(
259+
"optimization failed due to io exception", e);
260+
}
261+
}
262+
263+
/**
264+
* Repairs the specified csg mesh object.
265+
*
266+
* <b>Note: </b>the size of the
267+
* object during repairs can have a high impact on the overall
268+
* repair quality. Therefore, this method allows the specification of
269+
* the size at which the repair algorithm is performed. After repairing
270+
* the object is returned at original size.
271+
*
272+
* @param csg csg to repair
273+
* @param size object size at which to perform the repair operation (minimum
274+
* dimension)
275+
* @param tol default tolerance
276+
* @param maxTol maximum tolerance
277+
* @return repaired csg mesh object
278+
*/
279+
public static CSG repair(CSG csg, double size, double tol,
280+
double maxTol) {
281+
return scaleMinDimensionTo(csg, size,
282+
(csgObj) -> repair(csgObj, tol, maxTol));
283+
}
284+
285+
/**
286+
* Repairs the specified csg mesh object.
287+
*
288+
* @param csg csg to repair
289+
* @param tol default tolerance
290+
* @param maxTol maximum tolerance
291+
* @return repaired csg mesh object
292+
*/
293+
private static CSG repair(
294+
CSG csg, double tol,
295+
double maxTol) {
296+
try {
297+
298+
Path tmpDir = Files.createTempDirectory("jcsgmeshopt");
299+
Path stlFile = Paths.get(tmpDir.toAbsolutePath().toString(),
300+
"csg.stl");
301+
302+
System.out.println("mesh-ext: csg file: " + stlFile);
303+
304+
Files.write(stlFile, csg.toStlString().getBytes());
305+
306+
String code = read("repair.lua");
307+
308+
String pathVariable = stlFile.toAbsolutePath().toString();//
309+
310+
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
311+
pathVariable = pathVariable.replace("\\", "\\\\");
312+
}
313+
314+
code = code.replace("$fileName$", "\""
315+
+ pathVariable + "\"");
316+
code = code.replace("$removeDoublesTOL$", "" + tol);
317+
code = code.replace("$resolveTOL$", "" + maxTol);
318+
254319
Shell.execute(tmpDir.toFile(), code).print().waitFor();
255320

256321
return STL.file(stlFile);

0 commit comments

Comments
 (0)