/******************************************************************************* * 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.shape; import javax.vecmath.AxisAngle4d; import javax.vecmath.Matrix4d; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; import org.simantics.g3d.math.MathTools; import org.simantics.g3d.shape.Color4d; import org.simantics.g3d.shape.Cone; import org.simantics.g3d.shape.Cylinder; import org.simantics.g3d.shape.Mesh; import org.simantics.g3d.shape.Sphere; import vtk.vtkLinearTransform; import vtk.vtkMatrix4x4; import vtk.vtkRenderer; import vtk.vtkTextActor; public class axesSphereActor2 extends MeshActor{ private double axisLength; private vtkRenderer ren; private vtkTextActor xactor, yactor, zactor; public axesSphereActor2(vtkRenderer ren, double size) { int res = 16; axisLength = size; this.ren = ren; Mesh cone_x = Cone.create(size*0.3, res); Mesh cone_y = Cone.create(size*0.3, res); Mesh cone_z = Cone.create(size*0.3, res); cone_x.rotate(MathTools.getQuat(new AxisAngle4d(0,0,-1,Math.PI*0.5))); cone_z.rotate(MathTools.getQuat(new AxisAngle4d(1,0,0,Math.PI*0.5))); cone_x.translate(new Vector3d(size,0,0)); cone_y.translate(new Vector3d(0,size,0)); cone_z.translate(new Vector3d(0,0,size)); Mesh tube_x = Cylinder.create(MathTools.ORIGIN, new Vector3d(size,0,0), size*0.1, res); Mesh tube_y = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,size,0), size*0.1, res); Mesh tube_z = Cylinder.create(MathTools.ORIGIN, new Vector3d(0,0,size), size*0.1, res); Mesh sphere = Sphere.create(size*0.3, res, res*2/3); Color4d x_col = new Color4d(1,0,0,1); Color4d y_col = new Color4d(1,1,0,1); Color4d z_col = new Color4d(0,1,0,1); Color4d o_col = new Color4d(0,0,1,1); cone_x.setColor(x_col); tube_x.setColor(x_col); cone_y.setColor(y_col); tube_y.setColor(y_col); cone_z.setColor(z_col); tube_z.setColor(z_col); sphere.setColor(o_col); sphere.add(cone_x); sphere.add(tube_x); sphere.add(cone_y); sphere.add(tube_y); sphere.add(cone_z); sphere.add(tube_z); setMesh(sphere); xactor = new vtkTextActor(); yactor = new vtkTextActor(); zactor = new vtkTextActor(); xactor.SetInput("X"); yactor.SetInput("Y"); zactor.SetInput("Z"); xactor.SetTextScaleModeToNone(); yactor.SetTextScaleModeToNone(); zactor.SetTextScaleModeToNone(); xactor.GetTextProperty().SetColor(0.0, 0.0, 0.0); xactor.GetTextProperty().ShadowOff(); xactor.GetTextProperty().ItalicOff(); xactor.GetTextProperty().BoldOff(); yactor.GetTextProperty().SetColor(0.0, 0.0, 0.0); yactor.GetTextProperty().ShadowOff(); yactor.GetTextProperty().ItalicOff(); yactor.GetTextProperty().BoldOff(); zactor.GetTextProperty().SetColor(0.0, 0.0, 0.0); zactor.GetTextProperty().ShadowOff(); zactor.GetTextProperty().ItalicOff(); zactor.GetTextProperty().BoldOff(); xactor.GetTextProperty().Delete(); yactor.GetTextProperty().Delete(); zactor.GetTextProperty().Delete(); xactor.SetMaximumLineHeight(0.25); yactor.SetMaximumLineHeight(0.25); zactor.SetMaximumLineHeight(0.25); xactor.SetPickable(0); yactor.SetPickable(0); zactor.SetPickable(0); } private boolean labelVisible = false; public void setLabelVisibility(boolean ison) { if (ison == labelVisible) return; labelVisible = ison; if (labelVisible) { ren.AddActor2D(xactor); ren.AddActor2D(yactor); ren.AddActor2D(zactor); updateTextLoc(); } else { ren.RemoveActor2D(xactor); ren.RemoveActor2D(yactor); ren.RemoveActor2D(zactor); } } Matrix4d m = new Matrix4d(); double mat[] = new double[16]; Point3d x = new Point3d(); Point3d y = new Point3d(); Point3d z = new Point3d(); private void updateTextLoc() { if (!labelVisible) return; xactor.GetPositionCoordinate().SetCoordinateSystemToWorld(); yactor.GetPositionCoordinate().SetCoordinateSystemToWorld(); zactor.GetPositionCoordinate().SetCoordinateSystemToWorld(); GetMatrix(mat); MathTools.set(m, mat); x.set(axisLength, 0,0); y.set(0,axisLength, 0); z.set(0,0,axisLength); m.transform(x); m.transform(y); m.transform(z); xactor.GetPositionCoordinate().SetValue(x.x, x.y, x.z); yactor.GetPositionCoordinate().SetValue(y.x, y.y, y.z); zactor.GetPositionCoordinate().SetValue(z.x, z.y, z.z); xactor.GetPositionCoordinate().Delete(); yactor.GetPositionCoordinate().Delete(); zactor.GetPositionCoordinate().Delete(); } @Override public void SetOrientation(double id0, double id1, double id2) { super.SetOrientation(id0, id1, id2); updateTextLoc(); } @Override public void RotateWXYZ(double id0, double id1, double id2, double id3) { super.RotateWXYZ(id0, id1, id2, id3); updateTextLoc(); } @Override public void SetPosition(double[] id0) { super.SetPosition(id0); updateTextLoc(); } @Override public void SetPosition(double id0, double id1, double id2) { super.SetPosition(id0, id1, id2); updateTextLoc(); } @Override public void SetOrientation(double[] id0) { super.SetOrientation(id0); updateTextLoc(); } @Override public void SetScale(double id0) { super.SetScale(id0); updateTextLoc(); } @Override public void SetScale(double id0, double id1, double id2) { super.SetScale(id0, id1, id2); updateTextLoc(); } @Override public void SetScale(double[] id0) { super.SetScale(id0); updateTextLoc(); } @Override public void SetUserMatrix(vtkMatrix4x4 id0) { super.SetUserMatrix(id0); updateTextLoc(); } @Override public void SetUserTransform(vtkLinearTransform id0) { super.SetUserTransform(id0); updateTextLoc(); } @Override public void Delete() { ren.RemoveActor(xactor); ren.RemoveActor(yactor); ren.RemoveActor(zactor); xactor.Delete(); yactor.Delete(); zactor.Delete(); super.Delete(); } }