VTK
dox/Rendering/Annotation/vtkCubeAxesActor.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkCubeAxesActor.h
00005   Language:  C++
00006 
00007 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
00008 All rights reserve
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013      PURPOSE.  See the above copyright notice for more information.
00014 =========================================================================*/
00061 #ifndef __vtkCubeAxesActor_h
00062 #define __vtkCubeAxesActor_h
00063 
00064 #define VTK_FLY_OUTER_EDGES     0
00065 #define VTK_FLY_CLOSEST_TRIAD   1
00066 #define VTK_FLY_FURTHEST_TRIAD  2
00067 #define VTK_FLY_STATIC_TRIAD    3
00068 #define VTK_FLY_STATIC_EDGES    4
00069 
00070 #define VTK_TICKS_INSIDE        0
00071 #define VTK_TICKS_OUTSIDE       1
00072 #define VTK_TICKS_BOTH          2
00073 
00074 #define VTK_GRID_LINES_ALL      0
00075 #define VTK_GRID_LINES_CLOSEST  1
00076 #define VTK_GRID_LINES_FURTHEST 2
00077 
00078 #define NUMBER_OF_ALIGNED_AXIS 4
00079 
00080 #include "vtkRenderingAnnotationModule.h" // For export macro
00081 #include "vtkActor.h"
00082 
00083 class vtkAxisActor;
00084 class vtkCamera;
00085 class vtkTextProperty;
00086 class vtkStringArray;
00087 
00088 class VTKRENDERINGANNOTATION_EXPORT vtkCubeAxesActor : public vtkActor
00089 {
00090 public:
00091   vtkTypeMacro(vtkCubeAxesActor,vtkActor);
00092   void PrintSelf(ostream& os, vtkIndent indent);
00093 
00096   static vtkCubeAxesActor *New();
00097 
00099 
00100   virtual int RenderOpaqueGeometry(vtkViewport*);
00101   virtual int RenderTranslucentGeometry(vtkViewport*);
00102   virtual int RenderTranslucentPolygonalGeometry(vtkViewport*);
00103   virtual int RenderOverlay(vtkViewport*);
00104   int HasTranslucentPolygonalGeometry();
00106 
00108 
00109   vtkSetMacro( RebuildAxes, bool );
00110   vtkGetMacro( RebuildAxes, bool );
00112 
00114 
00118   vtkSetVector6Macro(Bounds,double);
00119   vtkGetVector6Macro(Bounds,double);
00121 
00123 
00125   virtual void GetRenderedBounds(double rBounds[6]);
00126   virtual double* GetRenderedBounds();
00128 
00130 
00137   vtkSetVector2Macro( XAxisRange, double );
00138   vtkSetVector2Macro( YAxisRange, double );
00139   vtkSetVector2Macro( ZAxisRange, double );
00140   vtkGetVector2Macro( XAxisRange, double );
00141   vtkGetVector2Macro( YAxisRange, double );
00143 
00144 
00146   vtkStringArray* GetAxisLabels(int axis);
00147   void SetAxisLabels(int axis, vtkStringArray* value);
00149 
00150   vtkGetVector2Macro( ZAxisRange, double );
00151 
00153 
00156   void SetScreenSize(double screenSize);
00157   vtkGetMacro(ScreenSize, double);
00159 
00161 
00163   void SetLabelOffset(double offset);
00164   vtkGetMacro(LabelOffset, double);
00166 
00168 
00170   void SetTitleOffset(double offset);
00171   vtkGetMacro(TitleOffset, double);
00173 
00175 
00177   virtual void SetCamera(vtkCamera*);
00178   vtkGetObjectMacro(Camera,vtkCamera);
00180 
00182 
00185   vtkSetClampMacro(FlyMode, int, VTK_FLY_OUTER_EDGES, VTK_FLY_STATIC_EDGES);
00186   vtkGetMacro(FlyMode, int);
00187   void SetFlyModeToOuterEdges()
00188     {this->SetFlyMode(VTK_FLY_OUTER_EDGES);};
00189   void SetFlyModeToClosestTriad()
00190     {this->SetFlyMode(VTK_FLY_CLOSEST_TRIAD);};
00191   void SetFlyModeToFurthestTriad()
00192     {this->SetFlyMode(VTK_FLY_FURTHEST_TRIAD);};
00193   void SetFlyModeToStaticTriad()
00194     {this->SetFlyMode(VTK_FLY_STATIC_TRIAD);};
00195   void SetFlyModeToStaticEdges()
00196     {this->SetFlyMode(VTK_FLY_STATIC_EDGES);};
00198 
00200 
00202   vtkSetStringMacro(XTitle);
00203   vtkGetStringMacro(XTitle);
00204   vtkSetStringMacro(XUnits);
00205   vtkGetStringMacro(XUnits);
00206   vtkSetStringMacro(YTitle);
00207   vtkGetStringMacro(YTitle);
00208   vtkSetStringMacro(YUnits);
00209   vtkGetStringMacro(YUnits);
00210   vtkSetStringMacro(ZTitle);
00211   vtkGetStringMacro(ZTitle);
00212   vtkSetStringMacro(ZUnits);
00213   vtkGetStringMacro(ZUnits);
00215 
00217 
00219   vtkSetStringMacro(XLabelFormat);
00220   vtkGetStringMacro(XLabelFormat);
00221   vtkSetStringMacro(YLabelFormat);
00222   vtkGetStringMacro(YLabelFormat);
00223   vtkSetStringMacro(ZLabelFormat);
00224   vtkGetStringMacro(ZLabelFormat);
00226 
00228 
00231   vtkSetClampMacro(Inertia, int, 1, VTK_INT_MAX);
00232   vtkGetMacro(Inertia, int);
00234 
00236 
00239   vtkSetMacro(CornerOffset, double);
00240   vtkGetMacro(CornerOffset, double);
00242 
00246   void ReleaseGraphicsResources(vtkWindow *);
00247 
00249 
00251   vtkSetMacro( EnableDistanceLOD, int );
00252   vtkGetMacro( EnableDistanceLOD, int );
00254 
00256 
00257   vtkSetClampMacro( DistanceLODThreshold, double, 0.0, 1.0 );
00258   vtkGetMacro( DistanceLODThreshold, double);
00260 
00262 
00264   vtkSetMacro( EnableViewAngleLOD, int );
00265   vtkGetMacro( EnableViewAngleLOD, int );
00267 
00269 
00270   vtkSetClampMacro( ViewAngleLODThreshold, double, 0., 1. );
00271   vtkGetMacro( ViewAngleLODThreshold, double );
00273 
00275 
00276   vtkSetMacro(XAxisVisibility,int);
00277   vtkGetMacro(XAxisVisibility,int);
00278   vtkBooleanMacro(XAxisVisibility,int);
00279   vtkSetMacro(YAxisVisibility,int);
00280   vtkGetMacro(YAxisVisibility,int);
00281   vtkBooleanMacro(YAxisVisibility,int);
00282   vtkSetMacro(ZAxisVisibility,int);
00283   vtkGetMacro(ZAxisVisibility,int);
00284   vtkBooleanMacro(ZAxisVisibility,int);
00286 
00288 
00289   vtkSetMacro(XAxisLabelVisibility,int);
00290   vtkGetMacro(XAxisLabelVisibility,int);
00291   vtkBooleanMacro(XAxisLabelVisibility,int);
00293 
00294   vtkSetMacro(YAxisLabelVisibility,int);
00295   vtkGetMacro(YAxisLabelVisibility,int);
00296   vtkBooleanMacro(YAxisLabelVisibility,int);
00297 
00298   vtkSetMacro(ZAxisLabelVisibility,int);
00299   vtkGetMacro(ZAxisLabelVisibility,int);
00300   vtkBooleanMacro(ZAxisLabelVisibility,int);
00301 
00303 
00304   vtkSetMacro(XAxisTickVisibility,int);
00305   vtkGetMacro(XAxisTickVisibility,int);
00306   vtkBooleanMacro(XAxisTickVisibility,int);
00308 
00309   vtkSetMacro(YAxisTickVisibility,int);
00310   vtkGetMacro(YAxisTickVisibility,int);
00311   vtkBooleanMacro(YAxisTickVisibility,int);
00312 
00313   vtkSetMacro(ZAxisTickVisibility,int);
00314   vtkGetMacro(ZAxisTickVisibility,int);
00315   vtkBooleanMacro(ZAxisTickVisibility,int);
00316 
00318 
00319   vtkSetMacro(XAxisMinorTickVisibility,int);
00320   vtkGetMacro(XAxisMinorTickVisibility,int);
00321   vtkBooleanMacro(XAxisMinorTickVisibility,int);
00323 
00324   vtkSetMacro(YAxisMinorTickVisibility,int);
00325   vtkGetMacro(YAxisMinorTickVisibility,int);
00326   vtkBooleanMacro(YAxisMinorTickVisibility,int);
00327 
00328   vtkSetMacro(ZAxisMinorTickVisibility,int);
00329   vtkGetMacro(ZAxisMinorTickVisibility,int);
00330   vtkBooleanMacro(ZAxisMinorTickVisibility,int);
00331 
00332   vtkSetMacro(DrawXGridlines,int);
00333   vtkGetMacro(DrawXGridlines,int);
00334   vtkBooleanMacro(DrawXGridlines,int);
00335 
00336   vtkSetMacro(DrawYGridlines,int);
00337   vtkGetMacro(DrawYGridlines,int);
00338   vtkBooleanMacro(DrawYGridlines,int);
00339 
00340   vtkSetMacro(DrawZGridlines,int);
00341   vtkGetMacro(DrawZGridlines,int);
00342   vtkBooleanMacro(DrawZGridlines,int);
00343 
00344   vtkSetMacro(DrawXInnerGridlines,int);
00345   vtkGetMacro(DrawXInnerGridlines,int);
00346   vtkBooleanMacro(DrawXInnerGridlines,int);
00347 
00348   vtkSetMacro(DrawYInnerGridlines,int);
00349   vtkGetMacro(DrawYInnerGridlines,int);
00350   vtkBooleanMacro(DrawYInnerGridlines,int);
00351 
00352   vtkSetMacro(DrawZInnerGridlines,int);
00353   vtkGetMacro(DrawZInnerGridlines,int);
00354   vtkBooleanMacro(DrawZInnerGridlines,int);
00355 
00356   vtkSetMacro(DrawXGridpolys,int);
00357   vtkGetMacro(DrawXGridpolys,int);
00358   vtkBooleanMacro(DrawXGridpolys,int);
00359 
00360   vtkSetMacro(DrawYGridpolys,int);
00361   vtkGetMacro(DrawYGridpolys,int);
00362   vtkBooleanMacro(DrawYGridpolys,int);
00363 
00364   vtkSetMacro(DrawZGridpolys,int);
00365   vtkGetMacro(DrawZGridpolys,int);
00366   vtkBooleanMacro(DrawZGridpolys,int);
00367 
00369   vtkTextProperty *GetTitleTextProperty(int);
00370 
00372   vtkTextProperty *GetLabelTextProperty(int);
00373 
00375 
00376   void SetXAxesLinesProperty(vtkProperty *);
00377   vtkProperty* GetXAxesLinesProperty();
00378   void SetYAxesLinesProperty(vtkProperty *);
00379   vtkProperty* GetYAxesLinesProperty();
00380   void SetZAxesLinesProperty(vtkProperty *);
00381   vtkProperty* GetZAxesLinesProperty();
00383 
00385 
00386   void SetXAxesGridlinesProperty(vtkProperty *);
00387   vtkProperty* GetXAxesGridlinesProperty();
00388   void SetYAxesGridlinesProperty(vtkProperty *);
00389   vtkProperty* GetYAxesGridlinesProperty();
00390   void SetZAxesGridlinesProperty(vtkProperty *);
00391   vtkProperty* GetZAxesGridlinesProperty();
00393 
00395 
00396   void SetXAxesInnerGridlinesProperty(vtkProperty *);
00397   vtkProperty* GetXAxesInnerGridlinesProperty();
00398   void SetYAxesInnerGridlinesProperty(vtkProperty *);
00399   vtkProperty* GetYAxesInnerGridlinesProperty();
00400   void SetZAxesInnerGridlinesProperty(vtkProperty *);
00401   vtkProperty* GetZAxesInnerGridlinesProperty();
00403 
00405 
00406   void SetXAxesGridpolysProperty(vtkProperty *);
00407   vtkProperty* GetXAxesGridpolysProperty();
00408   void SetYAxesGridpolysProperty(vtkProperty *);
00409   vtkProperty* GetYAxesGridpolysProperty();
00410   void SetZAxesGridpolysProperty(vtkProperty *);
00411   vtkProperty* GetZAxesGridpolysProperty();
00413 
00415 
00416   vtkSetClampMacro(TickLocation, int, VTK_TICKS_INSIDE, VTK_TICKS_BOTH);
00417   vtkGetMacro(TickLocation, int);
00419 
00420   void SetTickLocationToInside(void)
00421     { this->SetTickLocation(VTK_TICKS_INSIDE); };
00422   void SetTickLocationToOutside(void)
00423     { this->SetTickLocation(VTK_TICKS_OUTSIDE); };
00424   void SetTickLocationToBoth(void)
00425     { this->SetTickLocation(VTK_TICKS_BOTH); };
00426 
00427   void SetLabelScaling(bool, int, int, int);
00428 
00430 
00432   void SetUse2DMode( int val );
00433   int GetUse2DMode();
00435 
00437   void SetSaveTitlePosition( int val );
00438 
00440 
00441   vtkSetVector6Macro(OrientedBounds,double);
00442   vtkGetVector6Macro(OrientedBounds, double);
00444 
00446 
00447   vtkSetMacro(UseOrientedBounds, int);
00448   vtkGetMacro(UseOrientedBounds, int);
00450 
00452 
00453   vtkSetVector3Macro(AxisBaseForX,double);
00454   vtkGetVector3Macro(AxisBaseForX, double);
00456 
00458 
00459   vtkSetVector3Macro(AxisBaseForY,double);
00460   vtkGetVector3Macro(AxisBaseForY, double);
00462 
00464 
00465   vtkSetVector3Macro(AxisBaseForZ,double);
00466   vtkGetVector3Macro(AxisBaseForZ, double);
00468 
00470 
00472   vtkSetVector3Macro(AxisOrigin,double);
00473   vtkGetVector3Macro(AxisOrigin, double);
00475 
00477 
00478   vtkSetMacro(UseAxisOrigin, int);
00479   vtkGetMacro(UseAxisOrigin, int);
00481 
00483 
00484   vtkSetMacro(GridLineLocation,int);
00485   vtkGetMacro(GridLineLocation,int);
00487 
00488 protected:
00489   vtkCubeAxesActor();
00490   ~vtkCubeAxesActor();
00491 
00492   int LabelExponent(double min, double max);
00493 
00494   int Digits(double min, double max);
00495 
00496   double MaxOf(double, double);
00497   double MaxOf(double, double, double, double);
00498 
00499   double FFix(double);
00500   double FSign(double, double);
00501   int FRound( double fnt );
00502   int GetNumTicks( double range, double fxt);
00503 
00504   void UpdateLabels(vtkAxisActor **axis, int index);
00505 
00506   double Bounds[6]; //Define bounds explicitly
00507 
00508   vtkCamera *Camera;
00509 
00510   int FlyMode;
00511 
00512   // Expose internally closest axis index computation
00513   int FindClosestAxisIndex(double pts[8][3]);
00514 
00515   // Expose internally furthest axis index computation
00516   int FindFurtherstAxisIndex(double pts[8][3]);
00517 
00518   // Expose internally the boundary edge fly mode axis index computation
00519   void FindBoundaryEdge(int &indexOfAxisX, int &indexOfAxisY, int &indexOfAxisZ,
00520                         double pts[8][3]);
00521 
00525   void UpdateGridLineVisibility(int axisIndex);
00526 
00527   // VTK_ALL_GRID_LINES      0
00528   // VTK_CLOSEST_GRID_LINES  1
00529   // VTK_FURTHEST_GRID_LINES 2
00530   int GridLineLocation;
00531 
00534   int EnableDistanceLOD;
00535 
00538   double DistanceLODThreshold;
00539 
00542   int EnableViewAngleLOD;
00543 
00546   double ViewAngleLODThreshold;
00547 
00549 
00551   vtkAxisActor *XAxes[NUMBER_OF_ALIGNED_AXIS];
00552   vtkAxisActor *YAxes[NUMBER_OF_ALIGNED_AXIS];
00553   vtkAxisActor *ZAxes[NUMBER_OF_ALIGNED_AXIS];
00555 
00556   bool RebuildAxes;
00557 
00558   char *XTitle;
00559   char *XUnits;
00560   char *YTitle;
00561   char *YUnits;
00562   char *ZTitle;
00563   char *ZUnits;
00564 
00565   char *ActualXLabel;
00566   char *ActualYLabel;
00567   char *ActualZLabel;
00568 
00569   int TickLocation;
00570 
00571   int XAxisVisibility;
00572   int YAxisVisibility;
00573   int ZAxisVisibility;
00574 
00575   int XAxisTickVisibility;
00576   int YAxisTickVisibility;
00577   int ZAxisTickVisibility;
00578 
00579   int XAxisMinorTickVisibility;
00580   int YAxisMinorTickVisibility;
00581   int ZAxisMinorTickVisibility;
00582 
00583   int XAxisLabelVisibility;
00584   int YAxisLabelVisibility;
00585   int ZAxisLabelVisibility;
00586 
00587   int DrawXGridlines;
00588   int DrawYGridlines;
00589   int DrawZGridlines;
00590 
00591   int DrawXInnerGridlines;
00592   int DrawYInnerGridlines;
00593   int DrawZInnerGridlines;
00594 
00595   int DrawXGridpolys;
00596   int DrawYGridpolys;
00597   int DrawZGridpolys;
00598 
00599   char  *XLabelFormat;
00600   char  *YLabelFormat;
00601   char  *ZLabelFormat;
00602 
00603   double CornerOffset;
00604 
00605   int   Inertia;
00606 
00607   int   RenderCount;
00608 
00609   int   InertiaLocs[3];
00610 
00611   int RenderSomething;
00612 
00613   vtkTextProperty* TitleTextProperty[3];
00614   vtkStringArray* AxisLabels[3];
00615 
00616   vtkTextProperty* LabelTextProperty[3];
00617 
00618   vtkProperty  *XAxesLinesProperty;
00619   vtkProperty  *YAxesLinesProperty;
00620   vtkProperty  *ZAxesLinesProperty;
00621   vtkProperty  *XAxesGridlinesProperty;
00622   vtkProperty  *YAxesGridlinesProperty;
00623   vtkProperty  *ZAxesGridlinesProperty;
00624   vtkProperty  *XAxesInnerGridlinesProperty;
00625   vtkProperty  *YAxesInnerGridlinesProperty;
00626   vtkProperty  *ZAxesInnerGridlinesProperty;
00627   vtkProperty  *XAxesGridpolysProperty;
00628   vtkProperty  *YAxesGridpolysProperty;
00629   vtkProperty  *ZAxesGridpolysProperty;
00630 
00631   double RenderedBounds[6];
00632   double OrientedBounds[6];
00633   int UseOrientedBounds;
00634 
00635   double AxisOrigin[3];
00636   int UseAxisOrigin;
00637 
00638   double AxisBaseForX[3];
00639   double AxisBaseForY[3];
00640   double AxisBaseForZ[3];
00641 
00642 private:
00643   vtkCubeAxesActor(const vtkCubeAxesActor&); // Not implemented
00644   void operator=(const vtkCubeAxesActor&); // Not implemented
00645 
00646   vtkSetStringMacro(ActualXLabel);
00647   vtkSetStringMacro(ActualYLabel);
00648   vtkSetStringMacro(ActualZLabel);
00649 
00650   vtkTimeStamp BuildTime;
00651   int LastUseOrientedBounds;
00652   int LastXPow;
00653   int LastYPow;
00654   int LastZPow;
00655 
00656   int UserXPow;
00657   int UserYPow;
00658   int UserZPow;
00659 
00660   bool AutoLabelScaling;
00661 
00662   int LastXAxisDigits;
00663   int LastYAxisDigits;
00664   int LastZAxisDigits;
00665 
00666   double LastXRange[2];
00667   double LastYRange[2];
00668   double LastZRange[2];
00669   double LastBounds[6];
00670 
00671   int    LastFlyMode;
00672 
00673   int   RenderAxesX[NUMBER_OF_ALIGNED_AXIS];
00674   int   RenderAxesY[NUMBER_OF_ALIGNED_AXIS];
00675   int   RenderAxesZ[NUMBER_OF_ALIGNED_AXIS];
00676 
00677   int   NumberOfAxesX;
00678   int   NumberOfAxesY;
00679   int   NumberOfAxesZ;
00680 
00681   bool MustAdjustXValue;
00682   bool MustAdjustYValue;
00683   bool MustAdjustZValue;
00684 
00685   bool ForceXLabelReset;
00686   bool ForceYLabelReset;
00687   bool ForceZLabelReset;
00688 
00689   double XAxisRange[2];
00690   double YAxisRange[2];
00691   double ZAxisRange[2];
00692 
00693   double LabelScale;
00694   double TitleScale;
00695 
00696   double ScreenSize;
00697   double LabelOffset;
00698   double TitleOffset;
00699 
00701 
00703   double MajorStart[3];
00704   double DeltaMajor[3];
00706 
00707   int RenderGeometry(bool &initialRender, vtkViewport *viewport, bool checkAxisVisibility,int (vtkAxisActor::*renderMethod)(vtkViewport*));
00708 
00709   void  TransformBounds(vtkViewport *viewport, const double bounds[6],
00710                         double pts[8][3]);
00711   void  AdjustAxes(double bounds[6],
00712                    double xCoords[NUMBER_OF_ALIGNED_AXIS][6],
00713                    double yCoords[NUMBER_OF_ALIGNED_AXIS][6],
00714                    double zCoords[NUMBER_OF_ALIGNED_AXIS][6],
00715                    double xRange[2], double yRange[2], double zRange[2]);
00716 
00717   bool  ComputeTickSize(double bounds[6]);
00718   void  AdjustValues(const double xRange[2],
00719                      const double yRange[2],
00720                      const double zRange[2]);
00721   void  AdjustRange(const double bounds[6]);
00722   void  BuildAxes(vtkViewport *);
00723   void  DetermineRenderAxes(vtkViewport *);
00724   void  SetNonDependentAttributes(void);
00725   void  BuildLabels(vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS]);
00726   void  AdjustTicksComputeRange(vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS],
00727       double rangeMin, double rangeMax);
00728 
00729   void    AutoScale(vtkViewport *viewport);
00730   void    AutoScale(vtkViewport *viewport, vtkAxisActor *axes[NUMBER_OF_ALIGNED_AXIS]);
00731   double  AutoScale(vtkViewport *viewport, double screenSize, double position[3]);
00732 };
00733 
00734 
00735 #endif