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) VTK_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() VTK_OVERRIDE;
514 
518  bool Paint(vtkContext2D *painter) VTK_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() VTK_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 
712  double ScalingFactor;
713  double Shift;
715 
719  bool CustomTickLabels;
720 
724  vtkPen* Pen;
725 
729  vtkPen* GridPen;
730 
735 
739  vtkSmartPointer<vtkFloatArray> TickScenePositions;
740 
745 
750  bool UsingNiceMinMax;
751 
755  bool TickMarksDirty;
756 
760  bool Resized;
761 
765  int TickLabelAlgorithm;
766 
771 
772 private:
773  vtkAxis(const vtkAxis &) VTK_DELETE_FUNCTION;
774  void operator=(const vtkAxis &) VTK_DELETE_FUNCTION;
775 
779  bool InRange(double value);
780 
781 };
782 
783 #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
vtkTimeStamp BuildTime
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
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: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.
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)