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 =========================================================================*/
32 #ifndef vtkViewport_h
33 #define vtkViewport_h
34 
35 #include "vtkRenderingCoreModule.h" // For export macro
36 #include "vtkObject.h"
37 
39 class vtkAssemblyPath;
40 class vtkProp;
41 class vtkPropCollection;
42 class vtkWindow;
43 
44 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
45 {
46 public:
47  vtkTypeMacro(vtkViewport,vtkObject);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
55  void AddViewProp(vtkProp *);
56 
60  vtkPropCollection *GetViewProps() {return this->Props;};
61 
65  int HasViewProp(vtkProp *);
66 
71  void RemoveViewProp(vtkProp *);
72 
76  void RemoveAllViewProps(void);
77 
79 
84  void AddActor2D(vtkProp* p);
85  void RemoveActor2D(vtkProp* p);
86  vtkActor2DCollection *GetActors2D();
88 
90 
94  vtkSetVector3Macro(Background,double);
95  vtkGetVector3Macro(Background,double);
97 
99 
103  vtkSetVector3Macro(Background2,double);
104  vtkGetVector3Macro(Background2,double);
106  //
107 
109 
113  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
114  vtkGetMacro(BackgroundAlpha, double);
116 
118 
123  vtkSetMacro(GradientBackground,bool);
124  vtkGetMacro(GradientBackground,bool);
125  vtkBooleanMacro(GradientBackground,bool);
127 
129 
133  vtkSetVector2Macro(Aspect,double);
134  vtkGetVectorMacro(Aspect,double,2);
135  virtual void ComputeAspect();
137 
139 
144  vtkSetVector2Macro(PixelAspect,double);
145  vtkGetVectorMacro(PixelAspect,double,2);
147 
149 
154  vtkSetVector4Macro(Viewport,double);
155  vtkGetVectorMacro(Viewport,double,4);
157 
159 
164  vtkSetVector3Macro(DisplayPoint,double);
165  vtkGetVectorMacro(DisplayPoint,double,3);
167 
169 
174  vtkSetVector3Macro(ViewPoint,double);
175  vtkGetVectorMacro(ViewPoint,double,3);
177 
179 
183  vtkSetVector4Macro(WorldPoint,double);
184  vtkGetVectorMacro(WorldPoint,double,4);
186 
190  virtual double *GetCenter() VTK_SIZEHINT(2);
191 
195  virtual int IsInViewport(int x,int y);
196 
200  virtual vtkWindow *GetVTKWindow() = 0;
201 
205  virtual void DisplayToView(); // these get modified in subclasses
206 
210  virtual void ViewToDisplay(); // to handle stereo rendering
211 
215  virtual void WorldToView();
216 
220  virtual void ViewToWorld();
221 
225  void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();};
226 
230  void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
231 
233 
240  virtual void LocalDisplayToDisplay(double &x, double &y);
241  virtual void DisplayToNormalizedDisplay(double &u, double &v);
242  virtual void NormalizedDisplayToViewport(double &x, double &y);
243  virtual void ViewportToNormalizedViewport(double &u, double &v);
244  virtual void NormalizedViewportToView(double &x, double &y, double &z);
245  virtual void ViewToWorld(double &, double &, double &) {}
246  virtual void DisplayToLocalDisplay(double &x, double &y);
247  virtual void NormalizedDisplayToDisplay(double &u, double &v);
248  virtual void ViewportToNormalizedDisplay(double &x, double &y);
249  virtual void NormalizedViewportToViewport(double &u, double &v);
250  virtual void ViewToNormalizedViewport(double &x, double &y, double &z);
251  virtual void WorldToView(double &, double &, double &) {}
253 
255 
260  virtual int *GetSize() VTK_SIZEHINT(2);
261  virtual int *GetOrigin() VTK_SIZEHINT(2);
262  void GetTiledSize(int *width, int *height);
263  virtual void GetTiledSizeAndOrigin(int *width, int *height,
264  int *lowerLeftX, int *lowerLeftY);
266 
267  // The following methods describe the public pick interface for picking
268  // Props in a viewport.
269 
276  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
277 
285  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1,
286  double selectionX2, double selectionY2) = 0;
287 
293  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY,
295 
301  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1,
302  double selectionX2, double selectionY2,
304 
306 
310  double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;}
311  double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;}
312  double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;};
313  double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;};
314  double GetPickX1() const {return this->PickX1;}
315  double GetPickY1() const {return this->PickY1;}
316  double GetPickX2() const {return this->PickX2;}
317  double GetPickY2() const {return this->PickY2;}
318  vtkGetMacro(IsPicking, int);
319  vtkGetMacro(CurrentPickId, unsigned int);
320  void SetCurrentPickId(unsigned int a) {this->CurrentPickId = a;};
321  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
323 
327  virtual double GetPickedZ() = 0;
328 
329 protected:
330  // Create a vtkViewport with a black background, a white ambient light,
331  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
332  // culling turned off.
333  vtkViewport();
334  ~vtkViewport() override;
335 
336  // Picking functions to be implemented by sub-classes
337  // Perform the main picking loop
338  virtual void DevicePickRender() = 0;
339  // Enter a pick mode
340  virtual void StartPick(unsigned int pickFromSize) = 0;
341  // Set the pick id to the next id before drawing an object
342  virtual void UpdatePickId() = 0;
343  // Exit Pick mode
344  virtual void DonePick() = 0;
345  // Return the id of the picked object, only valid after a call to DonePick
346  virtual unsigned int GetPickedId() = 0;
347  // Return the number of objects picked, only valid after a call to DonePick
348  virtual unsigned int GetNumPickedIds() = 0;
349  // Put no more than atMost picked object ids into the callerBuffer and
350  // return the number of picked objects returned.
351  virtual int GetPickedIds(unsigned int atMost, unsigned int *callerBuffer) = 0;
352 
353  // Ivars for picking
354  // Store a picked Prop (contained in an assembly path)
358  // Boolean flag to determine if picking is enabled for this render
360  unsigned int CurrentPickId;
361  double PickX1;
362  double PickY1;
363  double PickX2;
364  double PickY2;
365  // End Ivars for picking
366 
370  double Background[3];
371  double Background2[3];
373  double Viewport[4];
374  double Aspect[2];
375  double PixelAspect[2];
376  double Center[2];
378 
379  int Size[2];
380  int Origin[2];
381  double DisplayPoint[3];
382  double ViewPoint[3];
383  double WorldPoint[4];
384 
385 
386 private:
387  vtkViewport(const vtkViewport&) = delete;
388  void operator=(const vtkViewport&) = delete;
389 };
390 
391 
392 
393 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:44
a list of 2D actors
unsigned int CurrentPickId
Definition: vtkViewport.h:360
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:357
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetCurrentPickId(unsigned int a)
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:320
abstract specification for Viewports
Definition: vtkViewport.h:44
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:251
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:60
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:355
vtkPropCollection * Props
Definition: vtkViewport.h:367
double PickY2
Definition: vtkViewport.h:364
an ordered list of Props
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:230
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:245
a list of nodes that form an assembly path
a simple class to control print indentation
Definition: vtkIndent.h:33
double GetPickWidth() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:312
double GetPickX1() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:314
#define VTK_SIZEHINT(...)
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:356
double GetPickY1() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:315
double PickX2
Definition: vtkViewport.h:363
double PickX1
Definition: vtkViewport.h:361
double GetPickHeight() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:313
double GetPickY() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:311
double GetPickX2() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:316
vtkWindow * VTKWindow
Definition: vtkViewport.h:369
double GetPickY2() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
Definition: vtkViewport.h:317
bool GradientBackground
Definition: vtkViewport.h:377
double PickY1
Definition: vtkViewport.h:362
double BackgroundAlpha
Definition: vtkViewport.h:372
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:368