4 * Axis actor created in the Java world
8 public class AxesActor extends vtkAssembly {
10 private vtkRenderer ren;
11 private double axisLength = 0.8;
12 private vtkTextActor xactor, yactor, zactor;
14 public AxesActor(vtkRenderer _ren) {
20 public void createAxes() {
21 vtkAxes axes = new vtkAxes();
22 axes.SetOrigin(0, 0, 0);
23 axes.SetScaleFactor(axisLength);
25 xactor = new vtkTextActor();
26 yactor = new vtkTextActor();
27 zactor = new vtkTextActor();
33 xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
34 yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
35 zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
37 xactor.GetPositionCoordinate().SetValue(axisLength, 0.0, 0.0);
38 yactor.GetPositionCoordinate().SetValue(0.0, axisLength, 0.0);
39 zactor.GetPositionCoordinate().SetValue(0.0, 0.0, axisLength);
41 xactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
42 xactor.GetTextProperty().ShadowOn();
43 xactor.GetTextProperty().ItalicOn();
44 xactor.GetTextProperty().BoldOff();
46 yactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
47 yactor.GetTextProperty().ShadowOn();
48 yactor.GetTextProperty().ItalicOn();
49 yactor.GetTextProperty().BoldOff();
51 zactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
52 zactor.GetTextProperty().ShadowOn();
53 zactor.GetTextProperty().ItalicOn();
54 zactor.GetTextProperty().BoldOff();
56 xactor.SetMaximumLineHeight(0.25);
57 yactor.SetMaximumLineHeight(0.25);
58 zactor.SetMaximumLineHeight(0.25);
60 vtkTubeFilter tube = new vtkTubeFilter();
61 tube.SetInputConnection(axes.GetOutputPort());
63 tube.SetNumberOfSides(8);
65 vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
66 tubeMapper.SetInputConnection(tube.GetOutputPort());
68 vtkActor tubeActor = new vtkActor();
69 tubeActor.SetMapper(tubeMapper);
70 tubeActor.PickableOff();
73 double coneScale = 0.3;
76 vtkConeSource xcone = new vtkConeSource();
77 xcone.SetResolution(coneRes);
78 vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();
79 xconeMapper.SetInputConnection(xcone.GetOutputPort());
80 vtkActor xconeActor = new vtkActor();
81 xconeActor.SetMapper(xconeMapper);
82 xconeActor.GetProperty().SetColor(1, 0, 0);
83 xconeActor.SetScale(coneScale, coneScale, coneScale);
84 xconeActor.SetPosition(axisLength, 0.0, 0.0);
87 vtkConeSource ycone = new vtkConeSource();
88 ycone.SetResolution(coneRes);
89 vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();
90 yconeMapper.SetInputConnection(ycone.GetOutputPort());
91 vtkActor yconeActor = new vtkActor();
92 yconeActor.SetMapper(yconeMapper);
93 yconeActor.GetProperty().SetColor(1, 1, 0);
94 yconeActor.RotateZ(90);
95 yconeActor.SetScale(coneScale, coneScale, coneScale);
96 yconeActor.SetPosition(0.0, axisLength, 0.0);
99 vtkConeSource zcone = new vtkConeSource();
100 zcone.SetResolution(coneRes);
101 vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();
102 zconeMapper.SetInputConnection(zcone.GetOutputPort());
103 vtkActor zconeActor = new vtkActor();
104 zconeActor.SetMapper(zconeMapper);
105 zconeActor.GetProperty().SetColor(0, 1, 0);
106 zconeActor.RotateY(-90);
107 zconeActor.SetScale(coneScale, coneScale, coneScale);
108 zconeActor.SetPosition(0.0, 0.0, axisLength);
110 ren.AddActor2D(xactor);
111 ren.AddActor2D(yactor);
112 ren.AddActor2D(zactor);
114 this.AddPart(tubeActor);
115 this.AddPart(xconeActor);
116 this.AddPart(yconeActor);
117 this.AddPart(zconeActor);
122 public void setAxesVisibility(boolean ison) {
123 this.SetVisibility(ison ? 1 : 0);
124 xactor.SetVisibility(ison ? 1 : 0);
125 yactor.SetVisibility(ison ? 1 : 0);
126 zactor.SetVisibility(ison ? 1 : 0);