]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Pass OCCT triangulation errors
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 11 Nov 2015 10:35:40 +0000 (10:35 +0000)
committerluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 11 Nov 2015 10:35:40 +0000 (10:35 +0000)
fixes #6141

git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@32035 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java

index 0e2e52ab3c947c2a04b798ff2c01ff222d6808b1..6e1e3dd1974dae04a20dd451dd3708f194f659bb 100644 (file)
@@ -21,6 +21,7 @@ import org.jcae.opencascade.jni.TopExp_Explorer;
 import org.jcae.opencascade.jni.TopoDS_Face;\r
 import org.jcae.opencascade.jni.TopoDS_Shape;\r
 import org.simantics.opencascade.OCCTTool;\r
+import org.simantics.utils.datastructures.Pair;\r
 import org.simantics.utils.threads.AWTThread;\r
 import org.simantics.utils.threads.ThreadUtils;\r
 \r
@@ -58,6 +59,8 @@ public class vtkSolidObject {
        private List<vtkProp3D> edges =  new ArrayList<vtkProp3D>(1);\r
        private vtkActor silhouette = null;\r
        \r
+       private boolean errors = false;\r
+       \r
        public vtkSolidObject(vtkPanel panel,TopoDS_Shape shape) {\r
                this.shape = shape;\r
                this.panel = panel;\r
@@ -73,9 +76,15 @@ public class vtkSolidObject {
        \r
        public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices, boolean showSilhouette) {\r
                clearActorsAWT();\r
-               vtkPolyData data = createSolidMesh(shape);\r
-               if (data == null)\r
+               errors = false;\r
+               Pair<vtkPolyData, Boolean> res = createSolidMesh(shape);\r
+               if (res == null) {\r
+                       errors = true;\r
                        return;\r
+               }\r
+               vtkPolyData data = res.first;\r
+               if (!res.second)\r
+                       errors = true;\r
                if (showFaces) {\r
                        solid.add(createActor(data));           \r
                }\r
@@ -98,9 +107,15 @@ public class vtkSolidObject {
        }\r
        \r
        public void visualizeFaces(boolean showEdges, boolean showVertices) {\r
+               errors = false;\r
                clearActorsAWT();\r
                Collection<vtkPolyData> datas = createFaceMeshes(shape);\r
                for (vtkPolyData data : datas) {\r
+                       if (data == null) {\r
+                               errors = true;\r
+                               continue;\r
+                       }\r
+                       \r
                        solid.add(createActor(data));\r
                        \r
                        if (showEdges) {\r
@@ -118,6 +133,10 @@ public class vtkSolidObject {
                showActorsAWT();\r
        }\r
        \r
+       public boolean hasErrors() {\r
+               return errors;\r
+       }\r
+       \r
        public List<vtkProp3D> getActors() {\r
                assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
                return actors;\r
@@ -223,7 +242,9 @@ public class vtkSolidObject {
        \r
        private static double TOLERANCE = 0.01;\r
        \r
-       public static vtkPolyData createSolidMesh(TopoDS_Shape shape) {\r
+       public static Pair<vtkPolyData, Boolean> createSolidMesh(TopoDS_Shape shape) {\r
+               \r
+               boolean success = true;\r
                \r
                double volume = OCCTTool.getBoundingBoxDiagonal(shape);\r
                if (volume < TOLERANCE)\r
@@ -237,7 +258,8 @@ public class vtkSolidObject {
                List<Integer> meshTriangles = new ArrayList<Integer>();\r
                for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {\r
                        TopoDS_Face face = (TopoDS_Face) expFace.current();\r
-                       OCCTTool.appendToMesh(face, meshPoints, meshTriangles);\r
+                       if (!OCCTTool.appendToMesh(face, meshPoints, meshTriangles))\r
+                               success = false;\r
                        face.delete();\r
                }\r
                if (meshPoints.size() == 0 || meshTriangles.size() == 0)\r
@@ -248,7 +270,7 @@ public class vtkSolidObject {
                expFace.delete();\r
                mesh.delete();\r
                \r
-               return data;\r
+               return new Pair<vtkPolyData, Boolean>(data, success);\r
        }\r
        \r
        public static Collection<vtkPolyData> createFaceMeshes(TopoDS_Shape shape) {\r