VTK
dox/Filtering/vtkViewport.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkViewport.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 =========================================================================*/
00034 #ifndef __vtkViewport_h
00035 #define __vtkViewport_h
00036 
00037 #include "vtkObject.h"
00038 
00039 class vtkActor2DCollection;
00040 class vtkAssemblyPath;
00041 class vtkProp;
00042 class vtkPropCollection;
00043 class vtkWindow;
00044 
00045 class VTK_FILTERING_EXPORT vtkViewport : public vtkObject
00046 {
00047 public:
00048   vtkTypeMacro(vtkViewport,vtkObject);
00049   void PrintSelf(ostream& os, vtkIndent indent);
00050 
00054   void AddViewProp(vtkProp *);
00055 
00057   vtkPropCollection *GetViewProps() {return this->Props;};
00058 
00060   int HasViewProp(vtkProp *);
00061 
00064   void RemoveViewProp(vtkProp *);
00065 
00067   void RemoveAllViewProps(void);
00068 
00070 
00073   void AddActor2D(vtkProp* p);
00074   void RemoveActor2D(vtkProp* p);
00075   vtkActor2DCollection *GetActors2D();
00077 
00079 
00081   vtkSetVector3Macro(Background,double);
00082   vtkGetVector3Macro(Background,double);
00084 
00086 
00088   vtkSetVector3Macro(Background2,double);
00089   vtkGetVector3Macro(Background2,double);
00091 
00093 
00095   vtkSetMacro(GradientBackground,bool);
00096   vtkGetMacro(GradientBackground,bool);
00097   vtkBooleanMacro(GradientBackground,bool);
00099 
00101 
00103   vtkSetVector2Macro(Aspect,double);
00104   vtkGetVectorMacro(Aspect,double,2);
00105   virtual void ComputeAspect();
00107 
00109 
00112   vtkSetVector2Macro(PixelAspect,double);
00113   vtkGetVectorMacro(PixelAspect,double,2);
00115 
00117 
00120   vtkSetVector4Macro(Viewport,double);
00121   vtkGetVectorMacro(Viewport,double,4);
00123 
00125 
00128   vtkSetVector3Macro(DisplayPoint,double);
00129   vtkGetVectorMacro(DisplayPoint,double,3);
00131 
00133 
00136   vtkSetVector3Macro(ViewPoint,double);
00137   vtkGetVectorMacro(ViewPoint,double,3);
00139 
00141 
00143   vtkSetVector4Macro(WorldPoint,double);
00144   vtkGetVectorMacro(WorldPoint,double,4);
00146 
00148   virtual double *GetCenter();
00149 
00151   virtual int IsInViewport(int x,int y);
00152 
00154   virtual vtkWindow *GetVTKWindow() = 0;
00155 
00157   virtual void DisplayToView(); // these get modified in subclasses
00158 
00160   virtual void ViewToDisplay(); // to handle stereo rendering
00161 
00163   virtual void WorldToView();
00164 
00166   virtual void ViewToWorld();
00167 
00169   void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
00170 
00172   void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
00173 
00175 
00180   virtual void LocalDisplayToDisplay(double &x, double &y);
00181   virtual void DisplayToNormalizedDisplay(double &u, double &v);
00182   virtual void NormalizedDisplayToViewport(double &x, double &y);
00183   virtual void ViewportToNormalizedViewport(double &u, double &v);
00184   virtual void NormalizedViewportToView(double &x, double &y, double &z);
00185   virtual void ViewToWorld(double &, double &, double &) {};
00186   virtual void DisplayToLocalDisplay(double &x, double &y);
00187   virtual void NormalizedDisplayToDisplay(double &u, double &v);
00188   virtual void ViewportToNormalizedDisplay(double &x, double &y);
00189   virtual void NormalizedViewportToViewport(double &u, double &v);
00190   virtual void ViewToNormalizedViewport(double &x, double &y, double &z);
00191   virtual void WorldToView(double &, double &, double &) {};
00193 
00195 
00198   virtual int *GetSize();
00199   virtual int *GetOrigin();
00200   void GetTiledSize(int *width, int *height);
00201   virtual void GetTiledSizeAndOrigin(int *width, int *height,
00202                                      int *lowerLeftX, int *lowerLeftY);
00204 
00205   // The following methods describe the public pick interface for picking
00206   // Props in a viewport.
00207 
00213   virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
00214 
00216 
00219   vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY,
00220                                 vtkPropCollection*);
00222 
00224 
00226   double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;}
00227   double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;}
00228   double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;};
00229   double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;};
00230   double GetPickX1() const {return this->PickX1;}
00231   double GetPickY1() const {return this->PickY1;}
00232   double GetPickX2() const {return this->PickX2;}
00233   double GetPickY2() const {return this->PickY2;}
00234   vtkGetMacro(IsPicking, int);
00235   vtkGetObjectMacro(PickResultProps, vtkPropCollection);
00237 
00239   virtual double GetPickedZ() = 0;
00240 
00241 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00242 # define RemovePropA RemoveProp
00243 # define RemovePropW RemoveProp
00244 #endif
00245 
00247   VTK_LEGACY(void RemoveProp(vtkProp*));
00248 
00249 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
00250 # undef RemovePropA
00251 # undef RemovePropW
00252   //BTX
00253   VTK_LEGACY(void RemovePropA(vtkProp*));
00254   VTK_LEGACY(void RemovePropW(vtkProp*));
00255   //ETX
00256 #endif
00257 
00259   VTK_LEGACY(void AddProp(vtkProp *));
00260 
00262   VTK_LEGACY(vtkPropCollection *GetProps());
00263 
00265   VTK_LEGACY(int HasProp(vtkProp *));
00266 
00269   VTK_LEGACY(void RemoveAllProps());
00270 
00271 protected:
00272   // Create a vtkViewport with a black background, a white ambient light,
00273   // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
00274   // culling turned off.
00275   vtkViewport();
00276   ~vtkViewport();
00277 
00278   //BTX
00279   // Picking functions to be implemented by sub-classes
00280   // Perform the main picking loop
00281   virtual void DevicePickRender() = 0;
00282   // Enter a pick mode
00283   virtual void StartPick(unsigned int pickFromSize) = 0;
00284   // Set the pick id to the next id before drawing an object
00285   virtual void UpdatePickId() = 0;
00286   // Exit Pick mode
00287   virtual void DonePick() = 0;
00288   // Return the id of the picked object, only valid after a call to DonePick
00289   virtual unsigned int GetPickedId() = 0;
00290   // Return the number of objects picked, only valid after a call to DonePick
00291   virtual unsigned int GetNumPickedIds() = 0;
00292   // Put no more than atMost picked object ids into the callerBuffer and
00293   // return the number of picked objects returned.
00294   virtual int GetPickedIds(unsigned int atMost, unsigned int *callerBuffer) = 0;
00295   //ETX
00296 
00297   // Ivars for picking
00298   // Store a picked Prop (contained in an assembly path)
00299   vtkAssemblyPath* PickedProp;
00300   vtkPropCollection* PickFromProps;
00301   vtkPropCollection* PickResultProps;
00302   // Boolean flag to determine if picking is enabled for this render
00303   int IsPicking;
00304   unsigned int CurrentPickId;
00305   double PickX1;
00306   double PickY1;
00307   double PickX2;
00308   double PickY2;
00309   // End Ivars for picking
00310 
00311   vtkPropCollection *Props;
00312   vtkActor2DCollection *Actors2D;
00313   vtkWindow *VTKWindow;
00314   double Background[3];
00315   double Background2[3];
00316   double Viewport[4];
00317   double Aspect[2];
00318   double PixelAspect[2];
00319   double Center[2];
00320   bool GradientBackground;
00321 
00322   int Size[2];
00323   int Origin[2];
00324   double DisplayPoint[3];
00325   double ViewPoint[3];
00326   double WorldPoint[4];
00327 
00328 
00329 private:
00330   vtkViewport(const vtkViewport&);  // Not implemented.
00331   void operator=(const vtkViewport&);  // Not implemented.
00332 };
00333 
00334 
00335 
00336 #endif