VTK
dox/Rendering/Core/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 "vtkRenderingCoreModule.h" // For export macro
00038 #include "vtkObject.h"
00039 
00040 class vtkActor2DCollection;
00041 class vtkAssemblyPath;
00042 class vtkProp;
00043 class vtkPropCollection;
00044 class vtkWindow;
00045 
00046 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
00047 {
00048 public:
00049   vtkTypeMacro(vtkViewport,vtkObject);
00050   void PrintSelf(ostream& os, vtkIndent indent);
00051 
00055   void AddViewProp(vtkProp *);
00056 
00058   vtkPropCollection *GetViewProps() {return this->Props;};
00059 
00061   int HasViewProp(vtkProp *);
00062 
00065   void RemoveViewProp(vtkProp *);
00066 
00068   void RemoveAllViewProps(void);
00069 
00071 
00074   void AddActor2D(vtkProp* p);
00075   void RemoveActor2D(vtkProp* p);
00076   vtkActor2DCollection *GetActors2D();
00078 
00080 
00082   vtkSetVector3Macro(Background,double);
00083   vtkGetVector3Macro(Background,double);
00085 
00087 
00089   vtkSetVector3Macro(Background2,double);
00090   vtkGetVector3Macro(Background2,double);
00092 
00094 
00096   vtkSetMacro(GradientBackground,bool);
00097   vtkGetMacro(GradientBackground,bool);
00098   vtkBooleanMacro(GradientBackground,bool);
00100 
00102 
00104   vtkSetVector2Macro(Aspect,double);
00105   vtkGetVectorMacro(Aspect,double,2);
00106   virtual void ComputeAspect();
00108 
00110 
00113   vtkSetVector2Macro(PixelAspect,double);
00114   vtkGetVectorMacro(PixelAspect,double,2);
00116 
00118 
00121   vtkSetVector4Macro(Viewport,double);
00122   vtkGetVectorMacro(Viewport,double,4);
00124 
00126 
00129   vtkSetVector3Macro(DisplayPoint,double);
00130   vtkGetVectorMacro(DisplayPoint,double,3);
00132 
00134 
00137   vtkSetVector3Macro(ViewPoint,double);
00138   vtkGetVectorMacro(ViewPoint,double,3);
00140 
00142 
00144   vtkSetVector4Macro(WorldPoint,double);
00145   vtkGetVectorMacro(WorldPoint,double,4);
00147 
00149   virtual double *GetCenter();
00150 
00152   virtual int IsInViewport(int x,int y);
00153 
00155   virtual vtkWindow *GetVTKWindow() = 0;
00156 
00158   virtual void DisplayToView(); // these get modified in subclasses
00159 
00161   virtual void ViewToDisplay(); // to handle stereo rendering
00162 
00164   virtual void WorldToView();
00165 
00167   virtual void ViewToWorld();
00168 
00170   void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
00171 
00173   void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
00174 
00176 
00181   virtual void LocalDisplayToDisplay(double &x, double &y);
00182   virtual void DisplayToNormalizedDisplay(double &u, double &v);
00183   virtual void NormalizedDisplayToViewport(double &x, double &y);
00184   virtual void ViewportToNormalizedViewport(double &u, double &v);
00185   virtual void NormalizedViewportToView(double &x, double &y, double &z);
00186   virtual void ViewToWorld(double &, double &, double &) {}
00187   virtual void DisplayToLocalDisplay(double &x, double &y);
00188   virtual void NormalizedDisplayToDisplay(double &u, double &v);
00189   virtual void ViewportToNormalizedDisplay(double &x, double &y);
00190   virtual void NormalizedViewportToViewport(double &u, double &v);
00191   virtual void ViewToNormalizedViewport(double &x, double &y, double &z);
00192   virtual void WorldToView(double &, double &, double &) {}
00194 
00196 
00199   virtual int *GetSize();
00200   virtual int *GetOrigin();
00201   void GetTiledSize(int *width, int *height);
00202   virtual void GetTiledSizeAndOrigin(int *width, int *height,
00203                                      int *lowerLeftX, int *lowerLeftY);
00205 
00206   // The following methods describe the public pick interface for picking
00207   // Props in a viewport.
00208 
00214   virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
00215 
00217 
00220   vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY,
00221                                 vtkPropCollection*);
00223 
00225 
00227   double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;}
00228   double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;}
00229   double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;};
00230   double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;};
00231   double GetPickX1() const {return this->PickX1;}
00232   double GetPickY1() const {return this->PickY1;}
00233   double GetPickX2() const {return this->PickX2;}
00234   double GetPickY2() const {return this->PickY2;}
00235   vtkGetMacro(IsPicking, int);
00236   vtkGetObjectMacro(PickResultProps, vtkPropCollection);
00238 
00240   virtual double GetPickedZ() = 0;
00241 
00242 protected:
00243   // Create a vtkViewport with a black background, a white ambient light,
00244   // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
00245   // culling turned off.
00246   vtkViewport();
00247   ~vtkViewport();
00248 
00249   //BTX
00250   // Picking functions to be implemented by sub-classes
00251   // Perform the main picking loop
00252   virtual void DevicePickRender() = 0;
00253   // Enter a pick mode
00254   virtual void StartPick(unsigned int pickFromSize) = 0;
00255   // Set the pick id to the next id before drawing an object
00256   virtual void UpdatePickId() = 0;
00257   // Exit Pick mode
00258   virtual void DonePick() = 0;
00259   // Return the id of the picked object, only valid after a call to DonePick
00260   virtual unsigned int GetPickedId() = 0;
00261   // Return the number of objects picked, only valid after a call to DonePick
00262   virtual unsigned int GetNumPickedIds() = 0;
00263   // Put no more than atMost picked object ids into the callerBuffer and
00264   // return the number of picked objects returned.
00265   virtual int GetPickedIds(unsigned int atMost, unsigned int *callerBuffer) = 0;
00266   //ETX
00267 
00268   // Ivars for picking
00269   // Store a picked Prop (contained in an assembly path)
00270   vtkAssemblyPath* PickedProp;
00271   vtkPropCollection* PickFromProps;
00272   vtkPropCollection* PickResultProps;
00273   // Boolean flag to determine if picking is enabled for this render
00274   int IsPicking;
00275   unsigned int CurrentPickId;
00276   double PickX1;
00277   double PickY1;
00278   double PickX2;
00279   double PickY2;
00280   // End Ivars for picking
00281 
00282   vtkPropCollection *Props;
00283   vtkActor2DCollection *Actors2D;
00284   vtkWindow *VTKWindow;
00285   double Background[3];
00286   double Background2[3];
00287   double Viewport[4];
00288   double Aspect[2];
00289   double PixelAspect[2];
00290   double Center[2];
00291   bool GradientBackground;
00292 
00293   int Size[2];
00294   int Origin[2];
00295   double DisplayPoint[3];
00296   double ViewPoint[3];
00297   double WorldPoint[4];
00298 
00299 
00300 private:
00301   vtkViewport(const vtkViewport&);  // Not implemented.
00302   void operator=(const vtkViewport&);  // Not implemented.
00303 };
00304 
00305 
00306 
00307 #endif