0032281: Visualization - add Select3D_SensitiveCylinder
[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 frustum and sensitive entities.
23 //! Overlap detection tests are implemented according to the terms of separating axis theorem (SAT).
24 //! NOTE: the object of this class can be created only as part of SelectMgr_TriangularFrustumSet.
25 class SelectMgr_TriangularFrustum : public SelectMgr_Frustum<3>
26 {
27 public:
28
29   //! Auxiliary structure to define selection triangle
30   struct SelectionTriangle
31   {
32     gp_Pnt2d Points[3];
33   };
34
35 public:
36
37   //! Destructor.
38   Standard_EXPORT virtual ~SelectMgr_TriangularFrustum();
39
40   //! Initializes selection triangle by input points
41   Standard_EXPORT void Init (const gp_Pnt2d& theP1,
42                              const gp_Pnt2d& theP2,
43                              const gp_Pnt2d& theP3);
44
45   //! Creates new triangular frustum with bases of triangles with vertices theP1, theP2 and theP3
46   //! projections onto near and far view frustum planes (only for triangular frustums)
47   //! NOTE: it should be called after Init() method
48   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
49
50   //! Returns FALSE (not applicable to this volume).
51   virtual Standard_Boolean IsScalable() const Standard_OVERRIDE { return false; }
52
53   //! Returns a copy of the frustum transformed according to the matrix given
54   Standard_EXPORT virtual Handle(SelectMgr_BaseIntersector) ScaleAndTransform (const Standard_Integer theScale,
55                                                                                const gp_GTrsf& theTrsf,
56                                                                                const Handle(SelectMgr_FrustumBuilder)& theBuilder) const Standard_OVERRIDE;
57
58 public: //! @name SAT Tests for different objects
59
60   //! SAT intersection test between defined volume and given axis-aligned box
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   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
67   //! with minimum corner at point theMinPt and maximum at point theMaxPt
68   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theMinPt,
69                                                         const SelectMgr_Vec3& theMaxPt,
70                                                         Standard_Boolean* theInside) const Standard_OVERRIDE;
71
72   //! Intersection test between defined volume and given point
73   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
74                                                           const SelectMgr_ViewClipRange& theClipRange,
75                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
76
77   //! Always returns FALSE (not applicable to this selector).
78   virtual Standard_Boolean OverlapsPoint (const gp_Pnt& ) const Standard_OVERRIDE
79   {
80     return Standard_False;
81   }
82
83   //! SAT intersection test between defined volume and given ordered set of points,
84   //! representing line segments. The test may be considered of interior part or
85   //! boundary line defined by segments depending on given sensitivity type
86   Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPnts,
87                                                             Select3D_TypeOfSensitivity theSensType,
88                                                             const SelectMgr_ViewClipRange& theClipRange,
89                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
90
91   //! Checks if line segment overlaps selecting frustum
92   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
93                                                             const gp_Pnt& thePnt2,
94                                                             const SelectMgr_ViewClipRange& theClipRange,
95                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
96
97   //! SAT intersection test between defined volume and given triangle. The test may
98   //! be considered of interior part or boundary line defined by triangle vertices
99   //! depending on given sensitivity type
100   Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
101                                                              const gp_Pnt& thePnt2,
102                                                              const gp_Pnt& thePnt3,
103                                                              Select3D_TypeOfSensitivity theSensType,
104                                                              const SelectMgr_ViewClipRange& theClipRange,
105                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
106
107   //! Returns true if selecting volume is overlapped by sphere with center theCenter
108   //! and radius theRadius
109   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
110                                                            const Standard_Real theRadius,
111                                                            Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
112
113   //! Returns true if selecting volume is overlapped by sphere with center theCenter
114   //! and radius theRadius
115   Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
116                                                            const Standard_Real theRadius,
117                                                            const SelectMgr_ViewClipRange& theClipRange,
118                                                            SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
119
120   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
121   //! and theTopRad, height theHeight and transformation to apply theTrsf.
122   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
123                                                              const Standard_Real theTopRad,
124                                                              const Standard_Real theHeight,
125                                                              const gp_Trsf& theTrsf,
126                                                              const SelectMgr_ViewClipRange& theClipRange,
127                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
128
129   //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
130   //! and theTopRad, height theHeight and transformation to apply theTrsf.
131   Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
132                                                              const Standard_Real theTopRad,
133                                                              const Standard_Real theHeight,
134                                                              const gp_Trsf& theTrsf,
135                                                              Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
136
137 public:
138
139   //! Nullifies the handle to corresponding builder instance to prevent memory leaks
140   Standard_EXPORT void Clear();
141
142   //! Stores plane equation coefficients (in the following form:
143   //! Ax + By + Cz + D = 0) to the given vector
144   Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
145
146   //! Dumps the content of me into the stream
147   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
148
149 protected:
150
151   //! Creates an empty triangular frustum.
152   Standard_EXPORT SelectMgr_TriangularFrustum();
153
154 private:
155
156   void cacheVertexProjections (SelectMgr_TriangularFrustum* theFrustum) const;
157
158 protected:
159
160   SelectionTriangle mySelTriangle; //!< parameters of selection triangle (it is used to build triangle frustum)
161
162 public:
163
164   DEFINE_STANDARD_RTTIEXT(SelectMgr_TriangularFrustum, SelectMgr_Frustum<3>)
165   friend class SelectMgr_TriangularFrustumSet;
166 };
167
168 #endif // _SelectMgr_TriangularFrustum_HeaderFile