VTK  9.7.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
26 #ifndef vtkViewport_h
27 #define vtkViewport_h
28 
29 #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0
30 #include "vtkObject.h"
31 #include "vtkRenderingCoreModule.h" // For export macro
32 #include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
33 
34 #include "vtkSelection.h" // Needed for selection
35 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
36 
37 #include <array> // To store matrices
38 
39 VTK_ABI_NAMESPACE_BEGIN
41 class vtkAssemblyPath;
42 class vtkProp;
43 class vtkPropCollection;
44 class vtkWindow;
45 
46 class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkViewport : public vtkObject
47 {
48 public:
49  vtkTypeMacro(vtkViewport, vtkObject);
50  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
58  void AddViewProp(vtkProp*);
59 
63  vtkPropCollection* GetViewProps() { return this->Props; }
64 
68  vtkTypeBool HasViewProp(vtkProp*);
69 
75  void RemoveViewProp(vtkProp*);
76 
81  void RemoveAllViewProps();
82 
87  VTK_DEPRECATED_IN_9_7_0("Use GetViewProps() instead.")
89  vtkActor2DCollection* GetActors2D();
90 
92 
96  vtkSetVector3Macro(Background, double);
97  vtkGetVector3Macro(Background, double);
99 
101 
105  vtkSetVector3Macro(Background2, double);
106  vtkGetVector3Macro(Background2, double);
108  //
109 
111 
115  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
116  vtkGetMacro(BackgroundAlpha, double);
118 
120 
125  vtkSetMacro(GradientBackground, bool);
126  vtkGetMacro(GradientBackground, bool);
127  vtkBooleanMacro(GradientBackground, bool);
129 
131 
136  vtkSetMacro(DitherGradient, bool);
137  vtkGetMacro(DitherGradient, bool);
138  vtkBooleanMacro(DitherGradient, bool);
140 
141  enum class GradientModes : int
142  {
143  // Background color is used at the bottom, Background2 color is used at the top.
144  VTK_GRADIENT_VERTICAL,
145  // Background color on the left, Background2 color on the right.
146  VTK_GRADIENT_HORIZONTAL,
147  // Background color in the center, Background2 color on and beyond the ellipse edge.
148  // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
149  // width and height.
150  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
151  // Background color in the center, Background2 color on and beyond the ellipse edge.
152  // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
153  // width and height.
154  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
155  };
156 
158 
163  vtkSetEnumMacro(GradientMode, GradientModes);
164  vtkGetEnumMacro(GradientMode, GradientModes);
166 
168 
172  vtkSetVector2Macro(Aspect, double);
173  vtkGetVectorMacro(Aspect, double, 2);
174  virtual void ComputeAspect();
176 
178 
183  vtkSetVector2Macro(PixelAspect, double);
184  vtkGetVectorMacro(PixelAspect, double, 2);
186 
188 
193  vtkSetVector4Macro(Viewport, double);
194  vtkGetVectorMacro(Viewport, double, 4);
196 
198 
203  vtkSetVector3Macro(DisplayPoint, double);
204  vtkGetVectorMacro(DisplayPoint, double, 3);
206 
208 
213  vtkSetVector3Macro(ViewPoint, double);
214  vtkGetVectorMacro(ViewPoint, double, 3);
216 
218 
222  vtkSetVector4Macro(WorldPoint, double);
223  vtkGetVectorMacro(WorldPoint, double, 4);
225 
229  virtual double* GetCenter() VTK_SIZEHINT(2);
230 
234  virtual vtkTypeBool IsInViewport(int x, int y);
235 
239  virtual vtkWindow* GetVTKWindow() = 0;
240 
244  virtual void DisplayToView(); // these get modified in subclasses
245 
249  virtual void ViewToDisplay(); // to handle stereo rendering
250 
254  virtual void WorldToView();
255 
259  virtual void ViewToWorld();
260 
264  void DisplayToWorld()
265  {
266  this->DisplayToView();
267  this->ViewToWorld();
268  }
269 
274  {
275  this->WorldToView();
276  this->ViewToDisplay();
277  }
278 
282  void WorldToDisplay(double& x, double& y, double& z)
283  {
284  this->WorldToView(x, y, z);
285  this->ViewToDisplay(x, y, z);
286  }
287 
289 
296  virtual void LocalDisplayToDisplay(double& x, double& y);
297  virtual void DisplayToNormalizedDisplay(double& u, double& v);
298  virtual void NormalizedDisplayToViewport(double& x, double& y);
299  virtual void ViewportToNormalizedViewport(double& u, double& v);
300  virtual void NormalizedViewportToView(double& x, double& y, double& z);
301  virtual void ViewToPose(double&, double&, double&) {}
302  virtual void PoseToWorld(double&, double&, double&) {}
303  virtual void DisplayToLocalDisplay(double& x, double& y);
304  virtual void NormalizedDisplayToDisplay(double& u, double& v);
305  virtual void ViewportToNormalizedDisplay(double& x, double& y);
306  virtual void NormalizedViewportToViewport(double& u, double& v);
307  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
308  virtual void PoseToView(double&, double&, double&) {}
309  virtual void WorldToPose(double&, double&, double&) {}
310  virtual void ViewToWorld(double&, double&, double&) {}
311  virtual void WorldToView(double&, double&, double&) {}
312  virtual void ViewToDisplay(double& x, double& y, double& z);
314 
316 
321  virtual int* GetSize() VTK_SIZEHINT(2);
322  virtual int* GetOrigin() VTK_SIZEHINT(2);
323  void GetTiledSize(int* width, int* height);
324  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
326 
327  // The following methods describe the public pick interface for picking
328  // Props in a viewport without/with setting fieldAssociation and selection.
329 
336  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
337 
345  virtual vtkAssemblyPath* PickProp(
346  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
347 
353  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
354 
360  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
361  double selectionY2, vtkPropCollection*);
362 
371  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
372  vtkSmartPointer<vtkSelection> selection) = 0;
373 
383  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
384  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
385 
393  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
394  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
395 
403  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
404  double selectionY2, vtkPropCollection*, int fieldAssociation,
405  vtkSmartPointer<vtkSelection> selection);
406 
408 
412  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
413  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
414  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
415  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
416  double GetPickX1() const { return this->PickX1; }
417  double GetPickY1() const { return this->PickY1; }
418  double GetPickX2() const { return this->PickX2; }
419  double GetPickY2() const { return this->PickY2; }
421  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
423 
427  virtual double GetPickedZ() { return this->PickedZ; }
428 
430 
434  vtkSetVector3Macro(EnvironmentalBG, double);
435  vtkGetVector3Macro(EnvironmentalBG, double);
437 
439 
443  vtkSetVector3Macro(EnvironmentalBG2, double);
444  vtkGetVector3Macro(EnvironmentalBG2, double);
447 
453  vtkSetMacro(GradientEnvironmentalBG, bool);
454  vtkGetMacro(GradientEnvironmentalBG, bool);
455  vtkBooleanMacro(GradientEnvironmentalBG, bool);
457 
458 protected:
459  // Create a vtkViewport with a black background, a white ambient light,
460  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
461  // culling turned off.
462  vtkViewport();
463  ~vtkViewport() override;
464 
465  // Ivars for picking
466  // Store a picked Prop (contained in an assembly path)
470  double PickX1;
471  double PickY1;
472  double PickX2;
473  double PickY2;
474  double PickedZ;
475  // End Ivars for picking
476 
478 
479  // VTK_DEPRECATED_IN_9_7_0
481 
483  double Background[3];
484  double Background2[3];
486  double Viewport[4];
487  double Aspect[2];
488  double PixelAspect[2];
489  double Center[2];
492  GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
493 
494  double EnvironmentalBG[3];
495  double EnvironmentalBG2[3];
497 
498  int Size[2];
499  int Origin[2];
500  double DisplayPoint[3];
501  double ViewPoint[3];
502  double WorldPoint[4];
503 
504 private:
505  std::array<int, 2> LastComputeAspectSize;
506  std::array<double, 4> LastComputeAspectVPort;
507  std::array<double, 2> LastComputeAspectPixelAspect;
508 
509  vtkViewport(const vtkViewport&) = delete;
510  void operator=(const vtkViewport&) = delete;
511 };
512 
513 VTK_ABI_NAMESPACE_END
514 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:49
double PickedZ
Definition: vtkViewport.h:474
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:282
virtual void WorldToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:309
a list of 2D actors
abstract base class for most VTK objects
Definition: vtkObject.h:52
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:469
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
abstract specification for Viewports
Definition: vtkViewport.h:46
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:414
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:311
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:49
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:467
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:413
vtkPropCollection * Props
Definition: vtkViewport.h:477
double PickY2
Definition: vtkViewport.h:473
bool GradientEnvironmentalBG
Definition: vtkViewport.h:496
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:41
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:418
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:273
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:310
a list of nodes that form an assembly path
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:417
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void PoseToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:302
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:415
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:301
#define VTK_SIZEHINT(...)
bool DitherGradient
Definition: vtkViewport.h:491
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:468
#define VTK_MARSHALEXCLUDE(reason)
double PickX2
Definition: vtkViewport.h:472
double PickX1
Definition: vtkViewport.h:470
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:416
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:308
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:419
#define VTK_MARSHALAUTO
vtkWindow * VTKWindow
Definition: vtkViewport.h:482
bool GradientBackground
Definition: vtkViewport.h:490
#define VTK_DEPRECATED_IN_9_7_0(reason)
double PickY1
Definition: vtkViewport.h:471
double BackgroundAlpha
Definition: vtkViewport.h:485
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:480
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL