Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SbViewportRegion.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SB_VIEWPORT_REGION_
51#define _SB_VIEWPORT_REGION_
52
54//
55// Class: SbViewportRegion
56//
57// Class that represents the active viewport region in a display
58// window. It contains the screen-space size of the window as well as
59// the origin and size of the viewport within the window. By default,
60// the viewport is the same as the full window. Methods allow the
61// viewport to be set either in terms of screen space pixels or as
62// normalized coordinates, where (0,0) is the lower-left corner of
63// the window and (1,1) is the upper-right corner.
64//
66
67#include <Inventor/SbLinear.h>
68
104
105 public:
110
115 SbViewportRegion(short width, short height, float newScale = 1.0);
116
121 SbViewportRegion(SbVec2s winSize, float newScale = 1.0);
122
127 SbViewportRegion(SbVec2i32 winSize, float newScale = 1.0);
128
133
142 void setWindowSize(short width, short height)
143 { setWindowSize(SbVec2i32(width, height)); }
144
153 void setWindowSize(SbVec2s winSize);
154
164
172 void setViewport(float left, float bottom, float width, float height)
173 { setViewport(SbVec2f(left, bottom), SbVec2f(width, height)); }
174
181 void setViewport(SbVec2f origin, SbVec2f size);
182
190 void setViewportPixels(short left, short bottom, short width, short height)
191 { setViewportPixels(SbVec2i32(left, bottom), SbVec2i32(width, height)); }
192
201
210
217 const SbVec2s &getWindowSize() const;
218
226
232 { return vpOrigin; }
233
238
243
249 { return vpSize; }
250
255
260
265
271 void scaleWidth(float ratio);
272
278 void scaleHeight(float ratio);
279
284 void setPixelsPerInch(float ppi)
285 { pixelsPerInch = ppi; }
286
291 float getPixelsPerInch() const
292 { return pixelsPerInch; }
293
297 float getPixelsPerPoint() const
298 { return (pixelsPerInch / s_historicalPixelPerInch); }
299
307 SbVec2f normalize( const SbVec2s& position ) const;
308
312 friend int operator ==(const SbViewportRegion &reg1,
313 const SbViewportRegion &reg2);
314
318 friend int operator !=( const SbViewportRegion &reg1, const SbViewportRegion &reg2 )
319 {
320 return !operator==( reg1, reg2 );
321 }
322
323 private:
324
330 SbViewportRegion(SbVec2s viewSize, SbVec2s winSize, float newScale = 1.0);
331
332 void setViewportScale(float vpScale)
333 { viewportScale = vpScale; }
334
335 float getViewportScale() const
336 {return viewportScale; }
337
338 static const float s_historicalPixelPerInch;
339 static float s_defaultPixelsPerInch;
340 static void setDefaultPixelsPerInch(float ppi)
341 { s_defaultPixelsPerInch = ppi; }
342
343 private:
344 SbVec2i32 windowSize_i32; // Window size in pixels
345 SbVec2s windowSize; // Window size in pixels
346 SbVec2f vpOrigin; // Viewport origin, normalized
347 SbVec2s vpOriginPix; // Viewport origin in pixels
348 SbVec2i32 vpOriginPix_i32; // Viewport origin in pixels
349 SbVec2f vpSize; // Viewport size, normalized
350 SbVec2s vpSizePix; // Viewport size in pixels
351 SbVec2i32 vpSizePix_i32; // Viewport size in pixels
352 SbBool vpSet; // TRUE if viewport was set explicitly
353 float pixelsPerInch; // Number of pixels per inch
354 float viewportScale; // Viewport scale (used for remote rendering)
355
356 // Sets viewport to be full window
357 void setFullViewport();
358
359 // Adjusts viewport pixel size based on new window size or new viewport
360 void adjustViewport();
361};
362
379 public:
384 virtual ~SoGetView() {};
385
391
395 virtual const SbVec2f getViewportOrigin() const;
396
400 virtual const SbVec2f getViewportSize() const;
401};
402
403#endif /* _SB_VIEWPORT_REGION_ */
404
2D vector class.
Definition SbVec.h:76
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
Class for representing a viewport.
const SbVec2i32 & getWindowSize_i32() const
Returns window size in pixels.
SbViewportRegion()
Default constructor.
void setWindowSize(short width, short height)
Changes window size to given width and height in pixels.
const SbVec2s & getWindowSize() const
Returns window size in pixels.
void scaleWidth(float ratio)
Scales viewport within window to be the given ratio of its current width, leaving the resulting viewp...
void setPixelsPerInch(float ppi)
Sets the pixel-per-inch ratio for the display device the viewport is part of.
float getPixelsPerPoint() const
Convenience function that returns number of pixels per printer's point.
void setViewportPixels(short left, short bottom, short width, short height)
Sets viewport to given region, specified as pixel coordinates in window: (0,0) is the lower-left corn...
float getPixelsPerInch() const
Returns the pixel-per-inch ratio for the display device the viewport is part of.
const SbVec2s & getViewportOriginPixels() const
Returns viewport origin in pixels.
SbViewportRegion(SbVec2i32 winSize, float newScale=1.0)
Constructor that takes width and a height in pixels.
SbViewportRegion(SbVec2s winSize, float newScale=1.0)
Constructor that takes width and a height in pixels.
void setWindowSize(SbVec2i32 winSize)
Changes window size to given width and height in pixels, given as SbVec2i32.
friend int operator==(const SbViewportRegion &reg1, const SbViewportRegion &reg2)
Equality comparison operator.
void setViewportPixels(SbVec2i32 origin, SbVec2i32 size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates.
void setWindowSize(SbVec2s winSize)
Changes window size to given width and height in pixels, given as SbVec2s.
SbViewportRegion(const SbViewportRegion &vpReg)
Constructor that takes a viewport region.
void setViewportPixels(SbVec2s origin, SbVec2s size)
Sets viewport to region with given origin (lower-left corner) and size, given as pixel coordinates.
const SbVec2i32 & getViewportOriginPixels_i32() const
Returns viewport origin in pixels.
const SbVec2f & getViewportOrigin() const
Returns viewport origin in 0..1 normalized coordinates relative to the current window size.
friend int operator!=(const SbViewportRegion &reg1, const SbViewportRegion &reg2)
Inequality comparison operator.
const SbVec2i32 & getViewportSizePixels_i32() const
Returns viewport size in pixels.
void scaleHeight(float ratio)
Scales viewport within window to be the given ratio of its current height, leaving the resulting view...
SbVec2f normalize(const SbVec2s &position) const
Compute the 0..1 normalized coordinates of the specified pixel position, relative to the current view...
SbViewportRegion(short width, short height, float newScale=1.0)
Constructor that takes width and a height in pixels.
float getViewportAspectRatio() const
Returns aspect ratio (width/height) of viewport.
void setViewport(SbVec2f origin, SbVec2f size)
Sets viewport to given region, specified as normalized coordinates relative to the current window siz...
void setViewport(float left, float bottom, float width, float height)
Sets viewport to given region, specified as normalized coordinates relative to the current window siz...
const SbVec2s & getViewportSizePixels() const
Returns viewport size in pixels.
const SbVec2f & getViewportSize() const
Returns viewport size in 0..1 normalized coordinates relative to the current window size.
Class to access a MeshViz view.
virtual const SbVec2f getViewportSize() const
Returns SbViewportRegion size.
virtual ~SoGetView()
SoGetView()
Default constructor.
virtual SbBool getViewportIsEnabled() const
Returns TRUE if SoGetView functionalities are enabled, FALSE otherwise.
virtual const SbVec2f getViewportOrigin() const
Returns SbViewportRegion origin.
int SbBool
Boolean type.
Definition SbBase.h:87