]> gerrit.simantics Code Review - simantics/3d.git/blob - vtk/src/vtk/AxesActor.java
Merge "Publish Plant3D feature"
[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.ScaledTextOn();
34         yactor.ScaledTextOn();
35         zactor.ScaledTextOn();
36
37         xactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
38         yactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
39         zactor.GetPositionCoordinate().SetCoordinateSystemToWorld();
40
41         xactor.GetPositionCoordinate().SetValue(axisLength, 0.0, 0.0);
42         yactor.GetPositionCoordinate().SetValue(0.0, axisLength, 0.0);
43         zactor.GetPositionCoordinate().SetValue(0.0, 0.0, axisLength);
44
45         xactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
46         xactor.GetTextProperty().ShadowOn();
47         xactor.GetTextProperty().ItalicOn();
48         xactor.GetTextProperty().BoldOff();
49
50         yactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
51         yactor.GetTextProperty().ShadowOn();
52         yactor.GetTextProperty().ItalicOn();
53         yactor.GetTextProperty().BoldOff();
54
55         zactor.GetTextProperty().SetColor(1.0, 1.0, 1.0);
56         zactor.GetTextProperty().ShadowOn();
57         zactor.GetTextProperty().ItalicOn();
58         zactor.GetTextProperty().BoldOff();
59
60         xactor.SetMaximumLineHeight(0.25);
61         yactor.SetMaximumLineHeight(0.25);
62         zactor.SetMaximumLineHeight(0.25);
63
64         vtkTubeFilter tube = new vtkTubeFilter();
65         tube.SetInput(axes.GetOutput());
66         tube.SetRadius(0.05);
67         tube.SetNumberOfSides(8);
68
69         vtkPolyDataMapper tubeMapper = new vtkPolyDataMapper();
70         tubeMapper.SetInput(tube.GetOutput());
71
72         vtkActor tubeActor = new vtkActor();
73         tubeActor.SetMapper(tubeMapper);
74         tubeActor.PickableOff();
75
76         int coneRes = 12;
77         double coneScale = 0.3;
78
79         // --- x-Cone
80         vtkConeSource xcone = new vtkConeSource();
81         xcone.SetResolution(coneRes);
82         vtkPolyDataMapper xconeMapper = new vtkPolyDataMapper();
83         xconeMapper.SetInput(xcone.GetOutput());
84         vtkActor xconeActor = new vtkActor();
85         xconeActor.SetMapper(xconeMapper);
86         xconeActor.GetProperty().SetColor(1, 0, 0);
87         xconeActor.SetScale(coneScale, coneScale, coneScale);
88         xconeActor.SetPosition(axisLength, 0.0, 0.0);
89
90         // --- y-Cone
91         vtkConeSource ycone = new vtkConeSource();
92         ycone.SetResolution(coneRes);
93         vtkPolyDataMapper yconeMapper = new vtkPolyDataMapper();
94         yconeMapper.SetInput(ycone.GetOutput());
95         vtkActor yconeActor = new vtkActor();
96         yconeActor.SetMapper(yconeMapper);
97         yconeActor.GetProperty().SetColor(1, 1, 0);
98         yconeActor.RotateZ(90);
99         yconeActor.SetScale(coneScale, coneScale, coneScale);
100         yconeActor.SetPosition(0.0, axisLength, 0.0);
101
102         // --- z-Cone
103         vtkConeSource zcone = new vtkConeSource();
104         zcone.SetResolution(coneRes);
105         vtkPolyDataMapper zconeMapper = new vtkPolyDataMapper();
106         zconeMapper.SetInput(zcone.GetOutput());
107         vtkActor zconeActor = new vtkActor();
108         zconeActor.SetMapper(zconeMapper);
109         zconeActor.GetProperty().SetColor(0, 1, 0);
110         zconeActor.RotateY(-90);
111         zconeActor.SetScale(coneScale, coneScale, coneScale);
112         zconeActor.SetPosition(0.0, 0.0, axisLength);
113
114         ren.AddActor2D(xactor);
115         ren.AddActor2D(yactor);
116         ren.AddActor2D(zactor);
117
118         this.AddPart(tubeActor);
119         this.AddPart(xconeActor);
120         this.AddPart(yconeActor);
121         this.AddPart(zconeActor);
122
123         ren.AddActor(this);
124     }
125
126     public void setAxesVisibility(boolean ison) {
127         this.SetVisibility(ison ? 1 : 0);
128         xactor.SetVisibility(ison ? 1 : 0);
129         yactor.SetVisibility(ison ? 1 : 0);
130         zactor.SetVisibility(ison ? 1 : 0);
131     }
132 }