VTK
vtkAxis.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAxis.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
54 #ifndef vtkAxis_h
55 #define vtkAxis_h
56 
57 #include "vtkChartsCoreModule.h" // For export macro
58 #include "vtkContextItem.h"
59 #include "vtkSmartPointer.h" // For vtkSmartPointer
60 #include "vtkVector.h" // For position variables
61 #include "vtkRect.h" // For bounding rect
62 #include "vtkStdString.h" // For vtkStdString ivars
63 
64 class vtkContext2D;
65 class vtkPen;
66 class vtkFloatArray;
67 class vtkDoubleArray;
68 class vtkStringArray;
69 class vtkTextProperty;
70 
71 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
72 {
73 public:
74  vtkTypeMacro(vtkAxis, vtkContextItem);
75  void PrintSelf(ostream &os, vtkIndent indent) override;
76 
81  enum Location {
82  LEFT = 0,
85  TOP,
86  PARALLEL
87  };
88 
89  enum {
90  TICK_SIMPLE = 0,
91  TICK_WILKINSON_EXTENDED
92  };
93 
97  static vtkAxis *New();
98 
100 
103  virtual void SetPosition(int position);
104  vtkGetMacro(Position, int);
106 
108 
111  void SetPoint1(const vtkVector2f& pos);
112  void SetPoint1(float x, float y);
114 
116 
119  vtkGetVector2Macro(Point1, float);
120  vtkVector2f GetPosition1();
122 
124 
127  void SetPoint2(const vtkVector2f& pos);
128  void SetPoint2(float x, float y);
130 
132 
135  vtkGetVector2Macro(Point2, float);
136  vtkVector2f GetPosition2();
138 
143  virtual void SetNumberOfTicks(int numberOfTicks);
144 
146 
149  vtkGetMacro(NumberOfTicks, int);
151 
153 
156  vtkSetMacro(TickLength, float);
157  vtkGetMacro(TickLength, float);
159 
161 
165  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
167 
173  virtual void SetMinimum(double minimum);
174 
176 
181  vtkGetMacro(Minimum, double);
183 
189  virtual void SetMaximum(double maximum);
190 
192 
197  vtkGetMacro(Maximum, double);
199 
205  virtual void SetUnscaledMinimum(double minimum);
206 
208 
211  vtkGetMacro(UnscaledMinimum, double);
213 
217  virtual void SetUnscaledMaximum(double maximum);
218 
220 
223  vtkGetMacro(UnscaledMaximum, double);
225 
227 
236  virtual void SetRange(double minimum, double maximum);
237  virtual void SetRange(double range[2]);
238  virtual void SetUnscaledRange(double minimum, double maximum);
239  virtual void SetUnscaledRange(double range[2]);
241 
243 
250  virtual void GetRange(double *range);
251  virtual void GetUnscaledRange(double *range);
253 
257  virtual void SetMinimumLimit(double lowest);
258 
260 
263  vtkGetMacro(MinimumLimit, double);
265 
269  virtual void SetMaximumLimit(double highest);
270 
272 
275  vtkGetMacro(MaximumLimit, double);
277 
281  virtual void SetUnscaledMinimumLimit(double lowest);
282 
284 
287  vtkGetMacro(UnscaledMinimumLimit, double);
289 
293  virtual void SetUnscaledMaximumLimit(double highest);
294 
296 
299  vtkGetMacro(UnscaledMaximumLimit, double);
301 
303 
306  vtkGetVector2Macro(Margins, int);
308 
310 
313  vtkSetVector2Macro(Margins, int);
315 
317 
320  virtual void SetTitle(const vtkStdString &title);
321  virtual vtkStdString GetTitle();
323 
325 
328  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
330 
332 
344  vtkGetMacro(LogScaleActive, bool);
346 
348 
354  vtkGetMacro(LogScale, bool);
355  virtual void SetLogScale(bool logScale);
356  vtkBooleanMacro(LogScale,bool);
358 
360 
363  vtkSetMacro(GridVisible, bool);
364  vtkGetMacro(GridVisible, bool);
366 
368 
371  vtkSetMacro(LabelsVisible, bool);
372  vtkGetMacro(LabelsVisible, bool);
374 
376 
379  vtkSetMacro(RangeLabelsVisible, bool);
380  vtkGetMacro(RangeLabelsVisible, bool);
382 
384 
387  vtkSetMacro(LabelOffset, float);
388  vtkGetMacro(LabelOffset, float);
390 
392 
395  vtkSetMacro(TicksVisible, bool);
396  vtkGetMacro(TicksVisible, bool);
398 
400 
403  vtkSetMacro(AxisVisible, bool);
404  vtkGetMacro(AxisVisible, bool);
406 
408 
411  vtkSetMacro(TitleVisible, bool);
412  vtkGetMacro(TitleVisible, bool);
414 
416 
420  virtual void SetPrecision(int precision);
421  vtkGetMacro(Precision, int);
423 
427  enum {
428  STANDARD_NOTATION = 0,
431  PRINTF_NOTATION
432  };
433 
435 
439  virtual void SetLabelFormat(const std::string &fmt);
440  vtkGetMacro(LabelFormat, std::string);
442 
444 
449  vtkSetMacro(RangeLabelFormat, std::string);
450  vtkGetMacro(RangeLabelFormat, std::string);
452 
454 
459  virtual void SetNotation(int notation);
460  vtkGetMacro(Notation, int);
462 
466  enum {
467  AUTO = 0, // Automatically scale the axis to view all data that is visible.
468  FIXED, // Use a fixed axis range and make no attempt to rescale.
469  CUSTOM // Deprecated, use the tick label settings instead.
470  };
471 
473 
476  vtkSetMacro(Behavior, int);
477  vtkGetMacro(Behavior, int);
479 
481 
484  vtkGetObjectMacro(Pen, vtkPen);
486 
488 
491  vtkGetObjectMacro(GridPen, vtkPen);
493 
495 
502  vtkSetMacro(TickLabelAlgorithm, int)
503  vtkGetMacro(TickLabelAlgorithm, int)
505 
507 
511  vtkSetMacro(ScalingFactor, double)
512  vtkGetMacro(ScalingFactor, double)
513  vtkSetMacro(Shift, double)
514  vtkGetMacro(Shift, double)
516 
521  void Update() override;
522 
526  bool Paint(vtkContext2D *painter) override;
527 
534  virtual void AutoScale();
535 
540  virtual void RecalculateTickSpacing();
541 
546  virtual vtkDoubleArray* GetTickPositions();
547 
552  virtual vtkFloatArray* GetTickScenePositions();
553 
557  virtual vtkStringArray* GetTickLabels();
558 
566  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
567  vtkStringArray* labels = nullptr);
568 
575  vtkRectf GetBoundingRect(vtkContext2D* painter);
576 
582  static double NiceNumber(double number, bool roundUp);
583 
588  static double NiceMinMax(double &min, double &max, float pixelRange,
589  float tickPixelSpacing);
590 
595  virtual vtkStdString GenerateSimpleLabel(double val);
596 
597 protected:
598  vtkAxis();
599  ~vtkAxis() override;
600 
609  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
610 
614  void GenerateTickLabels(double min, double max);
615 
619  void GenerateTickLabels();
620 
621  virtual void GenerateLabelFormat(int notation, double n);
622 
626  virtual vtkStdString GenerateSprintfLabel(double value, const std::string & format);
627 
632  double CalculateNiceMinMax(double &min, double &max);
633 
643  double LogScaleTickMark(double number,
644  bool roundUp,
645  bool &niceValue,
646  int &order);
647 
659  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
660 
671  void GenerateLogScaleTickMarks(int order,
672  double min = 1.0,
673  double max = 9.0,
674  bool detailLabels = true);
675 
676  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
677  float *Point1; // The position of point 1 (usually the origin)
678  float *Point2; // The position of point 2 (usually the terminus)
679  vtkVector2f Position1, Position2;
680  double TickInterval; // Interval between tick marks in plot space
681  int NumberOfTicks; // The number of tick marks to draw
682  float TickLength; // The length of the tick marks
683  vtkTextProperty* LabelProperties; // Text properties for the labels.
684  double Minimum; // Minimum value of the axis
685  double Maximum; // Maximum values of the axis
686  double MinimumLimit; // Lowest possible value for Minimum
687  double MaximumLimit; // Highest possible value for Maximum
688  double UnscaledMinimum; // UnscaledMinimum value of the axis
689  double UnscaledMaximum; // UnscaledMaximum values of the axis
690  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
691  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
692  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
693  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
694  int Margins[2]; // Horizontal/vertical margins for the axis
695  vtkStdString Title; // The text label drawn on the axis
696  vtkTextProperty* TitleProperties; // Text properties for the axis title
697  bool LogScale; // *Should* the axis use a log scale?
698  bool LogScaleActive; // *Is* the axis using a log scale?
699  bool GridVisible; // Whether the grid for the axis should be drawn
700  bool LabelsVisible; // Should the axis labels be visible
701  bool RangeLabelsVisible; // Should range labels be visible?
702  float LabelOffset; // Offset of label from the tick mark
703  bool TicksVisible; // Should the tick marks be visible.
704  bool AxisVisible; // Should the axis line be visible.
705  bool TitleVisible; // Should the title be visible.
706  int Precision; // Numerical precision to use, defaults to 2.
707  int Notation; // The notation to use (standard, scientific, mixed)
708  std::string LabelFormat; // The printf-style format string used for labels.
709  std::string RangeLabelFormat; // The printf-style format string used for range labels.
710  int Behavior; // The behaviour of the axis (auto, fixed, custom).
711  float MaxLabel[2]; // The widest/tallest axis label.
712  bool TitleAppended; // Track if the title is updated when the label formats
713  // are changed in the Extended Axis Labeling algorithm
714 
716 
722  double Shift;
724 
729 
734 
739 
744 
749 
754 
760 
765 
769  bool Resized;
770 
775 
780 
781 private:
782  vtkAxis(const vtkAxis &) = delete;
783  void operator=(const vtkAxis &) = delete;
784 
788  bool InRange(double value);
789 
790 };
791 
792 #endif //vtkAxis_h
vtkAxis::TickMarksDirty
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:764
vtkAxis::Point1
float * Point1
Definition: vtkAxis.h:677
vtkStdString.h
vtkAxis::Point2
float * Point2
Definition: vtkAxis.h:678
vtkAxis::Title
vtkStdString Title
Definition: vtkAxis.h:695
vtkAxis::TickScenePositions
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:748
vtkAxis::TickPositions
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:743
vtkX3D::value
Definition: vtkX3D.h:220
vtkAxis::CustomTickLabels
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:728
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
vtkAxis::UsingNiceMinMax
bool UsingNiceMinMax
Hint as to whether a nice min/max was set, otherwise labels may not be present at the top/bottom of t...
Definition: vtkAxis.h:759
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkAxis::Shift
double Shift
Definition: vtkAxis.h:722
vtkX3D::range
Definition: vtkX3D.h:238
vtkSmartPointer< vtkDoubleArray >
vtkAxis::Position
int Position
Definition: vtkAxis.h:676
vtkVector.h
vtkAxis::TickLength
float TickLength
Definition: vtkAxis.h:682
vtkAxis::UnscaledMaximum
double UnscaledMaximum
Definition: vtkAxis.h:689
vtkAxis::Position2
vtkVector2f Position2
Definition: vtkAxis.h:679
vtkAxis::TitleVisible
bool TitleVisible
Definition: vtkAxis.h:705
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
vtkContextItem.h
vtkAxis::UnscaledMinimum
double UnscaledMinimum
Definition: vtkAxis.h:688
vtkAxis::LogScaleActive
bool LogScaleActive
Definition: vtkAxis.h:698
vtkAxis::TickLabelAlgorithm
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:774
vtkAxis::Minimum
double Minimum
Definition: vtkAxis.h:684
vtkAxis::Pen
vtkPen * Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:733
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkAxis::MinimumLimit
double MinimumLimit
Definition: vtkAxis.h:686
vtkAxis::LabelOffset
float LabelOffset
Definition: vtkAxis.h:702
vtkAxis::Precision
int Precision
Definition: vtkAxis.h:706
vtkX3D::position
Definition: vtkX3D.h:261
vtkAxis::BuildTime
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:779
vtkX3D::title
Definition: vtkX3D.h:500
vtkAxis::NonLogUnscaledMinLimit
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:692
vtkAxis::Behavior
int Behavior
Definition: vtkAxis.h:710
vtkAxis::ScalingFactor
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:721
vtkAxis::AxisVisible
bool AxisVisible
Definition: vtkAxis.h:704
vtkAxis::TOP
Definition: vtkAxis.h:85
vtkAxis::MaximumLimit
double MaximumLimit
Definition: vtkAxis.h:687
vtkAxis::TicksVisible
bool TicksVisible
Definition: vtkAxis.h:703
vtkRect.h
vtkAxis::Location
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:81
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkAxis::BOTTOM
Definition: vtkAxis.h:83
vtkAxis::TitleProperties
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:696
vtkSmartPointer.h
vtkAxis::NonLogUnscaledMaxLimit
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:693
vtkContextItem::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAxis::TitleAppended
bool TitleAppended
Definition: vtkAxis.h:712
vtkAxis::GridPen
vtkPen * GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:738
vtkAxis::UnscaledMinimumLimit
double UnscaledMinimumLimit
Definition: vtkAxis.h:690
vtkAxis::Maximum
double Maximum
Definition: vtkAxis.h:685
vtkAxis::LogScale
bool LogScale
Definition: vtkAxis.h:697
vtkAxis::GridVisible
bool GridVisible
Definition: vtkAxis.h:699
vtkX3D::order
Definition: vtkX3D.h:440
vtkAxis::NumberOfTicks
int NumberOfTicks
Definition: vtkAxis.h:681
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:39
vtkAxis::RangeLabelFormat
std::string RangeLabelFormat
Definition: vtkAxis.h:709
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:34
vtkAxis::TickInterval
double TickInterval
Definition: vtkAxis.h:680
vtkAxis::FIXED_NOTATION
Definition: vtkAxis.h:430
vtkX3D::string
Definition: vtkX3D.h:490
vtkAxis::LabelFormat
std::string LabelFormat
Definition: vtkAxis.h:708
vtkAxis::RangeLabelsVisible
bool RangeLabelsVisible
Definition: vtkAxis.h:701
vtkAxis::Resized
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:769
vtkAbstractContextItem::Paint
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
vtkAxis
takes care of drawing 2D axes
Definition: vtkAxis.h:71
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:42
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:41
vtkAxis::Notation
int Notation
Definition: vtkAxis.h:707
vtkAxis::TickLabels
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:753
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkAxis::SCIENTIFIC_NOTATION
Definition: vtkAxis.h:429
vtkAxis::FIXED
Definition: vtkAxis.h:468
vtkAxis::UnscaledMaximumLimit
double UnscaledMaximumLimit
Definition: vtkAxis.h:691
vtkAxis::RIGHT
Definition: vtkAxis.h:84
vtkRectf
Definition: vtkRect.h:332
vtkVector2f
Definition: vtkVector.h:418
vtkAxis::LabelProperties
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:683
vtkAbstractContextItem::Update
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
vtkAxis::LabelsVisible
bool LabelsVisible
Definition: vtkAxis.h:700