VTK  9.3.20240424
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
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 {
154 VTK_MAX_LABELS = 25
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
234 vtkSetMacro(AdjustLabels, vtkTypeBool);
235 vtkGetMacro(AdjustLabels, vtkTypeBool);
236 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
238
240
244 virtual double* GetAdjustedRange()
245 {
246 this->UpdateAdjustedRange();
247 return this->AdjustedRange;
248 }
249 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
250 {
251 this->UpdateAdjustedRange();
252 _arg1 = this->AdjustedRange[0];
253 _arg2 = this->AdjustedRange[1];
254 }
255 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
257
262 {
263 this->UpdateAdjustedRange();
264 return this->AdjustedNumberOfLabels;
265 }
266
271
273
276 vtkSetStringMacro(Title);
277 vtkGetStringMacro(Title);
279
281
285 vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
287
289
293 vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
295
297
301 vtkSetClampMacro(TickLength, int, 0, 100);
302 vtkGetMacro(TickLength, int);
304
306
310 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
311 vtkGetMacro(NumberOfMinorTicks, int);
313
315
319 vtkSetClampMacro(MinorTickLength, int, 0, 100);
320 vtkGetMacro(MinorTickLength, int);
322
324
329 vtkSetClampMacro(TickOffset, int, 0, 100);
330 vtkGetMacro(TickOffset, int);
332
334
337 vtkSetMacro(AxisVisibility, vtkTypeBool);
338 vtkGetMacro(AxisVisibility, vtkTypeBool);
339 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
341
343
346 vtkSetMacro(TickVisibility, vtkTypeBool);
347 vtkGetMacro(TickVisibility, vtkTypeBool);
348 vtkBooleanMacro(TickVisibility, vtkTypeBool);
350
352
355 vtkSetMacro(LabelVisibility, vtkTypeBool);
356 vtkGetMacro(LabelVisibility, vtkTypeBool);
357 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
359
361
364 vtkSetMacro(TitleVisibility, vtkTypeBool);
365 vtkGetMacro(TitleVisibility, vtkTypeBool);
366 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
368
370
374 vtkSetMacro(TitlePosition, double);
375 vtkGetMacro(TitlePosition, double);
377
379
384 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
385 vtkGetMacro(FontFactor, double);
387
389
393 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
394 vtkGetMacro(LabelFactor, double);
396
404
406
409 int RenderOverlay(vtkViewport* viewport) override;
410 int RenderOpaqueGeometry(vtkViewport* viewport) override;
413
418
425
439 static void ComputeRange(
440 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
441
450 static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
451 int nbOfMappers, int* targetSize, double factor, int* stringSize);
452
454
458 vtkSetMacro(SizeFontRelativeToAxis, vtkTypeBool);
459 vtkGetMacro(SizeFontRelativeToAxis, vtkTypeBool);
460 vtkBooleanMacro(SizeFontRelativeToAxis, vtkTypeBool);
462
464
469 vtkSetMacro(UseFontSizeFromProperty, vtkTypeBool);
470 vtkGetMacro(UseFontSizeFromProperty, vtkTypeBool);
471 vtkBooleanMacro(UseFontSizeFromProperty, vtkTypeBool);
473
477 void ShallowCopy(vtkProp* prop) override;
478
479protected:
481 ~vtkAxisActor2D() override;
482
485
486 char* Title;
488 double Range[2] = { 0., 1. };
489 double TitlePosition = 0.5;
490 vtkTypeBool RulerMode = 0;
491 double RulerDistance = 1.;
492 int NumberOfLabels = 5;
493 vtkTypeBool AdjustLabels = 1;
494 double FontFactor = 1.;
495 double LabelFactor = 0.75;
496 int TickLength = 5;
497 int MinorTickLength = 3;
498 int TickOffset = 2;
499 int NumberOfMinorTicks = 0;
500
501 double AdjustedRange[2];
502 int AdjustedNumberOfLabels = 5;
503 int NumberOfLabelsBuilt = 0;
505
506 int Notation = 0;
507 int Precision = 2;
508
509 vtkTypeBool AxisVisibility = 1;
510 vtkTypeBool TickVisibility = 1;
511 vtkTypeBool LabelVisibility = 1;
512 vtkTypeBool TitleVisibility = 1;
513
514 int LastPosition[2] = { 0, 0 };
515 int LastPosition2[2] = { 0, 0 };
516
517 int LastSize[2] = { 0, 0 };
518 int LastMaxLabelSize[2] = { 0, 0 };
519
520 int SizeFontRelativeToAxis = 0;
521 vtkTypeBool UseFontSizeFromProperty = 0;
522
523 virtual void BuildAxis(vtkViewport* viewport);
524 static double ComputeStringOffset(double width, double height, double theta);
525 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
526 int offset, vtkActor2D* actor);
527 virtual void UpdateAdjustedRange();
528
531
534
538
541
542private:
543 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
544 void operator=(const vtkAxisActor2D&) = delete;
545
549 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
550
554 bool ShouldRebuild(vtkViewport* viewport);
555
563 void UpdateTicksValueAndPosition(vtkViewport* viewport);
564
568 void BuildTicksPolyData(vtkViewport* viewport);
569
573 void BuildLabels(vtkViewport* viewport);
574
578 void BuildTitle(vtkViewport* viewport);
579
583 double GetAxisAngle(vtkViewport* viewport);
584
588 void UpdateCachedInformations(vtkViewport* viewport);
589
593 double GetViewportRulerDistance(vtkViewport* viewport);
594
598 double GetViewportAxisLength(vtkViewport* viewport);
599
600 // tick position in axis, normalized on axis length.
601 std::vector<double> NormalizedTickPositions;
602 std::vector<double> TickValues;
603
604 bool SnapLabelsToGrid = false;
605};
606
607VTK_ABI_NAMESPACE_END
608#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
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
static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight, int offset, vtkActor2D *actor)
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.
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:160
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:144
#define VTK_FLOAT_MAX
Definition vtkType.h:152
#define VTK_MARSHALAUTO