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 
28 #ifndef __vtkAxis_h
29 #define __vtkAxis_h
30 
31 #include "vtkContextItem.h"
32 #include "vtkSmartPointer.h" // For vtkSmartPointer
33 #include "vtkVector.h" // For position variables
34 #include "vtkRect.h" // For bounding rect
35 #include "vtkStdString.h" // For vtkStdString ivars
36 
37 class vtkContext2D;
38 class vtkPen;
39 class vtkFloatArray;
40 class vtkDoubleArray;
41 class vtkStringArray;
42 class vtkTextProperty;
43 
45 {
46 public:
47  vtkTypeMacro(vtkAxis, vtkContextItem);
48  virtual void PrintSelf(ostream &os, vtkIndent indent);
49 
51 
53  enum {
54  LEFT = 0,
57  TOP,
58  PARALLEL
59  };
61 
62  enum {
63  TICK_SIMPLE = 0,
64  TICK_WILKINSON_EXTENDED
65  };
66 
68  static vtkAxis *New();
69 
71 
73  virtual void SetPosition(int position);
74  vtkGetMacro(Position, int);
76 
78 
79  void SetPoint1(const vtkVector2f& pos);
80  void SetPoint1(float x, float y);
82 
84 
85  vtkGetVector2Macro(Point1, float);
86  vtkVector2f GetPosition1();
88 
90 
91  void SetPoint2(const vtkVector2f& pos);
92  void SetPoint2(float x, float y);
94 
96 
97  vtkGetVector2Macro(Point2, float);
98  vtkVector2f GetPosition2();
100 
102 
104  vtkSetMacro(NumberOfTicks, int);
106 
108 
109  vtkGetMacro(NumberOfTicks, int);
111 
113 
115  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
117 
119  virtual void SetMinimum(double minimum);
120 
122 
123  vtkGetMacro(Minimum, double);
125 
127  virtual void SetMaximum(double maximum);
128 
130 
131  vtkGetMacro(Maximum, double);
133 
135 
136  virtual void SetRange(double minimum, double maximum);
137  virtual void SetRange(double range[2]);
139 
141  virtual void GetRange(double *range);
142 
145  virtual void SetMinimumLimit(double lowest);
146 
148 
150  vtkGetMacro(MinimumLimit, double);
152 
155  virtual void SetMaximumLimit(double highest);
156 
158 
160  vtkGetMacro(MaximumLimit, double);
162 
164 
165  vtkGetVector2Macro(Margins, int);
167 
169 
170  vtkSetVector2Macro(Margins, int);
172 
174 
175  virtual void SetTitle(const vtkStdString &title);
176  virtual vtkStdString GetTitle();
178 
180 
181  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
183 
185 
186  vtkSetMacro(LogScale, bool);
187  vtkGetMacro(LogScale, bool);
189 
191 
192  vtkSetMacro(GridVisible, bool);
193  vtkGetMacro(GridVisible, bool);
195 
197 
198  vtkSetMacro(LabelsVisible, bool);
199  vtkGetMacro(LabelsVisible, bool);
201 
203 
204  virtual void SetPrecision(int precision);
205  vtkGetMacro(Precision, int);
207 
209 
210  enum {
211  STANDARD_NOTATION = 0,
215 
216  // deprecated, use the *_NOTATION versions above
217  STANDARD = STANDARD_NOTATION,
218  SCIENTIFIC = SCIENTIFIC_NOTATION,
219  MIXED = FIXED_NOTATION
220  };
221 
223 
225  virtual void SetNotation(int notation);
226  vtkGetMacro(Notation, int);
228 
230 
231  enum {
232  AUTO = 0,
234  CUSTOM
235  };
237 
239 
241  vtkSetMacro(Behavior, int);
242  vtkGetMacro(Behavior, int);
244 
246 
248  vtkGetObjectMacro(Pen, vtkPen);
250 
252 
254  vtkGetObjectMacro(GridPen, vtkPen);
256 
258 
264  vtkSetMacro(TickLabelAlgorithm, int)
265  vtkGetMacro(TickLabelAlgorithm, int)
267 
270  virtual void Update();
271 
273  virtual bool Paint(vtkContext2D *painter);
274 
279  virtual void AutoScale();
280 
283  virtual void RecalculateTickSpacing();
284 
287  virtual vtkDoubleArray* GetTickPositions();
288 
290  virtual void SetTickPositions(vtkDoubleArray* positions);
291 
294  virtual vtkFloatArray* GetTickScenePositions();
295 
297  virtual vtkStringArray* GetTickLabels();
298 
300  virtual void SetTickLabels(vtkStringArray* labels);
301 
307  vtkRectf GetBoundingRect(vtkContext2D* painter);
308 
309 //BTX
310 protected:
311  vtkAxis();
312  ~vtkAxis();
313 
315  void GenerateTickLabels(double min, double max);
316 
319  void GenerateTickLabels();
320 
321  void GenerateLabelFormat(int notation, double n);
322 
325  double CalculateNiceMinMax(double &min, double &max);
326 
330  double NiceNumber(double number, bool roundUp);
331 
333 
339  double LogScaleTickMark(double number,
340  bool roundUp,
341  bool &niceValue,
342  int &order);
344 
346 
353  void GenerateLogScaleTickMarks(int order,
354  double min = 1.0,
355  double max = 9.0,
356  bool detailLabels = true);
358 
359  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
360  float *Point1; // The position of point 1 (usually the origin)
361  float *Point2; // The position of point 2 (usually the terminus)
362  vtkVector2f Position1, Position2;
363  double TickInterval; // Interval between tick marks in plot space
364  int NumberOfTicks; // The number of tick marks to draw
365  vtkTextProperty* LabelProperties; // Text properties for the labels.
366  double Minimum; // Minimum value of the axis
367  double Maximum; // Maximum values of the axis
368  double MinimumLimit; // Lowest possible value for Minimum
369  double MaximumLimit; // Highest possible value for Maximum
370  int Margins[2]; // Horizontal/vertical margins for the axis
371  vtkStdString Title; // The text label drawn on the axis
372  vtkTextProperty* TitleProperties; // Text properties for the axis title
373  bool LogScale; // Should the axis use a log scale
374  bool GridVisible; // Whether the grid for the axis should be drawn
375  bool LabelsVisible; // Should the axis labels be visible
376  int Precision; // Numerical precision to use, defaults to 2.
377  int Notation; // The notation to use (standard, scientific, mixed)
378  int Behavior; // The behaviour of the axis (auto, fixed, custom).
379  float MaxLabel[2]; // The widest/tallest axis label.
380  bool TitleAppended; // Track if the title is updated when the label formats
381  // are changed in the Extended Axis Labeling algorithm
382 
384  vtkPen* Pen;
385 
388  vtkPen* GridPen;
389 
392 
394  vtkSmartPointer<vtkFloatArray> TickScenePositions;
395 
398 
401  bool UsingNiceMinMax;
402 
404  bool TickMarksDirty;
405 
407  bool Resized;
408 
410  bool LogScaleReasonable;
411 
413  int TickLabelAlgorithm;
414 
416  vtkTimeStamp BuildTime;
417 
418 private:
419  vtkAxis(const vtkAxis &); // Not implemented.
420  void operator=(const vtkAxis &); // Not implemented.
421 //ETX
422 };
423 
424 #endif //__vtkAxis_h