0031035: Coding - uninitialized class fields reported by Visual Studio Code Analysis
[occt.git] / src / SelectMgr / SelectMgr_Frustum.hxx
1 // Created on: 2015-03-16
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-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 _SelectMgr_Frustum_HeaderFile
17 #define _SelectMgr_Frustum_HeaderFile
18
19 #include <BVH_Box.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Vec.hxx>
22 #include <gp_XYZ.hxx>
23 #include <SelectMgr_BaseFrustum.hxx>
24 #include <TColgp_HArray1OfPnt.hxx>
25 #include <TColgp_Array1OfPnt2d.hxx>
26
27 //! This is an internal class containing representation of rectangular selecting frustum, created in case
28 //! of point and box selection, and algorithms for overlap detection between selecting
29 //! frustum and sensitive entities. The principle of frustum calculation:
30 //! - for point selection: on a near view frustum plane rectangular neighborhood of
31 //!                        user-picked point is created according to the pixel tolerance
32 //!                        given and then this rectangle is projected onto far view frustum
33 //!                        plane. This rectangles define the parallel bases of selecting frustum;
34 //! - for box selection: box points are projected onto near and far view frustum planes.
35 //!                      These 2 projected rectangles define parallel bases of selecting frustum.
36 //! Overlap detection tests are implemented according to the terms of separating axis
37 //! theorem (SAT).
38 //! Vertex order:
39 //! - for triangular frustum: V0_Near, V1_Near, V2_Near,
40 //!                           V0_Far, V1_Far, V2_Far;
41 //! - for rectangular frustum: LeftTopNear, LeftTopFar,
42 //!                            LeftBottomNear,LeftBottomFar,
43 //!                            RightTopNear, RightTopFar,
44 //!                            RightBottomNear, RightBottomFar.
45 //! Plane order in array:
46 //! - for triangular frustum: V0V1, V1V2, V0V2, Near, Far;
47 //! - for rectangular frustum: Top, Bottom, Left, Right, Near, Far.
48 //! Uncollinear edge directions order:
49 //! - for rectangular frustum: Horizontal, Vertical,
50 //!                            LeftLower, RightLower,
51 //!                            LeftUpper, RightUpper;
52 //! - for triangular frustum: V0_Near - V0_Far, V1_Near - V1_Far, V2_Near - V2_Far,
53 //!                           V1_Near - V0_Near, V2_Near - V1_Near, V2_Near - V0_Near.
54 template <int N>
55 class SelectMgr_Frustum : public SelectMgr_BaseFrustum
56 {
57 public:
58
59   SelectMgr_Frustum() : SelectMgr_BaseFrustum()
60   {
61     memset (myMaxOrthoVertsProjections, 0, sizeof (myMaxOrthoVertsProjections));
62     memset (myMinOrthoVertsProjections, 0, sizeof (myMinOrthoVertsProjections));
63     memset (myMaxVertsProjections, 0, sizeof (myMaxVertsProjections));
64     memset (myMinVertsProjections, 0, sizeof (myMinVertsProjections));
65   }
66
67 protected:
68
69   // SAT Tests for different objects
70
71   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
72   //! with minimum corner at point theMinPt and maximum at point theMaxPt
73   Standard_Boolean hasOverlap (const SelectMgr_Vec3& theBoxMin,
74                                const SelectMgr_Vec3& theBoxMax,
75                                Standard_Boolean*     theInside = NULL) const;
76
77   //! SAT intersection test between defined volume and given point
78   Standard_Boolean hasOverlap (const gp_Pnt& thePnt) const;
79
80   //! SAT intersection test between defined volume and given segment
81   Standard_Boolean hasOverlap (const gp_Pnt& thePnt1,
82                                const gp_Pnt& thePnt2) const;
83
84   //! SAT intersection test between frustum given and planar convex polygon represented as ordered point set
85   Standard_Boolean hasOverlap (const TColgp_Array1OfPnt& theArrayOfPnts,
86                                gp_Vec& theNormal) const;
87
88   //! SAT intersection test between defined volume and given triangle
89   Standard_Boolean hasOverlap (const gp_Pnt& thePnt1,
90                                const gp_Pnt& thePnt2,
91                                const gp_Pnt& thePnt3,
92                                gp_Vec& theNormal) const;
93
94 private:
95
96   //! Checks if AABB and frustum are separated along the given axis
97   Standard_Boolean isSeparated (const SelectMgr_Vec3& theBoxMin,
98                                 const SelectMgr_Vec3& theBoxMax,
99                                 const gp_XYZ&         theDirect,
100                                 Standard_Boolean*     theInside) const;
101
102   //! Checks if triangle and frustum are separated along the given axis
103   Standard_Boolean isSeparated (const gp_Pnt& thePnt1,
104                                 const gp_Pnt& thePnt2,
105                                 const gp_Pnt& thePnt3,
106                                 const gp_XYZ& theAxis) const;
107
108 protected:
109
110   gp_Vec myPlanes[N + 2];        //!< Plane equations
111   gp_Pnt myVertices[N * 2];      //!< Vertices coordinates
112
113   Standard_Real myMaxVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
114   Standard_Real myMinVertsProjections[N + 2];      //!< Cached projections of vertices onto frustum plane directions
115   Standard_Real myMaxOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
116   Standard_Real myMinOrthoVertsProjections[3];     //!< Cached projections of vertices onto directions of ortho unit vectors
117
118   gp_Vec myEdgeDirs[6];                    //!< Cached edge directions
119 };
120
121 #include <SelectMgr_Frustum.lxx>
122
123 #endif // _SelectMgr_Frustum_HeaderFile