VTK  9.3.0
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
37VTK_ABI_NAMESPACE_BEGIN
39class vtkAssemblyPath;
40class vtkProp;
42class vtkWindow;
43
44class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
45{
46public:
47 vtkTypeMacro(vtkViewport, vtkObject);
48 void PrintSelf(ostream& os, vtkIndent indent) override;
49
56
60 vtkPropCollection* GetViewProps() { return this->Props; }
61
66
72
77
79
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
128 enum class GradientModes : int
129 {
130 // Background color is used at the bottom, Background2 color is used at the top.
131 VTK_GRADIENT_VERTICAL,
132 // Background color on the left, Background2 color on the right.
133 VTK_GRADIENT_HORIZONTAL,
134 // Background color in the center, Background2 color on and beyond the ellipse edge.
135 // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
136 // width and height.
137 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
138 // Background color in the center, Background2 color on and beyond the ellipse edge.
139 // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
140 // width and height.
141 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
142 };
143
145
153
155
159 vtkSetVector2Macro(Aspect, double);
160 vtkGetVectorMacro(Aspect, double, 2);
161 virtual void ComputeAspect();
163
165
170 vtkSetVector2Macro(PixelAspect, double);
171 vtkGetVectorMacro(PixelAspect, double, 2);
173
175
180 vtkSetVector4Macro(Viewport, double);
181 vtkGetVectorMacro(Viewport, double, 4);
183
185
190 vtkSetVector3Macro(DisplayPoint, double);
191 vtkGetVectorMacro(DisplayPoint, double, 3);
193
195
200 vtkSetVector3Macro(ViewPoint, double);
201 vtkGetVectorMacro(ViewPoint, double, 3);
203
205
209 vtkSetVector4Macro(WorldPoint, double);
210 vtkGetVectorMacro(WorldPoint, double, 4);
212
216 virtual double* GetCenter() VTK_SIZEHINT(2);
217
221 virtual vtkTypeBool IsInViewport(int x, int y);
222
226 virtual vtkWindow* GetVTKWindow() = 0;
227
231 virtual void DisplayToView(); // these get modified in subclasses
232
236 virtual void ViewToDisplay(); // to handle stereo rendering
237
241 virtual void WorldToView();
242
246 virtual void ViewToWorld();
247
251 void DisplayToWorld()
252 {
253 this->DisplayToView();
254 this->ViewToWorld();
255 }
256
261 {
262 this->WorldToView();
263 this->ViewToDisplay();
264 }
265
269 inline void WorldToDisplay(double& x, double& y, double& z)
270 {
271 this->WorldToView(x, y, z);
272 this->ViewToDisplay(x, y, z);
273 }
274
276
283 virtual void LocalDisplayToDisplay(double& x, double& y);
284 virtual void DisplayToNormalizedDisplay(double& u, double& v);
285 virtual void NormalizedDisplayToViewport(double& x, double& y);
286 virtual void ViewportToNormalizedViewport(double& u, double& v);
287 virtual void NormalizedViewportToView(double& x, double& y, double& z);
288 virtual void ViewToPose(double&, double&, double&) {}
289 virtual void PoseToWorld(double&, double&, double&) {}
290 virtual void DisplayToLocalDisplay(double& x, double& y);
291 virtual void NormalizedDisplayToDisplay(double& u, double& v);
292 virtual void ViewportToNormalizedDisplay(double& x, double& y);
293 virtual void NormalizedViewportToViewport(double& u, double& v);
294 virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
295 virtual void PoseToView(double&, double&, double&) {}
296 virtual void WorldToPose(double&, double&, double&) {}
297 virtual void ViewToWorld(double&, double&, double&) {}
298 virtual void WorldToView(double&, double&, double&) {}
299 virtual void ViewToDisplay(double& x, double& y, double& z);
301
303
308 virtual int* GetSize() VTK_SIZEHINT(2);
309 virtual int* GetOrigin() VTK_SIZEHINT(2);
310 void GetTiledSize(int* width, int* height);
311 virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
313
314 // The following methods describe the public pick interface for picking
315 // Props in a viewport without/with setting fieldAssociation and selection.
316
323 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
324
332 virtual vtkAssemblyPath* PickProp(
333 double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
334
340 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
341
347 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
348 double selectionY2, vtkPropCollection*);
349
358 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
359 vtkSmartPointer<vtkSelection> selection) = 0;
360
370 virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
371 double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
372
380 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
381 int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
382
390 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
391 double selectionY2, vtkPropCollection*, int fieldAssociation,
392 vtkSmartPointer<vtkSelection> selection);
393
395
399 double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
400 double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
401 double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
402 double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
403 double GetPickX1() const { return this->PickX1; }
404 double GetPickY1() const { return this->PickY1; }
405 double GetPickX2() const { return this->PickX2; }
406 double GetPickY2() const { return this->PickY2; }
407 vtkGetObjectMacro(PickResultProps, vtkPropCollection);
409
413 virtual double GetPickedZ() { return this->PickedZ; }
414
416
420 vtkSetVector3Macro(EnvironmentalBG, double);
421 vtkGetVector3Macro(EnvironmentalBG, double);
423
425
429 vtkSetVector3Macro(EnvironmentalBG2, double);
430 vtkGetVector3Macro(EnvironmentalBG2, double);
433
439 vtkSetMacro(GradientEnvironmentalBG, bool);
440 vtkGetMacro(GradientEnvironmentalBG, bool);
441 vtkBooleanMacro(GradientEnvironmentalBG, bool);
443
444protected:
445 // Create a vtkViewport with a black background, a white ambient light,
446 // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
447 // culling turned off.
449 ~vtkViewport() override;
450
451 // Ivars for picking
452 // Store a picked Prop (contained in an assembly path)
456 double PickX1;
457 double PickY1;
458 double PickX2;
459 double PickY2;
460 double PickedZ;
461 // End Ivars for picking
462
466 double Background[3];
467 double Background2[3];
469 double Viewport[4];
470 double Aspect[2];
471 double PixelAspect[2];
472 double Center[2];
474 GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
475
476 double EnvironmentalBG[3];
477 double EnvironmentalBG2[3];
479
480 int Size[2];
481 int Origin[2];
482 double DisplayPoint[3];
483 double ViewPoint[3];
484 double WorldPoint[4];
485
486private:
487 std::array<int, 2> LastComputeAspectSize;
488 std::array<double, 4> LastComputeAspectVPort;
489 std::array<double, 2> LastComputeAspectPixelAspect;
490
491 vtkViewport(const vtkViewport&) = delete;
492 void operator=(const vtkViewport&) = delete;
493};
494
495VTK_ABI_NAMESPACE_END
496#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:29
abstract base class for most VTK objects
Definition vtkObject.h:49
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:43
data object that represents a "selection" in VTK.
Hold a reference to a vtkObjectBase instance.
abstract specification for Viewports
Definition vtkViewport.h:45
double GetPickY2() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
virtual void ViewToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
double GetPickX1() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
vtkPropCollection * Props
void WorldToDisplay(double &x, double &y, double &z)
Convert world point coordinates to display (or screen) coordinates.
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.
void WorldToDisplay()
Convert world point coordinates to display (or screen) coordinates.
~vtkViewport() override
vtkAssemblyPath * PickedProp
virtual void ViewToNormalizedViewport(double &x, double &y, double &z)
These methods map from one coordinate system to another.
virtual double * GetCenter()
Return the center of this viewport in display coordinates.
vtkPropCollection * GetViewProps()
Return any props in this viewport.
Definition vtkViewport.h:60
double PickX2
vtkGetEnumMacro(GradientMode, GradientModes)
Specify the direction of the gradient background.
bool GradientBackground
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
double GetPickX2() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
vtkActor2DCollection * Actors2D
double GetPickHeight() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
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.
vtkWindow * VTKWindow
virtual void ComputeAspect()
Set the aspect ratio of the rendered image.
vtkPropCollection * PickResultProps
virtual int * GetSize()
Get the size and origin of the viewport in display coordinates.
double BackgroundAlpha
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
vtkSetEnumMacro(GradientMode, GradientModes)
Specify the direction of the gradient background.
vtkActor2DCollection * GetActors2D()
Add/Remove different types of props to the renderer.
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
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
virtual double GetPickedZ()
Return the Z value for the last picked Prop.
double GetPickWidth() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
double PickY1
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...
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.
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
double PickY2
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...
virtual void WorldToView(double &, double &, double &)
These methods map from one coordinate system to another.
double PickedZ
window superclass for vtkRenderWindow
Definition vtkWindow.h:25
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SIZEHINT(...)