0029285: Visualization, V3d_View::UpdateLights() - eliminate implicit redraw
[occt.git] / src / OpenGl / OpenGl_BVHTreeSelector.hxx
... / ...
CommitLineData
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>
20#include <Graphic3d_WorldViewProjState.hxx>
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
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);
35
36 Standard_EXPORT void SetViewportSize (const Standard_Integer theViewportWidth, const Standard_Integer theViewportHeight);
37
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_Vec3d& theMinPt,
43 const OpenGl_Vec3d& 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
49 //! Return the camera definition.
50 const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
51
52 //! Returns current projection matrix.
53 const OpenGl_Mat4d& ProjectionMatrix() const
54 {
55 return myProjectionMat;
56 }
57
58 //! Returns current world view transformation matrix.
59 const OpenGl_Mat4d& WorldViewMatrix() const
60 {
61 return myWorldViewMat;
62 }
63
64 Standard_Integer ViewportWidth() const
65 {
66 return myViewportWidth;
67 }
68
69 Standard_Integer ViewportHeight() const
70 {
71 return myViewportHeight;
72 }
73
74 //! Returns state of current world view projection transformation matrices.
75 const Graphic3d_WorldViewProjState& WorldViewProjState() const
76 {
77 return myWorldViewProjState;
78 }
79
80protected:
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_Real SignedPlanePointDistance (const OpenGl_Vec4d& theNormal,
86 const OpenGl_Vec4d& thePnt);
87
88protected:
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
116protected:
117
118 OpenGl_Vec4d myClipPlanes[PlanesNB]; //!< Plane equations
119 OpenGl_Vec4d myClipVerts[ClipVerticesNB]; //!< Vertices
120
121 Handle(Graphic3d_Camera) myCamera; //!< camera definition
122
123 // for caching clip points projections onto viewing area normals once per traverse
124 // ORDER: TOP, BOTTOM, LEFT, RIGHT, NEAR, FAR
125 Standard_Real myMaxClipProjectionPts[PlanesNB]; //!< Max view volume's vertices projections onto its normals
126 Standard_Real 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
130 Standard_Real myMaxOrthoProjectionPts[3]; //!< Max view volume's vertices projections onto normalized dimensions of AABB
131 Standard_Real myMinOrthoProjectionPts[3]; //!< Min view volume's vertices projections onto normalized dimensions of AABB
132
133 Standard_Boolean myIsProjectionParallel;
134
135 OpenGl_Mat4d myProjectionMat;
136 OpenGl_Mat4d myWorldViewMat;
137
138 Standard_Integer myViewportWidth;
139 Standard_Integer myViewportHeight;
140
141 Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices.
142};
143
144#endif // _OpenGl_BVHTreeSelector_HeaderFile