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 
412  virtual void SetPrecision(int precision);
413  vtkGetMacro(Precision, int);
415 
419  enum {
420  STANDARD_NOTATION = 0,
423  PRINTF_NOTATION
424  };
425 
427 
431  virtual void SetLabelFormat(const std::string &fmt);
432  vtkGetMacro(LabelFormat, std::string);
434 
436 
441  vtkSetMacro(RangeLabelFormat, std::string);
442  vtkGetMacro(RangeLabelFormat, std::string);
444 
446 
451  virtual void SetNotation(int notation);
452  vtkGetMacro(Notation, int);
454 
458  enum {
459  AUTO = 0, // Automatically scale the axis to view all data that is visible.
460  FIXED, // Use a fixed axis range and make no attempt to rescale.
461  CUSTOM // Deprecated, use the tick label settings instead.
462  };
463 
465 
468  vtkSetMacro(Behavior, int);
469  vtkGetMacro(Behavior, int);
471 
473 
476  vtkGetObjectMacro(Pen, vtkPen);
478 
480 
483  vtkGetObjectMacro(GridPen, vtkPen);
485 
487 
494  vtkSetMacro(TickLabelAlgorithm, int)
495  vtkGetMacro(TickLabelAlgorithm, int)
497 
499 
503  vtkSetMacro(ScalingFactor, double)
504  vtkGetMacro(ScalingFactor, double)
505  vtkSetMacro(Shift, double)
506  vtkGetMacro(Shift, double)
508 
513  void Update() override;
514 
518  bool Paint(vtkContext2D *painter) override;
519 
526  virtual void AutoScale();
527 
532  virtual void RecalculateTickSpacing();
533 
538  virtual vtkDoubleArray* GetTickPositions();
539 
544  virtual vtkFloatArray* GetTickScenePositions();
545 
549  virtual vtkStringArray* GetTickLabels();
550 
558  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
559  vtkStringArray* labels = nullptr);
560 
567  vtkRectf GetBoundingRect(vtkContext2D* painter);
568 
574  static double NiceNumber(double number, bool roundUp);
575 
580  static double NiceMinMax(double &min, double &max, float pixelRange,
581  float tickPixelSpacing);
582 
587  vtkStdString GenerateSimpleLabel(double val);
588 
589 protected:
590  vtkAxis();
591  ~vtkAxis() override;
592 
601  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
602 
606  void GenerateTickLabels(double min, double max);
607 
611  void GenerateTickLabels();
612 
613  void GenerateLabelFormat(int notation, double n);
614 
618  vtkStdString GenerateSprintfLabel(double value, const std::string & format);
619 
624  double CalculateNiceMinMax(double &min, double &max);
625 
635  double LogScaleTickMark(double number,
636  bool roundUp,
637  bool &niceValue,
638  int &order);
639 
651  void GenerateLogSpacedLinearTicks(int order, double min, double max);
652 
663  void GenerateLogScaleTickMarks(int order,
664  double min = 1.0,
665  double max = 9.0,
666  bool detailLabels = true);
667 
668  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
669  float *Point1; // The position of point 1 (usually the origin)
670  float *Point2; // The position of point 2 (usually the terminus)
671  vtkVector2f Position1, Position2;
672  double TickInterval; // Interval between tick marks in plot space
673  int NumberOfTicks; // The number of tick marks to draw
674  float TickLength; // The length of the tick marks
675  vtkTextProperty* LabelProperties; // Text properties for the labels.
676  double Minimum; // Minimum value of the axis
677  double Maximum; // Maximum values of the axis
678  double MinimumLimit; // Lowest possible value for Minimum
679  double MaximumLimit; // Highest possible value for Maximum
680  double UnscaledMinimum; // UnscaledMinimum value of the axis
681  double UnscaledMaximum; // UnscaledMaximum values of the axis
682  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
683  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
684  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
685  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
686  int Margins[2]; // Horizontal/vertical margins for the axis
687  vtkStdString Title; // The text label drawn on the axis
688  vtkTextProperty* TitleProperties; // Text properties for the axis title
689  bool LogScale; // *Should* the axis use a log scale?
690  bool LogScaleActive; // *Is* the axis using a log scale?
691  bool GridVisible; // Whether the grid for the axis should be drawn
692  bool LabelsVisible; // Should the axis labels be visible
693  bool RangeLabelsVisible; // Should range labels be visible?
694  float LabelOffset; // Offset of label from the tick mark
695  bool TicksVisible; // Should the tick marks be visible.
696  bool AxisVisible; // Should the axis line be visible.
697  int Precision; // Numerical precision to use, defaults to 2.
698  int Notation; // The notation to use (standard, scientific, mixed)
699  std::string LabelFormat; // The printf-style format string used for labels.
700  std::string RangeLabelFormat; // The printf-style format string used for range labels.
701  int Behavior; // The behaviour of the axis (auto, fixed, custom).
702  float MaxLabel[2]; // The widest/tallest axis label.
703  bool TitleAppended; // Track if the title is updated when the label formats
704  // are changed in the Extended Axis Labeling algorithm
705 
707 
713  double Shift;
715 
720 
725 
730 
735 
740 
745 
751 
756 
760  bool Resized;
761 
766 
771 
772 private:
773  vtkAxis(const vtkAxis &) = delete;
774  void operator=(const vtkAxis &) = delete;
775 
779  bool InRange(double value);
780 
781 };
782 
783 #endif //vtkAxis_h
double MaximumLimit
Definition: vtkAxis.h:679
double TickInterval
Definition: vtkAxis.h:672
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:675
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:40
bool LabelsVisible
Definition: vtkAxis.h:692
float * Point1
Definition: vtkAxis.h:669
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:684
vtkPen * Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:724
bool LogScale
Definition: vtkAxis.h:689
base class for items that are part of a vtkContextScene.
int Notation
Definition: vtkAxis.h:698
double MinimumLimit
Definition: vtkAxis.h:678
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
std::string RangeLabelFormat
Definition: vtkAxis.h:700
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:713
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:687
float TickLength
Definition: vtkAxis.h:674
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:765
bool GridVisible
Definition: vtkAxis.h:691
int Precision
Definition: vtkAxis.h:697
float * Point2
Definition: vtkAxis.h:670
dynamic, self-adjusting array of double
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:770
double UnscaledMinimumLimit
Definition: vtkAxis.h:682
double UnscaledMaximumLimit
Definition: vtkAxis.h:683
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:760
bool RangeLabelsVisible
Definition: vtkAxis.h:693
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
bool AxisVisible
Definition: vtkAxis.h:696
bool LogScaleActive
Definition: vtkAxis.h:690
takes care of drawing 2D axes
Definition: vtkAxis.h:71
double Maximum
Definition: vtkAxis.h:677
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:744
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Position
Definition: vtkAxis.h:668
int Behavior
Definition: vtkAxis.h:701
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
float LabelOffset
Definition: vtkAxis.h:694
represent text properties.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
bool TitleAppended
Definition: vtkAxis.h:703
vtkPen * GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:729
double Minimum
Definition: vtkAxis.h:676
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:712
std::string LabelFormat
Definition: vtkAxis.h:699
vtkVector2f Position2
Definition: vtkAxis.h:671
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:688
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:719
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:734
bool TicksVisible
Definition: vtkAxis.h:695
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:750
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:685
int NumberOfTicks
Definition: vtkAxis.h:673
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
double UnscaledMaximum
Definition: vtkAxis.h:681
#define max(a, b)
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:739
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:755
double UnscaledMinimum
Definition: vtkAxis.h:680