1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.vtk.gizmo;
14 import java.util.Collection;
16 import javax.vecmath.AxisAngle4d;
17 import javax.vecmath.Tuple3d;
18 import javax.vecmath.Vector3d;
20 import org.simantics.g3d.gizmo.Gizmo;
21 import org.simantics.g3d.math.MathTools;
22 import org.simantics.g3d.vtk.common.VtkView;
26 import vtk.vtkRenderer;
28 public abstract class vtkGizmo implements Gizmo<vtkProp, VtkView> {
31 private Collection<vtkProp> gizmo;
33 private Tuple3d position;
34 private AxisAngle4d orientation;
35 private Tuple3d scale;
38 public void attach(VtkView renderingPart) {
40 throw new RuntimeException("Gizmo is attached");
47 public void deattach() {
49 throw new RuntimeException("Gizmo is not attached");
54 public boolean isAttached() {
55 return (view != null);
58 protected void attachActors() {
61 vtkRenderer ren1 = view.getRenderer();
62 for (vtkProp p : gizmo) {
66 setPosition(position);
67 if (orientation != null)
68 setRotation(orientation);
74 protected void deattachActors() {
76 vtkRenderer ren1 = view.getRenderer();
78 for (vtkProp p : gizmo) {
86 public boolean isPartOf(vtkProp pickedObject) {
87 for (vtkProp prop : gizmo) {
88 if (prop.equals(pickedObject))
94 public void setPosition(Tuple3d position) {
95 this.position = position;
96 for (vtkProp p : gizmo) {
97 ((vtkProp3D)p).SetPosition(position.x, position.y, position.z);
101 public void setRotation(AxisAngle4d q) {
102 this.orientation = q;
103 for (vtkProp p : gizmo) {
104 ((vtkProp3D)p).SetOrientation(0,0,0);
105 ((vtkProp3D)p).RotateWXYZ(MathTools.radToDeg(q.angle), q.x, q.y, q.z);
110 public void setScale(Tuple3d s) {
112 for (vtkProp p : gizmo) {
113 ((vtkProp3D)p).SetScale(s.x, s.y, s.z);
117 public void setScale(double s) {
118 this.scale = new Vector3d(s,s,s);
119 for (vtkProp p : gizmo) {
120 ((vtkProp3D)p).SetScale(s, s, s);
124 public abstract Collection<vtkProp> getGizmo();
126 // public double[] add(double[] color1, double[] color2) {
127 // double[] result = new double[]{color1[0]+color2[0],color1[1],+color2[1],color1[2]+color2[2]};
131 // public double[] add(double[] color1, double[] color2, double[] color3) {
132 // double[] result = new double[]{color1[0]+color2[0]+color3[0],color1[1],+color2[1]+color3[1],color1[2]+color2[2]+color3[2]};
136 public double[] add(double[]... color) {
137 double result[] = new double[]{0,0,0};
138 for (double c[] : color) {
139 for (int i = 0; i < 3; i++)
147 public VtkView getView() {