VTK  9.4.20241121
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
45#ifndef vtkViewport_h
46#define vtkViewport_h
47
48#include "vtkObject.h"
49#include "vtkRenderingCoreModule.h" // For export macro
50#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
51
52#include "vtkSelection.h" // Needed for selection
53#include "vtkSmartPointer.h" // Needed for assigning default nullptr value
54
55#include <array> // To store matrices
56
57VTK_ABI_NAMESPACE_BEGIN
59class vtkAssemblyPath;
60class vtkProp;
62class vtkWindow;
63
64class VTKRENDERINGCORE_EXPORT VTK_MARSHALAUTO vtkViewport : public vtkObject
65{
66public:
67 vtkTypeMacro(vtkViewport, vtkObject);
68 void PrintSelf(ostream& os, vtkIndent indent) override;
69
76 void AddViewProp(vtkProp*);
77
81 vtkPropCollection* GetViewProps() { return this->Props; }
82
87
93 void RemoveViewProp(vtkProp*);
94
99 void RemoveAllViewProps();
100
102
108 void AddActor2D(vtkProp* p);
110 void RemoveActor2D(vtkProp* p);
112 vtkActor2DCollection* GetActors2D();
114
116
120 vtkSetVector3Macro(Background, double);
121 vtkGetVector3Macro(Background, double);
123
125
129 vtkSetVector3Macro(Background2, double);
130 vtkGetVector3Macro(Background2, double);
132 //
133
135
139 vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0);
140 vtkGetMacro(BackgroundAlpha, double);
142
144
149 vtkSetMacro(GradientBackground, bool);
150 vtkGetMacro(GradientBackground, bool);
151 vtkBooleanMacro(GradientBackground, bool);
153
155
160 vtkSetMacro(DitherGradient, bool);
161 vtkGetMacro(DitherGradient, bool);
162 vtkBooleanMacro(DitherGradient, bool);
164
165 enum class GradientModes : int
166 {
167 // Background color is used at the bottom, Background2 color is used at the top.
168 VTK_GRADIENT_VERTICAL,
169 // Background color on the left, Background2 color on the right.
170 VTK_GRADIENT_HORIZONTAL,
171 // Background color in the center, Background2 color on and beyond the ellipse edge.
172 // Ellipse touches all sides of the viewport. The ellipse is a circle for viewports with equal
173 // width and height.
174 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_SIDE,
175 // Background color in the center, Background2 color on and beyond the ellipse edge.
176 // Ellipse touches all corners of the viewport. The ellipse is a circle for viewports with equal
177 // width and height.
178 VTK_GRADIENT_RADIAL_VIEWPORT_FARTHEST_CORNER,
179 };
180
182
190
192
196 vtkSetVector2Macro(Aspect, double);
197 vtkGetVectorMacro(Aspect, double, 2);
198 virtual void ComputeAspect();
200
202
207 vtkSetVector2Macro(PixelAspect, double);
208 vtkGetVectorMacro(PixelAspect, double, 2);
210
212
217 vtkSetVector4Macro(Viewport, double);
218 vtkGetVectorMacro(Viewport, double, 4);
220
222
227 vtkSetVector3Macro(DisplayPoint, double);
228 vtkGetVectorMacro(DisplayPoint, double, 3);
230
232
237 vtkSetVector3Macro(ViewPoint, double);
238 vtkGetVectorMacro(ViewPoint, double, 3);
240
242
246 vtkSetVector4Macro(WorldPoint, double);
247 vtkGetVectorMacro(WorldPoint, double, 4);
249
253 virtual double* GetCenter() VTK_SIZEHINT(2);
254
258 virtual vtkTypeBool IsInViewport(int x, int y);
259
263 virtual vtkWindow* GetVTKWindow() = 0;
264
268 virtual void DisplayToView(); // these get modified in subclasses
269
273 virtual void ViewToDisplay(); // to handle stereo rendering
274
278 virtual void WorldToView();
279
283 virtual void ViewToWorld();
284
288 void DisplayToWorld()
289 {
290 this->DisplayToView();
291 this->ViewToWorld();
292 }
293
298 {
299 this->WorldToView();
300 this->ViewToDisplay();
301 }
302
306 inline void WorldToDisplay(double& x, double& y, double& z)
307 {
308 this->WorldToView(x, y, z);
309 this->ViewToDisplay(x, y, z);
310 }
311
313
320 virtual void LocalDisplayToDisplay(double& x, double& y);
321 virtual void DisplayToNormalizedDisplay(double& u, double& v);
322 virtual void NormalizedDisplayToViewport(double& x, double& y);
323 virtual void ViewportToNormalizedViewport(double& u, double& v);
324 virtual void NormalizedViewportToView(double& x, double& y, double& z);
325 virtual void ViewToPose(double&, double&, double&) {}
326 virtual void PoseToWorld(double&, double&, double&) {}
327 virtual void DisplayToLocalDisplay(double& x, double& y);
328 virtual void NormalizedDisplayToDisplay(double& u, double& v);
329 virtual void ViewportToNormalizedDisplay(double& x, double& y);
330 virtual void NormalizedViewportToViewport(double& u, double& v);
331 virtual void ViewToNormalizedViewport(double& x, double& y, double& z);
332 virtual void PoseToView(double&, double&, double&) {}
333 virtual void WorldToPose(double&, double&, double&) {}
334 virtual void ViewToWorld(double&, double&, double&) {}
335 virtual void WorldToView(double&, double&, double&) {}
336 virtual void ViewToDisplay(double& x, double& y, double& z);
338
340
345 virtual int* GetSize() VTK_SIZEHINT(2);
346 virtual int* GetOrigin() VTK_SIZEHINT(2);
347 void GetTiledSize(int* width, int* height);
348 virtual void GetTiledSizeAndOrigin(int* width, int* height, int* lowerLeftX, int* lowerLeftY);
350
351 // The following methods describe the public pick interface for picking
352 // Props in a viewport without/with setting fieldAssociation and selection.
353
360 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0;
361
369 virtual vtkAssemblyPath* PickProp(
370 double selectionX1, double selectionY1, double selectionX2, double selectionY2) = 0;
371
377 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*);
378
384 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
385 double selectionY2, vtkPropCollection*);
386
395 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY, int fieldAssociation,
396 vtkSmartPointer<vtkSelection> selection) = 0;
397
407 virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, double selectionX2,
408 double selectionY2, int fieldAssociation, vtkSmartPointer<vtkSelection> selection) = 0;
409
417 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, vtkPropCollection*,
418 int fieldAssociation, vtkSmartPointer<vtkSelection> selection);
419
427 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, double selectionX2,
428 double selectionY2, vtkPropCollection*, int fieldAssociation,
429 vtkSmartPointer<vtkSelection> selection);
430
432
436 double GetPickX() const { return (this->PickX1 + this->PickX2) * 0.5; }
437 double GetPickY() const { return (this->PickY1 + this->PickY2) * 0.5; }
438 double GetPickWidth() const { return this->PickX2 - this->PickX1 + 1; }
439 double GetPickHeight() const { return this->PickY2 - this->PickY1 + 1; }
440 double GetPickX1() const { return this->PickX1; }
441 double GetPickY1() const { return this->PickY1; }
442 double GetPickX2() const { return this->PickX2; }
443 double GetPickY2() const { return this->PickY2; }
445 vtkGetObjectMacro(PickResultProps, vtkPropCollection);
447
451 virtual double GetPickedZ() { return this->PickedZ; }
452
454
458 vtkSetVector3Macro(EnvironmentalBG, double);
459 vtkGetVector3Macro(EnvironmentalBG, double);
461
463
467 vtkSetVector3Macro(EnvironmentalBG2, double);
468 vtkGetVector3Macro(EnvironmentalBG2, double);
471
477 vtkSetMacro(GradientEnvironmentalBG, bool);
478 vtkGetMacro(GradientEnvironmentalBG, bool);
479 vtkBooleanMacro(GradientEnvironmentalBG, bool);
481
482protected:
483 // Create a vtkViewport with a black background, a white ambient light,
484 // two-sided lighting turned on, a viewport of (0,0,1,1), and back face
485 // culling turned off.
487 ~vtkViewport() override;
488
489 // Ivars for picking
490 // Store a picked Prop (contained in an assembly path)
494 double PickX1;
495 double PickY1;
496 double PickX2;
497 double PickY2;
498 double PickedZ;
499 // End Ivars for picking
500
504 double Background[3];
505 double Background2[3];
507 double Viewport[4];
508 double Aspect[2];
509 double PixelAspect[2];
510 double Center[2];
513 GradientModes GradientMode = GradientModes::VTK_GRADIENT_VERTICAL;
514
515 double EnvironmentalBG[3];
516 double EnvironmentalBG2[3];
518
519 int Size[2];
520 int Origin[2];
521 double DisplayPoint[3];
522 double ViewPoint[3];
523 double WorldPoint[4];
524
525private:
526 std::array<int, 2> LastComputeAspectSize;
527 std::array<double, 4> LastComputeAspectVPort;
528 std::array<double, 2> LastComputeAspectPixelAspect;
529
530 vtkViewport(const vtkViewport&) = delete;
531 void operator=(const vtkViewport&) = delete;
532};
533
534VTK_ABI_NAMESPACE_END
535#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:108
abstract base class for most VTK objects
Definition vtkObject.h:162
an ordered list of Props
abstract superclass for all actors, volumes and annotations
Definition vtkProp.h:66
data object that represents a "selection" in VTK.
Hold a reference to a vtkObjectBase instance.
abstract specification for Viewports
Definition vtkViewport.h:65
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.
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.
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.
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.
virtual void LocalDisplayToDisplay(double &x, double &y)
These methods map from one coordinate system to another.
vtkPropCollection * PickFromProps
virtual void NormalizedDisplayToDisplay(double &u, double &v)
These methods map from one coordinate system to another.
bool GradientEnvironmentalBG
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
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.
bool DitherGradient
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:48
int vtkTypeBool
Definition vtkABI.h:64
#define VTK_SIZEHINT(...)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)