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 
51 #ifndef vtkAxis_h
52 #define vtkAxis_h
53 
54 #include "vtkChartsCoreModule.h" // For export macro
55 #include "vtkContextItem.h"
56 #include "vtkSmartPointer.h" // For vtkSmartPointer
57 #include "vtkVector.h" // For position variables
58 #include "vtkRect.h" // For bounding rect
59 #include "vtkStdString.h" // For vtkStdString ivars
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  LEFT = 0,
82  TOP,
83  PARALLEL
84  };
85 
86  enum {
87  TICK_SIMPLE = 0,
88  TICK_WILKINSON_EXTENDED
89  };
90 
94  static vtkAxis *New();
95 
97 
100  virtual void SetPosition(int position);
101  vtkGetMacro(Position, int);
103 
105 
108  void SetPoint1(const vtkVector2f& pos);
109  void SetPoint1(float x, float y);
111 
113 
116  vtkGetVector2Macro(Point1, float);
117  vtkVector2f GetPosition1();
119 
121 
124  void SetPoint2(const vtkVector2f& pos);
125  void SetPoint2(float x, float y);
127 
129 
132  vtkGetVector2Macro(Point2, float);
133  vtkVector2f GetPosition2();
135 
140  virtual void SetNumberOfTicks(int numberOfTicks);
141 
143 
146  vtkGetMacro(NumberOfTicks, int);
148 
150 
153  vtkSetMacro(TickLength, float);
154  vtkGetMacro(TickLength, float);
156 
158 
162  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
164 
170  virtual void SetMinimum(double minimum);
171 
173 
178  vtkGetMacro(Minimum, double);
180 
186  virtual void SetMaximum(double maximum);
187 
189 
194  vtkGetMacro(Maximum, double);
196 
202  virtual void SetUnscaledMinimum(double minimum);
203 
205 
208  vtkGetMacro(UnscaledMinimum, double);
210 
214  virtual void SetUnscaledMaximum(double maximum);
215 
217 
220  vtkGetMacro(UnscaledMaximum, double);
222 
224 
233  virtual void SetRange(double minimum, double maximum);
234  virtual void SetRange(double range[2]);
235  virtual void SetUnscaledRange(double minimum, double maximum);
236  virtual void SetUnscaledRange(double range[2]);
238 
240 
247  virtual void GetRange(double *range);
248  virtual void GetUnscaledRange(double *range);
250 
254  virtual void SetMinimumLimit(double lowest);
255 
257 
260  vtkGetMacro(MinimumLimit, double);
262 
266  virtual void SetMaximumLimit(double highest);
267 
269 
272  vtkGetMacro(MaximumLimit, double);
274 
278  virtual void SetUnscaledMinimumLimit(double lowest);
279 
281 
284  vtkGetMacro(UnscaledMinimumLimit, double);
286 
290  virtual void SetUnscaledMaximumLimit(double highest);
291 
293 
296  vtkGetMacro(UnscaledMaximumLimit, double);
298 
300 
303  vtkGetVector2Macro(Margins, int);
305 
307 
310  vtkSetVector2Macro(Margins, int);
312 
314 
317  virtual void SetTitle(const vtkStdString &title);
318  virtual vtkStdString GetTitle();
320 
322 
325  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
327 
329 
341  vtkGetMacro(LogScaleActive, bool);
343 
345 
351  vtkGetMacro(LogScale, bool);
352  virtual void SetLogScale(bool logScale);
353  vtkBooleanMacro(LogScale,bool);
355 
357 
360  vtkSetMacro(GridVisible, bool);
361  vtkGetMacro(GridVisible, bool);
363 
365 
368  vtkSetMacro(LabelsVisible, bool);
369  vtkGetMacro(LabelsVisible, bool);
371 
373 
376  vtkSetMacro(RangeLabelsVisible, bool);
377  vtkGetMacro(RangeLabelsVisible, bool);
379 
381 
384  vtkSetMacro(LabelOffset, float);
385  vtkGetMacro(LabelOffset, float);
387 
389 
392  vtkSetMacro(TicksVisible, bool);
393  vtkGetMacro(TicksVisible, bool);
395 
397 
400  vtkSetMacro(AxisVisible, bool);
401  vtkGetMacro(AxisVisible, bool);
403 
405 
408  vtkSetMacro(TitleVisible, bool);
409  vtkGetMacro(TitleVisible, bool);
411 
413 
417  virtual void SetPrecision(int precision);
418  vtkGetMacro(Precision, int);
420 
424  enum {
425  STANDARD_NOTATION = 0,
428  PRINTF_NOTATION
429  };
430 
432 
436  virtual void SetLabelFormat(const std::string &fmt);
437  vtkGetMacro(LabelFormat, std::string);
439 
441 
446  vtkSetMacro(RangeLabelFormat, std::string);
447  vtkGetMacro(RangeLabelFormat, std::string);
449 
451 
456  virtual void SetNotation(int notation);
457  vtkGetMacro(Notation, int);
459 
463  enum {
464  AUTO = 0, // Automatically scale the axis to view all data that is visible.
465  FIXED, // Use a fixed axis range and make no attempt to rescale.
466  CUSTOM // Deprecated, use the tick label settings instead.
467  };
468 
470 
473  vtkSetMacro(Behavior, int);
474  vtkGetMacro(Behavior, int);
476 
478 
481  vtkGetObjectMacro(Pen, vtkPen);
483 
485 
488  vtkGetObjectMacro(GridPen, vtkPen);
490 
492 
499  vtkSetMacro(TickLabelAlgorithm, int)
500  vtkGetMacro(TickLabelAlgorithm, int)
502 
504 
508  vtkSetMacro(ScalingFactor, double)
509  vtkGetMacro(ScalingFactor, double)
510  vtkSetMacro(Shift, double)
511  vtkGetMacro(Shift, double)
513 
518  void Update() override;
519 
523  bool Paint(vtkContext2D *painter) override;
524 
531  virtual void AutoScale();
532 
537  virtual void RecalculateTickSpacing();
538 
543  virtual vtkDoubleArray* GetTickPositions();
544 
549  virtual vtkFloatArray* GetTickScenePositions();
550 
554  virtual vtkStringArray* GetTickLabels();
555 
563  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
564  vtkStringArray* labels = nullptr);
565 
572  vtkRectf GetBoundingRect(vtkContext2D* painter);
573 
579  static double NiceNumber(double number, bool roundUp);
580 
585  static double NiceMinMax(double &min, double &max, float pixelRange,
586  float tickPixelSpacing);
587 
592  virtual vtkStdString GenerateSimpleLabel(double val);
593 
594 protected:
595  vtkAxis();
596  ~vtkAxis() override;
597 
606  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
607 
611  void GenerateTickLabels(double min, double max);
612 
616  void GenerateTickLabels();
617 
618  virtual void GenerateLabelFormat(int notation, double n);
619 
623  virtual vtkStdString GenerateSprintfLabel(double value, const std::string & format);
624 
629  double CalculateNiceMinMax(double &min, double &max);
630 
640  double LogScaleTickMark(double number,
641  bool roundUp,
642  bool &niceValue,
643  int &order);
644 
656  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
657 
668  void GenerateLogScaleTickMarks(int order,
669  double min = 1.0,
670  double max = 9.0,
671  bool detailLabels = true);
672 
673  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
674  float *Point1; // The position of point 1 (usually the origin)
675  float *Point2; // The position of point 2 (usually the terminus)
676  vtkVector2f Position1, Position2;
677  double TickInterval; // Interval between tick marks in plot space
678  int NumberOfTicks; // The number of tick marks to draw
679  float TickLength; // The length of the tick marks
680  vtkTextProperty* LabelProperties; // Text properties for the labels.
681  double Minimum; // Minimum value of the axis
682  double Maximum; // Maximum values of the axis
683  double MinimumLimit; // Lowest possible value for Minimum
684  double MaximumLimit; // Highest possible value for Maximum
685  double UnscaledMinimum; // UnscaledMinimum value of the axis
686  double UnscaledMaximum; // UnscaledMaximum values of the axis
687  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
688  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
689  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
690  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
691  int Margins[2]; // Horizontal/vertical margins for the axis
692  vtkStdString Title; // The text label drawn on the axis
693  vtkTextProperty* TitleProperties; // Text properties for the axis title
694  bool LogScale; // *Should* the axis use a log scale?
695  bool LogScaleActive; // *Is* the axis using a log scale?
696  bool GridVisible; // Whether the grid for the axis should be drawn
697  bool LabelsVisible; // Should the axis labels be visible
698  bool RangeLabelsVisible; // Should range labels be visible?
699  float LabelOffset; // Offset of label from the tick mark
700  bool TicksVisible; // Should the tick marks be visible.
701  bool AxisVisible; // Should the axis line be visible.
702  bool TitleVisible; // Should the title be visible.
703  int Precision; // Numerical precision to use, defaults to 2.
704  int Notation; // The notation to use (standard, scientific, mixed)
705  std::string LabelFormat; // The printf-style format string used for labels.
706  std::string RangeLabelFormat; // The printf-style format string used for range labels.
707  int Behavior; // The behaviour of the axis (auto, fixed, custom).
708  float MaxLabel[2]; // The widest/tallest axis label.
709  bool TitleAppended; // Track if the title is updated when the label formats
710  // are changed in the Extended Axis Labeling algorithm
711 
713 
719  double Shift;
721 
726 
731 
736 
741 
746 
751 
757 
762 
766  bool Resized;
767 
772 
777 
778 private:
779  vtkAxis(const vtkAxis &) = delete;
780  void operator=(const vtkAxis &) = delete;
781 
785  bool InRange(double value);
786 
787 };
788 
789 #endif //vtkAxis_h
double MaximumLimit
Definition: vtkAxis.h:684
double TickInterval
Definition: vtkAxis.h:677
vtkTextProperty * LabelProperties
Definition: vtkAxis.h:680
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:78
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
bool LabelsVisible
Definition: vtkAxis.h:697
float * Point1
Definition: vtkAxis.h:674
double NonLogUnscaledMinLimit
Definition: vtkAxis.h:689
vtkPen * Pen
This object stores the vtkPen that controls how the axis is drawn.
Definition: vtkAxis.h:730
bool LogScale
Definition: vtkAxis.h:694
base class for items that are part of a vtkContextScene.
int Notation
Definition: vtkAxis.h:704
double MinimumLimit
Definition: vtkAxis.h:683
virtual bool Paint(vtkContext2D *painter)
Paint event for the item, called whenever the item needs to be drawn.
std::string RangeLabelFormat
Definition: vtkAxis.h:706
double Shift
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:719
record modification and/or execution time
Definition: vtkTimeStamp.h:32
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:35
a vtkAbstractArray subclass for strings
vtkStdString Title
Definition: vtkAxis.h:692
float TickLength
Definition: vtkAxis.h:679
int TickLabelAlgorithm
The algorithm being used to tick label placement.
Definition: vtkAxis.h:771
bool GridVisible
Definition: vtkAxis.h:696
int Precision
Definition: vtkAxis.h:703
float * Point2
Definition: vtkAxis.h:675
dynamic, self-adjusting array of double
vtkTimeStamp BuildTime
The point cache is marked dirty until it has been initialized.
Definition: vtkAxis.h:776
double UnscaledMinimumLimit
Definition: vtkAxis.h:687
double UnscaledMaximumLimit
Definition: vtkAxis.h:688
bool Resized
Flag to indicate that the axis has been resized.
Definition: vtkAxis.h:766
bool RangeLabelsVisible
Definition: vtkAxis.h:698
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:52
bool AxisVisible
Definition: vtkAxis.h:701
bool LogScaleActive
Definition: vtkAxis.h:695
takes care of drawing 2D axes
Definition: vtkAxis.h:68
double Maximum
Definition: vtkAxis.h:682
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkSmartPointer< vtkStringArray > TickLabels
The labels for the tick marks.
Definition: vtkAxis.h:750
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Position
Definition: vtkAxis.h:673
int Behavior
Definition: vtkAxis.h:707
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:36
float LabelOffset
Definition: vtkAxis.h:699
represent text properties.
bool TitleAppended
Definition: vtkAxis.h:709
vtkPen * GridPen
This object stores the vtkPen that controls how the grid lines are drawn.
Definition: vtkAxis.h:735
double Minimum
Definition: vtkAxis.h:681
double ScalingFactor
Scaling factor used on this axis, this is used to accurately render very small/large numbers accurate...
Definition: vtkAxis.h:718
std::string LabelFormat
Definition: vtkAxis.h:705
bool TitleVisible
Definition: vtkAxis.h:702
vtkVector2f Position2
Definition: vtkAxis.h:676
vtkTextProperty * TitleProperties
Definition: vtkAxis.h:693
bool CustomTickLabels
Are we using custom tick labels, or should the axis generate them?
Definition: vtkAxis.h:725
vtkSmartPointer< vtkDoubleArray > TickPositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:740
bool TicksVisible
Definition: vtkAxis.h:700
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:756
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
double NonLogUnscaledMaxLimit
Definition: vtkAxis.h:690
int NumberOfTicks
Definition: vtkAxis.h:678
virtual void Update()
Perform any updates to the item that may be necessary before rendering.
double UnscaledMaximum
Definition: vtkAxis.h:686
#define max(a, b)
vtkSmartPointer< vtkFloatArray > TickScenePositions
Position of tick marks in screen coordinates.
Definition: vtkAxis.h:745
bool TickMarksDirty
Mark the tick labels as dirty when the min/max value is changed.
Definition: vtkAxis.h:761
double UnscaledMinimum
Definition: vtkAxis.h:685