VTK  9.0.1
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 
51 #ifndef vtkAxis_h
52 #define vtkAxis_h
53 
54 #include "vtkChartsCoreModule.h" // For export macro
55 #include "vtkContextItem.h"
56 #include "vtkRect.h" // For bounding rect
57 #include "vtkSmartPointer.h" // For vtkSmartPointer
58 #include "vtkStdString.h" // For vtkStdString ivars
59 #include "vtkVector.h" // For position variables
60 
61 class vtkContext2D;
62 class vtkPen;
63 class vtkFloatArray;
64 class vtkDoubleArray;
65 class vtkStringArray;
66 class vtkTextProperty;
67 
68 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
69 {
70 public:
71  vtkTypeMacro(vtkAxis, vtkContextItem);
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
78  enum Location
79  {
80  LEFT = 0,
83  TOP,
84  PARALLEL
85  };
86 
87  enum
88  {
89  TICK_SIMPLE = 0,
90  TICK_WILKINSON_EXTENDED
91  };
92 
96  static vtkAxis* New();
97 
99 
102  virtual void SetPosition(int position);
103  vtkGetMacro(Position, int);
105 
107 
110  void SetPoint1(const vtkVector2f& pos);
111  void SetPoint1(float x, float y);
113 
115 
118  vtkGetVector2Macro(Point1, float);
119  vtkVector2f GetPosition1();
121 
123 
126  void SetPoint2(const vtkVector2f& pos);
127  void SetPoint2(float x, float y);
129 
131 
134  vtkGetVector2Macro(Point2, float);
135  vtkVector2f GetPosition2();
137 
142  virtual void SetNumberOfTicks(int numberOfTicks);
143 
145 
148  vtkGetMacro(NumberOfTicks, int);
150 
152 
155  vtkSetMacro(TickLength, float);
156  vtkGetMacro(TickLength, float);
158 
160 
164  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
166 
172  virtual void SetMinimum(double minimum);
173 
175 
180  vtkGetMacro(Minimum, double);
182 
188  virtual void SetMaximum(double maximum);
189 
191 
196  vtkGetMacro(Maximum, double);
198 
204  virtual void SetUnscaledMinimum(double minimum);
205 
207 
210  vtkGetMacro(UnscaledMinimum, double);
212 
216  virtual void SetUnscaledMaximum(double maximum);
217 
219 
222  vtkGetMacro(UnscaledMaximum, double);
224 
226 
235  virtual void SetRange(double minimum, double maximum);
236  virtual void SetRange(double range[2]);
237  virtual void SetUnscaledRange(double minimum, double maximum);
238  virtual void SetUnscaledRange(double range[2]);
240 
242 
249  virtual void GetRange(double* range);
250  virtual void GetUnscaledRange(double* range);
252 
256  virtual void SetMinimumLimit(double lowest);
257 
259 
262  vtkGetMacro(MinimumLimit, double);
264 
268  virtual void SetMaximumLimit(double highest);
269 
271 
274  vtkGetMacro(MaximumLimit, double);
276 
280  virtual void SetUnscaledMinimumLimit(double lowest);
281 
283 
286  vtkGetMacro(UnscaledMinimumLimit, double);
288 
292  virtual void SetUnscaledMaximumLimit(double highest);
293 
295 
298  vtkGetMacro(UnscaledMaximumLimit, double);
300 
302 
305  vtkGetVector2Macro(Margins, int);
307 
309 
312  vtkSetVector2Macro(Margins, int);
314 
316 
319  virtual void SetTitle(const vtkStdString& title);
320  virtual vtkStdString GetTitle();
322 
324 
327  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
329 
331 
343  vtkGetMacro(LogScaleActive, bool);
345 
347 
353  vtkGetMacro(LogScale, bool);
354  virtual void SetLogScale(bool logScale);
355  vtkBooleanMacro(LogScale, bool);
357 
359 
362  vtkSetMacro(GridVisible, bool);
363  vtkGetMacro(GridVisible, bool);
365 
367 
370  vtkSetMacro(LabelsVisible, bool);
371  vtkGetMacro(LabelsVisible, bool);
373 
375 
378  vtkSetMacro(RangeLabelsVisible, bool);
379  vtkGetMacro(RangeLabelsVisible, bool);
381 
383 
386  vtkSetMacro(LabelOffset, float);
387  vtkGetMacro(LabelOffset, float);
389 
391 
394  vtkSetMacro(TicksVisible, bool);
395  vtkGetMacro(TicksVisible, bool);
397 
399 
402  vtkSetMacro(AxisVisible, bool);
403  vtkGetMacro(AxisVisible, bool);
405 
407 
410  vtkSetMacro(TitleVisible, bool);
411  vtkGetMacro(TitleVisible, bool);
413 
415 
419  virtual void SetPrecision(int precision);
420  vtkGetMacro(Precision, int);
422 
426  enum
427  {
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  {
468  AUTO = 0, // Automatically scale the axis to view all data that is visible.
469  FIXED, // Use a fixed axis range and make no attempt to rescale.
470  CUSTOM // Deprecated, use the tick label settings instead.
471  };
472 
474 
477  vtkSetMacro(Behavior, int);
478  vtkGetMacro(Behavior, int);
480 
482 
485  vtkGetObjectMacro(Pen, vtkPen);
487 
489 
492  vtkGetObjectMacro(GridPen, vtkPen);
494 
496 
503  vtkSetMacro(TickLabelAlgorithm, int);
504  vtkGetMacro(TickLabelAlgorithm, int);
506 
508 
512  vtkSetMacro(ScalingFactor, double);
513  vtkGetMacro(ScalingFactor, double);
514  vtkSetMacro(Shift, double);
515  vtkGetMacro(Shift, double);
517 
522  void Update() override;
523 
527  bool Paint(vtkContext2D* painter) override;
528 
535  virtual void AutoScale();
536 
541  virtual void RecalculateTickSpacing();
542 
547  virtual vtkDoubleArray* GetTickPositions();
548 
553  virtual vtkFloatArray* GetTickScenePositions();
554 
558  virtual vtkStringArray* GetTickLabels();
559 
567  virtual bool SetCustomTickPositions(vtkDoubleArray* positions, 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, float tickPixelSpacing);
589 
594  virtual vtkStdString GenerateSimpleLabel(double val);
595 
596 protected:
597  vtkAxis();
598  ~vtkAxis() override;
599 
608  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
609 
613  virtual void GenerateTickLabels(double min, double max);
614 
618  virtual void GenerateTickLabels();
619 
620  virtual void GenerateLabelFormat(int notation, double n);
621 
625  virtual vtkStdString GenerateSprintfLabel(double value, const std::string& format);
626 
631  double CalculateNiceMinMax(double& min, double& max);
632 
642  double LogScaleTickMark(double number, bool roundUp, bool& niceValue, int& order);
643 
655  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
656 
667  void GenerateLogScaleTickMarks(
668  int order, double min = 1.0, double max = 9.0, bool detailLabels = true);
669 
670  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
671  float* Point1; // The position of point 1 (usually the origin)
672  float* Point2; // The position of point 2 (usually the terminus)
673  vtkVector2f Position1, Position2;
674  double TickInterval; // Interval between tick marks in plot space
675  int NumberOfTicks; // The number of tick marks to draw
676  float TickLength; // The length of the tick marks
677  vtkTextProperty* LabelProperties; // Text properties for the labels.
678  double Minimum; // Minimum value of the axis
679  double Maximum; // Maximum values of the axis
680  double MinimumLimit; // Lowest possible value for Minimum
681  double MaximumLimit; // Highest possible value for Maximum
682  double UnscaledMinimum; // UnscaledMinimum value of the axis
683  double UnscaledMaximum; // UnscaledMaximum values of the axis
684  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
685  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
686  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
687  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
688  int Margins[2]; // Horizontal/vertical margins for the axis
689  vtkStdString Title; // The text label drawn on the axis
690  vtkTextProperty* TitleProperties; // Text properties for the axis title
691  bool LogScale; // *Should* the axis use a log scale?
692  bool LogScaleActive; // *Is* the axis using a log scale?
693  bool GridVisible; // Whether the grid for the axis should be drawn
694  bool LabelsVisible; // Should the axis labels be visible
695  bool RangeLabelsVisible; // Should range labels be visible?
696  float LabelOffset; // Offset of label from the tick mark
697  bool TicksVisible; // Should the tick marks be visible.
698  bool AxisVisible; // Should the axis line be visible.
699  bool TitleVisible; // Should the title be visible.
700  int Precision; // Numerical precision to use, defaults to 2.
701  int Notation; // The notation to use (standard, scientific, mixed)
702  std::string LabelFormat; // The printf-style format string used for labels.
703  std::string RangeLabelFormat; // The printf-style format string used for range labels.
704  int Behavior; // The behaviour of the axis (auto, fixed, custom).
705  float MaxLabel[2]; // The widest/tallest axis label.
706  bool TitleAppended; // Track if the title is updated when the label formats
707  // are changed in the Extended Axis Labeling algorithm
708 
710 
716  double Shift;
718 
723 
728 
733 
738 
743 
748 
754 
759 
763  bool Resized;
764 
769 
774 
775 private:
776  vtkAxis(const vtkAxis&) = delete;
777  void operator=(const vtkAxis&) = delete;
778 
782  bool InRange(double value);
783 };
784 
785 #endif // vtkAxis_h
vtkAxis::TickMarksDirty
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:758
vtkAxis::Point1
float * Point1
Definition: vtkAxis.h:671
vtkStdString.h
vtkAxis::Point2
float * Point2
Definition: vtkAxis.h:672
vtkAxis::Title
vtkStdString Title
Definition: vtkAxis.h:689
vtkAxis::TickScenePositions
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:742
vtkAxis::TickPositions
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:737
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkAxis::CustomTickLabels
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:722
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
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:753
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:32
vtkAxis::Shift
double Shift
Definition: vtkAxis.h:716
vtkX3D::range
@ range
Definition: vtkX3D.h:244
vtkSmartPointer< vtkDoubleArray >
vtkAxis::Position
int Position
Definition: vtkAxis.h:670
vtkVector.h
vtkAxis::TickLength
float TickLength
Definition: vtkAxis.h:676
vtkAxis::UnscaledMaximum
double UnscaledMaximum
Definition: vtkAxis.h:683
vtkAxis::Position2
vtkVector2f Position2
Definition: vtkAxis.h:673
vtkAxis::TitleVisible
bool TitleVisible
Definition: vtkAxis.h:699
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
vtkContextItem.h
vtkAxis::UnscaledMinimum
double UnscaledMinimum
Definition: vtkAxis.h:682
vtkAxis::LogScaleActive
bool LogScaleActive
Definition: vtkAxis.h:692
vtkAxis::TickLabelAlgorithm
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:768
vtkAxis::Minimum
double Minimum
Definition: vtkAxis.h:678
vtkAxis::Pen
vtkPen * Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:727
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkAxis::MinimumLimit
double MinimumLimit
Definition: vtkAxis.h:680
vtkAxis::LabelOffset
float LabelOffset
Definition: vtkAxis.h:696
vtkAxis::Precision
int Precision
Definition: vtkAxis.h:700
vtkX3D::position
@ position
Definition: vtkX3D.h:267
vtkAxis::BuildTime
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:773
vtkX3D::title
@ title
Definition: vtkX3D.h:506
vtkAxis::NonLogUnscaledMinLimit
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:686
vtkAxis::Behavior
int Behavior
Definition: vtkAxis.h:704
vtkAxis::ScalingFactor
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:715
vtkAxis::AxisVisible
bool AxisVisible
Definition: vtkAxis.h:698
vtkAxis::TOP
@ TOP
Definition: vtkAxis.h:83
vtkAxis::MaximumLimit
double MaximumLimit
Definition: vtkAxis.h:681
vtkAxis::TicksVisible
bool TicksVisible
Definition: vtkAxis.h:697
vtkRect.h
vtkAxis::Location
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:78
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkAxis::BOTTOM
@ BOTTOM
Definition: vtkAxis.h:81
vtkAxis::TitleProperties
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:690
vtkSmartPointer.h
vtkAxis::NonLogUnscaledMaxLimit
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:687
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:706
vtkAxis::GridPen
vtkPen * GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:732
vtkAxis::UnscaledMinimumLimit
double UnscaledMinimumLimit
Definition: vtkAxis.h:684
vtkAxis::Maximum
double Maximum
Definition: vtkAxis.h:679
vtkAxis::LogScale
bool LogScale
Definition: vtkAxis.h:691
vtkAxis::GridVisible
bool GridVisible
Definition: vtkAxis.h:693
vtkX3D::order
@ order
Definition: vtkX3D.h:446
vtkAxis::NumberOfTicks
int NumberOfTicks
Definition: vtkAxis.h:675
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:33
vtkAxis::RangeLabelFormat
std::string RangeLabelFormat
Definition: vtkAxis.h:703
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:31
vtkAxis::TickInterval
double TickInterval
Definition: vtkAxis.h:674
vtkAxis::FIXED_NOTATION
@ FIXED_NOTATION
Definition: vtkAxis.h:430
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkAxis::LabelFormat
std::string LabelFormat
Definition: vtkAxis.h:702
vtkAxis::RangeLabelsVisible
bool RangeLabelsVisible
Definition: vtkAxis.h:695
vtkAxis::Resized
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:763
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:68
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:36
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:35
vtkAxis::Notation
int Notation
Definition: vtkAxis.h:701
vtkAxis::TickLabels
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:747
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkAxis::SCIENTIFIC_NOTATION
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:429
vtkAxis::FIXED
@ FIXED
Definition: vtkAxis.h:469
vtkAxis::UnscaledMaximumLimit
double UnscaledMaximumLimit
Definition: vtkAxis.h:685
vtkAxis::RIGHT
@ RIGHT
Definition: vtkAxis.h:82
vtkRectf
Definition: vtkRect.h:326
vtkVector2f
Definition: vtkVector.h:432
vtkAxis::LabelProperties
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:677
vtkAbstractContextItem::Update
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
vtkAxis::LabelsVisible
bool LabelsVisible
Definition: vtkAxis.h:694