VTK
dox/Charts/Core/vtkAxis.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkAxis.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00053 #ifndef __vtkAxis_h
00054 #define __vtkAxis_h
00055 
00056 #include "vtkChartsCoreModule.h" // For export macro
00057 #include "vtkContextItem.h"
00058 #include "vtkSmartPointer.h" // For vtkSmartPointer
00059 #include "vtkVector.h"       // For position variables
00060 #include "vtkRect.h"         // For bounding rect
00061 #include "vtkStdString.h"    // For vtkStdString ivars
00062 
00063 class vtkContext2D;
00064 class vtkPen;
00065 class vtkFloatArray;
00066 class vtkDoubleArray;
00067 class vtkStringArray;
00068 class vtkTextProperty;
00069 
00070 class VTKCHARTSCORE_EXPORT vtkAxis : public vtkContextItem
00071 {
00072 public:
00073   vtkTypeMacro(vtkAxis, vtkContextItem);
00074   virtual void PrintSelf(ostream &os, vtkIndent indent);
00075 
00077 
00079   enum {
00080     LEFT = 0,
00081     BOTTOM,
00082     RIGHT,
00083     TOP,
00084     PARALLEL
00085   };
00087 
00088   enum {
00089     TICK_SIMPLE = 0,
00090     TICK_WILKINSON_EXTENDED
00091   };
00092 
00094   static vtkAxis *New();
00095 
00097 
00099   virtual void SetPosition(int position);
00100   vtkGetMacro(Position, int);
00102 
00104 
00105   void SetPoint1(const vtkVector2f& pos);
00106   void SetPoint1(float x, float y);
00108 
00110 
00111   vtkGetVector2Macro(Point1, float);
00112   vtkVector2f GetPosition1();
00114 
00116 
00117   void SetPoint2(const vtkVector2f& pos);
00118   void SetPoint2(float x, float y);
00120 
00122 
00123   vtkGetVector2Macro(Point2, float);
00124   vtkVector2f GetPosition2();
00126 
00129   virtual void SetNumberOfTicks(int numberOfTicks);
00130 
00132 
00133   vtkGetMacro(NumberOfTicks, int);
00135 
00137 
00139   vtkGetObjectMacro(LabelProperties, vtkTextProperty);
00141 
00145   virtual void SetMinimum(double minimum);
00146 
00148 
00151   vtkGetMacro(Minimum, double);
00153 
00157   virtual void SetMaximum(double maximum);
00158 
00160 
00163   vtkGetMacro(Maximum, double);
00165 
00170   virtual void SetUnscaledMinimum(double minimum);
00171 
00173 
00174   vtkGetMacro(UnscaledMinimum, double);
00176 
00178   virtual void SetUnscaledMaximum(double maximum);
00179 
00181 
00182   vtkGetMacro(UnscaledMaximum, double);
00184 
00186 
00192   virtual void SetRange(double minimum, double maximum);
00193   virtual void SetRange(double range[2]);
00194   virtual void SetUnscaledRange(double minimum, double maximum);
00195   virtual void SetUnscaledRange(double range[2]);
00197 
00199 
00203   virtual void GetRange(double *range);
00204   virtual void GetUnscaledRange(double *range);
00206 
00209   virtual void SetMinimumLimit(double lowest);
00210 
00212 
00214   vtkGetMacro(MinimumLimit, double);
00216 
00219   virtual void SetMaximumLimit(double highest);
00220 
00222 
00224   vtkGetMacro(MaximumLimit, double);
00226 
00229   virtual void SetUnscaledMinimumLimit(double lowest);
00230 
00232 
00234   vtkGetMacro(UnscaledMinimumLimit, double);
00236 
00239   virtual void SetUnscaledMaximumLimit(double highest);
00240 
00242 
00244   vtkGetMacro(UnscaledMaximumLimit, double);
00246 
00248 
00249   vtkGetVector2Macro(Margins, int);
00251 
00253 
00254   vtkSetVector2Macro(Margins, int);
00256 
00258 
00259   virtual void SetTitle(const vtkStdString &title);
00260   virtual vtkStdString GetTitle();
00262 
00264 
00265   vtkGetObjectMacro(TitleProperties, vtkTextProperty);
00267 
00269 
00277   vtkGetMacro(LogScaleActive, bool);
00279 
00281 
00283   vtkGetMacro(LogScale, bool);
00284   virtual void SetLogScale(bool logScale);
00285   vtkBooleanMacro(LogScale,bool);
00287 
00289 
00290   vtkSetMacro(GridVisible, bool);
00291   vtkGetMacro(GridVisible, bool);
00293 
00295 
00296   vtkSetMacro(LabelsVisible, bool);
00297   vtkGetMacro(LabelsVisible, bool);
00299 
00301 
00302   vtkSetMacro(TicksVisible, bool);
00303   vtkGetMacro(TicksVisible, bool);
00305 
00307 
00308   virtual void SetPrecision(int precision);
00309   vtkGetMacro(Precision, int);
00311 
00313 
00314   enum {
00315     STANDARD_NOTATION = 0,
00316     SCIENTIFIC_NOTATION,
00317     FIXED_NOTATION,
00319 
00320 #ifndef VTK_LEGACY_REMOVE
00321     // deprecated, use the *_NOTATION versions above
00322     STANDARD = STANDARD_NOTATION,
00323     SCIENTIFIC = SCIENTIFIC_NOTATION,
00324     MIXED = FIXED_NOTATION
00325 #endif
00326   };
00327 
00329 
00331   virtual void SetNotation(int notation);
00332   vtkGetMacro(Notation, int);
00334 
00336 
00337   enum {
00338     AUTO = 0, // Automatically scale the axis to view all data that is visible.
00339     FIXED,    // Use a fixed axis range and make no attempt to rescale.
00340     CUSTOM    // Deprecated, use the tick label settings instead.
00341   };
00343 
00345 
00347   vtkSetMacro(Behavior, int);
00348   vtkGetMacro(Behavior, int);
00350 
00352 
00354   vtkGetObjectMacro(Pen, vtkPen);
00356 
00358 
00360   vtkGetObjectMacro(GridPen, vtkPen);
00362 
00364 
00370   vtkSetMacro(TickLabelAlgorithm, int)
00371   vtkGetMacro(TickLabelAlgorithm, int)
00373 
00376   virtual void Update();
00377 
00379   virtual bool Paint(vtkContext2D *painter);
00380 
00385   virtual void AutoScale();
00386 
00389   virtual void RecalculateTickSpacing();
00390 
00393   virtual vtkDoubleArray* GetTickPositions();
00394 
00397   virtual vtkFloatArray* GetTickScenePositions();
00398 
00400   virtual vtkStringArray* GetTickLabels();
00401 
00403 
00409   virtual bool SetCustomTickPositions(vtkDoubleArray* positions,
00410                                       vtkStringArray* labels = 0);
00412 
00415   VTK_LEGACY(virtual void SetTickPositions(vtkDoubleArray* positions));
00416 
00419   VTK_LEGACY(virtual void SetTickLabels(vtkStringArray* labels));
00420 
00426   vtkRectf GetBoundingRect(vtkContext2D* painter);
00427 
00431   static double NiceNumber(double number, bool roundUp);
00432 
00434 
00436   static double NiceMinMax(double &min, double &max, float pixelRange,
00437                            float tickPixelSpacing);
00439 
00440 //BTX
00441 protected:
00442   vtkAxis();
00443   ~vtkAxis();
00444 
00450   void UpdateLogScaleActive(bool updateMinMaxFromUnscaled);
00451 
00453   void GenerateTickLabels(double min, double max);
00454 
00457   void GenerateTickLabels();
00458 
00459   void GenerateLabelFormat(int notation, double n);
00460 
00463   double CalculateNiceMinMax(double &min, double &max);
00464 
00466 
00472   double LogScaleTickMark(double number,
00473                           bool roundUp,
00474                           bool &niceValue,
00475                           int &order);
00477 
00486   void GenerateLogSpacedLinearTicks(int order, double min, double max);
00487 
00489 
00496   void GenerateLogScaleTickMarks(int order,
00497                                  double min = 1.0,
00498                                  double max = 9.0,
00499                                  bool detailLabels = true);
00501 
00502   int Position;        // The position of the axis (LEFT, BOTTOM, RIGHT, TOP)
00503   float *Point1;       // The position of point 1 (usually the origin)
00504   float *Point2;       // The position of point 2 (usually the terminus)
00505   vtkVector2f Position1, Position2;
00506   double TickInterval; // Interval between tick marks in plot space
00507   int NumberOfTicks;   // The number of tick marks to draw
00508   vtkTextProperty* LabelProperties; // Text properties for the labels.
00509   double Minimum;      // Minimum value of the axis
00510   double Maximum;      // Maximum values of the axis
00511   double MinimumLimit; // Lowest possible value for Minimum
00512   double MaximumLimit; // Highest possible value for Maximum
00513   double UnscaledMinimum;      // UnscaledMinimum value of the axis
00514   double UnscaledMaximum;      // UnscaledMaximum values of the axis
00515   double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum
00516   double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum
00517   double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive)
00518   double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive)
00519   int Margins[2];      // Horizontal/vertical margins for the axis
00520   vtkStdString Title;  // The text label drawn on the axis
00521   vtkTextProperty* TitleProperties; // Text properties for the axis title
00522   bool LogScale;       // *Should* the axis use a log scale?
00523   bool LogScaleActive; // *Is* the axis using a log scale?
00524   bool GridVisible;    // Whether the grid for the axis should be drawn
00525   bool LabelsVisible;  // Should the axis labels be visible
00526   bool TicksVisible;   // Should the tick marks be visible.
00527   int Precision;       // Numerical precision to use, defaults to 2.
00528   int Notation;        // The notation to use (standard, scientific, mixed)
00529   int Behavior;        // The behaviour of the axis (auto, fixed, custom).
00530   float MaxLabel[2];   // The widest/tallest axis label.
00531   bool TitleAppended;  // Track if the title is updated when the label formats
00532                        // are changed in the Extended Axis Labeling algorithm
00533 
00535   bool CustomTickLabels;
00536 
00538   vtkPen* Pen;
00539 
00542   vtkPen* GridPen;
00543 
00545   vtkSmartPointer<vtkDoubleArray> TickPositions;
00546 
00548   vtkSmartPointer<vtkFloatArray> TickScenePositions;
00549 
00551   vtkSmartPointer<vtkStringArray> TickLabels;
00552 
00555   bool UsingNiceMinMax;
00556 
00558   bool TickMarksDirty;
00559 
00561   bool Resized;
00562 
00564   int TickLabelAlgorithm;
00565 
00567   vtkTimeStamp BuildTime;
00568 
00569 private:
00570   vtkAxis(const vtkAxis &); // Not implemented.
00571   void operator=(const vtkAxis &);   // Not implemented.
00572 
00574 
00575   bool InRange(double value);
00576 //ETX
00577 };
00579 
00580 #endif //__vtkAxis_h