VTK  9.5.20250807
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 "vtkStringArray.h"
15#include "vtkTextProperty.h"
16
17namespace
18{
19// ----------------------------------------------------------------------------
20inline void InitializeAxis(vtkAxisActor* axis)
21{
22 axis->SetPoint1(0, 0, 0);
23 axis->SetExponent("+00");
24 axis->SetExponentVisibility(true);
25 axis->SetTitleScale(0.8);
26 axis->SetLabelScale(0.5);
27
29 labels->SetNumberOfTuples(6);
30 labels->SetValue(0, "0");
31 labels->SetValue(1, "2");
32 labels->SetValue(2, "4");
33 labels->SetValue(3, "6");
34 labels->SetValue(4, "8");
35 labels->SetValue(5, "10");
36 axis->SetLabels(labels);
37
38 vtkNew<vtkCamera> camera;
39 axis->SetCamera(camera);
40}
41
42// ----------------------------------------------------------------------------
43inline void InitializeXAxis(vtkAxisActor* axis)
44{
45 ::InitializeAxis(axis);
46 axis->SetPoint2(10, 0, 0);
47 axis->SetTitle("X Axis");
48 axis->SetBounds(0, 10, 0, 0, 0, 0);
50 axis->SetAxisTypeToX();
51 axis->SetRange(0, 10);
52 axis->SetLabelOffset(5);
53 axis->SetDeltaRangeMajor(2);
54 axis->SetDeltaRangeMinor(0.5);
55 axis->SetExponentOffset(30);
56 axis->SetTitleOffset(0, 30);
57
59 textProp1->SetColor(0., 0., 1.);
60 textProp1->SetOpacity(0.9);
61 textProp1->SetFontSize(24);
62 axis->SetTitleTextProperty(textProp1);
63
65 textProp2->SetColor(1., 0., 0.);
66 textProp2->SetOpacity(0.6);
67 textProp2->SetFontSize(18);
68 axis->SetLabelTextProperty(textProp2);
69
71 prop1->SetColor(1., 0., 1.);
72 axis->SetAxisMainLineProperty(prop1);
73
75 prop2->SetColor(1., 1., 0.);
76 axis->SetAxisMajorTicksProperty(prop2);
77
79 prop3->SetColor(0., 1., 1.);
80 axis->SetAxisMinorTicksProperty(prop3);
81}
82
83// ----------------------------------------------------------------------------
84inline void InitializeYAxis(vtkAxisActor* axis)
85{
86 ::InitializeAxis(axis);
87 axis->SetPoint2(0, 10, 0);
88 axis->SetTitle("Y Axis");
89 axis->SetBounds(0, 0, 0, 10, 0, 0);
91 axis->SetAxisTypeToY();
92 axis->SetRange(0.1, 4000);
93 axis->SetMajorRangeStart(0.1);
94 axis->SetMinorRangeStart(0.1);
95 axis->SetMinorTicksVisible(true);
97 axis->SetTitleOffset(0, 3);
99 axis->SetExponentOffset(20);
100 axis->SetLog(true);
101
102 axis->GetCamera()->SetViewUp(1, 0, 0);
103
104 vtkNew<vtkTextProperty> textProp2;
105 textProp2->SetColor(1., 0., 0.);
106 textProp2->SetOpacity(0.6);
107 axis->SetTitleTextProperty(textProp2);
108
110 prop1->SetColor(1., 0., 1.);
111 axis->SetAxisLinesProperty(prop1);
112}
113
114// ----------------------------------------------------------------------------
115inline void InitializeZAxis(vtkAxisActor* axis)
116{
117 ::InitializeAxis(axis);
118
119 axis->SetPoint2(0, 0, 10);
120 axis->SetTitle("Z Axis");
121 axis->SetBounds(0, 0, 0, 0, 0, 10);
123 axis->SetAxisTypeToZ();
124 axis->SetRange(0, 10);
127 axis->SetTitleOffset(-80, -150);
128 axis->SetExponentOffset(-150);
129 axis->SetMajorTickSize(3);
130 axis->SetMinorTickSize(1);
131 axis->SetDeltaRangeMajor(2);
132 axis->SetDeltaRangeMinor(0.5);
133
134 axis->GetCamera()->SetPosition(0, 10, 0);
135 axis->GetCamera()->SetViewUp(1, 0, 0);
136
137 vtkNew<vtkTextProperty> textProp3;
138 textProp3->SetColor(0., 1., 0.);
139 textProp3->SetOpacity(1);
140 axis->SetTitleTextProperty(textProp3);
141}
142}
143
144// ----------------------------------------------------------------------------
145inline void AddToWindow(vtkRenderWindow* renderWindow, vtkAxisActor* axis)
146{
147 vtkNew<vtkRenderer> renderer;
148 renderer->SetActiveCamera(axis->GetCamera());
149 renderer->AddActor(axis);
150 renderer->SetBackground(.5, .5, .5);
151
152 renderWindow->AddRenderer(renderer);
153
154 renderWindow->SetSize(300, 300);
155 renderWindow->SetMultiSamples(0);
156 renderWindow->Render();
157 renderer->ResetCameraScreenSpace(0.8);
158}
159
160// ----------------------------------------------------------------------------
162{
163 vtkNew<vtkRenderWindow> renderWindow;
164 ::AddToWindow(renderWindow, axis);
165
166 vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
167 renderWindowInteractor->SetRenderWindow(renderWindow);
168
169 renderWindow->Render();
170 renderWindowInteractor->Start();
171
172 return EXIT_SUCCESS;
173}
174
175#endif
int TestAxisActorInternal(vtkAxisActor *axis)
void AddToWindow(vtkRenderWindow *renderWindow, vtkAxisActor *axis)
Create an axis with tick marks and labels.
void SetTickLocationToBoth()
virtual void SetCamera(vtkCamera *)
Set/Get the camera for this axis.
virtual void SetLog(bool)
Set/Get The type of scale, enable logarithmic scale or linear by default.
virtual void SetExponentOffset(double)
Set/Get the Y-offset used to position exponent.
virtual void SetMajorTickSize(double)
Set/Get the size of major tick marks.
virtual void SetMinorTickSize(double)
Set/Get the size of minor tick marks.
virtual void SetPoint2(double x[3])
Specify the position of the second point defining the axis.
void SetAxisMainLineProperty(vtkProperty *)
Get/Set main line axis actor property.
void SetBounds(const double bounds[6])
Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
void SetExponent(const std::string &exp)
Set/Get the common exponent of the labels values.
void SetAxisTypeToZ()
Set/Get the type of this axis.
void SetTitle(const std::string &title)
Set/Get the title of the axis actor.
virtual void SetRange(double, double)
Specify the (min,max) axis range.
virtual void SetLabelTextProperty(vtkTextProperty *p)
Set/Get the axis labels text property.
virtual void SetMajorRangeStart(double)
Set/Get the starting position for minor and major tick points on the range.
virtual void SetExponentLocation(int location)
Get/Set the location of the Detached Exponent related to the axis.
vtkCamera * GetCamera()
Set/Get the camera for this axis.
virtual void SetPoint1(double x[3])
Specify the position of the first point defining the axis.
void SetAxisLinesProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks) (kept for compatibility)
virtual void SetDeltaRangeMajor(double)
Set/Get the delta range for minor and major tick points that determine their spacing.
virtual void SetDeltaRangeMinor(double)
Set/Get the delta range for minor and major tick points that determine their spacing.
void SetAxisMajorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
void SetLabelScale(double scale)
Set scale on underlying actor.
void SetTickLocationToOutside()
void SetAxisTypeToY()
Set/Get the type of this axis.
void SetAxisTypeToX()
Set/Get the type of this axis.
virtual void SetLabelOffset(double)
Set/Get the Y-offset used to position label.
void SetTitleScale(double scale)
Set scale on underlying actor.
virtual void SetTitleAlignLocation(int location)
Get/Set the alignment of the title related to the axis.
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.
void SetTickLocationToInside()
void SetLabels(vtkStringArray *labels)
void SetAxisMinorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
virtual void SetMinorRangeStart(double)
Set/Get the starting position for minor and major tick points on the range.
virtual void SetTitleOffset(double, double)
Set/Get the 2D-offsets used to position title texts.
virtual void SetExponentVisibility(bool)
Set/Get visibility of the axis detached exponent.
void SetPosition(double x, double y, double z)
Set/Get the position of the camera in world coordinates.
void SetViewUp(double vx, double vy, double vz)
Set/Get the view up direction for the camera.
Allocate and hold a VTK object.
Definition vtkNew.h:167
create a window for renderers to draw into
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 SetMultiSamples(int)
Set / Get the number of multisamples to use for hardware antialiasing.
virtual void SetSize(int width, int height)
Set the size (width and height) of the rendering window in screen coordinates (in pixels).