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