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) VTK_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 
409  virtual void SetPrecision(int precision);
410  vtkGetMacro(Precision, int);
412 
416  enum {
417  STANDARD_NOTATION = 0,
420  PRINTF_NOTATION
421  };
422 
424 
428  virtual void SetLabelFormat(const std::string &fmt);
429  vtkGetMacro(LabelFormat, std::string);
431 
433 
438  vtkSetMacro(RangeLabelFormat, std::string);
439  vtkGetMacro(RangeLabelFormat, std::string);
441 
443 
448  virtual void SetNotation(int notation);
449  vtkGetMacro(Notation, int);
451 
455  enum {
456  AUTO = 0, // Automatically scale the axis to view all data that is visible.
457  FIXED, // Use a fixed axis range and make no attempt to rescale.
458  CUSTOM // Deprecated, use the tick label settings instead.
459  };
460 
462 
465  vtkSetMacro(Behavior, int);
466  vtkGetMacro(Behavior, int);
468 
470 
473  vtkGetObjectMacro(Pen, vtkPen);
475 
477 
480  vtkGetObjectMacro(GridPen, vtkPen);
482 
484 
491  vtkSetMacro(TickLabelAlgorithm, int)
492  vtkGetMacro(TickLabelAlgorithm, int)
494 
496 
500  vtkSetMacro(ScalingFactor, double)
501  vtkGetMacro(ScalingFactor, double)
502  vtkSetMacro(Shift, double)
503  vtkGetMacro(Shift, double)
505 
510  void Update() VTK_OVERRIDE;
511 
515  bool Paint(vtkContext2D *painter) VTK_OVERRIDE;
516 
523  virtual void AutoScale();
524 
529  virtual void RecalculateTickSpacing();
530 
535  virtual vtkDoubleArray* GetTickPositions();
536 
541  virtual vtkFloatArray* GetTickScenePositions();
542 
546  virtual vtkStringArray* GetTickLabels();
547 
555  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
556  vtkStringArray* labels = 0);
557 
564  vtkRectf GetBoundingRect(vtkContext2D* painter);
565 
571  static double NiceNumber(double number, bool roundUp);
572 
577  static double NiceMinMax(double &min, double &max, float pixelRange,
578  float tickPixelSpacing);
579 
584  vtkStdString GenerateSimpleLabel(double val);
585 
586 protected:
587  vtkAxis();
588  ~vtkAxis() VTK_OVERRIDE;
589 
598  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
599 
603  void GenerateTickLabels(double min, double max);
604 
608  void GenerateTickLabels();
609 
610  void GenerateLabelFormat(int notation, double n);
611 
615  vtkStdString GenerateSprintfLabel(double value, const std::string & format);
616 
621  double CalculateNiceMinMax(double &min, double &max);
622 
632  double LogScaleTickMark(double number,
633  bool roundUp,
634  bool &niceValue,
635  int &order);
636 
648  void GenerateLogSpacedLinearTicks(int order, double min, double max);
649 
660  void GenerateLogScaleTickMarks(int order,
661  double min = 1.0,
662  double max = 9.0,
663  bool detailLabels = true);
664 
665  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
666  float *Point1; // The position of point 1 (usually the origin)
667  float *Point2; // The position of point 2 (usually the terminus)
668  vtkVector2f Position1, Position2;
669  double TickInterval; // Interval between tick marks in plot space
670  int NumberOfTicks; // The number of tick marks to draw
671  float TickLength; // The length of the tick marks
672  vtkTextProperty* LabelProperties; // Text properties for the labels.
673  double Minimum; // Minimum value of the axis
674  double Maximum; // Maximum values of the axis
675  double MinimumLimit; // Lowest possible value for Minimum
676  double MaximumLimit; // Highest possible value for Maximum
677  double UnscaledMinimum; // UnscaledMinimum value of the axis
678  double UnscaledMaximum; // UnscaledMaximum values of the axis
679  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
680  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
681  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
682  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
683  int Margins[2]; // Horizontal/vertical margins for the axis
684  vtkStdString Title; // The text label drawn on the axis
685  vtkTextProperty* TitleProperties; // Text properties for the axis title
686  bool LogScale; // *Should* the axis use a log scale?
687  bool LogScaleActive; // *Is* the axis using a log scale?
688  bool GridVisible; // Whether the grid for the axis should be drawn
689  bool LabelsVisible; // Should the axis labels be visible
690  bool RangeLabelsVisible; // Should range labels be visible?
691  float LabelOffset; // Offset of label from the tick mark
692  bool TicksVisible; // Should the tick marks be visible.
693  bool AxisVisible; // Should the axis line be visible.
694  int Precision; // Numerical precision to use, defaults to 2.
695  int Notation; // The notation to use (standard, scientific, mixed)
696  std::string LabelFormat; // The printf-style format string used for labels.
697  std::string RangeLabelFormat; // The printf-style format string used for range labels.
698  int Behavior; // The behaviour of the axis (auto, fixed, custom).
699  float MaxLabel[2]; // The widest/tallest axis label.
700  bool TitleAppended; // Track if the title is updated when the label formats
701  // are changed in the Extended Axis Labeling algorithm
702 
704 
709  double ScalingFactor;
710  double Shift;
712 
716  bool CustomTickLabels;
717 
721  vtkPen* Pen;
722 
726  vtkPen* GridPen;
727 
732 
736  vtkSmartPointer<vtkFloatArray> TickScenePositions;
737 
742 
747  bool UsingNiceMinMax;
748 
752  bool TickMarksDirty;
753 
757  bool Resized;
758 
762  int TickLabelAlgorithm;
763 
768 
769 private:
770  vtkAxis(const vtkAxis &) VTK_DELETE_FUNCTION;
771  void operator=(const vtkAxis &) VTK_DELETE_FUNCTION;
772 
776  bool InRange(double value);
777 
778 };
779 
780 #endif //vtkAxis_h
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:41
vtkTimeStamp BuildTime
base class for items that are part of a vtkContextScene.
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
virtual void Update()
Updates the extensions string.
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:52
takes care of drawing 2D axes
Definition: vtkAxis.h:68
a simple class to control print indentation
Definition: vtkIndent.h:33
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:36
represent text properties.
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
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...
#define max(a, b)