VTK  9.5.20251030
vtkAxisActor2D.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
86#ifndef vtkAxisActor2D_h
87#define vtkAxisActor2D_h
88
89#include "vtkActor2D.h"
90#include "vtkRenderingAnnotationModule.h" // For export macro
91#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
92
93#include "vtkNew.h" // for vtkNew
94#include "vtkSmartPointer.h" // for vtkSmartPointer
95
96VTK_ABI_NAMESPACE_BEGIN
97class vtkPoints;
98class vtkPolyData;
100class vtkTextMapper;
101class vtkTextProperty;
102
103class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor2D : public vtkActor2D
104{
105public:
107 void PrintSelf(ostream& os, vtkIndent indent) override;
108
113
115
120 virtual void SetPoint1(double x[2]) { this->SetPosition(x); }
121 virtual void SetPoint1(double x, double y) { this->SetPosition(x, y); }
122 virtual double* GetPoint1() { return this->GetPosition(); }
124
126
133 virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }
134 virtual void SetPoint2(double x, double y) { this->SetPosition2(x, y); }
135 virtual double* GetPoint2() { return this->GetPosition2(); }
137
139
145 vtkSetVector2Macro(Range, double);
146 vtkGetVectorMacro(Range, double, 2);
148
150
157 vtkSetMacro(RulerMode, vtkTypeBool);
158 vtkGetMacro(RulerMode, vtkTypeBool);
159 vtkBooleanMacro(RulerMode, vtkTypeBool);
161
163
168 vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
169 vtkGetMacro(RulerDistance, double);
171
173 {
174 VTK_MAX_LABELS VTK_DEPRECATED_IN_9_6_0(
175 "VTK_MAX_LABELS has been removed. Labels are now dynamically allocated. Do not use.") = 25
176 };
177
179
184 vtkSetMacro(NumberOfLabels, int);
185 vtkGetMacro(NumberOfLabels, int);
187
189
193 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
194 vtkGetMacro(Precision, int);
196
198
205 vtkSetClampMacro(Notation, int, 0, 2);
206 vtkGetMacro(Notation, int);
208
210
214 void SetLabelFormat(const char* format);
215 vtkGetStringMacro(LabelFormat);
217
219
234 vtkSetMacro(SnapLabelsToGrid, bool);
235 vtkGetMacro(SnapLabelsToGrid, bool);
236 vtkBooleanMacro(SnapLabelsToGrid, bool);
238
240
255 vtkSetMacro(AdjustLabels, vtkTypeBool);
256 vtkGetMacro(AdjustLabels, vtkTypeBool);
257 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
259
261
266 vtkSetMacro(SkipFirstTick, bool);
267 vtkGetMacro(SkipFirstTick, bool);
268 vtkBooleanMacro(SkipFirstTick, bool);
270
272
276 virtual double* GetAdjustedRange()
277 {
278 this->UpdateAdjustedRange();
279 return this->AdjustedRange;
280 }
281 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
282 {
283 this->UpdateAdjustedRange();
284 _arg1 = this->AdjustedRange[0];
285 _arg2 = this->AdjustedRange[1];
286 }
287 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
289
294 {
295 this->UpdateAdjustedRange();
296 return this->AdjustedNumberOfLabels;
297 }
298
303
305
308 vtkSetStringMacro(Title);
309 vtkGetStringMacro(Title);
311
313
319
321
327
329
333 vtkSetClampMacro(TickLength, int, 0, 100);
334 vtkGetMacro(TickLength, int);
336
338
342 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
343 vtkGetMacro(NumberOfMinorTicks, int);
345
347
351 vtkSetClampMacro(MinorTickLength, int, 0, 100);
352 vtkGetMacro(MinorTickLength, int);
354
356
361 vtkSetClampMacro(TickOffset, int, 0, 100);
362 vtkGetMacro(TickOffset, int);
364
366
369 vtkSetMacro(AxisVisibility, vtkTypeBool);
370 vtkGetMacro(AxisVisibility, vtkTypeBool);
371 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
373
375
378 vtkSetMacro(TickVisibility, vtkTypeBool);
379 vtkGetMacro(TickVisibility, vtkTypeBool);
380 vtkBooleanMacro(TickVisibility, vtkTypeBool);
382
384
387 vtkSetMacro(LabelVisibility, vtkTypeBool);
388 vtkGetMacro(LabelVisibility, vtkTypeBool);
389 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
391
393
396 vtkSetMacro(TitleVisibility, vtkTypeBool);
397 vtkGetMacro(TitleVisibility, vtkTypeBool);
398 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
400
402
406 vtkSetMacro(TitlePosition, double);
407 vtkGetMacro(TitlePosition, double);
409
411
416 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
417 vtkGetMacro(FontFactor, double);
419
421
425 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
426 vtkGetMacro(LabelFactor, double);
428
432 virtual std::vector<vtkSmartPointer<vtkTextMapper>> GetLabelMappers()
433 {
434 return this->LabelMappers;
435 }
436
444
446
449 int RenderOverlay(vtkViewport* viewport) override;
450 int RenderOpaqueGeometry(vtkViewport* viewport) override;
453
458
465
479 static void ComputeRange(
480 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
481
490 static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
491 int nbOfMappers, int* targetSize, double factor, int* stringSize);
492
494
498 vtkSetMacro(SizeFontRelativeToAxis, vtkTypeBool);
499 vtkGetMacro(SizeFontRelativeToAxis, vtkTypeBool);
500 vtkBooleanMacro(SizeFontRelativeToAxis, vtkTypeBool);
502
504
509 vtkSetMacro(UseFontSizeFromProperty, vtkTypeBool);
510 vtkGetMacro(UseFontSizeFromProperty, vtkTypeBool);
511 vtkBooleanMacro(UseFontSizeFromProperty, vtkTypeBool);
513
517 void ShallowCopy(vtkProp* prop) override;
518
519protected:
521 ~vtkAxisActor2D() override;
522
523 char* Title;
525 double Range[2] = { 0., 1. };
526 double TitlePosition = 0.5;
527 vtkTypeBool RulerMode = 0;
528 double RulerDistance = 1.;
529 int NumberOfLabels = 5;
530 vtkTypeBool AdjustLabels = 1;
531 double FontFactor = 1.;
532 double LabelFactor = 0.75;
533 int TickLength = 5;
534 int MinorTickLength = 3;
535 int TickOffset = 2;
536 int NumberOfMinorTicks = 0;
537
538 double AdjustedRange[2];
539 int AdjustedNumberOfLabels = 5;
540 int NumberOfLabelsBuilt = 0;
542
543 int Notation = 0;
544 int Precision = 2;
545
546 vtkTypeBool AxisVisibility = 1;
547 vtkTypeBool TickVisibility = 1;
548 vtkTypeBool LabelVisibility = 1;
549 vtkTypeBool TitleVisibility = 1;
550
551 int LastPosition[2] = { 0, 0 };
552 int LastPosition2[2] = { 0, 0 };
553
554 int LastSize[2] = { 0, 0 };
555 int LastMaxLabelSize[2] = { 0, 0 };
556
557 int SizeFontRelativeToAxis = 0;
558 vtkTypeBool UseFontSizeFromProperty = 0;
559
560 virtual void BuildAxis(vtkViewport* viewport);
561 static double ComputeStringOffset(double width, double height, double theta);
562
566 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
567 int offset, vtkActor2D* textActor);
568
576 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
577 int offset, int finalPos[2]);
578
579 virtual void UpdateAdjustedRange();
580
583
587
590
591private:
592 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
593 void operator=(const vtkAxisActor2D&) = delete;
594
598 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
599
603 bool ShouldRebuild(vtkViewport* viewport);
604
612 void UpdateTicksValueAndPosition(vtkViewport* viewport);
613
617 void BuildTicksPolyData(vtkViewport* viewport);
618
622 void BuildLabels(vtkViewport* viewport);
623
627 void BuildTitle(vtkViewport* viewport);
628
632 double GetAxisAngle(vtkViewport* viewport);
633
637 void UpdateCachedInformations(vtkViewport* viewport);
638
642 double GetViewportRulerDistance(vtkViewport* viewport);
643
647 double GetViewportAxisLength(vtkViewport* viewport);
648
653 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
654
655 // tick position in axis, normalized on axis length.
656 std::vector<double> NormalizedTickPositions;
657 std::vector<double> TickValues;
658
659 bool SnapLabelsToGrid = false;
660
661 bool SkipFirstTick = false;
662
663 std::vector<vtkSmartPointer<vtkTextMapper>> LabelMappers;
664 std::vector<vtkSmartPointer<vtkActor2D>> LabelActors;
665
666 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
667 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
668};
669
670VTK_ABI_NAMESPACE_END
671#endif
a actor that draws 2D data
Definition vtkActor2D.h:145
virtual vtkCoordinate * GetPositionCoordinate()
Get the PositionCoordinate instance of vtkCoordinate.
virtual void SetPosition2(float x[2])
Access the Position2 instance variable.
virtual void SetPosition(float x[2])
Get the PositionCoordinate instance of vtkCoordinate.
virtual vtkCoordinate * GetPosition2Coordinate()
Access the Position2 instance variable.
virtual float * GetPosition2()
Access the Position2 instance variable.
virtual float * GetPosition()
Get the PositionCoordinate instance of vtkCoordinate.
Create an axis with tick marks and labels.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Draw the axis.
virtual void SetPoint1(double x[2])
Specify the position of the first point defining the axis.
virtual double * GetAdjustedRange()
Get the axis range adjusted for nice tick values.
vtkTimeStamp BuildTime
static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight, int offset, vtkActor2D *textActor)
Set the actor position according to the given parameters.
vtkNew< vtkPoints > TicksStartPos
vtkTextMapper * TitleMapper
vtkNew< vtkPolyDataMapper2D > AxisMapper
vtkTypeBool HasTranslucentPolygonalGeometry() override
Does this prop have some translucent polygonal geometry?
virtual std::vector< vtkSmartPointer< vtkTextMapper > > GetLabelMappers()
Get the label mappers.
virtual void SetTitleTextProperty(vtkTextProperty *)
Set/Get the title text property.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual vtkTextProperty * GetLabelTextProperty()
Set/Get the labels text property.
vtkNew< vtkActor2D > AxisActor
vtkNew< vtkPolyData > Axis
virtual void BuildAxis(vtkViewport *viewport)
static int SetMultipleFontSize(vtkViewport *viewport, vtkTextMapper **textMappers, int nbOfMappers, int *targetSize, double factor, int *stringSize)
General method to computes font size from a representative size on the viewport (given by size[2]).
virtual void SetPoint1(double x, double y)
Specify the position of the first point defining the axis.
int UpdateGeometryAndRenderOpaqueGeometry(vtkViewport *viewport, bool render)
Rebuild the geometry using the provided viewport, and trigger opaque geometry render only if render p...
static void ComputeRange(double inRange[2], double outRange[2], int inNumTicks, int &outNumTicks, double &interval)
This method computes the range of the axis given an input range.
void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight, int offset, int finalPos[2])
Get the shifted position.
virtual vtkCoordinate * GetPoint2Coordinate()
Specify the position of the second point defining the axis.
virtual vtkCoordinate * GetPoint1Coordinate()
Specify the position of the first point defining the axis.
int RenderOpaqueGeometry(vtkViewport *viewport) override
Draw the axis.
vtkTimeStamp AdjustedRangeBuildTime
virtual void GetAdjustedRange(double _arg[2])
Get the axis range adjusted for nice tick values.
vtkPoints * GetTickPositions()
Return the positions of ticks along the axis.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
static vtkAxisActor2D * New()
Instantiate object.
static double ComputeStringOffset(double width, double height, double theta)
int RenderOverlay(vtkViewport *viewport) override
Draw the axis.
virtual double * GetPoint1()
Specify the position of the first point defining the axis.
void SetLabelFormat(const char *format)
Set/Get the std::format style format with which to print the labels on the scalar bar.
void ShallowCopy(vtkProp *prop) override
Shallow copy of an axis actor.
virtual void SetPoint2(double x[2])
Specify the position of the second point defining the axis.
virtual double * GetPoint2()
Specify the position of the second point defining the axis.
virtual int GetAdjustedNumberOfLabels()
Get the number of labels.
virtual void GetAdjustedRange(double &_arg1, double &_arg2)
Get the axis range adjusted for nice tick values.
~vtkAxisActor2D() override
virtual void SetPoint2(double x, double y)
Specify the position of the second point defining the axis.
virtual void SetLabelTextProperty(vtkTextProperty *)
Set/Get the labels text property.
vtkActor2D * TitleActor
virtual vtkTextProperty * GetTitleTextProperty()
Set/Get the title text property.
virtual void UpdateAdjustedRange()
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
represent and manipulate 3D points
Definition vtkPoints.h:139
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:69
Hold a reference to a vtkObjectBase instance.
2D text annotation
represent text properties.
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:66
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_INT_MAX
Definition vtkType.h:196
#define VTK_FLOAT_MAX
Definition vtkType.h:204
#define VTK_MARSHALAUTO