Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SbViewVolume.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#ifndef _SB_VIEWVOLUME_
26#define _SB_VIEWVOLUME_
27
28#include <Inventor/SbBase.h>
29#include <Inventor/SbVec.h>
30#include <Inventor/SbBox.h>
31#include <Inventor/SbPlane.h>
32#include <Inventor/SbRotation.h>
33#include <Inventor/STL/vector>
34
35class SbLine;
36class SbMatrix;
37class SbPlane;
38class SbRotation;
39class SbVec2f;
40class SbVec3f;
41
42class DebugDataSbVolIntersect;
43class HomTransfData;
44
46//
47// Class: SbViewVolume
48//
49// Defines a 3D view volume. For perspective projection, the view
50// volume is a frustum. For orthographic (parallel) projection, the
51// view volume is a rectangular prism.
52//
54
55
81public:
82
91
102 float getMatrices(SbMatrix &affine, SbMatrix &proj) const;
103
116
123
127 void projectPointToLine(const SbVec2f &pt, SbLine &line) const;
128
134 SbVec3f &line0,
135 SbVec3f &line1) const;
136
154 void projectToScreen(const SbVec3f &src, SbVec3f &dst) const;
155
167 void projectFromScreen(const SbVec3f &src, SbVec3f &dst) const;
168
173 SbPlane getPlane(float distFromEye) const;
174
179 SbVec3f getSightPoint(float distFromEye) const;
180
186 SbVec3f getPlanePoint(float distFromEye,
187 const SbVec2f &normPoint) const;
188
195 SbRotation getAlignRotation(SbBool rightAngleOnly = FALSE) const;
196
202 float getWorldToScreenScale(const SbVec3f &worldCenter,
203 float normRadius) const;
204
209 SbVec2f projectBox(const SbBox3f &box) const;
210
216
221 static SbBox3f getProjectedBbox(const SbMatrix& affineProj, const SbBox3f& box);
222
228 SbViewVolume narrow(float left, float bottom,
229 float right, float top) const;
230
235 SbViewVolume narrow(const SbBox3f &box) const;
236
241 void ortho(float left, float right,
242 float bottom, float top,
243 float nearPlane, float farPlane);
244
250 void perspective(float fovy, float aspect,
251 float nearPlane, float farPlane);
252
258 void rotateCamera(const SbRotation &q);
259
265 void translateCamera(const SbVec3f &v);
266
272
279 SbViewVolume zNarrow(float nearPlane, float farPlane) const;
280
284 void scale(float factor);
285
291 void scaleWidth(float ratio);
292
298 void scaleHeight(float ratio);
299
313
317 inline ProjectionType getProjectionType() const { return type; }
318
322 inline const SbVec3f &getProjectionPoint() const { return projPoint; }
323
327 inline const SbVec3f &getProjectionDirection() const { return projDir; }
328
332 inline float getNearDist() const { return nearDist; }
333
337 inline float getWidth() const { return (lrfO-llfO).length(); }
338
342 inline float getHeight() const { return (ulfO-llfO).length(); }
343
347 inline float getDepth() const { return nearToFar; }
348
388
393
399 void setStereoAdjustment(float adjustment);
400
404 float getStereoAdjustment() const;
405
420 void setBalanceAdjustment(float adjustment, SbBool nearFrac = false);
421
425 float getBalanceAdjustment() const;
426
432
450
454 inline void setStereoMode(StereoMode mode) { stereoMode = mode ; }
455
459 inline StereoMode getStereoMode() const { return stereoMode ; }
460
464 SbBool equals(const SbViewVolume &v, float tolerance);
465
466 private:
467 ProjectionType type;
468
469 // Note that there is redundant info in this data structure and its
470 // elements should not be changed by hand.
471 SbVec3f projPoint; // "Top" of view frustum pyramid (for perspective), expressed in world space. Correspond in some way to eye location. must be (0,0,0) for ortho
472 SbVec3f projDir; // Line of sight in world space. Direction from point of view (projPoint) to center of screen.
473 float nearDist; // distance to near plane in world space
474 float nearToFar; // distance between z clips in world space
475 SbVec3f llf; // lower left front corner of view volume (over near clip plane), in world space
476 SbVec3f lrf; // lower right front corner of view volume (over near clip plane), in world space
477 SbVec3f ulf; // upper left front corner of view volume (over near clip plane), in world space
478 // Points on the near clipping plane. Add in the projPoint to
479 // figure out where they are in world space (llf = llfO + projPoint)
480 SbVec3f llfO; // x = -w, y = -w, z = -w
481 SbVec3f lrfO; // x = w, y = -w, z = -w
482 SbVec3f ulfO; // x = -w, y = w, z = -w
483
484 // Alternate way to set up a perspective view volume.
485 // Parameters are the same as for glFrustum.
486 void frustum( float left, float right, float bottom,
487 float top, float near_plane, float far_plane );
488
489 void frustumWorldCoords( const SbVec3f &projPt, const SbVec3f &projDire,
490 float radius, float near_plane, float far_plane, bool forceNearPlane = false );
491
492 // Transforms the view volume by the given matrix. NOTE: if the
493 // matrix performs a scale and a rotation, angles between the
494 // transformed projection direction and the sides of the view
495 // volume may not be preserved.
496 void transform( const SbMatrix &matrix);
497
498 // Returns TRUE if view volume contains point
499 SbBool intersect( const SbVec3f &point) const;
500
501 // Returns TRUE if view volume contains point, it uses the HomTransfData matrix if provided
502 SbBool intersect( const SbVec3f &point, HomTransfData *pHomTData ) const;
503
504 // Returns TRUE if line segment between 2 points may intersect
505 // volume. Returns closest point on line to center ray of volume
506 // if intersection is found.
507 SbBool intersectOld( const SbVec3f &p0,
508 const SbVec3f &p1,
509 HomTransfData *pHomTData,
510 SbVec3f &closestPoint,
511 DebugDataSbVolIntersect *pdd = 0 ) const;
512
513 // Returns TRUE if line segment between 2 points may intersect
514 // volume. Returns closest point on line to center ray of volume
515 // if intersection is found.
516 SbBool intersect(const SbVec3f &p0,
517 const SbVec3f &p1,
518 HomTransfData *pHomTData,
519 SbVec3f &closestPoint,
520 DebugDataSbVolIntersect *pdd = 0 ) const;
521
522 // Returns TRUE if triangle, made by three points, intersects
523 // volume. Returns closest point in the triangle to center ray of volume
524 // if intersection is found.
525 SbBool intersect( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
526 HomTransfData *pHomTData,
527 SbVec3f &intersection,
528 SbVec3f &barycentric, SbBool &front,
529 DebugDataSbVolIntersect *pdd = 0) const;
530
531 // Returns TRUE if bounding box may intersect volume
532 inline SbBool intersect( const SbBox3f &box) const
533 {
534 SbXfBox3f xbox(box);
535 return intersect(xbox);
536 }
537
538 // Returns TRUE if bounding box may intersect volume
539 SbBool intersect( const SbXfBox3f &box) const;
540
548 void clipFrustum(const SbXfBox3d& box, std::vector<SbVec3d>& points) const;
549
550 // Returns TRUE if the bounding box defined by min,max is totally
551 // outside plane p.
552 SbBool outsideTest( const SbPlane &p,
553 const SbVec3f &min, const SbVec3f &max) const;
554
555 void setCameraOffset(float);
556 float getCameraOffset(void) const;
557 void unsetCameraOffset(void);
558 int isCameraOffsetSet(void) const;
559
560 void setClipToFar(SbBool clipToFar);
561 void setClipToNear(SbBool clipToNear);
562
563 inline const SbBox3f& getFrustumBbox() const;
564
566 SbBox3f getRestrictedBbox(float visibilityLength) const ;
567
568 SbVec3f getllf() const { return llf; }
569
570 SbBool checkRadialDistance( const SbVec3f & pt, float radius ) const;
571
572 SbMatrix getAllMatrices( SbMatrix &affine, SbMatrix &proj ) const;
573
574private:
575
576 // Returns TRUE if triangle, made by three points, intersects
577 // volume. Returns closest point in the triangle to center ray of volume
578 // if intersection is found.
579 SbBool intersect1( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
580 HomTransfData *pHomTData,
581 SbVec3f &intersection,
582 SbVec3f &barycentric, SbBool &front,
583 DebugDataSbVolIntersect *pdd = 0) const;
584
585 SbBool intersect2( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
586 HomTransfData *pHomTData,
587 SbVec3f &intersection,
588 SbVec3f &barycentric, SbBool &front,
589 DebugDataSbVolIntersect *pdd = 0) const;
590
591 SbBox3f m_frustumBbox;
592
593 SbBool stereoAbsoluteAdjustments;
594 float stereoAdjustment, balanceAdjustment;
595 StereoMode stereoMode;
596 bool stereoNearFrac;
597
598 float mPStereoCameraOffset;
599 int mPStereoOffsetSet;
600
601 SbBool m_bClipToNear, m_bClipToFar;
602};
603
604// INLINE METHODS
605inline void
606SbViewVolume::setClipToFar(SbBool clipToFar)
607{
608 m_bClipToFar = clipToFar;
609}
610
611inline void
612SbViewVolume::setClipToNear(SbBool clipToNear)
613{
614 m_bClipToNear = clipToNear;
615}
616
617inline SbBool
619{
620 return stereoAbsoluteAdjustments;
621}
622
623inline void
625{
626 stereoAdjustment = adjustment;
627}
628
629inline float
631{
632 return stereoAdjustment;
633}
634
635inline void
637{
638 balanceAdjustment = adjustment;
639 stereoNearFrac = (nearFrac!=FALSE);
640}
641
642inline float
644{
645 return balanceAdjustment;
646}
647
648inline SbBool
650{
651 return stereoNearFrac;
652}
653
654inline void
656{
657 stereoAbsoluteAdjustments = absolute;
658}
659
660const SbBox3f&
661SbViewVolume::getFrustumBbox() const
662{
663 return m_frustumBbox;
664}
665
666#endif /* _SB_VIEWVOLUME_ */
667
668
3D box class.
Definition SbBox.h:649
Directed line in 3D.
Definition SbLine.h:57
4x4 matrix class.
Definition SbMatrix.h:309
Oriented plane in 3D.
Definition SbPlane.h:64
Class for representing a rotation.
Definition SbRotation.h:126
2D vector class.
Definition SbVec.h:76
3D vector class.
Definition SbVec.h:932
3D viewing volume class.
StereoMode
Stereo Modes.
@ RIGHT_VIEW
Right eye view.
@ LEFT_VIEW
Left eye view.
@ MONOSCOPIC
Monoscopic (i.e., non-stereo) viewing.
const SbVec3f & getProjectionPoint() const
Returns projection point.
void projectPointToLine(const SbVec2f &pt, SbLine &line) const
Maps a 2D point (in 0 <= x,y <= 1) to a 3D line.
ProjectionType getProjectionType() const
Returns projection type.
SbBool equals(const SbViewVolume &v, float tolerance)
Equality comparison within given tolerance.
void setStereoMode(StereoMode mode)
Sets the stereo mode.
float getDepth() const
Returns depth of viewing frustum.
void ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane)
Sets up an orthographic view volume with the given sides.
SbViewVolume()
Default constructor.
float getWorldToScreenScale(const SbVec3f &worldCenter, float normRadius) const
Returns a scale factor that would scale a unit sphere centered at worldCenter so that it would appe...
StereoMode getStereoMode() const
Queries the stereo mode.
void projectToScreen(const SbVec3f &src, SbVec3f &dst) const
Maps a 3D point in world coordinates to a 2D point in normalized screen coordinates (0 <= x,...
SbViewVolume narrow(const SbBox3f &box) const
Narrows a view volume by the given box.
void setStereoAdjustment(float adjustment)
Sets the stereo offset (the distance of each eye from the camera position).
float getBalanceAdjustment() const
Queries the parallax balance.
ProjectionType
Projection type.
@ ORTHOGRAPHIC
Orthographic projection.
@ PERSPECTIVE
Perspective projection.
void translateCamera(const SbVec3f &v)
Translate the camera viewpoint.
void rotateCamera(const SbRotation &q)
Rotate the camera view direction.
float getMatrices(SbMatrix &affine, SbMatrix &proj) const
Returns two matrices corresponding to the view volume.
void scale(float factor)
Scales width and height of view volume by given factor.
void setBalanceAdjustment(float adjustment, SbBool nearFrac=false)
Sets the stereo balance (the position of the zero parallax plane) and specifies whether the balance v...
SbViewVolume narrow(float left, float bottom, float right, float top) const
Given a view volume, narrows the view to the given sub-rectangle of the near plane.
void scaleHeight(float ratio)
Scales view volume to be the given ratio of its current height, leaving the resulting view volume cen...
float getHeight() const
Returns height of viewing frustum.
void perspective(float fovy, float aspect, float nearPlane, float farPlane)
Sets up a perspective view volume with the given field of view and aspect ratio.
void setStereoAbsoluteAdjustments(SbBool absolute)
Specifies if stereo adjustments are absolute.
SbVec3f getPlanePoint(float distFromEye, const SbVec2f &normPoint) const
Maps a 2D point in normalized screen coordinates (0 <= x,y <= 1) to a 3D world coordinates point on t...
void projectPointToLine(const SbVec2f &pt, SbVec3f &line0, SbVec3f &line1) const
Maps a 2D point (in 0 <= x,y <= 1) to a 3D line.
~SbViewVolume()
Destructor.
void scaleWidth(float ratio)
Scales view volume to be the given ratio of its current width, leaving the resulting view volume cent...
SbPlane getPlane(float distFromEye) const
Returns a plane parallel to the near (or far) plane of the view volume at a given distance from the p...
float getStereoAdjustment() const
Queries the stereo offset.
float getWidth() const
Returns width of viewing frustum.
SbRotation getAlignRotation(SbBool rightAngleOnly=FALSE) const
Returns a rotation that would align a viewed object so that its positive x-axis (of its object space)...
SbBox3f getProjectedBbox(const SbBox3f &box) const
Projects the given 3D bounding box onto the near plane and returns it (in normalized screen coordinat...
static SbBox3f getProjectedBbox(const SbMatrix &affineProj, const SbBox3f &box)
Same as getProjectedBbox but takes a matrix (containing affine and projection parts) to use instead o...
const SbVec3f & getProjectionDirection() const
Returns projection direction.
void projectFromScreen(const SbVec3f &src, SbVec3f &dst) const
Maps a 3D point in normalized screen coordinates (0 <= x,y,z <= 1) to a 3D world point.
SbMatrix getMatrix() const
Like the method above, but returns the affine and projection parts together in one matrix (i....
SbBool isStereoAbsoluteAdjustments() const
Returns TRUE if the stereo adjustments are absolute.
SbVec3f getSightPoint(float distFromEye) const
Returns the point along the line of sight at the given distance from the projection point (eye).
SbVec2f projectBox(const SbBox3f &box) const
Projects the given 3D bounding box onto the near plane and returns the size (in normalized screen coo...
SbMatrix getCameraSpaceMatrix() const
Returns a matrix that transforms the view volume into camera space: it translates the view volume so ...
SbViewVolume zNarrow(float nearPlane, float farPlane) const
Returns a narrowed view volume which contains as tightly as possible the given interval on the z axis...
SbVec3f zVector() const
Returns the positive z axis in eye space.
SbBool isBalanceNearFraction() const
Returns TRUE if the stereo balance adjustement is defined as a fraction of the camera near distance.
float getNearDist() const
Returns distance from projection point to near plane.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box with an a...
Definition SbBox.h:1513
3D box with an associated transformation matrix.
Definition SbBox.h:1250
int SbBool
Boolean type.
Definition SbBase.h:87