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 Location { 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 vtkSetMacro(AxisVisible, bool); 00309 vtkGetMacro(AxisVisible, bool); 00311 00313 00314 virtual void SetPrecision(int precision); 00315 vtkGetMacro(Precision, int); 00317 00319 00320 enum { 00321 STANDARD_NOTATION = 0, 00322 SCIENTIFIC_NOTATION, 00323 FIXED_NOTATION, 00325 00326 #ifndef VTK_LEGACY_REMOVE 00327 // deprecated, use the *_NOTATION versions above 00328 STANDARD = STANDARD_NOTATION, 00329 SCIENTIFIC = SCIENTIFIC_NOTATION, 00330 MIXED = FIXED_NOTATION 00331 #endif 00332 }; 00333 00335 00337 virtual void SetNotation(int notation); 00338 vtkGetMacro(Notation, int); 00340 00342 00343 enum { 00344 AUTO = 0, // Automatically scale the axis to view all data that is visible. 00345 FIXED, // Use a fixed axis range and make no attempt to rescale. 00346 CUSTOM // Deprecated, use the tick label settings instead. 00347 }; 00349 00351 00353 vtkSetMacro(Behavior, int); 00354 vtkGetMacro(Behavior, int); 00356 00358 00360 vtkGetObjectMacro(Pen, vtkPen); 00362 00364 00366 vtkGetObjectMacro(GridPen, vtkPen); 00368 00370 00376 vtkSetMacro(TickLabelAlgorithm, int) 00377 vtkGetMacro(TickLabelAlgorithm, int) 00379 00381 00384 vtkSetMacro(ScalingFactor, double) 00385 vtkGetMacro(ScalingFactor, double) 00386 vtkSetMacro(Shift, double) 00387 vtkGetMacro(Shift, double) 00389 00392 virtual void Update(); 00393 00395 virtual bool Paint(vtkContext2D *painter); 00396 00401 virtual void AutoScale(); 00402 00405 virtual void RecalculateTickSpacing(); 00406 00409 virtual vtkDoubleArray* GetTickPositions(); 00410 00413 virtual vtkFloatArray* GetTickScenePositions(); 00414 00416 virtual vtkStringArray* GetTickLabels(); 00417 00419 00425 virtual bool SetCustomTickPositions(vtkDoubleArray* positions, 00426 vtkStringArray* labels = 0); 00428 00431 VTK_LEGACY(virtual void SetTickPositions(vtkDoubleArray* positions)); 00432 00435 VTK_LEGACY(virtual void SetTickLabels(vtkStringArray* labels)); 00436 00442 vtkRectf GetBoundingRect(vtkContext2D* painter); 00443 00447 static double NiceNumber(double number, bool roundUp); 00448 00450 00452 static double NiceMinMax(double &min, double &max, float pixelRange, 00453 float tickPixelSpacing); 00455 00456 //BTX 00457 protected: 00458 vtkAxis(); 00459 ~vtkAxis(); 00460 00466 void UpdateLogScaleActive(bool updateMinMaxFromUnscaled); 00467 00469 void GenerateTickLabels(double min, double max); 00470 00473 void GenerateTickLabels(); 00474 00475 void GenerateLabelFormat(int notation, double n); 00476 00479 double CalculateNiceMinMax(double &min, double &max); 00480 00482 00488 double LogScaleTickMark(double number, 00489 bool roundUp, 00490 bool &niceValue, 00491 int &order); 00493 00502 void GenerateLogSpacedLinearTicks(int order, double min, double max); 00503 00505 00512 void GenerateLogScaleTickMarks(int order, 00513 double min = 1.0, 00514 double max = 9.0, 00515 bool detailLabels = true); 00517 00518 int Position; // The position of the axis (LEFT, BOTTOM, RIGHT, TOP) 00519 float *Point1; // The position of point 1 (usually the origin) 00520 float *Point2; // The position of point 2 (usually the terminus) 00521 vtkVector2f Position1, Position2; 00522 double TickInterval; // Interval between tick marks in plot space 00523 int NumberOfTicks; // The number of tick marks to draw 00524 vtkTextProperty* LabelProperties; // Text properties for the labels. 00525 double Minimum; // Minimum value of the axis 00526 double Maximum; // Maximum values of the axis 00527 double MinimumLimit; // Lowest possible value for Minimum 00528 double MaximumLimit; // Highest possible value for Maximum 00529 double UnscaledMinimum; // UnscaledMinimum value of the axis 00530 double UnscaledMaximum; // UnscaledMaximum values of the axis 00531 double UnscaledMinimumLimit; // Lowest possible value for UnscaledMinimum 00532 double UnscaledMaximumLimit; // Highest possible value for UnscaledMaximum 00533 double NonLogUnscaledMinLimit; // Saved UnscaledMinimumLimit (when !LogActive) 00534 double NonLogUnscaledMaxLimit; // Saved UnscaledMinimumLimit (when !LogActive) 00535 int Margins[2]; // Horizontal/vertical margins for the axis 00536 vtkStdString Title; // The text label drawn on the axis 00537 vtkTextProperty* TitleProperties; // Text properties for the axis title 00538 bool LogScale; // *Should* the axis use a log scale? 00539 bool LogScaleActive; // *Is* the axis using a log scale? 00540 bool GridVisible; // Whether the grid for the axis should be drawn 00541 bool LabelsVisible; // Should the axis labels be visible 00542 bool TicksVisible; // Should the tick marks be visible. 00543 bool AxisVisible; // Should the axis line be visible. 00544 int Precision; // Numerical precision to use, defaults to 2. 00545 int Notation; // The notation to use (standard, scientific, mixed) 00546 int Behavior; // The behaviour of the axis (auto, fixed, custom). 00547 float MaxLabel[2]; // The widest/tallest axis label. 00548 bool TitleAppended; // Track if the title is updated when the label formats 00549 // are changed in the Extended Axis Labeling algorithm 00550 00552 00555 double ScalingFactor; 00556 double Shift; 00558 00560 bool CustomTickLabels; 00561 00563 vtkPen* Pen; 00564 00567 vtkPen* GridPen; 00568 00570 vtkSmartPointer<vtkDoubleArray> TickPositions; 00571 00573 vtkSmartPointer<vtkFloatArray> TickScenePositions; 00574 00576 vtkSmartPointer<vtkStringArray> TickLabels; 00577 00580 bool UsingNiceMinMax; 00581 00583 bool TickMarksDirty; 00584 00586 bool Resized; 00587 00589 int TickLabelAlgorithm; 00590 00592 vtkTimeStamp BuildTime; 00593 00594 private: 00595 vtkAxis(const vtkAxis &); // Not implemented. 00596 void operator=(const vtkAxis &); // Not implemented. 00597 00599 00600 bool InRange(double value); 00601 //ETX 00602 }; 00604 00605 #endif //vtkAxis_h