VTK
TestAxisActorInternal.h
Go to the documentation of this file.
1 #ifndef TestAxisActorInternal_h
2 #define TestAxisActorInternal_h
3 
4 #include "vtkAxisActor.h"
5 #include "vtkCamera.h"
6 #include "vtkNew.h"
7 #include "vtkPolyDataMapper.h"
8 #include "vtkProperty.h"
9 #include "vtkRenderWindow.h"
11 #include "vtkRenderer.h"
12 #include "vtkSphereSource.h"
13 #include "vtkStringArray.h"
14 #include "vtkTextProperty.h"
15 
16 inline int TestAxisActorInternal(int use2dMode, int use3dProp)
17 {
19  labels->SetNumberOfTuples(6);
20  labels->SetValue(0, "0");
21  labels->SetValue(1, "2");
22  labels->SetValue(2, "4");
23  labels->SetValue(3, "6");
24  labels->SetValue(4, "8");
25  labels->SetValue(5, "10");
26 
27  vtkNew<vtkTextProperty> textProp1;
28  textProp1->SetColor(0., 0., 1.);
29  textProp1->SetOpacity(0.9);
30 
31  vtkNew<vtkTextProperty> textProp2;
32  textProp2->SetColor(1., 0., 0.);
33  textProp2->SetOpacity(0.6);
34 
35  vtkNew<vtkTextProperty> textProp3;
36  textProp3->SetColor(0., 1., 0.);
37  textProp3->SetOpacity(1);
38 
39  vtkNew<vtkProperty> prop1;
40  prop1->SetColor(1., 0., 1.);
41 
42  vtkNew<vtkProperty> prop2;
43  prop2->SetColor(1., 1., 0.);
44 
45  vtkNew<vtkProperty> prop3;
46  prop3->SetColor(0., 1., 1.);
47 
48  //------------- X Axis -------------
49  vtkNew<vtkAxisActor> axisXActor;
50  axisXActor->SetUse2DMode(use2dMode);
51  axisXActor->SetUseTextActor3D(use3dProp);
52  axisXActor->GetProperty()->SetAmbient(1);
53  axisXActor->GetProperty()->SetDiffuse(0);
54  axisXActor->SetPoint1(0, 0, 0);
55  axisXActor->SetPoint2(10, 0, 0);
56  axisXActor->SetTitle("X Axis");
57  axisXActor->SetBounds(0, 10, 0, 0, 0, 0);
58  axisXActor->SetTickLocationToBoth();
59  axisXActor->SetAxisTypeToX();
60  axisXActor->SetRange(0, 10);
61  axisXActor->SetLabels(labels.Get());
62  axisXActor->SetDeltaRangeMajor(2);
63  axisXActor->SetDeltaRangeMinor(0.5);
64  axisXActor->SetExponent("+00");
65  axisXActor->SetExponentVisibility(true);
66  axisXActor->SetTitleScale(0.8);
67  axisXActor->SetLabelScale(0.5);
68  axisXActor->SetTitleOffset(3);
69  axisXActor->SetExponentOffset(3);
70  axisXActor->SetLabelOffset(5);
71  axisXActor->SetTitleTextProperty(textProp1.Get());
72  axisXActor->SetLabelTextProperty(textProp2.Get());
73  axisXActor->SetAxisMainLineProperty(prop1.Get());
74  axisXActor->SetAxisMajorTicksProperty(prop2.Get());
75  axisXActor->SetAxisMinorTicksProperty(prop3.Get());
76 
77  //------------- Y Axis -------------
78  vtkNew<vtkAxisActor> axisYActor;
79  axisYActor->SetUse2DMode(use2dMode);
80  axisYActor->SetUseTextActor3D(use3dProp);
81  axisYActor->GetProperty()->SetAmbient(1);
82  axisYActor->GetProperty()->SetDiffuse(0);
83  axisYActor->SetPoint1(0, 0, 0);
84  axisYActor->SetPoint2(0, 10, 0);
85  axisYActor->SetTitle("Y Axis");
86  axisYActor->SetBounds(0, 0, 0, 10, 0, 0);
87  axisYActor->SetTickLocationToInside();
88  axisYActor->SetAxisTypeToY();
89  axisYActor->SetRange(0.1, 500);
90  axisYActor->SetMajorRangeStart(0.1);
91  axisYActor->SetMinorRangeStart(0.1);
92  axisYActor->SetMinorTicksVisible(true);
93  axisYActor->SetTitleAlignLocation(vtkAxisActor::VTK_ALIGN_TOP);
94  axisYActor->SetExponent("+00");
95  axisYActor->SetExponentVisibility(true);
96  axisYActor->SetExponentLocation(vtkAxisActor::VTK_ALIGN_TOP);
97  axisYActor->SetTitleScale(0.8);
98  axisYActor->SetLabelScale(0.5);
99  axisYActor->SetTitleOffset(3);
100  axisYActor->SetExponentOffset(5);
101  axisYActor->SetLabelOffset(5);
102  axisYActor->SetTitleTextProperty(textProp2.Get());
103  axisYActor->SetLog(true);
104  axisYActor->SetAxisLinesProperty(prop1.Get());
105 
106  //------------- Z Axis -------------
107  vtkNew<vtkAxisActor> axisZActor;
108  axisZActor->SetUse2DMode(use2dMode);
109  axisZActor->SetUseTextActor3D(use3dProp);
110  axisZActor->GetProperty()->SetAmbient(1);
111  axisZActor->GetProperty()->SetDiffuse(0);
112  axisZActor->SetPoint1(0, 0, 0);
113  axisZActor->SetPoint2(0, 0, 10);
114  axisZActor->SetTitle("Z Axis");
115  axisZActor->SetBounds(0, 0, 0, 0, 0, 10);
116  axisZActor->SetTickLocationToOutside();
117  axisZActor->SetAxisTypeToZ();
118  axisZActor->SetRange(0, 10);
119  axisZActor->SetTitleAlignLocation(vtkAxisActor::VTK_ALIGN_POINT2);
120  axisZActor->SetExponent("+00");
121  axisZActor->SetExponentVisibility(true);
122  axisZActor->SetExponentLocation(vtkAxisActor::VTK_ALIGN_POINT1);
123  axisZActor->SetTitleScale(0.8);
124  axisZActor->SetLabelScale(0.5);
125  axisZActor->SetTitleOffset(3);
126  axisZActor->SetExponentOffset(3);
127  axisZActor->SetLabelOffset(5);
128  axisZActor->SetTitleTextProperty(textProp3.Get());
129  axisZActor->SetMajorTickSize(3);
130  axisZActor->SetMinorTickSize(1);
131  axisZActor->SetDeltaRangeMajor(2);
132  axisZActor->SetDeltaRangeMinor(0.1);
133 
134  vtkNew<vtkRenderer> renderer;
135  vtkNew<vtkRenderWindow> renderWindow;
136  renderWindow->AddRenderer(renderer.Get());
137  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
138  renderWindowInteractor->SetRenderWindow(renderWindow.Get());
139  renderer->AddActor(axisXActor.Get());
140  renderer->AddActor(axisYActor.Get());
141  renderer->AddActor(axisZActor.Get());
142  renderer->SetBackground(.5, .5, .5);
143 
144  vtkCamera* camera = renderer->GetActiveCamera();
145  axisXActor->SetCamera(camera);
146  axisYActor->SetCamera(camera);
147  axisZActor->SetCamera(camera);
148  renderWindow->SetSize(300, 300);
149 
150  camera->SetPosition(-10.0, 22.0, -29);
151  camera->SetFocalPoint(-2, 8.5, -9.);
152 
153  renderWindow->SetMultiSamples(0);
154  renderWindow->Render();
155  renderWindowInteractor->Start();
156 
157  return EXIT_SUCCESS;
158 }
159 
160 #endif
int TestAxisActorInternal(int use2dMode, int use3dProp)
a virtual camera for 3D rendering
Definition: vtkCamera.h:51
void SetPosition(double x, double y, double z)
Set/Get the position of the camera in world coordinates.
void SetFocalPoint(double x, double y, double z)
Set/Get the focal of the camera in world coordinates.
T * Get() const
Definition: vtkNew.h:117
void SetValue(vtkIdType id, vtkStdString value)
Set the data at a particular index.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
virtual void SetOpacity(double)
Set/Get the text's opacity.
virtual void SetColor(double, double, double)
Set the color of the text.