VTK  9.6.1
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 {
156 "VTK_MAX_LABELS has been removed. Labels are now dynamically allocated. Do not use.") = 25
157 };
158
160
165 vtkSetMacro(NumberOfLabels, int);
166 vtkGetMacro(NumberOfLabels, int);
168
170
174 vtkSetClampMacro(Precision, int, 0, VTK_INT_MAX);
175 vtkGetMacro(Precision, int);
177
179
186 vtkSetClampMacro(Notation, int, 0, 2);
187 vtkGetMacro(Notation, int);
189
191
195 vtkSetStringMacro(LabelFormat);
196 vtkGetStringMacro(LabelFormat);
198
200
215 vtkSetMacro(SnapLabelsToGrid, bool);
216 vtkGetMacro(SnapLabelsToGrid, bool);
217 vtkBooleanMacro(SnapLabelsToGrid, bool);
219
221
238 vtkBooleanMacro(AdjustLabels, vtkTypeBool);
240
242
247 vtkSetMacro(SkipFirstTick, bool);
248 vtkGetMacro(SkipFirstTick, bool);
249 vtkBooleanMacro(SkipFirstTick, bool);
251
253
257 virtual double* GetAdjustedRange()
258 {
259 this->UpdateAdjustedRange();
260 return this->AdjustedRange;
261 }
262 virtual void GetAdjustedRange(double& _arg1, double& _arg2)
263 {
264 this->UpdateAdjustedRange();
265 _arg1 = this->AdjustedRange[0];
266 _arg2 = this->AdjustedRange[1];
267 }
268 virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
270
275 {
276 this->UpdateAdjustedRange();
277 return this->AdjustedNumberOfLabels;
278 }
279
284
286
289 vtkSetStringMacro(Title);
290 vtkGetStringMacro(Title);
292
294
300
302
308
310
314 vtkSetClampMacro(TickLength, int, 0, 100);
315 vtkGetMacro(TickLength, int);
317
319
323 vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
324 vtkGetMacro(NumberOfMinorTicks, int);
326
328
332 vtkSetClampMacro(MinorTickLength, int, 0, 100);
333 vtkGetMacro(MinorTickLength, int);
335
337
342 vtkSetClampMacro(TickOffset, int, 0, 100);
343 vtkGetMacro(TickOffset, int);
345
347
352 vtkBooleanMacro(AxisVisibility, vtkTypeBool);
354
356
361 vtkBooleanMacro(TickVisibility, vtkTypeBool);
363
365
370 vtkBooleanMacro(LabelVisibility, vtkTypeBool);
372
374
379 vtkBooleanMacro(TitleVisibility, vtkTypeBool);
381
383
387 vtkSetMacro(TitlePosition, double);
388 vtkGetMacro(TitlePosition, double);
390
392
397 vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
398 vtkGetMacro(FontFactor, double);
400
402
406 vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
407 vtkGetMacro(LabelFactor, double);
409
413 virtual std::vector<vtkSmartPointer<vtkTextMapper>> GetLabelMappers()
414 {
415 return this->LabelMappers;
416 }
417
425
427
430 int RenderOverlay(vtkViewport* viewport) override;
431 int RenderOpaqueGeometry(vtkViewport* viewport) override;
434
439
446
460 static void ComputeRange(
461 double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
462
471 static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
472 int nbOfMappers, int* targetSize, double factor, int* stringSize);
473
475
483
485
494
498 void ShallowCopy(vtkProp* prop) override;
499
500protected:
502 ~vtkAxisActor2D() override;
503
504 char* Title;
506 double Range[2] = { 0., 1. };
507 double TitlePosition = 0.5;
509 double RulerDistance = 1.;
512 double FontFactor = 1.;
513 double LabelFactor = 0.75;
514 int TickLength = 5;
516 int TickOffset = 2;
518
519 double AdjustedRange[2];
523
524 int Notation = 0;
525 int Precision = 2;
526
531
532 int LastPosition[2] = { 0, 0 };
533 int LastPosition2[2] = { 0, 0 };
534
535 int LastSize[2] = { 0, 0 };
536 int LastMaxLabelSize[2] = { 0, 0 };
537
540
541 virtual void BuildAxis(vtkViewport* viewport);
542 static double ComputeStringOffset(double width, double height, double theta);
543
547 static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
548 int offset, vtkActor2D* textActor);
549
557 void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
558 int offset, int finalPos[2]);
559
560 virtual void UpdateAdjustedRange();
561
564
568
571
572private:
573 vtkAxisActor2D(const vtkAxisActor2D&) = delete;
574 void operator=(const vtkAxisActor2D&) = delete;
575
579 bool PositionsChangedOrViewportResized(vtkViewport* viewport);
580
584 bool ShouldRebuild(vtkViewport* viewport);
585
593 void UpdateTicksValueAndPosition(vtkViewport* viewport);
594
598 void BuildTicksPolyData(vtkViewport* viewport);
599
603 void BuildLabels(vtkViewport* viewport);
604
608 void BuildTitle(vtkViewport* viewport);
609
613 double GetAxisAngle(vtkViewport* viewport);
614
618 void UpdateCachedInformations(vtkViewport* viewport);
619
623 double GetViewportRulerDistance(vtkViewport* viewport);
624
628 double GetViewportAxisLength(vtkViewport* viewport);
629
634 void SetTitleFontSize(vtkViewport* viewport, int box[2]);
635
636 // tick position in axis, normalized on axis length.
637 std::vector<double> NormalizedTickPositions;
638 std::vector<double> TickValues;
639
640 bool SnapLabelsToGrid = false;
641
642 bool SkipFirstTick = false;
643
644 std::vector<vtkSmartPointer<vtkTextMapper>> LabelMappers;
645 std::vector<vtkSmartPointer<vtkActor2D>> LabelActors;
646
647 vtkSmartPointer<vtkTextProperty> TitleTextProperty;
648 vtkSmartPointer<vtkTextProperty> LabelTextProperty;
649};
650
651VTK_ABI_NAMESPACE_END
652#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)
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]).
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: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
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:29
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_INT_MAX
Definition vtkType.h:197
#define VTK_FLOAT_MAX
Definition vtkType.h:205
#define VTK_MARSHALAUTO