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
26 #ifndef vtkViewport_h
27 #define vtkViewport_h
28 
29 #include "vtkObject.h"
30 #include "vtkRenderingCoreModule.h" // For export macro
31 
32 #include "vtkSelection.h" // Needed for selection
33 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
34 
35 #include <array> // To store matrices
36 
37 VTK_ABI_NAMESPACE_BEGIN
39 class vtkAssemblyPath;
40 class vtkProp;
41 class vtkPropCollection;
42 class vtkWindow;
43 
44 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
45 {
46 public:
47  vtkTypeMacro(vtkViewport, vtkObject);
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
55  void AddViewProp(vtkProp*);
56 
60  vtkPropCollection* GetViewProps() { return this->Props; }
61 
65  vtkTypeBool HasViewProp(vtkProp*);
66 
71  void RemoveViewProp(vtkProp*);
72 
76  void RemoveAllViewProps();
77 
79 
84  void AddActor2D(vtkProp* p);
85  void RemoveActor2D(vtkProp* p);
86  vtkActor2DCollection* GetActors2D();
88 
90 
94  vtkSetVector3Macro(Background, double);
95  vtkGetVector3Macro(Background, double);
97 
99 
103  vtkSetVector3Macro(Background2, double);
104  vtkGetVector3Macro(Background2, double);
106  //
107 
109 
113  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
114  vtkGetMacro(BackgroundAlpha, double);
116 
118 
123  vtkSetMacro(GradientBackground, bool);
124  vtkGetMacro(GradientBackground, bool);
125  vtkBooleanMacro(GradientBackground, bool);
127 
129 
134  vtkSetMacro(DitherGradient, bool);
135  vtkGetMacro(DitherGradient, bool);
136  vtkBooleanMacro(DitherGradient, bool);
138 
139  enum class GradientModes : int
140  {
141  // Background color is used at the bottom, Background2 color is used at the top.
142  VTK_GRADIENT_VERTICAL,
143  // Background color on the left, Background2 color on the right.
144  VTK_GRADIENT_HORIZONTAL,
145  // Background color in the center, Background2 color on and beyond the ellipse edge.
146  // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
147  // width and height.
148  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
149  // Background color in the center, Background2 color on and beyond the ellipse edge.
150  // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
151  // width and height.
152  VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
153  };
154 
156 
161  vtkSetEnumMacro(GradientMode, GradientModes);
162  vtkGetEnumMacro(GradientMode, GradientModes);
164 
166 
170  vtkSetVector2Macro(Aspect, double);
171  vtkGetVectorMacro(Aspect, double, 2);
172  virtual void ComputeAspect();
174 
176 
181  vtkSetVector2Macro(PixelAspect, double);
182  vtkGetVectorMacro(PixelAspect, double, 2);
184 
186 
191  vtkSetVector4Macro(Viewport, double);
192  vtkGetVectorMacro(Viewport, double, 4);
194 
196 
201  vtkSetVector3Macro(DisplayPoint, double);
202  vtkGetVectorMacro(DisplayPoint, double, 3);
204 
206 
211  vtkSetVector3Macro(ViewPoint, double);
212  vtkGetVectorMacro(ViewPoint, double, 3);
214 
216 
220  vtkSetVector4Macro(WorldPoint, double);
221  vtkGetVectorMacro(WorldPoint, double, 4);
223 
227  virtual double* GetCenter() VTK_SIZEHINT(2);
228 
232  virtual vtkTypeBool IsInViewport(int x, int y);
233 
237  virtual vtkWindow* GetVTKWindow() = 0;
238 
242  virtual void DisplayToView(); // these get modified in subclasses
243 
247  virtual void ViewToDisplay(); // to handle stereo rendering
248 
252  virtual void WorldToView();
253 
257  virtual void ViewToWorld();
258 
262  void DisplayToWorld()
263  {
264  this->DisplayToView();
265  this->ViewToWorld();
266  }
267 
272  {
273  this->WorldToView();
274  this->ViewToDisplay();
275  }
276 
280  inline void WorldToDisplay(double& x, double& y, double& z)
281  {
282  this->WorldToView(x, y, z);
283  this->ViewToDisplay(x, y, z);
284  }
285 
287 
294  virtual void LocalDisplayToDisplay(double& x, double& y);
295  virtual void DisplayToNormalizedDisplay(double& u, double& v);
296  virtual void NormalizedDisplayToViewport(double& x, double& y);
297  virtual void ViewportToNormalizedViewport(double& u, double& v);
298  virtual void NormalizedViewportToView(double& x, double& y, double& z);
299  virtual void ViewToPose(double&, double&, double&) {}
300  virtual void PoseToWorld(double&, double&, double&) {}
301  virtual void DisplayToLocalDisplay(double& x, double& y);
302  virtual void NormalizedDisplayToDisplay(double& u, double& v);
303  virtual void ViewportToNormalizedDisplay(double& x, double& y);
304  virtual void NormalizedViewportToViewport(double& u, double& v);
305  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
306  virtual void PoseToView(double&, double&, double&) {}
307  virtual void WorldToPose(double&, double&, double&) {}
308  virtual void ViewToWorld(double&, double&, double&) {}
309  virtual void WorldToView(double&, double&, double&) {}
310  virtual void ViewToDisplay(double& x, double& y, double& z);
312 
314 
319  virtual int* GetSize() VTK_SIZEHINT(2);
320  virtual int* GetOrigin() VTK_SIZEHINT(2);
321  void GetTiledSize(int* width, int* height);
322  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
324 
325  // The following methods describe the public pick interface for picking
326  // Props in a viewport without/with setting fieldAssociation and selection.
327 
334  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
335 
343  virtual vtkAssemblyPath* PickProp(
344  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
345 
351  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
352 
358  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
359  double selectionY2, vtkPropCollection*);
360 
369  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
370  vtkSmartPointer<vtkSelection> selection) = 0;
371 
381  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
382  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
383 
391  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
392  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
393 
401  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
402  double selectionY2, vtkPropCollection*, int fieldAssociation,
403  vtkSmartPointer<vtkSelection> selection);
404 
406 
410  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
411  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
412  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
413  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
414  double GetPickX1() const { return this->PickX1; }
415  double GetPickY1() const { return this->PickY1; }
416  double GetPickX2() const { return this->PickX2; }
417  double GetPickY2() const { return this->PickY2; }
418  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
420 
424  virtual double GetPickedZ() { return this->PickedZ; }
425 
427 
431  vtkSetVector3Macro(EnvironmentalBG, double);
432  vtkGetVector3Macro(EnvironmentalBG, double);
434 
436 
440  vtkSetVector3Macro(EnvironmentalBG2, double);
441  vtkGetVector3Macro(EnvironmentalBG2, double);
444 
450  vtkSetMacro(GradientEnvironmentalBG, bool);
451  vtkGetMacro(GradientEnvironmentalBG, bool);
452  vtkBooleanMacro(GradientEnvironmentalBG, bool);
454 
455 protected:
456  // Create a vtkViewport with a black background, a white ambient light,
457  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
458  // culling turned off.
459  vtkViewport();
460  ~vtkViewport() override;
461 
462  // Ivars for picking
463  // Store a picked Prop (contained in an assembly path)
467  double PickX1;
468  double PickY1;
469  double PickX2;
470  double PickY2;
471  double PickedZ;
472  // End Ivars for picking
473 
477  double Background[3];
478  double Background2[3];
480  double Viewport[4];
481  double Aspect[2];
482  double PixelAspect[2];
483  double Center[2];
486  GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
487 
488  double EnvironmentalBG[3];
489  double EnvironmentalBG2[3];
491 
492  int Size[2];
493  int Origin[2];
494  double DisplayPoint[3];
495  double ViewPoint[3];
496  double WorldPoint[4];
497 
498 private:
499  std::array<int, 2> LastComputeAspectSize;
500  std::array<double, 4> LastComputeAspectVPort;
501  std::array<double, 2> LastComputeAspectPixelAspect;
502 
503  vtkViewport(const vtkViewport&) = delete;
504  void operator=(const vtkViewport&) = delete;
505 };
506 
507 VTK_ABI_NAMESPACE_END
508 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:45
double PickedZ
Definition: vtkViewport.h:471
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:280
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
Definition: vtkViewport.h:424
virtual void WorldToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:307
a list of 2D actors
abstract base class for most VTK objects
Definition: vtkObject.h:51
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:466
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:44
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:412
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:309
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:49
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:60
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:464
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:411
vtkPropCollection * Props
Definition: vtkViewport.h:474
double PickY2
Definition: vtkViewport.h:470
bool GradientEnvironmentalBG
Definition: vtkViewport.h:490
an ordered list of Props
int vtkTypeBool
Definition: vtkABI.h:64
window superclass for vtkRenderWindow
Definition: vtkWindow.h:27
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:416
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:271
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:308
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:415
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:300
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:413
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:299
#define VTK_SIZEHINT(...)
bool DitherGradient
Definition: vtkViewport.h:485
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:465
double PickX2
Definition: vtkViewport.h:469
double PickX1
Definition: vtkViewport.h:467
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:414
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:306
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:417
vtkWindow * VTKWindow
Definition: vtkViewport.h:476
bool GradientBackground
Definition: vtkViewport.h:484
double PickY1
Definition: vtkViewport.h:468
double BackgroundAlpha
Definition: vtkViewport.h:479
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:475