--- /dev/null
+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.g3d.shape.Color4d;\r
+import org.simantics.g3d.shape.Cone;\r
+import org.simantics.g3d.shape.Cylinder;\r
+import org.simantics.g3d.shape.Mesh;\r
+import org.simantics.g3d.shape.Sphere;\r
+\r
+import vtk.vtkLinearTransform;\r
+import vtk.vtkMatrix4x4;\r
+import vtk.vtkRenderer;\r
+import vtk.vtkTextActor;\r
+\r
+public class axesSphereActor2 extends MeshActor{\r
+ \r
+ private double axisLength;\r
+ private vtkRenderer ren;\r
+ private vtkTextActor xactor, yactor, zactor;\r
+ \r
+ public axesSphereActor2(vtkRenderer ren, double size) {\r
+ int res = 16;\r
+ axisLength = size;\r
+ this.ren = ren;\r
+ Mesh cone_x = Cone.create(size*0.3, res);\r
+ Mesh cone_y = Cone.create(size*0.3, res);\r
+ Mesh cone_z = Cone.create(size*0.3, res);\r
+ cone_x.rotate(MathTools.getQuat(new AxisAngle4d(0,0,-1,Math.PI*0.5)));\r
+ cone_z.rotate(MathTools.getQuat(new AxisAngle4d(1,0,0,Math.PI*0.5)));\r
+ cone_x.translate(new Vector3d(size,0,0));\r
+ cone_y.translate(new Vector3d(0,size,0));\r
+ cone_z.translate(new Vector3d(0,0,size));\r
+ \r
+ Mesh tube_x = Cylinder.create(MathTools.ORIGIN, new Vector3d(size,0,0), size*0.1, res);\r
+ Mesh tube_y = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,size,0), size*0.1, res);\r
+ Mesh tube_z = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,0,size), size*0.1, res);\r
+ \r
+ Mesh sphere = Sphere.create(size*0.3, res, res*2/3);\r
+ \r
+ Color4d x_col = new Color4d(1,0,0,1);\r
+ Color4d y_col = new Color4d(1,1,0,1);\r
+ Color4d z_col = new Color4d(0,1,0,1);\r
+ Color4d o_col = new Color4d(0,0,1,1);\r
+ \r
+ cone_x.setColor(x_col);\r
+ tube_x.setColor(x_col);\r
+ cone_y.setColor(y_col);\r
+ tube_y.setColor(y_col);\r
+ cone_z.setColor(z_col);\r
+ tube_z.setColor(z_col);\r
+ sphere.setColor(o_col);\r
+ \r
+ sphere.add(cone_x);\r
+ sphere.add(tube_x);\r
+ sphere.add(cone_y);\r
+ sphere.add(tube_y);\r
+ sphere.add(cone_z);\r
+ sphere.add(tube_z);\r
+ \r
+ setMesh(sphere);\r
+ \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.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
+ private boolean labelVisible = false;\r
+ public void setLabelVisibility(boolean ison) {\r
+ if (ison == labelVisible)\r
+ return;\r
+ labelVisible = ison;\r
+ if (labelVisible) {\r
+ ren.AddActor2D(xactor);\r
+ ren.AddActor2D(yactor);\r
+ ren.AddActor2D(zactor);\r
+ updateTextLoc();\r
+ } else {\r
+ ren.RemoveActor2D(xactor);\r
+ ren.RemoveActor2D(yactor);\r
+ ren.RemoveActor2D(zactor);\r
+ }\r
+ \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 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
+ xactor.Delete();\r
+ yactor.Delete();\r
+ zactor.Delete();\r
+ super.Delete();\r
+ }\r
+}\r