From: luukkainen Date: Wed, 11 Nov 2015 10:35:40 +0000 (+0000) Subject: Pass OCCT triangulation errors X-Git-Tag: simantics-1.20.0~2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=8b251988283100a0d8cb59dbb288595bc7de3211;p=simantics%2F3d.git Pass OCCT triangulation errors fixes #6141 git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@32035 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java b/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java index 0e2e52ab..6e1e3dd1 100644 --- a/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java +++ b/org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java @@ -21,6 +21,7 @@ import org.jcae.opencascade.jni.TopExp_Explorer; import org.jcae.opencascade.jni.TopoDS_Face; import org.jcae.opencascade.jni.TopoDS_Shape; import org.simantics.opencascade.OCCTTool; +import org.simantics.utils.datastructures.Pair; import org.simantics.utils.threads.AWTThread; import org.simantics.utils.threads.ThreadUtils; @@ -58,6 +59,8 @@ public class vtkSolidObject { private List edges = new ArrayList(1); private vtkActor silhouette = null; + private boolean errors = false; + public vtkSolidObject(vtkPanel panel,TopoDS_Shape shape) { this.shape = shape; this.panel = panel; @@ -73,9 +76,15 @@ public class vtkSolidObject { public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices, boolean showSilhouette) { clearActorsAWT(); - vtkPolyData data = createSolidMesh(shape); - if (data == null) + errors = false; + Pair res = createSolidMesh(shape); + if (res == null) { + errors = true; return; + } + vtkPolyData data = res.first; + if (!res.second) + errors = true; if (showFaces) { solid.add(createActor(data)); } @@ -98,9 +107,15 @@ public class vtkSolidObject { } public void visualizeFaces(boolean showEdges, boolean showVertices) { + errors = false; clearActorsAWT(); Collection datas = createFaceMeshes(shape); for (vtkPolyData data : datas) { + if (data == null) { + errors = true; + continue; + } + solid.add(createActor(data)); if (showEdges) { @@ -118,6 +133,10 @@ public class vtkSolidObject { showActorsAWT(); } + public boolean hasErrors() { + return errors; + } + public List getActors() { assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread()); return actors; @@ -223,7 +242,9 @@ public class vtkSolidObject { private static double TOLERANCE = 0.01; - public static vtkPolyData createSolidMesh(TopoDS_Shape shape) { + public static Pair createSolidMesh(TopoDS_Shape shape) { + + boolean success = true; double volume = OCCTTool.getBoundingBoxDiagonal(shape); if (volume < TOLERANCE) @@ -237,7 +258,8 @@ public class vtkSolidObject { List meshTriangles = new ArrayList(); for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) { TopoDS_Face face = (TopoDS_Face) expFace.current(); - OCCTTool.appendToMesh(face, meshPoints, meshTriangles); + if (!OCCTTool.appendToMesh(face, meshPoints, meshTriangles)) + success = false; face.delete(); } if (meshPoints.size() == 0 || meshTriangles.size() == 0) @@ -248,7 +270,7 @@ public class vtkSolidObject { expFace.delete(); mesh.delete(); - return data; + return new Pair(data, success); } public static Collection createFaceMeshes(TopoDS_Shape shape) {