VTK  9.5.2
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->GetProperty()->SetAmbient(1);
23 axis->GetProperty()->SetDiffuse(0);
24 axis->SetPoint1(0, 0, 0);
25 axis->SetExponent("+00");
26 axis->SetExponentVisibility(true);
27 axis->SetTitleScale(0.8);
28 axis->SetLabelScale(0.5);
29
31 labels->SetNumberOfTuples(6);
32 labels->SetValue(0, "0");
33 labels->SetValue(1, "2");
34 labels->SetValue(2, "4");
35 labels->SetValue(3, "6");
36 labels->SetValue(4, "8");
37 labels->SetValue(5, "10");
38 axis->SetLabels(labels);
39
40 vtkNew<vtkCamera> camera;
41 axis->SetCamera(camera);
42}
43
44// ----------------------------------------------------------------------------
45inline void InitializeXAxis(vtkAxisActor* axis)
46{
47 ::InitializeAxis(axis);
48 axis->SetPoint2(10, 0, 0);
49 axis->SetTitle("X Axis");
50 axis->SetBounds(0, 10, 0, 0, 0, 0);
52 axis->SetAxisTypeToX();
53 axis->SetRange(0, 10);
54 axis->SetLabelOffset(5);
55 axis->SetDeltaRangeMajor(2);
56 axis->SetDeltaRangeMinor(0.5);
57 axis->SetExponentOffset(30);
58 axis->SetTitleOffset(0, 30);
59
61 textProp1->SetColor(0., 0., 1.);
62 textProp1->SetOpacity(0.9);
63 textProp1->SetFontSize(36);
64 axis->SetTitleTextProperty(textProp1);
65
67 textProp2->SetColor(1., 0., 0.);
68 textProp2->SetOpacity(0.6);
69 textProp2->SetFontSize(24);
70 axis->SetLabelTextProperty(textProp2);
71
73 prop1->SetColor(1., 0., 1.);
74 axis->SetAxisMainLineProperty(prop1);
75
77 prop2->SetColor(1., 1., 0.);
78 axis->SetAxisMajorTicksProperty(prop2);
79
81 prop3->SetColor(0., 1., 1.);
82 axis->SetAxisMinorTicksProperty(prop3);
83}
84
85// ----------------------------------------------------------------------------
86inline void InitializeYAxis(vtkAxisActor* axis)
87{
88 ::InitializeAxis(axis);
89 axis->SetPoint2(0, 10, 0);
90 axis->SetTitle("Y Axis");
91 axis->SetBounds(0, 0, 0, 10, 0, 0);
93 axis->SetAxisTypeToY();
94 axis->SetRange(0.1, 4000);
95 axis->SetMajorRangeStart(0.1);
96 axis->SetMinorRangeStart(0.1);
97 axis->SetMinorTicksVisible(true);
99 axis->SetTitleOffset(0, 3);
101 axis->SetExponentOffset(20);
102 axis->SetLog(true);
103
104 axis->GetCamera()->SetViewUp(1, 0, 0);
105
106 vtkNew<vtkTextProperty> textProp2;
107 textProp2->SetColor(1., 0., 0.);
108 textProp2->SetOpacity(0.6);
109 axis->SetTitleTextProperty(textProp2);
110
112 prop1->SetColor(1., 0., 1.);
113 axis->SetAxisLinesProperty(prop1);
114}
115
116// ----------------------------------------------------------------------------
117inline void InitializeZAxis(vtkAxisActor* axis)
118{
119 ::InitializeAxis(axis);
120
121 axis->SetPoint2(0, 0, 10);
122 axis->SetTitle("Z Axis");
123 axis->SetBounds(0, 0, 0, 0, 0, 10);
125 axis->SetAxisTypeToZ();
126 axis->SetRange(0, 10);
129 axis->SetTitleOffset(-80, -150);
130 axis->SetExponentOffset(-150);
131 axis->SetMajorTickSize(3);
132 axis->SetMinorTickSize(1);
133 axis->SetDeltaRangeMajor(2);
134 axis->SetDeltaRangeMinor(0.5);
135
136 axis->GetCamera()->SetPosition(0, 10, 0);
137 axis->GetCamera()->SetViewUp(1, 0, 0);
138
139 vtkNew<vtkTextProperty> textProp3;
140 textProp3->SetColor(0., 1., 0.);
141 textProp3->SetOpacity(1);
142 axis->SetTitleTextProperty(textProp3);
143}
144}
145
146// ----------------------------------------------------------------------------
148{
149 vtkNew<vtkRenderer> renderer;
150 renderer->SetActiveCamera(axis->GetCamera());
151 renderer->AddActor(axis);
152 renderer->SetBackground(.5, .5, .5);
153
154 vtkNew<vtkRenderWindow> renderWindow;
155 renderWindow->AddRenderer(renderer);
156
157 renderWindow->SetSize(300, 300);
158 renderWindow->SetMultiSamples(0);
159
160 vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
161 renderWindowInteractor->SetRenderWindow(renderWindow);
162
163 renderWindow->Render();
164 renderer->ResetCameraScreenSpace(0.8);
165 renderWindow->Render();
166 renderWindowInteractor->Start();
167
168 return EXIT_SUCCESS;
169}
170
171#endif
int TestAxisActorInternal(vtkAxisActor *axis)
vtkProperty * GetProperty()
Set/Get the property object that controls this actors surface properties.
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
virtual void SetAmbient(double)
Set/Get the ambient lighting coefficient.
virtual void SetDiffuse(double)
Set/Get the diffuse lighting coefficient.