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 
53 #ifndef vtkAxis_h
54 #define vtkAxis_h
55 
56 #include "vtkChartsCoreModule.h" // For export macro
57 #include "vtkContextItem.h"
58 #include "vtkSmartPointer.h" // For vtkSmartPointer
59 #include "vtkVector.h" // For position variables
60 #include "vtkRect.h" // For bounding rect
61 #include "vtkStdString.h" // For vtkStdString ivars
62 
63 class vtkContext2D;
64 class vtkPen;
65 class vtkFloatArray;
66 class vtkDoubleArray;
67 class vtkStringArray;
68 class vtkTextProperty;
69 
71 {
72 public:
74  virtual void PrintSelf(ostream &os, vtkIndent indent);
75 
77 
79  enum Location {
80  LEFT = 0,
83  TOP,
84  PARALLEL
85  };
87 
88  enum {
89  TICK_SIMPLE = 0,
90  TICK_WILKINSON_EXTENDED
91  };
92 
94  static vtkAxis *New();
95 
97 
99  virtual void SetPosition(int position);
100  vtkGetMacro(Position, int);
102 
104 
105  void SetPoint1(const vtkVector2f& pos);
106  void SetPoint1(float x, float y);
108 
110 
111  vtkGetVector2Macro(Point1, float);
114 
116 
117  void SetPoint2(const vtkVector2f& pos);
118  void SetPoint2(float x, float y);
120 
122 
123  vtkGetVector2Macro(Point2, float);
126 
129  virtual void SetNumberOfTicks(int numberOfTicks);
130 
132 
133  vtkGetMacro(NumberOfTicks, int);
135 
137 
141 
145  virtual void SetMinimum(double minimum);
146 
148 
151  vtkGetMacro(Minimum, double);
153 
157  virtual void SetMaximum(double maximum);
158 
160 
163  vtkGetMacro(Maximum, double);
165 
170  virtual void SetUnscaledMinimum(double minimum);
171 
173 
174  vtkGetMacro(UnscaledMinimum, double);
176 
178  virtual void SetUnscaledMaximum(double maximum);
179 
181 
182  vtkGetMacro(UnscaledMaximum, double);
184 
186 
192  virtual void SetRange(double minimum, double maximum);
193  virtual void SetRange(double range[2]);
194  virtual void SetUnscaledRange(double minimum, double maximum);
195  virtual void SetUnscaledRange(double range[2]);
197 
199 
203  virtual void GetRange(double *range);
204  virtual void GetUnscaledRange(double *range);
206 
209  virtual void SetMinimumLimit(double lowest);
210 
212 
214  vtkGetMacro(MinimumLimit, double);
216 
219  virtual void SetMaximumLimit(double highest);
220 
222 
224  vtkGetMacro(MaximumLimit, double);
226 
229  virtual void SetUnscaledMinimumLimit(double lowest);
230 
232 
234  vtkGetMacro(UnscaledMinimumLimit, double);
236 
239  virtual void SetUnscaledMaximumLimit(double highest);
240 
242 
244  vtkGetMacro(UnscaledMaximumLimit, double);
246 
248 
249  vtkGetVector2Macro(Margins, int);
251 
253 
254  vtkSetVector2Macro(Margins, int);
256 
258 
259  virtual void SetTitle(const vtkStdString &title);
262 
264 
267 
269 
277  vtkGetMacro(LogScaleActive, bool);
279 
281 
283  vtkGetMacro(LogScale, bool);
284  virtual void SetLogScale(bool logScale);
285  vtkBooleanMacro(LogScale,bool);
287 
289 
290  vtkSetMacro(GridVisible, bool);
291  vtkGetMacro(GridVisible, bool);
293 
295 
296  vtkSetMacro(LabelsVisible, bool);
297  vtkGetMacro(LabelsVisible, bool);
299 
301 
302  vtkSetMacro(TicksVisible, bool);
303  vtkGetMacro(TicksVisible, bool);
305 
307 
308  vtkSetMacro(AxisVisible, bool);
309  vtkGetMacro(AxisVisible, bool);
311 
313 
314  virtual void SetPrecision(int precision);
315  vtkGetMacro(Precision, int);
317 
319 
320  enum {
321  STANDARD_NOTATION = 0,
324  };
326 
328 
330  virtual void SetNotation(int notation);
331  vtkGetMacro(Notation, int);
333 
335 
336  enum {
337  AUTO = 0, // Automatically scale the axis to view all data that is visible.
338  FIXED, // Use a fixed axis range and make no attempt to rescale.
339  CUSTOM // Deprecated, use the tick label settings instead.
340  };
342 
344 
346  vtkSetMacro(Behavior, int);
347  vtkGetMacro(Behavior, int);
349 
351 
355 
357 
361 
363 
369  vtkSetMacro(TickLabelAlgorithm, int)
370  vtkGetMacro(TickLabelAlgorithm, int)
372 
374 
377  vtkSetMacro(ScalingFactor, double)
378  vtkGetMacro(ScalingFactor, double)
379  vtkSetMacro(Shift, double)
380  vtkGetMacro(Shift, double)
382 
385  virtual void Update();
386 
388  virtual bool Paint(vtkContext2D *painter);
389 
394  virtual void AutoScale();
395 
398  virtual void RecalculateTickSpacing();
399 
402  virtual vtkDoubleArray* GetTickPositions();
403 
406  virtual vtkFloatArray* GetTickScenePositions();
407 
409  virtual vtkStringArray* GetTickLabels();
410 
412 
418  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
419  vtkStringArray* labels = 0);
421 
427  vtkRectf GetBoundingRect(vtkContext2D* painter);
428 
432  static double NiceNumber(double number, bool roundUp);
433 
435 
437  static double NiceMinMax(double &min, double &max, float pixelRange,
438  float tickPixelSpacing);
440 
441 //BTX
442 protected:
445 
451  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
452 
454  void GenerateTickLabels(double min, double max);
455 
458  void GenerateTickLabels();
459 
460  void GenerateLabelFormat(int notation, double n);
461 
464  double CalculateNiceMinMax(double &min, double &max);
465 
467 
473  double LogScaleTickMark(double number,
474  bool roundUp,
475  bool &niceValue,
476  int &order);
478 
487  void GenerateLogSpacedLinearTicks(int order, double min, double max);
488 
490 
497  void GenerateLogScaleTickMarks(int order,
498  double min = 1.0,
499  double max = 9.0,
500  bool detailLabels = true);
502 
503  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
504  float *Point1; // The position of point 1 (usually the origin)
505  float *Point2; // The position of point 2 (usually the terminus)
506  vtkVector2f Position1, Position2;
507  double TickInterval; // Interval between tick marks in plot space
508  int NumberOfTicks; // The number of tick marks to draw
509  vtkTextProperty* LabelProperties; // Text properties for the labels.
510  double Minimum; // Minimum value of the axis
511  double Maximum; // Maximum values of the axis
512  double MinimumLimit; // Lowest possible value for Minimum
513  double MaximumLimit; // Highest possible value for Maximum
514  double UnscaledMinimum; // UnscaledMinimum value of the axis
515  double UnscaledMaximum; // UnscaledMaximum values of the axis
516  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
517  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
518  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
519  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
520  int Margins[2]; // Horizontal/vertical margins for the axis
521  vtkStdString Title; // The text label drawn on the axis
522  vtkTextProperty* TitleProperties; // Text properties for the axis title
523  bool LogScale; // *Should* the axis use a log scale?
524  bool LogScaleActive; // *Is* the axis using a log scale?
525  bool GridVisible; // Whether the grid for the axis should be drawn
526  bool LabelsVisible; // Should the axis labels be visible
527  bool TicksVisible; // Should the tick marks be visible.
528  bool AxisVisible; // Should the axis line be visible.
529  int Precision; // Numerical precision to use, defaults to 2.
530  int Notation; // The notation to use (standard, scientific, mixed)
531  int Behavior; // The behaviour of the axis (auto, fixed, custom).
532  float MaxLabel[2]; // The widest/tallest axis label.
533  bool TitleAppended; // Track if the title is updated when the label formats
534  // are changed in the Extended Axis Labeling algorithm
535 
537 
540  double ScalingFactor;
541  double Shift;
543 
545  bool CustomTickLabels;
546 
548  vtkPen* Pen;
549 
552  vtkPen* GridPen;
553 
556 
558  vtkSmartPointer<vtkFloatArray> TickScenePositions;
559 
562 
565  bool UsingNiceMinMax;
566 
568  bool TickMarksDirty;
569 
571  bool Resized;
572 
574  int TickLabelAlgorithm;
575 
578 
579 private:
580  vtkAxis(const vtkAxis &); // Not implemented.
581  void operator=(const vtkAxis &); // Not implemented.
582 
584 
585  bool InRange(double value);
586 //ETX
587 };
589 
590 #endif //vtkAxis_h
vtkAxis::GetUnscaledRange
virtual void GetUnscaledRange(double *range)
vtkChartsCoreModule.h
vtkStdString.h
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkSetVector2Macro
#define vtkSetVector2Macro(name, type)
Definition: vtkSetGet.h:254
vtkGetVector2Macro
#define vtkGetVector2Macro(name, type)
Definition: vtkSetGet.h:270
vtkAxis::SetPosition
virtual void SetPosition(int position)
vtkAxis::SetUnscaledRange
virtual void SetUnscaledRange(double range[2])
vtkAxis::SetPoint1
void SetPoint1(const vtkVector2f &pos)
vtkFloatArray
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:49
vtkAxis::GetPosition2
vtkVector2f GetPosition2()
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkAxis::SetUnscaledMinimum
virtual void SetUnscaledMinimum(double minimum)
vtkAxis::SetMaximum
virtual void SetMaximum(double maximum)
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkgl::n
GLclampd n
Definition: vtkgl.h:14370
vtkSmartPointer
Hold a reference to a vtkObjectBase instance.
Definition: vtkSmartPointer.h:35
vtkVector.h
vtkgl::x
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
vtkAxis::SetNumberOfTicks
virtual void SetNumberOfTicks(int numberOfTicks)
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
vtkAxis::SetPrecision
virtual void SetPrecision(int precision)
vtkAxis::SetRange
virtual void SetRange(double minimum, double maximum)
vtkContextItem.h
vtkgl::range
GLenum GLint * range
Definition: vtkgl.h:14180
vtkAxis::SetLogScale
virtual void SetLogScale(bool logScale)
vtkAxis::SetTitle
virtual void SetTitle(const vtkStdString &title)
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:30
vtkgl::precision
GLenum GLint GLint * precision
Definition: vtkgl.h:14180
vtkX3D::position
@ position
Definition: vtkX3D.h:261
vtkX3D::title
@ title
Definition: vtkX3D.h:500
vtkAxis::SetMinimum
virtual void SetMinimum(double minimum)
Update
virtual void Update()
vtkgl::value
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
vtkAxis::SetUnscaledMinimumLimit
virtual void SetUnscaledMinimumLimit(double lowest)
vtkAxis::TOP
@ TOP
Definition: vtkAxis.h:83
vtkRect.h
vtkAxis::SetPoint2
void SetPoint2(float x, float y)
vtkAxis::GetTitle
virtual vtkStdString GetTitle()
vtkAxis::SetUnscaledRange
virtual void SetUnscaledRange(double minimum, double maximum)
vtkAxis::Location
Location
Definition: vtkAxis.h:79
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkAxis::BOTTOM
@ BOTTOM
Definition: vtkAxis.h:81
vtkSmartPointer.h
vtkGetMacro
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:93
vtkAxis::New
static vtkAxis * New()
vtkgl::order
GLuint GLdouble GLdouble GLint GLint order
Definition: vtkgl.h:18750
vtkAxis::SetRange
virtual void SetRange(double range[2])
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:39
vtkBooleanMacro
vtkBooleanMacro(IgnoreDriverBugs, bool)
vtkContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkContextItem.h:34
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
vtkAxis::FIXED_NOTATION
@ FIXED_NOTATION
Definition: vtkAxis.h:323
vtkAxis::SetNotation
virtual void SetNotation(int notation)
vtkgl::y
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
vtkAxis
takes care of drawing 2D axes
Definition: vtkAxis.h:71
vtkAxis::SetUnscaledMaximumLimit
virtual void SetUnscaledMaximumLimit(double highest)
vtkAxis::GetRange
virtual void GetRange(double *range)
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:45
vtkAxis::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkAxis::SetPoint1
void SetPoint1(float x, float y)
vtkAxis::GetPosition1
vtkVector2f GetPosition1()
vtkAxis::SetMinimumLimit
virtual void SetMinimumLimit(double lowest)
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:49
vtkPen
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:39
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:48
vtkAxis::SCIENTIFIC_NOTATION
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:322
VTKCHARTSCORE_EXPORT
#define VTKCHARTSCORE_EXPORT
Definition: vtkChartsCoreModule.h:15
vtkAxis::SetMaximumLimit
virtual void SetMaximumLimit(double highest)
vtkAxis::SetUnscaledMaximum
virtual void SetUnscaledMaximum(double maximum)
vtkAxis::FIXED
@ FIXED
Definition: vtkAxis.h:338
vtkAxis::RIGHT
@ RIGHT
Definition: vtkAxis.h:82
vtkRectf
Definition: vtkRect.h:97
vtkVector2f
Definition: vtkVector.h:277
vtkAxis::SetPoint2
void SetPoint2(const vtkVector2f &pos)
BuildTime
vtkTimeStamp BuildTime
Definition: vtkOpenGLExtensionManager.h:327