1 // Created on: 2013-12-25
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_BVHTreeSelector_HeaderFile
17 #define _OpenGl_BVHTreeSelector_HeaderFile
19 #include <Graphic3d_Camera.hxx>
20 #include <Graphic3d_WorldViewProjState.hxx>
21 #include <OpenGl_Vec.hxx>
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
26 class OpenGl_BVHTreeSelector
30 //! Creates an empty selector object with parallel projection type by default.
31 Standard_EXPORT OpenGl_BVHTreeSelector();
33 //! Retrieves view volume's planes equations and its vertices from projection and world-view matrices.
34 Standard_EXPORT void SetViewVolume (const Handle(Graphic3d_Camera)& theCamera);
36 //! Detects if AABB overlaps view volume using separating axis theorem (SAT).
37 //! @param theMinPt [in] maximum point of AABB.
38 //! @param theMaxPt [in] minimum point of AABB.
39 //! @return Standard_True, if AABB is in viewing area, Standard_False otherwise.
40 Standard_EXPORT Standard_Boolean Intersect (const OpenGl_Vec4& theMinPt,
41 const OpenGl_Vec4& theMaxPt) const;
43 //! Caches view volume's vertices projections along its normals and AABBs dimensions.
44 //! Must be called at the beginning of each BVH tree traverse loop.
45 Standard_EXPORT void CacheClipPtsProjections();
47 //! Returns current projection matrix.
48 const OpenGl_Mat4& ProjectionMatrix() const
50 return myProjectionMat;
53 //! Returns current world view transformation matrix.
54 const OpenGl_Mat4& WorldViewMatrix() const
56 return myWorldViewMat;
59 //! Returns state of current world view projection transformation matrices.
60 const Graphic3d_WorldViewProjState& WorldViewProjState() const
62 return myWorldViewProjState;
67 //! Calculates signed distance from plane to point.
68 //! @param theNormal [in] the plane's normal.
69 //! @param thePnt [in]
70 Standard_EXPORT Standard_ShortReal SignedPlanePointDistance (const OpenGl_Vec4& theNormal,
71 const OpenGl_Vec4& thePnt);
75 //! Enumerates planes of view volume.
87 //! Enumerates vertices of view volume.
91 ClipVert_LeftBottomNear,
92 ClipVert_RightTopNear,
93 ClipVert_RightBottomNear,
95 ClipVert_LeftBottomFar,
97 ClipVert_RightBottomFar,
103 OpenGl_Vec4 myClipPlanes[PlanesNB]; //!< Plane equations
104 OpenGl_Vec4 myClipVerts[ClipVerticesNB]; //!< Vertices
106 // for caching clip points projections onto viewing area normals once per traverse
107 // ORDER: TOP, BOTTOM, LEFT, RIGHT, NEAR, FAR
108 Standard_ShortReal myMaxClipProjectionPts[PlanesNB]; //!< Max view volume's vertices projections onto its normals
109 Standard_ShortReal myMinClipProjectionPts[PlanesNB]; //!< Min view volume's vertices projections onto its normals
111 // for caching clip points projections onto AABB normals once per traverse
113 Standard_ShortReal myMaxOrthoProjectionPts[3]; //!< Max view volume's vertices projections onto normalized dimensions of AABB
114 Standard_ShortReal myMinOrthoProjectionPts[3]; //!< Min view volume's vertices projections onto normalized dimensions of AABB
116 Standard_Boolean myIsProjectionParallel;
118 OpenGl_Mat4 myProjectionMat;
119 OpenGl_Mat4 myWorldViewMat;
121 Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices.
124 #endif // _OpenGl_BVHTreeSelector_HeaderFile