Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Common/vtkViewport.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkViewport.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
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 
00015 =========================================================================*/
00038 #ifndef __vtkViewport_h
00039 #define __vtkViewport_h
00040 
00041 #include "vtkObject.h"
00042 
00043 class vtkActor2DCollection;
00044 class vtkAssemblyPath;
00045 class vtkProp;
00046 class vtkPropCollection;
00047 class vtkWindow;
00048 
00049 class VTK_COMMON_EXPORT vtkViewport : public vtkObject
00050 {
00051 public:
00052   vtkTypeRevisionMacro(vtkViewport,vtkObject);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00057   void AddProp(vtkProp *);
00058 
00060   vtkPropCollection *GetProps() {return this->Props;};
00061 
00063   int HasProp(vtkProp *);
00064 
00066   void RemoveProp(vtkProp *);
00067 
00069   void RemoveAllProps(void);
00070 
00072 
00075   void AddActor2D(vtkProp* p) {this->AddProp(p);};
00076   void RemoveActor2D(vtkProp* p);
00077   vtkActor2DCollection *GetActors2D();
00079 
00081 
00083   vtkSetVector3Macro(Background,float);
00084   vtkGetVectorMacro(Background,float,3);
00086 
00088 
00090   vtkSetVector2Macro(Aspect,float);
00091   vtkGetVectorMacro(Aspect,float,2);
00092   void ComputeAspect();
00094   
00096 
00099   vtkSetVector2Macro(PixelAspect,float);
00100   vtkGetVectorMacro(PixelAspect,float,2);
00102 
00104 
00107   vtkSetVector4Macro(Viewport,float);
00108   vtkGetVectorMacro(Viewport,float,4);
00110 
00112 
00115   vtkSetVector3Macro(DisplayPoint,float);
00116   vtkGetVectorMacro(DisplayPoint,float,3);
00117   void GetDisplayPoint(double a[3]) 
00118     {
00119       a[0] = this->DisplayPoint[0];
00120       a[1] = this->DisplayPoint[1];
00121       a[2] = this->DisplayPoint[2];
00122     };
00124 
00126 
00129   vtkSetVector3Macro(ViewPoint,float);
00130   vtkGetVectorMacro(ViewPoint,float,3);
00132 
00134 
00136   vtkSetVector4Macro(WorldPoint,float);
00137   vtkGetVectorMacro(WorldPoint,float,4);
00138   void GetWorldPoint(double a[4]) 
00139     {
00140       a[0] = this->WorldPoint[0];
00141       a[1] = this->WorldPoint[1];
00142       a[2] = this->WorldPoint[2];
00143       a[3] = this->WorldPoint[3];
00144     };
00146    
00148   virtual float *GetCenter();
00149 
00151   virtual int IsInViewport(int x,int y); 
00152 
00154   virtual vtkWindow *GetVTKWindow() = 0;
00155 
00158   void SetStartRenderMethod(void (*f)(void *), void *arg);
00159 
00162   void SetEndRenderMethod(void (*f)(void *), void *arg);
00163 
00165   void SetStartRenderMethodArgDelete(void (*f)(void *));
00166 
00168   void SetEndRenderMethodArgDelete(void (*f)(void *));
00169 
00171   virtual void DisplayToView(); // these get modified in subclasses
00172 
00174   virtual void ViewToDisplay(); // to handle stereo rendering
00175 
00177   virtual void WorldToView();
00178 
00180   virtual void ViewToWorld();
00181 
00183   void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
00184 
00186   void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
00187 
00189 
00194   virtual void LocalDisplayToDisplay(float &x, float &y);
00195   virtual void DisplayToNormalizedDisplay(float &u, float &v);
00196   virtual void NormalizedDisplayToViewport(float &x, float &y);
00197   virtual void ViewportToNormalizedViewport(float &u, float &v);
00198   virtual void NormalizedViewportToView(float &x, float &y, float &z);
00199   virtual void ViewToWorld(float &, float &, float &) {};
00200   virtual void DisplayToLocalDisplay(float &x, float &y);
00201   virtual void NormalizedDisplayToDisplay(float &u, float &v);
00202   virtual void ViewportToNormalizedDisplay(float &x, float &y);
00203   virtual void NormalizedViewportToViewport(float &u, float &v);
00204   virtual void ViewToNormalizedViewport(float &x, float &y, float &z);
00205   virtual void WorldToView(float &, float &, float &) {};
00207 
00209 
00212   int *GetSize();
00213   int *GetOrigin();
00214   void GetTiledSize(int *width, int *height);
00216   
00217   // The following methods describe the public pick interface for picking
00218   // Props in a viewport.
00219 
00225   virtual vtkAssemblyPath* PickProp(float selectionX, float selectionY) = 0;
00226 
00228 
00231   vtkAssemblyPath* PickPropFrom(float selectionX, float selectionY, 
00232                                 vtkPropCollection*);
00234   
00236 
00238   vtkGetMacro(PickX, float);
00239   vtkGetMacro(PickY, float);
00240   vtkGetMacro(IsPicking, int);
00242 
00244   virtual float GetPickedZ() = 0;
00245   
00246 protected:
00247   // Create a vtkViewport with a black background, a white ambient light, 
00248   // two-sided lighting turned on, a viewport of (0,0,1,1), and back face 
00249   // culling turned off.
00250   vtkViewport();
00251   ~vtkViewport();
00252 
00253   //BTX
00254   // Picking functions to be implemented by sub-classes
00255   // Perform the main picking loop
00256   virtual void DevicePickRender() = 0;
00257   // Enter a pick mode
00258   virtual void StartPick(unsigned int pickFromSize) = 0;
00259   // Set the pick id to the next id before drawing an object
00260   virtual void UpdatePickId() = 0;
00261   // Exit Pick mode
00262   virtual void DonePick() = 0; 
00263   // Return the id of the picked object, only valid after a call to DonePick
00264   virtual unsigned int GetPickedId() = 0;
00265   //ETX
00266 
00267   // Ivars for picking
00268   // Store a picked Prop (contained in an assembly path)
00269   vtkAssemblyPath* PickedProp;
00270   vtkPropCollection* PickFromProps;
00271   // Boolean flag to determine if picking is enabled for this render
00272   int IsPicking;
00273   unsigned int CurrentPickId;
00274   float PickX;
00275   float PickY;
00276   // End Ivars for picking
00277   
00278   vtkPropCollection *Props;
00279   vtkActor2DCollection *Actors2D;
00280   vtkWindow *VTKWindow;
00281   float Background[3];  
00282   float Viewport[4];
00283   float Aspect[2];
00284   float PixelAspect[2];
00285   float Center[2];
00286 
00287   unsigned long StartTag;
00288   unsigned long EndTag;
00289 
00290   int Size[2];
00291   int Origin[2];
00292   float DisplayPoint[3];
00293   float ViewPoint[3];
00294   float WorldPoint[4];
00295 
00296 private:
00297   vtkViewport(const vtkViewport&);  // Not implemented.
00298   void operator=(const vtkViewport&);  // Not implemented.
00299 };
00300 
00301 
00302 
00303 #endif