VTK
vtkViewport.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkViewport.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
34 #ifndef __vtkViewport_h
35 #define __vtkViewport_h
36 
37 #include "vtkObject.h"
38 
40 class vtkAssemblyPath;
41 class vtkProp;
42 class vtkPropCollection;
43 class vtkWindow;
44 
46 {
47 public:
48  vtkTypeMacro(vtkViewport,vtkObject);
49  void PrintSelf(ostream& os, vtkIndent indent);
50 
54  void AddViewProp(vtkProp *);
55 
57  vtkPropCollection *GetViewProps() {return this->Props;};
58 
60  int HasViewProp(vtkProp *);
61 
64  void RemoveViewProp(vtkProp *);
65 
67  void RemoveAllViewProps(void);
68 
70 
73  void AddActor2D(vtkProp* p);
74  void RemoveActor2D(vtkProp* p);
75  vtkActor2DCollection *GetActors2D();
77 
79 
81  vtkSetVector3Macro(Background,double);
82  vtkGetVector3Macro(Background,double);
84 
86 
88  vtkSetVector3Macro(Background2,double);
89  vtkGetVector3Macro(Background2,double);
91 
93 
95  vtkSetMacro(GradientBackground,bool);
96  vtkGetMacro(GradientBackground,bool);
97  vtkBooleanMacro(GradientBackground,bool);
99 
101 
103  vtkSetVector2Macro(Aspect,double);
104  vtkGetVectorMacro(Aspect,double,2);
105  virtual void ComputeAspect();
107 
109 
112  vtkSetVector2Macro(PixelAspect,double);
113  vtkGetVectorMacro(PixelAspect,double,2);
115 
117 
120  vtkSetVector4Macro(Viewport,double);
121  vtkGetVectorMacro(Viewport,double,4);
123 
125 
128  vtkSetVector3Macro(DisplayPoint,double);
129  vtkGetVectorMacro(DisplayPoint,double,3);
131 
133 
136  vtkSetVector3Macro(ViewPoint,double);
137  vtkGetVectorMacro(ViewPoint,double,3);
139 
141 
143  vtkSetVector4Macro(WorldPoint,double);
144  vtkGetVectorMacro(WorldPoint,double,4);
146 
148  virtual double *GetCenter();
149 
151  virtual int IsInViewport(int x,int y);
152 
154  virtual vtkWindow *GetVTKWindow() = 0;
155 
157  virtual void DisplayToView(); // these get modified in subclasses
158 
160  virtual void ViewToDisplay(); // to handle stereo rendering
161 
163  virtual void WorldToView();
164 
166  virtual void ViewToWorld();
167 
169  void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
170 
172  void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
173 
175 
180  virtual void LocalDisplayToDisplay(double &x, double &y);
181  virtual void DisplayToNormalizedDisplay(double &u, double &v);
182  virtual void NormalizedDisplayToViewport(double &x, double &y);
183  virtual void ViewportToNormalizedViewport(double &u, double &v);
184  virtual void NormalizedViewportToView(double &x, double &y, double &z);
185  virtual void ViewToWorld(double &, double &, double &) {};
186  virtual void DisplayToLocalDisplay(double &x, double &y);
187  virtual void NormalizedDisplayToDisplay(double &u, double &v);
188  virtual void ViewportToNormalizedDisplay(double &x, double &y);
189  virtual void NormalizedViewportToViewport(double &u, double &v);
190  virtual void ViewToNormalizedViewport(double &x, double &y, double &z);
191  virtual void WorldToView(double &, double &, double &) {};
193 
195 
198  virtual int *GetSize();
199  virtual int *GetOrigin();
200  void GetTiledSize(int *width, int *height);
201  virtual void GetTiledSizeAndOrigin(int *width, int *height,
202  int *lowerLeftX, int *lowerLeftY);
204 
205  // The following methods describe the public pick interface for picking
206  // Props in a viewport.
207 
213  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
214 
216 
219  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY,
222 
224 
226  double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;}
227  double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;}
228  double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;};
229  double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;};
230  double GetPickX1() const {return this->PickX1;}
231  double GetPickY1() const {return this->PickY1;}
232  double GetPickX2() const {return this->PickX2;}
233  double GetPickY2() const {return this->PickY2;}
234  vtkGetMacro(IsPicking, int);
235  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
237 
239  virtual double GetPickedZ() = 0;
240 
241 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
242 # define RemovePropA RemoveProp
243 # define RemovePropW RemoveProp
244 #endif
245 
247  VTK_LEGACY(void RemoveProp(vtkProp*));
248 
249 #ifdef VTK_WORKAROUND_WINDOWS_MANGLE
250 # undef RemovePropA
251 # undef RemovePropW
252  //BTX
253  VTK_LEGACY(void RemovePropA(vtkProp*));
254  VTK_LEGACY(void RemovePropW(vtkProp*));
255  //ETX
256 #endif
257 
259  VTK_LEGACY(void AddProp(vtkProp *));
260 
262  VTK_LEGACY(vtkPropCollection *GetProps());
263 
265  VTK_LEGACY(int HasProp(vtkProp *));
266 
269  VTK_LEGACY(void RemoveAllProps());
270 
271 protected:
272  // Create a vtkViewport with a black background, a white ambient light,
273  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
274  // culling turned off.
275  vtkViewport();
276  ~vtkViewport();
277 
278  //BTX
279  // Picking functions to be implemented by sub-classes
280  // Perform the main picking loop
281  virtual void DevicePickRender() = 0;
282  // Enter a pick mode
283  virtual void StartPick(unsigned int pickFromSize) = 0;
284  // Set the pick id to the next id before drawing an object
285  virtual void UpdatePickId() = 0;
286  // Exit Pick mode
287  virtual void DonePick() = 0;
288  // Return the id of the picked object, only valid after a call to DonePick
289  virtual unsigned int GetPickedId() = 0;
290  // Return the number of objects picked, only valid after a call to DonePick
291  virtual unsigned int GetNumPickedIds() = 0;
292  // Put no more than atMost picked object ids into the callerBuffer and
293  // return the number of picked objects returned.
294  virtual int GetPickedIds(unsigned int atMost, unsigned int *callerBuffer) = 0;
295  //ETX
296 
297  // Ivars for picking
298  // Store a picked Prop (contained in an assembly path)
302  // Boolean flag to determine if picking is enabled for this render
304  unsigned int CurrentPickId;
305  double PickX1;
306  double PickY1;
307  double PickX2;
308  double PickY2;
309  // End Ivars for picking
310 
314  double Background[3];
315  double Background2[3];
316  double Viewport[4];
317  double Aspect[2];
318  double PixelAspect[2];
319  double Center[2];
321 
322  int Size[2];
323  int Origin[2];
324  double DisplayPoint[3];
325  double ViewPoint[3];
326  double WorldPoint[4];
327 
328 
329 private:
330  vtkViewport(const vtkViewport&); // Not implemented.
331  void operator=(const vtkViewport&); // Not implemented.
332 };
333 
334 
335 
336 #endif