VTK  9.7.20260904
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
85
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
178 vtkSetMacro(NumberOfLabels, int);
179 vtkGetMacro(NumberOfLabels, int);
181
183
187 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
188 vtkGetMacro(Precision, int);
190
192
199 vtkSetClampMacro(Notation, int, 0, 2);
200 vtkGetMacro(Notation, int);
202
204
208 vtkSetStringMacro(LabelFormat);
209 vtkGetStringMacro(LabelFormat);
211
213
228 vtkSetMacro(SnapLabelsToGrid, bool);
229 vtkGetMacro(SnapLabelsToGrid, bool);
230 vtkBooleanMacro(SnapLabelsToGrid, bool);
232
234
251 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
253
255
260 vtkSetMacro(SkipFirstTick, bool);
261 vtkGetMacro(SkipFirstTick, bool);
262 vtkBooleanMacro(SkipFirstTick, bool);
264
266
270 virtual double* GetAdjustedRange()
271 {
272 this->UpdateAdjustedRange();
273 return this->AdjustedRange;
274 }
275 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
276 {
277 this->UpdateAdjustedRange();
278 _arg1 = this->AdjustedRange[0];
279 _arg2 = this->AdjustedRange[1];
280 }
281 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
283
288 {
289 this->UpdateAdjustedRange();
290 return this->AdjustedNumberOfLabels;
291 }
292
297
299
302 vtkSetStringMacro(Title);
303 vtkGetStringMacro(Title);
305
307
313
315
321
323
327 vtkSetClampMacro(TickLength, int, 0, 100);
328 vtkGetMacro(TickLength, int);
330
332
336 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
337 vtkGetMacro(NumberOfMinorTicks, int);
339
341
345 vtkSetClampMacro(MinorTickLength, int, 0, 100);
346 vtkGetMacro(MinorTickLength, int);
348
350
355 vtkSetClampMacro(TickOffset, int, 0, 100);
356 vtkGetMacro(TickOffset, int);
358
360
365 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
367
369
374 vtkBooleanMacro(TickVisibility, vtkTypeBool);
376
378
383 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
385
387
392 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
394
396
400 vtkSetMacro(TitlePosition, double);
401 vtkGetMacro(TitlePosition, double);
403
405
410 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
411 vtkGetMacro(FontFactor, double);
413
415
419 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
420 vtkGetMacro(LabelFactor, double);
422
426 virtual std::vector<vtkSmartPointer<vtkTextMapper>> GetLabelMappers()
427 {
428 return this->LabelMappers;
429 }
430
434 virtual std::vector<vtkSmartPointer<vtkActor2D>> GetLabelActors() { return this->LabelActors; }
435
443
445
448 int RenderOverlay(vtkViewport* viewport) override;
449 int RenderOpaqueGeometry(vtkViewport* viewport) override;
452
457
464
478 static void ComputeRange(
479 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
480
482
490
492
501
505 void ShallowCopy(vtkProp* prop) override;
506
507protected:
509 ~vtkAxisActor2D() override;
510
511 char* Title;
513 double Range[2] = { 0., 1. };
514 double TitlePosition = 0.5;
516 double RulerDistance = 1.;
519 double FontFactor = 1.;
520 double LabelFactor = 0.75;
521 int TickLength = 5;
523 int TickOffset = 2;
525
526 double AdjustedRange[2];
530
531 int Notation = 0;
532 int Precision = 2;
533
538
539 int LastPosition[2] = { 0, 0 };
540 int LastPosition2[2] = { 0, 0 };
541
542 int LastSize[2] = { 0, 0 };
543 int LastMaxLabelSize[2] = { 0, 0 };
544
547
548 virtual void BuildAxis(vtkViewport* viewport);
549 static double ComputeStringOffset(double width, double height, double theta);
550
554 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
555 int offset, vtkActor2D* textActor);
556
564 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
565 int offset, int finalPos[2]);
566
567 virtual void UpdateAdjustedRange();
568
571
575
578
579private:
580 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
581 void operator=(const vtkAxisActor2D&) = delete;
582
586 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
587
591 bool ShouldRebuild(vtkViewport* viewport);
592
600 void UpdateTicksValueAndPosition(vtkViewport* viewport);
601
605 void BuildTicksPolyData(vtkViewport* viewport);
606
610 void BuildLabels(vtkViewport* viewport);
611
615 void BuildTitle(vtkViewport* viewport);
616
620 double GetAxisAngle(vtkViewport* viewport);
621
625 void UpdateCachedInformations(vtkViewport* viewport);
626
630 double GetViewportRulerDistance(vtkViewport* viewport);
631
635 double GetViewportAxisLength(vtkViewport* viewport);
636
641 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
642
643 // tick position in axis, normalized on axis length.
644 std::vector<double> NormalizedTickPositions;
645 std::vector<double> TickValues;
646
647 bool SnapLabelsToGrid = false;
648
649 bool SkipFirstTick = false;
650
651 std::vector<vtkSmartPointer<vtkTextMapper>> LabelMappers;
652 std::vector<vtkSmartPointer<vtkActor2D>> LabelActors;
653
654 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
655 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
656};
657
658VTK_ABI_NAMESPACE_END
659#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?
virtual std::vector< vtkSmartPointer< vtkActor2D > > GetLabelActors()
Get the label actors.
virtual std::vector< vtkSmartPointer< vtkTextMapper > > GetLabelMappers()
Get the label mappers.
vtkTypeBool TickVisibility
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
vtkTypeBool LabelVisibility
virtual void BuildAxis(vtkViewport *viewport)
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.
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 double * GetPoint2()
Specify the position of the second point defining the axis.
vtkTypeBool RulerMode
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
vtkTypeBool TitleVisibility
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:168
represent and manipulate 3D points
Definition vtkPoints.h:140
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
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:62
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_INT_MAX
Definition vtkType.h:192
#define VTK_FLOAT_MAX
Definition vtkType.h:200
#define VTK_MARSHALAUTO