VTK  9.3.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
49 #ifndef vtkAxisActor2D_h
50 #define vtkAxisActor2D_h
51 
52 #include "vtkActor2D.h"
53 #include "vtkRenderingAnnotationModule.h" // For export macro
54 
55 #include "vtkNew.h" // for vtkNew
56 
57 VTK_ABI_NAMESPACE_BEGIN
59 class vtkPolyData;
60 class vtkTextMapper;
61 class vtkTextProperty;
62 
63 class VTKRENDERINGANNOTATION_EXPORT vtkAxisActor2D : public vtkActor2D
64 {
65 public:
66  vtkTypeMacro(vtkAxisActor2D, vtkActor2D);
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
72  static vtkAxisActor2D* New();
73 
75 
80  virtual void SetPoint1(double x[2]) { this->SetPosition(x); }
81  virtual void SetPoint1(double x, double y) { this->SetPosition(x, y); }
82  virtual double* GetPoint1() { return this->GetPosition(); }
84 
86 
93  virtual void SetPoint2(double x[2]) { this->SetPosition2(x); }
94  virtual void SetPoint2(double x, double y) { this->SetPosition2(x, y); }
95  virtual double* GetPoint2() { return this->GetPosition2(); }
97 
99 
103  vtkSetVector2Macro(Range, double);
104  vtkGetVectorMacro(Range, double, 2);
106 
108 
113  vtkSetMacro(RulerMode, vtkTypeBool);
114  vtkGetMacro(RulerMode, vtkTypeBool);
115  vtkBooleanMacro(RulerMode, vtkTypeBool);
117 
119 
123  vtkSetClampMacro(RulerDistance, double, 0, VTK_FLOAT_MAX);
124  vtkGetMacro(RulerDistance, double);
126 
127  enum LabelMax
128  {
129  VTK_MAX_LABELS = 25
130  };
131 
133 
138  vtkSetClampMacro(NumberOfLabels, int, 2, VTK_MAX_LABELS);
139  vtkGetMacro(NumberOfLabels, int);
141 
143 
147  vtkSetStringMacro(LabelFormat);
148  vtkGetStringMacro(LabelFormat);
150 
152 
160  vtkSetMacro(AdjustLabels, vtkTypeBool);
161  vtkGetMacro(AdjustLabels, vtkTypeBool);
162  vtkBooleanMacro(AdjustLabels, vtkTypeBool);
163  virtual double* GetAdjustedRange()
164  {
165  this->UpdateAdjustedRange();
166  return this->AdjustedRange;
167  }
168  virtual void GetAdjustedRange(double& _arg1, double& _arg2)
169  {
170  this->UpdateAdjustedRange();
171  _arg1 = this->AdjustedRange[0];
172  _arg2 = this->AdjustedRange[1];
173  };
174  virtual void GetAdjustedRange(double _arg[2]) { this->GetAdjustedRange(_arg[0], _arg[1]); }
176  {
177  this->UpdateAdjustedRange();
178  return this->AdjustedNumberOfLabels;
179  }
181 
183 
186  vtkSetStringMacro(Title);
187  vtkGetStringMacro(Title);
189 
191 
194  virtual void SetTitleTextProperty(vtkTextProperty* p);
195  vtkGetObjectMacro(TitleTextProperty, vtkTextProperty);
197 
199 
202  virtual void SetLabelTextProperty(vtkTextProperty* p);
203  vtkGetObjectMacro(LabelTextProperty, vtkTextProperty);
205 
207 
211  vtkSetClampMacro(TickLength, int, 0, 100);
212  vtkGetMacro(TickLength, int);
214 
216 
220  vtkSetClampMacro(NumberOfMinorTicks, int, 0, 20);
221  vtkGetMacro(NumberOfMinorTicks, int);
223 
225 
229  vtkSetClampMacro(MinorTickLength, int, 0, 100);
230  vtkGetMacro(MinorTickLength, int);
232 
234 
239  vtkSetClampMacro(TickOffset, int, 0, 100);
240  vtkGetMacro(TickOffset, int);
242 
244 
247  vtkSetMacro(AxisVisibility, vtkTypeBool);
248  vtkGetMacro(AxisVisibility, vtkTypeBool);
249  vtkBooleanMacro(AxisVisibility, vtkTypeBool);
251 
253 
256  vtkSetMacro(TickVisibility, vtkTypeBool);
257  vtkGetMacro(TickVisibility, vtkTypeBool);
258  vtkBooleanMacro(TickVisibility, vtkTypeBool);
260 
262 
265  vtkSetMacro(LabelVisibility, vtkTypeBool);
266  vtkGetMacro(LabelVisibility, vtkTypeBool);
267  vtkBooleanMacro(LabelVisibility, vtkTypeBool);
269 
271 
274  vtkSetMacro(TitleVisibility, vtkTypeBool);
275  vtkGetMacro(TitleVisibility, vtkTypeBool);
276  vtkBooleanMacro(TitleVisibility, vtkTypeBool);
278 
280 
284  vtkSetMacro(TitlePosition, double);
285  vtkGetMacro(TitlePosition, double);
287 
289 
294  vtkSetClampMacro(FontFactor, double, 0.1, 2.0);
295  vtkGetMacro(FontFactor, double);
297 
299 
303  vtkSetClampMacro(LabelFactor, double, 0.1, 2.0);
304  vtkGetMacro(LabelFactor, double);
306 
308 
311  int RenderOverlay(vtkViewport* viewport) override;
312  int RenderOpaqueGeometry(vtkViewport* viewport) override;
313  int RenderTranslucentPolygonalGeometry(vtkViewport*) override { return 0; }
315 
320 
326  void ReleaseGraphicsResources(vtkWindow*) override;
327 
338  static void ComputeRange(
339  double inRange[2], double outRange[2], int inNumTicks, int& outNumTicks, double& interval);
340 
349  static int SetMultipleFontSize(vtkViewport* viewport, vtkTextMapper** textMappers,
350  int nbOfMappers, int* targetSize, double factor, int* stringSize);
351 
353 
357  vtkSetMacro(SizeFontRelativeToAxis, vtkTypeBool);
358  vtkGetMacro(SizeFontRelativeToAxis, vtkTypeBool);
359  vtkBooleanMacro(SizeFontRelativeToAxis, vtkTypeBool);
361 
363 
368  vtkSetMacro(UseFontSizeFromProperty, vtkTypeBool);
369  vtkGetMacro(UseFontSizeFromProperty, vtkTypeBool);
370  vtkBooleanMacro(UseFontSizeFromProperty, vtkTypeBool);
372 
376  void ShallowCopy(vtkProp* prop) override;
377 
378 protected:
379  vtkAxisActor2D();
380  ~vtkAxisActor2D() override;
381 
384 
385  char* Title;
386  char* LabelFormat;
387  double Range[2] = { 0., 1. };
388  double TitlePosition = 0.5;
389  vtkTypeBool RulerMode = 0;
390  double RulerDistance = 1.;
391  int NumberOfLabels = 5;
392  vtkTypeBool AdjustLabels = 1;
393  double FontFactor = 1.;
394  double LabelFactor = 0.75;
395  int TickLength = 5;
396  int MinorTickLength = 3;
397  int TickOffset = 2;
398  int NumberOfMinorTicks = 0;
399 
400  double AdjustedRange[2];
401  int AdjustedNumberOfLabels = 5;
402  int NumberOfLabelsBuilt = 0;
403 
404  vtkTypeBool AxisVisibility = 1;
405  vtkTypeBool TickVisibility = 1;
406  vtkTypeBool LabelVisibility = 1;
407  vtkTypeBool TitleVisibility = 1;
408 
409  int LastPosition[2] = { 0, 0 };
410  int LastPosition2[2] = { 0, 0 };
411 
412  int LastSize[2] = { 0, 0 };
413  int LastMaxLabelSize[2] = { 0, 0 };
414 
415  int SizeFontRelativeToAxis = 0;
416  vtkTypeBool UseFontSizeFromProperty = 0;
417 
418  virtual void BuildAxis(vtkViewport* viewport);
419  static double ComputeStringOffset(double width, double height, double theta);
420  static void SetOffsetPosition(double xTick[3], double theta, int stringWidth, int stringHeight,
421  int offset, vtkActor2D* actor);
422  virtual void UpdateAdjustedRange();
423 
426 
429 
433 
436 
437 private:
438  vtkAxisActor2D(const vtkAxisActor2D&) = delete;
439  void operator=(const vtkAxisActor2D&) = delete;
440 };
441 
442 VTK_ABI_NAMESPACE_END
443 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
virtual void GetAdjustedRange(double _arg[2])
Set/Get the flag that controls whether the labels and ticks are adjusted for "nice" numerical 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:44
virtual double * GetPoint1()
Specify the position of the first point defining the axis.
a actor that draws 2D data
Definition: vtkActor2D.h:34
record modification and/or execution time
Definition: vtkTimeStamp.h:24
vtkActor2D ** LabelActors
virtual vtkCoordinate * GetPositionCoordinate()
Get the PositionCoordinate instance of vtkCoordinate.
Create an axis with tick marks and labels.
vtkTextProperty * TitleTextProperty
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:79
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)
Set/Get the flag that controls whether the labels and ticks are adjusted for "nice" numerical 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:27
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()
Set/Get the flag that controls whether the labels and ticks are adjusted for "nice" numerical values ...
vtkTimeStamp AdjustedRangeBuildTime
#define VTK_FLOAT_MAX
Definition: vtkType.h:152
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...
vtkTextMapper ** LabelMappers
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.
vtkTextProperty * LabelTextProperty
perform coordinate transformation, and represent position, in a variety of vtk coordinate systems ...
Definition: vtkCoordinate.h:68
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.
virtual int GetAdjustedNumberOfLabels()
Set/Get the flag that controls whether the labels and ticks are adjusted for "nice" numerical values ...
vtkTimeStamp BuildTime
draw vtkPolyData onto the image plane
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.