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);
112  vtkVector2f GetPosition1();
114 
116 
117  void SetPoint2(const vtkVector2f& pos);
118  void SetPoint2(float x, float y);
120 
122 
123  vtkGetVector2Macro(Point2, float);
124  vtkVector2f GetPosition2();
126 
129  virtual void SetNumberOfTicks(int numberOfTicks);
130 
132 
133  vtkGetMacro(NumberOfTicks, int);
135 
137 
139  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
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);
260  virtual vtkStdString GetTitle();
262 
264 
265  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
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,
325 
326 #ifndef VTK_LEGACY_REMOVE
327  // deprecated, use the *_NOTATION versions above
328  STANDARD = STANDARD_NOTATION,
329  SCIENTIFIC = SCIENTIFIC_NOTATION,
330  MIXED = FIXED_NOTATION
331 #endif
332  };
333 
335 
337  virtual void SetNotation(int notation);
338  vtkGetMacro(Notation, int);
340 
342 
343  enum {
344  AUTO = 0, // Automatically scale the axis to view all data that is visible.
345  FIXED, // Use a fixed axis range and make no attempt to rescale.
346  CUSTOM // Deprecated, use the tick label settings instead.
347  };
349 
351 
353  vtkSetMacro(Behavior, int);
354  vtkGetMacro(Behavior, int);
356 
358 
362 
364 
366  vtkGetObjectMacro(GridPen, vtkPen);
368 
370 
376  vtkSetMacro(TickLabelAlgorithm, int)
377  vtkGetMacro(TickLabelAlgorithm, int)
379 
381 
384  vtkSetMacro(ScalingFactor, double)
385  vtkGetMacro(ScalingFactor, double)
386  vtkSetMacro(Shift, double)
387  vtkGetMacro(Shift, double)
389 
392  virtual void Update();
393 
395  virtual bool Paint(vtkContext2D *painter);
396 
401  virtual void AutoScale();
402 
405  virtual void RecalculateTickSpacing();
406 
409  virtual vtkDoubleArray* GetTickPositions();
410 
413  virtual vtkFloatArray* GetTickScenePositions();
414 
416  virtual vtkStringArray* GetTickLabels();
417 
419 
425  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
426  vtkStringArray* labels = 0);
428 
431  VTK_LEGACY(virtual void SetTickPositions(vtkDoubleArray* positions));
432 
435  VTK_LEGACY(virtual void SetTickLabels(vtkStringArray* labels));
436 
442  vtkRectf GetBoundingRect(vtkContext2D* painter);
443 
447  static double NiceNumber(double number, bool roundUp);
448 
450 
452  static double NiceMinMax(double &min, double &max, float pixelRange,
453  float tickPixelSpacing);
455 
456 //BTX
457 protected:
458  vtkAxis();
459  ~vtkAxis();
460 
466  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
467 
469  void GenerateTickLabels(double min, double max);
470 
473  void GenerateTickLabels();
474 
475  void GenerateLabelFormat(int notation, double n);
476 
479  double CalculateNiceMinMax(double &min, double &max);
480 
482 
488  double LogScaleTickMark(double number,
489  bool roundUp,
490  bool &niceValue,
491  int &order);
493 
502  void GenerateLogSpacedLinearTicks(int order, double min, double max);
503 
505 
512  void GenerateLogScaleTickMarks(int order,
513  double min = 1.0,
514  double max = 9.0,
515  bool detailLabels = true);
517 
518  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
519  float *Point1; // The position of point 1 (usually the origin)
520  float *Point2; // The position of point 2 (usually the terminus)
521  vtkVector2f Position1, Position2;
522  double TickInterval; // Interval between tick marks in plot space
523  int NumberOfTicks; // The number of tick marks to draw
524  vtkTextProperty* LabelProperties; // Text properties for the labels.
525  double Minimum; // Minimum value of the axis
526  double Maximum; // Maximum values of the axis
527  double MinimumLimit; // Lowest possible value for Minimum
528  double MaximumLimit; // Highest possible value for Maximum
529  double UnscaledMinimum; // UnscaledMinimum value of the axis
530  double UnscaledMaximum; // UnscaledMaximum values of the axis
531  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
532  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
533  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
534  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
535  int Margins[2]; // Horizontal/vertical margins for the axis
536  vtkStdString Title; // The text label drawn on the axis
537  vtkTextProperty* TitleProperties; // Text properties for the axis title
538  bool LogScale; // *Should* the axis use a log scale?
539  bool LogScaleActive; // *Is* the axis using a log scale?
540  bool GridVisible; // Whether the grid for the axis should be drawn
541  bool LabelsVisible; // Should the axis labels be visible
542  bool TicksVisible; // Should the tick marks be visible.
543  bool AxisVisible; // Should the axis line be visible.
544  int Precision; // Numerical precision to use, defaults to 2.
545  int Notation; // The notation to use (standard, scientific, mixed)
546  int Behavior; // The behaviour of the axis (auto, fixed, custom).
547  float MaxLabel[2]; // The widest/tallest axis label.
548  bool TitleAppended; // Track if the title is updated when the label formats
549  // are changed in the Extended Axis Labeling algorithm
550 
552 
555  double ScalingFactor;
556  double Shift;
558 
560  bool CustomTickLabels;
561 
563  vtkPen* Pen;
564 
567  vtkPen* GridPen;
568 
571 
573  vtkSmartPointer<vtkFloatArray> TickScenePositions;
574 
577 
580  bool UsingNiceMinMax;
581 
583  bool TickMarksDirty;
584 
586  bool Resized;
587 
589  int TickLabelAlgorithm;
590 
593 
594 private:
595  vtkAxis(const vtkAxis &); // Not implemented.
596  void operator=(const vtkAxis &); // Not implemented.
597 
599 
600  bool InRange(double value);
601 //ETX
602 };
604 
605 #endif //vtkAxis_h
Location
Definition: vtkAxis.h:79
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
vtkTimeStamp BuildTime
GLuint GLdouble GLdouble GLint GLint order
Definition: vtkgl.h:18750
base class for items that are part of a vtkContextScene.
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
record modification and/or execution time
Definition: vtkTimeStamp.h:34
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:45
a vtkAbstractArray subclass for strings
virtual void Update()
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
Hold a reference to a vtkObjectBase instance.
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:632
dynamic, self-adjusting array of double
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
takes care of drawing 2D axes
Definition: vtkAxis.h:70
a simple class to control print indentation
Definition: vtkIndent.h:38
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:38
represent text properties.
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:222
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:800
#define vtkGetVector2Macro(name, type)
Definition: vtkSetGet.h:260
GLclampd n
Definition: vtkgl.h:14370
#define vtkBooleanMacro(name, type)
Definition: vtkSetGet.h:234
virtual void PrintSelf(ostream &os, vtkIndent indent)
static vtkObject * New()
GLenum GLint * range
Definition: vtkgl.h:14180
#define vtkSetVector2Macro(name, type)
Definition: vtkSetGet.h:244
#define max(a, b)
GLenum GLint GLint * precision
Definition: vtkgl.h:14180
#define VTKCHARTSCORE_EXPORT
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69