VTK  9.3.1
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 
138 
143  vtkSetMacro(DitherGradient, bool);
144  vtkGetMacro(DitherGradient, bool);
145  vtkBooleanMacro(DitherGradient, bool);
147 
148  enum class GradientModes : int
149  {
150  // Background color is used at the bottom, Background2 color is used at the top.
151  VTK_GRADIENT_VERTICAL,
152  // Background color on the left, Background2 color on the right.
153  VTK_GRADIENT_HORIZONTAL,
154  // Background color in the center, Background2 color on and beyond the ellipse edge.
155  // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
156  // width and height.
157  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
158  // Background color in the center, Background2 color on and beyond the ellipse edge.
159  // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
160  // width and height.
161  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
162  };
163 
165 
173 
175 
179  vtkSetVector2Macro(Aspect, double);
180  vtkGetVectorMacro(Aspect, double, 2);
181  virtual void ComputeAspect();
183 
185 
190  vtkSetVector2Macro(PixelAspect, double);
191  vtkGetVectorMacro(PixelAspect, double, 2);
193 
195 
200  vtkSetVector4Macro(Viewport, double);
201  vtkGetVectorMacro(Viewport, double, 4);
203 
205 
210  vtkSetVector3Macro(DisplayPoint, double);
211  vtkGetVectorMacro(DisplayPoint, double, 3);
213 
215 
220  vtkSetVector3Macro(ViewPoint, double);
221  vtkGetVectorMacro(ViewPoint, double, 3);
223 
225 
229  vtkSetVector4Macro(WorldPoint, double);
230  vtkGetVectorMacro(WorldPoint, double, 4);
232 
236  virtual double* GetCenter() VTK_SIZEHINT(2);
237 
241  virtual vtkTypeBool IsInViewport(int x, int y);
242 
246  virtual vtkWindow* GetVTKWindow() = 0;
247 
251  virtual void DisplayToView(); // these get modified in subclasses
252 
256  virtual void ViewToDisplay(); // to handle stereo rendering
257 
261  virtual void WorldToView();
262 
266  virtual void ViewToWorld();
267 
271  void DisplayToWorld()
272  {
273  this->DisplayToView();
274  this->ViewToWorld();
275  }
276 
281  {
282  this->WorldToView();
283  this->ViewToDisplay();
284  }
285 
289  inline void WorldToDisplay(double& x, double& y, double& z)
290  {
291  this->WorldToView(x, y, z);
292  this->ViewToDisplay(x, y, z);
293  }
294 
296 
303  virtual void LocalDisplayToDisplay(double& x, double& y);
304  virtual void DisplayToNormalizedDisplay(double& u, double& v);
305  virtual void NormalizedDisplayToViewport(double& x, double& y);
306  virtual void ViewportToNormalizedViewport(double& u, double& v);
307  virtual void NormalizedViewportToView(double& x, double& y, double& z);
308  virtual void ViewToPose(double&, double&, double&) {}
309  virtual void PoseToWorld(double&, double&, double&) {}
310  virtual void DisplayToLocalDisplay(double& x, double& y);
311  virtual void NormalizedDisplayToDisplay(double& u, double& v);
312  virtual void ViewportToNormalizedDisplay(double& x, double& y);
313  virtual void NormalizedViewportToViewport(double& u, double& v);
314  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
315  virtual void PoseToView(double&, double&, double&) {}
316  virtual void WorldToPose(double&, double&, double&) {}
317  virtual void ViewToWorld(double&, double&, double&) {}
318  virtual void WorldToView(double&, double&, double&) {}
319  virtual void ViewToDisplay(double& x, double& y, double& z);
321 
323 
328  virtual int* GetSize() VTK_SIZEHINT(2);
329  virtual int* GetOrigin() VTK_SIZEHINT(2);
330  void GetTiledSize(int* width, int* height);
331  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
333 
334  // The following methods describe the public pick interface for picking
335  // Props in a viewport without/with setting fieldAssociation and selection.
336 
343  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
344 
352  virtual vtkAssemblyPath* PickProp(
353  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
354 
360  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
361 
367  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
368  double selectionY2, vtkPropCollection*);
369 
378  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
379  vtkSmartPointer<vtkSelection> selection) = 0;
380 
390  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
391  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
392 
400  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
401  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
402 
410  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
411  double selectionY2, vtkPropCollection*, int fieldAssociation,
412  vtkSmartPointer<vtkSelection> selection);
413 
415 
419  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
420  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
421  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
422  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
423  double GetPickX1() const { return this->PickX1; }
424  double GetPickY1() const { return this->PickY1; }
425  double GetPickX2() const { return this->PickX2; }
426  double GetPickY2() const { return this->PickY2; }
427  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
429 
433  virtual double GetPickedZ() { return this->PickedZ; }
434 
436 
440  vtkSetVector3Macro(EnvironmentalBG, double);
441  vtkGetVector3Macro(EnvironmentalBG, double);
443 
445 
449  vtkSetVector3Macro(EnvironmentalBG2, double);
450  vtkGetVector3Macro(EnvironmentalBG2, double);
453 
459  vtkSetMacro(GradientEnvironmentalBG, bool);
460  vtkGetMacro(GradientEnvironmentalBG, bool);
461  vtkBooleanMacro(GradientEnvironmentalBG, bool);
463 
464 protected:
465  // Create a vtkViewport with a black background, a white ambient light,
466  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
467  // culling turned off.
469  ~vtkViewport() override;
470 
471  // Ivars for picking
472  // Store a picked Prop (contained in an assembly path)
476  double PickX1;
477  double PickY1;
478  double PickX2;
479  double PickY2;
480  double PickedZ;
481  // End Ivars for picking
482 
486  double Background[3];
487  double Background2[3];
489  double Viewport[4];
490  double Aspect[2];
491  double PixelAspect[2];
492  double Center[2];
495  GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
496 
497  double EnvironmentalBG[3];
498  double EnvironmentalBG2[3];
500 
501  int Size[2];
502  int Origin[2];
503  double DisplayPoint[3];
504  double ViewPoint[3];
505  double WorldPoint[4];
506 
507 private:
508  std::array<int, 2> LastComputeAspectSize;
509  std::array<double, 4> LastComputeAspectVPort;
510  std::array<double, 2> LastComputeAspectPixelAspect;
511 
512  vtkViewport(const vtkViewport&) = delete;
513  void operator=(const vtkViewport&) = delete;
514 };
515 
516 VTK_ABI_NAMESPACE_END
517 #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:426
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:317
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:423
vtkPropCollection * Props
Definition: vtkViewport.h:483
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:289
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:316
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:280
~vtkViewport() override
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:473
virtual void ViewToNormalizedViewport(double &x, double &y, double &z)
These methods map from one coordinate system to another.
double PickX2
Definition: vtkViewport.h:478
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:493
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:308
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:425
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:484
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:422
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:309
vtkWindow * VTKWindow
Definition: vtkViewport.h:485
virtual void ComputeAspect()
Set the aspect ratio of the rendered image.
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:475
double BackgroundAlpha
Definition: vtkViewport.h:488
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:476
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:474
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
Definition: vtkViewport.h:499
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
Definition: vtkViewport.h:433
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:421
double PickY1
Definition: vtkViewport.h:477
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:420
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.
bool DitherGradient
Definition: vtkViewport.h:494
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:315
double PickY2
Definition: vtkViewport.h:479
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:424
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:318
double PickedZ
Definition: vtkViewport.h:480
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(...)