1 #ifndef COIN_SBDPVIEWVOLUME_H
2 #define COIN_SBDPVIEWVOLUME_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 
38 #include <Inventor/SbBasic.h>
39 #include <Inventor/SbVec3d.h>
40 
41 class SbBox3f;
42 class SbDPLine;
43 class SbDPMatrix;
44 class SbPlane;
45 class SbDPRotation;
46 class SbVec2d;
47 class SbViewVolume;
48 
49 class COIN_DLL_API SbDPViewVolume {
50 public:
51   enum ProjectionType { ORTHOGRAPHIC = 0, PERSPECTIVE = 1 };
52 
53 public:
54   SbDPViewVolume(void);
55   ~SbDPViewVolume(void);
56   void getMatrices(SbDPMatrix& affine, SbDPMatrix& proj) const;
57   SbDPMatrix getMatrix(void) const;
58   SbDPMatrix getCameraSpaceMatrix(void) const;
59   void projectPointToLine(const SbVec2d& pt, SbDPLine& line) const;
60   void projectPointToLine(const SbVec2d& pt,
61                           SbVec3d& line0, SbVec3d& line1) const;
62   void projectToScreen(const SbVec3d& src, SbVec3d& dst) const;
63   SbPlane getPlane(const double distFromEye) const;
64   SbVec3d getSightPoint(const double distFromEye) const;
65   SbVec3d getPlanePoint(const double distFromEye,
66                         const SbVec2d& normPoint) const;
67   SbDPRotation getAlignRotation(SbBool rightAngleOnly = FALSE) const;
68   double getWorldToScreenScale(const SbVec3d& worldCenter,
69                               double normRadius) const;
70   SbVec2d projectBox(const SbBox3f& box) const;
71   SbDPViewVolume narrow(double left, double bottom,
72                       double right, double top) const;
73   SbDPViewVolume narrow(const SbBox3f& box) const;
74   void ortho(double left, double right,
75              double bottom, double top,
76              double nearval, double farval);
77   void perspective(double fovy, double aspect,
78                    double nearval, double farval);
79   void frustum(double left, double right,
80                double bottom, double top,
81                double nearval, double farval);
82   void rotateCamera(const SbDPRotation& q);
83   void translateCamera(const SbVec3d& v);
84   SbVec3d zVector(void) const;
85   SbDPViewVolume zNarrow(double nearval, double farval) const;
86   void scale(double factor);
87   void scaleWidth(double ratio);
88   void scaleHeight(double ratio);
89   ProjectionType getProjectionType(void) const;
90   const SbVec3d& getProjectionPoint(void) const;
91   const SbVec3d& getProjectionDirection(void) const;
92   double getNearDist(void) const;
93   double getWidth(void) const;
94   double getHeight(void) const;
95   double getDepth(void) const;
96 
97   void print(FILE * fp) const;
98   void getViewVolumePlanes(SbPlane planes[6]) const;
99   void transform(const SbDPMatrix &matrix);
100   SbVec3d getViewUp(void) const;
101 
102   void copyValues(SbViewVolume & vv);
103 
104 private:
105 
106   ProjectionType type;
107   SbVec3d projPoint;
108   SbVec3d projDir;
109   double nearDist;
110   double nearToFar;
111   SbVec3d llf;
112   SbVec3d lrf;
113   SbVec3d ulf;
114 
115   void getPlaneRectangle(const double depth, SbVec3d & lowerleft,
116                          SbVec3d & lowerright, SbVec3d & upperleft,
117                          SbVec3d & upperright) const;
118 };
119 
120 #endif // !COIN_SBDPVIEWVOLUME_H
121