VTK  9.4.20250303
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
95VTK_ABI_NAMESPACE_BEGIN
96class vtkPoints;
97class vtkPolyData;
99class vtkTextMapper;
100class vtkTextProperty;
101
102class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor2D : public vtkActor2D
103{
104public:
106 void PrintSelf(ostream& os, vtkIndent indent) override;
107
112
114
119 virtual void SetPoint1(double x[2]) { this->SetPosition(x); }
120 virtual void SetPoint1(double x, double y) { this->SetPosition(x, y); }
121 virtual double* GetPoint1() { return this->GetPosition(); }
123
125
132 virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }
133 virtual void SetPoint2(double x, double y) { this->SetPosition2(x, y); }
134 virtual double* GetPoint2() { return this->GetPosition2(); }
136
138
144 vtkSetVector2Macro(Range, double);
145 vtkGetVectorMacro(Range, double, 2);
147
149
156 vtkSetMacro(RulerMode, vtkTypeBool);
157 vtkGetMacro(RulerMode, vtkTypeBool);
158 vtkBooleanMacro(RulerMode, vtkTypeBool);
160
162
167 vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
168 vtkGetMacro(RulerDistance, double);
170
172 {
173 VTK_MAX_LABELS = 25
174 };
175
177
182 vtkSetClampMacro(NumberOfLabels, int, 2, VTK_MAX_LABELS);
183 vtkGetMacro(NumberOfLabels, int);
185
187
191 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
192 vtkGetMacro(Precision, int);
194
196
203 vtkSetClampMacro(Notation, int, 0, 2);
204 vtkGetMacro(Notation, int);
206
208
212 vtkSetStringMacro(LabelFormat);
213 vtkGetStringMacro(LabelFormat);
215
217
232 vtkSetMacro(SnapLabelsToGrid, bool);
233 vtkGetMacro(SnapLabelsToGrid, bool);
234 vtkBooleanMacro(SnapLabelsToGrid, bool);
236
238
253 vtkSetMacro(AdjustLabels, vtkTypeBool);
254 vtkGetMacro(AdjustLabels, vtkTypeBool);
255 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
257
259
264 vtkSetMacro(SkipFirstTick, bool);
265 vtkGetMacro(SkipFirstTick, bool);
266 vtkBooleanMacro(SkipFirstTick, bool);
268
270
274 virtual double* GetAdjustedRange()
275 {
276 this->UpdateAdjustedRange();
277 return this->AdjustedRange;
278 }
279 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
280 {
281 this->UpdateAdjustedRange();
282 _arg1 = this->AdjustedRange[0];
283 _arg2 = this->AdjustedRange[1];
284 }
285 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
287
292 {
293 this->UpdateAdjustedRange();
294 return this->AdjustedNumberOfLabels;
295 }
296
301
303
306 vtkSetStringMacro(Title);
307 vtkGetStringMacro(Title);
309
311
315 vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
317
319
323 vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
325
327
331 vtkSetClampMacro(TickLength, int, 0, 100);
332 vtkGetMacro(TickLength, int);
334
336
340 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
341 vtkGetMacro(NumberOfMinorTicks, int);
343
345
349 vtkSetClampMacro(MinorTickLength, int, 0, 100);
350 vtkGetMacro(MinorTickLength, int);
352
354
359 vtkSetClampMacro(TickOffset, int, 0, 100);
360 vtkGetMacro(TickOffset, int);
362
364
367 vtkSetMacro(AxisVisibility, vtkTypeBool);
368 vtkGetMacro(AxisVisibility, vtkTypeBool);
369 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
371
373
376 vtkSetMacro(TickVisibility, vtkTypeBool);
377 vtkGetMacro(TickVisibility, vtkTypeBool);
378 vtkBooleanMacro(TickVisibility, vtkTypeBool);
380
382
385 vtkSetMacro(LabelVisibility, vtkTypeBool);
386 vtkGetMacro(LabelVisibility, vtkTypeBool);
387 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
389
391
394 vtkSetMacro(TitleVisibility, vtkTypeBool);
395 vtkGetMacro(TitleVisibility, vtkTypeBool);
396 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
398
400
404 vtkSetMacro(TitlePosition, double);
405 vtkGetMacro(TitlePosition, double);
407
409
414 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
415 vtkGetMacro(FontFactor, double);
417
419
423 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
424 vtkGetMacro(LabelFactor, double);
426
434
436
439 int RenderOverlay(vtkViewport* viewport) override;
440 int RenderOpaqueGeometry(vtkViewport* viewport) override;
443
448
455
469 static void ComputeRange(
470 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
471
480 static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
481 int nbOfMappers, int* targetSize, double factor, int* stringSize);
482
484
488 vtkSetMacro(SizeFontRelativeToAxis, vtkTypeBool);
489 vtkGetMacro(SizeFontRelativeToAxis, vtkTypeBool);
490 vtkBooleanMacro(SizeFontRelativeToAxis, vtkTypeBool);
492
494
499 vtkSetMacro(UseFontSizeFromProperty, vtkTypeBool);
500 vtkGetMacro(UseFontSizeFromProperty, vtkTypeBool);
501 vtkBooleanMacro(UseFontSizeFromProperty, vtkTypeBool);
503
507 void ShallowCopy(vtkProp* prop) override;
508
509protected:
511 ~vtkAxisActor2D() override;
512
515
516 char* Title;
518 double Range[2] = { 0., 1. };
519 double TitlePosition = 0.5;
520 vtkTypeBool RulerMode = 0;
521 double RulerDistance = 1.;
522 int NumberOfLabels = 5;
523 vtkTypeBool AdjustLabels = 1;
524 double FontFactor = 1.;
525 double LabelFactor = 0.75;
526 int TickLength = 5;
527 int MinorTickLength = 3;
528 int TickOffset = 2;
529 int NumberOfMinorTicks = 0;
530
531 double AdjustedRange[2];
532 int AdjustedNumberOfLabels = 5;
533 int NumberOfLabelsBuilt = 0;
535
536 int Notation = 0;
537 int Precision = 2;
538
539 vtkTypeBool AxisVisibility = 1;
540 vtkTypeBool TickVisibility = 1;
541 vtkTypeBool LabelVisibility = 1;
542 vtkTypeBool TitleVisibility = 1;
543
544 int LastPosition[2] = { 0, 0 };
545 int LastPosition2[2] = { 0, 0 };
546
547 int LastSize[2] = { 0, 0 };
548 int LastMaxLabelSize[2] = { 0, 0 };
549
550 int SizeFontRelativeToAxis = 0;
551 vtkTypeBool UseFontSizeFromProperty = 0;
552
553 virtual void BuildAxis(vtkViewport* viewport);
554 static double ComputeStringOffset(double width, double height, double theta);
555
559 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
560 int offset, vtkActor2D* textActor);
561
569 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
570 int offset, int finalPos[2]);
571
572 virtual void UpdateAdjustedRange();
573
576
579
583
586
587private:
588 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
589 void operator=(const vtkAxisActor2D&) = delete;
590
594 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
595
599 bool ShouldRebuild(vtkViewport* viewport);
600
608 void UpdateTicksValueAndPosition(vtkViewport* viewport);
609
613 void BuildTicksPolyData(vtkViewport* viewport);
614
618 void BuildLabels(vtkViewport* viewport);
619
623 void BuildTitle(vtkViewport* viewport);
624
628 double GetAxisAngle(vtkViewport* viewport);
629
633 void UpdateCachedInformations(vtkViewport* viewport);
634
638 double GetViewportRulerDistance(vtkViewport* viewport);
639
643 double GetViewportAxisLength(vtkViewport* viewport);
644
649 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
650
651 // tick position in axis, normalized on axis length.
652 std::vector<double> NormalizedTickPositions;
653 std::vector<double> TickValues;
654
655 bool SnapLabelsToGrid = false;
656
657 bool SkipFirstTick = false;
658};
659
660VTK_ABI_NAMESPACE_END
661#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 void SetTitleTextProperty(vtkTextProperty *p)
Set/Get the title text property.
vtkActor2D ** LabelActors
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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]).
vtkTextProperty * TitleTextProperty
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.
vtkTextMapper ** LabelMappers
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 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 void SetLabelTextProperty(vtkTextProperty *p)
Set/Get the labels text property.
virtual double * GetPoint2()
Specify the position of the second point defining the axis.
vtkTextProperty * LabelTextProperty
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.
vtkActor2D * TitleActor
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:66
2D text annotation
represent text properties.
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:65
window superclass for vtkRenderWindow
Definition vtkWindow.h:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_INT_MAX
Definition vtkType.h:161
#define VTK_FLOAT_MAX
Definition vtkType.h:169
#define VTK_MARSHALAUTO