-package org.simantics.g3d.vtk.gizmo;\r
-\r
-import java.util.Collection;\r
-\r
-import javax.vecmath.AxisAngle4d;\r
-import javax.vecmath.Tuple3d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.simantics.g3d.gizmo.Gizmo;\r
-import org.simantics.g3d.math.MathTools;\r
-\r
-import vtk.vtkProp;\r
-import vtk.vtkProp3D;\r
-import vtk.vtkRenderer;\r
-\r
-public abstract class vtkGizmo implements Gizmo<vtkProp> {\r
-\r
- private vtkRenderer ren1;\r
- private Collection<vtkProp> gizmo;\r
- \r
- private Tuple3d position;\r
- private AxisAngle4d orientation;\r
- private Tuple3d scale;\r
- \r
- @Override\r
- public void attach(Object renderingPart) {\r
- if (ren1 != null)\r
- throw new RuntimeException("Gizmo is attached");\r
- ren1 = (vtkRenderer)renderingPart;\r
- attachActors();\r
- }\r
- \r
- @Override\r
- public void deattach() {\r
- if (ren1 == null)\r
- throw new RuntimeException("Gizmo is not attached");\r
- deattachActors();\r
- ren1 = null;\r
- }\r
- \r
- public boolean isAttached() {\r
- return (ren1 != null);\r
- }\r
- \r
- protected void attachActors() {\r
- gizmo = getGizmo();\r
- for (vtkProp p : gizmo) {\r
- ren1.AddActor(p);\r
- }\r
- if (position != null)\r
- setPosition(position);\r
- if (orientation != null)\r
- setRotation(orientation);\r
- if (scale != null)\r
- setScale(scale);\r
- }\r
- \r
- protected void deattachActors() {\r
- for (vtkProp p : gizmo) {\r
- ren1.RemoveActor(p);\r
- }\r
- }\r
- \r
- @Override\r
- public boolean isPartOf(vtkProp pickedObject) {\r
- for (vtkProp prop : gizmo) {\r
- if (prop.equals(pickedObject))\r
- return true;\r
- }\r
- return false;\r
- }\r
- \r
- public void setPosition(Tuple3d position) {\r
- this.position = position;\r
- for (vtkProp p : gizmo) {\r
- ((vtkProp3D)p).SetPosition(position.x, position.y, position.z);\r
- }\r
- }\r
- \r
- public void setRotation(AxisAngle4d q) {\r
- this.orientation = q;\r
- for (vtkProp p : gizmo) {\r
- ((vtkProp3D)p).SetOrientation(0,0,0);\r
- ((vtkProp3D)p).RotateWXYZ(MathTools.radToDeg(q.angle), q.x, q.y, q.z);\r
- }\r
- }\r
- \r
- \r
- public void setScale(Tuple3d s) {\r
- this.scale = s;\r
- for (vtkProp p : gizmo) {\r
- ((vtkProp3D)p).SetScale(s.x, s.y, s.z);\r
- }\r
- }\r
- \r
- public void setScale(double s) {\r
- this.scale = new Vector3d(s,s,s);\r
- for (vtkProp p : gizmo) {\r
- ((vtkProp3D)p).SetScale(s, s, s);\r
- }\r
- }\r
- \r
- public abstract Collection<vtkProp> getGizmo();\r
- \r
-// public double[] add(double[] color1, double[] color2) {\r
-// double[] result = new double[]{color1[0]+color2[0],color1[1],+color2[1],color1[2]+color2[2]};\r
-// return result;\r
-// }\r
-// \r
-// public double[] add(double[] color1, double[] color2, double[] color3) {\r
-// double[] result = new double[]{color1[0]+color2[0]+color3[0],color1[1],+color2[1]+color3[1],color1[2]+color2[2]+color3[2]};\r
-// return result;\r
-// }\r
- \r
- public double[] add(double[]... color) {\r
- double result[] = new double[]{0,0,0};\r
- for (double c[] : color) {\r
- for (int i = 0; i < 3; i++)\r
- result[i] += c[i];\r
- }\r
- \r
- return result;\r
- }\r
- \r
- \r
- public vtkRenderer getRenderer() {\r
- return ren1;\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.g3d.vtk.gizmo;
+
+import java.util.Collection;
+
+import javax.vecmath.AxisAngle4d;
+import javax.vecmath.Tuple3d;
+import javax.vecmath.Vector3d;
+
+import org.simantics.g3d.gizmo.Gizmo;
+import org.simantics.g3d.math.MathTools;
+import org.simantics.g3d.vtk.common.VtkView;
+
+import vtk.vtkProp;
+import vtk.vtkProp3D;
+import vtk.vtkRenderer;
+
+public abstract class vtkGizmo implements Gizmo<vtkProp, VtkView> {
+
+ private VtkView view;
+ private Collection<vtkProp> gizmo;
+
+ private Tuple3d position;
+ private AxisAngle4d orientation;
+ private Tuple3d scale;
+
+ @Override
+ public void attach(VtkView renderingPart) {
+ if (view != null)
+ throw new RuntimeException("Gizmo is attached");
+ view = renderingPart;
+
+ attachActors();
+ }
+
+ @Override
+ public void deattach() {
+ if (view == null)
+ throw new RuntimeException("Gizmo is not attached");
+ deattachActors();
+ view = null;
+ }
+
+ public boolean isAttached() {
+ return (view != null);
+ }
+
+ protected void attachActors() {
+ view.lock();
+ gizmo = getGizmo();
+ vtkRenderer ren1 = view.getRenderer();
+ for (vtkProp p : gizmo) {
+ ren1.AddActor(p);
+ }
+ if (position != null)
+ setPosition(position);
+ if (orientation != null)
+ setRotation(orientation);
+ if (scale != null)
+ setScale(scale);
+ view.unlock();
+ }
+
+ protected void deattachActors() {
+ view.lock();
+ vtkRenderer ren1 = view.getRenderer();
+ for (vtkProp p : gizmo) {
+ ren1.RemoveActor(p);
+ }
+ view.unlock();
+ }
+
+ @Override
+ public boolean isPartOf(vtkProp pickedObject) {
+ for (vtkProp prop : gizmo) {
+ if (prop.equals(pickedObject))
+ return true;
+ }
+ return false;
+ }
+
+ public void setPosition(Tuple3d position) {
+ this.position = position;
+ for (vtkProp p : gizmo) {
+ ((vtkProp3D)p).SetPosition(position.x, position.y, position.z);
+ }
+ }
+
+ public void setRotation(AxisAngle4d q) {
+ this.orientation = q;
+ for (vtkProp p : gizmo) {
+ ((vtkProp3D)p).SetOrientation(0,0,0);
+ ((vtkProp3D)p).RotateWXYZ(MathTools.radToDeg(q.angle), q.x, q.y, q.z);
+ }
+ }
+
+
+ public void setScale(Tuple3d s) {
+ this.scale = s;
+ for (vtkProp p : gizmo) {
+ ((vtkProp3D)p).SetScale(s.x, s.y, s.z);
+ }
+ }
+
+ public void setScale(double s) {
+ this.scale = new Vector3d(s,s,s);
+ for (vtkProp p : gizmo) {
+ ((vtkProp3D)p).SetScale(s, s, s);
+ }
+ }
+
+ public abstract Collection<vtkProp> getGizmo();
+
+// public double[] add(double[] color1, double[] color2) {
+// double[] result = new double[]{color1[0]+color2[0],color1[1],+color2[1],color1[2]+color2[2]};
+// return result;
+// }
+//
+// public double[] add(double[] color1, double[] color2, double[] color3) {
+// double[] result = new double[]{color1[0]+color2[0]+color3[0],color1[1],+color2[1]+color3[1],color1[2]+color2[2]+color3[2]};
+// return result;
+// }
+
+ public double[] add(double[]... color) {
+ double result[] = new double[]{0,0,0};
+ for (double c[] : color) {
+ for (int i = 0; i < 3; i++)
+ result[i] += c[i];
+ }
+
+ return result;
+ }
+
+
+ public VtkView getView() {
+ return view;
+ }
+
+
+
+}