b7cd4ba7 |
1 | // Created on: 2013-12-25 |
2 | // Created by: Varvara POSKONINA |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _OpenGl_BVHTreeSelector_HeaderFile |
17 | #define _OpenGl_BVHTreeSelector_HeaderFile |
18 | |
19 | #include <Graphic3d_Camera.hxx> |
825aa485 |
20 | #include <Graphic3d_WorldViewProjState.hxx> |
b7cd4ba7 |
21 | #include <OpenGl_Vec.hxx> |
22 | |
23 | //! BVHTreeSelector class provides a possibility to store parameters of view volume, |
24 | //! such as its vertices and equations, and contains methods detecting if given AABB overlaps |
25 | //! view volume. |
26 | class OpenGl_BVHTreeSelector |
27 | { |
28 | public: |
29 | |
30 | //! Creates an empty selector object with parallel projection type by default. |
31 | Standard_EXPORT OpenGl_BVHTreeSelector(); |
32 | |
825aa485 |
33 | //! Retrieves view volume's planes equations and its vertices from projection and world-view matrices. |
b7cd4ba7 |
34 | Standard_EXPORT void SetViewVolume (const Handle(Graphic3d_Camera)& theCamera); |
35 | |
91d96372 |
36 | Standard_EXPORT void SetViewportSize (const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight); |
37 | |
b7cd4ba7 |
38 | //! Detects if AABB overlaps view volume using separating axis theorem (SAT). |
39 | //! @param theMinPt [in] maximum point of AABB. |
40 | //! @param theMaxPt [in] minimum point of AABB. |
41 | //! @return Standard_True, if AABB is in viewing area, Standard_False otherwise. |
42 | Standard_EXPORT Standard_Boolean Intersect (const OpenGl_Vec4& theMinPt, |
43 | const OpenGl_Vec4& theMaxPt) const; |
44 | |
45 | //! Caches view volume's vertices projections along its normals and AABBs dimensions. |
46 | //! Must be called at the beginning of each BVH tree traverse loop. |
47 | Standard_EXPORT void CacheClipPtsProjections(); |
48 | |
3fe9ce0e |
49 | //! Return the camera definition. |
50 | const Handle(Graphic3d_Camera)& Camera() const { return myCamera; } |
51 | |
825aa485 |
52 | //! Returns current projection matrix. |
53 | const OpenGl_Mat4& ProjectionMatrix() const |
54 | { |
55 | return myProjectionMat; |
56 | } |
b7cd4ba7 |
57 | |
825aa485 |
58 | //! Returns current world view transformation matrix. |
59 | const OpenGl_Mat4& WorldViewMatrix() const |
60 | { |
61 | return myWorldViewMat; |
62 | } |
b7cd4ba7 |
63 | |
91d96372 |
64 | Standard_Integer ViewportWidth() const |
65 | { |
66 | return myViewportWidth; |
67 | } |
68 | |
69 | Standard_Integer ViewportHeight() const |
70 | { |
71 | return myViewportHeight; |
72 | } |
73 | |
825aa485 |
74 | //! Returns state of current world view projection transformation matrices. |
75 | const Graphic3d_WorldViewProjState& WorldViewProjState() const |
76 | { |
77 | return myWorldViewProjState; |
78 | } |
b7cd4ba7 |
79 | |
80 | protected: |
81 | |
82 | //! Calculates signed distance from plane to point. |
83 | //! @param theNormal [in] the plane's normal. |
84 | //! @param thePnt [in] |
85 | Standard_EXPORT Standard_ShortReal SignedPlanePointDistance (const OpenGl_Vec4& theNormal, |
86 | const OpenGl_Vec4& thePnt); |
87 | |
88 | protected: |
89 | |
90 | //! Enumerates planes of view volume. |
91 | enum |
92 | { |
93 | Plane_Top, |
94 | Plane_Bottom, |
95 | Plane_Left, |
96 | Plane_Right, |
97 | Plane_Near, |
98 | Plane_Far, |
99 | PlanesNB |
100 | }; |
101 | |
102 | //! Enumerates vertices of view volume. |
103 | enum |
104 | { |
105 | ClipVert_LeftTopNear, |
106 | ClipVert_LeftBottomNear, |
107 | ClipVert_RightTopNear, |
108 | ClipVert_RightBottomNear, |
109 | ClipVert_LeftTopFar, |
110 | ClipVert_LeftBottomFar, |
111 | ClipVert_RightTopFar, |
112 | ClipVert_RightBottomFar, |
113 | ClipVerticesNB |
114 | }; |
115 | |
116 | protected: |
117 | |
825aa485 |
118 | OpenGl_Vec4 myClipPlanes[PlanesNB]; //!< Plane equations |
119 | OpenGl_Vec4 myClipVerts[ClipVerticesNB]; //!< Vertices |
b7cd4ba7 |
120 | |
3fe9ce0e |
121 | Handle(Graphic3d_Camera) myCamera; //!< camera definition |
122 | |
b7cd4ba7 |
123 | // for caching clip points projections onto viewing area normals once per traverse |
124 | // ORDER: TOP, BOTTOM, LEFT, RIGHT, NEAR, FAR |
125 | Standard_ShortReal myMaxClipProjectionPts[PlanesNB]; //!< Max view volume's vertices projections onto its normals |
126 | Standard_ShortReal myMinClipProjectionPts[PlanesNB]; //!< Min view volume's vertices projections onto its normals |
127 | |
128 | // for caching clip points projections onto AABB normals once per traverse |
129 | // ORDER: E0, E1, E2 |
825aa485 |
130 | Standard_ShortReal myMaxOrthoProjectionPts[3]; //!< Max view volume's vertices projections onto normalized dimensions of AABB |
131 | Standard_ShortReal myMinOrthoProjectionPts[3]; //!< Min view volume's vertices projections onto normalized dimensions of AABB |
b7cd4ba7 |
132 | |
825aa485 |
133 | Standard_Boolean myIsProjectionParallel; |
b7cd4ba7 |
134 | |
825aa485 |
135 | OpenGl_Mat4 myProjectionMat; |
136 | OpenGl_Mat4 myWorldViewMat; |
b7cd4ba7 |
137 | |
91d96372 |
138 | Standard_Integer myViewportWidth; |
139 | Standard_Integer myViewportHeight; |
140 | |
825aa485 |
141 | Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices. |
b7cd4ba7 |
142 | }; |
143 | |
144 | #endif // _OpenGl_BVHTreeSelector_HeaderFile |