VTK
|
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 00375 00378 vtkSetMacro(ScalingFactor, double) 00379 vtkGetMacro(ScalingFactor, double) 00380 vtkSetMacro(Shift, double) 00381 vtkGetMacro(Shift, double) 00383 00386 virtual void Update(); 00387 00389 virtual bool Paint(vtkContext2D *painter); 00390 00395 virtual void AutoScale(); 00396 00399 virtual void RecalculateTickSpacing(); 00400 00403 virtual vtkDoubleArray* GetTickPositions(); 00404 00407 virtual vtkFloatArray* GetTickScenePositions(); 00408 00410 virtual vtkStringArray* GetTickLabels(); 00411 00413 00419 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, 00420 vtkStringArray* labels = 0); 00422 00425 VTK_LEGACY(virtual void SetTickPositions(vtkDoubleArray* positions)); 00426 00429 VTK_LEGACY(virtual void SetTickLabels(vtkStringArray* labels)); 00430 00436 vtkRectf GetBoundingRect(vtkContext2D* painter); 00437 00441 static double NiceNumber(double number, bool roundUp); 00442 00444 00446 static double NiceMinMax(double &min, double &max, float pixelRange, 00447 float tickPixelSpacing); 00449 00450 //BTX 00451 protected: 00452 vtkAxis(); 00453 ~vtkAxis(); 00454 00460 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled); 00461 00463 void GenerateTickLabels(double min, double max); 00464 00467 void GenerateTickLabels(); 00468 00469 void GenerateLabelFormat(int notation, double n); 00470 00473 double CalculateNiceMinMax(double &min, double &max); 00474 00476 00482 double LogScaleTickMark(double number, 00483 bool roundUp, 00484 bool &niceValue, 00485 int &order); 00487 00496 void GenerateLogSpacedLinearTicks(int order, double min, double max); 00497 00499 00506 void GenerateLogScaleTickMarks(int order, 00507 double min = 1.0, 00508 double max = 9.0, 00509 bool detailLabels = true); 00511 00512 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP) 00513 float *Point1; // The position of point 1 (usually the origin) 00514 float *Point2; // The position of point 2 (usually the terminus) 00515 vtkVector2f Position1, Position2; 00516 double TickInterval; // Interval between tick marks in plot space 00517 int NumberOfTicks; // The number of tick marks to draw 00518 vtkTextProperty* LabelProperties; // Text properties for the labels. 00519 double Minimum; // Minimum value of the axis 00520 double Maximum; // Maximum values of the axis 00521 double MinimumLimit; // Lowest possible value for Minimum 00522 double MaximumLimit; // Highest possible value for Maximum 00523 double UnscaledMinimum; // UnscaledMinimum value of the axis 00524 double UnscaledMaximum; // UnscaledMaximum values of the axis 00525 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum 00526 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum 00527 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive) 00528 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive) 00529 int Margins[2]; // Horizontal/vertical margins for the axis 00530 vtkStdString Title; // The text label drawn on the axis 00531 vtkTextProperty* TitleProperties; // Text properties for the axis title 00532 bool LogScale; // *Should* the axis use a log scale? 00533 bool LogScaleActive; // *Is* the axis using a log scale? 00534 bool GridVisible; // Whether the grid for the axis should be drawn 00535 bool LabelsVisible; // Should the axis labels be visible 00536 bool TicksVisible; // Should the tick marks be visible. 00537 int Precision; // Numerical precision to use, defaults to 2. 00538 int Notation; // The notation to use (standard, scientific, mixed) 00539 int Behavior; // The behaviour of the axis (auto, fixed, custom). 00540 float MaxLabel[2]; // The widest/tallest axis label. 00541 bool TitleAppended; // Track if the title is updated when the label formats 00542 // are changed in the Extended Axis Labeling algorithm 00543 00545 00548 double ScalingFactor; 00549 double Shift; 00551 00553 bool CustomTickLabels; 00554 00556 vtkPen* Pen; 00557 00560 vtkPen* GridPen; 00561 00563 vtkSmartPointer<vtkDoubleArray> TickPositions; 00564 00566 vtkSmartPointer<vtkFloatArray> TickScenePositions; 00567 00569 vtkSmartPointer<vtkStringArray> TickLabels; 00570 00573 bool UsingNiceMinMax; 00574 00576 bool TickMarksDirty; 00577 00579 bool Resized; 00580 00582 int TickLabelAlgorithm; 00583 00585 vtkTimeStamp BuildTime; 00586 00587 private: 00588 vtkAxis(const vtkAxis &); // Not implemented. 00589 void operator=(const vtkAxis &); // Not implemented. 00590 00592 00593 bool InRange(double value); 00594 //ETX 00595 }; 00597 00598 #endif //__vtkAxis_h