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