]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java
vtk 8.2.0 API changes
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / shape / MeshActor.java
index 042142fccdb9af1898a75785db6d00b9b012b19d..0466a02e3d081facd183b23706691a96c8bc6584 100644 (file)
@@ -1,97 +1,98 @@
-/*******************************************************************************\r
- * Copyright (c) 2012, 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g3d.vtk.shape;\r
-\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.shape.Color4d;\r
-import org.simantics.g3d.shape.Mesh;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkDataSetMapper;\r
-import vtk.vtkIdList;\r
-import vtk.vtkPoints;\r
-import vtk.vtkPolyData;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkPolyDataNormals;\r
-import vtk.vtkTriangle;\r
-import vtk.vtkUnsignedCharArray;\r
-\r
-public class MeshActor extends vtkActor {\r
-       \r
-       public void setMesh(Mesh mesh) {\r
-               \r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               \r
-               vtkPolyData polyData = new vtkPolyData();\r
-               polyData.Allocate(mesh.getIndices().size()/3, mesh.getIndices().size()/3);\r
-               \r
-               vtkTriangle triangle = new vtkTriangle();\r
-        vtkIdList list = triangle.GetPointIds();\r
-        for (int i = 0; i < mesh.getIndices().size(); i+=3) {\r
-               list.SetId(0, mesh.getIndices().get(i));\r
-               list.SetId(1, mesh.getIndices().get(i+1));\r
-               list.SetId(2, mesh.getIndices().get(i+2));\r
-               polyData.InsertNextCell(triangle.GetCellType(), list);\r
-        }\r
-        list.Delete();\r
-        triangle.Delete();\r
-               \r
-        \r
-        vtkPoints points = new vtkPoints();\r
-        for (int i = 0; i < mesh.getVertices().size(); i++) {\r
-               Vector3d p = mesh.getVertices().get(i);\r
-               points.InsertPoint(i, p.x, p.y, p.z);\r
-        }\r
-        \r
-        polyData.SetPoints(points);\r
-        points.Delete();\r
-        \r
-        if (mesh.getColors() != null) {\r
-               vtkUnsignedCharArray colors = new vtkUnsignedCharArray();\r
-               colors.SetName("Colors");\r
-               colors.SetNumberOfComponents(3);\r
-               colors.SetNumberOfTuples(mesh.getColors().size());\r
-               for (int i = 0; i < mesh.getColors().size(); i++) {\r
-                       Color4d c = mesh.getColors().get(i);\r
-                       colors.InsertTuple3(i, 255.0* c.x, 255.0 * c.y, 255.0 * c.z);\r
-               }\r
-               polyData.GetPointData().AddArray(colors);\r
-               colors.Delete();\r
-               \r
-        }\r
-        \r
-        boolean computeNormals = true;\r
-        if (computeNormals) {\r
-               vtkPolyDataNormals normals = new vtkPolyDataNormals();\r
-               normals.SetInput(polyData);\r
-               mapper.SetInputConnection(normals.GetOutputPort());\r
-               normals.GetOutputPort().Delete();\r
-               normals.Delete();\r
-        } else {\r
-               mapper.SetInput(polyData);\r
-        }\r
-        \r
-        if (mesh.getColors() != null) {\r
-                mapper.ScalarVisibilityOn();\r
-                mapper.SetScalarModeToUsePointFieldData();\r
-                mapper.SelectColorArray("Colors");\r
-        }\r
-        \r
-        SetMapper(mapper);\r
-        mapper.Delete();\r
-        polyData.GetPointData().Delete();\r
-        polyData.Delete();\r
-        \r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g3d.vtk.shape;
+
+import javax.vecmath.Tuple3d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.shape.Color4d;
+import org.simantics.g3d.shape.Mesh;
+
+import vtk.vtkActor;
+import vtk.vtkDataSetMapper;
+import vtk.vtkIdList;
+import vtk.vtkPoints;
+import vtk.vtkPolyData;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkPolyDataNormals;
+import vtk.vtkTriangle;
+import vtk.vtkUnsignedCharArray;
+
+public class MeshActor extends vtkActor {
+       
+       public void setMesh(Mesh mesh) {
+               
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               
+               vtkPolyData polyData = new vtkPolyData();
+               polyData.Allocate(mesh.getIndices().size()/3, mesh.getIndices().size()/3);
+               
+               vtkTriangle triangle = new vtkTriangle();
+        vtkIdList list = triangle.GetPointIds();
+        for (int i = 0; i < mesh.getIndices().size(); i+=3) {
+               list.SetId(0, mesh.getIndices().get(i));
+               list.SetId(1, mesh.getIndices().get(i+1));
+               list.SetId(2, mesh.getIndices().get(i+2));
+               polyData.InsertNextCell(triangle.GetCellType(), list);
+        }
+        list.Delete();
+        triangle.Delete();
+               
+        
+        vtkPoints points = new vtkPoints();
+        for (int i = 0; i < mesh.getVertices().size(); i++) {
+               Tuple3d p = mesh.getVertices().get(i);
+               points.InsertPoint(i, p.x, p.y, p.z);
+        }
+        
+        polyData.SetPoints(points);
+        points.Delete();
+        
+        if (mesh.getColors() != null) {
+               vtkUnsignedCharArray colors = new vtkUnsignedCharArray();
+               colors.SetName("Colors");
+               colors.SetNumberOfComponents(3);
+               colors.SetNumberOfTuples(mesh.getColors().size());
+               for (int i = 0; i < mesh.getColors().size(); i++) {
+                       Color4d c = mesh.getColors().get(i);
+                       colors.InsertTuple3(i, 255.0* c.x, 255.0 * c.y, 255.0 * c.z);
+               }
+               polyData.GetPointData().AddArray(colors);
+               colors.Delete();
+               
+        }
+        
+        boolean computeNormals = true;
+        if (computeNormals) {
+               vtkPolyDataNormals normals = new vtkPolyDataNormals();
+               normals.SetInputData(polyData);
+               mapper.SetInputConnection(normals.GetOutputPort());
+               normals.GetOutputPort().Delete();
+               normals.Delete();
+        } else {
+               mapper.SetInputData(polyData);
+        }
+        
+        if (mesh.getColors() != null) {
+                mapper.ScalarVisibilityOn();
+                mapper.SetScalarModeToUsePointFieldData();
+                mapper.SelectColorArray("Colors");
+        }
+        
+        SetMapper(mapper);
+        mapper.Delete();
+        polyData.GetPointData().Delete();
+        polyData.Delete();
+        
+       }
+
+}