1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.vtk.shape;
\r
14 import javax.vecmath.AxisAngle4d;
\r
15 import javax.vecmath.Matrix4d;
\r
16 import javax.vecmath.Point3d;
\r
17 import javax.vecmath.Vector3d;
\r
19 import org.simantics.g3d.math.MathTools;
\r
20 import org.simantics.g3d.shape.Color4d;
\r
21 import org.simantics.g3d.shape.Cone;
\r
22 import org.simantics.g3d.shape.Cylinder;
\r
23 import org.simantics.g3d.shape.Mesh;
\r
24 import org.simantics.g3d.shape.Sphere;
\r
26 import vtk.vtkLinearTransform;
\r
27 import vtk.vtkMatrix4x4;
\r
28 import vtk.vtkRenderer;
\r
29 import vtk.vtkTextActor;
\r
31 public class axesSphereActor2 extends MeshActor{
\r
33 private double axisLength;
\r
34 private vtkRenderer ren;
\r
35 private vtkTextActor xactor, yactor, zactor;
\r
37 public axesSphereActor2(vtkRenderer ren, double size) {
\r
41 Mesh cone_x = Cone.create(size*0.3, res);
\r
42 Mesh cone_y = Cone.create(size*0.3, res);
\r
43 Mesh cone_z = Cone.create(size*0.3, res);
\r
44 cone_x.rotate(MathTools.getQuat(new AxisAngle4d(0,0,-1,Math.PI*0.5)));
\r
45 cone_z.rotate(MathTools.getQuat(new AxisAngle4d(1,0,0,Math.PI*0.5)));
\r
46 cone_x.translate(new Vector3d(size,0,0));
\r
47 cone_y.translate(new Vector3d(0,size,0));
\r
48 cone_z.translate(new Vector3d(0,0,size));
\r
50 Mesh tube_x = Cylinder.create(MathTools.ORIGIN, new Vector3d(size,0,0), size*0.1, res);
\r
51 Mesh tube_y = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,size,0), size*0.1, res);
\r
52 Mesh tube_z = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,0,size), size*0.1, res);
\r
54 Mesh sphere = Sphere.create(size*0.3, res, res*2/3);
\r
56 Color4d x_col = new Color4d(1,0,0,1);
\r
57 Color4d y_col = new Color4d(1,1,0,1);
\r
58 Color4d z_col = new Color4d(0,1,0,1);
\r
59 Color4d o_col = new Color4d(0,0,1,1);
\r
61 cone_x.setColor(x_col);
\r
62 tube_x.setColor(x_col);
\r
63 cone_y.setColor(y_col);
\r
64 tube_y.setColor(y_col);
\r
65 cone_z.setColor(z_col);
\r
66 tube_z.setColor(z_col);
\r
67 sphere.setColor(o_col);
\r
80 xactor = new vtkTextActor();
\r
81 yactor = new vtkTextActor();
\r
82 zactor = new vtkTextActor();
\r
84 xactor.SetInput("X");
\r
85 yactor.SetInput("Y");
\r
86 zactor.SetInput("Z");
\r
88 xactor.SetTextScaleModeToNone();
\r
89 yactor.SetTextScaleModeToNone();
\r
90 zactor.SetTextScaleModeToNone();
\r
92 xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
93 xactor.GetTextProperty().ShadowOff();
\r
94 xactor.GetTextProperty().ItalicOff();
\r
95 xactor.GetTextProperty().BoldOff();
\r
97 yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
98 yactor.GetTextProperty().ShadowOff();
\r
99 yactor.GetTextProperty().ItalicOff();
\r
100 yactor.GetTextProperty().BoldOff();
\r
102 zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0);
\r
103 zactor.GetTextProperty().ShadowOff();
\r
104 zactor.GetTextProperty().ItalicOff();
\r
105 zactor.GetTextProperty().BoldOff();
\r
107 xactor.GetTextProperty().Delete();
\r
108 yactor.GetTextProperty().Delete();
\r
109 zactor.GetTextProperty().Delete();
\r
111 xactor.SetMaximumLineHeight(0.25);
\r
112 yactor.SetMaximumLineHeight(0.25);
\r
113 zactor.SetMaximumLineHeight(0.25);
\r
115 xactor.SetPickable(0);
\r
116 yactor.SetPickable(0);
\r
117 zactor.SetPickable(0);
\r
120 private boolean labelVisible = false;
\r
121 public void setLabelVisibility(boolean ison) {
\r
122 if (ison == labelVisible)
\r
124 labelVisible = ison;
\r
125 if (labelVisible) {
\r
126 ren.AddActor2D(xactor);
\r
127 ren.AddActor2D(yactor);
\r
128 ren.AddActor2D(zactor);
\r
131 ren.RemoveActor2D(xactor);
\r
132 ren.RemoveActor2D(yactor);
\r
133 ren.RemoveActor2D(zactor);
\r
138 Matrix4d m = new Matrix4d();
\r
139 double mat[] = new double[16];
\r
140 Point3d x = new Point3d();
\r
141 Point3d y = new Point3d();
\r
142 Point3d z = new Point3d();
\r
144 private void updateTextLoc() {
\r
147 xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
148 yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
149 zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
\r
152 MathTools.set(m, mat);
\r
153 x.set(axisLength, 0,0);
\r
154 y.set(0,axisLength, 0);
\r
155 z.set(0,0,axisLength);
\r
160 xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z);
\r
161 yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z);
\r
162 zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z);
\r
164 xactor.GetPositionCoordinate().Delete();
\r
165 yactor.GetPositionCoordinate().Delete();
\r
166 zactor.GetPositionCoordinate().Delete();
\r
170 public void SetOrientation(double id0, double id1, double id2) {
\r
171 super.SetOrientation(id0, id1, id2);
\r
176 public void RotateWXYZ(double id0, double id1, double id2, double id3) {
\r
177 super.RotateWXYZ(id0, id1, id2, id3);
\r
182 public void SetPosition(double[] id0) {
\r
183 super.SetPosition(id0);
\r
188 public void SetPosition(double id0, double id1, double id2) {
\r
189 super.SetPosition(id0, id1, id2);
\r
194 public void SetOrientation(double[] id0) {
\r
195 super.SetOrientation(id0);
\r
200 public void SetScale(double id0) {
\r
201 super.SetScale(id0);
\r
206 public void SetScale(double id0, double id1, double id2) {
\r
207 super.SetScale(id0, id1, id2);
\r
212 public void SetScale(double[] id0) {
\r
213 super.SetScale(id0);
\r
218 public void SetUserMatrix(vtkMatrix4x4 id0) {
\r
219 super.SetUserMatrix(id0);
\r
224 public void SetUserTransform(vtkLinearTransform id0) {
\r
225 super.SetUserTransform(id0);
\r
230 public void Delete() {
\r
231 ren.RemoveActor(xactor);
\r
232 ren.RemoveActor(yactor);
\r
233 ren.RemoveActor(zactor);
\r