VTK  9.3.0
vtkViewport.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
35 #ifndef vtkViewport_h
36 #define vtkViewport_h
37 
38 #include "vtkObject.h"
39 #include "vtkRenderingCoreModule.h" // For export macro
40 
41 #include "vtkSelection.h" // Needed for selection
42 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
43 
44 #include <array> // To store matrices
45 
46 VTK_ABI_NAMESPACE_BEGIN
48 class vtkAssemblyPath;
49 class vtkProp;
50 class vtkPropCollection;
51 class vtkWindow;
52 
53 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
54 {
55 public:
56  vtkTypeMacro(vtkViewport, vtkObject);
57  void PrintSelf(ostream& os, vtkIndent indent) override;
58 
65 
69  vtkPropCollection* GetViewProps() { return this->Props; }
70 
75 
81 
86 
88 
93  void AddActor2D(vtkProp* p);
97 
99 
103  vtkSetVector3Macro(Background, double);
104  vtkGetVector3Macro(Background, double);
106 
108 
112  vtkSetVector3Macro(Background2, double);
113  vtkGetVector3Macro(Background2, double);
115  //
116 
118 
122  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
123  vtkGetMacro(BackgroundAlpha, double);
125 
127 
132  vtkSetMacro(GradientBackground, bool);
133  vtkGetMacro(GradientBackground, bool);
134  vtkBooleanMacro(GradientBackground, bool);
136 
137  enum class GradientModes : int
138  {
139  // Background color is used at the bottom, Background2 color is used at the top.
140  VTK_GRADIENT_VERTICAL,
141  // Background color on the left, Background2 color on the right.
142  VTK_GRADIENT_HORIZONTAL,
143  // Background color in the center, Background2 color on and beyond the ellipse edge.
144  // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
145  // width and height.
146  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
147  // Background color in the center, Background2 color on and beyond the ellipse edge.
148  // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
149  // width and height.
150  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
151  };
152 
154 
162 
164 
168  vtkSetVector2Macro(Aspect, double);
169  vtkGetVectorMacro(Aspect, double, 2);
170  virtual void ComputeAspect();
172 
174 
179  vtkSetVector2Macro(PixelAspect, double);
180  vtkGetVectorMacro(PixelAspect, double, 2);
182 
184 
189  vtkSetVector4Macro(Viewport, double);
190  vtkGetVectorMacro(Viewport, double, 4);
192 
194 
199  vtkSetVector3Macro(DisplayPoint, double);
200  vtkGetVectorMacro(DisplayPoint, double, 3);
202 
204 
209  vtkSetVector3Macro(ViewPoint, double);
210  vtkGetVectorMacro(ViewPoint, double, 3);
212 
214 
218  vtkSetVector4Macro(WorldPoint, double);
219  vtkGetVectorMacro(WorldPoint, double, 4);
221 
225  virtual double* GetCenter() VTK_SIZEHINT(2);
226 
230  virtual vtkTypeBool IsInViewport(int x, int y);
231 
235  virtual vtkWindow* GetVTKWindow() = 0;
236 
240  virtual void DisplayToView(); // these get modified in subclasses
241 
245  virtual void ViewToDisplay(); // to handle stereo rendering
246 
250  virtual void WorldToView();
251 
255  virtual void ViewToWorld();
256 
260  void DisplayToWorld()
261  {
262  this->DisplayToView();
263  this->ViewToWorld();
264  }
265 
270  {
271  this->WorldToView();
272  this->ViewToDisplay();
273  }
274 
278  inline void WorldToDisplay(double& x, double& y, double& z)
279  {
280  this->WorldToView(x, y, z);
281  this->ViewToDisplay(x, y, z);
282  }
283 
285 
292  virtual void LocalDisplayToDisplay(double& x, double& y);
293  virtual void DisplayToNormalizedDisplay(double& u, double& v);
294  virtual void NormalizedDisplayToViewport(double& x, double& y);
295  virtual void ViewportToNormalizedViewport(double& u, double& v);
296  virtual void NormalizedViewportToView(double& x, double& y, double& z);
297  virtual void ViewToPose(double&, double&, double&) {}
298  virtual void PoseToWorld(double&, double&, double&) {}
299  virtual void DisplayToLocalDisplay(double& x, double& y);
300  virtual void NormalizedDisplayToDisplay(double& u, double& v);
301  virtual void ViewportToNormalizedDisplay(double& x, double& y);
302  virtual void NormalizedViewportToViewport(double& u, double& v);
303  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
304  virtual void PoseToView(double&, double&, double&) {}
305  virtual void WorldToPose(double&, double&, double&) {}
306  virtual void ViewToWorld(double&, double&, double&) {}
307  virtual void WorldToView(double&, double&, double&) {}
308  virtual void ViewToDisplay(double& x, double& y, double& z);
310 
312 
317  virtual int* GetSize() VTK_SIZEHINT(2);
318  virtual int* GetOrigin() VTK_SIZEHINT(2);
319  void GetTiledSize(int* width, int* height);
320  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
322 
323  // The following methods describe the public pick interface for picking
324  // Props in a viewport without/with setting fieldAssociation and selection.
325 
332  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
333 
341  virtual vtkAssemblyPath* PickProp(
342  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
343 
349  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
350 
356  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
357  double selectionY2, vtkPropCollection*);
358 
367  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
368  vtkSmartPointer<vtkSelection> selection) = 0;
369 
379  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
380  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
381 
389  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
390  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
391 
399  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
400  double selectionY2, vtkPropCollection*, int fieldAssociation,
401  vtkSmartPointer<vtkSelection> selection);
402 
404 
408  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
409  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
410  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
411  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
412  double GetPickX1() const { return this->PickX1; }
413  double GetPickY1() const { return this->PickY1; }
414  double GetPickX2() const { return this->PickX2; }
415  double GetPickY2() const { return this->PickY2; }
416  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
418 
422  virtual double GetPickedZ() { return this->PickedZ; }
423 
425 
429  vtkSetVector3Macro(EnvironmentalBG, double);
430  vtkGetVector3Macro(EnvironmentalBG, double);
432 
434 
438  vtkSetVector3Macro(EnvironmentalBG2, double);
439  vtkGetVector3Macro(EnvironmentalBG2, double);
442 
448  vtkSetMacro(GradientEnvironmentalBG, bool);
449  vtkGetMacro(GradientEnvironmentalBG, bool);
450  vtkBooleanMacro(GradientEnvironmentalBG, bool);
452 
453 protected:
454  // Create a vtkViewport with a black background, a white ambient light,
455  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
456  // culling turned off.
458  ~vtkViewport() override;
459 
460  // Ivars for picking
461  // Store a picked Prop (contained in an assembly path)
465  double PickX1;
466  double PickY1;
467  double PickX2;
468  double PickY2;
469  double PickedZ;
470  // End Ivars for picking
471 
475  double Background[3];
476  double Background2[3];
478  double Viewport[4];
479  double Aspect[2];
480  double PixelAspect[2];
481  double Center[2];
483  GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
484 
485  double EnvironmentalBG[3];
486  double EnvironmentalBG2[3];
488 
489  int Size[2];
490  int Origin[2];
491  double DisplayPoint[3];
492  double ViewPoint[3];
493  double WorldPoint[4];
494 
495 private:
496  std::array<int, 2> LastComputeAspectSize;
497  std::array<double, 4> LastComputeAspectVPort;
498  std::array<double, 2> LastComputeAspectPixelAspect;
499 
500  vtkViewport(const vtkViewport&) = delete;
501  void operator=(const vtkViewport&) = delete;
502 };
503 
504 VTK_ABI_NAMESPACE_END
505 #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:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:55
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:59
Hold a reference to a vtkObjectBase instance.
abstract specification for Viewports
Definition: vtkViewport.h:54
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:415
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:306
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:412
vtkPropCollection * Props
Definition: vtkViewport.h:472
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:278
vtkTypeBool HasViewProp(vtkProp *)
Query if a prop is in the list of props.
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:305
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:269
~vtkViewport() override
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:462
virtual void ViewToNormalizedViewport(double &x, double &y, double &z)
These methods map from one coordinate system to another.
double PickX2
Definition: vtkViewport.h:467
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.
vtkGetEnumMacro(GradientMode, GradientModes)
Specify the direction of the gradient background.
bool GradientBackground
Definition: vtkViewport.h:482
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:297
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:414
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:473
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:411
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:298
vtkWindow * VTKWindow
Definition: vtkViewport.h:474
virtual void ComputeAspect()
Set the aspect ratio of the rendered image.
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:464
double BackgroundAlpha
Definition: vtkViewport.h:477
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:465
vtkSetEnumMacro(GradientMode, GradientModes)
Specify the direction of the gradient background.
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:463
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
Definition: vtkViewport.h:487
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
Definition: vtkViewport.h:422
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:69
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:410
double PickY1
Definition: vtkViewport.h:466
void RemoveAllViewProps()
Remove all props from the list of props.
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:409
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:304
double PickY2
Definition: vtkViewport.h:468
virtual void ViewportToNormalizedViewport(double &u, double &v)
These methods map from one coordinate system to another.
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:413
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:307
double PickedZ
Definition: vtkViewport.h:469
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
@ Background
Definition: vtkX3D.h:71
@ height
Definition: vtkX3D.h:254
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_SIZEHINT(...)