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 =========================================================================*/ 15 /** 16 * @class vtkViewport 17 * @brief abstract specification for Viewports 18 * 19 * vtkViewport provides an abstract specification for Viewports. A Viewport 20 * is an object that controls the rendering process for objects. Rendering 21 * is the process of converting geometry, a specification for lights, and 22 * a camera view into an image. vtkViewport also performs coordinate 23 * transformation between world coordinates, view coordinates (the computer 24 * graphics rendering coordinate system), and display coordinates (the 25 * actual screen coordinates on the display device). Certain advanced 26 * rendering features such as two-sided lighting can also be controlled. 27 * 28 * @sa 29 * vtkWindow vtkRenderer 30 */ 31 32 #ifndef vtkViewport_h 33 #define vtkViewport_h 34 35 #include "vtkRenderingCoreModule.h" // For export macro 36 #include "vtkObject.h" 37 38 class vtkActor2DCollection; 39 class vtkAssemblyPath; 40 class vtkProp; 41 class vtkPropCollection; 42 class vtkWindow; 43 44 class VTKRENDERINGCORE_EXPORT vtkViewport : public vtkObject 45 { 46 public: 47 vtkTypeMacro(vtkViewport,vtkObject); 48 void PrintSelf(ostream& os, vtkIndent indent) override; 49 50 /** 51 * Add a prop to the list of props. Does nothing if the prop is 52 * already present. Prop is the superclass of all actors, volumes, 53 * 2D actors, composite props etc. 54 */ 55 void AddViewProp(vtkProp *); 56 57 /** 58 * Return any props in this viewport. 59 */ GetViewProps()60 vtkPropCollection *GetViewProps() {return this->Props;}; 61 62 /** 63 * Query if a prop is in the list of props. 64 */ 65 int HasViewProp(vtkProp *); 66 67 /** 68 * Remove a prop from the list of props. Does nothing if the prop 69 * is not already present. 70 */ 71 void RemoveViewProp(vtkProp *); 72 73 /** 74 * Remove all props from the list of props. 75 */ 76 void RemoveAllViewProps(void); 77 78 //@{ 79 /** 80 * Add/Remove different types of props to the renderer. 81 * These methods are all synonyms to AddViewProp and RemoveViewProp. 82 * They are here for convenience and backwards compatibility. 83 */ 84 void AddActor2D(vtkProp* p); 85 void RemoveActor2D(vtkProp* p); 86 vtkActor2DCollection *GetActors2D(); 87 //@} 88 89 //@{ 90 /** 91 * Set/Get the background color of the rendering screen using an rgb color 92 * specification. 93 */ 94 vtkSetVector3Macro(Background,double); 95 vtkGetVector3Macro(Background,double); 96 //@} 97 98 //@{ 99 /** 100 * Set/Get the second background color of the rendering screen 101 * for gradient backgrounds using an rgb color specification. 102 */ 103 vtkSetVector3Macro(Background2,double); 104 vtkGetVector3Macro(Background2,double); 105 //@} 106 // 107 108 //@{ 109 /** 110 * Set/Get the alpha value used to fill the background with. 111 * By default, this is set to 0.0. 112 */ 113 vtkSetClampMacro(BackgroundAlpha, double, 0.0, 1.0); 114 vtkGetMacro(BackgroundAlpha, double); 115 //@} 116 117 //@{ 118 /** 119 * Set/Get whether this viewport should have a gradient background 120 * using the Background (bottom) and Background2 (top) colors. 121 * Default is off. 122 */ 123 vtkSetMacro(GradientBackground,bool); 124 vtkGetMacro(GradientBackground,bool); 125 vtkBooleanMacro(GradientBackground,bool); 126 //@} 127 128 //@{ 129 /** 130 * Set the aspect ratio of the rendered image. This is computed 131 * automatically and should not be set by the user. 132 */ 133 vtkSetVector2Macro(Aspect,double); 134 vtkGetVectorMacro(Aspect,double,2); 135 virtual void ComputeAspect(); 136 //@} 137 138 //@{ 139 /** 140 * Set the aspect ratio of a pixel in the rendered image. 141 * This factor permits the image to rendered anisotropically 142 * (i.e., stretched in one direction or the other). 143 */ 144 vtkSetVector2Macro(PixelAspect,double); 145 vtkGetVectorMacro(PixelAspect,double,2); 146 //@} 147 148 //@{ 149 /** 150 * Specify the viewport for the Viewport to draw in the rendering window. 151 * Coordinates are expressed as (xmin,ymin,xmax,ymax), where each 152 * coordinate is 0 <= coordinate <= 1.0. 153 */ 154 vtkSetVector4Macro(Viewport,double); 155 vtkGetVectorMacro(Viewport,double,4); 156 //@} 157 158 //@{ 159 /** 160 * Set/get a point location in display (or screen) coordinates. 161 * The lower left corner of the window is the origin and y increases 162 * as you go up the screen. 163 */ 164 vtkSetVector3Macro(DisplayPoint,double); 165 vtkGetVectorMacro(DisplayPoint,double,3); 166 //@} 167 168 //@{ 169 /** 170 * Specify a point location in view coordinates. The origin is in the 171 * middle of the viewport and it extends from -1 to 1 in all three 172 * dimensions. 173 */ 174 vtkSetVector3Macro(ViewPoint,double); 175 vtkGetVectorMacro(ViewPoint,double,3); 176 //@} 177 178 //@{ 179 /** 180 * Specify a point location in world coordinates. This method takes 181 * homogeneous coordinates. 182 */ 183 vtkSetVector4Macro(WorldPoint,double); 184 vtkGetVectorMacro(WorldPoint,double,4); 185 //@} 186 187 /** 188 * Return the center of this viewport in display coordinates. 189 */ 190 virtual double *GetCenter() VTK_SIZEHINT(2); 191 192 /** 193 * Is a given display point in this Viewport's viewport. 194 */ 195 virtual int IsInViewport(int x,int y); 196 197 /** 198 * Return the vtkWindow that owns this vtkViewport. 199 */ 200 virtual vtkWindow *GetVTKWindow() = 0; 201 202 /** 203 * Convert display coordinates to view coordinates. 204 */ 205 virtual void DisplayToView(); // these get modified in subclasses 206 207 /** 208 * Convert view coordinates to display coordinates. 209 */ 210 virtual void ViewToDisplay(); // to handle stereo rendering 211 212 /** 213 * Convert world point coordinates to view coordinates. 214 */ 215 virtual void WorldToView(); 216 217 /** 218 * Convert view point coordinates to world coordinates. 219 */ 220 virtual void ViewToWorld(); 221 222 /** 223 * Convert display (or screen) coordinates to world coordinates. 224 */ DisplayToWorld()225 void DisplayToWorld() {this->DisplayToView(); this->ViewToWorld();}; 226 227 /** 228 * Convert world point coordinates to display (or screen) coordinates. 229 */ WorldToDisplay()230 void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();}; 231 232 //@{ 233 /** 234 * These methods map from one coordinate system to another. 235 * They are primarily used by the vtkCoordinate object and 236 * are often strung together. These methods return valid information 237 * only if the window has been realized (e.g., GetSize() returns 238 * something other than (0,0)). 239 */ 240 virtual void LocalDisplayToDisplay(double &x, double &y); 241 virtual void DisplayToNormalizedDisplay(double &u, double &v); 242 virtual void NormalizedDisplayToViewport(double &x, double &y); 243 virtual void ViewportToNormalizedViewport(double &u, double &v); 244 virtual void NormalizedViewportToView(double &x, double &y, double &z); ViewToPose(double &,double &,double &)245 virtual void ViewToPose(double &, double &, double &) {} PoseToWorld(double &,double &,double &)246 virtual void PoseToWorld(double &, double &, double &) {} 247 virtual void DisplayToLocalDisplay(double &x, double &y); 248 virtual void NormalizedDisplayToDisplay(double &u, double &v); 249 virtual void ViewportToNormalizedDisplay(double &x, double &y); 250 virtual void NormalizedViewportToViewport(double &u, double &v); 251 virtual void ViewToNormalizedViewport(double &x, double &y, double &z); PoseToView(double &,double &,double &)252 virtual void PoseToView(double &, double &, double &) {} WorldToPose(double &,double &,double &)253 virtual void WorldToPose(double &, double &, double &) {} ViewToWorld(double &,double &,double &)254 virtual void ViewToWorld(double &, double &, double &) {} WorldToView(double &,double &,double &)255 virtual void WorldToView(double &, double &, double &) {} 256 //@} 257 258 //@{ 259 /** 260 * Get the size and origin of the viewport in display coordinates. Note: 261 * if the window has not yet been realized, GetSize() and GetOrigin() 262 * return (0,0). 263 */ 264 virtual int *GetSize() VTK_SIZEHINT(2); 265 virtual int *GetOrigin() VTK_SIZEHINT(2); 266 void GetTiledSize(int *width, int *height); 267 virtual void GetTiledSizeAndOrigin(int *width, int *height, 268 int *lowerLeftX, int *lowerLeftY); 269 //@} 270 271 // The following methods describe the public pick interface for picking 272 // Props in a viewport. 273 274 /** 275 * Return the Prop that has the highest z value at the given x, y position 276 * in the viewport. Basically, the top most prop that renders the pixel at 277 * selectionX, selectionY will be returned. If no Props are there NULL is 278 * returned. This method selects from the Viewports Prop list. 279 */ 280 virtual vtkAssemblyPath* PickProp(double selectionX, double selectionY) = 0; 281 282 /** 283 * Return the Prop that has the highest z value at the given x1, y1 284 * and x2,y2 positions in the viewport. Basically, the top most prop that 285 * renders the pixel at selectionX1, selectionY1, selectionX2, selectionY2 286 * will be returned. If no Props are there NULL is returned. This method 287 * selects from the Viewports Prop list. 288 */ 289 virtual vtkAssemblyPath* PickProp(double selectionX1, double selectionY1, 290 double selectionX2, double selectionY2) = 0; 291 292 /** 293 * Same as PickProp with two arguments, but selects from the given 294 * collection of Props instead of the Renderers props. Make sure 295 * the Props in the collection are in this renderer. 296 */ 297 vtkAssemblyPath* PickPropFrom(double selectionX, double selectionY, 298 vtkPropCollection*); 299 300 /** 301 * Same as PickProp with four arguments, but selects from the given 302 * collection of Props instead of the Renderers props. Make sure 303 * the Props in the collection are in this renderer. 304 */ 305 vtkAssemblyPath* PickPropFrom(double selectionX1, double selectionY1, 306 double selectionX2, double selectionY2, 307 vtkPropCollection*); 308 309 //@{ 310 /** 311 * Methods used to return the pick (x,y) in local display coordinates (i.e., 312 * it's that same as selectionX and selectionY). 313 */ GetPickX()314 double GetPickX() const {return (this->PickX1 + this->PickX2)*0.5;} GetPickY()315 double GetPickY() const {return (this->PickY1 + this->PickY2)*0.5;} GetPickWidth()316 double GetPickWidth() const {return this->PickX2 - this->PickX1 + 1;}; GetPickHeight()317 double GetPickHeight() const {return this->PickY2 - this->PickY1 + 1;}; GetPickX1()318 double GetPickX1() const {return this->PickX1;} GetPickY1()319 double GetPickY1() const {return this->PickY1;} GetPickX2()320 double GetPickX2() const {return this->PickX2;} GetPickY2()321 double GetPickY2() const {return this->PickY2;} 322 vtkGetObjectMacro(PickResultProps, vtkPropCollection); 323 //@} 324 325 /** 326 * Return the Z value for the last picked Prop. 327 */ GetPickedZ()328 virtual double GetPickedZ() { return this->PickedZ; }; 329 330 protected: 331 // Create a vtkViewport with a black background, a white ambient light, 332 // two-sided lighting turned on, a viewport of (0,0,1,1), and back face 333 // culling turned off. 334 vtkViewport(); 335 ~vtkViewport() override; 336 337 // Ivars for picking 338 // Store a picked Prop (contained in an assembly path) 339 vtkAssemblyPath* PickedProp; 340 vtkPropCollection* PickFromProps; 341 vtkPropCollection* PickResultProps; 342 double PickX1; 343 double PickY1; 344 double PickX2; 345 double PickY2; 346 double PickedZ; 347 // End Ivars for picking 348 349 vtkPropCollection *Props; 350 vtkActor2DCollection *Actors2D; 351 vtkWindow *VTKWindow; 352 double Background[3]; 353 double Background2[3]; 354 double BackgroundAlpha; 355 double Viewport[4]; 356 double Aspect[2]; 357 double PixelAspect[2]; 358 double Center[2]; 359 bool GradientBackground; 360 361 int Size[2]; 362 int Origin[2]; 363 double DisplayPoint[3]; 364 double ViewPoint[3]; 365 double WorldPoint[4]; 366 367 368 private: 369 vtkViewport(const vtkViewport&) = delete; 370 void operator=(const vtkViewport&) = delete; 371 }; 372 373 374 375 #endif 376