VTK  9.3.1
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 
18 inline 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 
29  vtkNew<vtkTextProperty> textProp1;
30  textProp1->SetColor(0., 0., 1.);
31  textProp1->SetOpacity(0.9);
32 
33  vtkNew<vtkTextProperty> textProp2;
34  textProp2->SetColor(1., 0., 0.);
35  textProp2->SetOpacity(0.6);
36 
37  vtkNew<vtkTextProperty> textProp3;
38  textProp3->SetColor(0., 1., 0.);
39  textProp3->SetOpacity(1);
40 
41  vtkNew<vtkProperty> prop1;
42  prop1->SetColor(1., 0., 1.);
43 
44  vtkNew<vtkProperty> prop2;
45  prop2->SetColor(1., 1., 0.);
46 
47  vtkNew<vtkProperty> prop3;
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);
96  axisYActor->SetExponent("+00");
97  axisYActor->SetExponentVisibility(true);
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);
122  axisZActor->SetExponent("+00");
123  axisZActor->SetExponentVisibility(true);
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
virtual void SetPoint1(double x[3])
Specify the position of the first point defining the axis.
Definition: vtkAxisActor.h:85
virtual void SetMinorRangeStart(double)
Set/Get the starting position for minor and major tick points on the range.
void SetTickLocationToInside()
Definition: vtkAxisActor.h:203
virtual void SetUse2DMode(bool)
Set/Get the 2D mode.
void AddActor(vtkProp *p)
Add/Remove different types of props to the renderer.
void SetTitleScale(double scale)
virtual void SetColor(double, double, double)
Set the color of the text.
virtual void SetDiffuse(double)
Set/Get the diffuse lighting coefficient.
vtkProperty * GetProperty()
Set/Get the property object that controls this actors surface properties.
virtual void SetPoint2(double x[3])
Specify the position of the second point defining the axis.
Definition: vtkAxisActor.h:95
void SetTickLocationToBoth()
Definition: vtkAxisActor.h:205
void SetRenderWindow(vtkRenderWindow *aren)
Set/Get the rendering window being controlled by this object.
void SetAxisTypeToY()
Set/Get the type of this axis.
Definition: vtkAxisActor.h:440
virtual void SetBackground(double, double, double)
Set/Get the background color of the rendering screen using an rgb color specification.
virtual void AddRenderer(vtkRenderer *)
Add a renderer to the list of renderers.
void Render() override
Ask each renderer owned by this RenderWindow to render its image and synchronize this process...
virtual void SetDeltaRangeMinor(double)
Set/Get the delta range for minor and major tick points that determine their spacing.
void SetPosition(double x, double y, double z)
Set/Get the position of the camera in world coordinates.
void SetBounds(const double bounds[6])
Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
void SetAxisTypeToX()
Set/Get the type of this axis.
Definition: vtkAxisActor.h:439
vtkCamera * GetActiveCamera()
Get the current camera.
void SetValue(vtkIdType id, vtkStdString value)
Set the data at a particular index.
virtual void SetCamera(vtkCamera *)
Set/Get the camera for this axis.
virtual void SetTitleAlignLocation(int location)
Get/Set the alignment of the title related to the axis.
virtual void SetMajorTickSize(double)
Set/Get the size of major tick marks.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
virtual void Start()
Start the event loop.
virtual void SetMinorTickSize(double)
Set/Get the size of minor tick marks.
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels)...
void SetTitle(const char *t)
Set/Get the title of the axis actor.
virtual void SetLog(bool)
Set/Get The type of scale, enable logarithmic scale or linear by default.
a virtual camera for 3D rendering
Definition: vtkCamera.h:40
void SetAxisLinesProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks) (kept for compatibility)
void SetLabels(vtkStringArray *labels)
virtual void SetOpacity(double)
Set/Get the text's opacity.
void SetTickLocationToOutside()
Definition: vtkAxisActor.h:204
virtual void SetExponentOffset(double)
Set/Get the Y-offset used to position exponent.
void SetFocalPoint(double x, double y, double z)
Set/Get the focal of the camera in world coordinates.
void SetAxisMainLineProperty(vtkProperty *)
Get/Set main line axis actor property.
virtual void SetLabelOffset(double)
Set/Get the Y-offset used to position label.
virtual void SetDeltaRangeMajor(double)
Set/Get the delta range for minor and major tick points that determine their spacing.
void SetLabelScale(double scale)
virtual void SetMultiSamples(int)
Set / Get the number of multisamples to use for hardware antialiasing.
void SetExponent(const char *t)
Set/Get the common exponent of the labels values.
virtual void SetAmbient(double)
Set/Get the ambient lighting coefficient.
virtual void SetTitleTextProperty(vtkTextProperty *p)
Set/Get the axis title text property.
virtual void SetMinorTicksVisible(bool)
Set/Get the flag that controls whether the minor ticks are visible.
int TestAxisActorInternal(int use2dMode, int use3dProp)
virtual void SetColor(double r, double g, double b)
Set the color of the object.
virtual void SetMajorRangeStart(double)
Set/Get the starting position for minor and major tick points on the range.
void SetAxisMajorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
virtual void SetRange(double, double)
Specify the (min,max) axis range.
virtual void SetExponentLocation(int location)
Get/Set the location of the Detached Exponent related to the axis.
void SetAxisMinorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
virtual void SetUseTextActor3D(bool)
Render text as polygons (vtkVectorText) or as sprites (vtkTextActor3D).
virtual void SetLabelTextProperty(vtkTextProperty *p)
Set/Get the axis labels text property.
void SetAxisTypeToZ()
Set/Get the type of this axis.
Definition: vtkAxisActor.h:441
void SetTitleOffset(double titleOffsetY)
Set/Get the 2D-offsets used to position title texts.
virtual void SetExponentVisibility(bool)
Set/Get visibility of the axis detached exponent.