VTK  9.6.20260206
vtkAxisActor.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
62
63#ifndef vtkAxisActor_h
64#define vtkAxisActor_h
65
66#include "vtkActor.h"
67#include "vtkNew.h" // For vtkNew
68#include "vtkRenderingAnnotationModule.h" // For export macro
69#include "vtkSmartPointer.h" // For vtkSmartPointer
70#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
71
72#include <memory>
73#include <string>
74
75VTK_ABI_NAMESPACE_BEGIN
76class vtkAxisFollower;
77class vtkCamera;
78class vtkCoordinate;
79class vtkPoints;
80class vtkPolyData;
83class vtkStringArray;
84class vtkTextActor;
86class vtkTextActor3D;
87class vtkTextProperty;
88class vtkVectorText;
89
90class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor : public vtkActor
91{
92public:
93 vtkTypeMacro(vtkAxisActor, vtkActor);
94 void PrintSelf(ostream& os, vtkIndent indent) override;
95
99 static vtkAxisActor* New();
100
102
106 virtual void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
107 virtual void SetPoint1(double x, double y, double z);
108 virtual double* GetPoint1();
110
112
116 virtual void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
117 virtual void SetPoint2(double x, double y, double z);
118 virtual double* GetPoint2();
120
122
127 vtkSetVector2Macro(Range, double);
128 vtkGetVectorMacro(Range, double, 2);
130
132
136 void SetBounds(const double bounds[6]);
137 void SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
138 double* GetBounds() VTK_SIZEHINT(6) override;
139 void GetBounds(double bounds[6]);
141
143
146 void SetLabelFormat(const char* format);
147 vtkGetStringMacro(LabelFormat);
149
151
158 vtkSetMacro(UseTextActor3D, bool);
159 vtkGetMacro(UseTextActor3D, bool);
161
163
167 vtkSetMacro(MinorTicksVisible, bool);
168 vtkGetMacro(MinorTicksVisible, bool);
169 vtkBooleanMacro(MinorTicksVisible, bool);
171
173
176 void SetTitle(const std::string& title);
177 vtkGetMacro(Title, std::string);
179
181
184 void SetExponent(const std::string& exp);
185 vtkGetMacro(Exponent, std::string);
187
189
193 vtkSetMacro(MajorTickSize, double);
194 vtkGetMacro(MajorTickSize, double);
196
198
202 vtkSetMacro(MinorTickSize, double);
203 vtkGetMacro(MinorTickSize, double);
205
212
214
221 vtkGetMacro(TickLocation, int);
223
227
229
233 vtkSetMacro(AxisVisibility, bool);
234 vtkGetMacro(AxisVisibility, bool);
235 vtkBooleanMacro(AxisVisibility, bool);
237
239
243 vtkSetMacro(TickVisibility, bool);
244 vtkGetMacro(TickVisibility, bool);
245 vtkBooleanMacro(TickVisibility, bool);
247
249
253 vtkSetMacro(LabelVisibility, bool);
254 vtkGetMacro(LabelVisibility, bool);
255 vtkBooleanMacro(LabelVisibility, bool);
257
259
263 vtkSetMacro(TitleVisibility, bool);
264 vtkGetMacro(TitleVisibility, bool);
265 vtkBooleanMacro(TitleVisibility, bool);
267
269
273 vtkSetMacro(ExponentVisibility, bool);
274 vtkGetMacro(ExponentVisibility, bool);
275 vtkBooleanMacro(ExponentVisibility, bool);
277
279
283 vtkSetMacro(LastMajorTickPointCorrection, bool);
284 vtkGetMacro(LastMajorTickPointCorrection, bool);
285 vtkBooleanMacro(LastMajorTickPointCorrection, bool);
287
295
297
302 virtual void SetTitleAlignLocation(int location);
303 vtkGetMacro(TitleAlignLocation, int);
305
307
312 virtual void SetExponentLocation(int location);
313 vtkGetMacro(ExponentLocation, int);
315
317
323
325
331
333
339
341
347
349
355
357
363
365
371
373
379
381
387
389
393 vtkSetMacro(DrawGridlines, bool);
394 vtkGetMacro(DrawGridlines, bool);
395 vtkBooleanMacro(DrawGridlines, bool);
397
399
405 vtkSetMacro(DrawGridlinesOnly, bool);
406 vtkGetMacro(DrawGridlinesOnly, bool);
407 vtkBooleanMacro(DrawGridlinesOnly, bool);
409
410 vtkSetMacro(DrawGridlinesLocation, int);
411 vtkGetMacro(DrawGridlinesLocation, int);
412
414
418 vtkSetMacro(DrawInnerGridlines, bool);
419 vtkGetMacro(DrawInnerGridlines, bool);
420 vtkBooleanMacro(DrawInnerGridlines, bool);
422
424
428 vtkSetMacro(GridlineXLength, double);
429 vtkGetMacro(GridlineXLength, double);
430 vtkSetMacro(GridlineYLength, double);
431 vtkGetMacro(GridlineYLength, double);
432 vtkSetMacro(GridlineZLength, double);
433 vtkGetMacro(GridlineZLength, double);
435
437
441 vtkSetMacro(DrawGridpolys, bool);
442 vtkGetMacro(DrawGridpolys, bool);
443 vtkBooleanMacro(DrawGridpolys, bool);
445
452
454
458 vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
459 vtkGetMacro(AxisType, int);
464
472
474
478 vtkSetMacro(Log, bool);
479 vtkGetMacro(Log, bool);
480 vtkBooleanMacro(Log, bool);
482
484
493 vtkGetMacro(AxisPosition, int);
495
500
502
506 virtual void SetCamera(vtkCamera*);
509
511
514 int RenderOpaqueGeometry(vtkViewport* viewport) override;
517 int RenderOverlay(vtkViewport* viewport) override;
520
527
533
539
541
544 void SetLabelScale(double scale);
545 void SetLabelScale(int labelIndex, double scale);
546 void SetTitleScale(double scale);
547 void SetExponentScale(double scale);
549
551
555 double GetMajorStart(int axis);
556 void SetMajorStart(int axis, double value);
557 double GetDeltaMajor(int axis);
558 void SetDeltaMajor(int axis, double value);
560
562
568 vtkSetMacro(MinorRangeStart, double);
569 vtkGetMacro(MinorRangeStart, double);
570 vtkSetMacro(MajorRangeStart, double);
571 vtkGetMacro(MajorRangeStart, double);
573
575
579 vtkSetMacro(DeltaRangeMinor, double);
580 vtkGetMacro(DeltaRangeMinor, double);
581 vtkSetMacro(DeltaRangeMajor, double);
582 vtkGetMacro(DeltaRangeMajor, double);
584
586
587 void BuildAxis(vtkViewport* viewport, bool);
588
594
599
601
607
609
615
617
623
625
631
633
637 vtkGetMacro(NumberOfLabelsBuilt, int);
639
641
645 vtkSetMacro(Use2DMode, bool);
646 vtkGetMacro(Use2DMode, bool);
648
650
654 vtkSetMacro(VerticalOffsetXTitle2D, double);
655 vtkGetMacro(VerticalOffsetXTitle2D, double);
657
659
663 vtkSetMacro(HorizontalOffsetYTitle2D, double);
664 vtkGetMacro(HorizontalOffsetYTitle2D, double);
666
668
672 vtkSetMacro(SaveTitlePosition, int);
673 vtkGetMacro(SaveTitlePosition, int);
675
677
681 vtkSetVector3Macro(AxisBaseForX, double);
682 vtkGetVector3Macro(AxisBaseForX, double);
684
686
690 vtkSetVector3Macro(AxisBaseForY, double);
691 vtkGetVector3Macro(AxisBaseForY, double);
693
695
699 vtkSetVector3Macro(AxisBaseForZ, double);
700 vtkGetVector3Macro(AxisBaseForZ, double);
702
704
708 vtkSetMacro(AxisOnOrigin, bool);
709 vtkGetMacro(AxisOnOrigin, bool);
711
713
717 vtkSetMacro(ScreenSize, double);
718 vtkGetMacro(ScreenSize, double);
720
722
726 vtkSetMacro(LabelOffset, double);
727 vtkGetMacro(LabelOffset, double);
729
731
735 vtkSetMacro(ExponentOffset, double);
736 vtkGetMacro(ExponentOffset, double);
738
740
747 vtkSetVector2Macro(TitleOffset, double);
748 vtkGetVector2Macro(TitleOffset, double);
750
751protected:
753 ~vtkAxisActor() override;
754
755private:
756 vtkAxisActor(const vtkAxisActor&) = delete;
757 void operator=(const vtkAxisActor&) = delete;
758
759 void TransformBounds(vtkViewport*, double bnds[6]);
760
761 void BuildLabels(vtkViewport*, bool);
762 void BuildLabels2D(vtkViewport*, bool);
763 void SetLabelPositions(vtkViewport*, bool);
764 void SetLabelPositions2D(vtkViewport*, bool);
765
772 void BuildTitle(bool);
773
778 void BuildExponent(bool force);
779
780 void BuildExponent2D(vtkViewport* viewport, bool force);
781
782 void BuildTitle2D(vtkViewport* viewport, bool);
783
787 void Get2DPosition(
788 vtkViewport* viewport, double multiplier, double scenepos[3], double displayPos[2]);
789
790 void SetAxisPointsAndLines();
791
792 bool BuildTickPoints(double p1[3], double p2[3], bool force);
793
794 // Build major ticks for linear scale.
795 void BuildMajorTicks(double p1[3], double p2[3], double localCoordSys[3][3]);
796
797 // Build major ticks for logarithmic scale.
798 void BuildMajorTicksLog(double p1[3], double p2[3], double localCoordSys[3][3]);
799
800 // Build minor ticks for linear scale.
801 void BuildMinorTicks(double p1[3], double p2[3], double localCoordSys[3][3]);
802
803 // Build minor ticks for logarithmic scale enabled
804 void BuildMinorTicksLog(double p1[3], double p2[3], double localCoordSys[3][3]);
805
806 void BuildAxisGridLines(double p1[3], double p2[3], double localCoordSys[3][3]);
807
808 bool TickVisibilityChanged();
809
810 vtkProperty* NewTitleProperty();
811 vtkProperty* NewLabelProperty();
812
813 bool BoundsDisplayCoordinateChanged(vtkViewport* viewport);
814
816
819 vtkProp* GetTitleActorInternal();
820 vtkProp* GetLabelActorInternal(int index);
821 vtkProp* GetExponentActorInternal();
823
833 void UpdateTitleActorProperty();
834 void UpdateLabelActorProperty(int idx);
835 void UpdateExponentActorProperty();
837
843 void GetTranslucentProps(vtkPropCollection* collection);
844
845 std::string Title;
846 std::string Exponent;
847 char* LabelFormat = nullptr;
848 double Range[2] = { 0.0, 1.0 };
849 double LastRange[2] = { -1.0, -1.0 };
850 bool UseTextActor3D = false;
851 int NumberOfLabelsBuilt = 0;
852 bool MinorTicksVisible = true;
853 bool LastMinorTicksVisible = true;
854
860 int TickLocation = VTK_TICKS_INSIDE;
861
866 int TitleAlignLocation = VTK_ALIGN_BOTTOM;
867
872 int ExponentLocation = VTK_ALIGN_POINT2;
873
874 bool DrawGridlines = false;
875 bool DrawGridlinesOnly = false;
876 bool LastDrawGridlines = false;
877 int DrawGridlinesLocation = 0; // 0: all | 1: closest | 2: furthest
878 int LastDrawGridlinesLocation = 0; // 0: all | 1: closest | 2: furthest
879 double GridlineXLength = 1.0;
880 double GridlineYLength = 1.0;
881 double GridlineZLength = 1.0;
882
883 bool DrawInnerGridlines = false;
884
885 bool DrawGridpolys = false;
886
887 bool AxisVisibility = true;
888 bool TickVisibility = true;
889 bool LastTickVisibility = true;
890 bool LabelVisibility = true;
891 bool TitleVisibility = true;
892 bool ExponentVisibility = false;
893 bool LastMajorTickPointCorrection = false;
894
895 bool Log = false;
896 int AxisType = VTK_AXIS_TYPE_X;
897 int AxisPosition = VTK_AXIS_POS_MINMIN;
898
899 // coordinate system for axisAxtor, relative to world coordinates
900 double AxisBaseForX[3] = { 1.0, 0.0, 0.0 };
901 double AxisBaseForY[3] = { 0.0, 1.0, 0.0 };
902 double AxisBaseForZ[3] = { 0.0, 0.0, 1.0 };
903
904 vtkNew<vtkCoordinate> Point1Coordinate;
905 vtkNew<vtkCoordinate> Point2Coordinate;
906
907 double MajorTickSize = 1.0;
908 double MinorTickSize = 0.5;
909
910 // For each axis (for the inner gridline generation)
911 double MajorStart[3] = { 0.0, 0.0, 0.0 };
912 double DeltaMajor[3] = { 1.0, 1.0, 1.0 };
913
914 // For the ticks, w.r.t to the set range
915 double MajorRangeStart = 0.0;
916 double MinorRangeStart = 0.0;
917
921 double DeltaRangeMinor = 1.0;
922
926 double DeltaRangeMajor = 1.0;
927
928 int LastAxisPosition = -1;
929 int LastTickLocation = -1;
930
931 vtkNew<vtkPoints> MinorTickPts;
932 vtkNew<vtkPoints> MajorTickPts;
933 vtkNew<vtkPoints> GridlinePts;
934 vtkNew<vtkPoints> InnerGridlinePts;
935 vtkNew<vtkPoints> GridpolyPts;
936
937 std::unique_ptr<vtkTextActorInterfaceInternal> TitleProp;
938 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
939
941
944 std::unique_ptr<vtkTextActorInterfaceInternal> ExponentProp;
946
947 std::vector<std::shared_ptr<vtkTextActorInterfaceInternal>> LabelProps;
948 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
949
950 // Main line axis
951 vtkNew<vtkPolyData> AxisLines;
952 vtkNew<vtkActor> AxisLinesActor;
953
954 // Ticks of the axis
955 vtkNew<vtkPolyData> AxisMajorTicks, AxisMinorTicks;
956 vtkNew<vtkActor> AxisMajorTicksActor, AxisMinorTicksActor;
957
958 vtkNew<vtkPolyData> Gridlines;
959 vtkNew<vtkActor> GridlinesActor;
960 vtkNew<vtkPolyData> InnerGridlines;
961 vtkNew<vtkActor> InnerGridlinesActor;
962 vtkNew<vtkPolyData> Gridpolys;
963 vtkNew<vtkActor> GridpolysActor;
964
965 vtkSmartPointer<vtkCamera> Camera;
966 vtkTimeStamp BuildTime;
967 vtkTimeStamp BuildTickPointsTime;
968 vtkTimeStamp BoundsTime;
969 vtkTimeStamp LabelBuildTime;
970 vtkTimeStamp TitleTextTime;
971 vtkTimeStamp ExponentTextTime;
972
973 bool AxisOnOrigin = false;
974
975 bool AxisHasZeroLength = false;
976
980 bool Use2DMode = false;
981
986 double VerticalOffsetXTitle2D = -40;
987
992 double HorizontalOffsetYTitle2D = -50;
993
1000 int SaveTitlePosition = 0;
1001
1005 double TitleConstantPosition[2] = { 0.0, 0.0 };
1006
1010 bool NeedBuild2D = false;
1011
1012 double LastMinDisplayCoordinate[3] = { 0.0, 0.0, 0.0 };
1013 double LastMaxDisplayCoordinate[3] = { 0.0, 0.0, 0.0 };
1014 double TickVector[3] = { 0.0, 0.0, 0.0 };
1015
1019 double ScreenSize = 10.0;
1020
1022
1025 double LabelOffset = 30.0;
1026 double TitleOffset[2] = { 20.0, 20.0 };
1027 double ExponentOffset = 20.0;
1029};
1030
1031VTK_ABI_NAMESPACE_END
1032#endif
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetTickLocationToBoth()
void SetAxisPositionToMinMax()
virtual void SetPoint2(double x, double y, double z)
Specify the position of the second point defining the axis.
virtual void SetCamera(vtkCamera *)
Set/Get the camera for this axis.
virtual void SetPoint2(double x[3])
Specify the position of the second point defining the axis.
void SetDeltaMajor(int axis, double value)
Set/Get the starting position for minor and major tick points, and the delta values that determine th...
void SetAxisMainLineProperty(vtkProperty *)
Get/Set main line axis actor property.
virtual double * GetPoint1()
Specify the position of the first point defining the axis.
double ComputeTitleLength()
Compute the diagonal length of the Title text.
vtkProperty * GetGridlinesProperty()
Get/Set gridlines actor property (outer grid lines)
void SetBounds(const double bounds[6])
Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
int RenderOverlay(vtkViewport *viewport) override
Draw the axis.
vtkTypeBool HasTranslucentPolygonalGeometry() override
Draw the axis.
~vtkAxisActor() override
void SetExponent(const std::string &exp)
Set/Get the common exponent of the labels values.
double GetMajorStart(int axis)
Set/Get the starting position for minor and major tick points, and the delta values that determine th...
int GetNumberOfLabelFollower3D()
Get label actors responsigle for drawing label text.
void SetGridlinesProperty(vtkProperty *)
Get/Set gridlines actor property (outer grid lines)
void SetAxisTypeToZ()
Set/Get the type of this axis.
double ComputeMaxLabelLength()
Compute the max diagonal lentgh of the labels.
void SetTitle(const std::string &title)
Set/Get the title of the axis actor.
vtkProperty * GetGridpolysProperty()
Get/Set gridPolys actor property (grid quads)
int GetNumberOfLabelFollowers()
Get label actors responsible for drawing label text.
void SetLabelFormat(const char *format)
Set/Get the std::format or printf style format with which to print the labels on the axis.
virtual void SetLabelTextProperty(vtkTextProperty *p)
Set/Get the axis labels text property.
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 vtkCoordinate * GetPoint2Coordinate()
Specify the position of the second point defining the axis.
vtkProperty * GetInnerGridlinesProperty()
Get/Set inner gridlines actor property.
void SetAxisPositionToMinMin()
double GetDeltaMajor(int axis)
Set/Get the starting position for minor and major tick points, and the delta values that determine th...
vtkProp3DAxisFollower * GetLabelFollower3D(int index)
Get label actors responsigle for drawing label text.
double * GetBounds() override
Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
vtkTextProperty * GetLabelTextProperty()
Set/Get the axis labels text property.
void SetLabelScale(int labelIndex, double scale)
Set scale on underlying actor.
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)
void SetInnerGridlinesProperty(vtkProperty *)
Get/Set inner gridlines actor property.
vtkProperty * GetAxisMajorTicksProperty()
Get/Set axis actor property (axis and its ticks)
void SetAxisMajorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
void SetLabelScale(double scale)
Set scale on underlying actor.
void SetTickLocationToOutside()
void SetExponentScale(double scale)
Set scale on underlying actor.
void SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax)
Set or get the bounds for this Actor as (Xmin,Xmax,Ymin,Ymax,Zmin,Zmax).
void BuildAxis(vtkViewport *viewport, bool)
virtual double * GetPoint2()
Specify the position of the second point defining the axis.
void SetAxisTypeToY()
Set/Get the type of this axis.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
vtkAxisFollower * GetExponentActor()
Get exponent follower actor.
int RenderOpaqueGeometry(vtkViewport *viewport) override
Draw the axis.
virtual void SetAxisType(int)
Set/Get the type of this axis.
virtual void SetAxisPosition(int)
Set/Get the position of this axis (in relation to an an assumed bounding box).
void SetAxisTypeToX()
Set/Get the type of this axis.
virtual void SetTickLocation(int)
Set/Get the location of the ticks.
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.
vtkProperty * GetAxisMainLineProperty()
Get/Set main line axis actor property.
vtkAxisFollower * GetTitleActor()
Get title actor and it is responsible for drawing title text.
virtual void SetTitleTextProperty(vtkTextProperty *p)
Set/Get the axis title text property.
void SetAxisPositionToMaxMin()
virtual vtkCoordinate * GetPoint1Coordinate()
Specify the position of the first point defining the axis.
virtual int RenderTranslucentGeometry(vtkViewport *viewport)
Draw the axis.
virtual int GetNumberOfLabelsBuilt()
Get total number of labels built.
void SetTickLocationToInside()
void SetLabels(vtkStringArray *labels)
vtkAxisFollower * GetLabelFollower(int index)
Get label actors responsible for drawing label text.
vtkProperty * GetAxisMinorTicksProperty()
Get/Set axis actor property (axis and its ticks)
vtkProp3DAxisFollower * GetExponentProp3D()
Get title actor and it is responsible for drawing title text.
vtkTextProperty * GetTitleTextProperty()
Set/Get the axis title text property.
void SetAxisPositionToMaxMax()
virtual void SetPoint1(double x, double y, double z)
Specify the position of the first point defining the axis.
void SetAxisMinorTicksProperty(vtkProperty *)
Get/Set axis actor property (axis and its ticks)
static vtkAxisActor * New()
Instantiate object.
void SetMajorStart(int axis, double value)
Set/Get the starting position for minor and major tick points, and the delta values that determine th...
vtkProp3DAxisFollower * GetTitleProp3D()
Get title actor and it is responsible for drawing title text.
vtkProperty * GetAxisLinesProperty()
Get/Set axis actor property (axis and its ticks) (kept for compatibility)
int RenderTranslucentPolygonalGeometry(vtkViewport *viewport) override
Draw the axis.
void SetGridpolysProperty(vtkProperty *)
Get/Set gridPolys actor property (grid quads)
a subclass of vtkFollower that ensures that data is always parallel to the axis defined by a vtkAxisA...
a virtual camera for 3D rendering
Definition vtkCamera.h:151
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 3D points
Definition vtkPoints.h:139
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
a subclass of vtkProp3DFollower that ensures that data is always parallel to the axis defined by a vt...
an ordered list of Props
represent surface properties of a geometric object
a vtkAbstractArray subclass for strings
An actor that displays text.
VTK Internal interface to manipulate text actors from vtkAxisActor.
An actor that displays text.
represent text properties.
create polygonal text
abstract specification for Viewports
Definition vtkViewport.h:66
window superclass for vtkRenderWindow
Definition vtkWindow.h:61
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO