0029283: Visualization - allow defining more than 8 light sources
[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
4ecf34cc 36 Standard_EXPORT void SetViewportSize (Standard_Integer theViewportWidth,
37 Standard_Integer theViewportHeight,
38 Standard_Real theResolutionRatio);
39
40 //! Setup distance culling.
41 Standard_EXPORT void SetCullingDistance (Standard_Real theDistance);
42
43 //! Setup size culling.
44 Standard_EXPORT void SetCullingSize (Standard_Real theSize);
45
46 //! Caches view volume's vertices projections along its normals and AABBs dimensions.
47 //! Must be called at the beginning of each BVH tree traverse loop.
48 Standard_EXPORT void CacheClipPtsProjections();
91d96372 49
b7cd4ba7 50 //! Detects if AABB overlaps view volume using separating axis theorem (SAT).
51 //! @param theMinPt [in] maximum point of AABB.
52 //! @param theMaxPt [in] minimum point of AABB.
53 //! @return Standard_True, if AABB is in viewing area, Standard_False otherwise.
7c3ef2f7 54 Standard_EXPORT Standard_Boolean Intersect (const OpenGl_Vec3d& theMinPt,
55 const OpenGl_Vec3d& theMaxPt) const;
b7cd4ba7 56
3fe9ce0e 57 //! Return the camera definition.
58 const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
59
825aa485 60 //! Returns current projection matrix.
7c3ef2f7 61 const OpenGl_Mat4d& ProjectionMatrix() const
825aa485 62 {
63 return myProjectionMat;
64 }
b7cd4ba7 65
825aa485 66 //! Returns current world view transformation matrix.
7c3ef2f7 67 const OpenGl_Mat4d& WorldViewMatrix() const
825aa485 68 {
69 return myWorldViewMat;
70 }
b7cd4ba7 71
91d96372 72 Standard_Integer ViewportWidth() const
73 {
74 return myViewportWidth;
75 }
76
77 Standard_Integer ViewportHeight() const
78 {
79 return myViewportHeight;
80 }
81
825aa485 82 //! Returns state of current world view projection transformation matrices.
83 const Graphic3d_WorldViewProjState& WorldViewProjState() const
84 {
85 return myWorldViewProjState;
86 }
b7cd4ba7 87
88protected:
89
90 //! Calculates signed distance from plane to point.
91 //! @param theNormal [in] the plane's normal.
92 //! @param thePnt [in]
7c3ef2f7 93 Standard_EXPORT Standard_Real SignedPlanePointDistance (const OpenGl_Vec4d& theNormal,
94 const OpenGl_Vec4d& thePnt);
b7cd4ba7 95
96protected:
97
98 //! Enumerates planes of view volume.
99 enum
100 {
101 Plane_Top,
102 Plane_Bottom,
103 Plane_Left,
104 Plane_Right,
105 Plane_Near,
106 Plane_Far,
107 PlanesNB
108 };
109
110 //! Enumerates vertices of view volume.
111 enum
112 {
113 ClipVert_LeftTopNear,
114 ClipVert_LeftBottomNear,
115 ClipVert_RightTopNear,
116 ClipVert_RightBottomNear,
117 ClipVert_LeftTopFar,
118 ClipVert_LeftBottomFar,
119 ClipVert_RightTopFar,
120 ClipVert_RightBottomFar,
121 ClipVerticesNB
122 };
123
124protected:
125
7c3ef2f7 126 OpenGl_Vec4d myClipPlanes[PlanesNB]; //!< Plane equations
127 OpenGl_Vec4d myClipVerts[ClipVerticesNB]; //!< Vertices
b7cd4ba7 128
3fe9ce0e 129 Handle(Graphic3d_Camera) myCamera; //!< camera definition
130
b7cd4ba7 131 // for caching clip points projections onto viewing area normals once per traverse
132 // ORDER: TOP, BOTTOM, LEFT, RIGHT, NEAR, FAR
7c3ef2f7 133 Standard_Real myMaxClipProjectionPts[PlanesNB]; //!< Max view volume's vertices projections onto its normals
134 Standard_Real myMinClipProjectionPts[PlanesNB]; //!< Min view volume's vertices projections onto its normals
b7cd4ba7 135
136 // for caching clip points projections onto AABB normals once per traverse
137 // ORDER: E0, E1, E2
7c3ef2f7 138 Standard_Real myMaxOrthoProjectionPts[3]; //!< Max view volume's vertices projections onto normalized dimensions of AABB
139 Standard_Real myMinOrthoProjectionPts[3]; //!< Min view volume's vertices projections onto normalized dimensions of AABB
b7cd4ba7 140
825aa485 141 Standard_Boolean myIsProjectionParallel;
b7cd4ba7 142
7c3ef2f7 143 OpenGl_Mat4d myProjectionMat;
144 OpenGl_Mat4d myWorldViewMat;
b7cd4ba7 145
91d96372 146 Standard_Integer myViewportWidth;
147 Standard_Integer myViewportHeight;
148
825aa485 149 Graphic3d_WorldViewProjState myWorldViewProjState; //!< State of world view projection matrices.
4ecf34cc 150
151 Graphic3d_Vec3d myCamEye; //!< camera eye position for distance culling
152 Standard_Real myCamScaleInv; //!< inverted camera scale for size culling
153 Standard_Real myDistCull; //!< culling distance
154 Standard_Real myPixelSize; //!< pixel size for size culling
155 Standard_Real mySizeCull2; //!< squared culling size
156
b7cd4ba7 157};
158
159#endif // _OpenGl_BVHTreeSelector_HeaderFile