1 package org.simantics.g3d.vtk.shape;
\r
3 import javax.vecmath.AxisAngle4d;
\r
4 import javax.vecmath.Matrix4d;
\r
5 import javax.vecmath.Point3d;
\r
6 import javax.vecmath.Vector3d;
\r
8 import org.simantics.g3d.math.MathTools;
\r
9 import org.simantics.g3d.shape.Color4d;
\r
10 import org.simantics.g3d.shape.Cone;
\r
11 import org.simantics.g3d.shape.Cylinder;
\r
12 import org.simantics.g3d.shape.Mesh;
\r
13 import org.simantics.g3d.shape.Sphere;
\r
15 import vtk.vtkLinearTransform;
\r
16 import vtk.vtkMatrix4x4;
\r
17 import vtk.vtkRenderer;
\r
18 import vtk.vtkTextActor;
\r
20 public class axesSphereActor2 extends MeshActor{
\r
22 private double axisLength;
\r
23 private vtkRenderer ren;
\r
24 private vtkTextActor xactor, yactor, zactor;
\r
26 public axesSphereActor2(vtkRenderer ren, double size) {
\r
30 Mesh cone_x = Cone.create(size*0.3, res);
\r
31 Mesh cone_y = Cone.create(size*0.3, res);
\r
32 Mesh cone_z = Cone.create(size*0.3, res);
\r
33 cone_x.rotate(MathTools.getQuat(new AxisAngle4d(0,0,-1,Math.PI*0.5)));
\r
34 cone_z.rotate(MathTools.getQuat(new AxisAngle4d(1,0,0,Math.PI*0.5)));
\r
35 cone_x.translate(new Vector3d(size,0,0));
\r
36 cone_y.translate(new Vector3d(0,size,0));
\r
37 cone_z.translate(new Vector3d(0,0,size));
\r
39 Mesh tube_x = Cylinder.create(MathTools.ORIGIN, new Vector3d(size,0,0), size*0.1, res);
\r
40 Mesh tube_y = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,size,0), size*0.1, res);
\r
41 Mesh tube_z = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,0,size), size*0.1, res);
\r
43 Mesh sphere = Sphere.create(size*0.3, res, res*2/3);
\r
45 Color4d x_col = new Color4d(1,0,0,1);
\r
46 Color4d y_col = new Color4d(1,1,0,1);
\r
47 Color4d z_col = new Color4d(0,1,0,1);
\r
48 Color4d o_col = new Color4d(0,0,1,1);
\r
50 cone_x.setColor(x_col);
\r
51 tube_x.setColor(x_col);
\r
52 cone_y.setColor(y_col);
\r
53 tube_y.setColor(y_col);
\r
54 cone_z.setColor(z_col);
\r
55 tube_z.setColor(z_col);
\r
56 sphere.setColor(o_col);
\r
69 xactor = new vtkTextActor();
\r
70 yactor = new vtkTextActor();
\r
71 zactor = new vtkTextActor();
\r
73 xactor.SetInput("X");
\r
74 yactor.SetInput("Y");
\r
75 zactor.SetInput("Z");
\r
77 xactor.SetTextScaleModeToNone();
\r
78 yactor.SetTextScaleModeToNone();
\r
79 zactor.SetTextScaleModeToNone();
\r
81 xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
82 xactor.GetTextProperty().ShadowOff();
\r
83 xactor.GetTextProperty().ItalicOff();
\r
84 xactor.GetTextProperty().BoldOff();
\r
86 yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
87 yactor.GetTextProperty().ShadowOff();
\r
88 yactor.GetTextProperty().ItalicOff();
\r
89 yactor.GetTextProperty().BoldOff();
\r
91 zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
92 zactor.GetTextProperty().ShadowOff();
\r
93 zactor.GetTextProperty().ItalicOff();
\r
94 zactor.GetTextProperty().BoldOff();
\r
96 xactor.GetTextProperty().Delete();
\r
97 yactor.GetTextProperty().Delete();
\r
98 zactor.GetTextProperty().Delete();
\r
100 xactor.SetMaximumLineHeight(0.25);
\r
101 yactor.SetMaximumLineHeight(0.25);
\r
102 zactor.SetMaximumLineHeight(0.25);
\r
104 xactor.SetPickable(0);
\r
105 yactor.SetPickable(0);
\r
106 zactor.SetPickable(0);
\r
109 private boolean labelVisible = false;
\r
110 public void setLabelVisibility(boolean ison) {
\r
111 if (ison == labelVisible)
\r
113 labelVisible = ison;
\r
114 if (labelVisible) {
\r
115 ren.AddActor2D(xactor);
\r
116 ren.AddActor2D(yactor);
\r
117 ren.AddActor2D(zactor);
\r
120 ren.RemoveActor2D(xactor);
\r
121 ren.RemoveActor2D(yactor);
\r
122 ren.RemoveActor2D(zactor);
\r
127 Matrix4d m = new Matrix4d();
\r
128 double mat[] = new double[16];
\r
129 Point3d x = new Point3d();
\r
130 Point3d y = new Point3d();
\r
131 Point3d z = new Point3d();
\r
133 private void updateTextLoc() {
\r
136 xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
137 yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
138 zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
141 MathTools.set(m, mat);
\r
142 x.set(axisLength, 0,0);
\r
143 y.set(0,axisLength, 0);
\r
144 z.set(0,0,axisLength);
\r
149 xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);
\r
150 yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);
\r
151 zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);
\r
153 xactor.GetPositionCoordinate().Delete();
\r
154 yactor.GetPositionCoordinate().Delete();
\r
155 zactor.GetPositionCoordinate().Delete();
\r
159 public void SetOrientation(double id0, double id1, double id2) {
\r
160 super.SetOrientation(id0, id1, id2);
\r
165 public void RotateWXYZ(double id0, double id1, double id2, double id3) {
\r
166 super.RotateWXYZ(id0, id1, id2, id3);
\r
171 public void SetPosition(double[] id0) {
\r
172 super.SetPosition(id0);
\r
177 public void SetPosition(double id0, double id1, double id2) {
\r
178 super.SetPosition(id0, id1, id2);
\r
183 public void SetOrientation(double[] id0) {
\r
184 super.SetOrientation(id0);
\r
189 public void SetScale(double id0) {
\r
190 super.SetScale(id0);
\r
195 public void SetScale(double id0, double id1, double id2) {
\r
196 super.SetScale(id0, id1, id2);
\r
201 public void SetScale(double[] id0) {
\r
202 super.SetScale(id0);
\r
207 public void SetUserMatrix(vtkMatrix4x4 id0) {
\r
208 super.SetUserMatrix(id0);
\r
213 public void SetUserTransform(vtkLinearTransform id0) {
\r
214 super.SetUserTransform(id0);
\r
219 public void Delete() {
\r
220 ren.RemoveActor(xactor);
\r
221 ren.RemoveActor(yactor);
\r
222 ren.RemoveActor(zactor);
\r