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();
77 for (vtkProp p : gizmo) {
84 public boolean isPartOf(vtkProp pickedObject) {
85 for (vtkProp prop : gizmo) {
86 if (prop.equals(pickedObject))
92 public void setPosition(Tuple3d position) {
93 this.position = position;
94 for (vtkProp p : gizmo) {
95 ((vtkProp3D)p).SetPosition(position.x, position.y, position.z);
99 public void setRotation(AxisAngle4d q) {
100 this.orientation = q;
101 for (vtkProp p : gizmo) {
102 ((vtkProp3D)p).SetOrientation(0,0,0);
103 ((vtkProp3D)p).RotateWXYZ(MathTools.radToDeg(q.angle), q.x, q.y, q.z);
108 public void setScale(Tuple3d s) {
110 for (vtkProp p : gizmo) {
111 ((vtkProp3D)p).SetScale(s.x, s.y, s.z);
115 public void setScale(double s) {
116 this.scale = new Vector3d(s,s,s);
117 for (vtkProp p : gizmo) {
118 ((vtkProp3D)p).SetScale(s, s, s);
122 public abstract Collection<vtkProp> getGizmo();
124 // public double[] add(double[] color1, double[] color2) {
125 // double[] result = new double[]{color1[0]+color2[0],color1[1],+color2[1],color1[2]+color2[2]};
129 // public double[] add(double[] color1, double[] color2, double[] color3) {
130 // double[] result = new double[]{color1[0]+color2[0]+color3[0],color1[1],+color2[1]+color3[1],color1[2]+color2[2]+color3[2]};
134 public double[] add(double[]... color) {
135 double result[] = new double[]{0,0,0};
136 for (double c[] : color) {
137 for (int i = 0; i < 3; i++)
145 public VtkView getView() {