VTK  9.2.6
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 
63 #ifndef vtkAxis_h
64 #define vtkAxis_h
65 
66 #include "vtkChartsCoreModule.h" // For export macro
67 #include "vtkContextItem.h"
68 #include "vtkPen.h" // For vtkPen
69 #include "vtkRect.h" // For bounding rect
70 #include "vtkSmartPointer.h" // For vtkSmartPointer
71 #include "vtkStdString.h" // For vtkStdString ivars
72 #include "vtkVector.h" // For position variables
73 
74 class vtkContext2D;
75 class vtkFloatArray;
76 class vtkDoubleArray;
77 class vtkStringArray;
78 class vtkTextProperty;
79 
80 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
81 {
82 public:
83  vtkTypeMacro(vtkAxis, vtkContextItem);
84  void PrintSelf(ostream& os, vtkIndent indent) override;
85 
90  enum Location
91  {
92  LEFT = 0,
95  TOP,
96  PARALLEL
97  };
98 
99  enum
100  {
101  TICK_SIMPLE = 0,
102  TICK_WILKINSON_EXTENDED
103  };
104 
108  static vtkAxis* New();
109 
111 
114  virtual void SetPosition(int position);
115  vtkGetMacro(Position, int);
117 
119 
122  void SetPoint1(const vtkVector2f& pos);
123  void SetPoint1(float x, float y);
125 
127 
130  vtkGetVector2Macro(Point1, float);
133 
135 
138  void SetPoint2(const vtkVector2f& pos);
139  void SetPoint2(float x, float y);
141 
143 
146  vtkGetVector2Macro(Point2, float);
149 
154  virtual void SetNumberOfTicks(int numberOfTicks);
155 
157 
160  vtkGetMacro(NumberOfTicks, int);
162 
164 
167  vtkSetMacro(TickLength, float);
168  vtkGetMacro(TickLength, float);
170 
172 
176  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
178 
184  virtual void SetMinimum(double minimum);
185 
187 
192  vtkGetMacro(Minimum, double);
194 
200  virtual void SetMaximum(double maximum);
201 
203 
208  vtkGetMacro(Maximum, double);
210 
216  virtual void SetUnscaledMinimum(double minimum);
217 
219 
222  vtkGetMacro(UnscaledMinimum, double);
224 
228  virtual void SetUnscaledMaximum(double maximum);
229 
231 
234  vtkGetMacro(UnscaledMaximum, double);
236 
238 
247  virtual void SetRange(double minimum, double maximum);
248  virtual void SetRange(double range[2]);
249  virtual void SetUnscaledRange(double minimum, double maximum);
250  virtual void SetUnscaledRange(double range[2]);
252 
254 
261  virtual void GetRange(double* range);
262  virtual void GetUnscaledRange(double* range);
264 
268  virtual void SetMinimumLimit(double lowest);
269 
271 
274  vtkGetMacro(MinimumLimit, double);
276 
280  virtual void SetMaximumLimit(double highest);
281 
283 
286  vtkGetMacro(MaximumLimit, double);
288 
292  virtual void SetUnscaledMinimumLimit(double lowest);
293 
295 
298  vtkGetMacro(UnscaledMinimumLimit, double);
300 
304  virtual void SetUnscaledMaximumLimit(double highest);
305 
307 
310  vtkGetMacro(UnscaledMaximumLimit, double);
312 
314 
317  vtkGetVector2Macro(Margins, int);
319 
321 
324  vtkSetVector2Macro(Margins, int);
326 
328 
331  virtual void SetTitle(const vtkStdString& title);
334 
336 
339  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
341 
343 
355  vtkGetMacro(LogScaleActive, bool);
357 
359 
365  vtkGetMacro(LogScale, bool);
366  virtual void SetLogScale(bool logScale);
367  vtkBooleanMacro(LogScale, bool);
369 
371 
374  vtkSetMacro(GridVisible, bool);
375  vtkGetMacro(GridVisible, bool);
377 
379 
382  vtkSetMacro(LabelsVisible, bool);
383  vtkGetMacro(LabelsVisible, bool);
385 
387 
390  vtkSetMacro(RangeLabelsVisible, bool);
391  vtkGetMacro(RangeLabelsVisible, bool);
393 
395 
398  vtkSetMacro(LabelOffset, float);
399  vtkGetMacro(LabelOffset, float);
401 
403 
406  vtkSetMacro(TicksVisible, bool);
407  vtkGetMacro(TicksVisible, bool);
409 
411 
414  vtkSetMacro(AxisVisible, bool);
415  vtkGetMacro(AxisVisible, bool);
417 
419 
422  vtkSetMacro(TitleVisible, bool);
423  vtkGetMacro(TitleVisible, bool);
425 
427 
431  virtual void SetPrecision(int precision);
432  vtkGetMacro(Precision, int);
434 
438  enum
439  {
440  STANDARD_NOTATION = 0,
443  PRINTF_NOTATION
444  };
445 
447 
451  virtual void SetLabelFormat(const std::string& fmt);
452  vtkGetMacro(LabelFormat, std::string);
454 
456 
461  vtkSetMacro(RangeLabelFormat, std::string);
462  vtkGetMacro(RangeLabelFormat, std::string);
464 
466 
471  virtual void SetNotation(int notation);
472  vtkGetMacro(Notation, int);
474 
478  enum
479  {
480  AUTO = 0, // Automatically scale the axis to view all data that is visible.
481  FIXED, // Use a fixed axis range and make no attempt to rescale.
482  CUSTOM // Deprecated, use the tick label settings instead.
483  };
484 
486 
489  vtkSetMacro(Behavior, int);
490  vtkGetMacro(Behavior, int);
492 
494 
498  vtkGetObjectMacro(Pen, vtkPen);
500 
502 
506  vtkGetObjectMacro(GridPen, vtkPen);
508 
510 
517  vtkSetMacro(TickLabelAlgorithm, int);
518  vtkGetMacro(TickLabelAlgorithm, int);
520 
522 
526  vtkSetMacro(ScalingFactor, double);
527  vtkGetMacro(ScalingFactor, double);
528  vtkSetMacro(Shift, double);
529  vtkGetMacro(Shift, double);
531 
536  void Update() override;
537 
541  bool Paint(vtkContext2D* painter) override;
542 
549  virtual void AutoScale();
550 
555  virtual void RecalculateTickSpacing();
556 
562 
568 
573 
581  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
582 
590 
596  static double NiceNumber(double number, bool roundUp);
597 
602  static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
603 
608  virtual vtkStdString GenerateSimpleLabel(double val);
609 
613  bool Hit(const vtkContextMouseEvent& mouse) override;
614 
615 protected:
617  ~vtkAxis() override;
618 
627  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
628 
632  virtual void GenerateTickLabels(double min, double max);
633 
637  virtual void GenerateTickLabels();
638 
639  virtual void GenerateLabelFormat(int notation, double n);
640 
644  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
645 
650  double CalculateNiceMinMax(double& min, double& max);
651 
661  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
662 
674  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
675 
687  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
688 
693 
694  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
695  float* Point1; // The position of point 1 (usually the origin)
696  float* Point2; // The position of point 2 (usually the terminus)
697  vtkVector2f Position1, Position2;
698  double TickInterval; // Interval between tick marks in plot space
699  int NumberOfTicks; // The number of tick marks to draw
700  float TickLength; // The length of the tick marks
701  vtkTextProperty* LabelProperties; // Text properties for the labels.
702  double Minimum; // Minimum value of the axis
703  double Maximum; // Maximum values of the axis
704  double MinimumLimit; // Lowest possible value for Minimum
705  double MaximumLimit; // Highest possible value for Maximum
706  double UnscaledMinimum; // UnscaledMinimum value of the axis
707  double UnscaledMaximum; // UnscaledMaximum values of the axis
708  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
709  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
710  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
711  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
712  int Margins[2]; // Horizontal/vertical margins for the axis
713  vtkStdString Title; // The text label drawn on the axis
714  vtkTextProperty* TitleProperties; // Text properties for the axis title
715  bool LogScale; // *Should* the axis use a log scale?
716  bool LogScaleActive; // *Is* the axis using a log scale?
717  bool GridVisible; // Whether the grid for the axis should be drawn
718  bool LabelsVisible; // Should the axis labels be visible
719  bool RangeLabelsVisible; // Should range labels be visible?
720  float LabelOffset; // Offset of label from the tick mark
721  bool TicksVisible; // Should the tick marks be visible.
722  bool AxisVisible; // Should the axis line be visible.
723  bool TitleVisible; // Should the title be visible.
724  int Precision; // Numerical precision to use, defaults to 2.
725  int Notation; // The notation to use (standard, scientific, mixed)
726  std::string LabelFormat; // The printf-style format string used for labels.
727  std::string RangeLabelFormat; // The printf-style format string used for range labels.
728  int Behavior; // The behaviour of the axis (auto, fixed, custom).
729  float MaxLabel[2]; // The widest/tallest axis label.
730  bool TitleAppended; // Track if the title is updated when the label formats
731  // are changed in the Extended Axis Labeling algorithm
732 
734 
740  double Shift;
742 
747 
752 
757 
762 
767 
772 
778 
783 
787  bool Resized;
788 
793 
798 
799 private:
800  vtkAxis(const vtkAxis&) = delete;
801  void operator=(const vtkAxis&) = delete;
802 
806  bool InRange(double value);
807 };
808 
809 #endif // vtkAxis_h
takes care of drawing 2D axes
Definition: vtkAxis.h:81
virtual void SetUnscaledMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
bool Paint(vtkContext2D *painter) override
Paint event for the axis, called whenever the axis needs to be drawn.
virtual void SetMinimum(double minimum)
Set the logical minimum value of the axis, in plot coordinates.
vtkVector2f Position1
Definition: vtkAxis.h:697
vtkSetSmartPointerMacro(GridPen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
void GenerateLogScaleTickMarks(int order, double min=1.0, double max=9.0, bool detailLabels=true)
Generate tick marks for logarithmic scale for specific order of magnitude.
virtual void SetUnscaledMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual void GenerateTickLabels()
Generate tick labels from the supplied double array of tick positions.
bool TitleVisible
Definition: vtkAxis.h:723
void SetPoint1(float x, float y)
Set point 1 of the axis (in pixels), this is usually the origin.
double UnscaledMaximumLimit
Definition: vtkAxis.h:709
bool TitleAppended
Definition: vtkAxis.h:730
int Behavior
Definition: vtkAxis.h:728
static double NiceNumber(double number, bool roundUp)
Return a "nice number", often defined as 1, 2 or 5.
void SetPoint2(const vtkVector2f &pos)
Set point 2 of the axis (in pixels), this is usually the terminus.
vtkVector2f GetPosition2()
Get point 2 of the axis (in pixels), this is usually the terminus.
std::string RangeLabelFormat
Definition: vtkAxis.h:727
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a printf-style format string.
int Precision
Definition: vtkAxis.h:724
void Update() override
Update the geometry of the axis.
vtkRectf GetBoundingRect(vtkContext2D *painter)
Request the space the axes require to be drawn.
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:710
int Position
Definition: vtkAxis.h:694
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:777
virtual void SetNumberOfTicks(int numberOfTicks)
Set the number of tick marks for this axis.
virtual void SetLabelFormat(const std::string &fmt)
Get/Set the printf-style format string used when TickLabelAlgorithm is TICK_SIMPLE and Notation is PR...
virtual void GenerateLogSpacedLinearTicks(int order, double min, double max)
Generate logarithmically-spaced tick marks with linear-style labels.
bool Hit(const vtkContextMouseEvent &mouse) override
Return true if the supplied x, y coordinate is inside the item.
double CalculateNiceMinMax(double &min, double &max)
Calculate the next "nicest" numbers above and below the current minimum.
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:792
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the axis.
bool GridVisible
Definition: vtkAxis.h:717
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:740
double UnscaledMinimumLimit
Definition: vtkAxis.h:708
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:701
static double NiceMinMax(double &min, double &max, float pixelRange, float tickPixelSpacing)
Static function to calculate "nice" minimum, maximum, and tick spacing values.
float * Point2
Definition: vtkAxis.h:696
virtual void SetUnscaledRange(double range[2])
Set the logical range of the axis, in plot coordinates.
int NumberOfTicks
Definition: vtkAxis.h:699
vtkStdString Title
Definition: vtkAxis.h:713
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
@ FIXED
Definition: vtkAxis.h:481
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:787
double MinimumLimit
Definition: vtkAxis.h:704
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
double UnscaledMinimum
Definition: vtkAxis.h:706
float TickLength
Definition: vtkAxis.h:700
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
bool RangeLabelsVisible
Definition: vtkAxis.h:719
vtkSetSmartPointerMacro(Pen, vtkPen)
Set/get the vtkPen object that controls the way this axis is drawn.
virtual vtkStringArray * GetTickLabels()
A string array containing the tick labels for the axis.
vtkVector2f GetPosition1()
Get point 1 of the axis (in pixels), this is usually the origin.
double TickInterval
Definition: vtkAxis.h:698
virtual void SetMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
void SetPoint2(float x, float y)
Set point 2 of the axis (in pixels), this is usually the terminus.
virtual void SetPrecision(int precision)
Get/set the numerical precision to use, default is 2.
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:766
virtual void SetMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual vtkStdString GenerateSprintfLabel(double value, const std::string &format)
Generate label using a printf-style format string.
virtual void RecalculateTickSpacing()
Recalculate the spacing of the tick marks - typically useful to do after scaling the axis.
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:751
virtual vtkDoubleArray * GetTickPositions()
An array with the positions of the tick marks along the axis line.
virtual void SetUnscaledMinimum(double minimum)
Set the logical, unscaled minimum value of the axis, in plot coordinates.
virtual void SetRange(double range[2])
Set the logical range of the axis, in plot coordinates.
bool LabelsVisible
Definition: vtkAxis.h:718
void CalculateTitlePosition(vtkVector2f &out)
Calculate the position where the title of the axis would be drawn.
~vtkAxis() override
bool TicksVisible
Definition: vtkAxis.h:721
@ FIXED_NOTATION
Definition: vtkAxis.h:442
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:441
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:91
@ TOP
Definition: vtkAxis.h:95
@ BOTTOM
Definition: vtkAxis.h:93
@ RIGHT
Definition: vtkAxis.h:94
double Maximum
Definition: vtkAxis.h:703
virtual vtkStdString GenerateSimpleLabel(double val)
Generate a single label using the current settings when TickLabelAlgorithm is TICK_SIMPLE.
double Minimum
Definition: vtkAxis.h:702
virtual void GenerateTickLabels(double min, double max)
Calculate and assign nice labels/logical label positions.
int Notation
Definition: vtkAxis.h:725
virtual bool SetCustomTickPositions(vtkDoubleArray *positions, vtkStringArray *labels=nullptr)
Set the tick positions, and optionally custom tick labels.
virtual void GenerateLabelFormat(int notation, double n)
virtual void AutoScale()
Use this function to autoscale the axes after setting the minimum and maximum values.
virtual void SetUnscaledMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:739
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:756
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:711
float * Point1
Definition: vtkAxis.h:695
double MaximumLimit
Definition: vtkAxis.h:705
virtual void GetUnscaledRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:714
virtual void SetRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:746
void UpdateLogScaleActive(bool updateMinMaxFromUnscaled)
Update whether log scaling will be used for layout and rendering.
virtual vtkStdString GetTitle()
Get/set the title text of the axis.
std::string LabelFormat
Definition: vtkAxis.h:726
static vtkAxis * New()
Creates a 2D Chart object.
double LogScaleTickMark(double number, bool roundUp, bool &niceValue, int &order)
Return a tick mark for a logarithmic axis.
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:782
float LabelOffset
Definition: vtkAxis.h:720
bool AxisVisible
Definition: vtkAxis.h:722
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:771
virtual void SetUnscaledRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
double UnscaledMaximum
Definition: vtkAxis.h:707
bool LogScale
Definition: vtkAxis.h:715
virtual void SetMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual vtkFloatArray * GetTickScenePositions()
An array with the positions of the tick marks along the axis line.
virtual void SetLogScale(bool logScale)
Get/set whether the axis should attempt to use a log scale.
bool LogScaleActive
Definition: vtkAxis.h:716
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:797
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:761
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:67
base class for items that are part of a vtkContextScene.
data structure to represent mouse events.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:51
a simple class to control print indentation
Definition: vtkIndent.h:49
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:49
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
a vtkAbstractArray subclass for strings
represent text properties.
record modification and/or execution time
Definition: vtkTimeStamp.h:45
@ order
Definition: vtkX3D.h:446
@ value
Definition: vtkX3D.h:226
@ range
Definition: vtkX3D.h:244
@ position
Definition: vtkX3D.h:267
@ title
Definition: vtkX3D.h:506
@ string
Definition: vtkX3D.h:496
#define max(a, b)