0027350: Support for Universal Windows Platform
[occt.git] / src / OpenGl / OpenGl_BVHTreeSelector.hxx
CommitLineData
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.
26class OpenGl_BVHTreeSelector
27{
28public:
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
825aa485 49 //! Returns current projection matrix.
50 const OpenGl_Mat4& ProjectionMatrix() const
51 {
52 return myProjectionMat;
53 }
b7cd4ba7 54
825aa485 55 //! Returns current world view transformation matrix.
56 const OpenGl_Mat4& WorldViewMatrix() const
57 {
58 return myWorldViewMat;
59 }
b7cd4ba7 60
91d96372 61 Standard_Integer ViewportWidth() const
62 {
63 return myViewportWidth;
64 }
65
66 Standard_Integer ViewportHeight() const
67 {
68 return myViewportHeight;
69 }
70
825aa485 71 //! Returns state of current world view projection transformation matrices.
72 const Graphic3d_WorldViewProjState& WorldViewProjState() const
73 {
74 return myWorldViewProjState;
75 }
b7cd4ba7 76
77protected:
78
79 //! Calculates signed distance from plane to point.
80 //! @param theNormal [in] the plane's normal.
81 //! @param thePnt [in]
82 Standard_EXPORT Standard_ShortReal SignedPlanePointDistance (const OpenGl_Vec4& theNormal,
83 const OpenGl_Vec4& thePnt);
84
85protected:
86
87 //! Enumerates planes of view volume.
88 enum
89 {
90 Plane_Top,
91 Plane_Bottom,
92 Plane_Left,
93 Plane_Right,
94 Plane_Near,
95 Plane_Far,
96 PlanesNB
97 };
98
99 //! Enumerates vertices of view volume.
100 enum
101 {
102 ClipVert_LeftTopNear,
103 ClipVert_LeftBottomNear,
104 ClipVert_RightTopNear,
105 ClipVert_RightBottomNear,
106 ClipVert_LeftTopFar,
107 ClipVert_LeftBottomFar,
108 ClipVert_RightTopFar,
109 ClipVert_RightBottomFar,
110 ClipVerticesNB
111 };
112
113protected:
114
825aa485 115 OpenGl_Vec4 myClipPlanes[PlanesNB]; //!< Plane equations
116 OpenGl_Vec4 myClipVerts[ClipVerticesNB]; //!< Vertices
b7cd4ba7 117
118 // for caching clip points projections onto viewing area normals once per traverse
119 // ORDER: TOP, BOTTOM, LEFT, RIGHT, NEAR, FAR
120 Standard_ShortReal myMaxClipProjectionPts[PlanesNB]; //!< Max view volume's vertices projections onto its normals
121 Standard_ShortReal myMinClipProjectionPts[PlanesNB]; //!< Min view volume's vertices projections onto its normals
122
123 // for caching clip points projections onto AABB normals once per traverse
124 // ORDER: E0, E1, E2
825aa485 125 Standard_ShortReal myMaxOrthoProjectionPts[3]; //!< Max view volume's vertices projections onto normalized dimensions of AABB
126 Standard_ShortReal myMinOrthoProjectionPts[3]; //!< Min view volume's vertices projections onto normalized dimensions of AABB
b7cd4ba7 127
825aa485 128 Standard_Boolean myIsProjectionParallel;
b7cd4ba7 129
825aa485 130 OpenGl_Mat4 myProjectionMat;
131 OpenGl_Mat4 myWorldViewMat;
b7cd4ba7 132
91d96372 133 Standard_Integer myViewportWidth;
134 Standard_Integer myViewportHeight;
135
825aa485 136 Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices.
b7cd4ba7 137};
138
139#endif // _OpenGl_BVHTreeSelector_HeaderFile