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 =========================================================================*/
00050 #ifndef __vtkViewport_h
00051 #define __vtkViewport_h
00052 
00053 #include "vtkObject.h"
00054 
00055 class vtkActor2DCollection;
00056 class vtkAssemblyPath;
00057 class vtkProp;
00058 class vtkPropCollection;
00059 class vtkWindow;
00060 
00061 class VTK_COMMON_EXPORT vtkViewport : public vtkObject
00062 {
00063 public:
00064   vtkTypeRevisionMacro(vtkViewport,vtkObject);
00065   void PrintSelf(ostream& os, vtkIndent indent);
00066 
00069   void AddProp(vtkProp *);
00070 
00072   vtkPropCollection *GetProps() {return this->Props;};
00073 
00075   int HasProp(vtkProp *);
00076 
00078   void RemoveProp(vtkProp *);
00079 
00081   void RemoveAllProps(void);
00082 
00084 
00087   void AddActor2D(vtkProp* p) {this->AddProp(p);};
00088   void RemoveActor2D(vtkProp* p);
00089   vtkActor2DCollection *GetActors2D();
00091 
00093 
00095   vtkSetVector3Macro(Background,float);
00096   vtkGetVectorMacro(Background,float,3);
00098 
00100 
00102   vtkSetVector2Macro(Aspect,float);
00103   vtkGetVectorMacro(Aspect,float,2);
00104   void ComputeAspect();
00106   
00108 
00111   vtkSetVector2Macro(PixelAspect,float);
00112   vtkGetVectorMacro(PixelAspect,float,2);
00114 
00116 
00119   vtkSetVector4Macro(Viewport,float);
00120   vtkGetVectorMacro(Viewport,float,4);
00122 
00124 
00127   vtkSetVector3Macro(DisplayPoint,float);
00128   vtkGetVectorMacro(DisplayPoint,float,3);
00129   void GetDisplayPoint(double a[3]) 
00130     {
00131       a[0] = this->DisplayPoint[0];
00132       a[1] = this->DisplayPoint[1];
00133       a[2] = this->DisplayPoint[2];
00134     };
00136 
00138 
00141   vtkSetVector3Macro(ViewPoint,float);
00142   vtkGetVectorMacro(ViewPoint,float,3);
00144 
00146 
00148   vtkSetVector4Macro(WorldPoint,float);
00149   vtkGetVectorMacro(WorldPoint,float,4);
00150   void GetWorldPoint(double a[4]) 
00151     {
00152       a[0] = this->WorldPoint[0];
00153       a[1] = this->WorldPoint[1];
00154       a[2] = this->WorldPoint[2];
00155       a[3] = this->WorldPoint[3];
00156     };
00158    
00160   virtual float *GetCenter();
00161 
00163   virtual int IsInViewport(int x,int y); 
00164 
00166   virtual vtkWindow *GetVTKWindow() = 0;
00167 
00170   void SetStartRenderMethod(void (*f)(void *), void *arg);
00171 
00174   void SetEndRenderMethod(void (*f)(void *), void *arg);
00175 
00177   void SetStartRenderMethodArgDelete(void (*f)(void *));
00178 
00180   void SetEndRenderMethodArgDelete(void (*f)(void *));
00181 
00183   virtual void DisplayToView(); // these get modified in subclasses
00184 
00186   virtual void ViewToDisplay(); // to handle stereo rendering
00187 
00189   virtual void WorldToView();
00190 
00192   virtual void ViewToWorld();
00193 
00195   void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
00196 
00198   void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
00199 
00201 
00206   virtual void LocalDisplayToDisplay(float &x, float &y);
00207   virtual void DisplayToNormalizedDisplay(float &u, float &v);
00208   virtual void NormalizedDisplayToViewport(float &x, float &y);
00209   virtual void ViewportToNormalizedViewport(float &u, float &v);
00210   virtual void NormalizedViewportToView(float &x, float &y, float &z);
00211   virtual void ViewToWorld(float &, float &, float &) {};
00212   virtual void DisplayToLocalDisplay(float &x, float &y);
00213   virtual void NormalizedDisplayToDisplay(float &u, float &v);
00214   virtual void ViewportToNormalizedDisplay(float &x, float &y);
00215   virtual void NormalizedViewportToViewport(float &u, float &v);
00216   virtual void ViewToNormalizedViewport(float &x, float &y, float &z);
00217   virtual void WorldToView(float &, float &, float &) {};
00219 
00221 
00224   int *GetSize();
00225   int *GetOrigin();
00226   void GetTiledSize(int *width, int *height);
00228   
00229   // The following methods describe the public pick interface for picking
00230   // Props in a viewport.
00231 
00237   virtual vtkAssemblyPath* PickProp(float selectionX, float selectionY) = 0;
00238 
00240 
00243   vtkAssemblyPath* PickPropFrom(float selectionX, float selectionY, 
00244                                 vtkPropCollection*);
00246   
00248 
00250   vtkGetMacro(PickX, float);
00251   vtkGetMacro(PickY, float);
00252   vtkGetMacro(IsPicking, int);
00254 
00256   virtual float GetPickedZ() = 0;
00257   
00258 protected:
00259   // Create a vtkViewport with a black background, a white ambient light, 
00260   // two-sided lighting turned on, a viewport of (0,0,1,1), and back face 
00261   // culling turned off.
00262   vtkViewport();
00263   ~vtkViewport();
00264 
00265   //BTX
00266   // Picking functions to be implemented by sub-classes
00267   // Perform the main picking loop
00268   virtual void DevicePickRender() = 0;
00269   // Enter a pick mode
00270   virtual void StartPick(unsigned int pickFromSize) = 0;
00271   // Set the pick id to the next id before drawing an object
00272   virtual void UpdatePickId() = 0;
00273   // Exit Pick mode
00274   virtual void DonePick() = 0; 
00275   // Return the id of the picked object, only valid after a call to DonePick
00276   virtual unsigned int GetPickedId() = 0;
00277   //ETX
00278 
00279   // Ivars for picking
00280   // Store a picked Prop (contained in an assembly path)
00281   vtkAssemblyPath* PickedProp;
00282   vtkPropCollection* PickFromProps;
00283   // Boolean flag to determine if picking is enabled for this render
00284   int IsPicking;
00285   unsigned int CurrentPickId;
00286   float PickX;
00287   float PickY;
00288   // End Ivars for picking
00289   
00290   vtkPropCollection *Props;
00291   vtkActor2DCollection *Actors2D;
00292   vtkWindow *VTKWindow;
00293   float Background[3];  
00294   float Viewport[4];
00295   float Aspect[2];
00296   float PixelAspect[2];
00297   float Center[2];
00298 
00299   unsigned long StartTag;
00300   unsigned long EndTag;
00301 
00302   int Size[2];
00303   int Origin[2];
00304   float DisplayPoint[3];
00305   float ViewPoint[3];
00306   float WorldPoint[4];
00307 
00308 private:
00309   vtkViewport(const vtkViewport&);  // Not implemented.
00310   void operator=(const vtkViewport&);  // Not implemented.
00311 };
00312 
00313 
00314 
00315 #endif