00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SB_VIEWVOLUME_
00026 #define _SB_VIEWVOLUME_
00027
00028 #include <Inventor/SbBase.h>
00029 #include <Inventor/SbVec.h>
00030 #include <Inventor/SbBox.h>
00031 #include <Inventor/SbPlane.h>
00032 #include <Inventor/SbRotation.h>
00033 #include <Inventor/STL/vector>
00034
00035 class SbLine;
00036 class SbMatrix;
00037 class SbPlane;
00038 class SbRotation;
00039 class SbVec2f;
00040 class SbVec3f;
00041
00042 class DebugDataSbVolIntersect;
00043 class HomTransfData;
00044
00046
00047
00048
00049
00050
00051
00052
00054
00055
00080 class SbViewVolume {
00081 public:
00082
00086 SbViewVolume();
00090 ~SbViewVolume() {}
00091
00102 float getMatrices(SbMatrix &affine, SbMatrix &proj) const;
00103
00115 SbMatrix getMatrix() const;
00116
00122 SbMatrix getCameraSpaceMatrix() const;
00123
00127 void projectPointToLine(const SbVec2f &pt, SbLine &line) const;
00128
00133 void projectPointToLine(const SbVec2f &pt,
00134 SbVec3f &line0,
00135 SbVec3f &line1) const;
00136
00154 void projectToScreen(const SbVec3f &src, SbVec3f &dst) const;
00155
00167 void projectFromScreen(const SbVec3f &src, SbVec3f &dst) const;
00168
00173 SbPlane getPlane(float distFromEye) const;
00174
00179 SbVec3f getSightPoint(float distFromEye) const;
00180
00186 SbVec3f getPlanePoint(float distFromEye,
00187 const SbVec2f &normPoint) const;
00188
00195 SbRotation getAlignRotation(SbBool rightAngleOnly = FALSE) const;
00196
00202 float getWorldToScreenScale(const SbVec3f &worldCenter,
00203 float normRadius) const;
00204
00209 SbVec2f projectBox(const SbBox3f &box) const;
00210
00215 SbBox3f getProjectedBbox(const SbBox3f &box) const;
00216
00221 SbBox3f getProjectedBbox(const SbMatrix& affineProj, const SbBox3f &box) const;
00222
00228 SbViewVolume narrow(float left, float bottom,
00229 float right, float top) const;
00230
00235 SbViewVolume narrow(const SbBox3f &box) const;
00236
00241 void ortho(float left, float right,
00242 float bottom, float top,
00243 float nearPlane, float farPlane);
00244
00250 void perspective(float fovy, float aspect,
00251 float nearPlane, float farPlane);
00252
00258 void rotateCamera(const SbRotation &q);
00259
00265 void translateCamera(const SbVec3f &v);
00266
00271 SbVec3f zVector() const;
00272
00279 SbViewVolume zNarrow(float nearPlane, float farPlane) const;
00280
00284 void scale(float factor);
00285
00291 void scaleWidth(float ratio);
00292
00298 void scaleHeight(float ratio);
00299
00303 enum ProjectionType {
00307 ORTHOGRAPHIC,
00311 PERSPECTIVE
00312 };
00313
00317 inline ProjectionType getProjectionType() const { return type; }
00318
00322 inline const SbVec3f &getProjectionPoint() const { return projPoint; }
00323
00327 inline const SbVec3f &getProjectionDirection() const { return projDir; }
00328
00332 inline float getNearDist() const { return nearDist; }
00333
00337 inline float getWidth() const { return (lrfO-llfO).length(); }
00338
00342 inline float getHeight() const { return (ulfO-llfO).length(); }
00343
00347 inline float getDepth() const { return nearToFar; }
00348
00387 void setStereoAbsoluteAdjustments(SbBool absolute);
00388
00392 SbBool isStereoAbsoluteAdjustments() const;
00393
00399 void setStereoAdjustment(float adjustment);
00400
00404 float getStereoAdjustment() const;
00405
00420 void setBalanceAdjustment(float adjustment, SbBool nearFrac = false);
00421
00425 float getBalanceAdjustment() const;
00426
00431 SbBool isBalanceNearFraction() const;
00432
00436 enum StereoMode {
00440 MONOSCOPIC,
00444 LEFT_VIEW,
00448 RIGHT_VIEW
00449 } ;
00450
00454 inline void setStereoMode(StereoMode mode) { stereoMode = mode ; }
00455
00459 inline StereoMode getStereoMode() const { return stereoMode ; }
00460
00464 SbBool equals(const SbViewVolume &v, float tolerance);
00465
00466 private:
00467 ProjectionType type;
00468
00469
00470
00471 SbVec3f projPoint;
00472 SbVec3f projDir;
00473 float nearDist;
00474 float nearToFar;
00475 SbVec3f llf;
00476 SbVec3f lrf;
00477 SbVec3f ulf;
00478
00479
00480 SbVec3f llfO;
00481 SbVec3f lrfO;
00482 SbVec3f ulfO;
00483
00484
00485
00486 void frustum( float left, float right, float bottom,
00487 float top, float near_plane, float far_plane );
00488
00489 void frustumWorldCoords( const SbVec3f &projPt, const SbVec3f &projDire,
00490 float radius, float near_plane, float far_plane, bool forceNearPlane = false );
00491
00492
00493
00494
00495
00496 void transform( const SbMatrix &matrix);
00497
00498
00499 SbBool intersect( const SbVec3f &point) const;
00500
00501
00502 SbBool intersect( const SbVec3f &point, HomTransfData *pHomTData ) const;
00503
00504
00505
00506
00507 SbBool intersectOld( const SbVec3f &p0,
00508 const SbVec3f &p1,
00509 HomTransfData *pHomTData,
00510 SbVec3f &closestPoint,
00511 DebugDataSbVolIntersect *pdd = 0 ) const;
00512
00513
00514
00515
00516 SbBool intersect(const SbVec3f &p0,
00517 const SbVec3f &p1,
00518 HomTransfData *pHomTData,
00519 SbVec3f &closestPoint,
00520 DebugDataSbVolIntersect *pdd = 0 ) const;
00521
00522
00523
00524
00525 SbBool intersect( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00526 HomTransfData *pHomTData,
00527 SbVec3f &intersection,
00528 SbVec3f &barycentric, SbBool &front,
00529 DebugDataSbVolIntersect *pdd = 0) const;
00530
00531
00532 inline SbBool intersect( const SbBox3f &box) const
00533 {
00534 SbXfBox3f xbox(box);
00535 return intersect(xbox);
00536 }
00537
00538
00539 SbBool intersect( const SbXfBox3f &box) const;
00540
00548 void clipFrustum(const SbXfBox3d& box, std::vector<SbVec3d>& points) const;
00549
00550
00551
00552 SbBool outsideTest( const SbPlane &p,
00553 const SbVec3f &min, const SbVec3f &max) const;
00554
00555 void setCameraOffset(float);
00556 float getCameraOffset(void) const;
00557 void unsetCameraOffset(void);
00558 int isCameraOffsetSet(void) const;
00559
00560 void setClipToFar(SbBool clipToFar);
00561 void setClipToNear(SbBool clipToNear);
00562
00563 inline const SbBox3f& getFrustumBbox() const;
00564
00566 SbBox3f getRestrictedBbox(float visibilityLength) const ;
00567
00568 SbVec3f getllf() const { return llf; }
00569
00570 SbBool checkRadialDistance( const SbVec3f & pt, float radius ) const;
00571
00572 SbMatrix getAllMatrices( SbMatrix &affine, SbMatrix &proj ) const;
00573
00574 private:
00575
00576
00577
00578
00579 SbBool intersect1( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00580 HomTransfData *pHomTData,
00581 SbVec3f &intersection,
00582 SbVec3f &barycentric, SbBool &front,
00583 DebugDataSbVolIntersect *pdd = 0) const;
00584
00585 SbBool intersect2( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00586 HomTransfData *pHomTData,
00587 SbVec3f &intersection,
00588 SbVec3f &barycentric, SbBool &front,
00589 DebugDataSbVolIntersect *pdd = 0) const;
00590
00591 SbBox3f m_frustumBbox;
00592
00593 SbBool stereoAbsoluteAdjustments;
00594 float stereoAdjustment, balanceAdjustment;
00595 StereoMode stereoMode;
00596 bool stereoNearFrac;
00597
00598 float mPStereoCameraOffset;
00599 int mPStereoOffsetSet;
00600
00601 SbBool m_bClipToNear, m_bClipToFar;
00602 };
00603
00604
00605 inline void
00606 SbViewVolume::setClipToFar(SbBool clipToFar)
00607 {
00608 m_bClipToFar = clipToFar;
00609 }
00610
00611 inline void
00612 SbViewVolume::setClipToNear(SbBool clipToNear)
00613 {
00614 m_bClipToNear = clipToNear;
00615 }
00616
00617 inline SbBool
00618 SbViewVolume::isStereoAbsoluteAdjustments() const
00619 {
00620 return stereoAbsoluteAdjustments;
00621 }
00622
00623 inline void
00624 SbViewVolume::setStereoAdjustment(float adjustment)
00625 {
00626 stereoAdjustment = adjustment;
00627 }
00628
00629 inline float
00630 SbViewVolume::getStereoAdjustment() const
00631 {
00632 return stereoAdjustment;
00633 }
00634
00635 inline void
00636 SbViewVolume::setBalanceAdjustment(float adjustment, SbBool nearFrac)
00637 {
00638 balanceAdjustment = adjustment;
00639 stereoNearFrac = (nearFrac!=FALSE);
00640 }
00641
00642 inline float
00643 SbViewVolume::getBalanceAdjustment() const
00644 {
00645 return balanceAdjustment;
00646 }
00647
00648 inline SbBool
00649 SbViewVolume::isBalanceNearFraction() const
00650 {
00651 return stereoNearFrac;
00652 }
00653
00654 inline void
00655 SbViewVolume::setStereoAbsoluteAdjustments(SbBool absolute)
00656 {
00657 stereoAbsoluteAdjustments = absolute;
00658 }
00659
00660 const SbBox3f&
00661 SbViewVolume::getFrustumBbox() const
00662 {
00663 return m_frustumBbox;
00664 }
00665
00666 #endif
00667
00668
00669