VTK  9.2.6
vtkViewport.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkViewport.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
38 #ifndef vtkViewport_h
39 #define vtkViewport_h
40 
41 #include "vtkObject.h"
42 #include "vtkRenderingCoreModule.h" // For export macro
43 
44 #include "vtkSelection.h" // Needed for selection
45 #include "vtkSmartPointer.h" // Needed for assigning default nullptr value
46 
47 #include <array> // To store matrices
48 
50 class vtkAssemblyPath;
51 class vtkProp;
52 class vtkPropCollection;
53 class vtkWindow;
54 
55 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
56 {
57 public:
58  vtkTypeMacro(vtkViewport, vtkObject);
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
66  void AddViewProp(vtkProp*);
67 
71  vtkPropCollection* GetViewProps() { return this->Props; }
72 
76  int HasViewProp(vtkProp*);
77 
82  void RemoveViewProp(vtkProp*);
83 
87  void RemoveAllViewProps(void);
88 
90 
95  void AddActor2D(vtkProp* p);
96  void RemoveActor2D(vtkProp* p);
97  vtkActor2DCollection* GetActors2D();
99 
101 
105  vtkSetVector3Macro(Background, double);
106  vtkGetVector3Macro(Background, double);
108 
110 
114  vtkSetVector3Macro(Background2, double);
115  vtkGetVector3Macro(Background2, double);
117  //
118 
120 
124  vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
125  vtkGetMacro(BackgroundAlpha, double);
127 
129 
134  vtkSetMacro(GradientBackground, bool);
135  vtkGetMacro(GradientBackground, bool);
136  vtkBooleanMacro(GradientBackground, bool);
138 
140 
144  vtkSetVector2Macro(Aspect, double);
145  vtkGetVectorMacro(Aspect, double, 2);
146  virtual void ComputeAspect();
148 
150 
155  vtkSetVector2Macro(PixelAspect, double);
156  vtkGetVectorMacro(PixelAspect, double, 2);
158 
160 
165  vtkSetVector4Macro(Viewport, double);
166  vtkGetVectorMacro(Viewport, double, 4);
168 
170 
175  vtkSetVector3Macro(DisplayPoint, double);
176  vtkGetVectorMacro(DisplayPoint, double, 3);
178 
180 
185  vtkSetVector3Macro(ViewPoint, double);
186  vtkGetVectorMacro(ViewPoint, double, 3);
188 
190 
194  vtkSetVector4Macro(WorldPoint, double);
195  vtkGetVectorMacro(WorldPoint, double, 4);
197 
201  virtual double* GetCenter() VTK_SIZEHINT(2);
202 
206  virtual int IsInViewport(int x, int y);
207 
211  virtual vtkWindow* GetVTKWindow() = 0;
212 
216  virtual void DisplayToView(); // these get modified in subclasses
217 
221  virtual void ViewToDisplay(); // to handle stereo rendering
222 
226  virtual void WorldToView();
227 
231  virtual void ViewToWorld();
232 
236  void DisplayToWorld()
237  {
238  this->DisplayToView();
239  this->ViewToWorld();
240  }
241 
246  {
247  this->WorldToView();
248  this->ViewToDisplay();
249  }
250 
254  inline void WorldToDisplay(double& x, double& y, double& z)
255  {
256  this->WorldToView(x, y, z);
257  this->ViewToDisplay(x, y, z);
258  }
259 
261 
268  virtual void LocalDisplayToDisplay(double& x, double& y);
269  virtual void DisplayToNormalizedDisplay(double& u, double& v);
270  virtual void NormalizedDisplayToViewport(double& x, double& y);
271  virtual void ViewportToNormalizedViewport(double& u, double& v);
272  virtual void NormalizedViewportToView(double& x, double& y, double& z);
273  virtual void ViewToPose(double&, double&, double&) {}
274  virtual void PoseToWorld(double&, double&, double&) {}
275  virtual void DisplayToLocalDisplay(double& x, double& y);
276  virtual void NormalizedDisplayToDisplay(double& u, double& v);
277  virtual void ViewportToNormalizedDisplay(double& x, double& y);
278  virtual void NormalizedViewportToViewport(double& u, double& v);
279  virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
280  virtual void PoseToView(double&, double&, double&) {}
281  virtual void WorldToPose(double&, double&, double&) {}
282  virtual void ViewToWorld(double&, double&, double&) {}
283  virtual void WorldToView(double&, double&, double&) {}
284  virtual void ViewToDisplay(double& x, double& y, double& z);
286 
288 
293  virtual int* GetSize() VTK_SIZEHINT(2);
294  virtual int* GetOrigin() VTK_SIZEHINT(2);
295  void GetTiledSize(int* width, int* height);
296  virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
298 
299  // The following methods describe the public pick interface for picking
300  // Props in a viewport without/with setting fieldAssociation and selection.
301 
308  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
309 
317  virtual vtkAssemblyPath* PickProp(
318  double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
319 
325  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
326 
332  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
333  double selectionY2, vtkPropCollection*);
334 
343  virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
344  vtkSmartPointer<vtkSelection> selection) = 0;
345 
355  virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
356  double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
357 
365  vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
366  int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
367 
375  vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
376  double selectionY2, vtkPropCollection*, int fieldAssociation,
377  vtkSmartPointer<vtkSelection> selection);
378 
380 
384  double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
385  double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
386  double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
387  double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
388  double GetPickX1() const { return this->PickX1; }
389  double GetPickY1() const { return this->PickY1; }
390  double GetPickX2() const { return this->PickX2; }
391  double GetPickY2() const { return this->PickY2; }
392  vtkGetObjectMacro(PickResultProps, vtkPropCollection);
394 
398  virtual double GetPickedZ() { return this->PickedZ; }
399 
401 
405  vtkSetVector3Macro(EnvironmentalBG, double);
406  vtkGetVector3Macro(EnvironmentalBG, double);
408 
410 
414  vtkSetVector3Macro(EnvironmentalBG2, double);
415  vtkGetVector3Macro(EnvironmentalBG2, double);
418 
424  vtkSetMacro(GradientEnvironmentalBG, bool);
425  vtkGetMacro(GradientEnvironmentalBG, bool);
426  vtkBooleanMacro(GradientEnvironmentalBG, bool);
428 
429 protected:
430  // Create a vtkViewport with a black background, a white ambient light,
431  // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
432  // culling turned off.
433  vtkViewport();
434  ~vtkViewport() override;
435 
436  // Ivars for picking
437  // Store a picked Prop (contained in an assembly path)
441  double PickX1;
442  double PickY1;
443  double PickX2;
444  double PickY2;
445  double PickedZ;
446  // End Ivars for picking
447 
451  double Background[3];
452  double Background2[3];
454  double Viewport[4];
455  double Aspect[2];
456  double PixelAspect[2];
457  double Center[2];
459 
460  double EnvironmentalBG[3];
461  double EnvironmentalBG2[3];
463 
464  int Size[2];
465  int Origin[2];
466  double DisplayPoint[3];
467  double ViewPoint[3];
468  double WorldPoint[4];
469 
470 private:
471  std::array<int, 2> LastComputeAspectSize;
472  std::array<double, 4> LastComputeAspectVPort;
473  std::array<double, 2> LastComputeAspectPixelAspect;
474 
475  vtkViewport(const vtkViewport&) = delete;
476  void operator=(const vtkViewport&) = delete;
477 };
478 
479 #endif
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:56
double PickedZ
Definition: vtkViewport.h:445
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:254
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
Definition: vtkViewport.h:398
virtual void WorldToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:281
a list of 2D actors
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkPropCollection * PickResultProps
Definition: vtkViewport.h:440
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:55
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:386
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:283
data object that represents a "selection" in VTK.
Definition: vtkSelection.h:59
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition: vtkViewport.h:71
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:32
vtkAssemblyPath * PickedProp
Definition: vtkViewport.h:438
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:385
vtkPropCollection * Props
Definition: vtkViewport.h:448
double PickY2
Definition: vtkViewport.h:444
bool GradientEnvironmentalBG
Definition: vtkViewport.h:462
an ordered list of Props
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
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:390
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
Definition: vtkViewport.h:245
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:282
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:389
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual void PoseToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:274
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:387
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:273
#define VTK_SIZEHINT(...)
vtkPropCollection * PickFromProps
Definition: vtkViewport.h:439
double PickX2
Definition: vtkViewport.h:443
double PickX1
Definition: vtkViewport.h:441
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:388
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
Definition: vtkViewport.h:280
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:391
vtkWindow * VTKWindow
Definition: vtkViewport.h:450
bool GradientBackground
Definition: vtkViewport.h:458
double PickY1
Definition: vtkViewport.h:442
double BackgroundAlpha
Definition: vtkViewport.h:453
vtkActor2DCollection * Actors2D
Definition: vtkViewport.h:449