VTK  9.7.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
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 
77 VTK_ABI_NAMESPACE_BEGIN
78 class vtkPoints;
79 class vtkPolyData;
81 class vtkTextMapper;
82 class vtkTextProperty;
83 
84 class VTKRENDERINGANNOTATION_EXPORT VTK_MARSHALAUTO vtkAxisActor2D : public vtkActor2D
85 {
86 public:
87  vtkTypeMacro(vtkAxisActor2D, vtkActor2D);
88  void PrintSelf(ostream& os, vtkIndent indent) override;
89 
93  static vtkAxisActor2D* New();
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 
153  enum LabelMax
154  {
155  VTK_MAX_LABELS VTK_DEPRECATED_IN_9_6_0(
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 
236  vtkSetMacro(AdjustLabels, vtkTypeBool);
237  vtkGetMacro(AdjustLabels, vtkTypeBool);
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 
283  vtkPoints* GetTickPositions();
284 
286 
289  vtkSetStringMacro(Title);
290  vtkGetStringMacro(Title);
292 
294 
297  virtual void SetTitleTextProperty(vtkTextProperty*);
298  virtual vtkTextProperty* GetTitleTextProperty();
300 
302 
305  virtual void SetLabelTextProperty(vtkTextProperty*);
306  virtual vtkTextProperty* GetLabelTextProperty();
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 
350  vtkSetMacro(AxisVisibility, vtkTypeBool);
351  vtkGetMacro(AxisVisibility, vtkTypeBool);
352  vtkBooleanMacro(AxisVisibility, vtkTypeBool);
354 
356 
359  vtkSetMacro(TickVisibility, vtkTypeBool);
360  vtkGetMacro(TickVisibility, vtkTypeBool);
361  vtkBooleanMacro(TickVisibility, vtkTypeBool);
363 
365 
368  vtkSetMacro(LabelVisibility, vtkTypeBool);
369  vtkGetMacro(LabelVisibility, vtkTypeBool);
370  vtkBooleanMacro(LabelVisibility, vtkTypeBool);
372 
374 
377  vtkSetMacro(TitleVisibility, vtkTypeBool);
378  vtkGetMacro(TitleVisibility, vtkTypeBool);
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 
421  virtual std::vector<vtkSmartPointer<vtkActor2D>> GetLabelActors() { return this->LabelActors; }
422 
429  int UpdateGeometryAndRenderOpaqueGeometry(vtkViewport* viewport, bool render);
430 
432 
435  int RenderOverlay(vtkViewport* viewport) override;
436  int RenderOpaqueGeometry(vtkViewport* viewport) override;
437  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
439 
444 
450  void ReleaseGraphicsResources(vtkWindow*) override;
451 
465  static void ComputeRange(
466  double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
467 
476  static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
477  int nbOfMappers, int* targetSize, double factor, int* stringSize);
478 
480 
484  vtkSetMacro(SizeFontRelativeToAxis, vtkTypeBool);
485  vtkGetMacro(SizeFontRelativeToAxis, vtkTypeBool);
486  vtkBooleanMacro(SizeFontRelativeToAxis, vtkTypeBool);
488 
490 
495  vtkSetMacro(UseFontSizeFromProperty, vtkTypeBool);
496  vtkGetMacro(UseFontSizeFromProperty, vtkTypeBool);
497  vtkBooleanMacro(UseFontSizeFromProperty, vtkTypeBool);
499 
503  void ShallowCopy(vtkProp* prop) override;
504 
505 protected:
506  vtkAxisActor2D();
507  ~vtkAxisActor2D() override;
508 
509  char* Title;
510  char* LabelFormat;
511  double Range[2] = { 0., 1. };
512  double TitlePosition = 0.5;
513  vtkTypeBool RulerMode = 0;
514  double RulerDistance = 1.;
515  int NumberOfLabels = 5;
516  vtkTypeBool AdjustLabels = 1;
517  double FontFactor = 1.;
518  double LabelFactor = 0.75;
519  int TickLength = 5;
520  int MinorTickLength = 3;
521  int TickOffset = 2;
522  int NumberOfMinorTicks = 0;
523 
524  double AdjustedRange[2];
525  int AdjustedNumberOfLabels = 5;
526  int NumberOfLabelsBuilt = 0;
528 
529  int Notation = 0;
530  int Precision = 2;
531 
532  vtkTypeBool AxisVisibility = 1;
533  vtkTypeBool TickVisibility = 1;
534  vtkTypeBool LabelVisibility = 1;
535  vtkTypeBool TitleVisibility = 1;
536 
537  int LastPosition[2] = { 0, 0 };
538  int LastPosition2[2] = { 0, 0 };
539 
540  int LastSize[2] = { 0, 0 };
541  int LastMaxLabelSize[2] = { 0, 0 };
542 
543  int SizeFontRelativeToAxis = 0;
544  vtkTypeBool UseFontSizeFromProperty = 0;
545 
546  virtual void BuildAxis(vtkViewport* viewport);
547  static double ComputeStringOffset(double width, double height, double theta);
548 
552  static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
553  int offset, vtkActor2D* textActor);
554 
562  void ShiftPosition(double start[3], double textAngle, int stringWidth, int stringHeight,
563  int offset, int finalPos[2]);
564 
565  virtual void UpdateAdjustedRange();
566 
569 
573 
576 
577 private:
578  vtkAxisActor2D(const vtkAxisActor2D&) = delete;
579  void operator=(const vtkAxisActor2D&) = delete;
580 
584  bool PositionsChangedOrViewportResized(vtkViewport* viewport);
585 
589  bool ShouldRebuild(vtkViewport* viewport);
590 
598  void UpdateTicksValueAndPosition(vtkViewport* viewport);
599 
603  void BuildTicksPolyData(vtkViewport* viewport);
604 
608  void BuildLabels(vtkViewport* viewport);
609 
613  void BuildTitle(vtkViewport* viewport);
614 
618  double GetAxisAngle(vtkViewport* viewport);
619 
623  void UpdateCachedInformations(vtkViewport* viewport);
624 
628  double GetViewportRulerDistance(vtkViewport* viewport);
629 
633  double GetViewportAxisLength(vtkViewport* viewport);
634 
639  void SetTitleFontSize(vtkViewport* viewport, int box[2]);
640 
641  // tick position in axis, normalized on axis length.
642  std::vector<double> NormalizedTickPositions;
643  std::vector<double> TickValues;
644 
645  bool SnapLabelsToGrid = false;
646 
647  bool SkipFirstTick = false;
648 
649  std::vector<vtkSmartPointer<vtkTextMapper>> LabelMappers;
650  std::vector<vtkSmartPointer<vtkActor2D>> LabelActors;
651 
652  vtkSmartPointer<vtkTextProperty> TitleTextProperty;
653  vtkSmartPointer<vtkTextProperty> LabelTextProperty;
654 };
655 
656 VTK_ABI_NAMESPACE_END
657 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
virtual void GetAdjustedRange(double _arg[2])
Get the axis range adjusted for nice tick values.
virtual void SetPosition(float x[2])
Get the PositionCoordinate instance of vtkCoordinate.
int RenderOverlay(vtkViewport *viewport) override
Support the standard render methods.
vtkActor2D * TitleActor
abstract specification for Viewports
Definition: vtkViewport.h:46
vtkNew< vtkPoints > TicksStartPos
virtual double * GetPoint1()
Specify the position of the first point defining the axis.
#define VTK_INT_MAX
Definition: vtkType.h:192
a actor that draws 2D data
Definition: vtkActor2D.h:35
record modification and/or execution time
Definition: vtkTimeStamp.h:24
virtual vtkCoordinate * GetPositionCoordinate()
Get the PositionCoordinate instance of vtkCoordinate.
Create an axis with tick marks and labels.
virtual void SetPoint1(double x, double y)
Specify the position of the first point defining the axis.
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
void ShallowCopy(vtkProp *prop) override
Shallow copy of this vtkActor2D.
virtual void SetPoint2(double x, double y)
Specify the position of the second point defining the axis.
virtual float * GetPosition2()
Access the Position2 instance variable.
2D text annotation
Definition: vtkTextMapper.h:39
virtual vtkCoordinate * GetPoint2Coordinate()
Specify the position of the second point defining the axis.
virtual void GetAdjustedRange(double &_arg1, double &_arg2)
Get the axis range adjusted for nice tick values.
int vtkTypeBool
Definition: vtkABI.h:64
virtual vtkCoordinate * GetPoint1Coordinate()
Specify the position of the first point defining the axis.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
auto Range(IterablePtr iterable, Options &&...opts) -> typename detail::IterableTraits< typename detail::StripPointers< IterablePtr >::type >::RangeType
Generate an iterable STL proxy object for a VTK container.
Definition: vtkRange.h:74
virtual double * GetAdjustedRange()
Get the axis range adjusted for nice tick values.
vtkTimeStamp AdjustedRangeBuildTime
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_FLOAT_MAX
Definition: vtkType.h:200
virtual double * GetPoint2()
Specify the position of the second point defining the axis.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this actor.
vtkNew< vtkActor2D > AxisActor
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkTextMapper * TitleMapper
static vtkActor2D * New()
Creates an actor2D with the following defaults: position (0,0) (coordinate system is viewport); at la...
virtual void SetPosition2(float x[2])
Access the Position2 instance variable.
virtual float * GetPosition()
Get the PositionCoordinate instance of vtkCoordinate.
virtual void SetPoint2(double x[2])
Specify the position of the second point defining the axis.
virtual vtkCoordinate * GetPosition2Coordinate()
Access the Position2 instance variable.
int RenderTranslucentPolygonalGeometry(vtkViewport *) override
Draw the axis.
represent text properties.
virtual std::vector< vtkSmartPointer< vtkActor2D > > GetLabelActors()
Get the label actors.
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems ...
Definition: vtkCoordinate.h:69
virtual void SetPoint1(double x[2])
Specify the position of the first point defining the axis.
vtkTypeBool HasTranslucentPolygonalGeometry() override
Does this prop have some translucent polygonal geometry?
vtkNew< vtkPolyData > Axis
vtkNew< vtkPolyDataMapper2D > AxisMapper
int RenderOpaqueGeometry(vtkViewport *viewport) override
Support the standard render methods.
#define VTK_MARSHALAUTO
virtual int GetAdjustedNumberOfLabels()
Get the number of labels.
vtkTimeStamp BuildTime
virtual std::vector< vtkSmartPointer< vtkTextMapper > > GetLabelMappers()
Get the label mappers.
draw vtkPolyData onto the image plane
represent and manipulate 3D points
Definition: vtkPoints.h:30
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.