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 =========================================================================*/
35 #ifndef vtkViewport_h
36 #define vtkViewport_h
37 
38 #include "vtkRenderingCoreModule.h" // For export macro
39 #include "vtkObject.h"
40 
42 class vtkAssemblyPath;
43 class vtkProp;
44 class vtkPropCollection;
45 class vtkWindow;
46 
47 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
48 {
49 public:
50  vtkTypeMacro(vtkViewport,vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent);
52 
58  void AddViewProp(vtkProp *);
59 
63  vtkPropCollection *GetViewProps() {return this->Props;};
64 
68  int HasViewProp(vtkProp *);
69 
74  void RemoveViewProp(vtkProp *);
75 
79  void RemoveAllViewProps(void);
80 
82 
87  void AddActor2D(vtkProp* p);
88  void RemoveActor2D(vtkProp* p);
89  vtkActor2DCollection *GetActors2D();
91 
93 
97  vtkSetVector3Macro(Background,double);
98  vtkGetVector3Macro(Background,double);
100 
102 
106  vtkSetVector3Macro(Background2,double);
107  vtkGetVector3Macro(Background2,double);
109 
111 
116  vtkSetMacro(GradientBackground,bool);
117  vtkGetMacro(GradientBackground,bool);
118  vtkBooleanMacro(GradientBackground,bool);
120 
122 
126  vtkSetVector2Macro(Aspect,double);
127  vtkGetVectorMacro(Aspect,double,2);
128  virtual void ComputeAspect();
130 
132 
137  vtkSetVector2Macro(PixelAspect,double);
138  vtkGetVectorMacro(PixelAspect,double,2);
140 
142 
147  vtkSetVector4Macro(Viewport,double);
148  vtkGetVectorMacro(Viewport,double,4);
150 
152 
157  vtkSetVector3Macro(DisplayPoint,double);
158  vtkGetVectorMacro(DisplayPoint,double,3);
160 
162 
167  vtkSetVector3Macro(ViewPoint,double);
168  vtkGetVectorMacro(ViewPoint,double,3);
170 
172 
176  vtkSetVector4Macro(WorldPoint,double);
177  vtkGetVectorMacro(WorldPoint,double,4);
179 
183  virtual double *GetCenter();
184 
188  virtual int IsInViewport(int x,int y);
189 
193  virtual vtkWindow *GetVTKWindow() = 0;
194 
198  virtual void DisplayToView(); // these get modified in subclasses
199 
203  virtual void ViewToDisplay(); // to handle stereo rendering
204 
208  virtual void WorldToView();
209 
213  virtual void ViewToWorld();
214 
218  void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
219 
223  void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
224 
226 
233  virtual void LocalDisplayToDisplay(double &x, double &y);
234  virtual void DisplayToNormalizedDisplay(double &u, double &v);
235  virtual void NormalizedDisplayToViewport(double &x, double &y);
236  virtual void ViewportToNormalizedViewport(double &u, double &v);
237  virtual void NormalizedViewportToView(double &x, double &y, double &z);
238  virtual void ViewToWorld(double &, double &, double &) {}
239  virtual void DisplayToLocalDisplay(double &x, double &y);
240  virtual void NormalizedDisplayToDisplay(double &u, double &v);
241  virtual void ViewportToNormalizedDisplay(double &x, double &y);
242  virtual void NormalizedViewportToViewport(double &u, double &v);
243  virtual void ViewToNormalizedViewport(double &x, double &y, double &z);
244  virtual void WorldToView(double &, double &, double &) {}
246 
248 
253  virtual int *GetSize();
254  virtual int *GetOrigin();
255  void GetTiledSize(int *width, int *height);
256  virtual void GetTiledSizeAndOrigin(int *width, int *height,
257  int *lowerLeftX, int *lowerLeftY);
259 
260  // The following methods describe the public pick interface for picking
261  // Props in a viewport.
262 
269  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
270 
278  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1,
279  double selectionX2, double selectionY2) = 0;
280 
286  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY,
288 
294  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1,
295  double selectionX2, double selectionY2,
297 
299 
303  double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;}
304  double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;}
305  double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;};
306  double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;};
307  double GetPickX1() const {return this->PickX1;}
308  double GetPickY1() const {return this->PickY1;}
309  double GetPickX2() const {return this->PickX2;}
310  double GetPickY2() const {return this->PickY2;}
311  vtkGetMacro(IsPicking, int);
312  vtkGetMacro(CurrentPickId, unsigned int);
313  void SetCurrentPickId(unsigned int a) {this->CurrentPickId = a;};
314  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
316 
320  virtual double GetPickedZ() = 0;
321 
322 protected:
323  // Create a vtkViewport with a black background, a white ambient light,
324  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
325  // culling turned off.
326  vtkViewport();
327  ~vtkViewport();
328 
329  // Picking functions to be implemented by sub-classes
330  // Perform the main picking loop
331  virtual void DevicePickRender() = 0;
332  // Enter a pick mode
333  virtual void StartPick(unsigned int pickFromSize) = 0;
334  // Set the pick id to the next id before drawing an object
335  virtual void UpdatePickId() = 0;
336  // Exit Pick mode
337  virtual void DonePick() = 0;
338  // Return the id of the picked object, only valid after a call to DonePick
339  virtual unsigned int GetPickedId() = 0;
340  // Return the number of objects picked, only valid after a call to DonePick
341  virtual unsigned int GetNumPickedIds() = 0;
342  // Put no more than atMost picked object ids into the callerBuffer and
343  // return the number of picked objects returned.
344  virtual int GetPickedIds(unsigned int atMost, unsigned int *callerBuffer) = 0;
345 
346  // Ivars for picking
347  // Store a picked Prop (contained in an assembly path)
351  // Boolean flag to determine if picking is enabled for this render
353  unsigned int CurrentPickId;
354  double PickX1;
355  double PickY1;
356  double PickX2;
357  double PickY2;
358  // End Ivars for picking
359 
363  double Background[3];
364  double Background2[3];
365  double Viewport[4];
366  double Aspect[2];
367  double PixelAspect[2];
368  double Center[2];
370 
371  int Size[2];
372  int Origin[2];
373  double DisplayPoint[3];
374  double ViewPoint[3];
375  double WorldPoint[4];
376 
377 
378 private:
379  vtkViewport(const vtkViewport&) VTK_DELETE_FUNCTION;
380  void operator=(const vtkViewport&) VTK_DELETE_FUNCTION;
381 };
382 
383 
384 
385 #endif
vtkViewport::PickResultProps
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:350
vtkViewport::GetPickY2
double GetPickY2() const
Definition: vtkViewport.h:310
vtkViewport::CurrentPickId
unsigned int CurrentPickId
Definition: vtkViewport.h:353
vtkViewport::Actors2D
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:361
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkViewport::SetCurrentPickId
void SetCurrentPickId(unsigned int a)
Definition: vtkViewport.h:313
vtkViewport::Props
vtkPropCollection * Props
Definition: vtkViewport.h:360
vtkViewport::PickY2
double PickY2
Definition: vtkViewport.h:357
vtkAssemblyPath
a list of nodes that form an assembly path
Definition: vtkAssemblyPath.h:41
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkViewport::WorldToView
virtual void WorldToView(double &, double &, double &)
Definition: vtkViewport.h:244
vtkViewport::DisplayToWorld
void DisplayToWorld()
Convert display (or screen) coordinates to world coordinates.
Definition: vtkViewport.h:218
vtkViewport::GetViewProps
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:63
vtkX3D::Background
Definition: vtkX3D.h:71
vtkX3D::height
Definition: vtkX3D.h:254
vtkViewport::PickedProp
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:348
vtkViewport::WorldToDisplay
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:223
vtkViewport::PickX2
double PickX2
Definition: vtkViewport.h:356
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkViewport::IsPicking
int IsPicking
Definition: vtkViewport.h:352
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkViewport::GetPickX
double GetPickX() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:303
vtkViewport::ViewToWorld
virtual void ViewToWorld(double &, double &, double &)
Definition: vtkViewport.h:238
vtkViewport
abstract specification for Viewports
Definition: vtkViewport.h:47
vtkObject.h
vtkBooleanMacro
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkSetMacro
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkViewport::PickFromProps
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:349
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:47
vtkViewport::GetPickWidth
double GetPickWidth() const
Definition: vtkViewport.h:305
vtkViewport::GetPickX1
double GetPickX1() const
Definition: vtkViewport.h:307
vtkActor2DCollection
a list of 2D actors
Definition: vtkActor2DCollection.h:38
vtkViewport::GetPickX2
double GetPickX2() const
Definition: vtkViewport.h:309
vtkViewport::GetPickHeight
double GetPickHeight() const
Definition: vtkViewport.h:306
vtkViewport::VTKWindow
vtkWindow * VTKWindow
Definition: vtkViewport.h:362
vtkViewport::GetPickY1
double GetPickY1() const
Definition: vtkViewport.h:308
vtkViewport::PickX1
double PickX1
Definition: vtkViewport.h:354
vtkViewport::GradientBackground
bool GradientBackground
Definition: vtkViewport.h:369
vtkPropCollection
a list of Props
Definition: vtkPropCollection.h:38
vtkViewport::PickY1
double PickY1
Definition: vtkViewport.h:355
vtkViewport::GetPickY
double GetPickY() const
Definition: vtkViewport.h:304