VTK  9.7.0
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
43
44#ifndef vtkAxisActor_h
45#define vtkAxisActor_h
46
47#include "vtkActor.h"
48#include "vtkNew.h" // For vtkNew
49#include "vtkRenderingAnnotationModule.h" // For export macro
50#include "vtkSmartPointer.h" // For vtkSmartPointer
51#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
52
53#include <memory>
54#include <string>
55
56VTK_ABI_NAMESPACE_BEGIN
57class vtkAxisFollower;
58class vtkCamera;
59class vtkCoordinate;
60class vtkPoints;
61class vtkPolyData;
64class vtkStringArray;
65class vtkTextActor;
67class vtkTextActor3D;
68class vtkTextProperty;
69class vtkVectorText;
70
71class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor : public vtkActor
72{
73public:
74 vtkTypeMacro(vtkAxisActor, vtkActor);
75 void PrintSelf(ostream& os, vtkIndent indent) override;
76
80 static vtkAxisActor* New();
81
83
87 virtual void SetPoint1(double x[3]) { this->SetPoint1(x[0], x[1], x[2]); }
88 virtual void SetPoint1(double x, double y, double z);
89 virtual double* GetPoint1();
91
93
97 virtual void SetPoint2(double x[3]) { this->SetPoint2(x[0], x[1], x[2]); }
98 virtual void SetPoint2(double x, double y, double z);
99 virtual double* GetPoint2();
101
103
108 vtkSetVector2Macro(Range, double);
109 vtkGetVectorMacro(Range, double, 2);
111
113
117 void SetBounds(const double bounds[6]);
118 void SetBounds(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax);
119 double* GetBounds() VTK_SIZEHINT(6) override;
120 void GetBounds(double bounds[6]);
122
124
127 void SetLabelFormat(const char* format);
128 vtkGetStringMacro(LabelFormat);
130
132
139 vtkSetMacro(UseTextActor3D, bool);
140 vtkGetMacro(UseTextActor3D, bool);
142
144
148 vtkSetMacro(MinorTicksVisible, bool);
149 vtkGetMacro(MinorTicksVisible, bool);
150 vtkBooleanMacro(MinorTicksVisible, bool);
152
154
157 void SetTitle(const std::string& title);
158 vtkGetMacro(Title, std::string);
160
162
165 void SetExponent(const std::string& exp);
166 vtkGetMacro(Exponent, std::string);
168
170
174 vtkSetMacro(MajorTickSize, double);
175 vtkGetMacro(MajorTickSize, double);
177
179
183 vtkSetMacro(MinorTickSize, double);
184 vtkGetMacro(MinorTickSize, double);
186
188 {
192 };
193
195
202 vtkGetMacro(TickLocation, int);
204
208
210
214 vtkSetMacro(AxisVisibility, bool);
215 vtkGetMacro(AxisVisibility, bool);
216 vtkBooleanMacro(AxisVisibility, bool);
218
220
224 vtkSetMacro(TickVisibility, bool);
225 vtkGetMacro(TickVisibility, bool);
226 vtkBooleanMacro(TickVisibility, bool);
228
230
234 vtkSetMacro(LabelVisibility, bool);
235 vtkGetMacro(LabelVisibility, bool);
236 vtkBooleanMacro(LabelVisibility, bool);
238
240
244 vtkSetMacro(TitleVisibility, bool);
245 vtkGetMacro(TitleVisibility, bool);
246 vtkBooleanMacro(TitleVisibility, bool);
248
250
254 vtkSetMacro(ExponentVisibility, bool);
255 vtkGetMacro(ExponentVisibility, bool);
256 vtkBooleanMacro(ExponentVisibility, bool);
258
260
264 vtkSetMacro(LastMajorTickPointCorrection, bool);
265 vtkGetMacro(LastMajorTickPointCorrection, bool);
266 vtkBooleanMacro(LastMajorTickPointCorrection, bool);
268
270 {
275 };
276
278
283 virtual void SetTitleAlignLocation(int location);
284 vtkGetMacro(TitleAlignLocation, int);
286
288
293 virtual void SetExponentLocation(int location);
294 vtkGetMacro(ExponentLocation, int);
296
298
304
306
312
314
320
322
328
330
336
338
344
346
352
354
360
362
368
370
374 vtkSetMacro(DrawGridlines, bool);
375 vtkGetMacro(DrawGridlines, bool);
376 vtkBooleanMacro(DrawGridlines, bool);
378
380
386 vtkSetMacro(DrawGridlinesOnly, bool);
387 vtkGetMacro(DrawGridlinesOnly, bool);
388 vtkBooleanMacro(DrawGridlinesOnly, bool);
390
391 vtkSetMacro(DrawGridlinesLocation, int);
392 vtkGetMacro(DrawGridlinesLocation, int);
393
395
399 vtkSetMacro(DrawInnerGridlines, bool);
400 vtkGetMacro(DrawInnerGridlines, bool);
401 vtkBooleanMacro(DrawInnerGridlines, bool);
403
405
409 vtkSetMacro(GridlineXLength, double);
410 vtkGetMacro(GridlineXLength, double);
411 vtkSetMacro(GridlineYLength, double);
412 vtkGetMacro(GridlineYLength, double);
413 vtkSetMacro(GridlineZLength, double);
414 vtkGetMacro(GridlineZLength, double);
416
418
422 vtkSetMacro(DrawGridpolys, bool);
423 vtkGetMacro(DrawGridpolys, bool);
424 vtkBooleanMacro(DrawGridpolys, bool);
426
428 {
432 };
433
435
439 vtkSetClampMacro(AxisType, int, VTK_AXIS_TYPE_X, VTK_AXIS_TYPE_Z);
440 vtkGetMacro(AxisType, int);
445
447 {
452 };
453
455
459 vtkSetMacro(Log, bool);
460 vtkGetMacro(Log, bool);
461 vtkBooleanMacro(Log, bool);
463
465
474 vtkGetMacro(AxisPosition, int);
476
481
483
487 virtual void SetCamera(vtkCamera*);
490
492
495 int RenderOpaqueGeometry(vtkViewport* viewport) override;
498 int RenderOverlay(vtkViewport* viewport) override;
501
508
514
520
522
525 void SetLabelScale(double scale);
526 void SetLabelScale(int labelIndex, double scale);
527 void SetTitleScale(double scale);
528 void SetExponentScale(double scale);
530
532
536 double GetMajorStart(int axis);
537 void SetMajorStart(int axis, double value);
538 double GetDeltaMajor(int axis);
539 void SetDeltaMajor(int axis, double value);
541
543
549 vtkSetMacro(MinorRangeStart, double);
550 vtkGetMacro(MinorRangeStart, double);
551 vtkSetMacro(MajorRangeStart, double);
552 vtkGetMacro(MajorRangeStart, double);
554
556
560 vtkSetMacro(DeltaRangeMinor, double);
561 vtkGetMacro(DeltaRangeMinor, double);
562 vtkSetMacro(DeltaRangeMajor, double);
563 vtkGetMacro(DeltaRangeMajor, double);
565
567
568 void BuildAxis(vtkViewport* viewport, bool);
569
575
580
582
588
590
596
598
604
606
612
614
618 vtkGetMacro(NumberOfLabelsBuilt, int);
620
622
626 vtkSetMacro(Use2DMode, bool);
627 vtkGetMacro(Use2DMode, bool);
629
631
635 vtkSetMacro(VerticalOffsetXTitle2D, double);
636 vtkGetMacro(VerticalOffsetXTitle2D, double);
638
640
644 vtkSetMacro(HorizontalOffsetYTitle2D, double);
645 vtkGetMacro(HorizontalOffsetYTitle2D, double);
647
649
653 vtkSetMacro(SaveTitlePosition, int);
654 vtkGetMacro(SaveTitlePosition, int);
656
658
662 vtkSetVector3Macro(AxisBaseForX, double);
663 vtkGetVector3Macro(AxisBaseForX, double);
665
667
671 vtkSetVector3Macro(AxisBaseForY, double);
672 vtkGetVector3Macro(AxisBaseForY, double);
674
676
680 vtkSetVector3Macro(AxisBaseForZ, double);
681 vtkGetVector3Macro(AxisBaseForZ, double);
683
685
689 vtkSetMacro(AxisOnOrigin, bool);
690 vtkGetMacro(AxisOnOrigin, bool);
692
694
698 vtkSetMacro(ScreenSize, double);
699 vtkGetMacro(ScreenSize, double);
701
703
707 vtkSetMacro(LabelOffset, double);
708 vtkGetMacro(LabelOffset, double);
710
712
716 vtkSetMacro(ExponentOffset, double);
717 vtkGetMacro(ExponentOffset, double);
719
721
728 vtkSetVector2Macro(TitleOffset, double);
729 vtkGetVector2Macro(TitleOffset, double);
731
732protected:
734 ~vtkAxisActor() override;
735
736private:
737 vtkAxisActor(const vtkAxisActor&) = delete;
738 void operator=(const vtkAxisActor&) = delete;
739
740 void TransformBounds(vtkViewport*, double bnds[6]);
741
742 void BuildLabels(vtkViewport*, bool);
743 void BuildLabels2D(vtkViewport*, bool);
744 void SetLabelPositions(vtkViewport*, bool);
745 void SetLabelPositions2D(vtkViewport*, bool);
746
753 void BuildTitle(bool);
754
759 void BuildExponent(bool force);
760
761 void BuildExponent2D(vtkViewport* viewport, bool force);
762
763 void BuildTitle2D(vtkViewport* viewport, bool);
764
768 void Get2DPosition(
769 vtkViewport* viewport, double multiplier, double scenepos[3], double displayPos[2]);
770
771 void SetAxisPointsAndLines();
772
773 bool BuildTickPoints(double p1[3], double p2[3], bool force);
774
775 // Build major ticks for linear scale.
776 void BuildMajorTicks(double p1[3], double p2[3], double localCoordSys[3][3]);
777
778 // Build major ticks for logarithmic scale.
779 void BuildMajorTicksLog(double p1[3], double p2[3], double localCoordSys[3][3]);
780
781 // Build minor ticks for linear scale.
782 void BuildMinorTicks(double p1[3], double p2[3], double localCoordSys[3][3]);
783
784 // Build minor ticks for logarithmic scale enabled
785 void BuildMinorTicksLog(double p1[3], double p2[3], double localCoordSys[3][3]);
786
787 void BuildAxisGridLines(double p1[3], double p2[3], double localCoordSys[3][3]);
788
789 bool TickVisibilityChanged();
790
791 vtkProperty* NewTitleProperty();
792 vtkProperty* NewLabelProperty();
793
794 bool BoundsDisplayCoordinateChanged(vtkViewport* viewport);
795
797
800 vtkProp* GetTitleActorInternal();
801 vtkProp* GetLabelActorInternal(int index);
802 vtkProp* GetExponentActorInternal();
804
814 void UpdateTitleActorProperty();
815 void UpdateLabelActorProperty(int idx);
816 void UpdateExponentActorProperty();
818
824 void GetTranslucentProps(vtkPropCollection* collection);
825
826 std::string Title;
827 std::string Exponent;
828 char* LabelFormat = nullptr;
829 double Range[2] = { 0.0, 1.0 };
830 double LastRange[2] = { -1.0, -1.0 };
831 bool UseTextActor3D = false;
832 int NumberOfLabelsBuilt = 0;
833 bool MinorTicksVisible = true;
834 bool LastMinorTicksVisible = true;
835
841 int TickLocation = VTK_TICKS_INSIDE;
842
847 int TitleAlignLocation = VTK_ALIGN_BOTTOM;
848
853 int ExponentLocation = VTK_ALIGN_POINT2;
854
855 bool DrawGridlines = false;
856 bool DrawGridlinesOnly = false;
857 bool LastDrawGridlines = false;
858 int DrawGridlinesLocation = 0; // 0: all | 1: closest | 2: furthest
859 int LastDrawGridlinesLocation = 0; // 0: all | 1: closest | 2: furthest
860 double GridlineXLength = 1.0;
861 double GridlineYLength = 1.0;
862 double GridlineZLength = 1.0;
863
864 bool DrawInnerGridlines = false;
865
866 bool DrawGridpolys = false;
867
868 bool AxisVisibility = true;
869 bool TickVisibility = true;
870 bool LastTickVisibility = true;
871 bool LabelVisibility = true;
872 bool TitleVisibility = true;
873 bool ExponentVisibility = false;
874 bool LastMajorTickPointCorrection = false;
875
876 bool Log = false;
877 int AxisType = VTK_AXIS_TYPE_X;
878 int AxisPosition = VTK_AXIS_POS_MINMIN;
879
880 // coordinate system for axisAxtor, relative to world coordinates
881 double AxisBaseForX[3] = { 1.0, 0.0, 0.0 };
882 double AxisBaseForY[3] = { 0.0, 1.0, 0.0 };
883 double AxisBaseForZ[3] = { 0.0, 0.0, 1.0 };
884
885 vtkNew<vtkCoordinate> Point1Coordinate;
886 vtkNew<vtkCoordinate> Point2Coordinate;
887
888 double MajorTickSize = 1.0;
889 double MinorTickSize = 0.5;
890
891 // For each axis (for the inner gridline generation)
892 double MajorStart[3] = { 0.0, 0.0, 0.0 };
893 double DeltaMajor[3] = { 1.0, 1.0, 1.0 };
894
895 // For the ticks, w.r.t to the set range
896 double MajorRangeStart = 0.0;
897 double MinorRangeStart = 0.0;
898
902 double DeltaRangeMinor = 1.0;
903
907 double DeltaRangeMajor = 1.0;
908
909 int LastAxisPosition = -1;
910 int LastTickLocation = -1;
911
912 vtkNew<vtkPoints> MinorTickPts;
913 vtkNew<vtkPoints> MajorTickPts;
914 vtkNew<vtkPoints> GridlinePts;
915 vtkNew<vtkPoints> InnerGridlinePts;
916 vtkNew<vtkPoints> GridpolyPts;
917
918 std::unique_ptr<vtkTextActorInterfaceInternal> TitleProp;
919 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
920
922
925 std::unique_ptr<vtkTextActorInterfaceInternal> ExponentProp;
927
928 std::vector<std::shared_ptr<vtkTextActorInterfaceInternal>> LabelProps;
929 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
930
931 // Main line axis
932 vtkNew<vtkPolyData> AxisLines;
933 vtkNew<vtkActor> AxisLinesActor;
934
935 // Ticks of the axis
936 vtkNew<vtkPolyData> AxisMajorTicks, AxisMinorTicks;
937 vtkNew<vtkActor> AxisMajorTicksActor, AxisMinorTicksActor;
938
939 vtkNew<vtkPolyData> Gridlines;
940 vtkNew<vtkActor> GridlinesActor;
941 vtkNew<vtkPolyData> InnerGridlines;
942 vtkNew<vtkActor> InnerGridlinesActor;
943 vtkNew<vtkPolyData> Gridpolys;
944 vtkNew<vtkActor> GridpolysActor;
945
946 vtkSmartPointer<vtkCamera> Camera;
947 vtkTimeStamp BuildTime;
948 vtkTimeStamp BuildTickPointsTime;
949 vtkTimeStamp BoundsTime;
950 vtkTimeStamp LabelBuildTime;
951 vtkTimeStamp TitleTextTime;
952 vtkTimeStamp ExponentTextTime;
953
954 bool AxisOnOrigin = false;
955
956 bool AxisHasZeroLength = false;
957
961 bool Use2DMode = false;
962
967 double VerticalOffsetXTitle2D = -40;
968
973 double HorizontalOffsetYTitle2D = -50;
974
981 int SaveTitlePosition = 0;
982
986 double TitleConstantPosition[2] = { 0.0, 0.0 };
987
991 bool NeedBuild2D = false;
992
993 double LastMinDisplayCoordinate[3] = { 0.0, 0.0, 0.0 };
994 double LastMaxDisplayCoordinate[3] = { 0.0, 0.0, 0.0 };
995 double TickVector[3] = { 0.0, 0.0, 0.0 };
996
1000 double ScreenSize = 10.0;
1001
1003
1006 double LabelOffset = 30.0;
1007 double TitleOffset[2] = { 20.0, 20.0 };
1008 double ExponentOffset = 20.0;
1010};
1011
1012VTK_ABI_NAMESPACE_END
1013#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:42
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems
a simple class to control print indentation
Definition vtkIndent.h:29
represent and manipulate 3D points
Definition vtkPoints.h:31
map vtkPolyData to graphics primitives
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
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
Definition vtkProperty.h:60
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:47
window superclass for vtkRenderWindow
Definition vtkWindow.h:42
int vtkTypeBool
Definition vtkABI.h:64
vtkTimeStamp BuildTime
vtkCamera * Camera
#define VTK_SIZEHINT(...)
#define VTK_MARSHALAUTO