]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk/src/vtk/AxesActor.java
Perform view direction switching via vtkCameraAndSelectorAction
[simantics/3d.git] / vtk / src / vtk / AxesActor.java
1 package vtk;
2
3 /**
4  * Axis actor created in the Java world
5  *
6  * @author Kitware
7  */
8 public class AxesActor extends vtkAssembly {
9
10   private vtkRenderer ren;
11   private double axisLength = 0.8;
12   private vtkTextActor xactor, yactor, zactor;
13
14   public AxesActor(vtkRenderer _ren) {
15     super();
16     ren = _ren;
17     createAxes();
18   }
19
20   public void createAxes() {
21     vtkAxes axes = new vtkAxes();
22     axes.SetOrigin(0, 0, 0);
23     axes.SetScaleFactor(axisLength);
24
25     xactor = new vtkTextActor();
26     yactor = new vtkTextActor();
27     zactor = new vtkTextActor();
28
29     xactor.SetInput("X");
30     yactor.SetInput("Y");
31     zactor.SetInput("Z");
32
33     xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
34     yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
35     zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
36
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);
40
41     xactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
42     xactor.GetTextProperty().ShadowOn();
43     xactor.GetTextProperty().ItalicOn();
44     xactor.GetTextProperty().BoldOff();
45
46     yactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
47     yactor.GetTextProperty().ShadowOn();
48     yactor.GetTextProperty().ItalicOn();
49     yactor.GetTextProperty().BoldOff();
50
51     zactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
52     zactor.GetTextProperty().ShadowOn();
53     zactor.GetTextProperty().ItalicOn();
54     zactor.GetTextProperty().BoldOff();
55
56     xactor.SetMaximumLineHeight(0.25);
57     yactor.SetMaximumLineHeight(0.25);
58     zactor.SetMaximumLineHeight(0.25);
59
60     vtkTubeFilter tube = new vtkTubeFilter();
61     tube.SetInputConnection(axes.GetOutputPort());
62     tube.SetRadius(0.05);
63     tube.SetNumberOfSides(8);
64
65     vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
66     tubeMapper.SetInputConnection(tube.GetOutputPort());
67
68     vtkActor tubeActor = new vtkActor();
69     tubeActor.SetMapper(tubeMapper);
70     tubeActor.PickableOff();
71
72     int coneRes = 12;
73     double coneScale = 0.3;
74
75     // --- x-Cone
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);
85
86     // --- y-Cone
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);
97
98     // --- z-Cone
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);
109
110     ren.AddActor2D(xactor);
111     ren.AddActor2D(yactor);
112     ren.AddActor2D(zactor);
113
114     this.AddPart(tubeActor);
115     this.AddPart(xconeActor);
116     this.AddPart(yconeActor);
117     this.AddPart(zconeActor);
118
119     ren.AddActor(this);
120   }
121
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);
127   }
128 }