VTK  9.5.2
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
25
26#ifndef vtkViewport_h
27#define vtkViewport_h
28
29#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_5_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
39VTK_ABI_NAMESPACE_BEGIN
41class vtkAssemblyPath;
42class vtkProp;
44class vtkWindow;
45
46class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkViewport : public vtkObject
47{
48public:
49 vtkTypeMacro(vtkViewport, vtkObject);
50 void PrintSelf(ostream& os, vtkIndent indent) override;
51
59
64
69
76
82
84
87 VTK_DEPRECATED_IN_9_5_0("Use AddViewProp() instead.")
90
94 VTK_DEPRECATED_IN_9_5_0("Use RemoveViewProp() instead.")
97
105
107
111 vtkSetVector3Macro(Background, double);
112 vtkGetVector3Macro(Background, double);
114
116
120 vtkSetVector3Macro(Background2, double);
121 vtkGetVector3Macro(Background2, double);
123 //
124
126
130 vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
131 vtkGetMacro(BackgroundAlpha, double);
133
135
140 vtkSetMacro(GradientBackground, bool);
141 vtkGetMacro(GradientBackground, bool);
142 vtkBooleanMacro(GradientBackground, bool);
144
146
151 vtkSetMacro(DitherGradient, bool);
152 vtkGetMacro(DitherGradient, bool);
153 vtkBooleanMacro(DitherGradient, bool);
155
156 enum class GradientModes : int
157 {
158 // Background color is used at the bottom, Background2 color is used at the top.
159 VTK_GRADIENT_VERTICAL,
160 // Background color on the left, Background2 color on the right.
161 VTK_GRADIENT_HORIZONTAL,
162 // Background color in the center, Background2 color on and beyond the ellipse edge.
163 // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
164 // width and height.
165 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
166 // Background color in the center, Background2 color on and beyond the ellipse edge.
167 // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
168 // width and height.
169 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
170 };
171
173
181
183
187 vtkSetVector2Macro(Aspect, double);
188 vtkGetVectorMacro(Aspect, double, 2);
189 virtual void ComputeAspect();
191
193
198 vtkSetVector2Macro(PixelAspect, double);
199 vtkGetVectorMacro(PixelAspect, double, 2);
201
203
208 vtkSetVector4Macro(Viewport, double);
209 vtkGetVectorMacro(Viewport, double, 4);
211
213
218 vtkSetVector3Macro(DisplayPoint, double);
219 vtkGetVectorMacro(DisplayPoint, double, 3);
221
223
228 vtkSetVector3Macro(ViewPoint, double);
229 vtkGetVectorMacro(ViewPoint, double, 3);
231
233
237 vtkSetVector4Macro(WorldPoint, double);
238 vtkGetVectorMacro(WorldPoint, double, 4);
240
244 virtual double* GetCenter() VTK_SIZEHINT(2);
245
249 virtual vtkTypeBool IsInViewport(int x, int y);
250
254 virtual vtkWindow* GetVTKWindow() = 0;
255
259 virtual void DisplayToView(); // these get modified in subclasses
260
264 virtual void ViewToDisplay(); // to handle stereo rendering
265
269 virtual void WorldToView();
270
274 virtual void ViewToWorld();
275
280 {
281 this->DisplayToView();
282 this->ViewToWorld();
283 }
284
289 {
290 this->WorldToView();
291 this->ViewToDisplay();
292 }
293
297 void WorldToDisplay(double& x, double& y, double& z)
298 {
299 this->WorldToView(x, y, z);
300 this->ViewToDisplay(x, y, z);
301 }
302
304
311 virtual void LocalDisplayToDisplay(double& x, double& y);
312 virtual void DisplayToNormalizedDisplay(double& u, double& v);
313 virtual void NormalizedDisplayToViewport(double& x, double& y);
314 virtual void ViewportToNormalizedViewport(double& u, double& v);
315 virtual void NormalizedViewportToView(double& x, double& y, double& z);
316 virtual void ViewToPose(double&, double&, double&) {}
317 virtual void PoseToWorld(double&, double&, double&) {}
318 virtual void DisplayToLocalDisplay(double& x, double& y);
319 virtual void NormalizedDisplayToDisplay(double& u, double& v);
320 virtual void ViewportToNormalizedDisplay(double& x, double& y);
321 virtual void NormalizedViewportToViewport(double& u, double& v);
322 virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
323 virtual void PoseToView(double&, double&, double&) {}
324 virtual void WorldToPose(double&, double&, double&) {}
325 virtual void ViewToWorld(double&, double&, double&) {}
326 virtual void WorldToView(double&, double&, double&) {}
327 virtual void ViewToDisplay(double& x, double& y, double& z);
329
331
336 virtual int* GetSize() VTK_SIZEHINT(2);
337 virtual int* GetOrigin() VTK_SIZEHINT(2);
338 void GetTiledSize(int* width, int* height);
339 virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
341
342 // The following methods describe the public pick interface for picking
343 // Props in a viewport without/with setting fieldAssociation and selection.
344
351 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
352
361 double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
362
368 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
369
375 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
376 double selectionY2, vtkPropCollection*);
377
386 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
387 vtkSmartPointer<vtkSelection> selection) = 0;
388
398 virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
399 double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
400
408 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
409 int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
410
418 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
419 double selectionY2, vtkPropCollection*, int fieldAssociation,
420 vtkSmartPointer<vtkSelection> selection);
421
423
427 double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
428 double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
429 double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
430 double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
431 double GetPickX1() const { return this->PickX1; }
432 double GetPickY1() const { return this->PickY1; }
433 double GetPickX2() const { return this->PickX2; }
434 double GetPickY2() const { return this->PickY2; }
438
442 virtual double GetPickedZ() { return this->PickedZ; }
443
445
449 vtkSetVector3Macro(EnvironmentalBG, double);
450 vtkGetVector3Macro(EnvironmentalBG, double);
452
454
458 vtkSetVector3Macro(EnvironmentalBG2, double);
459 vtkGetVector3Macro(EnvironmentalBG2, double);
462
468 vtkSetMacro(GradientEnvironmentalBG, bool);
469 vtkGetMacro(GradientEnvironmentalBG, bool);
470 vtkBooleanMacro(GradientEnvironmentalBG, bool);
472
473protected:
474 // Create a vtkViewport with a black background, a white ambient light,
475 // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
476 // culling turned off.
478 ~vtkViewport() override;
479
480 // Ivars for picking
481 // Store a picked Prop (contained in an assembly path)
485 double PickX1;
486 double PickY1;
487 double PickX2;
488 double PickY2;
489 double PickedZ;
490 // End Ivars for picking
491
495 double Background[3];
496 double Background2[3];
498 double Viewport[4];
499 double Aspect[2];
500 double PixelAspect[2];
501 double Center[2];
505
509
510 int Size[2];
511 int Origin[2];
512 double DisplayPoint[3];
513 double ViewPoint[3];
514 double WorldPoint[4];
515
516private:
517 std::array<int, 2> LastComputeAspectSize;
518 std::array<double, 4> LastComputeAspectVPort;
519 std::array<double, 2> LastComputeAspectPixelAspect;
520
521 vtkViewport(const vtkViewport&) = delete;
522 void operator=(const vtkViewport&) = delete;
523};
524
525VTK_ABI_NAMESPACE_END
526#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
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:44
data object that represents a "selection" in VTK.
Hold a reference to a vtkObjectBase instance.
virtual vtkWindow * GetVTKWindow()=0
Return the vtkWindow that owns this vtkViewport.
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
double GetPickX() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
double WorldPoint[4]
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.
double Aspect[2]
virtual void WorldToView()
Convert world point coordinates to view coordinates.
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:63
double PickX2
vtkGetEnumMacro(GradientMode, GradientModes)
Specify the direction of the gradient background.
virtual void DisplayToView()
Convert display coordinates to view coordinates.
double EnvironmentalBG2[3]
bool GradientBackground
double DisplayPoint[3]
double Background2[3]
virtual void ViewToPose(double &, double &, double &)
These methods map from one coordinate system to another.
double Background[3]
double GetPickX2() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
void DisplayToWorld()
Convert display (or screen) coordinates to world coordinates.
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)
Remove the given prop from the renderer.
virtual void PoseToWorld(double &, double &, double &)
These methods map from one coordinate system to another.
double ViewPoint[3]
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.
virtual vtkTypeBool IsInViewport(int x, int y)
Is a given display point in this Viewport's viewport.
double EnvironmentalBG[3]
virtual int * GetOrigin()
Get the size and origin of the viewport in display coordinates.
void AddActor2D(vtkProp *p)
Add the given prop to the renderer.
double Viewport[4]
vtkAssemblyPath * PickPropFrom(double selectionX, double selectionY, vtkPropCollection *)
Same as PickProp with two arguments, but selects from the given collection of Props instead of the Re...
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()
Loops through the props and returns a collection of those that are vtkActor2D (or one of its subclass...
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.
GradientModes GradientMode
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.
virtual void GetTiledSizeAndOrigin(int *width, int *height, int *lowerLeftX, int *lowerLeftY)
Get the size and origin of the viewport in display coordinates.
double GetPickWidth() const
Methods used to return the pick (x,y) in local display coordinates (i.e., it's that same as selection...
int Origin[2]
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...
double PixelAspect[2]
virtual void DisplayToNormalizedDisplay(double &u, double &v)
These methods map from one coordinate system to another.
virtual vtkAssemblyPath * PickProp(double selectionX, double selectionY)=0
Return the Prop that has the highest z value at the given x, y position in the viewport.
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 ViewToWorld()
Convert view point coordinates to world coordinates.
bool DitherGradient
void GetTiledSize(int *width, int *height)
Get the size and origin of the viewport in display coordinates.
virtual void PoseToView(double &, double &, double &)
These methods map from one coordinate system to another.
double PickY2
double Center[2]
virtual void ViewToDisplay()
Convert view coordinates to display coordinates.
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:26
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_DEPRECATED_IN_9_5_0(reason)
#define VTK_SIZEHINT(...)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)