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  virtual void PrintSelf(ostream &os, vtkIndent indent);
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);
122 
124 
127  void SetPoint2(const vtkVector2f& pos);
128  void SetPoint2(float x, float y);
130 
132 
135  vtkGetVector2Macro(Point2, float);
138 
143  virtual void SetNumberOfTicks(int numberOfTicks);
144 
146 
149  vtkGetMacro(NumberOfTicks, int);
151 
153 
157  vtkGetObjectMacro(LabelProperties, vtkTextProperty);
159 
165  virtual void SetMinimum(double minimum);
166 
168 
173  vtkGetMacro(Minimum, double);
175 
181  virtual void SetMaximum(double maximum);
182 
184 
189  vtkGetMacro(Maximum, double);
191 
197  virtual void SetUnscaledMinimum(double minimum);
198 
200 
203  vtkGetMacro(UnscaledMinimum, double);
205 
209  virtual void SetUnscaledMaximum(double maximum);
210 
212 
215  vtkGetMacro(UnscaledMaximum, double);
217 
219 
228  virtual void SetRange(double minimum, double maximum);
229  virtual void SetRange(double range[2]);
230  virtual void SetUnscaledRange(double minimum, double maximum);
231  virtual void SetUnscaledRange(double range[2]);
233 
235 
242  virtual void GetRange(double *range);
243  virtual void GetUnscaledRange(double *range);
245 
249  virtual void SetMinimumLimit(double lowest);
250 
252 
255  vtkGetMacro(MinimumLimit, double);
257 
261  virtual void SetMaximumLimit(double highest);
262 
264 
267  vtkGetMacro(MaximumLimit, double);
269 
273  virtual void SetUnscaledMinimumLimit(double lowest);
274 
276 
279  vtkGetMacro(UnscaledMinimumLimit, double);
281 
285  virtual void SetUnscaledMaximumLimit(double highest);
286 
288 
291  vtkGetMacro(UnscaledMaximumLimit, double);
293 
295 
298  vtkGetVector2Macro(Margins, int);
300 
302 
305  vtkSetVector2Macro(Margins, int);
307 
309 
312  virtual void SetTitle(const vtkStdString &title);
315 
317 
320  vtkGetObjectMacro(TitleProperties, vtkTextProperty);
322 
324 
336  vtkGetMacro(LogScaleActive, bool);
338 
340 
346  vtkGetMacro(LogScale, bool);
347  virtual void SetLogScale(bool logScale);
348  vtkBooleanMacro(LogScale,bool);
350 
352 
355  vtkSetMacro(GridVisible, bool);
356  vtkGetMacro(GridVisible, bool);
358 
360 
363  vtkSetMacro(LabelsVisible, bool);
364  vtkGetMacro(LabelsVisible, bool);
366 
368 
371  vtkSetMacro(RangeLabelsVisible, bool);
372  vtkGetMacro(RangeLabelsVisible, bool);
374 
376 
379  vtkSetMacro(LabelOffset, float);
380  vtkGetMacro(LabelOffset, float);
382 
384 
387  vtkSetMacro(TicksVisible, bool);
388  vtkGetMacro(TicksVisible, bool);
390 
392 
395  vtkSetMacro(AxisVisible, bool);
396  vtkGetMacro(AxisVisible, bool);
398 
400 
404  virtual void SetPrecision(int precision);
405  vtkGetMacro(Precision, int);
407 
411  enum {
412  STANDARD_NOTATION = 0,
415  PRINTF_NOTATION
416  };
417 
419 
423  virtual void SetLabelFormat(const std::string &fmt);
424  vtkGetMacro(LabelFormat, std::string);
426 
428 
433  vtkSetMacro(RangeLabelFormat, std::string);
434  vtkGetMacro(RangeLabelFormat, std::string);
436 
438 
443  virtual void SetNotation(int notation);
444  vtkGetMacro(Notation, int);
446 
450  enum {
451  AUTO = 0, // Automatically scale the axis to view all data that is visible.
452  FIXED, // Use a fixed axis range and make no attempt to rescale.
453  CUSTOM // Deprecated, use the tick label settings instead.
454  };
455 
457 
460  vtkSetMacro(Behavior, int);
461  vtkGetMacro(Behavior, int);
463 
465 
468  vtkGetObjectMacro(Pen, vtkPen);
470 
472 
475  vtkGetObjectMacro(GridPen, vtkPen);
477 
479 
486  vtkSetMacro(TickLabelAlgorithm, int)
487  vtkGetMacro(TickLabelAlgorithm, int)
489 
491 
495  vtkSetMacro(ScalingFactor, double)
496  vtkGetMacro(ScalingFactor, double)
497  vtkSetMacro(Shift, double)
498  vtkGetMacro(Shift, double)
500 
505  virtual void Update();
506 
510  virtual bool Paint(vtkContext2D *painter);
511 
518  virtual void AutoScale();
519 
524  virtual void RecalculateTickSpacing();
525 
530  virtual vtkDoubleArray* GetTickPositions();
531 
536  virtual vtkFloatArray* GetTickScenePositions();
537 
541  virtual vtkStringArray* GetTickLabels();
542 
550  virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
551  vtkStringArray* labels = 0);
552 
559  vtkRectf GetBoundingRect(vtkContext2D* painter);
560 
566  static double NiceNumber(double number, bool roundUp);
567 
572  static double NiceMinMax(double &min, double &max, float pixelRange,
573  float tickPixelSpacing);
574 
579  vtkStdString GenerateSimpleLabel(double val);
580 
581 protected:
584 
593  void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
594 
598  void GenerateTickLabels(double min, double max);
599 
603  void GenerateTickLabels();
604 
605  void GenerateLabelFormat(int notation, double n);
606 
610  vtkStdString GenerateSprintfLabel(double value, const std::string & format);
611 
616  double CalculateNiceMinMax(double &min, double &max);
617 
627  double LogScaleTickMark(double number,
628  bool roundUp,
629  bool &niceValue,
630  int &order);
631 
643  void GenerateLogSpacedLinearTicks(int order, double min, double max);
644 
655  void GenerateLogScaleTickMarks(int order,
656  double min = 1.0,
657  double max = 9.0,
658  bool detailLabels = true);
659 
660  int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
661  float *Point1; // The position of point 1 (usually the origin)
662  float *Point2; // The position of point 2 (usually the terminus)
663  vtkVector2f Position1, Position2;
664  double TickInterval; // Interval between tick marks in plot space
665  int NumberOfTicks; // The number of tick marks to draw
666  vtkTextProperty* LabelProperties; // Text properties for the labels.
667  double Minimum; // Minimum value of the axis
668  double Maximum; // Maximum values of the axis
669  double MinimumLimit; // Lowest possible value for Minimum
670  double MaximumLimit; // Highest possible value for Maximum
671  double UnscaledMinimum; // UnscaledMinimum value of the axis
672  double UnscaledMaximum; // UnscaledMaximum values of the axis
673  double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
674  double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
675  double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
676  double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
677  int Margins[2]; // Horizontal/vertical margins for the axis
678  vtkStdString Title; // The text label drawn on the axis
679  vtkTextProperty* TitleProperties; // Text properties for the axis title
680  bool LogScale; // *Should* the axis use a log scale?
681  bool LogScaleActive; // *Is* the axis using a log scale?
682  bool GridVisible; // Whether the grid for the axis should be drawn
683  bool LabelsVisible; // Should the axis labels be visible
684  bool RangeLabelsVisible; // Should range labels be visible?
685  float LabelOffset; // Offset of label from the tick mark
686  bool TicksVisible; // Should the tick marks be visible.
687  bool AxisVisible; // Should the axis line be visible.
688  int Precision; // Numerical precision to use, defaults to 2.
689  int Notation; // The notation to use (standard, scientific, mixed)
690  std::string LabelFormat; // The printf-style format string used for labels.
691  std::string RangeLabelFormat; // The printf-style format string used for range labels.
692  int Behavior; // The behaviour of the axis (auto, fixed, custom).
693  float MaxLabel[2]; // The widest/tallest axis label.
694  bool TitleAppended; // Track if the title is updated when the label formats
695  // are changed in the Extended Axis Labeling algorithm
696 
698 
703  double ScalingFactor;
704  double Shift;
706 
710  bool CustomTickLabels;
711 
715  vtkPen* Pen;
716 
720  vtkPen* GridPen;
721 
726 
730  vtkSmartPointer<vtkFloatArray> TickScenePositions;
731 
736 
741  bool UsingNiceMinMax;
742 
746  bool TickMarksDirty;
747 
751  bool Resized;
752 
756  int TickLabelAlgorithm;
757 
762 
763 private:
764  vtkAxis(const vtkAxis &) VTK_DELETE_FUNCTION;
765  void operator=(const vtkAxis &) VTK_DELETE_FUNCTION;
766 
770  bool InRange(double value);
771 
772 };
773 
774 #endif //vtkAxis_h
takes care of drawing 2D axes
Definition: vtkAxis.h:72
virtual void SetUnscaledMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
virtual void SetMinimum(double minimum)
Set the logical minimum value of the axis, in plot coordinates.
virtual void SetUnscaledMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
void SetPoint1(float x, float y)
void SetPoint2(const vtkVector2f &pos)
Set point 2 of the axis (in pixels), this is usually the terminus.
vtkVector2f GetPosition2()
virtual void SetNotation(int notation)
Get/set the numerical notation, standard, scientific, fixed, or a printf-style format string.
@ FIXED_NOTATION
Definition: vtkAxis.h:414
@ SCIENTIFIC_NOTATION
Definition: vtkAxis.h:413
virtual void SetNumberOfTicks(int numberOfTicks)
Set the number of tick marks for this axis.
virtual void SetLabelFormat(const std::string &fmt)
Get/Set the printf-style format string used when TickLabelAlgorithm is TICK_SIMPLE and Notation is PR...
virtual void SetTitle(const vtkStdString &title)
Get/set the title text of the axis.
virtual void SetUnscaledRange(double range[2])
void SetPoint1(const vtkVector2f &pos)
Set point 1 of the axis (in pixels), this is usually the origin.
virtual void SetPosition(int position)
Get/set the position of the axis (LEFT, BOTTOM, RIGHT, TOP, PARALLEL).
virtual void GetRange(double *range)
Get the logical range of the axis, in plot coordinates.
vtkVector2f GetPosition1()
virtual void SetMaximumLimit(double highest)
Set the logical highest possible value for Maximum, in plot coordinates.
void SetPoint2(float x, float y)
virtual void SetPrecision(int precision)
Get/set the numerical precision to use, default is 2.
virtual void SetMinimumLimit(double lowest)
Set the logical lowest possible value for Minimum, in plot coordinates.
virtual void SetUnscaledMinimum(double minimum)
Set the logical, unscaled minimum value of the axis, in plot coordinates.
virtual void SetRange(double range[2])
@ FIXED
Definition: vtkAxis.h:452
Location
Enumeration of the axis locations in a conventional XY chart.
Definition: vtkAxis.h:81
@ TOP
Definition: vtkAxis.h:85
@ BOTTOM
Definition: vtkAxis.h:83
@ RIGHT
Definition: vtkAxis.h:84
virtual void SetUnscaledMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
virtual void GetUnscaledRange(double *range)
virtual void SetRange(double minimum, double maximum)
Set the logical range of the axis, in plot coordinates.
virtual vtkStdString GetTitle()
static vtkAxis * New()
Creates a 2D Chart object.
virtual void SetUnscaledRange(double minimum, double maximum)
virtual void SetMaximum(double maximum)
Set the logical maximum value of the axis, in plot coordinates.
virtual void SetLogScale(bool logScale)
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
base class for items that are part of a vtkContextScene.
dynamic, self-adjusting array of double
dynamic, self-adjusting array of float
Definition: vtkFloatArray.h:42
a simple class to control print indentation
Definition: vtkIndent.h:40
provides a pen that draws the outlines of shapes drawn by vtkContext2D.
Definition: vtkPen.h:40
Hold a reference to a vtkObjectBase instance.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
a vtkAbstractArray subclass for strings
represent text properties.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
@ order
Definition: vtkX3D.h:440
@ value
Definition: vtkX3D.h:220
@ range
Definition: vtkX3D.h:238
@ position
Definition: vtkX3D.h:261
@ title
Definition: vtkX3D.h:500
@ string
Definition: vtkX3D.h:490
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkTimeStamp BuildTime
Updates the extensions string.
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
virtual void Update()
Updates the extensions string.
#define max(a, b)