VTK  9.7.20260805
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#include "vtkSmartPointer.h" // for vtkSmartPointer
76
77VTK_ABI_NAMESPACE_BEGIN
78class vtkPoints;
79class vtkPolyData;
81class vtkTextMapper;
82class vtkTextProperty;
83
84class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor2D : public vtkActor2D
85{
86public:
87 vtkTypeMacro(vtkAxisActor2D, vtkActor2D);
88 void PrintSelf(ostream& os, vtkIndent indent) override;
89
94
96
101 virtual void SetPoint1(double x[2]) { this->SetPosition(x); }
102 virtual void SetPoint1(double x, double y) { this->SetPosition(x, y); }
103 virtual double* GetPoint1() { return this->GetPosition(); }
105
107
114 virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }
115 virtual void SetPoint2(double x, double y) { this->SetPosition2(x, y); }
116 virtual double* GetPoint2() { return this->GetPosition2(); }
118
120
126 vtkSetVector2Macro(Range, double);
127 vtkGetVectorMacro(Range, double, 2);
129
131
138 vtkSetMacro(RulerMode, vtkTypeBool);
139 vtkGetMacro(RulerMode, vtkTypeBool);
140 vtkBooleanMacro(RulerMode, vtkTypeBool);
142
144
149 vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
150 vtkGetMacro(RulerDistance, double);
152
154
159 vtkSetMacro(NumberOfLabels, int);
160 vtkGetMacro(NumberOfLabels, int);
162
164
168 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
169 vtkGetMacro(Precision, int);
171
173
180 vtkSetClampMacro(Notation, int, 0, 2);
181 vtkGetMacro(Notation, int);
183
185
189 vtkSetStringMacro(LabelFormat);
190 vtkGetStringMacro(LabelFormat);
192
194
209 vtkSetMacro(SnapLabelsToGrid, bool);
210 vtkGetMacro(SnapLabelsToGrid, bool);
211 vtkBooleanMacro(SnapLabelsToGrid, bool);
213
215
232 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
234
236
241 vtkSetMacro(SkipFirstTick, bool);
242 vtkGetMacro(SkipFirstTick, bool);
243 vtkBooleanMacro(SkipFirstTick, bool);
245
247
251 virtual double* GetAdjustedRange()
252 {
253 this->UpdateAdjustedRange();
254 return this->AdjustedRange;
255 }
256 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
257 {
258 this->UpdateAdjustedRange();
259 _arg1 = this->AdjustedRange[0];
260 _arg2 = this->AdjustedRange[1];
261 }
262 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
264
269 {
270 this->UpdateAdjustedRange();
271 return this->AdjustedNumberOfLabels;
272 }
273
278
280
283 vtkSetStringMacro(Title);
284 vtkGetStringMacro(Title);
286
288
294
296
302
304
308 vtkSetClampMacro(TickLength, int, 0, 100);
309 vtkGetMacro(TickLength, int);
311
313
317 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
318 vtkGetMacro(NumberOfMinorTicks, int);
320
322
326 vtkSetClampMacro(MinorTickLength, int, 0, 100);
327 vtkGetMacro(MinorTickLength, int);
329
331
336 vtkSetClampMacro(TickOffset, int, 0, 100);
337 vtkGetMacro(TickOffset, int);
339
341
346 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
348
350
355 vtkBooleanMacro(TickVisibility, vtkTypeBool);
357
359
364 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
366
368
373 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
375
377
381 vtkSetMacro(TitlePosition, double);
382 vtkGetMacro(TitlePosition, double);
384
386
391 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
392 vtkGetMacro(FontFactor, double);
394
396
400 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
401 vtkGetMacro(LabelFactor, double);
403
407 virtual std::vector<vtkSmartPointer<vtkTextMapper>> GetLabelMappers()
408 {
409 return this->LabelMappers;
410 }
411
419
421
424 int RenderOverlay(vtkViewport* viewport) override;
425 int RenderOpaqueGeometry(vtkViewport* viewport) override;
428
433
440
454 static void ComputeRange(
455 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
456
458
466
468
477
481 void ShallowCopy(vtkProp* prop) override;
482
483protected:
485 ~vtkAxisActor2D() override;
486
487 char* Title;
489 double Range[2] = { 0., 1. };
490 double TitlePosition = 0.5;
492 double RulerDistance = 1.;
495 double FontFactor = 1.;
496 double LabelFactor = 0.75;
497 int TickLength = 5;
499 int TickOffset = 2;
501
502 double AdjustedRange[2];
506
507 int Notation = 0;
508 int Precision = 2;
509
514
515 int LastPosition[2] = { 0, 0 };
516 int LastPosition2[2] = { 0, 0 };
517
518 int LastSize[2] = { 0, 0 };
519 int LastMaxLabelSize[2] = { 0, 0 };
520
523
524 virtual void BuildAxis(vtkViewport* viewport);
525 static double ComputeStringOffset(double width, double height, double theta);
526
530 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
531 int offset, vtkActor2D* textActor);
532
540 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
541 int offset, int finalPos[2]);
542
543 virtual void UpdateAdjustedRange();
544
547
551
554
555private:
556 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
557 void operator=(const vtkAxisActor2D&) = delete;
558
562 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
563
567 bool ShouldRebuild(vtkViewport* viewport);
568
576 void UpdateTicksValueAndPosition(vtkViewport* viewport);
577
581 void BuildTicksPolyData(vtkViewport* viewport);
582
586 void BuildLabels(vtkViewport* viewport);
587
591 void BuildTitle(vtkViewport* viewport);
592
596 double GetAxisAngle(vtkViewport* viewport);
597
601 void UpdateCachedInformations(vtkViewport* viewport);
602
606 double GetViewportRulerDistance(vtkViewport* viewport);
607
611 double GetViewportAxisLength(vtkViewport* viewport);
612
617 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
618
619 // tick position in axis, normalized on axis length.
620 std::vector<double> NormalizedTickPositions;
621 std::vector<double> TickValues;
622
623 bool SnapLabelsToGrid = false;
624
625 bool SkipFirstTick = false;
626
627 std::vector<vtkSmartPointer<vtkTextMapper>> LabelMappers;
628 std::vector<vtkSmartPointer<vtkActor2D>> LabelActors;
629
630 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
631 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
632};
633
634VTK_ABI_NAMESPACE_END
635#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< 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:29
Allocate and hold a VTK object.
Definition vtkNew.h:59
represent and manipulate 3D points
Definition vtkPoints.h:31
draw vtkPolyData onto the image plane
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
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:47
window superclass for vtkRenderWindow
Definition vtkWindow.h:43
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