VTK  9.2.6
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 =========================================================================*/
47 #ifndef vtkViewport_h
48 #define vtkViewport_h
49 
50 #include "vtkObject.h"
51 #include "vtkRenderingCoreModule.h" // For export macro
52 
53 #include "vtkSelection.h" // Needed for selection
54 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
55 
56 #include <array> // To store matrices
57 
59 class vtkAssemblyPath;
60 class vtkProp;
61 class vtkPropCollection;
62 class vtkWindow;
63 
64 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
65 {
66 public:
67  vtkTypeMacro(vtkViewport, vtkObject);
68  void PrintSelf(ostream& os, vtkIndent indent) override;
69 
76 
80  vtkPropCollection* GetViewProps() { return this->Props; }
81 
86 
92 
96  void RemoveAllViewProps(void);
97 
99 
104  void AddActor2D(vtkProp* p);
108 
110 
114  vtkSetVector3Macro(Background, double);
115  vtkGetVector3Macro(Background, double);
117 
119 
123  vtkSetVector3Macro(Background2, double);
124  vtkGetVector3Macro(Background2, double);
126  //
127 
129 
133  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
134  vtkGetMacro(BackgroundAlpha, double);
136 
138 
143  vtkSetMacro(GradientBackground, bool);
144  vtkGetMacro(GradientBackground, bool);
145  vtkBooleanMacro(GradientBackground, bool);
147 
149 
153  vtkSetVector2Macro(Aspect, double);
154  vtkGetVectorMacro(Aspect, double, 2);
155  virtual void ComputeAspect();
157 
159 
164  vtkSetVector2Macro(PixelAspect, double);
165  vtkGetVectorMacro(PixelAspect, double, 2);
167 
169 
174  vtkSetVector4Macro(Viewport, double);
175  vtkGetVectorMacro(Viewport, double, 4);
177 
179 
184  vtkSetVector3Macro(DisplayPoint, double);
185  vtkGetVectorMacro(DisplayPoint, double, 3);
187 
189 
194  vtkSetVector3Macro(ViewPoint, double);
195  vtkGetVectorMacro(ViewPoint, double, 3);
197 
199 
203  vtkSetVector4Macro(WorldPoint, double);
204  vtkGetVectorMacro(WorldPoint, double, 4);
206 
210  virtual double* GetCenter() VTK_SIZEHINT(2);
211 
215  virtual int IsInViewport(int x, int y);
216 
220  virtual vtkWindow* GetVTKWindow() = 0;
221 
225  virtual void DisplayToView(); // these get modified in subclasses
226 
230  virtual void ViewToDisplay(); // to handle stereo rendering
231 
235  virtual void WorldToView();
236 
240  virtual void ViewToWorld();
241 
245  void DisplayToWorld()
246  {
247  this->DisplayToView();
248  this->ViewToWorld();
249  }
250 
255  {
256  this->WorldToView();
257  this->ViewToDisplay();
258  }
259 
263  inline void WorldToDisplay(double& x, double& y, double& z)
264  {
265  this->WorldToView(x, y, z);
266  this->ViewToDisplay(x, y, z);
267  }
268 
270 
277  virtual void LocalDisplayToDisplay(double& x, double& y);
278  virtual void DisplayToNormalizedDisplay(double& u, double& v);
279  virtual void NormalizedDisplayToViewport(double& x, double& y);
280  virtual void ViewportToNormalizedViewport(double& u, double& v);
281  virtual void NormalizedViewportToView(double& x, double& y, double& z);
282  virtual void ViewToPose(double&, double&, double&) {}
283  virtual void PoseToWorld(double&, double&, double&) {}
284  virtual void DisplayToLocalDisplay(double& x, double& y);
285  virtual void NormalizedDisplayToDisplay(double& u, double& v);
286  virtual void ViewportToNormalizedDisplay(double& x, double& y);
287  virtual void NormalizedViewportToViewport(double& u, double& v);
288  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
289  virtual void PoseToView(double&, double&, double&) {}
290  virtual void WorldToPose(double&, double&, double&) {}
291  virtual void ViewToWorld(double&, double&, double&) {}
292  virtual void WorldToView(double&, double&, double&) {}
293  virtual void ViewToDisplay(double& x, double& y, double& z);
295 
297 
302  virtual int* GetSize() VTK_SIZEHINT(2);
303  virtual int* GetOrigin() VTK_SIZEHINT(2);
304  void GetTiledSize(int* width, int* height);
305  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
307 
308  // The following methods describe the public pick interface for picking
309  // Props in a viewport without/with setting fieldAssociation and selection.
310 
317  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
318 
326  virtual vtkAssemblyPath* PickProp(
327  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
328 
334  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
335 
341  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
342  double selectionY2, vtkPropCollection*);
343 
352  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
353  vtkSmartPointer<vtkSelection> selection) = 0;
354 
364  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
365  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
366 
374  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
375  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
376 
384  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
385  double selectionY2, vtkPropCollection*, int fieldAssociation,
386  vtkSmartPointer<vtkSelection> selection);
387 
389 
393  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
394  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
395  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
396  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
397  double GetPickX1() const { return this->PickX1; }
398  double GetPickY1() const { return this->PickY1; }
399  double GetPickX2() const { return this->PickX2; }
400  double GetPickY2() const { return this->PickY2; }
401  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
403 
407  virtual double GetPickedZ() { return this->PickedZ; }
408 
410 
414  vtkSetVector3Macro(EnvironmentalBG, double);
415  vtkGetVector3Macro(EnvironmentalBG, double);
417 
419 
423  vtkSetVector3Macro(EnvironmentalBG2, double);
424  vtkGetVector3Macro(EnvironmentalBG2, double);
427 
433  vtkSetMacro(GradientEnvironmentalBG, bool);
434  vtkGetMacro(GradientEnvironmentalBG, bool);
435  vtkBooleanMacro(GradientEnvironmentalBG, bool);
437 
438 protected:
439  // Create a vtkViewport with a black background, a white ambient light,
440  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
441  // culling turned off.
443  ~vtkViewport() override;
444 
445  // Ivars for picking
446  // Store a picked Prop (contained in an assembly path)
450  double PickX1;
451  double PickY1;
452  double PickX2;
453  double PickY2;
454  double PickedZ;
455  // End Ivars for picking
456 
460  double Background[3];
461  double Background2[3];
463  double Viewport[4];
464  double Aspect[2];
465  double PixelAspect[2];
466  double Center[2];
468 
469  double EnvironmentalBG[3];
470  double EnvironmentalBG2[3];
472 
473  int Size[2];
474  int Origin[2];
475  double DisplayPoint[3];
476  double ViewPoint[3];
477  double WorldPoint[4];
478 
479 private:
480  std::array<int, 2> LastComputeAspectSize;
481  std::array<double, 4> LastComputeAspectVPort;
482  std::array<double, 2> LastComputeAspectPixelAspect;
483 
484  vtkViewport(const vtkViewport&) = delete;
485  void operator=(const vtkViewport&) = delete;
486 };
487 
488 #endif
a list of 2D actors
a list of nodes that form an assembly path
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:66
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:69
Hold a reference to a vtkObjectBase instance.
abstract specification for Viewports
Definition: vtkViewport.h:65
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:400
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:291
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:397
vtkPropCollection * Props
Definition: vtkViewport.h:457
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:263
virtual void DisplayToLocalDisplay(double &x, double &y)
These methods map from one coordinate system to another.
virtual void WorldToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:290
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:254
~vtkViewport() override
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:447
virtual void ViewToNormalizedViewport(double &x, double &y, double &z)
These methods map from one coordinate system to another.
double PickX2
Definition: vtkViewport.h:452
virtual double * GetCenter()
Return the center of this viewport in display coordinates.
virtual int * GetSize()
Get the size and origin of the viewport in display coordinates.
bool GradientBackground
Definition: vtkViewport.h:467
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:282
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:399
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:458
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:396
virtual void NormalizedDisplayToViewport(double &x, double &y)
These methods map from one coordinate system to another.
void RemoveActor2D(vtkProp *p)
Add/Remove different types of props to the renderer.
virtual void PoseToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:283
vtkWindow * VTKWindow
Definition: vtkViewport.h:459
virtual void ComputeAspect()
Set the aspect ratio of the rendered image.
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:449
double BackgroundAlpha
Definition: vtkViewport.h:462
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void NormalizedViewportToView(double &x, double &y, double &z)
These methods map from one coordinate system to another.
vtkActor2DCollection * GetActors2D()
Add/Remove different types of props to the renderer.
void AddActor2D(vtkProp *p)
Add/Remove different types of props to the renderer.
virtual void ViewportToNormalizedDisplay(double &x, double &y)
These methods map from one coordinate system to another.
double PickX1
Definition: vtkViewport.h:450
virtual void LocalDisplayToDisplay(double &x, double &y)
These methods map from one coordinate system to another.
void AddViewProp(vtkProp *)
Add a prop to the list of props.
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:448
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
Definition: vtkViewport.h:471
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
Definition: vtkViewport.h:407
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:80
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:395
double PickY1
Definition: vtkViewport.h:451
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:394
void RemoveAllViewProps(void)
Remove all props from the list of props.
virtual void DisplayToNormalizedDisplay(double &u, double &v)
These methods map from one coordinate system to another.
virtual void ViewToDisplay(double &x, double &y, double &z)
These methods map from one coordinate system to another.
virtual void NormalizedViewportToViewport(double &u, double &v)
These methods map from one coordinate system to another.
void RemoveViewProp(vtkProp *)
Remove a prop from the list of props.
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:289
double PickY2
Definition: vtkViewport.h:453
virtual void ViewportToNormalizedViewport(double &u, double &v)
These methods map from one coordinate system to another.
int HasViewProp(vtkProp *)
Query if a prop is in the list of props.
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:398
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:292
double PickedZ
Definition: vtkViewport.h:454
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ Background
Definition: vtkX3D.h:77
@ height
Definition: vtkX3D.h:260
#define VTK_SIZEHINT(...)