VTK  9.4.20251007
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
66
67#ifndef vtkAxisActor2D_h
68#define vtkAxisActor2D_h
69
70#include "vtkActor2D.h"
71#include "vtkRenderingAnnotationModule.h" // For export macro
72#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
73
74#include "vtkNew.h" // for vtkNew
75
76VTK_ABI_NAMESPACE_BEGIN
77class vtkPoints;
78class vtkPolyData;
80class vtkTextMapper;
81class vtkTextProperty;
82
83class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor2D : public vtkActor2D
84{
85public:
86 vtkTypeMacro(vtkAxisActor2D, vtkActor2D);
87 void PrintSelf(ostream& os, vtkIndent indent) override;
88
93
95
100 virtual void SetPoint1(double x[2]) { this->SetPosition(x); }
101 virtual void SetPoint1(double x, double y) { this->SetPosition(x, y); }
102 virtual double* GetPoint1() { return this->GetPosition(); }
104
106
113 virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }
114 virtual void SetPoint2(double x, double y) { this->SetPosition2(x, y); }
115 virtual double* GetPoint2() { return this->GetPosition2(); }
117
119
125 vtkSetVector2Macro(Range, double);
126 vtkGetVectorMacro(Range, double, 2);
128
130
137 vtkSetMacro(RulerMode, vtkTypeBool);
138 vtkGetMacro(RulerMode, vtkTypeBool);
139 vtkBooleanMacro(RulerMode, vtkTypeBool);
141
143
148 vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
149 vtkGetMacro(RulerDistance, double);
151
153 {
155 };
156
158
163 vtkSetClampMacro(NumberOfLabels, int, 2, VTK_MAX_LABELS);
164 vtkGetMacro(NumberOfLabels, int);
166
168
172 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
173 vtkGetMacro(Precision, int);
175
177
184 vtkSetClampMacro(Notation, int, 0, 2);
185 vtkGetMacro(Notation, int);
187
189
193 vtkSetStringMacro(LabelFormat);
194 vtkGetStringMacro(LabelFormat);
196
198
213 vtkSetMacro(SnapLabelsToGrid, bool);
214 vtkGetMacro(SnapLabelsToGrid, bool);
215 vtkBooleanMacro(SnapLabelsToGrid, bool);
217
219
236 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
238
240
245 vtkSetMacro(SkipFirstTick, bool);
246 vtkGetMacro(SkipFirstTick, bool);
247 vtkBooleanMacro(SkipFirstTick, bool);
249
251
255 virtual double* GetAdjustedRange()
256 {
257 this->UpdateAdjustedRange();
258 return this->AdjustedRange;
259 }
260 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
261 {
262 this->UpdateAdjustedRange();
263 _arg1 = this->AdjustedRange[0];
264 _arg2 = this->AdjustedRange[1];
265 }
266 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
268
273 {
274 this->UpdateAdjustedRange();
275 return this->AdjustedNumberOfLabels;
276 }
277
282
284
287 vtkSetStringMacro(Title);
288 vtkGetStringMacro(Title);
290
292
298
300
306
308
312 vtkSetClampMacro(TickLength, int, 0, 100);
313 vtkGetMacro(TickLength, int);
315
317
321 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
322 vtkGetMacro(NumberOfMinorTicks, int);
324
326
330 vtkSetClampMacro(MinorTickLength, int, 0, 100);
331 vtkGetMacro(MinorTickLength, int);
333
335
340 vtkSetClampMacro(TickOffset, int, 0, 100);
341 vtkGetMacro(TickOffset, int);
343
345
350 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
352
354
359 vtkBooleanMacro(TickVisibility, vtkTypeBool);
361
363
368 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
370
372
377 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
379
381
385 vtkSetMacro(TitlePosition, double);
386 vtkGetMacro(TitlePosition, double);
388
390
395 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
396 vtkGetMacro(FontFactor, double);
398
400
404 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
405 vtkGetMacro(LabelFactor, double);
407
415
417
420 int RenderOverlay(vtkViewport* viewport) override;
421 int RenderOpaqueGeometry(vtkViewport* viewport) override;
424
429
436
450 static void ComputeRange(
451 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
452
461 static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
462 int nbOfMappers, int* targetSize, double factor, int* stringSize);
463
465
473
475
484
488 void ShallowCopy(vtkProp* prop) override;
489
490protected:
492 ~vtkAxisActor2D() override;
493
496
497 char* Title;
499 double Range[2] = { 0., 1. };
500 double TitlePosition = 0.5;
502 double RulerDistance = 1.;
505 double FontFactor = 1.;
506 double LabelFactor = 0.75;
507 int TickLength = 5;
509 int TickOffset = 2;
511
512 double AdjustedRange[2];
516
517 int Notation = 0;
518 int Precision = 2;
519
524
525 int LastPosition[2] = { 0, 0 };
526 int LastPosition2[2] = { 0, 0 };
527
528 int LastSize[2] = { 0, 0 };
529 int LastMaxLabelSize[2] = { 0, 0 };
530
533
534 virtual void BuildAxis(vtkViewport* viewport);
535 static double ComputeStringOffset(double width, double height, double theta);
536
540 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
541 int offset, vtkActor2D* textActor);
542
550 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
551 int offset, int finalPos[2]);
552
553 virtual void UpdateAdjustedRange();
554
557
560
564
567
568private:
569 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
570 void operator=(const vtkAxisActor2D&) = delete;
571
575 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
576
580 bool ShouldRebuild(vtkViewport* viewport);
581
589 void UpdateTicksValueAndPosition(vtkViewport* viewport);
590
594 void BuildTicksPolyData(vtkViewport* viewport);
595
599 void BuildLabels(vtkViewport* viewport);
600
604 void BuildTitle(vtkViewport* viewport);
605
609 double GetAxisAngle(vtkViewport* viewport);
610
614 void UpdateCachedInformations(vtkViewport* viewport);
615
619 double GetViewportRulerDistance(vtkViewport* viewport);
620
624 double GetViewportAxisLength(vtkViewport* viewport);
625
630 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
631
632 // tick position in axis, normalized on axis length.
633 std::vector<double> NormalizedTickPositions;
634 std::vector<double> TickValues;
635
636 bool SnapLabelsToGrid = false;
637
638 bool SkipFirstTick = false;
639};
640
641VTK_ABI_NAMESPACE_END
642#endif
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.
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
double AdjustedRange[2]
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.
vtkTypeBool AdjustLabels
vtkNew< vtkPoints > TicksStartPos
vtkTextMapper * TitleMapper
vtkNew< vtkPolyDataMapper2D > AxisMapper
vtkTypeBool HasTranslucentPolygonalGeometry() override
Does this prop have some translucent polygonal geometry?
vtkTypeBool TickVisibility
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
vtkTypeBool LabelVisibility
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.
vtkTypeBool UseFontSizeFromProperty
vtkTypeBool AxisVisibility
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.
vtkTypeBool RulerMode
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
vtkTypeBool TitleVisibility
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:29
Allocate and hold a VTK object.
Definition vtkNew.h:58
represent and manipulate 3D points
Definition vtkPoints.h:30
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
2D text annotation
represent text properties.
record modification and/or execution time
abstract specification for Viewports
Definition vtkViewport.h:46
window superclass for vtkRenderWindow
Definition vtkWindow.h:29
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_INT_MAX
Definition vtkType.h:144
#define VTK_FLOAT_MAX
Definition vtkType.h:152
#define VTK_MARSHALAUTO