0032337: Visualization - rename Overlaps() method in selection to more self-describab...
[occt.git] / src / SelectMgr / SelectMgr_TriangularFrustumSet.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_TriangularFrustumSet_HeaderFile
17 #define _SelectMgr_TriangularFrustumSet_HeaderFile
18
19 #include <SelectMgr_TriangularFrustum.hxx>
20 #include <TColgp_HArray1OfPnt2d.hxx>
21
22 typedef NCollection_List<Handle(SelectMgr_TriangularFrustum)> SelectMgr_TriangFrustums;
23 typedef NCollection_List<Handle(SelectMgr_TriangularFrustum)>::Iterator SelectMgr_TriangFrustumsIter;
24
25 //! This class is used to handle polyline selection. The main principle of polyline selection
26 //! algorithm is to split the polygon defined by polyline onto triangles. Than each of
27 //! them is considered as a base for triangular frustum building. In other
28 //! words, each triangle vertiex will be projected from 2d screen space to 3d world space
29 //! onto near and far view frustum planes. Thus, the projected triangles make up the bases of
30 //! selecting frustum. When the set of such frustums is created, the function determining
31 //! selection iterates through triangular frustum set and searches for overlap with any
32 //! frustum.
33 class SelectMgr_TriangularFrustumSet : public SelectMgr_BaseFrustum
34 {
35 public:
36
37   //! Auxiliary structure to define selection polyline
38   struct SelectionPolyline
39   {
40     Handle(TColgp_HArray1OfPnt2d) Points;
41   };
42
43   SelectMgr_TriangularFrustumSet();
44
45   ~SelectMgr_TriangularFrustumSet() {};
46
47   //! Initializes set of triangular frustums by polyline
48   Standard_EXPORT void Init (const TColgp_Array1OfPnt2d& thePoints);
49
50   //! Meshes polygon bounded by polyline. Than organizes a set of triangular frustums,
51   //! where each triangle's projection onto near and far view frustum planes is
52   //! considered as a frustum base
53   //! NOTE: it should be called after Init() method
54   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
55
56   //! Returns a copy of the frustum with all sub-volumes transformed according to the matrix given
57   Standard_EXPORT virtual Handle(SelectMgr_BaseIntersector) ScaleAndTransform (const Standard_Integer theScale,
58                                                                                const gp_GTrsf& theTrsf,
59                                                                                const Handle(SelectMgr_FrustumBuilder)& theBuilder) const Standard_OVERRIDE;
60
61   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPnt,
62                                                         const SelectMgr_Vec3& theMaxPnt,
63                                                         const SelectMgr_ViewClipRange& theClipRange,
64                                                         SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
65
66   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPnt,
67                                                         const SelectMgr_Vec3& theMaxPnt,
68                                                         Standard_Boolean* theInside) const Standard_OVERRIDE;
69
70   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
71                                                           const SelectMgr_ViewClipRange& theClipRange,
72                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
73
74   Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPnts,
75                                                             Select3D_TypeOfSensitivity theSensType,
76                                                             const SelectMgr_ViewClipRange& theClipRange,
77                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
78
79   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
80                                                             const gp_Pnt& thePnt2,
81                                                             const SelectMgr_ViewClipRange& theClipRange,
82                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
83
84   Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
85                                                              const gp_Pnt& thePnt2,
86                                                              const gp_Pnt& thePnt3,
87                                                              Select3D_TypeOfSensitivity theSensType,
88                                                              const SelectMgr_ViewClipRange& theClipRange,
89                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
90
91   //! Calculates the point on a view ray that was detected during the run of selection algo by given depth
92   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
93
94   //! Stores plane equation coefficients (in the following form:
95   //! Ax + By + Cz + D = 0) to the given vector
96   Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
97
98   //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
99   //! mark both included and overlapped entities as matched
100   Standard_EXPORT virtual void SetAllowOverlapDetection (const Standard_Boolean theIsToAllow);
101
102   //! Dumps the content of me into the stream
103   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
104
105 private:
106
107   //! Checks whether the segment intersects with the boundary of the current volume selection
108   Standard_EXPORT Standard_Boolean isIntersectBoundary (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) const;
109
110   //! Checks whether the triangle intersects with a segment
111   Standard_EXPORT Standard_Boolean segmentTriangleIntersection (const gp_Pnt &theOrig, const gp_Vec& theDir,
112                                                                 const gp_Pnt& theV1, const gp_Pnt& theV2, const gp_Pnt& theV3) const;
113
114 private:
115
116   SelectMgr_TriangFrustums      myFrustums;          //!< set of triangular frustums
117   SelectionPolyline             mySelPolyline;       //!< parameters of selection polyline (it is used to build triangle frustum set)
118   TColgp_Array1OfPnt            myBoundaryPoints;    //!< boundary points
119   Standard_Boolean              myToAllowOverlap;    //!< flag to detect only fully included sensitives or not
120 };
121
122 #endif // _SelectMgr_TriangularFrustumSet_HeaderFile