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
35#ifndef vtkViewport_h
36#define vtkViewport_h
37
38#include "vtkObject.h"
39#include "vtkRenderingCoreModule.h" // For export macro
40
41#include "vtkSelection.h" // Needed for selection
42#include "vtkSmartPointer.h" // Needed for assigning default nullptr value
43
44#include <array> // To store matrices
45
46VTK_ABI_NAMESPACE_BEGIN
48class vtkAssemblyPath;
49class vtkProp;
51class vtkWindow;
52
53class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject
54{
55public:
56 vtkTypeMacro(vtkViewport, vtkObject);
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
65
69 vtkPropCollection* GetViewProps() { return this->Props; }
70
75
81
86
88
97
99
103 vtkSetVector3Macro(Background, double);
104 vtkGetVector3Macro(Background, double);
106
108
112 vtkSetVector3Macro(Background2, double);
113 vtkGetVector3Macro(Background2, double);
115 //
116
118
122 vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
123 vtkGetMacro(BackgroundAlpha, double);
125
127
132 vtkSetMacro(GradientBackground, bool);
133 vtkGetMacro(GradientBackground, bool);
134 vtkBooleanMacro(GradientBackground, bool);
136
137 enum class GradientModes : int
138 {
139 // Background color is used at the bottom, Background2 color is used at the top.
140 VTK_GRADIENT_VERTICAL,
141 // Background color on the left, Background2 color on the right.
142 VTK_GRADIENT_HORIZONTAL,
143 // Background color in the center, Background2 color on and beyond the ellipse edge.
144 // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
145 // width and height.
146 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
147 // Background color in the center, Background2 color on and beyond the ellipse edge.
148 // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
149 // width and height.
150 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
151 };
152
154
162
164
168 vtkSetVector2Macro(Aspect, double);
169 vtkGetVectorMacro(Aspect, double, 2);
170 virtual void ComputeAspect();
172
174
179 vtkSetVector2Macro(PixelAspect, double);
180 vtkGetVectorMacro(PixelAspect, double, 2);
182
184
189 vtkSetVector4Macro(Viewport, double);
190 vtkGetVectorMacro(Viewport, double, 4);
192
194
199 vtkSetVector3Macro(DisplayPoint, double);
200 vtkGetVectorMacro(DisplayPoint, double, 3);
202
204
209 vtkSetVector3Macro(ViewPoint, double);
210 vtkGetVectorMacro(ViewPoint, double, 3);
212
214
218 vtkSetVector4Macro(WorldPoint, double);
219 vtkGetVectorMacro(WorldPoint, double, 4);
221
225 virtual double* GetCenter() VTK_SIZEHINT(2);
226
230 virtual vtkTypeBool IsInViewport(int x, int y);
231
235 virtual vtkWindow* GetVTKWindow() = 0;
236
240 virtual void DisplayToView(); // these get modified in subclasses
241
245 virtual void ViewToDisplay(); // to handle stereo rendering
246
250 virtual void WorldToView();
251
255 virtual void ViewToWorld();
256
260 void DisplayToWorld()
261 {
262 this->DisplayToView();
263 this->ViewToWorld();
264 }
265
270 {
271 this->WorldToView();
272 this->ViewToDisplay();
273 }
274
278 inline void WorldToDisplay(double& x, double& y, double& z)
279 {
280 this->WorldToView(x, y, z);
281 this->ViewToDisplay(x, y, z);
282 }
283
285
292 virtual void LocalDisplayToDisplay(double& x, double& y);
293 virtual void DisplayToNormalizedDisplay(double& u, double& v);
294 virtual void NormalizedDisplayToViewport(double& x, double& y);
295 virtual void ViewportToNormalizedViewport(double& u, double& v);
296 virtual void NormalizedViewportToView(double& x, double& y, double& z);
297 virtual void ViewToPose(double&, double&, double&) {}
298 virtual void PoseToWorld(double&, double&, double&) {}
299 virtual void DisplayToLocalDisplay(double& x, double& y);
300 virtual void NormalizedDisplayToDisplay(double& u, double& v);
301 virtual void ViewportToNormalizedDisplay(double& x, double& y);
302 virtual void NormalizedViewportToViewport(double& u, double& v);
303 virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
304 virtual void PoseToView(double&, double&, double&) {}
305 virtual void WorldToPose(double&, double&, double&) {}
306 virtual void ViewToWorld(double&, double&, double&) {}
307 virtual void WorldToView(double&, double&, double&) {}
308 virtual void ViewToDisplay(double& x, double& y, double& z);
310
312
317 virtual int* GetSize() VTK_SIZEHINT(2);
318 virtual int* GetOrigin() VTK_SIZEHINT(2);
319 void GetTiledSize(int* width, int* height);
320 virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
322
323 // The following methods describe the public pick interface for picking
324 // Props in a viewport without/with setting fieldAssociation and selection.
325
332 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
333
341 virtual vtkAssemblyPath* PickProp(
342 double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
343
349 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
350
356 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
357 double selectionY2, vtkPropCollection*);
358
367 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
368 vtkSmartPointer<vtkSelection> selection) = 0;
369
379 virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
380 double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
381
389 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
390 int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
391
399 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
400 double selectionY2, vtkPropCollection*, int fieldAssociation,
401 vtkSmartPointer<vtkSelection> selection);
402
404
408 double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
409 double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
410 double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
411 double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
412 double GetPickX1() const { return this->PickX1; }
413 double GetPickY1() const { return this->PickY1; }
414 double GetPickX2() const { return this->PickX2; }
415 double GetPickY2() const { return this->PickY2; }
416 vtkGetObjectMacro(PickResultProps, vtkPropCollection);
418
422 virtual double GetPickedZ() { return this->PickedZ; }
423
425
429 vtkSetVector3Macro(EnvironmentalBG, double);
430 vtkGetVector3Macro(EnvironmentalBG, double);
432
434
438 vtkSetVector3Macro(EnvironmentalBG2, double);
439 vtkGetVector3Macro(EnvironmentalBG2, double);
442
448 vtkSetMacro(GradientEnvironmentalBG, bool);
449 vtkGetMacro(GradientEnvironmentalBG, bool);
450 vtkBooleanMacro(GradientEnvironmentalBG, bool);
452
453protected:
454 // Create a vtkViewport with a black background, a white ambient light,
455 // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
456 // culling turned off.
458 ~vtkViewport() override;
459
460 // Ivars for picking
461 // Store a picked Prop (contained in an assembly path)
465 double PickX1;
466 double PickY1;
467 double PickX2;
468 double PickY2;
469 double PickedZ;
470 // End Ivars for picking
471
475 double Background[3];
476 double Background2[3];
478 double Viewport[4];
479 double Aspect[2];
480 double PixelAspect[2];
481 double Center[2];
483 GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
484
485 double EnvironmentalBG[3];
486 double EnvironmentalBG2[3];
488
489 int Size[2];
490 int Origin[2];
491 double DisplayPoint[3];
492 double ViewPoint[3];
493 double WorldPoint[4];
494
495private:
496 std::array<int, 2> LastComputeAspectSize;
497 std::array<double, 4> LastComputeAspectVPort;
498 std::array<double, 2> LastComputeAspectPixelAspect;
499
500 vtkViewport(const vtkViewport&) = delete;
501 void operator=(const vtkViewport&) = delete;
502};
503
504VTK_ABI_NAMESPACE_END
505#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:38
abstract base class for most VTK objects
Definition vtkObject.h:58
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:52
data object that represents a "selection" in VTK.
Hold a reference to a vtkObjectBase instance.
abstract specification for Viewports
Definition vtkViewport.h:54
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:69
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:34
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SIZEHINT(...)