VTK  9.3.20240329
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
45 #ifndef vtkViewport_h
46 #define vtkViewport_h
47 
48 #include "vtkObject.h"
49 #include "vtkRenderingCoreModule.h" // For export macro
50 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
51 
52 #include "vtkSelection.h" // Needed for selection
53 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
54 
55 #include <array> // To store matrices
56 
57 VTK_ABI_NAMESPACE_BEGIN
59 class vtkAssemblyPath;
60 class vtkProp;
61 class vtkPropCollection;
62 class vtkWindow;
63 
64 class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO 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 
97 
99 
104  void AddActor2D(vtkProp* p);
107  vtkActor2DCollection* GetActors2D();
109 
111 
115  vtkSetVector3Macro(Background, double);
116  vtkGetVector3Macro(Background, double);
118 
120 
124  vtkSetVector3Macro(Background2, double);
125  vtkGetVector3Macro(Background2, double);
127  //
128 
130 
134  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
135  vtkGetMacro(BackgroundAlpha, double);
137 
139 
144  vtkSetMacro(GradientBackground, bool);
145  vtkGetMacro(GradientBackground, bool);
146  vtkBooleanMacro(GradientBackground, bool);
148 
150 
155  vtkSetMacro(DitherGradient, bool);
156  vtkGetMacro(DitherGradient, bool);
157  vtkBooleanMacro(DitherGradient, bool);
159 
160  enum class GradientModes : int
161  {
162  // Background color is used at the bottom, Background2 color is used at the top.
163  VTK_GRADIENT_VERTICAL,
164  // Background color on the left, Background2 color on the right.
165  VTK_GRADIENT_HORIZONTAL,
166  // Background color in the center, Background2 color on and beyond the ellipse edge.
167  // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
168  // width and height.
169  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
170  // Background color in the center, Background2 color on and beyond the ellipse edge.
171  // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
172  // width and height.
173  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
174  };
175 
177 
185 
187 
191  vtkSetVector2Macro(Aspect, double);
192  vtkGetVectorMacro(Aspect, double, 2);
193  virtual void ComputeAspect();
195 
197 
202  vtkSetVector2Macro(PixelAspect, double);
203  vtkGetVectorMacro(PixelAspect, double, 2);
205 
207 
212  vtkSetVector4Macro(Viewport, double);
213  vtkGetVectorMacro(Viewport, double, 4);
215 
217 
222  vtkSetVector3Macro(DisplayPoint, double);
223  vtkGetVectorMacro(DisplayPoint, double, 3);
225 
227 
232  vtkSetVector3Macro(ViewPoint, double);
233  vtkGetVectorMacro(ViewPoint, double, 3);
235 
237 
241  vtkSetVector4Macro(WorldPoint, double);
242  vtkGetVectorMacro(WorldPoint, double, 4);
244 
248  virtual double* GetCenter() VTK_SIZEHINT(2);
249 
253  virtual vtkTypeBool IsInViewport(int x, int y);
254 
258  virtual vtkWindow* GetVTKWindow() = 0;
259 
263  virtual void DisplayToView(); // these get modified in subclasses
264 
268  virtual void ViewToDisplay(); // to handle stereo rendering
269 
273  virtual void WorldToView();
274 
278  virtual void ViewToWorld();
279 
283  void DisplayToWorld()
284  {
285  this->DisplayToView();
286  this->ViewToWorld();
287  }
288 
293  {
294  this->WorldToView();
295  this->ViewToDisplay();
296  }
297 
301  inline void WorldToDisplay(double& x, double& y, double& z)
302  {
303  this->WorldToView(x, y, z);
304  this->ViewToDisplay(x, y, z);
305  }
306 
308 
315  virtual void LocalDisplayToDisplay(double& x, double& y);
316  virtual void DisplayToNormalizedDisplay(double& u, double& v);
317  virtual void NormalizedDisplayToViewport(double& x, double& y);
318  virtual void ViewportToNormalizedViewport(double& u, double& v);
319  virtual void NormalizedViewportToView(double& x, double& y, double& z);
320  virtual void ViewToPose(double&, double&, double&) {}
321  virtual void PoseToWorld(double&, double&, double&) {}
322  virtual void DisplayToLocalDisplay(double& x, double& y);
323  virtual void NormalizedDisplayToDisplay(double& u, double& v);
324  virtual void ViewportToNormalizedDisplay(double& x, double& y);
325  virtual void NormalizedViewportToViewport(double& u, double& v);
326  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
327  virtual void PoseToView(double&, double&, double&) {}
328  virtual void WorldToPose(double&, double&, double&) {}
329  virtual void ViewToWorld(double&, double&, double&) {}
330  virtual void WorldToView(double&, double&, double&) {}
331  virtual void ViewToDisplay(double& x, double& y, double& z);
333 
335 
340  virtual int* GetSize() VTK_SIZEHINT(2);
341  virtual int* GetOrigin() VTK_SIZEHINT(2);
342  void GetTiledSize(int* width, int* height);
343  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
345 
346  // The following methods describe the public pick interface for picking
347  // Props in a viewport without/with setting fieldAssociation and selection.
348 
355  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
356 
364  virtual vtkAssemblyPath* PickProp(
365  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
366 
372  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
373 
379  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
380  double selectionY2, vtkPropCollection*);
381 
390  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
391  vtkSmartPointer<vtkSelection> selection) = 0;
392 
402  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
403  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
404 
412  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
413  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
414 
422  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
423  double selectionY2, vtkPropCollection*, int fieldAssociation,
424  vtkSmartPointer<vtkSelection> selection);
425 
427 
431  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
432  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
433  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
434  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
435  double GetPickX1() const { return this->PickX1; }
436  double GetPickY1() const { return this->PickY1; }
437  double GetPickX2() const { return this->PickX2; }
438  double GetPickY2() const { return this->PickY2; }
440  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
442 
446  virtual double GetPickedZ() { return this->PickedZ; }
447 
449 
453  vtkSetVector3Macro(EnvironmentalBG, double);
454  vtkGetVector3Macro(EnvironmentalBG, double);
456 
458 
462  vtkSetVector3Macro(EnvironmentalBG2, double);
463  vtkGetVector3Macro(EnvironmentalBG2, double);
466 
472  vtkSetMacro(GradientEnvironmentalBG, bool);
473  vtkGetMacro(GradientEnvironmentalBG, bool);
474  vtkBooleanMacro(GradientEnvironmentalBG, bool);
476 
477 protected:
478  // Create a vtkViewport with a black background, a white ambient light,
479  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
480  // culling turned off.
482  ~vtkViewport() override;
483 
484  // Ivars for picking
485  // Store a picked Prop (contained in an assembly path)
489  double PickX1;
490  double PickY1;
491  double PickX2;
492  double PickY2;
493  double PickedZ;
494  // End Ivars for picking
495 
499  double Background[3];
500  double Background2[3];
502  double Viewport[4];
503  double Aspect[2];
504  double PixelAspect[2];
505  double Center[2];
508  GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
509 
510  double EnvironmentalBG[3];
511  double EnvironmentalBG2[3];
513 
514  int Size[2];
515  int Origin[2];
516  double DisplayPoint[3];
517  double ViewPoint[3];
518  double WorldPoint[4];
519 
520 private:
521  std::array<int, 2> LastComputeAspectSize;
522  std::array<double, 4> LastComputeAspectVPort;
523  std::array<double, 2> LastComputeAspectPixelAspect;
524 
525  vtkViewport(const vtkViewport&) = delete;
526  void operator=(const vtkViewport&) = delete;
527 };
528 
529 VTK_ABI_NAMESPACE_END
530 #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:108
abstract base class for most VTK objects
Definition: vtkObject.h:162
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:159
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:438
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:329
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:435
vtkPropCollection * Props
Definition: vtkViewport.h:496
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:301
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:328
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:292
~vtkViewport() override
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:486
virtual void ViewToNormalizedViewport(double &x, double &y, double &z)
These methods map from one coordinate system to another.
double PickX2
Definition: vtkViewport.h:491
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:506
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:320
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:437
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:497
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:434
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:321
vtkWindow * VTKWindow
Definition: vtkViewport.h:498
virtual void ComputeAspect()
Set the aspect ratio of the rendered image.
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:488
double BackgroundAlpha
Definition: vtkViewport.h:501
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.
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:489
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:487
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
Definition: vtkViewport.h:512
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:433
double PickY1
Definition: vtkViewport.h:490
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:432
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:507
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:327
double PickY2
Definition: vtkViewport.h:492
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:436
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:330
double PickedZ
Definition: vtkViewport.h:493
window superclass for vtkRenderWindow
Definition: vtkWindow.h:48
@ Background
Definition: vtkX3D.h:71
@ height
Definition: vtkX3D.h:254
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_SIZEHINT(...)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)