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 
54 #ifndef vtkAxis_h
55 #define vtkAxis_h
56 
57 #include "vtkChartsCoreModule.h" // For export macro
58 #include "vtkContextItem.h"
59 #include "vtkPen.h" // For vtkPen
60 #include "vtkRect.h" // For bounding rect
61 #include "vtkSmartPointer.h" // For vtkSmartPointer
62 #include "vtkStdString.h" // For vtkStdString ivars
63 #include "vtkVector.h" // For position variables
64 
65 class vtkContext2D;
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  {
83  LEFT = 0,
86  TOP,
87  PARALLEL
88  };
89 
90  enum
91  {
92  TICK_SIMPLE = 0,
93  TICK_WILKINSON_EXTENDED
94  };
95 
99  static vtkAxis* New();
100 
102 
105  virtual void SetPosition(int position);
106  vtkGetMacro(Position, int);
108 
110 
113  void SetPoint1(const vtkVector2f& pos);
114  void SetPoint1(float x, float y);
116 
118 
121  vtkGetVector2Macro(Point1, float);
122  vtkVector2f GetPosition1();
124 
126 
129  void SetPoint2(const vtkVector2f& pos);
130  void SetPoint2(float x, float y);
132 
134 
137  vtkGetVector2Macro(Point2, float);
138  vtkVector2f GetPosition2();
140 
145  virtual void SetNumberOfTicks(int numberOfTicks);
146 
148 
151  vtkGetMacro(NumberOfTicks, int);
153 
155 
158  vtkSetMacro(TickLength, float);
159  vtkGetMacro(TickLength, float);
161 
163 
167  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
169 
175  virtual void SetMinimum(double minimum);
176 
178 
183  vtkGetMacro(Minimum, double);
185 
191  virtual void SetMaximum(double maximum);
192 
194 
199  vtkGetMacro(Maximum, double);
201 
207  virtual void SetUnscaledMinimum(double minimum);
208 
210 
213  vtkGetMacro(UnscaledMinimum, double);
215 
219  virtual void SetUnscaledMaximum(double maximum);
220 
222 
225  vtkGetMacro(UnscaledMaximum, double);
227 
229 
238  virtual void SetRange(double minimum, double maximum);
239  virtual void SetRange(double range[2]);
240  virtual void SetUnscaledRange(double minimum, double maximum);
241  virtual void SetUnscaledRange(double range[2]);
243 
245 
252  virtual void GetRange(double* range);
253  virtual void GetUnscaledRange(double* range);
255 
259  virtual void SetMinimumLimit(double lowest);
260 
262 
265  vtkGetMacro(MinimumLimit, double);
267 
271  virtual void SetMaximumLimit(double highest);
272 
274 
277  vtkGetMacro(MaximumLimit, double);
279 
283  virtual void SetUnscaledMinimumLimit(double lowest);
284 
286 
289  vtkGetMacro(UnscaledMinimumLimit, double);
291 
295  virtual void SetUnscaledMaximumLimit(double highest);
296 
298 
301  vtkGetMacro(UnscaledMaximumLimit, double);
303 
305 
308  vtkGetVector2Macro(Margins, int);
310 
312 
315  vtkSetVector2Macro(Margins, int);
317 
319 
322  virtual void SetTitle(const vtkStdString& title);
323  virtual vtkStdString GetTitle();
325 
327 
330  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
332 
334 
346  vtkGetMacro(LogScaleActive, bool);
348 
350 
356  vtkGetMacro(LogScale, bool);
357  virtual void SetLogScale(bool logScale);
358  vtkBooleanMacro(LogScale, bool);
360 
362 
365  vtkSetMacro(GridVisible, bool);
366  vtkGetMacro(GridVisible, bool);
368 
370 
373  vtkSetMacro(LabelsVisible, bool);
374  vtkGetMacro(LabelsVisible, bool);
376 
378 
381  vtkSetMacro(RangeLabelsVisible, bool);
382  vtkGetMacro(RangeLabelsVisible, bool);
384 
386 
389  vtkSetMacro(LabelOffset, float);
390  vtkGetMacro(LabelOffset, float);
392 
394 
397  vtkSetMacro(TicksVisible, bool);
398  vtkGetMacro(TicksVisible, bool);
400 
402 
405  vtkSetMacro(AxisVisible, bool);
406  vtkGetMacro(AxisVisible, bool);
408 
410 
413  vtkSetMacro(TitleVisible, bool);
414  vtkGetMacro(TitleVisible, bool);
416 
418 
422  virtual void SetPrecision(int precision);
423  vtkGetMacro(Precision, int);
425 
429  enum
430  {
431  STANDARD_NOTATION = 0,
434  PRINTF_NOTATION
435  };
436 
438 
442  virtual void SetLabelFormat(const std::string& fmt);
443  vtkGetMacro(LabelFormat, std::string);
445 
447 
452  vtkSetMacro(RangeLabelFormat, std::string);
453  vtkGetMacro(RangeLabelFormat, std::string);
455 
457 
462  virtual void SetNotation(int notation);
463  vtkGetMacro(Notation, int);
465 
469  enum
470  {
471  AUTO = 0, // Automatically scale the axis to view all data that is visible.
472  FIXED, // Use a fixed axis range and make no attempt to rescale.
473  CUSTOM // Deprecated, use the tick label settings instead.
474  };
475 
477 
480  vtkSetMacro(Behavior, int);
481  vtkGetMacro(Behavior, int);
483 
485 
488  vtkSetSmartPointerMacro(Pen, vtkPen);
489  vtkGetObjectMacro(Pen, vtkPen);
491 
493 
496  vtkSetSmartPointerMacro(GridPen, vtkPen);
497  vtkGetObjectMacro(GridPen, vtkPen);
499 
501 
508  vtkSetMacro(TickLabelAlgorithm, int);
509  vtkGetMacro(TickLabelAlgorithm, int);
511 
513 
517  vtkSetMacro(ScalingFactor, double);
518  vtkGetMacro(ScalingFactor, double);
519  vtkSetMacro(Shift, double);
520  vtkGetMacro(Shift, double);
522 
527  void Update() override;
528 
532  bool Paint(vtkContext2D* painter) override;
533 
540  virtual void AutoScale();
541 
546  virtual void RecalculateTickSpacing();
547 
552  virtual vtkDoubleArray* GetTickPositions();
553 
558  virtual vtkFloatArray* GetTickScenePositions();
559 
563  virtual vtkStringArray* GetTickLabels();
564 
572  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, vtkStringArray* labels = nullptr);
573 
580  vtkRectf GetBoundingRect(vtkContext2D* painter);
581 
587  static double NiceNumber(double number, bool roundUp);
588 
593  static double NiceMinMax(double& min, double& max, float pixelRange, float tickPixelSpacing);
594 
599  virtual vtkStdString GenerateSimpleLabel(double val);
600 
604  bool Hit(const vtkContextMouseEvent& mouse) override;
605 
606 protected:
607  vtkAxis();
608  ~vtkAxis() override;
609 
618  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
619 
623  virtual void GenerateTickLabels(double min, double max);
624 
628  virtual void GenerateTickLabels();
629 
630  virtual void GenerateLabelFormat(int notation, double n);
631 
635  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
636 
641  double CalculateNiceMinMax(double& min, double& max);
642 
652  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
653 
665  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
666 
677  void GenerateLogScaleTickMarks(
678  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
679 
683  void CalculateTitlePosition(vtkVector2f& out);
684 
685  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
686  float* Point1; // The position of point 1 (usually the origin)
687  float* Point2; // The position of point 2 (usually the terminus)
688  vtkVector2f Position1, Position2;
689  double TickInterval; // Interval between tick marks in plot space
690  int NumberOfTicks; // The number of tick marks to draw
691  float TickLength; // The length of the tick marks
692  vtkTextProperty* LabelProperties; // Text properties for the labels.
693  double Minimum; // Minimum value of the axis
694  double Maximum; // Maximum values of the axis
695  double MinimumLimit; // Lowest possible value for Minimum
696  double MaximumLimit; // Highest possible value for Maximum
697  double UnscaledMinimum; // UnscaledMinimum value of the axis
698  double UnscaledMaximum; // UnscaledMaximum values of the axis
699  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
700  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
701  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
702  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
703  int Margins[2]; // Horizontal/vertical margins for the axis
704  vtkStdString Title; // The text label drawn on the axis
705  vtkTextProperty* TitleProperties; // Text properties for the axis title
706  bool LogScale; // *Should* the axis use a log scale?
707  bool LogScaleActive; // *Is* the axis using a log scale?
708  bool GridVisible; // Whether the grid for the axis should be drawn
709  bool LabelsVisible; // Should the axis labels be visible
710  bool RangeLabelsVisible; // Should range labels be visible?
711  float LabelOffset; // Offset of label from the tick mark
712  bool TicksVisible; // Should the tick marks be visible.
713  bool AxisVisible; // Should the axis line be visible.
714  bool TitleVisible; // Should the title be visible.
715  int Precision; // Numerical precision to use, defaults to 2.
716  int Notation; // The notation to use (standard, scientific, mixed)
717  std::string LabelFormat; // The printf-style format string used for labels.
718  std::string RangeLabelFormat; // The printf-style format string used for range labels.
719  int Behavior; // The behaviour of the axis (auto, fixed, custom).
720  float MaxLabel[2]; // The widest/tallest axis label.
721  bool TitleAppended; // Track if the title is updated when the label formats
722  // are changed in the Extended Axis Labeling algorithm
723 
725 
731  double Shift;
733 
738 
743 
748 
753 
758 
763 
769 
774 
778  bool Resized;
779 
784 
789 
790 private:
791  vtkAxis(const vtkAxis&) = delete;
792  void operator=(const vtkAxis&) = delete;
793 
797  bool InRange(double value);
798 };
799 
800 #endif // vtkAxis_h
double MaximumLimit
Definition: vtkAxis.h:696
double TickInterval
Definition: vtkAxis.h:689
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:692
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:81
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
bool LabelsVisible
Definition: vtkAxis.h:709
float * Point1
Definition: vtkAxis.h:686
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:701
bool LogScale
Definition: vtkAxis.h:706
base class for items that are part of a vtkContextScene.
int Notation
Definition: vtkAxis.h:716
double MinimumLimit
Definition: vtkAxis.h:695
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
std::string RangeLabelFormat
Definition: vtkAxis.h:718
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:731
record modification and/or execution time
Definition: vtkTimeStamp.h:35
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:41
a vtkAbstractArray subclass for strings
vtkStdString Title
Definition: vtkAxis.h:704
float TickLength
Definition: vtkAxis.h:691
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:783
bool GridVisible
Definition: vtkAxis.h:708
int Precision
Definition: vtkAxis.h:715
float * Point2
Definition: vtkAxis.h:687
dynamic, self-adjusting array of double
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:788
double UnscaledMinimumLimit
Definition: vtkAxis.h:699
double UnscaledMaximumLimit
Definition: vtkAxis.h:700
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:778
bool RangeLabelsVisible
Definition: vtkAxis.h:710
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
bool AxisVisible
Definition: vtkAxis.h:713
bool LogScaleActive
Definition: vtkAxis.h:707
takes care of drawing 2D axes
Definition: vtkAxis.h:71
double Maximum
Definition: vtkAxis.h:694
data structure to represent mouse events.
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:762
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Position
Definition: vtkAxis.h:685
int Behavior
Definition: vtkAxis.h:719
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
float LabelOffset
Definition: vtkAxis.h:711
represent text properties.
bool TitleAppended
Definition: vtkAxis.h:721
double Minimum
Definition: vtkAxis.h:693
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:730
vtkSmartPointer< vtkPen > GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:747
std::string LabelFormat
Definition: vtkAxis.h:717
bool TitleVisible
Definition: vtkAxis.h:714
vtkVector2f Position2
Definition: vtkAxis.h:688
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:705
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:737
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:752
virtual bool Hit(const vtkContextMouseEvent &mouse)
Return true if the supplied x, y coordinate is inside the item.
bool TicksVisible
Definition: vtkAxis.h:712
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:768
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:702
int NumberOfTicks
Definition: vtkAxis.h:690
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
double UnscaledMaximum
Definition: vtkAxis.h:698
vtkSmartPointer< vtkPen > Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:742
#define max(a, b)
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:757
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:773
double UnscaledMinimum
Definition: vtkAxis.h:697