]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
vtk 8.2.0 API changes 78/2878/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 6 May 2019 10:16:16 +0000 (13:16 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 6 May 2019 10:16:16 +0000 (13:16 +0300)
gitlab #2

Change-Id: Ie4041b690cae32cd4f0615233cf03edc013282fc

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/gizmo/TranslateGizmo.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/DualHeadArrowActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/MeshActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/axesActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/axesSphereActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/axisActor.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/shape/vtkShape.java
org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/utils/vtkEffect.java
org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/VTKOCCTool.java
org.simantics.opencascade.vtk/src/org/simantics/opencascade/vtk/vtkSolidObject.java
org.simantics.plant3d/src/org/simantics/plant3d/gizmo/TerminalSelectionGizmo.java

index c747e0b943cadc3bc62a23cde0d64f12b6140fcd..49abd1f271f269b40bab4536c9fc24a63ab9c4a2 100644 (file)
-/*******************************************************************************\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.gizmo;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkDataSetMapper;\r
-import vtk.vtkPoints;\r
-import vtk.vtkPolyData;\r
-import vtk.vtkProp;\r
-import vtk.vtkTriangle;\r
-\r
-public class TranslateGizmo extends vtkGizmo {\r
-       \r
-       \r
-       \r
-       private List<vtkProp> parts;\r
-       \r
-       @Override\r
-       public Collection<vtkProp> getGizmo() {\r
-               if (parts == null) {\r
-                       parts = new ArrayList<vtkProp>();\r
-               \r
-               \r
-                       float size = 2.f;               \r
-               float sizeD2 = 1.f;\r
-               float offset = 0.2f;\r
-                       \r
-               double[] colorX = new double[]{0.5,0.0,0.0};\r
-               double[] colorY = new double[]{0.0,0.5,0.0};\r
-               double[] colorZ = new double[]{0.0,0.0,0.5};\r
-               \r
-               double[] colorXY = add(colorX, colorY);\r
-               double[] colorXZ = add(colorX, colorZ);\r
-               double[] colorYZ = add(colorY, colorZ);\r
-               double[] colorP =  add(colorX,colorY,colorZ);\r
-               \r
-                       vtkActor actorX = new vtkActor();\r
-                       vtkActor actorY = new vtkActor();\r
-                       vtkActor actorZ = new vtkActor();\r
-                       vtkActor actorXY = new vtkActor();\r
-                       vtkActor actorXZ = new vtkActor();\r
-                       vtkActor actorYZ = new vtkActor();\r
-                       vtkActor actorP = new vtkActor();\r
-                       \r
-                       actorX.GetProperty().SetColor(colorX);\r
-                       actorY.GetProperty().SetColor(colorY);\r
-                       actorZ.GetProperty().SetColor(colorZ);\r
-                       actorXY.GetProperty().SetColor(colorXY);\r
-                       actorXZ.GetProperty().SetColor(colorXZ);\r
-                       actorYZ.GetProperty().SetColor(colorYZ);\r
-                       actorP.GetProperty().SetColor(colorP);\r
-                       \r
-                       actorX.GetProperty().SetOpacity(0.5);\r
-                       actorY.GetProperty().SetOpacity(0.5);\r
-                       actorZ.GetProperty().SetOpacity(0.5);\r
-                       actorXY.GetProperty().SetOpacity(0.5);\r
-                       actorXZ.GetProperty().SetOpacity(0.5);\r
-                       actorYZ.GetProperty().SetOpacity(0.5);\r
-                       actorP.GetProperty().SetOpacity(0.5);\r
-                       \r
-                       actorX.GetProperty().BackfaceCullingOff();\r
-                       actorY.GetProperty().BackfaceCullingOff();\r
-                       actorZ.GetProperty().BackfaceCullingOff();\r
-                       actorXY.GetProperty().BackfaceCullingOff();\r
-                       actorXZ.GetProperty().BackfaceCullingOff();\r
-                       actorYZ.GetProperty().BackfaceCullingOff();\r
-                       actorP.GetProperty().BackfaceCullingOff();\r
-                       \r
-                       actorX.SetPickable(1);\r
-                       actorY.SetPickable(1);\r
-                       actorZ.SetPickable(1);\r
-                       actorXY.SetPickable(1);\r
-                       actorXZ.SetPickable(1);\r
-                       actorYZ.SetPickable(1);\r
-                       actorP.SetPickable(1);\r
-                       \r
-                       \r
-                       actorX.GetProperty().LightingOff();\r
-                       actorY.GetProperty().LightingOff();\r
-                       actorZ.GetProperty().LightingOff();\r
-                       actorXY.GetProperty().LightingOff();\r
-                       actorXZ.GetProperty().LightingOff();\r
-                       actorYZ.GetProperty().LightingOff();\r
-                       actorP.GetProperty().LightingOff();\r
-                       \r
-\r
-                       vtkTriangle triangle = new vtkTriangle();\r
-                       \r
-                       // X\r
-                       vtkPolyData actorXData = new vtkPolyData();\r
-                       actorXData.Allocate(6, 6);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 1);\r
-                       triangle.GetPointIds().SetId(1, 2);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 3);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 3);\r
-                       triangle.GetPointIds().SetId(1, 4);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       vtkPoints partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{size,0.,0.});\r
-                       partPoints.InsertPoint(1, new double[]{size-offset,offset,0.});\r
-                       partPoints.InsertPoint(2, new double[]{sizeD2-offset,offset,0.});\r
-                       partPoints.InsertPoint(3, new double[]{sizeD2,0.,0.});\r
-                       partPoints.InsertPoint(4, new double[]{sizeD2-offset,0.,offset});\r
-                       partPoints.InsertPoint(5, new double[]{size-offset,0.,offset});\r
-                       actorXData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       // Y\r
-                       vtkPolyData actorYData = new vtkPolyData();\r
-                       actorYData.Allocate(6, 6);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 1);\r
-                       triangle.GetPointIds().SetId(1, 2);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 3);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 3);\r
-                       triangle.GetPointIds().SetId(1, 4);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{0., size, 0.});\r
-                       partPoints.InsertPoint(1, new double[]{offset, size - offset, 0.});\r
-                       partPoints.InsertPoint(2, new double[]{offset, sizeD2 - offset, 0.});\r
-                       partPoints.InsertPoint(3, new double[]{0., sizeD2, 0.});\r
-                       partPoints.InsertPoint(4, new double[]{0., sizeD2 - offset, offset});\r
-                       partPoints.InsertPoint(5, new double[]{0., size - offset, offset});\r
-                       actorYData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       // Z\r
-                       vtkPolyData actorZData = new vtkPolyData();\r
-                       actorZData.Allocate(6, 6);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 1);\r
-                       triangle.GetPointIds().SetId(1, 2);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 3);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 3);\r
-                       triangle.GetPointIds().SetId(1, 4);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{0., 0.,size});\r
-                       partPoints.InsertPoint(1, new double[]{offset, 0., size - offset});\r
-                       partPoints.InsertPoint(2, new double[]{offset, 0., sizeD2 - offset});\r
-                       partPoints.InsertPoint(3, new double[]{0., 0., sizeD2});\r
-                       partPoints.InsertPoint(4, new double[]{0., offset, sizeD2 - offset});\r
-                       partPoints.InsertPoint(5, new double[]{0., offset, size - offset});\r
-                       actorZData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       // XY\r
-                       vtkPolyData actorXYData = new vtkPolyData();\r
-                       actorXYData.Allocate(4, 4);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 2);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{offset, size-offset, 0.f});\r
-                       partPoints.InsertPoint(1, new double[]{offset, sizeD2 - offset, 0.f});\r
-                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, offset, 0.f});\r
-                       partPoints.InsertPoint(3, new double[]{size-offset, offset, 0.f});\r
-                       actorXYData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       // XZ\r
-                       vtkPolyData actorXZData = new vtkPolyData();\r
-                       actorXZData.Allocate(4, 4);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 2);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorXZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{offset, 0.f, size-offset});\r
-                       partPoints.InsertPoint(1, new double[]{offset, 0.f, sizeD2 - offset});\r
-                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, 0.f, offset});\r
-                       partPoints.InsertPoint(3, new double[]{size-offset, 0.f, offset});\r
-                       actorXZData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       // YZ\r
-                       vtkPolyData actorYZData = new vtkPolyData();\r
-                       actorYZData.Allocate(4, 4);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 2);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorYZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorYZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{0.f,offset, size-offset});\r
-                       partPoints.InsertPoint(1, new double[]{0.f,offset, sizeD2 - offset});\r
-                       partPoints.InsertPoint(2, new double[]{0.f,sizeD2 - offset, offset});\r
-                       partPoints.InsertPoint(3, new double[]{0.f,size-offset, offset});\r
-                       \r
-                       actorYZData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       vtkPolyData actorPData = new vtkPolyData();\r
-                       actorPData.Allocate(10, 10);\r
-                       \r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 1);\r
-                       triangle.GetPointIds().SetId(2, 2);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 2);\r
-                       triangle.GetPointIds().SetId(2, 3);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 3);\r
-                       triangle.GetPointIds().SetId(2, 4);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 4);\r
-                       triangle.GetPointIds().SetId(2, 5);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 5);\r
-                       triangle.GetPointIds().SetId(2, 6);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 6);\r
-                       triangle.GetPointIds().SetId(2, 7);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 7);\r
-                       triangle.GetPointIds().SetId(2, 8);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 8);\r
-                       triangle.GetPointIds().SetId(2, 9);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       triangle.GetPointIds().SetId(0, 0);\r
-                       triangle.GetPointIds().SetId(1, 9);\r
-                       triangle.GetPointIds().SetId(2, 1);\r
-                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());\r
-                       \r
-                       partPoints = new vtkPoints();\r
-                       partPoints.InsertPoint(0, new double[]{0.f, 0.f, 0.f});\r
-                       partPoints.InsertPoint(1, new double[]{sizeD2, 0.f, 0.f});\r
-                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, offset, 0.f});\r
-                       partPoints.InsertPoint(3, new double[]{offset, sizeD2 - offset, 0.f});\r
-                       partPoints.InsertPoint(4, new double[]{0.f, sizeD2, 0.f});\r
-                       partPoints.InsertPoint(5, new double[]{0.f, sizeD2 - offset, offset});\r
-                       partPoints.InsertPoint(6, new double[]{0.f, offset, sizeD2-offset});\r
-                       partPoints.InsertPoint(7, new double[]{0.f, 0.f, sizeD2});\r
-                       partPoints.InsertPoint(8, new double[]{offset, 0.f, sizeD2-offset});\r
-                       partPoints.InsertPoint(9, new double[]{sizeD2-offset, 0.f, offset});\r
-                       actorPData.SetPoints(partPoints);\r
-                       partPoints.Delete();\r
-                       \r
-                       \r
-                       vtkDataSetMapper partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorXData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorX.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorYData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorY.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorZData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorZ.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorXYData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorXY.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorXZData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorXZ.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorYZData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorYZ.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       partMapper = new vtkDataSetMapper();\r
-                       partMapper.SetInput(actorPData);\r
-                       partMapper.ScalarVisibilityOn();\r
-                       actorP.SetMapper(partMapper);\r
-                       partMapper.Delete();\r
-                       \r
-                       \r
-                       actorXData.Delete();\r
-                       actorYData.Delete();\r
-                       actorZData.Delete();\r
-                       actorXYData.Delete();\r
-                       actorXZData.Delete();\r
-                       actorYZData.Delete();\r
-                       actorPData.Delete();\r
-                       \r
-                       parts.add(actorX);\r
-                       parts.add(actorY);\r
-                       parts.add(actorZ);\r
-                       parts.add(actorXY);\r
-                       parts.add(actorXZ);\r
-                       parts.add(actorYZ);\r
-                       parts.add(actorP);\r
-               }\r
-               return parts;\r
-       }\r
-       \r
-       public int getTranslateAxis(vtkActor actor) {\r
-               if (actor == null)\r
-                       return -1;\r
-               return parts.indexOf(actor);\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.gizmo;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import vtk.vtkActor;
+import vtk.vtkDataSetMapper;
+import vtk.vtkPoints;
+import vtk.vtkPolyData;
+import vtk.vtkProp;
+import vtk.vtkTriangle;
+
+public class TranslateGizmo extends vtkGizmo {
+       
+       
+       
+       private List<vtkProp> parts;
+       
+       @Override
+       public Collection<vtkProp> getGizmo() {
+               if (parts == null) {
+                       parts = new ArrayList<vtkProp>();
+               
+               
+                       float size = 2.f;               
+               float sizeD2 = 1.f;
+               float offset = 0.2f;
+                       
+               double[] colorX = new double[]{0.5,0.0,0.0};
+               double[] colorY = new double[]{0.0,0.5,0.0};
+               double[] colorZ = new double[]{0.0,0.0,0.5};
+               
+               double[] colorXY = add(colorX, colorY);
+               double[] colorXZ = add(colorX, colorZ);
+               double[] colorYZ = add(colorY, colorZ);
+               double[] colorP =  add(colorX,colorY,colorZ);
+               
+                       vtkActor actorX = new vtkActor();
+                       vtkActor actorY = new vtkActor();
+                       vtkActor actorZ = new vtkActor();
+                       vtkActor actorXY = new vtkActor();
+                       vtkActor actorXZ = new vtkActor();
+                       vtkActor actorYZ = new vtkActor();
+                       vtkActor actorP = new vtkActor();
+                       
+                       actorX.GetProperty().SetColor(colorX);
+                       actorY.GetProperty().SetColor(colorY);
+                       actorZ.GetProperty().SetColor(colorZ);
+                       actorXY.GetProperty().SetColor(colorXY);
+                       actorXZ.GetProperty().SetColor(colorXZ);
+                       actorYZ.GetProperty().SetColor(colorYZ);
+                       actorP.GetProperty().SetColor(colorP);
+                       
+                       actorX.GetProperty().SetOpacity(0.5);
+                       actorY.GetProperty().SetOpacity(0.5);
+                       actorZ.GetProperty().SetOpacity(0.5);
+                       actorXY.GetProperty().SetOpacity(0.5);
+                       actorXZ.GetProperty().SetOpacity(0.5);
+                       actorYZ.GetProperty().SetOpacity(0.5);
+                       actorP.GetProperty().SetOpacity(0.5);
+                       
+                       actorX.GetProperty().BackfaceCullingOff();
+                       actorY.GetProperty().BackfaceCullingOff();
+                       actorZ.GetProperty().BackfaceCullingOff();
+                       actorXY.GetProperty().BackfaceCullingOff();
+                       actorXZ.GetProperty().BackfaceCullingOff();
+                       actorYZ.GetProperty().BackfaceCullingOff();
+                       actorP.GetProperty().BackfaceCullingOff();
+                       
+                       actorX.SetPickable(1);
+                       actorY.SetPickable(1);
+                       actorZ.SetPickable(1);
+                       actorXY.SetPickable(1);
+                       actorXZ.SetPickable(1);
+                       actorYZ.SetPickable(1);
+                       actorP.SetPickable(1);
+                       
+                       
+                       actorX.GetProperty().LightingOff();
+                       actorY.GetProperty().LightingOff();
+                       actorZ.GetProperty().LightingOff();
+                       actorXY.GetProperty().LightingOff();
+                       actorXZ.GetProperty().LightingOff();
+                       actorYZ.GetProperty().LightingOff();
+                       actorP.GetProperty().LightingOff();
+                       
+
+                       vtkTriangle triangle = new vtkTriangle();
+                       
+                       // X
+                       vtkPolyData actorXData = new vtkPolyData();
+                       actorXData.Allocate(6, 6);
+                       
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 1);
+                       triangle.GetPointIds().SetId(1, 2);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 3);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 3);
+                       triangle.GetPointIds().SetId(1, 4);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorXData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       vtkPoints partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{size,0.,0.});
+                       partPoints.InsertPoint(1, new double[]{size-offset,offset,0.});
+                       partPoints.InsertPoint(2, new double[]{sizeD2-offset,offset,0.});
+                       partPoints.InsertPoint(3, new double[]{sizeD2,0.,0.});
+                       partPoints.InsertPoint(4, new double[]{sizeD2-offset,0.,offset});
+                       partPoints.InsertPoint(5, new double[]{size-offset,0.,offset});
+                       actorXData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       // Y
+                       vtkPolyData actorYData = new vtkPolyData();
+                       actorYData.Allocate(6, 6);
+                       
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 1);
+                       triangle.GetPointIds().SetId(1, 2);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 3);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 3);
+                       triangle.GetPointIds().SetId(1, 4);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{0., size, 0.});
+                       partPoints.InsertPoint(1, new double[]{offset, size - offset, 0.});
+                       partPoints.InsertPoint(2, new double[]{offset, sizeD2 - offset, 0.});
+                       partPoints.InsertPoint(3, new double[]{0., sizeD2, 0.});
+                       partPoints.InsertPoint(4, new double[]{0., sizeD2 - offset, offset});
+                       partPoints.InsertPoint(5, new double[]{0., size - offset, offset});
+                       actorYData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       // Z
+                       vtkPolyData actorZData = new vtkPolyData();
+                       actorZData.Allocate(6, 6);
+                       
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 1);
+                       triangle.GetPointIds().SetId(1, 2);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 3);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 3);
+                       triangle.GetPointIds().SetId(1, 4);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{0., 0.,size});
+                       partPoints.InsertPoint(1, new double[]{offset, 0., size - offset});
+                       partPoints.InsertPoint(2, new double[]{offset, 0., sizeD2 - offset});
+                       partPoints.InsertPoint(3, new double[]{0., 0., sizeD2});
+                       partPoints.InsertPoint(4, new double[]{0., offset, sizeD2 - offset});
+                       partPoints.InsertPoint(5, new double[]{0., offset, size - offset});
+                       actorZData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       // XY
+                       vtkPolyData actorXYData = new vtkPolyData();
+                       actorXYData.Allocate(4, 4);
+                       
+                       triangle.GetPointIds().SetId(0, 2);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXYData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{offset, size-offset, 0.f});
+                       partPoints.InsertPoint(1, new double[]{offset, sizeD2 - offset, 0.f});
+                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, offset, 0.f});
+                       partPoints.InsertPoint(3, new double[]{size-offset, offset, 0.f});
+                       actorXYData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       // XZ
+                       vtkPolyData actorXZData = new vtkPolyData();
+                       actorXZData.Allocate(4, 4);
+                       
+                       triangle.GetPointIds().SetId(0, 2);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorXZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{offset, 0.f, size-offset});
+                       partPoints.InsertPoint(1, new double[]{offset, 0.f, sizeD2 - offset});
+                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, 0.f, offset});
+                       partPoints.InsertPoint(3, new double[]{size-offset, 0.f, offset});
+                       actorXZData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       // YZ
+                       vtkPolyData actorYZData = new vtkPolyData();
+                       actorYZData.Allocate(4, 4);
+                       
+                       triangle.GetPointIds().SetId(0, 2);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorYZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorYZData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{0.f,offset, size-offset});
+                       partPoints.InsertPoint(1, new double[]{0.f,offset, sizeD2 - offset});
+                       partPoints.InsertPoint(2, new double[]{0.f,sizeD2 - offset, offset});
+                       partPoints.InsertPoint(3, new double[]{0.f,size-offset, offset});
+                       
+                       actorYZData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       vtkPolyData actorPData = new vtkPolyData();
+                       actorPData.Allocate(10, 10);
+                       
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 1);
+                       triangle.GetPointIds().SetId(2, 2);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 2);
+                       triangle.GetPointIds().SetId(2, 3);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 3);
+                       triangle.GetPointIds().SetId(2, 4);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 4);
+                       triangle.GetPointIds().SetId(2, 5);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 5);
+                       triangle.GetPointIds().SetId(2, 6);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 6);
+                       triangle.GetPointIds().SetId(2, 7);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 7);
+                       triangle.GetPointIds().SetId(2, 8);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 8);
+                       triangle.GetPointIds().SetId(2, 9);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       triangle.GetPointIds().SetId(0, 0);
+                       triangle.GetPointIds().SetId(1, 9);
+                       triangle.GetPointIds().SetId(2, 1);
+                       actorPData.InsertNextCell(triangle.GetCellType(), triangle.GetPointIds());
+                       
+                       partPoints = new vtkPoints();
+                       partPoints.InsertPoint(0, new double[]{0.f, 0.f, 0.f});
+                       partPoints.InsertPoint(1, new double[]{sizeD2, 0.f, 0.f});
+                       partPoints.InsertPoint(2, new double[]{sizeD2 - offset, offset, 0.f});
+                       partPoints.InsertPoint(3, new double[]{offset, sizeD2 - offset, 0.f});
+                       partPoints.InsertPoint(4, new double[]{0.f, sizeD2, 0.f});
+                       partPoints.InsertPoint(5, new double[]{0.f, sizeD2 - offset, offset});
+                       partPoints.InsertPoint(6, new double[]{0.f, offset, sizeD2-offset});
+                       partPoints.InsertPoint(7, new double[]{0.f, 0.f, sizeD2});
+                       partPoints.InsertPoint(8, new double[]{offset, 0.f, sizeD2-offset});
+                       partPoints.InsertPoint(9, new double[]{sizeD2-offset, 0.f, offset});
+                       actorPData.SetPoints(partPoints);
+                       partPoints.Delete();
+                       
+                       
+                       vtkDataSetMapper partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorXData);
+                       partMapper.ScalarVisibilityOn();
+                       actorX.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorYData);
+                       partMapper.ScalarVisibilityOn();
+                       actorY.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorZData);
+                       partMapper.ScalarVisibilityOn();
+                       actorZ.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorXYData);
+                       partMapper.ScalarVisibilityOn();
+                       actorXY.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorXZData);
+                       partMapper.ScalarVisibilityOn();
+                       actorXZ.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorYZData);
+                       partMapper.ScalarVisibilityOn();
+                       actorYZ.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       partMapper = new vtkDataSetMapper();
+                       partMapper.SetInputData(actorPData);
+                       partMapper.ScalarVisibilityOn();
+                       actorP.SetMapper(partMapper);
+                       partMapper.Delete();
+                       
+                       
+                       actorXData.Delete();
+                       actorYData.Delete();
+                       actorZData.Delete();
+                       actorXYData.Delete();
+                       actorXZData.Delete();
+                       actorYZData.Delete();
+                       actorPData.Delete();
+                       
+                       parts.add(actorX);
+                       parts.add(actorY);
+                       parts.add(actorZ);
+                       parts.add(actorXY);
+                       parts.add(actorXZ);
+                       parts.add(actorYZ);
+                       parts.add(actorP);
+               }
+               return parts;
+       }
+       
+       public int getTranslateAxis(vtkActor actor) {
+               if (actor == null)
+                       return -1;
+               return parts.indexOf(actor);
+       }
+       
+
+}
index 25274e8339396067fff1cd645e366d16cceebbbd..2df9ffb0aeede8e5a56e83fa39e2c80b9713d1be 100644 (file)
-/*******************************************************************************\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.AxisAngle4d;\r
-import javax.vecmath.Matrix4d;\r
-import javax.vecmath.Point3d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.utils.threads.AWTThread;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkAssembly;\r
-import vtk.vtkConeSource;\r
-import vtk.vtkLineSource;\r
-import vtk.vtkLinearTransform;\r
-import vtk.vtkMatrix4x4;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkTextActor;\r
-import vtk.vtkTubeFilter;\r
-\r
-public class DualHeadArrowActor extends vtkAssembly implements IvtkVisualObject{\r
-\r
-       private vtkRenderer ren;\r
-       private Vector3d axisDir = new Vector3d(1,0,0);\r
-       private vtkTextActor tactor;\r
-       private vtkActor tubeActor;\r
-       private vtkActor coneActor;\r
-       private vtkActor coneActor2;\r
-       private boolean rendered = false;\r
-\r
-       public DualHeadArrowActor(vtkRenderer _ren, String label) {\r
-               super();\r
-               ren = _ren;\r
-               createAxis(label);\r
-       }\r
-       \r
-       public DualHeadArrowActor(vtkRenderer _ren, String label, Vector3d dir) {\r
-               super();\r
-               ren = _ren;\r
-               this.axisDir = dir;\r
-               if (dir.lengthSquared() < MathTools.NEAR_ZERO)\r
-                       throw new IllegalArgumentException("Direction vector length must mer larger than zero");\r
-               createAxis(label);\r
-       }\r
-\r
-       public void createAxis(String label) {\r
-               double coneScale = 0.3 * axisDir.length();\r
-               Vector3d coneOffset = new Vector3d(axisDir);\r
-               coneOffset.normalize();\r
-               coneOffset.scale(coneScale*0.5);\r
-               \r
-               vtkLineSource line = new vtkLineSource();\r
-               //line.SetPoint1(0.0,0.0,0.0);\r
-               line.SetPoint1(coneOffset.x,coneOffset.y,coneOffset.z);\r
-               line.SetPoint2(axisDir.x-coneOffset.x,axisDir.y-coneOffset.y,axisDir.z-coneOffset.z);\r
-               \r
-               tactor = new vtkTextActor();\r
-               \r
-               tactor.SetInput(label);\r
-               \r
-               tactor.SetTextScaleModeToNone();\r
-               tactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               tactor.GetTextProperty().ShadowOff();\r
-               tactor.GetTextProperty().ItalicOff();\r
-               tactor.GetTextProperty().BoldOff();\r
-               \r
-               tactor.GetTextProperty().Delete();\r
-               \r
-               tactor.SetMaximumLineHeight(0.25);\r
-               \r
-               tactor.SetPickable(0);\r
-               \r
-               vtkTubeFilter tube = new vtkTubeFilter();\r
-               tube.SetInput(line.GetOutput());\r
-               tube.SetRadius(0.05 * axisDir.length());\r
-               tube.SetNumberOfSides(8);\r
-\r
-               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();\r
-               tubeMapper.SetInput(tube.GetOutput());\r
-\r
-               tubeActor = new vtkActor();\r
-               tubeActor.SetMapper(tubeMapper);\r
-               tubeActor.PickableOff();\r
-\r
-               int coneRes = 12;\r
-               \r
-\r
-               \r
-               \r
-               // --- x-Cone\r
-               vtkConeSource cone = new vtkConeSource();\r
-               cone.SetResolution(coneRes);\r
-               vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();\r
-               coneMapper.SetInput(cone.GetOutput());\r
-               coneActor = new vtkActor();\r
-               coneActor.SetMapper(coneMapper);\r
-               coneActor.GetProperty().SetColor(1, 0, 0);\r
-               coneActor.SetScale(coneScale, coneScale, coneScale);\r
-               coneActor.SetPosition(axisDir.x-coneOffset.x,axisDir.y-coneOffset.y,axisDir.z-coneOffset.z);\r
-               coneActor.SetPickable(0);\r
-               \r
-               AxisAngle4d aa = MathTools.createRotation(new Vector3d(1,0,0), axisDir);\r
-               if (aa != null)\r
-                       coneActor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);\r
-               \r
-               \r
-               coneActor2 = new vtkActor();\r
-               coneActor2.SetMapper(coneMapper);\r
-               coneActor2.GetProperty().SetColor(1, 0, 0);\r
-               coneActor2.SetScale(coneScale, coneScale, coneScale);\r
-               coneActor2.SetPosition(coneOffset.x,coneOffset.y,coneOffset.z);\r
-               coneActor2.SetPickable(0);\r
-               \r
-               aa = MathTools.createRotation(new Vector3d(-1,0,0), axisDir);\r
-               if (aa != null)\r
-                       coneActor2.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);\r
-               \r
-               this.AddPart(tubeActor);\r
-               this.AddPart(coneActor);\r
-               this.AddPart(coneActor2);\r
-               \r
-               tube.GetOutput().Delete();\r
-               cone.GetOutput().Delete();\r
-               line.GetOutput().Delete();\r
-               \r
-               tubeMapper.Delete();\r
-               tube.Delete();\r
-               cone.Delete();\r
-               line.Delete();\r
-\r
-               coneMapper.Delete();\r
-               \r
-               coneActor.GetProperty().Delete();\r
-               coneActor2.GetProperty().Delete();\r
-       }\r
-       \r
-       public void addToRenderer() {\r
-               if (rendered)\r
-                       return;\r
-               rendered = true;\r
-               \r
-               ren.AddActor2D(tactor);\r
-               \r
-               ren.AddActor(this);\r
-       }\r
-       \r
-       public void removeFromRenderer() {\r
-               if (!rendered)\r
-                       return;\r
-               rendered = false;\r
-               ren.RemoveActor2D(tactor);\r
-               ren.RemoveActor(this);\r
-       }\r
-       \r
-       public boolean isRendered() {\r
-               return rendered;\r
-       }\r
-\r
-       public void setAxesVisibility(boolean ison) {\r
-               this.SetVisibility(ison ? 1 : 0);\r
-               tactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       public void setLabelVisibility(boolean ison) {\r
-               tactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       double mat[] = new double[16];\r
-       Matrix4d m = new Matrix4d();\r
-       private void updateTextLoc() {\r
-               tactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               \r
-               \r
-               GetMatrix(mat);\r
-               MathTools.set(m,mat);\r
-               Point3d p = new Point3d(axisDir.x*0.5, axisDir.y*0.5,axisDir.z*0.5);\r
-               m.transform(p);\r
-               tactor.GetPositionCoordinate().SetValue(p.x, p.y, p.z);\r
-               \r
-               tactor.GetPositionCoordinate().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPickable(int id0) {\r
-               super.SetPickable(id0);\r
-               tubeActor.SetPickable(id0);\r
-               coneActor.SetPickable(id0);\r
-               coneActor2.SetPickable(id0);\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double id0, double id1, double id2) {\r
-               super.SetOrientation(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void RotateWXYZ(double id0, double id1, double id2, double id3) {\r
-               super.RotateWXYZ(id0, id1, id2, id3);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double[] id0) {\r
-               super.SetPosition(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double id0, double id1, double id2) {\r
-               super.SetPosition(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double[] id0) {\r
-               super.SetOrientation(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0, double id1, double id2) {\r
-               super.SetScale(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double[] id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       public void SetColor(double r, double g, double b) {\r
-               coneActor.GetProperty().SetColor(r, g, b);\r
-               coneActor2.GetProperty().SetColor(r, g, b);\r
-               tubeActor.GetProperty().SetColor(r, g, b);\r
-               coneActor.GetProperty().Delete();\r
-               coneActor2.GetProperty().Delete();\r
-               tubeActor.GetProperty().Delete();\r
-       }\r
-       \r
-       public void SetTextColor(double r, double g, double b) {\r
-               tactor.GetTextProperty().SetColor(r, g, b);\r
-               tactor.GetTextProperty().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserMatrix(vtkMatrix4x4 id0) {\r
-               super.SetUserMatrix(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserTransform(vtkLinearTransform id0) {\r
-               super.SetUserTransform(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void Delete() {\r
-               ren.RemoveActor(tactor);\r
-               ren.RemoveActor(tubeActor);\r
-               ren.RemoveActor(coneActor);\r
-               ren.RemoveActor(coneActor2);\r
-               tactor.Delete();\r
-               tubeActor.Delete();\r
-               coneActor.Delete();\r
-               coneActor2.Delete();\r
-               super.Delete();\r
-       }\r
-\r
-       public void dispose() {\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               removeFromRenderer();\r
-                               Delete();\r
-                       }\r
-               });\r
-       }\r
-       \r
-       @Override\r
-       public vtkProp3D getVtkProp() {\r
-               return this;\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.AxisAngle4d;
+import javax.vecmath.Matrix4d;
+import javax.vecmath.Point3d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.math.MathTools;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.ThreadUtils;
+
+import vtk.vtkActor;
+import vtk.vtkAssembly;
+import vtk.vtkConeSource;
+import vtk.vtkLineSource;
+import vtk.vtkLinearTransform;
+import vtk.vtkMatrix4x4;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkProp3D;
+import vtk.vtkRenderer;
+import vtk.vtkTextActor;
+import vtk.vtkTubeFilter;
+
+public class DualHeadArrowActor extends vtkAssembly implements IvtkVisualObject{
+
+       private vtkRenderer ren;
+       private Vector3d axisDir = new Vector3d(1,0,0);
+       private vtkTextActor tactor;
+       private vtkActor tubeActor;
+       private vtkActor coneActor;
+       private vtkActor coneActor2;
+       private boolean rendered = false;
+
+       public DualHeadArrowActor(vtkRenderer _ren, String label) {
+               super();
+               ren = _ren;
+               createAxis(label);
+       }
+       
+       public DualHeadArrowActor(vtkRenderer _ren, String label, Vector3d dir) {
+               super();
+               ren = _ren;
+               this.axisDir = dir;
+               if (dir.lengthSquared() < MathTools.NEAR_ZERO)
+                       throw new IllegalArgumentException("Direction vector length must mer larger than zero");
+               createAxis(label);
+       }
+
+       public void createAxis(String label) {
+               double coneScale = 0.3 * axisDir.length();
+               Vector3d coneOffset = new Vector3d(axisDir);
+               coneOffset.normalize();
+               coneOffset.scale(coneScale*0.5);
+               
+               vtkLineSource line = new vtkLineSource();
+               //line.SetPoint1(0.0,0.0,0.0);
+               line.SetPoint1(coneOffset.x,coneOffset.y,coneOffset.z);
+               line.SetPoint2(axisDir.x-coneOffset.x,axisDir.y-coneOffset.y,axisDir.z-coneOffset.z);
+               
+               tactor = new vtkTextActor();
+               
+               tactor.SetInput(label);
+               
+               tactor.SetTextScaleModeToNone();
+               tactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               tactor.GetTextProperty().ShadowOff();
+               tactor.GetTextProperty().ItalicOff();
+               tactor.GetTextProperty().BoldOff();
+               
+               tactor.GetTextProperty().Delete();
+               
+               tactor.SetMaximumLineHeight(0.25);
+               
+               tactor.SetPickable(0);
+               
+               vtkTubeFilter tube = new vtkTubeFilter();
+               tube.SetInputData(line.GetOutput());
+               tube.SetRadius(0.05 * axisDir.length());
+               tube.SetNumberOfSides(8);
+
+               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
+               tubeMapper.SetInputData(tube.GetOutput());
+
+               tubeActor = new vtkActor();
+               tubeActor.SetMapper(tubeMapper);
+               tubeActor.PickableOff();
+
+               int coneRes = 12;
+               
+
+               
+               
+               // --- x-Cone
+               vtkConeSource cone = new vtkConeSource();
+               cone.SetResolution(coneRes);
+               vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
+               coneMapper.SetInputData(cone.GetOutput());
+               coneActor = new vtkActor();
+               coneActor.SetMapper(coneMapper);
+               coneActor.GetProperty().SetColor(1, 0, 0);
+               coneActor.SetScale(coneScale, coneScale, coneScale);
+               coneActor.SetPosition(axisDir.x-coneOffset.x,axisDir.y-coneOffset.y,axisDir.z-coneOffset.z);
+               coneActor.SetPickable(0);
+               
+               AxisAngle4d aa = MathTools.createRotation(new Vector3d(1,0,0), axisDir);
+               if (aa != null)
+                       coneActor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);
+               
+               
+               coneActor2 = new vtkActor();
+               coneActor2.SetMapper(coneMapper);
+               coneActor2.GetProperty().SetColor(1, 0, 0);
+               coneActor2.SetScale(coneScale, coneScale, coneScale);
+               coneActor2.SetPosition(coneOffset.x,coneOffset.y,coneOffset.z);
+               coneActor2.SetPickable(0);
+               
+               aa = MathTools.createRotation(new Vector3d(-1,0,0), axisDir);
+               if (aa != null)
+                       coneActor2.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);
+               
+               this.AddPart(tubeActor);
+               this.AddPart(coneActor);
+               this.AddPart(coneActor2);
+               
+               tube.GetOutput().Delete();
+               cone.GetOutput().Delete();
+               line.GetOutput().Delete();
+               
+               tubeMapper.Delete();
+               tube.Delete();
+               cone.Delete();
+               line.Delete();
+
+               coneMapper.Delete();
+               
+               coneActor.GetProperty().Delete();
+               coneActor2.GetProperty().Delete();
+       }
+       
+       public void addToRenderer() {
+               if (rendered)
+                       return;
+               rendered = true;
+               
+               ren.AddActor2D(tactor);
+               
+               ren.AddActor(this);
+       }
+       
+       public void removeFromRenderer() {
+               if (!rendered)
+                       return;
+               rendered = false;
+               ren.RemoveActor2D(tactor);
+               ren.RemoveActor(this);
+       }
+       
+       public boolean isRendered() {
+               return rendered;
+       }
+
+       public void setAxesVisibility(boolean ison) {
+               this.SetVisibility(ison ? 1 : 0);
+               tactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       public void setLabelVisibility(boolean ison) {
+               tactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       double mat[] = new double[16];
+       Matrix4d m = new Matrix4d();
+       private void updateTextLoc() {
+               tactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               
+               
+               GetMatrix(mat);
+               MathTools.set(m,mat);
+               Point3d p = new Point3d(axisDir.x*0.5, axisDir.y*0.5,axisDir.z*0.5);
+               m.transform(p);
+               tactor.GetPositionCoordinate().SetValue(p.x, p.y, p.z);
+               
+               tactor.GetPositionCoordinate().Delete();
+       }
+       
+       @Override
+       public void SetPickable(int id0) {
+               super.SetPickable(id0);
+               tubeActor.SetPickable(id0);
+               coneActor.SetPickable(id0);
+               coneActor2.SetPickable(id0);
+       }
+       
+       @Override
+       public void SetOrientation(double id0, double id1, double id2) {
+               super.SetOrientation(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void RotateWXYZ(double id0, double id1, double id2, double id3) {
+               super.RotateWXYZ(id0, id1, id2, id3);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double[] id0) {
+               super.SetPosition(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double id0, double id1, double id2) {
+               super.SetPosition(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetOrientation(double[] id0) {
+               super.SetOrientation(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0, double id1, double id2) {
+               super.SetScale(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double[] id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       public void SetColor(double r, double g, double b) {
+               coneActor.GetProperty().SetColor(r, g, b);
+               coneActor2.GetProperty().SetColor(r, g, b);
+               tubeActor.GetProperty().SetColor(r, g, b);
+               coneActor.GetProperty().Delete();
+               coneActor2.GetProperty().Delete();
+               tubeActor.GetProperty().Delete();
+       }
+       
+       public void SetTextColor(double r, double g, double b) {
+               tactor.GetTextProperty().SetColor(r, g, b);
+               tactor.GetTextProperty().Delete();
+       }
+       
+       @Override
+       public void SetUserMatrix(vtkMatrix4x4 id0) {
+               super.SetUserMatrix(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserTransform(vtkLinearTransform id0) {
+               super.SetUserTransform(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void Delete() {
+               ren.RemoveActor(tactor);
+               ren.RemoveActor(tubeActor);
+               ren.RemoveActor(coneActor);
+               ren.RemoveActor(coneActor2);
+               tactor.Delete();
+               tubeActor.Delete();
+               coneActor.Delete();
+               coneActor2.Delete();
+               super.Delete();
+       }
+
+       public void dispose() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               removeFromRenderer();
+                               Delete();
+                       }
+               });
+       }
+       
+       @Override
+       public vtkProp3D getVtkProp() {
+               return this;
+       }
+       
+}
index 0cfc8246bcc155d43e25edf0dcb550800369669a..0466a02e3d081facd183b23706691a96c8bc6584 100644 (file)
@@ -74,12 +74,12 @@ public class MeshActor extends vtkActor {
         boolean computeNormals = true;
         if (computeNormals) {
                vtkPolyDataNormals normals = new vtkPolyDataNormals();
-               normals.SetInput(polyData);
+               normals.SetInputData(polyData);
                mapper.SetInputConnection(normals.GetOutputPort());
                normals.GetOutputPort().Delete();
                normals.Delete();
         } else {
-               mapper.SetInput(polyData);
+               mapper.SetInputData(polyData);
         }
         
         if (mesh.getColors() != null) {
index 1b1a6150eef6da6d0b57d5f7228c04f0c9fe75bc..7bc9fbbbfdc21774b32718f09c484484a14d862c 100644 (file)
-/*******************************************************************************\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.Matrix4d;\r
-import javax.vecmath.Point3d;\r
-\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.utils.threads.AWTThread;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkAssembly;\r
-import vtk.vtkAxes;\r
-import vtk.vtkConeSource;\r
-import vtk.vtkLinearTransform;\r
-import vtk.vtkMatrix4x4;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkTextActor;\r
-import vtk.vtkTubeFilter;\r
-\r
-public class axesActor extends vtkAssembly implements IvtkVisualObject{\r
-\r
-       private vtkRenderer ren;\r
-       private double axisLength = 0.8;\r
-       private vtkTextActor xactor, yactor, zactor;\r
-       private vtkActor tubeActor;\r
-       private vtkActor xconeActor;\r
-       private vtkActor yconeActor;\r
-       private vtkActor zconeActor;\r
-       private boolean rendered = false;\r
-\r
-       public axesActor(vtkRenderer _ren) {\r
-               super();\r
-               ren = _ren;\r
-               createAxes();\r
-       }\r
-       \r
-       public axesActor(vtkRenderer _ren, double axisLength) {\r
-               super();\r
-               ren = _ren;\r
-               this.axisLength = axisLength;\r
-               createAxes();\r
-       }\r
-\r
-       public void createAxes() {\r
-               vtkAxes axes = new vtkAxes();\r
-               axes.SetOrigin(0, 0, 0);\r
-               axes.SetScaleFactor(axisLength);\r
-\r
-               xactor = new vtkTextActor();\r
-               yactor = new vtkTextActor();\r
-               zactor = new vtkTextActor();\r
-\r
-               xactor.SetInput("X");\r
-               yactor.SetInput("Y");\r
-               zactor.SetInput("Z");\r
-\r
-//             xactor.SetTextScaleModeToViewport();\r
-//             yactor.SetTextScaleModeToViewport();\r
-//             zactor.SetTextScaleModeToViewport();\r
-               xactor.SetTextScaleModeToNone();\r
-               yactor.SetTextScaleModeToNone();\r
-               zactor.SetTextScaleModeToNone();\r
-               \r
-               xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               xactor.GetTextProperty().ShadowOff();\r
-               xactor.GetTextProperty().ItalicOff();\r
-               xactor.GetTextProperty().BoldOff();\r
-\r
-               yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               yactor.GetTextProperty().ShadowOff();\r
-               yactor.GetTextProperty().ItalicOff();\r
-               yactor.GetTextProperty().BoldOff();\r
-\r
-               zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               zactor.GetTextProperty().ShadowOff();\r
-               zactor.GetTextProperty().ItalicOff();\r
-               zactor.GetTextProperty().BoldOff();\r
-               \r
-               xactor.GetTextProperty().Delete();\r
-               yactor.GetTextProperty().Delete();\r
-               zactor.GetTextProperty().Delete();\r
-\r
-               xactor.SetMaximumLineHeight(0.25);\r
-               yactor.SetMaximumLineHeight(0.25);\r
-               zactor.SetMaximumLineHeight(0.25);\r
-               \r
-               xactor.SetPickable(0);\r
-               yactor.SetPickable(0);\r
-               zactor.SetPickable(0);\r
-\r
-               vtkTubeFilter tube = new vtkTubeFilter();\r
-               tube.SetInput(axes.GetOutput());\r
-               tube.SetRadius(0.05 * axisLength);\r
-               tube.SetNumberOfSides(8);\r
-\r
-               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();\r
-               tubeMapper.SetInput(tube.GetOutput());\r
-\r
-               tubeActor = new vtkActor();\r
-               tubeActor.SetMapper(tubeMapper);\r
-               tubeActor.PickableOff();\r
-\r
-               int coneRes = 12;\r
-               double coneScale = 0.3 * axisLength;\r
-\r
-               // --- x-Cone\r
-               vtkConeSource xcone = new vtkConeSource();\r
-               xcone.SetResolution(coneRes);\r
-               vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();\r
-               xconeMapper.SetInput(xcone.GetOutput());\r
-               xconeActor = new vtkActor();\r
-               xconeActor.SetMapper(xconeMapper);\r
-               xconeActor.GetProperty().SetColor(1, 0, 0);\r
-               xconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               xconeActor.SetPosition(axisLength, 0.0, 0.0);\r
-               xconeActor.SetPickable(0);\r
-\r
-               // --- y-Cone\r
-               vtkConeSource ycone = new vtkConeSource();\r
-               ycone.SetResolution(coneRes);\r
-               vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();\r
-               yconeMapper.SetInput(ycone.GetOutput());\r
-               yconeActor = new vtkActor();\r
-               yconeActor.SetMapper(yconeMapper);\r
-               yconeActor.GetProperty().SetColor(1, 1, 0);\r
-               yconeActor.RotateZ(90);\r
-               yconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               yconeActor.SetPosition(0.0, axisLength, 0.0);\r
-               yconeActor.SetPickable(0);\r
-\r
-               // --- z-Cone\r
-               vtkConeSource zcone = new vtkConeSource();\r
-               zcone.SetResolution(coneRes);\r
-               vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();\r
-               zconeMapper.SetInput(zcone.GetOutput());\r
-               zconeActor = new vtkActor();\r
-               zconeActor.SetMapper(zconeMapper);\r
-               zconeActor.GetProperty().SetColor(0, 1, 0);\r
-               zconeActor.RotateY(-90);\r
-               zconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               zconeActor.SetPosition(0.0, 0.0, axisLength);\r
-               zconeActor.SetPickable(0);\r
-\r
-               \r
-               this.AddPart(tubeActor);\r
-               this.AddPart(xconeActor);\r
-               this.AddPart(yconeActor);\r
-               this.AddPart(zconeActor);\r
-               \r
-               tube.GetOutput().Delete();\r
-               xcone.GetOutput().Delete();\r
-               ycone.GetOutput().Delete();\r
-               zcone.GetOutput().Delete();\r
-               axes.GetOutput().Delete();\r
-               axes.Delete();\r
-               tubeMapper.Delete();\r
-               tube.Delete();\r
-               xcone.Delete();\r
-               ycone.Delete();\r
-               zcone.Delete();\r
-               xconeMapper.Delete();\r
-               yconeMapper.Delete();\r
-               zconeMapper.Delete();\r
-               \r
-               xconeActor.GetProperty().Delete();\r
-               yconeActor.GetProperty().Delete();\r
-               zconeActor.GetProperty().Delete();\r
-       }\r
-       \r
-       public void addToRenderer() {\r
-               if (rendered)\r
-                       return;\r
-               rendered = true;\r
-               \r
-               ren.AddActor2D(xactor);\r
-               ren.AddActor2D(yactor);\r
-               ren.AddActor2D(zactor);\r
-               \r
-               \r
-               ren.AddActor(this);\r
-       }\r
-       \r
-       public void removeFromRenderer() {\r
-               if (!rendered)\r
-                       return;\r
-               rendered = false;\r
-               ren.RemoveActor2D(xactor);\r
-               ren.RemoveActor2D(yactor);\r
-               ren.RemoveActor2D(zactor);\r
-               ren.RemoveActor(this);\r
-       }\r
-       \r
-       public boolean isRendered() {\r
-               return rendered;\r
-       }\r
-\r
-       public void setAxesVisibility(boolean ison) {\r
-               this.SetVisibility(ison ? 1 : 0);\r
-               xactor.SetVisibility(ison ? 1 : 0);\r
-               yactor.SetVisibility(ison ? 1 : 0);\r
-               zactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       private boolean labelVisible = true;\r
-       \r
-       public void setLabelVisibility(boolean ison) {\r
-               xactor.SetVisibility(ison ? 1 : 0);\r
-               yactor.SetVisibility(ison ? 1 : 0);\r
-               zactor.SetVisibility(ison ? 1 : 0);\r
-               labelVisible = ison;\r
-               if (labelVisible)\r
-                       updateTextLoc();\r
-       }\r
-       \r
-       Matrix4d m = new Matrix4d();\r
-       double mat[] = new double[16];\r
-       Point3d x = new Point3d();\r
-       Point3d y = new Point3d();\r
-       Point3d z = new Point3d();\r
-       \r
-       private void updateTextLoc() {\r
-               if (!labelVisible)\r
-                       return;\r
-               xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               \r
-               GetMatrix(mat);\r
-               MathTools.set(m, mat);\r
-               x.set(axisLength, 0,0);\r
-               y.set(0,axisLength, 0);\r
-               z.set(0,0,axisLength);\r
-               \r
-               m.transform(x);\r
-               m.transform(y);\r
-               m.transform(z);\r
-               xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);\r
-               yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);\r
-               zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);\r
-               \r
-               xactor.GetPositionCoordinate().Delete();\r
-               yactor.GetPositionCoordinate().Delete();\r
-               zactor.GetPositionCoordinate().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPickable(int id0) {\r
-               super.SetPickable(id0);\r
-               tubeActor.SetPickable(id0);\r
-               xconeActor.SetPickable(id0);\r
-               yconeActor.SetPickable(id0);\r
-               zconeActor.SetPickable(id0);\r
-\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double id0, double id1, double id2) {\r
-               super.SetOrientation(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void RotateWXYZ(double id0, double id1, double id2, double id3) {\r
-               super.RotateWXYZ(id0, id1, id2, id3);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double[] id0) {\r
-               super.SetPosition(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double id0, double id1, double id2) {\r
-               super.SetPosition(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double[] id0) {\r
-               super.SetOrientation(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0, double id1, double id2) {\r
-               super.SetScale(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double[] id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserMatrix(vtkMatrix4x4 id0) {\r
-               super.SetUserMatrix(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserTransform(vtkLinearTransform id0) {\r
-               super.SetUserTransform(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void Delete() {\r
-               ren.RemoveActor(xactor);\r
-               ren.RemoveActor(yactor);\r
-               ren.RemoveActor(zactor);\r
-               ren.RemoveActor(tubeActor);\r
-               ren.RemoveActor(xconeActor);\r
-               ren.RemoveActor(yconeActor);\r
-               ren.RemoveActor(xconeActor);\r
-               xactor.Delete();\r
-               yactor.Delete();\r
-               zactor.Delete();\r
-               tubeActor.Delete();\r
-               xconeActor.Delete();\r
-               yconeActor.Delete();\r
-               zconeActor.Delete();\r
-               super.Delete();\r
-       }\r
-\r
-       public void dispose() {\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               removeFromRenderer();\r
-                               Delete();\r
-                       }\r
-               });\r
-       }\r
-       \r
-       @Override\r
-       public vtkProp3D getVtkProp() {\r
-               return this;\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.Matrix4d;
+import javax.vecmath.Point3d;
+
+import org.simantics.g3d.math.MathTools;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.ThreadUtils;
+
+import vtk.vtkActor;
+import vtk.vtkAssembly;
+import vtk.vtkAxes;
+import vtk.vtkConeSource;
+import vtk.vtkLinearTransform;
+import vtk.vtkMatrix4x4;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkProp3D;
+import vtk.vtkRenderer;
+import vtk.vtkTextActor;
+import vtk.vtkTubeFilter;
+
+public class axesActor extends vtkAssembly implements IvtkVisualObject{
+
+       private vtkRenderer ren;
+       private double axisLength = 0.8;
+       private vtkTextActor xactor, yactor, zactor;
+       private vtkActor tubeActor;
+       private vtkActor xconeActor;
+       private vtkActor yconeActor;
+       private vtkActor zconeActor;
+       private boolean rendered = false;
+
+       public axesActor(vtkRenderer _ren) {
+               super();
+               ren = _ren;
+               createAxes();
+       }
+       
+       public axesActor(vtkRenderer _ren, double axisLength) {
+               super();
+               ren = _ren;
+               this.axisLength = axisLength;
+               createAxes();
+       }
+
+       public void createAxes() {
+               vtkAxes axes = new vtkAxes();
+               axes.SetOrigin(0, 0, 0);
+               axes.SetScaleFactor(axisLength);
+
+               xactor = new vtkTextActor();
+               yactor = new vtkTextActor();
+               zactor = new vtkTextActor();
+
+               xactor.SetInput("X");
+               yactor.SetInput("Y");
+               zactor.SetInput("Z");
+
+//             xactor.SetTextScaleModeToViewport();
+//             yactor.SetTextScaleModeToViewport();
+//             zactor.SetTextScaleModeToViewport();
+               xactor.SetTextScaleModeToNone();
+               yactor.SetTextScaleModeToNone();
+               zactor.SetTextScaleModeToNone();
+               
+               xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               xactor.GetTextProperty().ShadowOff();
+               xactor.GetTextProperty().ItalicOff();
+               xactor.GetTextProperty().BoldOff();
+
+               yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               yactor.GetTextProperty().ShadowOff();
+               yactor.GetTextProperty().ItalicOff();
+               yactor.GetTextProperty().BoldOff();
+
+               zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               zactor.GetTextProperty().ShadowOff();
+               zactor.GetTextProperty().ItalicOff();
+               zactor.GetTextProperty().BoldOff();
+               
+               xactor.GetTextProperty().Delete();
+               yactor.GetTextProperty().Delete();
+               zactor.GetTextProperty().Delete();
+
+               xactor.SetMaximumLineHeight(0.25);
+               yactor.SetMaximumLineHeight(0.25);
+               zactor.SetMaximumLineHeight(0.25);
+               
+               xactor.SetPickable(0);
+               yactor.SetPickable(0);
+               zactor.SetPickable(0);
+
+               vtkTubeFilter tube = new vtkTubeFilter();
+               tube.SetInputData(axes.GetOutput());
+               tube.SetRadius(0.05 * axisLength);
+               tube.SetNumberOfSides(8);
+
+               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
+               tubeMapper.SetInputData(tube.GetOutput());
+
+               tubeActor = new vtkActor();
+               tubeActor.SetMapper(tubeMapper);
+               tubeActor.PickableOff();
+
+               int coneRes = 12;
+               double coneScale = 0.3 * axisLength;
+
+               // --- x-Cone
+               vtkConeSource xcone = new vtkConeSource();
+               xcone.SetResolution(coneRes);
+               vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();
+               xconeMapper.SetInputData(xcone.GetOutput());
+               xconeActor = new vtkActor();
+               xconeActor.SetMapper(xconeMapper);
+               xconeActor.GetProperty().SetColor(1, 0, 0);
+               xconeActor.SetScale(coneScale, coneScale, coneScale);
+               xconeActor.SetPosition(axisLength, 0.0, 0.0);
+               xconeActor.SetPickable(0);
+
+               // --- y-Cone
+               vtkConeSource ycone = new vtkConeSource();
+               ycone.SetResolution(coneRes);
+               vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();
+               yconeMapper.SetInputData(ycone.GetOutput());
+               yconeActor = new vtkActor();
+               yconeActor.SetMapper(yconeMapper);
+               yconeActor.GetProperty().SetColor(1, 1, 0);
+               yconeActor.RotateZ(90);
+               yconeActor.SetScale(coneScale, coneScale, coneScale);
+               yconeActor.SetPosition(0.0, axisLength, 0.0);
+               yconeActor.SetPickable(0);
+
+               // --- z-Cone
+               vtkConeSource zcone = new vtkConeSource();
+               zcone.SetResolution(coneRes);
+               vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();
+               zconeMapper.SetInputData(zcone.GetOutput());
+               zconeActor = new vtkActor();
+               zconeActor.SetMapper(zconeMapper);
+               zconeActor.GetProperty().SetColor(0, 1, 0);
+               zconeActor.RotateY(-90);
+               zconeActor.SetScale(coneScale, coneScale, coneScale);
+               zconeActor.SetPosition(0.0, 0.0, axisLength);
+               zconeActor.SetPickable(0);
+
+               
+               this.AddPart(tubeActor);
+               this.AddPart(xconeActor);
+               this.AddPart(yconeActor);
+               this.AddPart(zconeActor);
+               
+               tube.GetOutput().Delete();
+               xcone.GetOutput().Delete();
+               ycone.GetOutput().Delete();
+               zcone.GetOutput().Delete();
+               axes.GetOutput().Delete();
+               axes.Delete();
+               tubeMapper.Delete();
+               tube.Delete();
+               xcone.Delete();
+               ycone.Delete();
+               zcone.Delete();
+               xconeMapper.Delete();
+               yconeMapper.Delete();
+               zconeMapper.Delete();
+               
+               xconeActor.GetProperty().Delete();
+               yconeActor.GetProperty().Delete();
+               zconeActor.GetProperty().Delete();
+       }
+       
+       public void addToRenderer() {
+               if (rendered)
+                       return;
+               rendered = true;
+               
+               ren.AddActor2D(xactor);
+               ren.AddActor2D(yactor);
+               ren.AddActor2D(zactor);
+               
+               
+               ren.AddActor(this);
+       }
+       
+       public void removeFromRenderer() {
+               if (!rendered)
+                       return;
+               rendered = false;
+               ren.RemoveActor2D(xactor);
+               ren.RemoveActor2D(yactor);
+               ren.RemoveActor2D(zactor);
+               ren.RemoveActor(this);
+       }
+       
+       public boolean isRendered() {
+               return rendered;
+       }
+
+       public void setAxesVisibility(boolean ison) {
+               this.SetVisibility(ison ? 1 : 0);
+               xactor.SetVisibility(ison ? 1 : 0);
+               yactor.SetVisibility(ison ? 1 : 0);
+               zactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       private boolean labelVisible = true;
+       
+       public void setLabelVisibility(boolean ison) {
+               xactor.SetVisibility(ison ? 1 : 0);
+               yactor.SetVisibility(ison ? 1 : 0);
+               zactor.SetVisibility(ison ? 1 : 0);
+               labelVisible = ison;
+               if (labelVisible)
+                       updateTextLoc();
+       }
+       
+       Matrix4d m = new Matrix4d();
+       double mat[] = new double[16];
+       Point3d x = new Point3d();
+       Point3d y = new Point3d();
+       Point3d z = new Point3d();
+       
+       private void updateTextLoc() {
+               if (!labelVisible)
+                       return;
+               xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               
+               GetMatrix(mat);
+               MathTools.set(m, mat);
+               x.set(axisLength, 0,0);
+               y.set(0,axisLength, 0);
+               z.set(0,0,axisLength);
+               
+               m.transform(x);
+               m.transform(y);
+               m.transform(z);
+               xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);
+               yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);
+               zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);
+               
+               xactor.GetPositionCoordinate().Delete();
+               yactor.GetPositionCoordinate().Delete();
+               zactor.GetPositionCoordinate().Delete();
+       }
+       
+       @Override
+       public void SetPickable(int id0) {
+               super.SetPickable(id0);
+               tubeActor.SetPickable(id0);
+               xconeActor.SetPickable(id0);
+               yconeActor.SetPickable(id0);
+               zconeActor.SetPickable(id0);
+
+       }
+       
+       @Override
+       public void SetOrientation(double id0, double id1, double id2) {
+               super.SetOrientation(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void RotateWXYZ(double id0, double id1, double id2, double id3) {
+               super.RotateWXYZ(id0, id1, id2, id3);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double[] id0) {
+               super.SetPosition(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double id0, double id1, double id2) {
+               super.SetPosition(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetOrientation(double[] id0) {
+               super.SetOrientation(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0, double id1, double id2) {
+               super.SetScale(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double[] id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserMatrix(vtkMatrix4x4 id0) {
+               super.SetUserMatrix(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserTransform(vtkLinearTransform id0) {
+               super.SetUserTransform(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void Delete() {
+               ren.RemoveActor(xactor);
+               ren.RemoveActor(yactor);
+               ren.RemoveActor(zactor);
+               ren.RemoveActor(tubeActor);
+               ren.RemoveActor(xconeActor);
+               ren.RemoveActor(yconeActor);
+               ren.RemoveActor(xconeActor);
+               xactor.Delete();
+               yactor.Delete();
+               zactor.Delete();
+               tubeActor.Delete();
+               xconeActor.Delete();
+               yconeActor.Delete();
+               zconeActor.Delete();
+               super.Delete();
+       }
+
+       public void dispose() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               removeFromRenderer();
+                               Delete();
+                       }
+               });
+       }
+       
+       @Override
+       public vtkProp3D getVtkProp() {
+               return this;
+       }
+       
+}
index 97725bbc42285104e82848c25279c97f90fcdbf3..bf37abf7726c2869f510f4917effa8b4f3cb2961 100644 (file)
-/*******************************************************************************\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.Matrix4d;\r
-import javax.vecmath.Point3d;\r
-\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.utils.threads.AWTThread;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkAssembly;\r
-import vtk.vtkAxes;\r
-import vtk.vtkConeSource;\r
-import vtk.vtkLinearTransform;\r
-import vtk.vtkMatrix4x4;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkSphereSource;\r
-import vtk.vtkTextActor;\r
-import vtk.vtkTubeFilter;\r
-\r
-public class axesSphereActor extends vtkAssembly implements IvtkVisualObject{\r
-\r
-       private vtkRenderer ren;\r
-       private double axisLength = 0.8;\r
-       private vtkTextActor xactor, yactor, zactor;\r
-       private vtkActor tubeActor;\r
-       private vtkActor xconeActor;\r
-       private vtkActor yconeActor;\r
-       private vtkActor zconeActor;\r
-       private vtkActor oBallActor;\r
-       private boolean rendered = false;\r
-\r
-       public axesSphereActor(vtkRenderer _ren) {\r
-               super();\r
-               ren = _ren;\r
-               createAxes();\r
-       }\r
-       \r
-       public axesSphereActor(vtkRenderer _ren, double axisLength) {\r
-               super();\r
-               ren = _ren;\r
-               this.axisLength = axisLength;\r
-               createAxes();\r
-       }\r
-\r
-       public void createAxes() {\r
-               vtkAxes axes = new vtkAxes();\r
-               axes.SetOrigin(0, 0, 0);\r
-               axes.SetScaleFactor(axisLength);\r
-\r
-\r
-\r
-               vtkTubeFilter tube = new vtkTubeFilter();\r
-               tube.SetInput(axes.GetOutput());\r
-               tube.SetRadius(0.05 * axisLength);\r
-               tube.SetNumberOfSides(8);\r
-\r
-               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();\r
-               tubeMapper.SetInput(tube.GetOutput());\r
-\r
-               tubeActor = new vtkActor();\r
-               tubeActor.SetMapper(tubeMapper);\r
-               tubeActor.PickableOff();\r
-\r
-               int coneRes = 12;\r
-               double coneScale = 0.3 * axisLength;\r
-\r
-               // --- x-Cone\r
-               vtkConeSource xcone = new vtkConeSource();\r
-               xcone.SetResolution(coneRes);\r
-               vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();\r
-               xconeMapper.SetInput(xcone.GetOutput());\r
-               xconeActor = new vtkActor();\r
-               xconeActor.SetMapper(xconeMapper);\r
-               xconeActor.GetProperty().SetColor(1, 0, 0);\r
-               xconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               xconeActor.SetPosition(axisLength, 0.0, 0.0);\r
-               xconeActor.SetPickable(0);\r
-\r
-               // --- y-Cone\r
-               vtkConeSource ycone = new vtkConeSource();\r
-               ycone.SetResolution(coneRes);\r
-               vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();\r
-               yconeMapper.SetInput(ycone.GetOutput());\r
-               yconeActor = new vtkActor();\r
-               yconeActor.SetMapper(yconeMapper);\r
-               yconeActor.GetProperty().SetColor(1, 1, 0);\r
-               yconeActor.RotateZ(90);\r
-               yconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               yconeActor.SetPosition(0.0, axisLength, 0.0);\r
-               yconeActor.SetPickable(0);\r
-\r
-               // --- z-Cone\r
-               vtkConeSource zcone = new vtkConeSource();\r
-               zcone.SetResolution(coneRes);\r
-               vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();\r
-               zconeMapper.SetInput(zcone.GetOutput());\r
-               zconeActor = new vtkActor();\r
-               zconeActor.SetMapper(zconeMapper);\r
-               zconeActor.GetProperty().SetColor(0, 1, 0);\r
-               zconeActor.RotateY(-90);\r
-               zconeActor.SetScale(coneScale, coneScale, coneScale);\r
-               zconeActor.SetPosition(0.0, 0.0, axisLength);\r
-               zconeActor.SetPickable(0);\r
-\r
-               vtkSphereSource ball = new vtkSphereSource();\r
-               ball.SetRadius(axisLength * 0.3);\r
-               ball.SetPhiResolution(6);\r
-               ball.SetThetaResolution(8);\r
-               vtkPolyDataMapper ballMapper = new vtkPolyDataMapper();\r
-               ballMapper.SetInput(ball.GetOutput());\r
-               oBallActor = new vtkActor();\r
-               oBallActor.SetMapper(ballMapper);\r
-               oBallActor.GetProperty().SetColor(0, 0, 1);\r
-               oBallActor.SetPickable(0);\r
-               \r
-               \r
-               this.AddPart(tubeActor);\r
-               this.AddPart(xconeActor);\r
-               this.AddPart(yconeActor);\r
-               this.AddPart(zconeActor);\r
-               this.AddPart(oBallActor);\r
-               \r
-               tube.GetOutput().Delete();\r
-               xcone.GetOutput().Delete();\r
-               ycone.GetOutput().Delete();\r
-               zcone.GetOutput().Delete();\r
-               axes.GetOutput().Delete();\r
-               ball.GetOutput().Delete();\r
-               axes.Delete();\r
-               tube.Delete();\r
-               xcone.Delete();\r
-               ycone.Delete();\r
-               zcone.Delete();\r
-               ball.Delete();\r
-               tubeMapper.Delete();\r
-               xconeMapper.Delete();\r
-               yconeMapper.Delete();\r
-               zconeMapper.Delete();\r
-               ballMapper.Delete();\r
-               \r
-               xconeActor.GetProperty().Delete();\r
-               yconeActor.GetProperty().Delete();\r
-               zconeActor.GetProperty().Delete();\r
-               oBallActor.GetProperty().Delete();\r
-               \r
-               \r
-               xactor = new vtkTextActor();\r
-               yactor = new vtkTextActor();\r
-               zactor = new vtkTextActor();\r
-\r
-               xactor.SetInput("X");\r
-               yactor.SetInput("Y");\r
-               zactor.SetInput("Z");\r
-\r
-//             xactor.SetTextScaleModeToViewport();\r
-//             yactor.SetTextScaleModeToViewport();\r
-//             zactor.SetTextScaleModeToViewport();\r
-               xactor.SetTextScaleModeToNone();\r
-               yactor.SetTextScaleModeToNone();\r
-               zactor.SetTextScaleModeToNone();\r
-               \r
-               xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               xactor.GetTextProperty().ShadowOff();\r
-               xactor.GetTextProperty().ItalicOff();\r
-               xactor.GetTextProperty().BoldOff();\r
-\r
-               yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               yactor.GetTextProperty().ShadowOff();\r
-               yactor.GetTextProperty().ItalicOff();\r
-               yactor.GetTextProperty().BoldOff();\r
-\r
-               zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               zactor.GetTextProperty().ShadowOff();\r
-               zactor.GetTextProperty().ItalicOff();\r
-               zactor.GetTextProperty().BoldOff();\r
-               \r
-               xactor.GetTextProperty().Delete();\r
-               yactor.GetTextProperty().Delete();\r
-               zactor.GetTextProperty().Delete();\r
-\r
-               xactor.SetMaximumLineHeight(0.25);\r
-               yactor.SetMaximumLineHeight(0.25);\r
-               zactor.SetMaximumLineHeight(0.25);\r
-               \r
-               xactor.SetPickable(0);\r
-               yactor.SetPickable(0);\r
-               zactor.SetPickable(0);\r
-       }\r
-       \r
-       public void addToRenderer() {\r
-               if (rendered)\r
-                       return;\r
-               rendered = true;\r
-               \r
-               ren.AddActor2D(xactor);\r
-               ren.AddActor2D(yactor);\r
-               ren.AddActor2D(zactor);\r
-               \r
-               \r
-               ren.AddActor(this);\r
-       }\r
-       \r
-       public void removeFromRenderer() {\r
-               if (!rendered)\r
-                       return;\r
-               rendered = false;\r
-               ren.RemoveActor2D(xactor);\r
-               ren.RemoveActor2D(yactor);\r
-               ren.RemoveActor2D(zactor);\r
-               ren.RemoveActor(this);\r
-       }\r
-       \r
-       public boolean isRendered() {\r
-               return rendered;\r
-       }\r
-\r
-       public void setAxesVisibility(boolean ison) {\r
-               this.SetVisibility(ison ? 1 : 0);\r
-               xactor.SetVisibility(ison ? 1 : 0);\r
-               yactor.SetVisibility(ison ? 1 : 0);\r
-               zactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       private boolean labelVisible = true;\r
-       public void setLabelVisibility(boolean ison) {\r
-               xactor.SetVisibility(ison ? 1 : 0);\r
-               yactor.SetVisibility(ison ? 1 : 0);\r
-               zactor.SetVisibility(ison ? 1 : 0);\r
-               labelVisible = ison;\r
-               if (labelVisible)\r
-                       updateTextLoc();\r
-       }\r
-       \r
-       Matrix4d m = new Matrix4d();\r
-       double mat[] = new double[16];\r
-       Point3d x = new Point3d();\r
-       Point3d y = new Point3d();\r
-       Point3d z = new Point3d();\r
-       \r
-       private void updateTextLoc() {\r
-               if (!labelVisible)\r
-                       return;\r
-               xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-\r
-               GetMatrix(mat);\r
-               MathTools.set(m, mat);\r
-               x.set(axisLength, 0,0);\r
-               y.set(0,axisLength, 0);\r
-               z.set(0,0,axisLength);\r
-               \r
-               m.transform(x);\r
-               m.transform(y);\r
-               m.transform(z);\r
-               xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);\r
-               yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);\r
-               zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);\r
-               \r
-               xactor.GetPositionCoordinate().Delete();\r
-               yactor.GetPositionCoordinate().Delete();\r
-               zactor.GetPositionCoordinate().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPickable(int id0) {\r
-               super.SetPickable(id0);\r
-               tubeActor.SetPickable(id0);\r
-               xconeActor.SetPickable(id0);\r
-               yconeActor.SetPickable(id0);\r
-               zconeActor.SetPickable(id0);\r
-               oBallActor.SetPickable(id0);\r
-\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double id0, double id1, double id2) {\r
-               super.SetOrientation(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void RotateWXYZ(double id0, double id1, double id2, double id3) {\r
-               super.RotateWXYZ(id0, id1, id2, id3);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double[] id0) {\r
-               super.SetPosition(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double id0, double id1, double id2) {\r
-               super.SetPosition(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double[] id0) {\r
-               super.SetOrientation(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0, double id1, double id2) {\r
-               super.SetScale(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double[] id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserMatrix(vtkMatrix4x4 id0) {\r
-               super.SetUserMatrix(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserTransform(vtkLinearTransform id0) {\r
-               super.SetUserTransform(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void Delete() {\r
-               ren.RemoveActor(xactor);\r
-               ren.RemoveActor(yactor);\r
-               ren.RemoveActor(zactor);\r
-               ren.RemoveActor(tubeActor);\r
-               ren.RemoveActor(xconeActor);\r
-               ren.RemoveActor(yconeActor);\r
-               ren.RemoveActor(xconeActor);\r
-               xactor.Delete();\r
-               yactor.Delete();\r
-               zactor.Delete();\r
-               tubeActor.Delete();\r
-               xconeActor.Delete();\r
-               yconeActor.Delete();\r
-               zconeActor.Delete();\r
-               super.Delete();\r
-       }\r
-\r
-       public void dispose() {\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               removeFromRenderer();\r
-                               Delete();\r
-                       }\r
-               });\r
-       }\r
-       \r
-       @Override\r
-       public vtkProp3D getVtkProp() {\r
-               return this;\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.Matrix4d;
+import javax.vecmath.Point3d;
+
+import org.simantics.g3d.math.MathTools;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.ThreadUtils;
+
+import vtk.vtkActor;
+import vtk.vtkAssembly;
+import vtk.vtkAxes;
+import vtk.vtkConeSource;
+import vtk.vtkLinearTransform;
+import vtk.vtkMatrix4x4;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkProp3D;
+import vtk.vtkRenderer;
+import vtk.vtkSphereSource;
+import vtk.vtkTextActor;
+import vtk.vtkTubeFilter;
+
+public class axesSphereActor extends vtkAssembly implements IvtkVisualObject{
+
+       private vtkRenderer ren;
+       private double axisLength = 0.8;
+       private vtkTextActor xactor, yactor, zactor;
+       private vtkActor tubeActor;
+       private vtkActor xconeActor;
+       private vtkActor yconeActor;
+       private vtkActor zconeActor;
+       private vtkActor oBallActor;
+       private boolean rendered = false;
+
+       public axesSphereActor(vtkRenderer _ren) {
+               super();
+               ren = _ren;
+               createAxes();
+       }
+       
+       public axesSphereActor(vtkRenderer _ren, double axisLength) {
+               super();
+               ren = _ren;
+               this.axisLength = axisLength;
+               createAxes();
+       }
+
+       public void createAxes() {
+               vtkAxes axes = new vtkAxes();
+               axes.SetOrigin(0, 0, 0);
+               axes.SetScaleFactor(axisLength);
+
+
+
+               vtkTubeFilter tube = new vtkTubeFilter();
+               tube.SetInputData(axes.GetOutput());
+               tube.SetRadius(0.05 * axisLength);
+               tube.SetNumberOfSides(8);
+
+               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
+               tubeMapper.SetInputData(tube.GetOutput());
+
+               tubeActor = new vtkActor();
+               tubeActor.SetMapper(tubeMapper);
+               tubeActor.PickableOff();
+
+               int coneRes = 12;
+               double coneScale = 0.3 * axisLength;
+
+               // --- x-Cone
+               vtkConeSource xcone = new vtkConeSource();
+               xcone.SetResolution(coneRes);
+               vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();
+               xconeMapper.SetInputData(xcone.GetOutput());
+               xconeActor = new vtkActor();
+               xconeActor.SetMapper(xconeMapper);
+               xconeActor.GetProperty().SetColor(1, 0, 0);
+               xconeActor.SetScale(coneScale, coneScale, coneScale);
+               xconeActor.SetPosition(axisLength, 0.0, 0.0);
+               xconeActor.SetPickable(0);
+
+               // --- y-Cone
+               vtkConeSource ycone = new vtkConeSource();
+               ycone.SetResolution(coneRes);
+               vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();
+               yconeMapper.SetInputData(ycone.GetOutput());
+               yconeActor = new vtkActor();
+               yconeActor.SetMapper(yconeMapper);
+               yconeActor.GetProperty().SetColor(1, 1, 0);
+               yconeActor.RotateZ(90);
+               yconeActor.SetScale(coneScale, coneScale, coneScale);
+               yconeActor.SetPosition(0.0, axisLength, 0.0);
+               yconeActor.SetPickable(0);
+
+               // --- z-Cone
+               vtkConeSource zcone = new vtkConeSource();
+               zcone.SetResolution(coneRes);
+               vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();
+               zconeMapper.SetInputData(zcone.GetOutput());
+               zconeActor = new vtkActor();
+               zconeActor.SetMapper(zconeMapper);
+               zconeActor.GetProperty().SetColor(0, 1, 0);
+               zconeActor.RotateY(-90);
+               zconeActor.SetScale(coneScale, coneScale, coneScale);
+               zconeActor.SetPosition(0.0, 0.0, axisLength);
+               zconeActor.SetPickable(0);
+
+               vtkSphereSource ball = new vtkSphereSource();
+               ball.SetRadius(axisLength * 0.3);
+               ball.SetPhiResolution(6);
+               ball.SetThetaResolution(8);
+               vtkPolyDataMapper ballMapper = new vtkPolyDataMapper();
+               ballMapper.SetInputData(ball.GetOutput());
+               oBallActor = new vtkActor();
+               oBallActor.SetMapper(ballMapper);
+               oBallActor.GetProperty().SetColor(0, 0, 1);
+               oBallActor.SetPickable(0);
+               
+               
+               this.AddPart(tubeActor);
+               this.AddPart(xconeActor);
+               this.AddPart(yconeActor);
+               this.AddPart(zconeActor);
+               this.AddPart(oBallActor);
+               
+               tube.GetOutput().Delete();
+               xcone.GetOutput().Delete();
+               ycone.GetOutput().Delete();
+               zcone.GetOutput().Delete();
+               axes.GetOutput().Delete();
+               ball.GetOutput().Delete();
+               axes.Delete();
+               tube.Delete();
+               xcone.Delete();
+               ycone.Delete();
+               zcone.Delete();
+               ball.Delete();
+               tubeMapper.Delete();
+               xconeMapper.Delete();
+               yconeMapper.Delete();
+               zconeMapper.Delete();
+               ballMapper.Delete();
+               
+               xconeActor.GetProperty().Delete();
+               yconeActor.GetProperty().Delete();
+               zconeActor.GetProperty().Delete();
+               oBallActor.GetProperty().Delete();
+               
+               
+               xactor = new vtkTextActor();
+               yactor = new vtkTextActor();
+               zactor = new vtkTextActor();
+
+               xactor.SetInput("X");
+               yactor.SetInput("Y");
+               zactor.SetInput("Z");
+
+//             xactor.SetTextScaleModeToViewport();
+//             yactor.SetTextScaleModeToViewport();
+//             zactor.SetTextScaleModeToViewport();
+               xactor.SetTextScaleModeToNone();
+               yactor.SetTextScaleModeToNone();
+               zactor.SetTextScaleModeToNone();
+               
+               xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               xactor.GetTextProperty().ShadowOff();
+               xactor.GetTextProperty().ItalicOff();
+               xactor.GetTextProperty().BoldOff();
+
+               yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               yactor.GetTextProperty().ShadowOff();
+               yactor.GetTextProperty().ItalicOff();
+               yactor.GetTextProperty().BoldOff();
+
+               zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               zactor.GetTextProperty().ShadowOff();
+               zactor.GetTextProperty().ItalicOff();
+               zactor.GetTextProperty().BoldOff();
+               
+               xactor.GetTextProperty().Delete();
+               yactor.GetTextProperty().Delete();
+               zactor.GetTextProperty().Delete();
+
+               xactor.SetMaximumLineHeight(0.25);
+               yactor.SetMaximumLineHeight(0.25);
+               zactor.SetMaximumLineHeight(0.25);
+               
+               xactor.SetPickable(0);
+               yactor.SetPickable(0);
+               zactor.SetPickable(0);
+       }
+       
+       public void addToRenderer() {
+               if (rendered)
+                       return;
+               rendered = true;
+               
+               ren.AddActor2D(xactor);
+               ren.AddActor2D(yactor);
+               ren.AddActor2D(zactor);
+               
+               
+               ren.AddActor(this);
+       }
+       
+       public void removeFromRenderer() {
+               if (!rendered)
+                       return;
+               rendered = false;
+               ren.RemoveActor2D(xactor);
+               ren.RemoveActor2D(yactor);
+               ren.RemoveActor2D(zactor);
+               ren.RemoveActor(this);
+       }
+       
+       public boolean isRendered() {
+               return rendered;
+       }
+
+       public void setAxesVisibility(boolean ison) {
+               this.SetVisibility(ison ? 1 : 0);
+               xactor.SetVisibility(ison ? 1 : 0);
+               yactor.SetVisibility(ison ? 1 : 0);
+               zactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       private boolean labelVisible = true;
+       public void setLabelVisibility(boolean ison) {
+               xactor.SetVisibility(ison ? 1 : 0);
+               yactor.SetVisibility(ison ? 1 : 0);
+               zactor.SetVisibility(ison ? 1 : 0);
+               labelVisible = ison;
+               if (labelVisible)
+                       updateTextLoc();
+       }
+       
+       Matrix4d m = new Matrix4d();
+       double mat[] = new double[16];
+       Point3d x = new Point3d();
+       Point3d y = new Point3d();
+       Point3d z = new Point3d();
+       
+       private void updateTextLoc() {
+               if (!labelVisible)
+                       return;
+               xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+
+               GetMatrix(mat);
+               MathTools.set(m, mat);
+               x.set(axisLength, 0,0);
+               y.set(0,axisLength, 0);
+               z.set(0,0,axisLength);
+               
+               m.transform(x);
+               m.transform(y);
+               m.transform(z);
+               xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);
+               yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);
+               zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);
+               
+               xactor.GetPositionCoordinate().Delete();
+               yactor.GetPositionCoordinate().Delete();
+               zactor.GetPositionCoordinate().Delete();
+       }
+       
+       @Override
+       public void SetPickable(int id0) {
+               super.SetPickable(id0);
+               tubeActor.SetPickable(id0);
+               xconeActor.SetPickable(id0);
+               yconeActor.SetPickable(id0);
+               zconeActor.SetPickable(id0);
+               oBallActor.SetPickable(id0);
+
+       }
+       
+       @Override
+       public void SetOrientation(double id0, double id1, double id2) {
+               super.SetOrientation(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void RotateWXYZ(double id0, double id1, double id2, double id3) {
+               super.RotateWXYZ(id0, id1, id2, id3);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double[] id0) {
+               super.SetPosition(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double id0, double id1, double id2) {
+               super.SetPosition(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetOrientation(double[] id0) {
+               super.SetOrientation(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0, double id1, double id2) {
+               super.SetScale(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double[] id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserMatrix(vtkMatrix4x4 id0) {
+               super.SetUserMatrix(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserTransform(vtkLinearTransform id0) {
+               super.SetUserTransform(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void Delete() {
+               ren.RemoveActor(xactor);
+               ren.RemoveActor(yactor);
+               ren.RemoveActor(zactor);
+               ren.RemoveActor(tubeActor);
+               ren.RemoveActor(xconeActor);
+               ren.RemoveActor(yconeActor);
+               ren.RemoveActor(xconeActor);
+               xactor.Delete();
+               yactor.Delete();
+               zactor.Delete();
+               tubeActor.Delete();
+               xconeActor.Delete();
+               yconeActor.Delete();
+               zconeActor.Delete();
+               super.Delete();
+       }
+
+       public void dispose() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               removeFromRenderer();
+                               Delete();
+                       }
+               });
+       }
+       
+       @Override
+       public vtkProp3D getVtkProp() {
+               return this;
+       }
+       
+}
index a9e507eec597ee9111521a9bef3ed868338e426f..a94233ccc43209d2ac399c01f2ecbd1b1ac89e59 100644 (file)
-/*******************************************************************************\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.AxisAngle4d;\r
-import javax.vecmath.Matrix4d;\r
-import javax.vecmath.Point3d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.utils.threads.AWTThread;\r
-import org.simantics.utils.threads.ThreadUtils;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkAssembly;\r
-import vtk.vtkConeSource;\r
-import vtk.vtkLineSource;\r
-import vtk.vtkLinearTransform;\r
-import vtk.vtkMatrix4x4;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkTextActor;\r
-import vtk.vtkTubeFilter;\r
-\r
-public class axisActor extends vtkAssembly implements IvtkVisualObject{\r
-\r
-       private vtkRenderer ren;\r
-       private Vector3d axisDir = new Vector3d(1,0,0);\r
-       private vtkTextActor tactor;\r
-       private vtkActor tubeActor;\r
-       private vtkActor coneActor;\r
-       private boolean rendered = false;\r
-\r
-       public axisActor(vtkRenderer _ren, String label) {\r
-               super();\r
-               ren = _ren;\r
-               createAxis(label);\r
-       }\r
-       \r
-       public axisActor(vtkRenderer _ren, String label, Vector3d dir) {\r
-               super();\r
-               ren = _ren;\r
-               this.axisDir = dir;\r
-               createAxis(label);\r
-       }\r
-\r
-       public void createAxis(String label) {\r
-               vtkLineSource line = new vtkLineSource();\r
-               line.SetPoint1(0.0,0.0,0.0);\r
-               line.SetPoint2(axisDir.x,axisDir.y,axisDir.z);\r
-               \r
-               tactor = new vtkTextActor();\r
-               \r
-               tactor.SetInput(label);\r
-               \r
-               tactor.SetTextScaleModeToNone();\r
-               tactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);\r
-               tactor.GetTextProperty().ShadowOff();\r
-               tactor.GetTextProperty().ItalicOff();\r
-               tactor.GetTextProperty().BoldOff();\r
-               \r
-               tactor.GetTextProperty().Delete();\r
-               \r
-               tactor.SetMaximumLineHeight(0.25);\r
-               \r
-               tactor.SetPickable(0);\r
-               \r
-               vtkTubeFilter tube = new vtkTubeFilter();\r
-               tube.SetInput(line.GetOutput());\r
-               tube.SetRadius(0.05 * axisDir.length());\r
-               tube.SetNumberOfSides(8);\r
-\r
-               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();\r
-               tubeMapper.SetInput(tube.GetOutput());\r
-\r
-               tubeActor = new vtkActor();\r
-               tubeActor.SetMapper(tubeMapper);\r
-               tubeActor.PickableOff();\r
-\r
-               int coneRes = 12;\r
-               double coneScale = 0.3 * axisDir.length();\r
-\r
-               // --- x-Cone\r
-               vtkConeSource cone = new vtkConeSource();\r
-               cone.SetResolution(coneRes);\r
-               vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();\r
-               coneMapper.SetInput(cone.GetOutput());\r
-               coneActor = new vtkActor();\r
-               coneActor.SetMapper(coneMapper);\r
-               coneActor.GetProperty().SetColor(1, 0, 0);\r
-               coneActor.SetScale(coneScale, coneScale, coneScale);\r
-               coneActor.SetPosition(axisDir.x,axisDir.y,axisDir.z);\r
-               coneActor.SetPickable(0);\r
-               \r
-               AxisAngle4d aa = MathTools.createRotation(new Vector3d(1,0,0), new Vector3d(axisDir));\r
-               if (aa != null)\r
-                       coneActor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);\r
-               \r
-               this.AddPart(tubeActor);\r
-               this.AddPart(coneActor);\r
-               \r
-               tube.GetOutput().Delete();\r
-               cone.GetOutput().Delete();\r
-               line.GetOutput().Delete();\r
-               \r
-               tubeMapper.Delete();\r
-               tube.Delete();\r
-               cone.Delete();\r
-               line.Delete();\r
-\r
-               coneMapper.Delete();\r
-               \r
-               coneActor.GetProperty().Delete();\r
-       }\r
-       \r
-       public void addToRenderer() {\r
-               if (rendered)\r
-                       return;\r
-               rendered = true;\r
-               \r
-               ren.AddActor2D(tactor);\r
-               \r
-               ren.AddActor(this);\r
-       }\r
-       \r
-       public void removeFromRenderer() {\r
-               if (!rendered)\r
-                       return;\r
-               rendered = false;\r
-               ren.RemoveActor2D(tactor);\r
-               ren.RemoveActor(this);\r
-       }\r
-       \r
-       public boolean isRendered() {\r
-               return rendered;\r
-       }\r
-\r
-       public void setAxesVisibility(boolean ison) {\r
-               this.SetVisibility(ison ? 1 : 0);\r
-               tactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       public void setLabelVisibility(boolean ison) {\r
-               tactor.SetVisibility(ison ? 1 : 0);\r
-       }\r
-       \r
-       double mat[] = new double[16];\r
-       Matrix4d m = new Matrix4d();\r
-       Point3d p = new Point3d();\r
-       private void updateTextLoc() {\r
-               tactor.GetPositionCoordinate().SetCoordinateSystemToWorld();\r
-               \r
-               \r
-               GetMatrix(mat);\r
-               MathTools.set(m, mat);\r
-               p.set(axisDir.x, axisDir.y,axisDir.z);\r
-               m.transform(p);\r
-               tactor.GetPositionCoordinate().SetValue(p.x, p.y, p.z);\r
-               \r
-               tactor.GetPositionCoordinate().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPickable(int id0) {\r
-               super.SetPickable(id0);\r
-               tubeActor.SetPickable(id0);\r
-               coneActor.SetPickable(id0);\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double id0, double id1, double id2) {\r
-               super.SetOrientation(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void RotateWXYZ(double id0, double id1, double id2, double id3) {\r
-               super.RotateWXYZ(id0, id1, id2, id3);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double[] id0) {\r
-               super.SetPosition(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetPosition(double id0, double id1, double id2) {\r
-               super.SetPosition(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetOrientation(double[] id0) {\r
-               super.SetOrientation(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double id0, double id1, double id2) {\r
-               super.SetScale(id0, id1, id2);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetScale(double[] id0) {\r
-               super.SetScale(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       public void SetColor(double r, double g, double b) {\r
-               coneActor.GetProperty().SetColor(r, g, b);\r
-               tubeActor.GetProperty().SetColor(r, g, b);\r
-               coneActor.GetProperty().Delete();\r
-               tubeActor.GetProperty().Delete();\r
-       }\r
-       \r
-       public void SetTextColor(double r, double g, double b) {\r
-               tactor.GetTextProperty().SetColor(r, g, b);\r
-               tactor.GetTextProperty().Delete();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserMatrix(vtkMatrix4x4 id0) {\r
-               super.SetUserMatrix(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void SetUserTransform(vtkLinearTransform id0) {\r
-               super.SetUserTransform(id0);\r
-               updateTextLoc();\r
-       }\r
-       \r
-       @Override\r
-       public void Delete() {\r
-               ren.RemoveActor(tactor);\r
-               ren.RemoveActor(tubeActor);\r
-               ren.RemoveActor(coneActor);\r
-               tactor.Delete();\r
-               tubeActor.Delete();\r
-               coneActor.Delete();\r
-               super.Delete();\r
-       }\r
-\r
-       public void dispose() {\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               removeFromRenderer();\r
-                               Delete();\r
-                       }\r
-               });\r
-       }\r
-       \r
-       @Override\r
-       public vtkProp3D getVtkProp() {\r
-               return this;\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.AxisAngle4d;
+import javax.vecmath.Matrix4d;
+import javax.vecmath.Point3d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.math.MathTools;
+import org.simantics.utils.threads.AWTThread;
+import org.simantics.utils.threads.ThreadUtils;
+
+import vtk.vtkActor;
+import vtk.vtkAssembly;
+import vtk.vtkConeSource;
+import vtk.vtkLineSource;
+import vtk.vtkLinearTransform;
+import vtk.vtkMatrix4x4;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkProp3D;
+import vtk.vtkRenderer;
+import vtk.vtkTextActor;
+import vtk.vtkTubeFilter;
+
+public class axisActor extends vtkAssembly implements IvtkVisualObject{
+
+       private vtkRenderer ren;
+       private Vector3d axisDir = new Vector3d(1,0,0);
+       private vtkTextActor tactor;
+       private vtkActor tubeActor;
+       private vtkActor coneActor;
+       private boolean rendered = false;
+
+       public axisActor(vtkRenderer _ren, String label) {
+               super();
+               ren = _ren;
+               createAxis(label);
+       }
+       
+       public axisActor(vtkRenderer _ren, String label, Vector3d dir) {
+               super();
+               ren = _ren;
+               this.axisDir = dir;
+               createAxis(label);
+       }
+
+       public void createAxis(String label) {
+               vtkLineSource line = new vtkLineSource();
+               line.SetPoint1(0.0,0.0,0.0);
+               line.SetPoint2(axisDir.x,axisDir.y,axisDir.z);
+               
+               tactor = new vtkTextActor();
+               
+               tactor.SetInput(label);
+               
+               tactor.SetTextScaleModeToNone();
+               tactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
+               tactor.GetTextProperty().ShadowOff();
+               tactor.GetTextProperty().ItalicOff();
+               tactor.GetTextProperty().BoldOff();
+               
+               tactor.GetTextProperty().Delete();
+               
+               tactor.SetMaximumLineHeight(0.25);
+               
+               tactor.SetPickable(0);
+               
+               vtkTubeFilter tube = new vtkTubeFilter();
+               tube.SetInputData(line.GetOutput());
+               tube.SetRadius(0.05 * axisDir.length());
+               tube.SetNumberOfSides(8);
+
+               vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
+               tubeMapper.SetInputData(tube.GetOutput());
+
+               tubeActor = new vtkActor();
+               tubeActor.SetMapper(tubeMapper);
+               tubeActor.PickableOff();
+
+               int coneRes = 12;
+               double coneScale = 0.3 * axisDir.length();
+
+               // --- x-Cone
+               vtkConeSource cone = new vtkConeSource();
+               cone.SetResolution(coneRes);
+               vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
+               coneMapper.SetInputData(cone.GetOutput());
+               coneActor = new vtkActor();
+               coneActor.SetMapper(coneMapper);
+               coneActor.GetProperty().SetColor(1, 0, 0);
+               coneActor.SetScale(coneScale, coneScale, coneScale);
+               coneActor.SetPosition(axisDir.x,axisDir.y,axisDir.z);
+               coneActor.SetPickable(0);
+               
+               AxisAngle4d aa = MathTools.createRotation(new Vector3d(1,0,0), new Vector3d(axisDir));
+               if (aa != null)
+                       coneActor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);
+               
+               this.AddPart(tubeActor);
+               this.AddPart(coneActor);
+               
+               tube.GetOutput().Delete();
+               cone.GetOutput().Delete();
+               line.GetOutput().Delete();
+               
+               tubeMapper.Delete();
+               tube.Delete();
+               cone.Delete();
+               line.Delete();
+
+               coneMapper.Delete();
+               
+               coneActor.GetProperty().Delete();
+       }
+       
+       public void addToRenderer() {
+               if (rendered)
+                       return;
+               rendered = true;
+               
+               ren.AddActor2D(tactor);
+               
+               ren.AddActor(this);
+       }
+       
+       public void removeFromRenderer() {
+               if (!rendered)
+                       return;
+               rendered = false;
+               ren.RemoveActor2D(tactor);
+               ren.RemoveActor(this);
+       }
+       
+       public boolean isRendered() {
+               return rendered;
+       }
+
+       public void setAxesVisibility(boolean ison) {
+               this.SetVisibility(ison ? 1 : 0);
+               tactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       public void setLabelVisibility(boolean ison) {
+               tactor.SetVisibility(ison ? 1 : 0);
+       }
+       
+       double mat[] = new double[16];
+       Matrix4d m = new Matrix4d();
+       Point3d p = new Point3d();
+       private void updateTextLoc() {
+               tactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
+               
+               
+               GetMatrix(mat);
+               MathTools.set(m, mat);
+               p.set(axisDir.x, axisDir.y,axisDir.z);
+               m.transform(p);
+               tactor.GetPositionCoordinate().SetValue(p.x, p.y, p.z);
+               
+               tactor.GetPositionCoordinate().Delete();
+       }
+       
+       @Override
+       public void SetPickable(int id0) {
+               super.SetPickable(id0);
+               tubeActor.SetPickable(id0);
+               coneActor.SetPickable(id0);
+       }
+       
+       @Override
+       public void SetOrientation(double id0, double id1, double id2) {
+               super.SetOrientation(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void RotateWXYZ(double id0, double id1, double id2, double id3) {
+               super.RotateWXYZ(id0, id1, id2, id3);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double[] id0) {
+               super.SetPosition(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetPosition(double id0, double id1, double id2) {
+               super.SetPosition(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetOrientation(double[] id0) {
+               super.SetOrientation(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double id0, double id1, double id2) {
+               super.SetScale(id0, id1, id2);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetScale(double[] id0) {
+               super.SetScale(id0);
+               updateTextLoc();
+       }
+       
+       public void SetColor(double r, double g, double b) {
+               coneActor.GetProperty().SetColor(r, g, b);
+               tubeActor.GetProperty().SetColor(r, g, b);
+               coneActor.GetProperty().Delete();
+               tubeActor.GetProperty().Delete();
+       }
+       
+       public void SetTextColor(double r, double g, double b) {
+               tactor.GetTextProperty().SetColor(r, g, b);
+               tactor.GetTextProperty().Delete();
+       }
+       
+       @Override
+       public void SetUserMatrix(vtkMatrix4x4 id0) {
+               super.SetUserMatrix(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void SetUserTransform(vtkLinearTransform id0) {
+               super.SetUserTransform(id0);
+               updateTextLoc();
+       }
+       
+       @Override
+       public void Delete() {
+               ren.RemoveActor(tactor);
+               ren.RemoveActor(tubeActor);
+               ren.RemoveActor(coneActor);
+               tactor.Delete();
+               tubeActor.Delete();
+               coneActor.Delete();
+               super.Delete();
+       }
+
+       public void dispose() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               removeFromRenderer();
+                               Delete();
+                       }
+               });
+       }
+       
+       @Override
+       public vtkProp3D getVtkProp() {
+               return this;
+       }
+       
+}
index d3284df285983b28707705e411235d69ea5d877c..c992547fa76bce98a041f8a2501733bc729ef861 100644 (file)
-/*******************************************************************************\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.Tuple3d;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkDataSetMapper;\r
-import vtk.vtkLine;\r
-import vtk.vtkPoints;\r
-import vtk.vtkPolyLine;\r
-import vtk.vtkUnstructuredGrid;\r
-\r
-public class vtkShape {\r
-       \r
-       /**\r
-        * Creates a grid shaped actor.\r
-        * \r
-        * @param size number of grid lines\r
-        * @param space distance between grid lines\r
-        * @param axes bitmask of axes: 1:x, 2:y, 4:z\r
-        * @return vtkActor representing a grid.\r
-        */\r
-       public static vtkActor createGridActor(int size, double space, int axes) {\r
-               int gridCount = 0;\r
-               if ((axes & 0x1) > 0) {\r
-                       gridCount++;\r
-               }\r
-               if ((axes & 0x2) > 0) {\r
-                       gridCount++;\r
-               }\r
-               if ((axes & 0x4) > 0) {\r
-                       gridCount++;\r
-               }\r
-               int pointCount = (size+1) * 2 * 2 * gridCount;\r
-               vtkPoints linePoints = new vtkPoints();\r
-               linePoints.SetNumberOfPoints(pointCount);\r
-               \r
-               \r
-               double max = space * (double)size * 0.5;\r
-               double min = -max;\r
-               int base = 0;\r
-               if ((axes & 0x1) > 0) {\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,0.0, s, min);\r
-                               linePoints.InsertPoint(base + i*2+1,0.0, s, max);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,0.0, s, max);\r
-                               linePoints.InsertPoint(base + i*2+1,0.0, s, min);\r
-                       }\r
-                       base += (size+1)*2;\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  , 0.0, max, s);\r
-                               linePoints.InsertPoint(base + i*2+1, 0.0, min, s);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  , 0.0, min, s);\r
-                               linePoints.InsertPoint(base + i*2+1, 0.0, max, s);\r
-                       }\r
-                       base += (size+1)*2;\r
-               } \r
-               if ((axes & 0x4) > 0) {\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,s, min, 0.0);\r
-                               linePoints.InsertPoint(base + i*2+1,s, max, 0.0);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,s, max, 0.0);\r
-                               linePoints.InsertPoint(base + i*2+1,s, min, 0.0);\r
-                       }\r
-                       base += (size+1)*2;\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,max, s, 0.0);\r
-                               linePoints.InsertPoint(base + i*2+1,min, s, 0.0);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,min, s, 0.0);\r
-                               linePoints.InsertPoint(base + i*2+1,max, s, 0.0);\r
-                       }\r
-                       base += (size+1)*2;\r
-               } \r
-               if ((axes & 0x2) > 0) {\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,s, 0.0, min);\r
-                               linePoints.InsertPoint(base + i*2+1,s, 0.0, max);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,s, 0.0, max);\r
-                               linePoints.InsertPoint(base + i*2+1,s, 0.0, min);\r
-                       }\r
-                       base += (size+1)*2;\r
-                       for (int i = 0; i <= size; i++) {\r
-                               double s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,max, 0.0, s);\r
-                               linePoints.InsertPoint(base + i*2+1,min, 0.0, s);\r
-                               i++;\r
-                               if (i > size)\r
-                                       break;\r
-                               s = min + ((double)i) * space;\r
-                               linePoints.InsertPoint(base + i*2  ,min, 0.0, s);\r
-                               linePoints.InsertPoint(base + i*2+1,max, 0.0, s);\r
-                       }\r
-                       base += (size+1)*2;\r
-               }\r
-                       \r
-               \r
-               //vtkLine aLine = new vtkLine();\r
-               vtkPolyLine aLine = new vtkPolyLine();\r
-               aLine.GetPointIds().SetNumberOfIds(pointCount);\r
-               for (int i = 0; i < pointCount; i++) {\r
-                       aLine.GetPointIds().SetId(i, i);\r
-               }\r
-               \r
-               \r
-               vtkUnstructuredGrid aLineGrid = new vtkUnstructuredGrid();\r
-               aLineGrid.Allocate(pointCount, pointCount);\r
-               aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds());\r
-               aLineGrid.SetPoints(linePoints);\r
-               vtkDataSetMapper aLineMapper = new vtkDataSetMapper();\r
-               aLineMapper.SetInput(aLineGrid);\r
-               vtkActor aLineActor = new vtkActor();\r
-               aLineActor.SetMapper(aLineMapper);\r
-               \r
-               linePoints.Delete();\r
-               aLine.GetPointIds().Delete();\r
-           aLine.Delete();\r
-           aLineGrid.Delete();\r
-           aLineMapper.Delete();\r
-           \r
-           aLineActor.GetProperty().SetColor(0, 0, 0);\r
-           aLineActor.GetProperty().Delete();\r
-           \r
-           return aLineActor;\r
-       }\r
-       \r
-       /**\r
-        * Creates a line.\r
-        * \r
-        * @param p1\r
-        * @param p2\r
-        * @return\r
-        */\r
-       public static vtkActor createLineActor(Tuple3d p1, Tuple3d p2) {\r
-               vtkPoints linePoints = new vtkPoints();\r
-               linePoints.SetNumberOfPoints(2);\r
-               linePoints.InsertPoint(0,p1.x, p1.y, p1.z);\r
-               linePoints.InsertPoint(1,p2.x, p2.y, p2.z);\r
-               vtkLine aLine = new vtkLine();\r
-               aLine.GetPointIds().SetId(0, 0);\r
-               aLine.GetPointIds().SetId(1, 1);\r
-               vtkUnstructuredGrid aLineGrid = new vtkUnstructuredGrid();\r
-               aLineGrid.Allocate(1, 1);\r
-               aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds());\r
-               aLineGrid.SetPoints(linePoints);\r
-               vtkDataSetMapper aLineMapper = new vtkDataSetMapper();\r
-               aLineMapper.SetInput(aLineGrid);\r
-               vtkActor aLineActor = new vtkActor();\r
-               aLineActor.SetMapper(aLineMapper);\r
-               //aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1);\r
-           \r
-           linePoints.Delete();\r
-           aLine.GetPointIds().Delete();\r
-           aLine.Delete();\r
-           aLineGrid.Delete();\r
-           aLineMapper.Delete();\r
-           \r
-           return aLineActor;\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 vtk.vtkActor;
+import vtk.vtkDataSetMapper;
+import vtk.vtkLine;
+import vtk.vtkPoints;
+import vtk.vtkPolyLine;
+import vtk.vtkUnstructuredGrid;
+
+public class vtkShape {
+       
+       /**
+        * Creates a grid shaped actor.
+        * 
+        * @param size number of grid lines
+        * @param space distance between grid lines
+        * @param axes bitmask of axes: 1:x, 2:y, 4:z
+        * @return vtkActor representing a grid.
+        */
+       public static vtkActor createGridActor(int size, double space, int axes) {
+               int gridCount = 0;
+               if ((axes & 0x1) > 0) {
+                       gridCount++;
+               }
+               if ((axes & 0x2) > 0) {
+                       gridCount++;
+               }
+               if ((axes & 0x4) > 0) {
+                       gridCount++;
+               }
+               int pointCount = (size+1) * 2 * 2 * gridCount;
+               vtkPoints linePoints = new vtkPoints();
+               linePoints.SetNumberOfPoints(pointCount);
+               
+               
+               double max = space * (double)size * 0.5;
+               double min = -max;
+               int base = 0;
+               if ((axes & 0x1) > 0) {
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,0.0, s, min);
+                               linePoints.InsertPoint(base + i*2+1,0.0, s, max);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,0.0, s, max);
+                               linePoints.InsertPoint(base + i*2+1,0.0, s, min);
+                       }
+                       base += (size+1)*2;
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  , 0.0, max, s);
+                               linePoints.InsertPoint(base + i*2+1, 0.0, min, s);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  , 0.0, min, s);
+                               linePoints.InsertPoint(base + i*2+1, 0.0, max, s);
+                       }
+                       base += (size+1)*2;
+               } 
+               if ((axes & 0x4) > 0) {
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,s, min, 0.0);
+                               linePoints.InsertPoint(base + i*2+1,s, max, 0.0);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,s, max, 0.0);
+                               linePoints.InsertPoint(base + i*2+1,s, min, 0.0);
+                       }
+                       base += (size+1)*2;
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,max, s, 0.0);
+                               linePoints.InsertPoint(base + i*2+1,min, s, 0.0);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,min, s, 0.0);
+                               linePoints.InsertPoint(base + i*2+1,max, s, 0.0);
+                       }
+                       base += (size+1)*2;
+               } 
+               if ((axes & 0x2) > 0) {
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,s, 0.0, min);
+                               linePoints.InsertPoint(base + i*2+1,s, 0.0, max);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,s, 0.0, max);
+                               linePoints.InsertPoint(base + i*2+1,s, 0.0, min);
+                       }
+                       base += (size+1)*2;
+                       for (int i = 0; i <= size; i++) {
+                               double s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,max, 0.0, s);
+                               linePoints.InsertPoint(base + i*2+1,min, 0.0, s);
+                               i++;
+                               if (i > size)
+                                       break;
+                               s = min + ((double)i) * space;
+                               linePoints.InsertPoint(base + i*2  ,min, 0.0, s);
+                               linePoints.InsertPoint(base + i*2+1,max, 0.0, s);
+                       }
+                       base += (size+1)*2;
+               }
+                       
+               
+               //vtkLine aLine = new vtkLine();
+               vtkPolyLine aLine = new vtkPolyLine();
+               aLine.GetPointIds().SetNumberOfIds(pointCount);
+               for (int i = 0; i < pointCount; i++) {
+                       aLine.GetPointIds().SetId(i, i);
+               }
+               
+               
+               vtkUnstructuredGrid aLineGrid = new vtkUnstructuredGrid();
+               aLineGrid.Allocate(pointCount, pointCount);
+               aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds());
+               aLineGrid.SetPoints(linePoints);
+               vtkDataSetMapper aLineMapper = new vtkDataSetMapper();
+               aLineMapper.SetInputData(aLineGrid);
+               vtkActor aLineActor = new vtkActor();
+               aLineActor.SetMapper(aLineMapper);
+               
+               linePoints.Delete();
+               aLine.GetPointIds().Delete();
+           aLine.Delete();
+           aLineGrid.Delete();
+           aLineMapper.Delete();
+           
+           aLineActor.GetProperty().SetColor(0, 0, 0);
+           aLineActor.GetProperty().Delete();
+           
+           return aLineActor;
+       }
+       
+       /**
+        * Creates a line.
+        * 
+        * @param p1
+        * @param p2
+        * @return
+        */
+       public static vtkActor createLineActor(Tuple3d p1, Tuple3d p2) {
+               vtkPoints linePoints = new vtkPoints();
+               linePoints.SetNumberOfPoints(2);
+               linePoints.InsertPoint(0,p1.x, p1.y, p1.z);
+               linePoints.InsertPoint(1,p2.x, p2.y, p2.z);
+               vtkLine aLine = new vtkLine();
+               aLine.GetPointIds().SetId(0, 0);
+               aLine.GetPointIds().SetId(1, 1);
+               vtkUnstructuredGrid aLineGrid = new vtkUnstructuredGrid();
+               aLineGrid.Allocate(1, 1);
+               aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds());
+               aLineGrid.SetPoints(linePoints);
+               vtkDataSetMapper aLineMapper = new vtkDataSetMapper();
+               aLineMapper.SetInputData(aLineGrid);
+               vtkActor aLineActor = new vtkActor();
+               aLineActor.SetMapper(aLineMapper);
+               //aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1);
+           
+           linePoints.Delete();
+           aLine.GetPointIds().Delete();
+           aLine.Delete();
+           aLineGrid.Delete();
+           aLineMapper.Delete();
+           
+           return aLineActor;
+       }
+
+}
index 7fa374aab8bb689e3e958ff1ebaf090ec0a9eae0..d4cd71034e6c8d488b12c9528d6140f55f1f4701 100644 (file)
-/*******************************************************************************\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.utils;\r
-\r
-import javax.vecmath.AxisAngle4d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.math.MathTools;\r
-import org.simantics.g3d.vtk.shape.IvtkVisualObject;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkCamera;\r
-import vtk.vtkContourFilter;\r
-import vtk.vtkDataObject;\r
-import vtk.vtkOutlineFilter;\r
-import vtk.vtkOutlineSource;\r
-import vtk.vtkPolyData;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkPolyDataSilhouette;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderWindow;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkTransform;\r
-import vtk.vtkTransformPolyDataFilter;\r
-import vtk.vtkWindowToImageFilter;\r
-\r
-public class vtkEffect {\r
-\r
-       private static vtkRenderer tmpRenderer;\r
-       \r
-       public static vtkRenderer getRenderer() {\r
-               if (tmpRenderer == null)\r
-                       tmpRenderer = new vtkRenderer();\r
-               return tmpRenderer;\r
-       }\r
-       public static vtkActor createContour(vtkProp3D tmpProp) {\r
-               \r
-               vtkRenderer tmpRenderer = getRenderer();\r
-               tmpRenderer.SetBackground(1,1,1);\r
-               \r
-               \r
-               if (tmpProp instanceof IvtkVisualObject) {\r
-                       ((IvtkVisualObject)tmpProp).addToRenderer();\r
-               } else {\r
-                       tmpRenderer.AddActor(tmpProp);\r
-               }\r
-               \r
-               if (tmpProp instanceof vtkActor) {\r
-                       ((vtkActor)tmpProp).GetProperty().SetColor(0, 0, 0);\r
-               }\r
-               \r
-               \r
-               double bounds_data[] = tmpProp.GetBounds();\r
-               double center_data[] = tmpProp.GetCenter();\r
-               \r
-               tmpRenderer.ResetCamera();\r
-               tmpRenderer.GetActiveCamera().SetParallelProjection(1);\r
-               \r
-               vtkRenderWindow tmpRenderWindow = new vtkRenderWindow();\r
-               tmpRenderWindow.SetOffScreenRendering(1);\r
-               tmpRenderWindow.AddRenderer(tmpRenderer);\r
-               tmpRenderWindow.Render();\r
-               \r
-               vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();\r
-               windowToImageFilter.SetInput(tmpRenderWindow);\r
-               windowToImageFilter.SetMagnification(2);\r
-               windowToImageFilter.Update();\r
-               \r
-               vtkContourFilter contourFilter = new vtkContourFilter();\r
-               contourFilter.SetInputConnection(windowToImageFilter.GetOutputPort());\r
-               \r
-               contourFilter.SetValue(0, 255);\r
-               contourFilter.Update();\r
-               \r
-               vtkPolyData contour = contourFilter.GetOutput();\r
-               \r
-               double bounds_contour[] = new double[6]; \r
-               double center_contour[] = new double[3];\r
-               double trans_x=0., trans_y=0., trans_z=0., ratio_x=0., ratio_y=0.;\r
-               contour.GetBounds(bounds_contour);\r
-        \r
-               ratio_x = (bounds_data[1]-bounds_data[0])/(bounds_contour[1]-bounds_contour[0]);\r
-               ratio_y = (bounds_data[3]-bounds_data[2])/(bounds_contour[3]-bounds_contour[2]);\r
-               \r
-               vtkTransform transform1 = new vtkTransform();\r
-               transform1.Scale(ratio_x,ratio_y,1);\r
-               \r
-               vtkTransformPolyDataFilter tFilter1 = new vtkTransformPolyDataFilter();\r
-               tFilter1.SetInput(contour);\r
-               tFilter1.SetTransform(transform1);\r
-               tFilter1.Update();\r
-               \r
-               contour = tFilter1.GetOutput();\r
-               \r
-               contour.GetCenter(center_contour);\r
-               trans_x = center_data[0]-center_contour[0];\r
-               trans_y = center_data[1]-center_contour[1];\r
-               trans_z = center_data[2]-center_contour[2];\r
-\r
-               vtkTransform transform2 = new vtkTransform();\r
-               transform2.Translate( trans_x, trans_y, trans_z);\r
-               \r
-               vtkTransformPolyDataFilter tFilter2 = new vtkTransformPolyDataFilter();\r
-               tFilter2.SetInput(contour);\r
-               tFilter2.SetTransform(transform2);\r
-               tFilter2.Update();\r
-               \r
-               contour = tFilter2.GetOutput();\r
-               \r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               mapper.SetInput(contour);\r
-               \r
-                \r
-               vtkActor actor =new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               actor.GetProperty().SetLineWidth(2.);\r
-               \r
-               tmpRenderer.RemoveActor(tmpProp);\r
-               \r
-               tFilter1.Delete();\r
-               tFilter2.Delete();\r
-               contour.Delete();\r
-               contourFilter.Delete();\r
-               mapper.Delete();\r
-               tmpRenderWindow.Delete();\r
-               transform1.Delete();\r
-               transform2.Delete();\r
-               windowToImageFilter.Delete();\r
-               \r
-               return actor;\r
-       }\r
-       \r
-       public static vtkActor createContour(vtkProp3D tmpProp, vtkRenderer ren) {\r
-               \r
-               vtkRenderer tmpRenderer = getRenderer();\r
-               tmpRenderer.SetBackground(1,1,1);\r
-               \r
-               \r
-               if (tmpProp instanceof IvtkVisualObject) {\r
-                       ((IvtkVisualObject)tmpProp).addToRenderer();\r
-               } else {\r
-                       tmpRenderer.AddActor(tmpProp);\r
-               }\r
-               \r
-               if (tmpProp instanceof vtkActor) {\r
-                       ((vtkActor)tmpProp).GetProperty().SetColor(0, 0, 0);\r
-               }\r
-               \r
-               \r
-               //double bounds_data[] = tmpProp.GetBounds();\r
-               double center_data[] = tmpProp.GetCenter();\r
-               \r
-               tmpRenderer.ResetCamera();\r
-               \r
-               vtkCamera camera = ren.GetActiveCamera();\r
-               \r
-               vtkCamera tmpCamera = tmpRenderer.GetActiveCamera(); \r
-               tmpCamera.SetParallelProjection(camera.GetParallelProjection());\r
-               \r
-               \r
-               Vector3d pos = new Vector3d(camera.GetPosition());\r
-               Vector3d foc = new Vector3d(camera.GetFocalPoint());\r
-               Vector3d dir = new Vector3d();\r
-               dir.sub(pos,foc);\r
-               double l = dir.length();\r
-//             dir.scale(1.0/l);\r
-//             \r
-//             \r
-//\r
-//             \r
-//             dir.scale(2.0);\r
-//             Vector3d tmpFoc = new Vector3d(tmpCamera.GetFocalPoint());\r
-//             tmpFoc.add(dir);\r
-//             tmpCamera.SetPosition(tmpFoc.x,tmpFoc.y,tmpFoc.z);\r
-//             tmpCamera.SetRoll(camera.GetRoll());\r
-               \r
-               tmpCamera.DeepCopy(camera);\r
-               //tmpCamera.SetModelTransformMatrix(camera.GetModelTransformMatrix());\r
-               tmpCamera.UpdateViewport(tmpRenderer);\r
-               \r
-               vtkRenderWindow tmpRenderWindow = new vtkRenderWindow();\r
-               tmpRenderWindow.SetOffScreenRendering(1);\r
-               tmpRenderWindow.AddRenderer(tmpRenderer);\r
-               tmpRenderWindow.Render();\r
-               \r
-               vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();\r
-               windowToImageFilter.SetInput(tmpRenderWindow);\r
-               windowToImageFilter.SetMagnification(2);\r
-               windowToImageFilter.Update();\r
-               \r
-               vtkContourFilter contourFilter = new vtkContourFilter();\r
-               contourFilter.SetInputConnection(windowToImageFilter.GetOutputPort());\r
-               \r
-               contourFilter.SetValue(0, 255);\r
-               contourFilter.Update();\r
-               \r
-               vtkPolyData contour = contourFilter.GetOutput();\r
-               \r
-               \r
-               double or[] = camera.GetOrientationWXYZ();\r
-               AxisAngle4d aa = new AxisAngle4d();\r
-               aa.angle = -MathTools.degToRad(or[0]);\r
-               aa.x = or[1];\r
-               aa.y = or[2];\r
-               aa.z = or[3];\r
-               \r
-               vtkTransform transform0 = new vtkTransform();\r
-               transform0.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);\r
-               \r
-               vtkTransformPolyDataFilter tFilter0 = new vtkTransformPolyDataFilter();\r
-               tFilter0.SetInput(contour);\r
-               tFilter0.SetTransform(transform0);\r
-               tFilter0.Update();\r
-               \r
-               contour.Delete();\r
-               contour = tFilter0.GetOutput();\r
-               \r
-               double bounds_contour[] = new double[6]; \r
-               \r
-               double trans_x=0., trans_y=0., trans_z=0., ratio_x=0.002, ratio_y=0.002, ratio_z=0.002;\r
-               contour.GetBounds(bounds_contour);\r
-//      \r
-//             ratio_x = (bounds_data[1]-bounds_data[0])/(bounds_contour[1]-bounds_contour[0]);\r
-//             ratio_y = (bounds_data[3]-bounds_data[2])/(bounds_contour[3]-bounds_contour[2]);\r
-//             ratio_z = (bounds_data[5]-bounds_data[4])/(bounds_contour[5]-bounds_contour[4]);\r
-               ratio_x = l*0.0008;\r
-               ratio_y = l*0.0008;\r
-               ratio_z = l*0.0008;\r
-               \r
-               \r
-               System.out.println(ratio_x + " " + ratio_y);\r
-               \r
-               \r
-//             \r
-               vtkTransform transform1 = new vtkTransform();\r
-               transform1.Scale(ratio_x,ratio_y,ratio_z);\r
-               \r
-               vtkTransformPolyDataFilter tFilter1 = new vtkTransformPolyDataFilter();\r
-               tFilter1.SetInput(contour);\r
-               tFilter1.SetTransform(transform1);\r
-               tFilter1.Update();\r
-               \r
-               contour.Delete();\r
-               contour = tFilter1.GetOutput();\r
-               \r
-               double center_contour[] = new double[3];\r
-               contour.GetCenter(center_contour);\r
-               trans_x = center_data[0]-center_contour[0];\r
-               trans_y = center_data[1]-center_contour[1];\r
-               trans_z = center_data[2]-center_contour[2];\r
-//             \r
-               System.out.println(trans_x + " " + trans_y + " " + trans_z);\r
-//\r
-               vtkTransform transform2 = new vtkTransform();\r
-               transform2.Translate( trans_x, trans_y, trans_z);\r
-               \r
-               vtkTransformPolyDataFilter tFilter2 = new vtkTransformPolyDataFilter();\r
-               tFilter2.SetInput(contour);\r
-               tFilter2.SetTransform(transform2);\r
-               tFilter2.Update();\r
-               \r
-               contour.Delete();\r
-               contour = tFilter2.GetOutput();\r
-               \r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               mapper.SetInput(contour);\r
-               \r
-                \r
-               vtkActor actor =new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               actor.GetProperty().SetLineWidth(2.);\r
-               actor.GetProperty().SetColor(0,0,1);\r
-               actor.GetProperty().Delete();\r
-               \r
-               tmpRenderer.RemoveActor(tmpProp);\r
-               \r
-               tFilter0.Delete();\r
-               tFilter1.Delete();\r
-               tFilter2.Delete();\r
-               contour.Delete();\r
-               contourFilter.Delete();\r
-               mapper.Delete();\r
-               tmpRenderWindow.Delete();\r
-               transform0.Delete();\r
-               transform1.Delete();\r
-               transform2.Delete();\r
-               windowToImageFilter.GetOutputPort().Delete();\r
-               windowToImageFilter.Delete();\r
-               \r
-               ren.AddActor(actor);\r
-               \r
-//             vtkMatrix4x4 m = camera.GetModelTransformMatrix();\r
-//             m.Invert();\r
-//             actor.SetUserMatrix(m);\r
-               //m.Delete();\r
-               //actor.SetPosition(trans_x,trans_y, trans_z);\r
-               //actor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);\r
-               //\r
-               return actor;\r
-       }\r
-       \r
-       public static vtkActor createSilhouette(vtkRenderer ren, vtkDataObject data) {\r
-               \r
-               \r
-               vtkPolyDataSilhouette silhouette = new vtkPolyDataSilhouette();\r
-               \r
-               silhouette.SetInput(data);\r
-               silhouette.SetCamera(ren.GetActiveCamera());\r
-               silhouette.SetEnableFeatureAngle(0);\r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               \r
-               mapper.SetInputConnection(silhouette.GetOutputPort());\r
-               \r
-               vtkActor actor = new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               \r
-               silhouette.GetOutputPort().Delete();\r
-               silhouette.Delete();\r
-               mapper.Delete();\r
-               \r
-               return actor;\r
-       }\r
-       \r
-       public static vtkActor createOutline(vtkDataObject data) {\r
-               vtkOutlineFilter filter = new vtkOutlineFilter();\r
-               filter.SetInput(data);\r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               mapper.SetInputConnection(filter.GetOutputPort());\r
-               \r
-               vtkActor actor = new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               \r
-               filter.GetOutputPort().Delete();\r
-               filter.Delete();\r
-               mapper.Delete();\r
-               \r
-               return actor;\r
-       }\r
-       \r
-       public static vtkActor createOutline(vtkProp3D prop) {\r
-\r
-               double bounds[] = prop.GetBounds();\r
-\r
-               vtkOutlineSource source = new vtkOutlineSource();\r
-               source.SetBounds(bounds);\r
-               \r
-               vtkOutlineFilter filter = new vtkOutlineFilter();\r
-               filter.SetInput(source.GetOutput());\r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               mapper.SetInputConnection(filter.GetOutputPort());\r
-               \r
-               vtkActor actor = new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               \r
-               source.GetOutput().Delete();\r
-               source.Delete();\r
-               filter.GetOutputPort().Delete();\r
-               filter.Delete();\r
-               mapper.Delete();\r
-               \r
-               actor.SetPickable(0);\r
-               return actor;\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.utils;
+
+import javax.vecmath.AxisAngle4d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.vtk.shape.IvtkVisualObject;
+
+import vtk.vtkActor;
+import vtk.vtkCamera;
+import vtk.vtkContourFilter;
+import vtk.vtkDataObject;
+import vtk.vtkOutlineFilter;
+import vtk.vtkOutlineSource;
+import vtk.vtkPolyData;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkPolyDataSilhouette;
+import vtk.vtkProp3D;
+import vtk.vtkRenderWindow;
+import vtk.vtkRenderer;
+import vtk.vtkTransform;
+import vtk.vtkTransformPolyDataFilter;
+import vtk.vtkWindowToImageFilter;
+
+public class vtkEffect {
+
+       private static vtkRenderer tmpRenderer;
+       
+       public static vtkRenderer getRenderer() {
+               if (tmpRenderer == null)
+                       tmpRenderer = new vtkRenderer();
+               return tmpRenderer;
+       }
+       public static vtkActor createContour(vtkProp3D tmpProp) {
+               
+               vtkRenderer tmpRenderer = getRenderer();
+               tmpRenderer.SetBackground(1,1,1);
+               
+               
+               if (tmpProp instanceof IvtkVisualObject) {
+                       ((IvtkVisualObject)tmpProp).addToRenderer();
+               } else {
+                       tmpRenderer.AddActor(tmpProp);
+               }
+               
+               if (tmpProp instanceof vtkActor) {
+                       ((vtkActor)tmpProp).GetProperty().SetColor(0, 0, 0);
+               }
+               
+               
+               double bounds_data[] = tmpProp.GetBounds();
+               double center_data[] = tmpProp.GetCenter();
+               
+               tmpRenderer.ResetCamera();
+               tmpRenderer.GetActiveCamera().SetParallelProjection(1);
+               
+               vtkRenderWindow tmpRenderWindow = new vtkRenderWindow();
+               tmpRenderWindow.SetOffScreenRendering(1);
+               tmpRenderWindow.AddRenderer(tmpRenderer);
+               tmpRenderWindow.Render();
+               
+               vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();
+               windowToImageFilter.SetInput(tmpRenderWindow);
+               //windowToImageFilter.SetMagnification(2);
+               windowToImageFilter.Update();
+               
+               vtkContourFilter contourFilter = new vtkContourFilter();
+               contourFilter.SetInputConnection(windowToImageFilter.GetOutputPort());
+               
+               contourFilter.SetValue(0, 255);
+               contourFilter.Update();
+               
+               vtkPolyData contour = contourFilter.GetOutput();
+               
+               double bounds_contour[] = new double[6]; 
+               double center_contour[] = new double[3];
+               double trans_x=0., trans_y=0., trans_z=0., ratio_x=0., ratio_y=0.;
+               contour.GetBounds(bounds_contour);
+        
+               ratio_x = (bounds_data[1]-bounds_data[0])/(bounds_contour[1]-bounds_contour[0]);
+               ratio_y = (bounds_data[3]-bounds_data[2])/(bounds_contour[3]-bounds_contour[2]);
+               
+               vtkTransform transform1 = new vtkTransform();
+               transform1.Scale(ratio_x,ratio_y,1);
+               
+               vtkTransformPolyDataFilter tFilter1 = new vtkTransformPolyDataFilter();
+               tFilter1.SetInputData(contour);
+               tFilter1.SetTransform(transform1);
+               tFilter1.Update();
+               
+               contour = tFilter1.GetOutput();
+               
+               contour.GetCenter(center_contour);
+               trans_x = center_data[0]-center_contour[0];
+               trans_y = center_data[1]-center_contour[1];
+               trans_z = center_data[2]-center_contour[2];
+
+               vtkTransform transform2 = new vtkTransform();
+               transform2.Translate( trans_x, trans_y, trans_z);
+               
+               vtkTransformPolyDataFilter tFilter2 = new vtkTransformPolyDataFilter();
+               tFilter2.SetInputData(contour);
+               tFilter2.SetTransform(transform2);
+               tFilter2.Update();
+               
+               contour = tFilter2.GetOutput();
+               
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               mapper.SetInputData(contour);
+               
+                
+               vtkActor actor =new vtkActor();
+               actor.SetMapper(mapper);
+               actor.GetProperty().SetLineWidth(2.);
+               
+               tmpRenderer.RemoveActor(tmpProp);
+               
+               tFilter1.Delete();
+               tFilter2.Delete();
+               contour.Delete();
+               contourFilter.Delete();
+               mapper.Delete();
+               tmpRenderWindow.Delete();
+               transform1.Delete();
+               transform2.Delete();
+               windowToImageFilter.Delete();
+               
+               return actor;
+       }
+       
+       public static vtkActor createContour(vtkProp3D tmpProp, vtkRenderer ren) {
+               
+               vtkRenderer tmpRenderer = getRenderer();
+               tmpRenderer.SetBackground(1,1,1);
+               
+               
+               if (tmpProp instanceof IvtkVisualObject) {
+                       ((IvtkVisualObject)tmpProp).addToRenderer();
+               } else {
+                       tmpRenderer.AddActor(tmpProp);
+               }
+               
+               if (tmpProp instanceof vtkActor) {
+                       ((vtkActor)tmpProp).GetProperty().SetColor(0, 0, 0);
+               }
+               
+               
+               //double bounds_data[] = tmpProp.GetBounds();
+               double center_data[] = tmpProp.GetCenter();
+               
+               tmpRenderer.ResetCamera();
+               
+               vtkCamera camera = ren.GetActiveCamera();
+               
+               vtkCamera tmpCamera = tmpRenderer.GetActiveCamera(); 
+               tmpCamera.SetParallelProjection(camera.GetParallelProjection());
+               
+               
+               Vector3d pos = new Vector3d(camera.GetPosition());
+               Vector3d foc = new Vector3d(camera.GetFocalPoint());
+               Vector3d dir = new Vector3d();
+               dir.sub(pos,foc);
+               double l = dir.length();
+//             dir.scale(1.0/l);
+//             
+//             
+//
+//             
+//             dir.scale(2.0);
+//             Vector3d tmpFoc = new Vector3d(tmpCamera.GetFocalPoint());
+//             tmpFoc.add(dir);
+//             tmpCamera.SetPosition(tmpFoc.x,tmpFoc.y,tmpFoc.z);
+//             tmpCamera.SetRoll(camera.GetRoll());
+               
+               tmpCamera.DeepCopy(camera);
+               //tmpCamera.SetModelTransformMatrix(camera.GetModelTransformMatrix());
+               tmpCamera.UpdateViewport(tmpRenderer);
+               
+               vtkRenderWindow tmpRenderWindow = new vtkRenderWindow();
+               tmpRenderWindow.SetOffScreenRendering(1);
+               tmpRenderWindow.AddRenderer(tmpRenderer);
+               tmpRenderWindow.Render();
+               
+               vtkWindowToImageFilter windowToImageFilter = new vtkWindowToImageFilter();
+               windowToImageFilter.SetInput(tmpRenderWindow);
+               //windowToImageFilter.SetMagnification(2);
+               windowToImageFilter.Update();
+               
+               vtkContourFilter contourFilter = new vtkContourFilter();
+               contourFilter.SetInputConnection(windowToImageFilter.GetOutputPort());
+               
+               contourFilter.SetValue(0, 255);
+               contourFilter.Update();
+               
+               vtkPolyData contour = contourFilter.GetOutput();
+               
+               
+               double or[] = camera.GetOrientationWXYZ();
+               AxisAngle4d aa = new AxisAngle4d();
+               aa.angle = -MathTools.degToRad(or[0]);
+               aa.x = or[1];
+               aa.y = or[2];
+               aa.z = or[3];
+               
+               vtkTransform transform0 = new vtkTransform();
+               transform0.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);
+               
+               vtkTransformPolyDataFilter tFilter0 = new vtkTransformPolyDataFilter();
+               tFilter0.SetInputData(contour);
+               tFilter0.SetTransform(transform0);
+               tFilter0.Update();
+               
+               contour.Delete();
+               contour = tFilter0.GetOutput();
+               
+               double bounds_contour[] = new double[6]; 
+               
+               double trans_x=0., trans_y=0., trans_z=0., ratio_x=0.002, ratio_y=0.002, ratio_z=0.002;
+               contour.GetBounds(bounds_contour);
+//      
+//             ratio_x = (bounds_data[1]-bounds_data[0])/(bounds_contour[1]-bounds_contour[0]);
+//             ratio_y = (bounds_data[3]-bounds_data[2])/(bounds_contour[3]-bounds_contour[2]);
+//             ratio_z = (bounds_data[5]-bounds_data[4])/(bounds_contour[5]-bounds_contour[4]);
+               ratio_x = l*0.0008;
+               ratio_y = l*0.0008;
+               ratio_z = l*0.0008;
+               
+               
+               System.out.println(ratio_x + " " + ratio_y);
+               
+               
+//             
+               vtkTransform transform1 = new vtkTransform();
+               transform1.Scale(ratio_x,ratio_y,ratio_z);
+               
+               vtkTransformPolyDataFilter tFilter1 = new vtkTransformPolyDataFilter();
+               tFilter1.SetInputData(contour);
+               tFilter1.SetTransform(transform1);
+               tFilter1.Update();
+               
+               contour.Delete();
+               contour = tFilter1.GetOutput();
+               
+               double center_contour[] = new double[3];
+               contour.GetCenter(center_contour);
+               trans_x = center_data[0]-center_contour[0];
+               trans_y = center_data[1]-center_contour[1];
+               trans_z = center_data[2]-center_contour[2];
+//             
+               System.out.println(trans_x + " " + trans_y + " " + trans_z);
+//
+               vtkTransform transform2 = new vtkTransform();
+               transform2.Translate( trans_x, trans_y, trans_z);
+               
+               vtkTransformPolyDataFilter tFilter2 = new vtkTransformPolyDataFilter();
+               tFilter2.SetInputData(contour);
+               tFilter2.SetTransform(transform2);
+               tFilter2.Update();
+               
+               contour.Delete();
+               contour = tFilter2.GetOutput();
+               
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               mapper.SetInputData(contour);
+               
+                
+               vtkActor actor =new vtkActor();
+               actor.SetMapper(mapper);
+               actor.GetProperty().SetLineWidth(2.);
+               actor.GetProperty().SetColor(0,0,1);
+               actor.GetProperty().Delete();
+               
+               tmpRenderer.RemoveActor(tmpProp);
+               
+               tFilter0.Delete();
+               tFilter1.Delete();
+               tFilter2.Delete();
+               contour.Delete();
+               contourFilter.Delete();
+               mapper.Delete();
+               tmpRenderWindow.Delete();
+               transform0.Delete();
+               transform1.Delete();
+               transform2.Delete();
+               windowToImageFilter.GetOutputPort().Delete();
+               windowToImageFilter.Delete();
+               
+               ren.AddActor(actor);
+               
+//             vtkMatrix4x4 m = camera.GetModelTransformMatrix();
+//             m.Invert();
+//             actor.SetUserMatrix(m);
+               //m.Delete();
+               //actor.SetPosition(trans_x,trans_y, trans_z);
+               //actor.RotateWXYZ(MathTools.radToDeg(aa.angle), aa.x, aa.y, aa.z);
+               //
+               return actor;
+       }
+       
+       public static vtkActor createSilhouette(vtkRenderer ren, vtkDataObject data) {
+               
+               
+               vtkPolyDataSilhouette silhouette = new vtkPolyDataSilhouette();
+               
+               silhouette.SetInputData(data);
+               silhouette.SetCamera(ren.GetActiveCamera());
+               silhouette.SetEnableFeatureAngle(0);
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               
+               mapper.SetInputConnection(silhouette.GetOutputPort());
+               
+               vtkActor actor = new vtkActor();
+               actor.SetMapper(mapper);
+               
+               silhouette.GetOutputPort().Delete();
+               silhouette.Delete();
+               mapper.Delete();
+               
+               return actor;
+       }
+       
+       public static vtkActor createOutline(vtkDataObject data) {
+               vtkOutlineFilter filter = new vtkOutlineFilter();
+               filter.SetInputData(data);
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               mapper.SetInputConnection(filter.GetOutputPort());
+               
+               vtkActor actor = new vtkActor();
+               actor.SetMapper(mapper);
+               
+               filter.GetOutputPort().Delete();
+               filter.Delete();
+               mapper.Delete();
+               
+               return actor;
+       }
+       
+       public static vtkActor createOutline(vtkProp3D prop) {
+
+               double bounds[] = prop.GetBounds();
+
+               vtkOutlineSource source = new vtkOutlineSource();
+               source.SetBounds(bounds);
+               
+               vtkOutlineFilter filter = new vtkOutlineFilter();
+               filter.SetInputData(source.GetOutput());
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               mapper.SetInputConnection(filter.GetOutputPort());
+               
+               vtkActor actor = new vtkActor();
+               actor.SetMapper(mapper);
+               
+               source.GetOutput().Delete();
+               source.Delete();
+               filter.GetOutputPort().Delete();
+               filter.Delete();
+               mapper.Delete();
+               
+               actor.SetPickable(0);
+               return actor;
+       }
+}
index 8f5078dff059460fdccda26614d4e872127c2ba0..8f8c7b1523ea589358106b8c1a9b815a7ce55a47 100644 (file)
-/*******************************************************************************\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.opencascade.vtk;\r
-\r
-import java.util.List;\r
-\r
-import javax.vecmath.Matrix4d;\r
-import javax.vecmath.Point3d;\r
-\r
-import org.jcae.opencascade.jni.BRepMesh_IncrementalMesh;\r
-import org.jcae.opencascade.jni.BRep_Tool;\r
-import org.jcae.opencascade.jni.GP_Trsf;\r
-import org.jcae.opencascade.jni.Poly_Triangulation;\r
-import org.jcae.opencascade.jni.TopAbs_Orientation;\r
-import org.jcae.opencascade.jni.TopAbs_ShapeEnum;\r
-import org.jcae.opencascade.jni.TopExp_Explorer;\r
-import org.jcae.opencascade.jni.TopLoc_Location;\r
-import org.jcae.opencascade.jni.TopoDS_Face;\r
-import org.jcae.opencascade.jni.TopoDS_Shape;\r
-import org.simantics.opencascade.OCCTTool;\r
-\r
-import vtk.vtkActor;\r
-import vtk.vtkAlgorithmOutput;\r
-import vtk.vtkAppendPolyData;\r
-import vtk.vtkAssembly;\r
-import vtk.vtkCleanPolyData;\r
-import vtk.vtkDataSetMapper;\r
-import vtk.vtkFeatureEdges;\r
-import vtk.vtkGlyph3D;\r
-import vtk.vtkIdList;\r
-import vtk.vtkPoints;\r
-import vtk.vtkPolyData;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkPolyDataNormals;\r
-import vtk.vtkProp;\r
-import vtk.vtkPropCollection;\r
-import vtk.vtkProperty;\r
-import vtk.vtkSphereSource;\r
-import vtk.vtkTriangle;\r
-\r
-public class VTKOCCTool {\r
-       public static vtkAssembly vtkTestAssembly() {\r
-               vtkAssembly assemblies = new vtkAssembly();\r
-               vtkPolyData partGrid = createTestPartGrid();\r
-               gridToAssembly(assemblies, partGrid);\r
-               return assemblies;\r
-       }\r
-       \r
-       public static vtkAssembly vtkOCCShapeToAssembly(TopoDS_Shape shape) {\r
-               double deflection = 0.001;\r
-\r
-               if (deflection <= 0.0) {\r
-                       deflection = 0.0005;\r
-                       System.out.println("Bad value for deflection. Using: " + deflection);\r
-               }\r
-\r
-               // FIXME : leaks memory!\r
-               //BRepTools.clean(shape);\r
-\r
-               double mass = OCCTTool.getMass(shape);\r
-\r
-               if (mass < 1.0e-12) {\r
-                       System.out.println("Non 3D-shape detected");\r
-                       System.out.println("The cad import features are currently limited to 3D models.");\r
-               }\r
-\r
-               double length = OCCTTool.getBoundingBoxDiagonal(shape);\r
-               deflection *= length; // use relative units\r
-\r
-               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection);\r
-\r
-               int faceNumber = 0;\r
-               TopExp_Explorer expFace = new TopExp_Explorer();\r
-\r
-               vtkAssembly assemblies = new vtkAssembly();\r
-               for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {\r
-                       TopoDS_Face face = (TopoDS_Face) expFace.current();\r
-                       vtkPolyData partGrid = createPartGrid(face);\r
-                       face.delete();\r
-                       if (partGrid == null)\r
-                               continue;\r
-                       faceNumber++;\r
-                       //gridToAssembly(assemblies, partGrid, stlSurfaceData, stlEdgeData);\r
-                       gridToAssembly(assemblies, partGrid);\r
-                       \r
-               }\r
-               expFace.delete();\r
-               mesh.delete();\r
-\r
-               if (faceNumber == 0) {\r
-                       System.out\r
-                                       .println("Cad import: error: no surface triangulation was generated.");\r
-                       return null;\r
-               }\r
-\r
-               return assemblies;\r
-       }\r
-       \r
-       private static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid, vtkAppendPolyData stlSurfaceData, vtkAppendPolyData stlEdgeData) {\r
-        \r
-        double featureAngle = 30;\r
-\r
-        \r
-        vtkDataSetMapper partMapper = new vtkDataSetMapper();\r
-        \r
-        boolean computeNormals = true;\r
-        boolean cleanPart = true;\r
-        boolean mergePoints = false;\r
-\r
-        vtkCleanPolyData partCleaner = new vtkCleanPolyData();       \r
-        if (cleanPart)\r
-        {\r
-            partCleaner.SetInput(partGrid);\r
-            if(mergePoints) {\r
-              partCleaner.PointMergingOn();\r
-            } else {\r
-              partCleaner.PointMergingOff();\r
-            }\r
-        }\r
-        \r
-        if (computeNormals)\r
-        {\r
-            vtkPolyDataNormals partNormals = new vtkPolyDataNormals();\r
-         \r
-            if (cleanPart)\r
-            {\r
-                partNormals.SetInputConnection(partCleaner.GetOutputPort());\r
-            }\r
-            else partNormals.SetInput(partGrid);\r
-                \r
-            partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called\r
-            partMapper.SetInputConnection(partNormals.GetOutputPort());\r
-            partNormals.Delete();          \r
-        }\r
-        else\r
-        {\r
-            if (cleanPart) partMapper.SetInputConnection(partCleaner.GetOutputPort()); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-            else partMapper.SetInput(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-        }\r
-        partMapper.ScalarVisibilityOn();\r
-        \r
-        vtkActor partActor = new vtkActor();\r
-\r
-        partActor.SetPickable(1);\r
-        partActor.GetProperty().SetColor(1, 1, 0);\r
-        partActor.SetMapper(partMapper);\r
-        \r
-        // EDGES OF PARTS DETECTION\r
-        vtkFeatureEdges partEdges = new vtkFeatureEdges();\r
-        if (cleanPart) partEdges.SetInputConnection(partCleaner.GetOutputPort());\r
-        else partEdges.SetInput(partGrid); \r
-        partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called\r
-        partEdges.FeatureEdgesOn();\r
-        partEdges.BoundaryEdgesOn();\r
-        partEdges.NonManifoldEdgesOn();\r
-        partEdges.ManifoldEdgesOn();\r
-\r
-        vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();\r
-        partEdgesMapper.SetInputConnection(partEdges.GetOutputPort());\r
-        partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();\r
-        partEdgesMapper.ScalarVisibilityOff();\r
-        \r
-        vtkActor partEdgesActor = new vtkActor();\r
-        partEdgesActor.SetPickable(0);\r
-        partEdgesActor.GetProperty().SetColor(1, 0, 1);\r
-        partEdgesActor.SetMapper(partEdgesMapper);\r
-        \r
-\r
-        // Add triangles and edges to STL structures:\r
-        //--------------------------------------------\r
-        if (cleanPart) stlSurfaceData.AddInput(partCleaner.GetOutput());\r
-        else stlSurfaceData.AddInput(partGrid);\r
-        stlEdgeData.AddInput(partEdges.GetOutput());\r
-                \r
-        assemblies.AddPart(partActor);\r
-        assemblies.AddPart(partEdgesActor);        \r
-        \r
-        // Clean up:\r
-        //----------\r
-        partEdgesActor.Delete();\r
-        partEdgesMapper.Delete();\r
-        partEdges.Delete();\r
-        partActor.Delete();\r
-        partMapper.Delete();\r
-        partGrid.Delete();\r
-        partCleaner.Delete();\r
-    }\r
-\r
-public static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid) {\r
-    \r
-    double featureAngle = 30;\r
-\r
-    \r
-    vtkDataSetMapper partMapper = new vtkDataSetMapper();\r
-    \r
-    boolean computeNormals = true;\r
-    boolean cleanPart = false;\r
-    boolean mergePoints = false;\r
-\r
-    vtkCleanPolyData partCleaner = new vtkCleanPolyData();       \r
-    if (cleanPart)\r
-    {\r
-        partCleaner.SetInput(partGrid);\r
-        if(mergePoints) {\r
-          partCleaner.PointMergingOn();\r
-        } else {\r
-          partCleaner.PointMergingOff();\r
-        }\r
-    }\r
-    \r
-    if (computeNormals)\r
-    {\r
-        vtkPolyDataNormals partNormals = new vtkPolyDataNormals();\r
-     \r
-        if (cleanPart)\r
-        {\r
-               vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-            partNormals.SetInputConnection(out);\r
-            out.Delete();\r
-        }\r
-        else partNormals.SetInput(partGrid);\r
-            \r
-        partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called\r
-        vtkAlgorithmOutput out = partNormals.GetOutputPort();\r
-        partMapper.SetInputConnection(out);\r
-        out.Delete();\r
-        partNormals.Delete();          \r
-    }\r
-    else\r
-    {\r
-        if (cleanPart) {\r
-               vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-               partMapper.SetInputConnection(out); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-               out.Delete();\r
-        }\r
-        else partMapper.SetInput(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-    }\r
-    partMapper.ScalarVisibilityOn();\r
-    \r
-    vtkActor partActor = new vtkActor();\r
-    partActor.SetPickable(1);\r
-    vtkProperty prop = partActor.GetProperty();\r
-    prop.SetColor(1, 1, 0);\r
-    prop.Delete();\r
-    partActor.SetMapper(partMapper);\r
-    \r
-    assemblies.AddPart(partActor);\r
-    \r
-    {\r
-           // EDGES OF PARTS DETECTION\r
-           vtkFeatureEdges partEdges = new vtkFeatureEdges();\r
-           if (cleanPart) {\r
-               vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-               partEdges.SetInputConnection(out);\r
-               out.Delete();\r
-           }\r
-           else partEdges.SetInput(partGrid); \r
-          // partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called\r
-           partEdges.FeatureEdgesOn();\r
-           partEdges.BoundaryEdgesOn();\r
-           partEdges.NonManifoldEdgesOn();\r
-           partEdges.ManifoldEdgesOn();\r
-       \r
-           vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();\r
-           vtkAlgorithmOutput out = partEdges.GetOutputPort();\r
-           partEdgesMapper.SetInputConnection(out);\r
-           out.Delete();\r
-           partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();\r
-           partEdgesMapper.ScalarVisibilityOff();\r
-           \r
-           vtkActor partEdgesActor = new vtkActor();\r
-          \r
-           prop = partEdgesActor.GetProperty();\r
-           prop.SetColor(0, 0, 0);\r
-           prop.SetLineWidth(2.0);\r
-           prop.Delete();\r
-           partEdgesActor.SetMapper(partEdgesMapper);\r
-           partEdgesActor.PickableOn();  \r
-           \r
-           assemblies.AddPart(partEdgesActor);        \r
-           \r
-           {\r
-\r
-               EdgePointsFilter edgePoints = new EdgePointsFilter();\r
-               \r
-                \r
-               out = partEdges.GetOutputPort();\r
-                   edgePoints.SetInputConnection(out);\r
-                   out.Delete();\r
-                   \r
-//                 vtkDataSetMapper partEdgePointsMapper = new vtkDataSetMapper();\r
-//                 out = edgePoints.GetOutputPort();\r
-//                 partEdgePointsMapper.SetInputConnection(out);\r
-//                 out.Delete();\r
-                   \r
-//                 vtkVertexGlyphFilter glyphFilter = new vtkVertexGlyphFilter();\r
-//                 out = edgePoints.GetOutputPort();\r
-//                 glyphFilter.SetInputConnection(out);\r
-//                 glyphFilter.Update();\r
-//                 out.Delete();\r
-//                 \r
-//                 vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();\r
-//                 out = glyphFilter.GetOutputPort();\r
-//                 partEdgePointsMapper.SetInputConnection(out);\r
-//                 out.Delete();\r
-                   \r
-                   vtkSphereSource sphereSource = new vtkSphereSource();\r
-                   vtkGlyph3D glyph3D = new vtkGlyph3D();\r
-                   out = sphereSource.GetOutputPort();\r
-                   glyph3D.SetSourceConnection(out);\r
-                   out.Delete();\r
-                   \r
-                   out = edgePoints.GetOutputPort();\r
-                   glyph3D.SetInputConnection(out);\r
-                   out.Delete();\r
-                   \r
-                   //glyph3D.ScalingOff();\r
-                   glyph3D.SetScaleFactor(0.03);\r
-                   \r
-                   glyph3D.Update();\r
-                   \r
-                   vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();\r
-                   out = glyph3D.GetOutputPort();\r
-                   partEdgePointsMapper.SetInputConnection(out);\r
-                   out.Delete();\r
-                   \r
-                   vtkActor edgePointsActor = new vtkActor();\r
-                  \r
-                   prop = edgePointsActor.GetProperty();\r
-                   prop.SetColor(0, 0, 1);\r
-                   //prop.SetPointSize(10.0);\r
-                   //prop.SetRepresentationToPoints();\r
-                   prop.Delete();\r
-                   edgePointsActor.SetMapper(partEdgePointsMapper);\r
-                  \r
-                   edgePointsActor.PickableOn();\r
-                   assemblies.AddPart(edgePointsActor);\r
-                   \r
-                   \r
-                   edgePointsActor.Delete();\r
-                   partEdgePointsMapper.Delete();\r
-                  // edgePoints.Delete();\r
-           }\r
-           // Clean up:\r
-           //----------\r
-           partEdgesActor.Delete();\r
-           partEdgesMapper.Delete();\r
-           partEdges.Delete();\r
-    }\r
-   \r
-    partActor.Delete();\r
-    partMapper.Delete();\r
-    partGrid.Delete();\r
-    partCleaner.Delete();\r
-}\r
-       \r
-       \r
-       \r
-       public static vtkPolyData createPartGrid ( TopoDS_Face face)\r
-    {\r
-        TopLoc_Location Location = new TopLoc_Location();\r
-        \r
-        Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);\r
-\r
-        if(triangulation == null) {\r
-               Location.delete();\r
-               System.out.println("Encountered empty triangulation after face");\r
-               return null;\r
-        }\r
-                \r
-        boolean reverse = face.orientation()==TopAbs_Orientation.REVERSED;\r
-\r
-        int[]triangles = triangulation.triangles();\r
-        double[]nodes = triangulation.nodes();\r
-\r
-        int nofTriangles = triangulation.nbTriangles();\r
-        int nofNodes = triangulation.nbNodes();\r
-        \r
-        triangulation.delete();\r
-\r
-        if(nofTriangles < 1) {\r
-          System.out.println("No triangles for mesh on face");\r
-          Location.delete();\r
-          return null;\r
-        }\r
-\r
-        if(nofNodes < 1) {\r
-            System.out.println("No nodes for mesh on face:");\r
-            Location.delete();\r
-            return null;\r
-        }\r
-        //System.out.println("v " + nofNodes + " t " +nofTriangles);\r
-        vtkPolyData partGrid = new vtkPolyData();\r
-        partGrid.Allocate(nofTriangles, nofTriangles);\r
-\r
-        vtkTriangle triangle = new vtkTriangle();\r
-        vtkIdList list = triangle.GetPointIds();\r
-        for(int i = 0; i < nofTriangles; i++) \r
-        {\r
-          int n0, n1, n2;\r
-          if (!reverse) {\r
-                 n0 = triangles[3 * i]; \r
-                 n1 = triangles[3 * i + 1]; \r
-                 n2 = triangles[3 * i + 2];\r
-          } else {\r
-                 n0 = triangles[3 * i + 2]; \r
-                 n1 = triangles[3 * i + 1]; \r
-                 n2 = triangles[3 * i];\r
-          }\r
-          \r
-          list.SetId(0, n0);\r
-          list.SetId(1, n1);\r
-          list.SetId(2, n2);\r
-          partGrid.InsertNextCell(triangle.GetCellType(), list);\r
-          \r
-        }\r
-        list.Delete();\r
-        triangle.Delete();   \r
-        \r
-        GP_Trsf transformation = Location.transformation();\r
-        Location.delete();\r
-\r
-        double d_mat[] = new double[16];\r
-        double d_p[] = new double[3];\r
-        transformation.getValues(d_mat);\r
-        Matrix4d mat = new Matrix4d(d_mat);\r
-        \r
-        vtkPoints partPoints = new vtkPoints();\r
-        \r
-        for(int i = 0; i < nofNodes; i++) {     \r
-          // FIXME: GP_Trsf.transform(double[]) leaks memory\r
-               \r
-          //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          \r
-          //transformation.transforms(xyz);\r
-          //partPoints.InsertPoint(i, xyz);\r
-               Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);\r
-               mat.transform(p);\r
-               d_p[0] = p.x;\r
-               d_p[1] = p.y;\r
-               d_p[2] = p.z;\r
-               partPoints.InsertPoint(i, d_p);\r
-        }\r
-        \r
-        transformation.delete();\r
-        \r
-        partGrid.SetPoints(partPoints);\r
-        partPoints.Delete();\r
-       \r
-        return partGrid;\r
-    }\r
-       \r
-       \r
-       \r
-       public static vtkPolyData createPartGrid ( List<Double> meshPoints, List<Integer> meshTriangles)\r
-    {\r
-       \r
-                \r
-      \r
-\r
-        \r
-        int nofTriangles = meshTriangles.size() / 3;\r
-        int nofNodes = meshPoints.size() /3;\r
-        \r
-      \r
-        if(nofTriangles < 1) {\r
-          System.out.println("No triangles for mesh on face");\r
-          return null;\r
-        }\r
-\r
-        if(nofNodes < 1) {\r
-            System.out.println("No nodes for mesh on face:");\r
-            return null;\r
-        }\r
-        //System.out.println("v " + nofNodes + " t " +nofTriangles);\r
-        vtkPolyData partGrid = new vtkPolyData();\r
-        partGrid.Allocate(nofTriangles, nofTriangles);\r
-\r
-        vtkTriangle triangle = new vtkTriangle();\r
-        vtkIdList list = triangle.GetPointIds();\r
-        for(int i = 0; i < nofTriangles; i++) \r
-        {\r
-          int n0, n1, n2;          \r
-          n0 = meshTriangles.get(3 * i); \r
-          n1 = meshTriangles.get(3 * i + 1);\r
-          n2 = meshTriangles.get(3 * i + 2); \r
-\r
-         \r
-          list.SetId(0, n0);\r
-          list.SetId(1, n1);\r
-          list.SetId(2, n2);\r
-          partGrid.InsertNextCell(triangle.GetCellType(), list);\r
-          \r
-        }\r
-        list.Delete();\r
-        triangle.Delete();   \r
-        \r
-\r
-\r
-        double d_p[] = new double[3];\r
-\r
-        \r
-        vtkPoints partPoints = new vtkPoints();\r
-        \r
-        for(int i = 0; i < nofNodes; i++) {     \r
-\r
-               d_p[0] = meshPoints.get(3*i);\r
-               d_p[1] = meshPoints.get(3*i+1);\r
-               d_p[2] = meshPoints.get(3*i+2);\r
-               partPoints.InsertPoint(i, d_p);\r
-        }\r
-        \r
-        partGrid.SetPoints(partPoints);\r
-        partPoints.Delete();\r
-       \r
-        return partGrid;\r
-    }\r
-       \r
-       private static vtkPolyData createTestPartGrid ()\r
-    {\r
-               int size = 64;\r
-               \r
-        double[] nodes = new double[(size+1)*(size+1)*3];\r
-        int[] triangles = new int[3 * size * size * 2];\r
-\r
-        double es = 1.0;\r
-        for (int i = 0; i <= size; i++) {\r
-               for (int j = 0; j <= size; j++) {\r
-                       int index = j * size + i;\r
-                       index *= 3;\r
-                       double x = (double)i * es;\r
-                       double y = (Math.sin((double)i/(double)size)  + Math.sin((double)j/(double)size)) * es;\r
-                       double z = (double)j * es;\r
-                       nodes[index] = x;\r
-                       nodes[index+1] = y;\r
-                       nodes[index+2] = z;\r
-               }\r
-        }\r
-        \r
-        for (int i = 0; i < size; i++) {\r
-               for (int j = 0; j < size; j++) {\r
-                       int index = j * size + i;\r
-                       index *= 3;\r
-                       index *= 2;\r
-                       triangles[index  ] = (j     * (size+1) + i  );\r
-                       triangles[index+1] = (j     * (size+1) + i+1);\r
-                       triangles[index+2] = ((j+1) * (size+1) + i  );\r
-                       triangles[index+3] = ((j+1) * (size+1) + i  );\r
-                       triangles[index+4] = ((j  ) * (size+1) + i +1 );\r
-                       triangles[index+5] = ((j+1) * (size+1) + i +1 );\r
-               }\r
-        }\r
-\r
-        int nofTriangles = triangles.length / 3;\r
-        int nofNodes = nodes.length / 3;\r
-\r
-        if(nofTriangles < 1) {\r
-         \r
-          return null;\r
-        }\r
-\r
-        if(nofNodes < 1) {\r
-           \r
-            return null;\r
-        }\r
-        //System.out.println("v " + nofNodes + " t " +nofTriangles);\r
-        vtkPolyData partGrid = new vtkPolyData();\r
-        partGrid.Allocate(nofTriangles, nofTriangles);\r
-\r
-        vtkTriangle triangle = new vtkTriangle();\r
-        vtkIdList list = triangle.GetPointIds();\r
-        for(int i = 0; i < nofTriangles; i++) \r
-        {\r
-          int n0, n1, n2;          \r
-          n0 = triangles[3 * i]; n1 = triangles[3 * i + 1]; n2 = triangles[3 * i + 2]; // triangles(i).Get(n0, n1, n2);\r
-\r
-//          if(face.orientation() != TopAbs_Orientation.FORWARD) {\r
-//              int tmp = n2; n2 = n1; n1 = tmp;\r
-//          }\r
-         \r
-          list.SetId(0, n0);\r
-          list.SetId(1, n1);\r
-          list.SetId(2, n2);\r
-          partGrid.InsertNextCell(triangle.GetCellType(), list);\r
-          \r
-        }\r
-        list.Delete();\r
-        triangle.Delete();      \r
-\r
-        vtkPoints partPoints = new vtkPoints();\r
-        for(int i = 0; i < nofNodes; i++) {       \r
-            double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          \r
-            partPoints.InsertPoint(i, xyz);\r
-        }\r
-        \r
-        partGrid.SetPoints(partPoints);\r
-        \r
-        partPoints.Delete();\r
-\r
-        return partGrid;\r
-    }\r
-       \r
-       public static void test() {\r
-               TopoDS_Shape shape = null;\r
-               //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);\r
-               for (int t = 0; t < 5000; t++) {\r
-                       //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);\r
-                       int test = 2;\r
-                       if (test == 0) {\r
-                               vtkAssembly ass = VTKOCCTool.vtkOCCShapeToAssembly(shape);\r
-                               vtkPropCollection col;\r
-                       col = ass.GetParts();\r
-                       for (int i = 0; i < col.GetNumberOfItems(); i++)\r
-                       {\r
-                           vtkProp prop = (vtkProp) col.GetItemAsObject(i);\r
-                           //System.out.println(prop.Print());\r
-                           prop.Delete();\r
-                       }\r
-                       col.Delete();\r
-                       ass.Delete();\r
-                       }\r
-                       else if (test == 1) {\r
-                               //BRepTools.clean(shape);\r
-                               \r
-                               \r
-                               vtkAssembly ass = new vtkAssembly();\r
-                               \r
-                               double vol = OCCTTool.getBoundingBoxDiagonal(shape);\r
-                               double d = 0.001 * vol;\r
-                               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,d);\r
-                               TopExp_Explorer expFace = new TopExp_Explorer();\r
-                               for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {\r
-                                       TopoDS_Face face = (TopoDS_Face) expFace.current();\r
-                                       {\r
-//                                             TopLoc_Location Location = new TopLoc_Location();\r
-//                                             Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);\r
-//                                             if (triangulation != null) {\r
-//                                                     \r
-//                                                     int[]triangles = triangulation.triangles();\r
-//                                             double[]nodes = triangulation.nodes();\r
-//                                             int nofTriangles = triangulation.nbTriangles();\r
-//                                             int nofNodes = triangulation.nbNodes();\r
-//                                             \r
-//                                             triangulation.delete();\r
-//                                             \r
-//                                             GP_Trsf transformation = Location.transformation();\r
-//                                             double d_mat[] = new double[16];\r
-//                                             transformation.getValues(d_mat);\r
-//                                             Matrix4d mat = new Matrix4d(d_mat);\r
-//                                             for(int i = 0; i < nofNodes; i++) {       \r
-//                                                 //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          \r
-//                                                 Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);\r
-//                                                     //transformation.transforms(xyz);\r
-//                                                 mat.transform(p);\r
-//                                             }\r
-//                                             transformation.delete();\r
-//                                             }\r
-//                                             \r
-//                                             Location.delete();\r
-                                               vtkPolyData data = VTKOCCTool.createPartGrid(face);\r
-                                               VTKOCCTool.gridToAssembly(ass, data);\r
-                                               //data.Delete();\r
-                                       }\r
-                                       face.delete();\r
-                               }\r
-                               expFace.delete();\r
-                               mesh.delete();\r
-                               \r
-                               vtkPropCollection col;\r
-                       col = ass.GetParts();\r
-                       for (int i = 0; i < col.GetNumberOfItems(); i++)\r
-                       {\r
-                           vtkProp prop = (vtkProp) col.GetItemAsObject(i);\r
-                           //System.out.println(prop.Print());\r
-                           prop.Delete();\r
-                       }\r
-                       col.Delete();\r
-                       ass.Delete();\r
-                       } else if (test == 2) {\r
-                               double[] pointStruct = new double[]{0,0,0}, dirStruct = new double[]{0,1,0};\r
-                               double radius = 1.0;\r
-                               double height = 1.0;\r
-                               \r
-                               double[] axe = new double[6];\r
-                                \r
-                       System.arraycopy(pointStruct, 0, axe, 0, 3);\r
-                       System.arraycopy(dirStruct, 0, axe, 3, 3);\r
-                       org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder cyl = new org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder(axe, radius, height, 2 * Math.PI);\r
-                       org.jcae.opencascade.jni.TopoDS_Shape tds = cyl.shape();\r
-                       cyl.delete();\r
-                       \r
-                       double vol = OCCTTool.getBoundingBoxDiagonal(tds);\r
-                               double d = 0.001 * vol;\r
-                               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(tds,d);\r
-//                             TopExp_Explorer expFace = new TopExp_Explorer();\r
-//                             for (expFace.init(tds, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {\r
-//                                     TopoDS_Face face = (TopoDS_Face) expFace.current();\r
-//                                     {\r
-//                                             \r
-//                                     }\r
-//                                     face.delete();\r
-//                             }\r
-                               mesh.delete();\r
-                               \r
-                       tds.delete();\r
-                       }\r
-                       //shape.delete();\r
-               System.out.println(t);\r
-               }\r
-               //shape.delete();\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.opencascade.vtk;
+
+import java.util.List;
+
+import javax.vecmath.Matrix4d;
+import javax.vecmath.Point3d;
+
+import org.jcae.opencascade.jni.BRepMesh_IncrementalMesh;
+import org.jcae.opencascade.jni.BRep_Tool;
+import org.jcae.opencascade.jni.GP_Trsf;
+import org.jcae.opencascade.jni.Poly_Triangulation;
+import org.jcae.opencascade.jni.TopAbs_Orientation;
+import org.jcae.opencascade.jni.TopAbs_ShapeEnum;
+import org.jcae.opencascade.jni.TopExp_Explorer;
+import org.jcae.opencascade.jni.TopLoc_Location;
+import org.jcae.opencascade.jni.TopoDS_Face;
+import org.jcae.opencascade.jni.TopoDS_Shape;
+import org.simantics.opencascade.OCCTTool;
+
+import vtk.vtkActor;
+import vtk.vtkAlgorithmOutput;
+import vtk.vtkAppendPolyData;
+import vtk.vtkAssembly;
+import vtk.vtkCleanPolyData;
+import vtk.vtkDataSetMapper;
+import vtk.vtkFeatureEdges;
+import vtk.vtkGlyph3D;
+import vtk.vtkIdList;
+import vtk.vtkPoints;
+import vtk.vtkPolyData;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkPolyDataNormals;
+import vtk.vtkProp;
+import vtk.vtkPropCollection;
+import vtk.vtkProperty;
+import vtk.vtkSphereSource;
+import vtk.vtkTriangle;
+
+public class VTKOCCTool {
+       public static vtkAssembly vtkTestAssembly() {
+               vtkAssembly assemblies = new vtkAssembly();
+               vtkPolyData partGrid = createTestPartGrid();
+               gridToAssembly(assemblies, partGrid);
+               return assemblies;
+       }
+       
+       public static vtkAssembly vtkOCCShapeToAssembly(TopoDS_Shape shape) {
+               double deflection = 0.001;
+
+               if (deflection <= 0.0) {
+                       deflection = 0.0005;
+                       System.out.println("Bad value for deflection. Using: " + deflection);
+               }
+
+               // FIXME : leaks memory!
+               //BRepTools.clean(shape);
+
+               double mass = OCCTTool.getMass(shape);
+
+               if (mass < 1.0e-12) {
+                       System.out.println("Non 3D-shape detected");
+                       System.out.println("The cad import features are currently limited to 3D models.");
+               }
+
+               double length = OCCTTool.getBoundingBoxDiagonal(shape);
+               deflection *= length; // use relative units
+
+               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection);
+
+               int faceNumber = 0;
+               TopExp_Explorer expFace = new TopExp_Explorer();
+
+               vtkAssembly assemblies = new vtkAssembly();
+               for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
+                       TopoDS_Face face = (TopoDS_Face) expFace.current();
+                       vtkPolyData partGrid = createPartGrid(face);
+                       face.delete();
+                       if (partGrid == null)
+                               continue;
+                       faceNumber++;
+                       //gridToAssembly(assemblies, partGrid, stlSurfaceData, stlEdgeData);
+                       gridToAssembly(assemblies, partGrid);
+                       
+               }
+               expFace.delete();
+               mesh.delete();
+
+               if (faceNumber == 0) {
+                       System.out
+                                       .println("Cad import: error: no surface triangulation was generated.");
+                       return null;
+               }
+
+               return assemblies;
+       }
+       
+       private static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid, vtkAppendPolyData stlSurfaceData, vtkAppendPolyData stlEdgeData) {
+        
+        double featureAngle = 30;
+
+        
+        vtkDataSetMapper partMapper = new vtkDataSetMapper();
+        
+        boolean computeNormals = true;
+        boolean cleanPart = true;
+        boolean mergePoints = false;
+
+        vtkCleanPolyData partCleaner = new vtkCleanPolyData();       
+        if (cleanPart)
+        {
+            partCleaner.SetInputData(partGrid);
+            if(mergePoints) {
+              partCleaner.PointMergingOn();
+            } else {
+              partCleaner.PointMergingOff();
+            }
+        }
+        
+        if (computeNormals)
+        {
+            vtkPolyDataNormals partNormals = new vtkPolyDataNormals();
+         
+            if (cleanPart)
+            {
+                partNormals.SetInputConnection(partCleaner.GetOutputPort());
+            }
+            else partNormals.SetInputData(partGrid);
+                
+            partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called
+            partMapper.SetInputConnection(partNormals.GetOutputPort());
+            partNormals.Delete();          
+        }
+        else
+        {
+            if (cleanPart) partMapper.SetInputConnection(partCleaner.GetOutputPort()); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+            else partMapper.SetInputData(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+        }
+        partMapper.ScalarVisibilityOn();
+        
+        vtkActor partActor = new vtkActor();
+
+        partActor.SetPickable(1);
+        partActor.GetProperty().SetColor(1, 1, 0);
+        partActor.SetMapper(partMapper);
+        
+        // EDGES OF PARTS DETECTION
+        vtkFeatureEdges partEdges = new vtkFeatureEdges();
+        if (cleanPart) partEdges.SetInputConnection(partCleaner.GetOutputPort());
+        else partEdges.SetInputData(partGrid); 
+        partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called
+        partEdges.FeatureEdgesOn();
+        partEdges.BoundaryEdgesOn();
+        partEdges.NonManifoldEdgesOn();
+        partEdges.ManifoldEdgesOn();
+
+        vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();
+        partEdgesMapper.SetInputConnection(partEdges.GetOutputPort());
+        partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();
+        partEdgesMapper.ScalarVisibilityOff();
+        
+        vtkActor partEdgesActor = new vtkActor();
+        partEdgesActor.SetPickable(0);
+        partEdgesActor.GetProperty().SetColor(1, 0, 1);
+        partEdgesActor.SetMapper(partEdgesMapper);
+        
+
+        // Add triangles and edges to STL structures:
+        //--------------------------------------------
+        if (cleanPart) stlSurfaceData.AddInputData(partCleaner.GetOutput());
+        else stlSurfaceData.AddInputData(partGrid);
+        stlEdgeData.AddInputData(partEdges.GetOutput());
+                
+        assemblies.AddPart(partActor);
+        assemblies.AddPart(partEdgesActor);        
+        
+        // Clean up:
+        //----------
+        partEdgesActor.Delete();
+        partEdgesMapper.Delete();
+        partEdges.Delete();
+        partActor.Delete();
+        partMapper.Delete();
+        partGrid.Delete();
+        partCleaner.Delete();
+    }
+
+public static void gridToAssembly(vtkAssembly assemblies, vtkPolyData partGrid) {
+    
+    double featureAngle = 30;
+
+    
+    vtkDataSetMapper partMapper = new vtkDataSetMapper();
+    
+    boolean computeNormals = true;
+    boolean cleanPart = false;
+    boolean mergePoints = false;
+
+    vtkCleanPolyData partCleaner = new vtkCleanPolyData();       
+    if (cleanPart)
+    {
+        partCleaner.SetInputData(partGrid);
+        if(mergePoints) {
+          partCleaner.PointMergingOn();
+        } else {
+          partCleaner.PointMergingOff();
+        }
+    }
+    
+    if (computeNormals)
+    {
+        vtkPolyDataNormals partNormals = new vtkPolyDataNormals();
+     
+        if (cleanPart)
+        {
+               vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+            partNormals.SetInputConnection(out);
+            out.Delete();
+        }
+        else partNormals.SetInputData(partGrid);
+            
+        partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called
+        vtkAlgorithmOutput out = partNormals.GetOutputPort();
+        partMapper.SetInputConnection(out);
+        out.Delete();
+        partNormals.Delete();          
+    }
+    else
+    {
+        if (cleanPart) {
+               vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+               partMapper.SetInputConnection(out); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+               out.Delete();
+        }
+        else partMapper.SetInputData(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+    }
+    partMapper.ScalarVisibilityOn();
+    
+    vtkActor partActor = new vtkActor();
+    partActor.SetPickable(1);
+    vtkProperty prop = partActor.GetProperty();
+    prop.SetColor(1, 1, 0);
+    prop.Delete();
+    partActor.SetMapper(partMapper);
+    
+    assemblies.AddPart(partActor);
+    
+    {
+           // EDGES OF PARTS DETECTION
+           vtkFeatureEdges partEdges = new vtkFeatureEdges();
+           if (cleanPart) {
+               vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+               partEdges.SetInputConnection(out);
+               out.Delete();
+           }
+           else partEdges.SetInputData(partGrid); 
+          // partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called
+           partEdges.FeatureEdgesOn();
+           partEdges.BoundaryEdgesOn();
+           partEdges.NonManifoldEdgesOn();
+           partEdges.ManifoldEdgesOn();
+       
+           vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();
+           vtkAlgorithmOutput out = partEdges.GetOutputPort();
+           partEdgesMapper.SetInputConnection(out);
+           out.Delete();
+           partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();
+           partEdgesMapper.ScalarVisibilityOff();
+           
+           vtkActor partEdgesActor = new vtkActor();
+          
+           prop = partEdgesActor.GetProperty();
+           prop.SetColor(0, 0, 0);
+           prop.SetLineWidth(2.0);
+           prop.Delete();
+           partEdgesActor.SetMapper(partEdgesMapper);
+           partEdgesActor.PickableOn();  
+           
+           assemblies.AddPart(partEdgesActor);        
+           
+           {
+
+               EdgePointsFilter edgePoints = new EdgePointsFilter();
+               
+                
+               out = partEdges.GetOutputPort();
+                   edgePoints.SetInputConnection(out);
+                   out.Delete();
+                   
+//                 vtkDataSetMapper partEdgePointsMapper = new vtkDataSetMapper();
+//                 out = edgePoints.GetOutputPort();
+//                 partEdgePointsMapper.SetInputConnection(out);
+//                 out.Delete();
+                   
+//                 vtkVertexGlyphFilter glyphFilter = new vtkVertexGlyphFilter();
+//                 out = edgePoints.GetOutputPort();
+//                 glyphFilter.SetInputConnection(out);
+//                 glyphFilter.Update();
+//                 out.Delete();
+//                 
+//                 vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();
+//                 out = glyphFilter.GetOutputPort();
+//                 partEdgePointsMapper.SetInputConnection(out);
+//                 out.Delete();
+                   
+                   vtkSphereSource sphereSource = new vtkSphereSource();
+                   vtkGlyph3D glyph3D = new vtkGlyph3D();
+                   out = sphereSource.GetOutputPort();
+                   glyph3D.SetSourceConnection(out);
+                   out.Delete();
+                   
+                   out = edgePoints.GetOutputPort();
+                   glyph3D.SetInputConnection(out);
+                   out.Delete();
+                   
+                   //glyph3D.ScalingOff();
+                   glyph3D.SetScaleFactor(0.03);
+                   
+                   glyph3D.Update();
+                   
+                   vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();
+                   out = glyph3D.GetOutputPort();
+                   partEdgePointsMapper.SetInputConnection(out);
+                   out.Delete();
+                   
+                   vtkActor edgePointsActor = new vtkActor();
+                  
+                   prop = edgePointsActor.GetProperty();
+                   prop.SetColor(0, 0, 1);
+                   //prop.SetPointSize(10.0);
+                   //prop.SetRepresentationToPoints();
+                   prop.Delete();
+                   edgePointsActor.SetMapper(partEdgePointsMapper);
+                  
+                   edgePointsActor.PickableOn();
+                   assemblies.AddPart(edgePointsActor);
+                   
+                   
+                   edgePointsActor.Delete();
+                   partEdgePointsMapper.Delete();
+                  // edgePoints.Delete();
+           }
+           // Clean up:
+           //----------
+           partEdgesActor.Delete();
+           partEdgesMapper.Delete();
+           partEdges.Delete();
+    }
+   
+    partActor.Delete();
+    partMapper.Delete();
+    partGrid.Delete();
+    partCleaner.Delete();
+}
+       
+       
+       
+       public static vtkPolyData createPartGrid ( TopoDS_Face face)
+    {
+        TopLoc_Location Location = new TopLoc_Location();
+        
+        Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);
+
+        if(triangulation == null) {
+               Location.delete();
+               System.out.println("Encountered empty triangulation after face");
+               return null;
+        }
+                
+        boolean reverse = face.orientation()==TopAbs_Orientation.REVERSED;
+
+        int[]triangles = triangulation.triangles();
+        double[]nodes = triangulation.nodes();
+
+        int nofTriangles = triangulation.nbTriangles();
+        int nofNodes = triangulation.nbNodes();
+        
+        triangulation.delete();
+
+        if(nofTriangles < 1) {
+          System.out.println("No triangles for mesh on face");
+          Location.delete();
+          return null;
+        }
+
+        if(nofNodes < 1) {
+            System.out.println("No nodes for mesh on face:");
+            Location.delete();
+            return null;
+        }
+        //System.out.println("v " + nofNodes + " t " +nofTriangles);
+        vtkPolyData partGrid = new vtkPolyData();
+        partGrid.Allocate(nofTriangles, nofTriangles);
+
+        vtkTriangle triangle = new vtkTriangle();
+        vtkIdList list = triangle.GetPointIds();
+        for(int i = 0; i < nofTriangles; i++) 
+        {
+          int n0, n1, n2;
+          if (!reverse) {
+                 n0 = triangles[3 * i]; 
+                 n1 = triangles[3 * i + 1]; 
+                 n2 = triangles[3 * i + 2];
+          } else {
+                 n0 = triangles[3 * i + 2]; 
+                 n1 = triangles[3 * i + 1]; 
+                 n2 = triangles[3 * i];
+          }
+          
+          list.SetId(0, n0);
+          list.SetId(1, n1);
+          list.SetId(2, n2);
+          partGrid.InsertNextCell(triangle.GetCellType(), list);
+          
+        }
+        list.Delete();
+        triangle.Delete();   
+        
+        GP_Trsf transformation = Location.transformation();
+        Location.delete();
+
+        double d_mat[] = new double[16];
+        double d_p[] = new double[3];
+        transformation.getValues(d_mat);
+        Matrix4d mat = new Matrix4d(d_mat);
+        
+        vtkPoints partPoints = new vtkPoints();
+        
+        for(int i = 0; i < nofNodes; i++) {     
+          // FIXME: GP_Trsf.transform(double[]) leaks memory
+               
+          //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
+          //transformation.transforms(xyz);
+          //partPoints.InsertPoint(i, xyz);
+               Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);
+               mat.transform(p);
+               d_p[0] = p.x;
+               d_p[1] = p.y;
+               d_p[2] = p.z;
+               partPoints.InsertPoint(i, d_p);
+        }
+        
+        transformation.delete();
+        
+        partGrid.SetPoints(partPoints);
+        partPoints.Delete();
+       
+        return partGrid;
+    }
+       
+       
+       
+       public static vtkPolyData createPartGrid ( List<Double> meshPoints, List<Integer> meshTriangles)
+    {
+       
+                
+      
+
+        
+        int nofTriangles = meshTriangles.size() / 3;
+        int nofNodes = meshPoints.size() /3;
+        
+      
+        if(nofTriangles < 1) {
+          System.out.println("No triangles for mesh on face");
+          return null;
+        }
+
+        if(nofNodes < 1) {
+            System.out.println("No nodes for mesh on face:");
+            return null;
+        }
+        //System.out.println("v " + nofNodes + " t " +nofTriangles);
+        vtkPolyData partGrid = new vtkPolyData();
+        partGrid.Allocate(nofTriangles, nofTriangles);
+
+        vtkTriangle triangle = new vtkTriangle();
+        vtkIdList list = triangle.GetPointIds();
+        for(int i = 0; i < nofTriangles; i++) 
+        {
+          int n0, n1, n2;          
+          n0 = meshTriangles.get(3 * i); 
+          n1 = meshTriangles.get(3 * i + 1);
+          n2 = meshTriangles.get(3 * i + 2); 
+
+         
+          list.SetId(0, n0);
+          list.SetId(1, n1);
+          list.SetId(2, n2);
+          partGrid.InsertNextCell(triangle.GetCellType(), list);
+          
+        }
+        list.Delete();
+        triangle.Delete();   
+        
+
+
+        double d_p[] = new double[3];
+
+        
+        vtkPoints partPoints = new vtkPoints();
+        
+        for(int i = 0; i < nofNodes; i++) {     
+
+               d_p[0] = meshPoints.get(3*i);
+               d_p[1] = meshPoints.get(3*i+1);
+               d_p[2] = meshPoints.get(3*i+2);
+               partPoints.InsertPoint(i, d_p);
+        }
+        
+        partGrid.SetPoints(partPoints);
+        partPoints.Delete();
+       
+        return partGrid;
+    }
+       
+       private static vtkPolyData createTestPartGrid ()
+    {
+               int size = 64;
+               
+        double[] nodes = new double[(size+1)*(size+1)*3];
+        int[] triangles = new int[3 * size * size * 2];
+
+        double es = 1.0;
+        for (int i = 0; i <= size; i++) {
+               for (int j = 0; j <= size; j++) {
+                       int index = j * size + i;
+                       index *= 3;
+                       double x = (double)i * es;
+                       double y = (Math.sin((double)i/(double)size)  + Math.sin((double)j/(double)size)) * es;
+                       double z = (double)j * es;
+                       nodes[index] = x;
+                       nodes[index+1] = y;
+                       nodes[index+2] = z;
+               }
+        }
+        
+        for (int i = 0; i < size; i++) {
+               for (int j = 0; j < size; j++) {
+                       int index = j * size + i;
+                       index *= 3;
+                       index *= 2;
+                       triangles[index  ] = (j     * (size+1) + i  );
+                       triangles[index+1] = (j     * (size+1) + i+1);
+                       triangles[index+2] = ((j+1) * (size+1) + i  );
+                       triangles[index+3] = ((j+1) * (size+1) + i  );
+                       triangles[index+4] = ((j  ) * (size+1) + i +1 );
+                       triangles[index+5] = ((j+1) * (size+1) + i +1 );
+               }
+        }
+
+        int nofTriangles = triangles.length / 3;
+        int nofNodes = nodes.length / 3;
+
+        if(nofTriangles < 1) {
+         
+          return null;
+        }
+
+        if(nofNodes < 1) {
+           
+            return null;
+        }
+        //System.out.println("v " + nofNodes + " t " +nofTriangles);
+        vtkPolyData partGrid = new vtkPolyData();
+        partGrid.Allocate(nofTriangles, nofTriangles);
+
+        vtkTriangle triangle = new vtkTriangle();
+        vtkIdList list = triangle.GetPointIds();
+        for(int i = 0; i < nofTriangles; i++) 
+        {
+          int n0, n1, n2;          
+          n0 = triangles[3 * i]; n1 = triangles[3 * i + 1]; n2 = triangles[3 * i + 2]; // triangles(i).Get(n0, n1, n2);
+
+//          if(face.orientation() != TopAbs_Orientation.FORWARD) {
+//              int tmp = n2; n2 = n1; n1 = tmp;
+//          }
+         
+          list.SetId(0, n0);
+          list.SetId(1, n1);
+          list.SetId(2, n2);
+          partGrid.InsertNextCell(triangle.GetCellType(), list);
+          
+        }
+        list.Delete();
+        triangle.Delete();      
+
+        vtkPoints partPoints = new vtkPoints();
+        for(int i = 0; i < nofNodes; i++) {       
+            double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
+            partPoints.InsertPoint(i, xyz);
+        }
+        
+        partGrid.SetPoints(partPoints);
+        
+        partPoints.Delete();
+
+        return partGrid;
+    }
+       
+       public static void test() {
+               TopoDS_Shape shape = null;
+               //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);
+               for (int t = 0; t < 5000; t++) {
+                       //shape = OccTriangulator.makeCylinder(new double[]{0,0,0}, new double[]{0,1,0}, 1, 1);
+                       int test = 2;
+                       if (test == 0) {
+                               vtkAssembly ass = VTKOCCTool.vtkOCCShapeToAssembly(shape);
+                               vtkPropCollection col;
+                       col = ass.GetParts();
+                       for (int i = 0; i < col.GetNumberOfItems(); i++)
+                       {
+                           vtkProp prop = (vtkProp) col.GetItemAsObject(i);
+                           //System.out.println(prop.Print());
+                           prop.Delete();
+                       }
+                       col.Delete();
+                       ass.Delete();
+                       }
+                       else if (test == 1) {
+                               //BRepTools.clean(shape);
+                               
+                               
+                               vtkAssembly ass = new vtkAssembly();
+                               
+                               double vol = OCCTTool.getBoundingBoxDiagonal(shape);
+                               double d = 0.001 * vol;
+                               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,d);
+                               TopExp_Explorer expFace = new TopExp_Explorer();
+                               for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
+                                       TopoDS_Face face = (TopoDS_Face) expFace.current();
+                                       {
+//                                             TopLoc_Location Location = new TopLoc_Location();
+//                                             Poly_Triangulation triangulation = BRep_Tool.triangulation(face, Location);
+//                                             if (triangulation != null) {
+//                                                     
+//                                                     int[]triangles = triangulation.triangles();
+//                                             double[]nodes = triangulation.nodes();
+//                                             int nofTriangles = triangulation.nbTriangles();
+//                                             int nofNodes = triangulation.nbNodes();
+//                                             
+//                                             triangulation.delete();
+//                                             
+//                                             GP_Trsf transformation = Location.transformation();
+//                                             double d_mat[] = new double[16];
+//                                             transformation.getValues(d_mat);
+//                                             Matrix4d mat = new Matrix4d(d_mat);
+//                                             for(int i = 0; i < nofNodes; i++) {       
+//                                                 //double xyz[] = new double[]{nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]};          
+//                                                 Point3d p = new Point3d(nodes[3 * i], nodes[3 * i + 1], nodes[3 * i + 2]);
+//                                                     //transformation.transforms(xyz);
+//                                                 mat.transform(p);
+//                                             }
+//                                             transformation.delete();
+//                                             }
+//                                             
+//                                             Location.delete();
+                                               vtkPolyData data = VTKOCCTool.createPartGrid(face);
+                                               VTKOCCTool.gridToAssembly(ass, data);
+                                               //data.Delete();
+                                       }
+                                       face.delete();
+                               }
+                               expFace.delete();
+                               mesh.delete();
+                               
+                               vtkPropCollection col;
+                       col = ass.GetParts();
+                       for (int i = 0; i < col.GetNumberOfItems(); i++)
+                       {
+                           vtkProp prop = (vtkProp) col.GetItemAsObject(i);
+                           //System.out.println(prop.Print());
+                           prop.Delete();
+                       }
+                       col.Delete();
+                       ass.Delete();
+                       } else if (test == 2) {
+                               double[] pointStruct = new double[]{0,0,0}, dirStruct = new double[]{0,1,0};
+                               double radius = 1.0;
+                               double height = 1.0;
+                               
+                               double[] axe = new double[6];
+                                
+                       System.arraycopy(pointStruct, 0, axe, 0, 3);
+                       System.arraycopy(dirStruct, 0, axe, 3, 3);
+                       org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder cyl = new org.jcae.opencascade.jni.BRepPrimAPI_MakeCylinder(axe, radius, height, 2 * Math.PI);
+                       org.jcae.opencascade.jni.TopoDS_Shape tds = cyl.shape();
+                       cyl.delete();
+                       
+                       double vol = OCCTTool.getBoundingBoxDiagonal(tds);
+                               double d = 0.001 * vol;
+                               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(tds,d);
+//                             TopExp_Explorer expFace = new TopExp_Explorer();
+//                             for (expFace.init(tds, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
+//                                     TopoDS_Face face = (TopoDS_Face) expFace.current();
+//                                     {
+//                                             
+//                                     }
+//                                     face.delete();
+//                             }
+                               mesh.delete();
+                               
+                       tds.delete();
+                       }
+                       //shape.delete();
+               System.out.println(t);
+               }
+               //shape.delete();
+       }
+}
index 6e1e3dd1974dae04a20dd451dd3708f194f659bb..fd2c0bb1d6bc6637d7e613d671457fdd5e855a25 100644 (file)
-/*******************************************************************************\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.opencascade.vtk;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-\r
-import org.jcae.opencascade.jni.BRepMesh_IncrementalMesh;\r
-import org.jcae.opencascade.jni.TopAbs_ShapeEnum;\r
-import org.jcae.opencascade.jni.TopExp_Explorer;\r
-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
-import vtk.vtkActor;\r
-import vtk.vtkAlgorithmOutput;\r
-import vtk.vtkCleanPolyData;\r
-import vtk.vtkDataSetMapper;\r
-import vtk.vtkFeatureEdges;\r
-import vtk.vtkGlyph3D;\r
-import vtk.vtkPanel;\r
-import vtk.vtkPolyData;\r
-import vtk.vtkPolyDataMapper;\r
-import vtk.vtkPolyDataNormals;\r
-import vtk.vtkPolyDataSilhouette;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkProperty;\r
-import vtk.vtkRenderer;\r
-import vtk.vtkSphereSource;\r
-\r
-public class vtkSolidObject {\r
-       \r
-       public static double deflection = 0.001;\r
-       \r
-       public static double featureAngle = 30;\r
-       public static boolean computeNormals = true;\r
-       public static boolean cleanPart = false;\r
-       public static boolean mergePoints = false;\r
-       \r
-       private vtkPanel panel;\r
-       private TopoDS_Shape shape;\r
-       \r
-       private List<vtkProp3D> actors = new ArrayList<vtkProp3D>(2);\r
-       \r
-       private List<vtkProp3D> solid = new ArrayList<vtkProp3D>(1);\r
-       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
-       }\r
-       \r
-       public void visualizeSolid(boolean showEdges, boolean showVertices) {\r
-               visualizeSolid(true, showEdges, showVertices);\r
-       }\r
-       \r
-       public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices) {\r
-               visualizeSolid(showFaces, showEdges, showVertices, false);\r
-       }\r
-       \r
-       public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices, boolean showSilhouette) {\r
-               clearActorsAWT();\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
-               if (showEdges) {\r
-                       vtkActor edge = createEdgesActor(data);\r
-                       edges.add(edge);                        \r
-                       if (showVertices) {\r
-                               actors.add(createVerticesActor(edge));\r
-                       }\r
-               }\r
-               if (showSilhouette) {\r
-                       silhouette = createSilhouette(panel.GetRenderer(), data);\r
-               }\r
-               actors.addAll(solid);\r
-               actors.addAll(edges);\r
-               if (silhouette != null)\r
-                       actors.add(silhouette);\r
-               data.Delete();\r
-               showActorsAWT();\r
-       }\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
-                               vtkActor edgesActor = createEdgesActor(data); \r
-                               edges.add(edgesActor);\r
-                               if (showVertices) {\r
-                                       actors.add(createVerticesActor(edgesActor));\r
-                               }\r
-                       }\r
-                       data.Delete();\r
-               }\r
-               actors.addAll(solid);\r
-               actors.addAll(edges);\r
-               \r
-               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
-       }\r
-       \r
-       public List<vtkProp3D> getSolid() {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               return solid;\r
-       }\r
-       \r
-       public List<vtkProp3D> getEdges() {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               return edges;\r
-       }\r
-       \r
-       public vtkActor getSilhouette() {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               return silhouette;\r
-       }\r
-       \r
-       public void showActorsAWT() {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               vtkRenderer ren = panel.GetRenderer();\r
-               for (vtkProp3D act : actors) {\r
-                       ren.AddActor(act);\r
-               }\r
-       }\r
-       \r
-       public void showActors() {\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               showActorsAWT();\r
-                       }\r
-               });\r
-       }\r
-       \r
-       public void clearActorsAWT() {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               if (actors.size() == 0)\r
-                       return;\r
-               vtkRenderer ren = panel.GetRenderer();\r
-               for (vtkProp3D act : actors) {\r
-                       if (act.GetVTKId() != 0) {\r
-                               ren.RemoveActor(act);\r
-                               act.Delete();\r
-                       }\r
-               }\r
-               actors.clear();\r
-               solid.clear();\r
-               edges.clear();\r
-       }\r
-       \r
-       private void clearActorsAWT(List<vtkProp3D> actors) {\r
-               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());\r
-               \r
-               if (actors.size() == 0)\r
-                       return;\r
-               vtkRenderer ren = panel.GetRenderer();\r
-               panel.lock();\r
-               for (vtkProp3D act : actors) {\r
-                       if (act.GetVTKId() != 0) {\r
-                               ren.RemoveActor(act);\r
-                               act.Delete();\r
-                       }\r
-               }\r
-               panel.unlock();\r
-       }\r
-       \r
-       public void clearActors() {\r
-               if (actors.size() == 0)\r
-                       return;\r
-               final List<vtkProp3D> temp = new ArrayList<vtkProp3D>(actors.size());\r
-               temp.addAll(actors);\r
-               actors.clear();\r
-               solid.clear();\r
-               edges.clear();\r
-               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               clearActorsAWT(temp);\r
-                       }\r
-               });\r
-       }\r
-       \r
-       public void dispose() {\r
-               if (shape != null) {\r
-                       shape.delete();\r
-                       shape = null;\r
-               }\r
-               clearActors();\r
-       }\r
-       \r
-       public void delete() {\r
-               if (shape != null) {\r
-                       shape.delete();\r
-                       shape = null;\r
-               }\r
-               clearActorsAWT();\r
-       }\r
-       \r
-       private static double TOLERANCE = 0.01;\r
-       \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
-                       return null;\r
-               \r
-               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection*volume);\r
-       \r
-               TopExp_Explorer expFace = new TopExp_Explorer();\r
-               \r
-               List<Double> meshPoints = new ArrayList<Double>();\r
-               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
-                       if (!OCCTTool.appendToMesh(face, meshPoints, meshTriangles))\r
-                               success = false;\r
-                       face.delete();\r
-               }\r
-               if (meshPoints.size() == 0 || meshTriangles.size() == 0)\r
-                       return null;\r
-                       \r
-               vtkPolyData data = VTKOCCTool.createPartGrid(meshPoints, meshTriangles);\r
-               \r
-               expFace.delete();\r
-               mesh.delete();\r
-               \r
-               return new Pair<vtkPolyData, Boolean>(data, success);\r
-       }\r
-       \r
-       public static Collection<vtkPolyData> createFaceMeshes(TopoDS_Shape shape) {\r
-               \r
-               double volume = OCCTTool.getBoundingBoxDiagonal(shape);\r
-               Collection<vtkPolyData> faces = new ArrayList<vtkPolyData>();\r
-               \r
-               if (volume > TOLERANCE) {\r
-               \r
-                       BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection*volume);\r
-               \r
-                       TopExp_Explorer expFace = new TopExp_Explorer();\r
-                       \r
-                       \r
-                       for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {\r
-                               TopoDS_Face face = (TopoDS_Face) expFace.current();\r
-                               vtkPolyData data = VTKOCCTool.createPartGrid(face);\r
-                               face.delete();\r
-                               faces.add(data);\r
-                       }\r
-                       \r
-                       expFace.delete();\r
-                       mesh.delete();\r
-               }\r
-               \r
-               return faces;\r
-       }\r
-       \r
-       \r
-       \r
-       public static vtkActor createActor(vtkPolyData partGrid) {\r
-               \r
-               \r
-           vtkDataSetMapper partMapper = new vtkDataSetMapper();\r
-           \r
-           vtkCleanPolyData partCleaner = null;       \r
-           if (cleanPart)\r
-           {\r
-               partCleaner = new vtkCleanPolyData();\r
-               partCleaner.SetInput(partGrid);\r
-               if(mergePoints) {\r
-                 partCleaner.PointMergingOn();\r
-               } else {\r
-                 partCleaner.PointMergingOff();\r
-               }\r
-           }\r
-           \r
-           if (computeNormals)\r
-           {\r
-               vtkPolyDataNormals partNormals = new vtkPolyDataNormals();\r
-            \r
-               if (cleanPart)\r
-               {\r
-                       vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-                   partNormals.SetInputConnection(out);\r
-                   out.Delete();\r
-               }\r
-               else partNormals.SetInput(partGrid);\r
-                   \r
-               partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called\r
-               vtkAlgorithmOutput out = partNormals.GetOutputPort();\r
-               partMapper.SetInputConnection(out);\r
-               out.Delete();\r
-               partNormals.Delete();          \r
-           }\r
-           else\r
-           {\r
-               if (cleanPart) {\r
-                       vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-                       partMapper.SetInputConnection(out); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-                       out.Delete();\r
-               }\r
-               else partMapper.SetInput(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681\r
-           }\r
-           partMapper.ScalarVisibilityOn();\r
-           \r
-           vtkActor partActor = new vtkActor();\r
-          // partActor.SetPickable(1);\r
-           vtkProperty prop = partActor.GetProperty();\r
-           prop.SetColor(1, 1, 0);\r
-           prop.Delete();\r
-           partActor.SetMapper(partMapper);\r
-           \r
-           partMapper.Delete();\r
-           \r
-           if (cleanPart)\r
-               partCleaner.Delete();\r
-           \r
-           return partActor;\r
-       }\r
-       \r
-       public static vtkActor createEdgesActor(vtkPolyData partGrid) {\r
-               vtkCleanPolyData partCleaner = null;       \r
-          \r
-               if (cleanPart)\r
-           {\r
-                       partCleaner = new vtkCleanPolyData();\r
-               partCleaner.SetInput(partGrid);\r
-               if(mergePoints) {\r
-                 partCleaner.PointMergingOn();\r
-               } else {\r
-                 partCleaner.PointMergingOff();\r
-               }\r
-           }\r
-           \r
-               vtkFeatureEdges partEdges = new vtkFeatureEdges();\r
-           if (cleanPart) {\r
-               vtkAlgorithmOutput out = partCleaner.GetOutputPort();\r
-               partEdges.SetInputConnection(out);\r
-               out.Delete();\r
-           }\r
-           else partEdges.SetInput(partGrid); \r
-          // partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called\r
-           partEdges.FeatureEdgesOn();\r
-           partEdges.BoundaryEdgesOn();\r
-           partEdges.NonManifoldEdgesOn();\r
-           partEdges.ManifoldEdgesOn();\r
-       \r
-           vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();\r
-           vtkAlgorithmOutput out = partEdges.GetOutputPort();\r
-           partEdgesMapper.SetInputConnection(out);\r
-           out.Delete();\r
-           partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();\r
-           partEdgesMapper.ScalarVisibilityOff();\r
-           \r
-           vtkActor partEdgesActor = new vtkActor();\r
-          \r
-           vtkProperty prop = partEdgesActor.GetProperty();\r
-           prop.SetColor(0, 0, 0);\r
-           prop.SetLineWidth(2.0);\r
-           prop.Delete();\r
-           partEdgesActor.SetMapper(partEdgesMapper);\r
-\r
-           partEdgesMapper.Delete();\r
-           partEdges.Delete();\r
-           \r
-           if (cleanPart)\r
-               partCleaner.Delete();\r
-           \r
-           return partEdgesActor;\r
-       }\r
-       \r
-       public static vtkActor createVerticesActor(vtkActor partEdgesActor) {\r
-               vtkDataSetMapper partEdgesMapper = (vtkDataSetMapper) partEdgesActor.GetMapper();\r
-               vtkAlgorithmOutput out = partEdgesMapper.GetInputConnection(0, 0);\r
-               vtkFeatureEdges partEdges = (vtkFeatureEdges)out.GetProducer();\r
-               \r
-               vtkActor edgePointsActor = createVerticesActor(partEdges);\r
-               \r
-               partEdges.Delete();\r
-               //out.Delete();\r
-               partEdgesMapper.Delete();\r
-               return edgePointsActor;\r
-       }\r
-       \r
-       public static vtkActor createVerticesActor(vtkFeatureEdges partEdges) {\r
-               EdgePointsFilter edgePoints = new EdgePointsFilter();\r
-       \r
-        \r
-       vtkAlgorithmOutput out = partEdges.GetOutputPort();\r
-           edgePoints.SetInputConnection(out);\r
-           out.Delete();\r
-           \r
-           vtkSphereSource sphereSource = new vtkSphereSource();\r
-           vtkGlyph3D glyph3D = new vtkGlyph3D();\r
-           out = sphereSource.GetOutputPort();\r
-           glyph3D.SetSourceConnection(out);\r
-           out.Delete();\r
-           \r
-           out = edgePoints.GetOutputPort();\r
-           glyph3D.SetInputConnection(out);\r
-           out.Delete();\r
-           \r
-           glyph3D.SetScaleFactor(0.03);\r
-           \r
-           glyph3D.Update();\r
-           \r
-           vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();\r
-           out = glyph3D.GetOutputPort();\r
-           partEdgePointsMapper.SetInputConnection(out);\r
-           out.Delete();\r
-           \r
-           vtkActor edgePointsActor = new vtkActor();\r
-          \r
-           vtkProperty prop = edgePointsActor.GetProperty();\r
-           prop.SetColor(0, 0, 1);\r
-           prop.Delete();\r
-           edgePointsActor.SetMapper(partEdgePointsMapper);\r
-          \r
-           edgePointsActor.PickableOn();\r
-\r
-           \r
-           partEdgePointsMapper.Delete();\r
-           edgePoints.Delete();\r
-           sphereSource.Delete();\r
-           \r
-           return edgePointsActor;\r
-       }\r
-       \r
-       public static vtkActor createSilhouette(vtkRenderer ren, vtkPolyData data) {\r
-               \r
-               \r
-               vtkPolyDataSilhouette silhouette = new vtkPolyDataSilhouette();\r
-               \r
-               silhouette.SetInput(data);\r
-               silhouette.SetCamera(ren.GetActiveCamera());\r
-               silhouette.SetEnableFeatureAngle(0);\r
-               vtkPolyDataMapper mapper = new vtkPolyDataMapper();\r
-               \r
-               mapper.SetInputConnection(silhouette.GetOutputPort());\r
-               \r
-               vtkActor actor = new vtkActor();\r
-               actor.SetMapper(mapper);\r
-               \r
-               actor.GetProperty().SetColor(0,0,1);\r
-               actor.GetProperty().SetLineWidth(6);\r
-               \r
-               return actor;\r
-               \r
-               \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.opencascade.vtk;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jcae.opencascade.jni.BRepMesh_IncrementalMesh;
+import org.jcae.opencascade.jni.TopAbs_ShapeEnum;
+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;
+
+import vtk.vtkActor;
+import vtk.vtkAlgorithmOutput;
+import vtk.vtkCleanPolyData;
+import vtk.vtkDataSetMapper;
+import vtk.vtkFeatureEdges;
+import vtk.vtkGlyph3D;
+import vtk.vtkPanel;
+import vtk.vtkPolyData;
+import vtk.vtkPolyDataMapper;
+import vtk.vtkPolyDataNormals;
+import vtk.vtkPolyDataSilhouette;
+import vtk.vtkProp3D;
+import vtk.vtkProperty;
+import vtk.vtkRenderer;
+import vtk.vtkSphereSource;
+
+public class vtkSolidObject {
+       
+       public static double deflection = 0.001;
+       
+       public static double featureAngle = 30;
+       public static boolean computeNormals = true;
+       public static boolean cleanPart = false;
+       public static boolean mergePoints = false;
+       
+       private vtkPanel panel;
+       private TopoDS_Shape shape;
+       
+       private List<vtkProp3D> actors = new ArrayList<vtkProp3D>(2);
+       
+       private List<vtkProp3D> solid = new ArrayList<vtkProp3D>(1);
+       private List<vtkProp3D> edges =  new ArrayList<vtkProp3D>(1);
+       private vtkActor silhouette = null;
+       
+       private boolean errors = false;
+       
+       public vtkSolidObject(vtkPanel panel,TopoDS_Shape shape) {
+               this.shape = shape;
+               this.panel = panel;
+       }
+       
+       public void visualizeSolid(boolean showEdges, boolean showVertices) {
+               visualizeSolid(true, showEdges, showVertices);
+       }
+       
+       public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices) {
+               visualizeSolid(showFaces, showEdges, showVertices, false);
+       }
+       
+       public void visualizeSolid(boolean showFaces, boolean showEdges, boolean showVertices, boolean showSilhouette) {
+               clearActorsAWT();
+               errors = false;
+               Pair<vtkPolyData, Boolean> res = createSolidMesh(shape);
+               if (res == null) {
+                       errors = true;
+                       return;
+               }
+               vtkPolyData data = res.first;
+               if (!res.second)
+                       errors = true;
+               if (showFaces) {
+                       solid.add(createActor(data));           
+               }
+               if (showEdges) {
+                       vtkActor edge = createEdgesActor(data);
+                       edges.add(edge);                        
+                       if (showVertices) {
+                               actors.add(createVerticesActor(edge));
+                       }
+               }
+               if (showSilhouette) {
+                       silhouette = createSilhouette(panel.GetRenderer(), data);
+               }
+               actors.addAll(solid);
+               actors.addAll(edges);
+               if (silhouette != null)
+                       actors.add(silhouette);
+               data.Delete();
+               showActorsAWT();
+       }
+       
+       public void visualizeFaces(boolean showEdges, boolean showVertices) {
+               errors = false;
+               clearActorsAWT();
+               Collection<vtkPolyData> datas = createFaceMeshes(shape);
+               for (vtkPolyData data : datas) {
+                       if (data == null) {
+                               errors = true;
+                               continue;
+                       }
+                       
+                       solid.add(createActor(data));
+                       
+                       if (showEdges) {
+                               vtkActor edgesActor = createEdgesActor(data); 
+                               edges.add(edgesActor);
+                               if (showVertices) {
+                                       actors.add(createVerticesActor(edgesActor));
+                               }
+                       }
+                       data.Delete();
+               }
+               actors.addAll(solid);
+               actors.addAll(edges);
+               
+               showActorsAWT();
+       }
+       
+       public boolean hasErrors() {
+               return errors;
+       }
+       
+       public List<vtkProp3D> getActors() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               return actors;
+       }
+       
+       public List<vtkProp3D> getSolid() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               return solid;
+       }
+       
+       public List<vtkProp3D> getEdges() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               return edges;
+       }
+       
+       public vtkActor getSilhouette() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               return silhouette;
+       }
+       
+       public void showActorsAWT() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               vtkRenderer ren = panel.GetRenderer();
+               for (vtkProp3D act : actors) {
+                       ren.AddActor(act);
+               }
+       }
+       
+       public void showActors() {
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               showActorsAWT();
+                       }
+               });
+       }
+       
+       public void clearActorsAWT() {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               if (actors.size() == 0)
+                       return;
+               vtkRenderer ren = panel.GetRenderer();
+               for (vtkProp3D act : actors) {
+                       if (act.GetVTKId() != 0) {
+                               ren.RemoveActor(act);
+                               act.Delete();
+                       }
+               }
+               actors.clear();
+               solid.clear();
+               edges.clear();
+       }
+       
+       private void clearActorsAWT(List<vtkProp3D> actors) {
+               assert (Thread.currentThread() == AWTThread.getThreadAccess().getThread());
+               
+               if (actors.size() == 0)
+                       return;
+               vtkRenderer ren = panel.GetRenderer();
+               panel.lock();
+               for (vtkProp3D act : actors) {
+                       if (act.GetVTKId() != 0) {
+                               ren.RemoveActor(act);
+                               act.Delete();
+                       }
+               }
+               panel.unlock();
+       }
+       
+       public void clearActors() {
+               if (actors.size() == 0)
+                       return;
+               final List<vtkProp3D> temp = new ArrayList<vtkProp3D>(actors.size());
+               temp.addAll(actors);
+               actors.clear();
+               solid.clear();
+               edges.clear();
+               ThreadUtils.asyncExec(AWTThread.getThreadAccess(), new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               clearActorsAWT(temp);
+                       }
+               });
+       }
+       
+       public void dispose() {
+               if (shape != null) {
+                       shape.delete();
+                       shape = null;
+               }
+               clearActors();
+       }
+       
+       public void delete() {
+               if (shape != null) {
+                       shape.delete();
+                       shape = null;
+               }
+               clearActorsAWT();
+       }
+       
+       private static double TOLERANCE = 0.01;
+       
+       public static Pair<vtkPolyData, Boolean> createSolidMesh(TopoDS_Shape shape) {
+               
+               boolean success = true;
+               
+               double volume = OCCTTool.getBoundingBoxDiagonal(shape);
+               if (volume < TOLERANCE)
+                       return null;
+               
+               BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection*volume);
+       
+               TopExp_Explorer expFace = new TopExp_Explorer();
+               
+               List<Double> meshPoints = new ArrayList<Double>();
+               List<Integer> meshTriangles = new ArrayList<Integer>();
+               for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
+                       TopoDS_Face face = (TopoDS_Face) expFace.current();
+                       if (!OCCTTool.appendToMesh(face, meshPoints, meshTriangles))
+                               success = false;
+                       face.delete();
+               }
+               if (meshPoints.size() == 0 || meshTriangles.size() == 0)
+                       return null;
+                       
+               vtkPolyData data = VTKOCCTool.createPartGrid(meshPoints, meshTriangles);
+               
+               expFace.delete();
+               mesh.delete();
+               
+               return new Pair<vtkPolyData, Boolean>(data, success);
+       }
+       
+       public static Collection<vtkPolyData> createFaceMeshes(TopoDS_Shape shape) {
+               
+               double volume = OCCTTool.getBoundingBoxDiagonal(shape);
+               Collection<vtkPolyData> faces = new ArrayList<vtkPolyData>();
+               
+               if (volume > TOLERANCE) {
+               
+                       BRepMesh_IncrementalMesh mesh = new BRepMesh_IncrementalMesh(shape,deflection*volume);
+               
+                       TopExp_Explorer expFace = new TopExp_Explorer();
+                       
+                       
+                       for (expFace.init(shape, TopAbs_ShapeEnum.FACE); expFace.more(); expFace.next()) {
+                               TopoDS_Face face = (TopoDS_Face) expFace.current();
+                               vtkPolyData data = VTKOCCTool.createPartGrid(face);
+                               face.delete();
+                               faces.add(data);
+                       }
+                       
+                       expFace.delete();
+                       mesh.delete();
+               }
+               
+               return faces;
+       }
+       
+       
+       
+       public static vtkActor createActor(vtkPolyData partGrid) {
+               
+               
+           vtkDataSetMapper partMapper = new vtkDataSetMapper();
+           
+           vtkCleanPolyData partCleaner = null;       
+           if (cleanPart)
+           {
+               partCleaner = new vtkCleanPolyData();
+               partCleaner.SetInputData(partGrid);
+               if(mergePoints) {
+                 partCleaner.PointMergingOn();
+               } else {
+                 partCleaner.PointMergingOff();
+               }
+           }
+           
+           if (computeNormals)
+           {
+               vtkPolyDataNormals partNormals = new vtkPolyDataNormals();
+            
+               if (cleanPart)
+               {
+                       vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+                   partNormals.SetInputConnection(out);
+                   out.Delete();
+               }
+               else partNormals.SetInputData(partGrid);
+                   
+               partNormals.SetFeatureAngle(featureAngle); // this do not have to be neccesarily called
+               vtkAlgorithmOutput out = partNormals.GetOutputPort();
+               partMapper.SetInputConnection(out);
+               out.Delete();
+               partNormals.Delete();          
+           }
+           else
+           {
+               if (cleanPart) {
+                       vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+                       partMapper.SetInputConnection(out); // metoda 2, ne tak pekne, viz http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+                       out.Delete();
+               }
+               else partMapper.SetInputData(partGrid); // metoda 1, ne tak pekne stinovani, viz: http://www.codeguru.com/cpp/g-m/opengl/article.php/c2681
+           }
+           partMapper.ScalarVisibilityOn();
+           
+           vtkActor partActor = new vtkActor();
+          // partActor.SetPickable(1);
+           vtkProperty prop = partActor.GetProperty();
+           prop.SetColor(1, 1, 0);
+           prop.Delete();
+           partActor.SetMapper(partMapper);
+           
+           partMapper.Delete();
+           
+           if (cleanPart)
+               partCleaner.Delete();
+           
+           return partActor;
+       }
+       
+       public static vtkActor createEdgesActor(vtkPolyData partGrid) {
+               vtkCleanPolyData partCleaner = null;       
+          
+               if (cleanPart)
+           {
+                       partCleaner = new vtkCleanPolyData();
+               partCleaner.SetInputData(partGrid);
+               if(mergePoints) {
+                 partCleaner.PointMergingOn();
+               } else {
+                 partCleaner.PointMergingOff();
+               }
+           }
+           
+               vtkFeatureEdges partEdges = new vtkFeatureEdges();
+           if (cleanPart) {
+               vtkAlgorithmOutput out = partCleaner.GetOutputPort();
+               partEdges.SetInputConnection(out);
+               out.Delete();
+           }
+           else partEdges.SetInputData(partGrid); 
+          // partEdges.SetFeatureAngle(featureAngle);  // this do not have to be neccesarily called
+           partEdges.FeatureEdgesOn();
+           partEdges.BoundaryEdgesOn();
+           partEdges.NonManifoldEdgesOn();
+           partEdges.ManifoldEdgesOn();
+       
+           vtkDataSetMapper partEdgesMapper = new vtkDataSetMapper();
+           vtkAlgorithmOutput out = partEdges.GetOutputPort();
+           partEdgesMapper.SetInputConnection(out);
+           out.Delete();
+           partEdgesMapper.SetResolveCoincidentTopologyToPolygonOffset();
+           partEdgesMapper.ScalarVisibilityOff();
+           
+           vtkActor partEdgesActor = new vtkActor();
+          
+           vtkProperty prop = partEdgesActor.GetProperty();
+           prop.SetColor(0, 0, 0);
+           prop.SetLineWidth(2.0);
+           prop.Delete();
+           partEdgesActor.SetMapper(partEdgesMapper);
+
+           partEdgesMapper.Delete();
+           partEdges.Delete();
+           
+           if (cleanPart)
+               partCleaner.Delete();
+           
+           return partEdgesActor;
+       }
+       
+       public static vtkActor createVerticesActor(vtkActor partEdgesActor) {
+               vtkDataSetMapper partEdgesMapper = (vtkDataSetMapper) partEdgesActor.GetMapper();
+               vtkAlgorithmOutput out = partEdgesMapper.GetInputConnection(0, 0);
+               vtkFeatureEdges partEdges = (vtkFeatureEdges)out.GetProducer();
+               
+               vtkActor edgePointsActor = createVerticesActor(partEdges);
+               
+               partEdges.Delete();
+               //out.Delete();
+               partEdgesMapper.Delete();
+               return edgePointsActor;
+       }
+       
+       public static vtkActor createVerticesActor(vtkFeatureEdges partEdges) {
+               EdgePointsFilter edgePoints = new EdgePointsFilter();
+       
+        
+       vtkAlgorithmOutput out = partEdges.GetOutputPort();
+           edgePoints.SetInputConnection(out);
+           out.Delete();
+           
+           vtkSphereSource sphereSource = new vtkSphereSource();
+           vtkGlyph3D glyph3D = new vtkGlyph3D();
+           out = sphereSource.GetOutputPort();
+           glyph3D.SetSourceConnection(out);
+           out.Delete();
+           
+           out = edgePoints.GetOutputPort();
+           glyph3D.SetInputConnection(out);
+           out.Delete();
+           
+           glyph3D.SetScaleFactor(0.03);
+           
+           glyph3D.Update();
+           
+           vtkPolyDataMapper partEdgePointsMapper = new vtkPolyDataMapper();
+           out = glyph3D.GetOutputPort();
+           partEdgePointsMapper.SetInputConnection(out);
+           out.Delete();
+           
+           vtkActor edgePointsActor = new vtkActor();
+          
+           vtkProperty prop = edgePointsActor.GetProperty();
+           prop.SetColor(0, 0, 1);
+           prop.Delete();
+           edgePointsActor.SetMapper(partEdgePointsMapper);
+          
+           edgePointsActor.PickableOn();
+
+           
+           partEdgePointsMapper.Delete();
+           edgePoints.Delete();
+           sphereSource.Delete();
+           
+           return edgePointsActor;
+       }
+       
+       public static vtkActor createSilhouette(vtkRenderer ren, vtkPolyData data) {
+               
+               
+               vtkPolyDataSilhouette silhouette = new vtkPolyDataSilhouette();
+               
+               silhouette.SetInputData(data);
+               silhouette.SetCamera(ren.GetActiveCamera());
+               silhouette.SetEnableFeatureAngle(0);
+               vtkPolyDataMapper mapper = new vtkPolyDataMapper();
+               
+               mapper.SetInputConnection(silhouette.GetOutputPort());
+               
+               vtkActor actor = new vtkActor();
+               actor.SetMapper(mapper);
+               
+               actor.GetProperty().SetColor(0,0,1);
+               actor.GetProperty().SetLineWidth(6);
+               
+               return actor;
+               
+               
+               
+       }
+
+}
index 422e022a95db65dfb96ba84b373971699ec92fa4..287ce3401a513a27c36fd293050fb4385972b931 100644 (file)
@@ -195,7 +195,7 @@ public class TerminalSelectionGizmo extends vtkGizmo {
                plusTex.SetInterpolate(1);
                
                vtkPolyDataMapper2D mapper = new vtkPolyDataMapper2D();
-               mapper.SetInput(quad);
+               mapper.SetInputData(quad);
 
                nextProp = new vtkTexturedActor2D();
                prevProp = new vtkTexturedActor2D();