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 
411  vtkSetMacro(TitleVisible, bool);
412  vtkGetMacro(TitleVisible, bool);
414 
416 
420  virtual void SetPrecision(int precision);
421  vtkGetMacro(Precision, int);
423 
427  enum {
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  AUTO = 0, // Automatically scale the axis to view all data that is visible.
468  FIXED, // Use a fixed axis range and make no attempt to rescale.
469  CUSTOM // Deprecated, use the tick label settings instead.
470  };
471 
473 
476  vtkSetMacro(Behavior, int);
477  vtkGetMacro(Behavior, int);
479 
481 
484  vtkGetObjectMacro(Pen, vtkPen);
486 
488 
491  vtkGetObjectMacro(GridPen, vtkPen);
493 
495 
502  vtkSetMacro(TickLabelAlgorithm, int)
503  vtkGetMacro(TickLabelAlgorithm, int)
505 
507 
511  vtkSetMacro(ScalingFactor, double)
512  vtkGetMacro(ScalingFactor, double)
513  vtkSetMacro(Shift, double)
514  vtkGetMacro(Shift, double)
516 
521  void Update() override;
522 
526  bool Paint(vtkContext2D *painter) override;
527 
534  virtual void AutoScale();
535 
540  virtual void RecalculateTickSpacing();
541 
546  virtual vtkDoubleArray* GetTickPositions();
547 
552  virtual vtkFloatArray* GetTickScenePositions();
553 
557  virtual vtkStringArray* GetTickLabels();
558 
566  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
567  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,
589  float tickPixelSpacing);
590 
595  virtual vtkStdString GenerateSimpleLabel(double val);
596 
597 protected:
598  vtkAxis();
599  ~vtkAxis() override;
600 
609  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
610 
614  void GenerateTickLabels(double min, double max);
615 
619  void GenerateTickLabels();
620 
621  virtual void GenerateLabelFormat(int notation, double n);
622 
626  virtual vtkStdString GenerateSprintfLabel(double value, const std::string & format);
627 
632  double CalculateNiceMinMax(double &min, double &max);
633 
643  double LogScaleTickMark(double number,
644  bool roundUp,
645  bool &niceValue,
646  int &order);
647 
659  virtual void GenerateLogSpacedLinearTicks(int order, double min, double max);
660 
671  void GenerateLogScaleTickMarks(int order,
672  double min = 1.0,
673  double max = 9.0,
674  bool detailLabels = true);
675 
676  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
677  float *Point1; // The position of point 1 (usually the origin)
678  float *Point2; // The position of point 2 (usually the terminus)
679  vtkVector2f Position1, Position2;
680  double TickInterval; // Interval between tick marks in plot space
681  int NumberOfTicks; // The number of tick marks to draw
682  float TickLength; // The length of the tick marks
683  vtkTextProperty* LabelProperties; // Text properties for the labels.
684  double Minimum; // Minimum value of the axis
685  double Maximum; // Maximum values of the axis
686  double MinimumLimit; // Lowest possible value for Minimum
687  double MaximumLimit; // Highest possible value for Maximum
688  double UnscaledMinimum; // UnscaledMinimum value of the axis
689  double UnscaledMaximum; // UnscaledMaximum values of the axis
690  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
691  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
692  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
693  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
694  int Margins[2]; // Horizontal/vertical margins for the axis
695  vtkStdString Title; // The text label drawn on the axis
696  vtkTextProperty* TitleProperties; // Text properties for the axis title
697  bool LogScale; // *Should* the axis use a log scale?
698  bool LogScaleActive; // *Is* the axis using a log scale?
699  bool GridVisible; // Whether the grid for the axis should be drawn
700  bool LabelsVisible; // Should the axis labels be visible
701  bool RangeLabelsVisible; // Should range labels be visible?
702  float LabelOffset; // Offset of label from the tick mark
703  bool TicksVisible; // Should the tick marks be visible.
704  bool AxisVisible; // Should the axis line be visible.
705  bool TitleVisible; // Should the title be visible.
706  int Precision; // Numerical precision to use, defaults to 2.
707  int Notation; // The notation to use (standard, scientific, mixed)
708  std::string LabelFormat; // The printf-style format string used for labels.
709  std::string RangeLabelFormat; // The printf-style format string used for range labels.
710  int Behavior; // The behaviour of the axis (auto, fixed, custom).
711  float MaxLabel[2]; // The widest/tallest axis label.
712  bool TitleAppended; // Track if the title is updated when the label formats
713  // are changed in the Extended Axis Labeling algorithm
714 
716 
721  double ScalingFactor;
722  double Shift;
724 
728  bool CustomTickLabels;
729 
733  vtkPen* Pen;
734 
738  vtkPen* GridPen;
739 
744 
748  vtkSmartPointer<vtkFloatArray> TickScenePositions;
749 
754 
759  bool UsingNiceMinMax;
760 
764  bool TickMarksDirty;
765 
769  bool Resized;
770 
774  int TickLabelAlgorithm;
775 
779  vtkTimeStamp BuildTime;
780 
781 private:
782  vtkAxis(const vtkAxis &) = delete;
783  void operator=(const vtkAxis &) = delete;
784 
788  bool InRange(double value);
789 
790 };
791 
792 #endif //vtkAxis_h
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
base class for items that are part of a vtkContextScene.
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
Hold a reference to a vtkObjectBase instance.
dynamic, self-adjusting array of double
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
takes care of drawing 2D axes
Definition: vtkAxis.h:71
a simple class to control print indentation
Definition: vtkIndent.h:39
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
represent text properties.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define max(a, b)