0032337: Visualization - rename Overlaps() method in selection to more self-describab...
[occt.git] / src / SelectMgr / SelectMgr_TriangularFrustum.hxx
1 // Created on: 2014-05-22
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_TriangularFrustum_HeaderFile
17 #define _SelectMgr_TriangularFrustum_HeaderFile
18
19 #include <SelectMgr_Frustum.hxx>
20
21 //! This class contains representation of triangular selecting frustum, created in case
22 //! of polyline selection, and algorithms for overlap detection between selecting
23 //! frustum and sensitive entities.
24 //! Overlap detection tests are implemented according to the terms of separating axis
25 //! theorem (SAT).
26 //! NOTE: the object of this class can be created only as part of SelectMgr_TriangularFrustumSet.
27 class SelectMgr_TriangularFrustum : public SelectMgr_Frustum<3>
28 {
29 protected:
30
31   //! Creates new triangular frustum with bases of triangles with vertices theP1,
32   //! theP2 and theP3 projections onto near and far view frustum planes
33   SelectMgr_TriangularFrustum() {}
34
35 public:
36
37   //! Auxiliary structure to define selection triangle
38   struct SelectionTriangle
39   {
40     gp_Pnt2d Points[3];
41   };
42
43   Standard_EXPORT ~SelectMgr_TriangularFrustum();
44
45   //! Initializes selection triangle by input points
46   Standard_EXPORT void Init (const gp_Pnt2d& theP1,
47                              const gp_Pnt2d& theP2,
48                              const gp_Pnt2d& theP3);
49
50   //! Creates new triangular frustum with bases of triangles with vertices theP1, theP2 and theP3
51   //! projections onto near and far view frustum planes (only for triangular frustums)
52   //! NOTE: it should be called after Init() method
53   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
54
55   //! Returns a copy of the frustum transformed according to the matrix given
56   Standard_EXPORT virtual Handle(SelectMgr_BaseIntersector) ScaleAndTransform (const Standard_Integer theScale,
57                                                                                const gp_GTrsf& theTrsf,
58                                                                                const Handle(SelectMgr_FrustumBuilder)& theBuilder) const Standard_OVERRIDE;
59
60   // SAT Tests for different objects
61
62   //! SAT intersection test between defined volume and given axis-aligned box
63   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPnt,
64                                                         const SelectMgr_Vec3& theMaxPnt,
65                                                         const SelectMgr_ViewClipRange& theClipRange,
66                                                         SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
67
68   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
69   //! with minimum corner at point theMinPt and maximum at point theMaxPt
70   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPt,
71                                                         const SelectMgr_Vec3& theMaxPt,
72                                                         Standard_Boolean* theInside) const Standard_OVERRIDE;
73
74   //! Intersection test between defined volume and given point
75   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
76                                                           const SelectMgr_ViewClipRange& theClipRange,
77                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
78
79   //! SAT intersection test between defined volume and given ordered set of points,
80   //! representing line segments. The test may be considered of interior part or
81   //! boundary line defined by segments depending on given sensitivity type
82   Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPnts,
83                                                             Select3D_TypeOfSensitivity theSensType,
84                                                             const SelectMgr_ViewClipRange& theClipRange,
85                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
86
87   //! Checks if line segment overlaps selecting frustum
88   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
89                                                             const gp_Pnt& thePnt2,
90                                                             const SelectMgr_ViewClipRange& theClipRange,
91                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
92
93   //! SAT intersection test between defined volume and given triangle. The test may
94   //! be considered of interior part or boundary line defined by triangle vertices
95   //! depending on given sensitivity type
96   Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
97                                                              const gp_Pnt& thePnt2,
98                                                              const gp_Pnt& thePnt3,
99                                                              Select3D_TypeOfSensitivity theSensType,
100                                                              const SelectMgr_ViewClipRange& theClipRange,
101                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
102
103   //! Nullifies the handle to corresponding builder instance to prevent memory leaks
104   Standard_EXPORT void Clear();
105
106   //! Stores plane equation coefficients (in the following form:
107   //! Ax + By + Cz + D = 0) to the given vector
108   Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
109
110   //! Dumps the content of me into the stream
111   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
112
113 private:
114
115   void cacheVertexProjections (SelectMgr_TriangularFrustum* theFrustum) const;
116
117 protected:
118
119   SelectionTriangle mySelTriangle; //!< parameters of selection triangle (it is used to build triangle frustum)
120
121 public:
122
123   DEFINE_STANDARD_RTTIEXT(SelectMgr_TriangularFrustum, SelectMgr_Frustum<3>)
124
125   friend class SelectMgr_TriangularFrustumSet;
126 };
127
128 #endif // _SelectMgr_TriangularFrustum_HeaderFile