0032337: Visualization - rename Overlaps() method in selection to more self-describab...
[occt.git] / src / SelectMgr / SelectMgr_AxisIntersector.hxx
1 // Copyright (c) 2021 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _SelectMgr_AxisIntersector_HeaderFile
15 #define _SelectMgr_AxisIntersector_HeaderFile
16
17 #include <SelectMgr_BaseIntersector.hxx>
18
19 #include <gp_Ax1.hxx>
20
21 //! This class contains representation of selecting axis, created in case of point selection
22 //! and algorithms for overlap detection between this axis and sensitive entities.
23 class SelectMgr_AxisIntersector : public SelectMgr_BaseIntersector
24 {
25 public:
26
27   //! Empty constructor
28   Standard_EXPORT SelectMgr_AxisIntersector();
29
30   //! Destructor
31   virtual ~SelectMgr_AxisIntersector() {}
32
33   //! Initializes selecting axis according to the input one
34   Standard_EXPORT void Init (const gp_Ax1& theAxis);
35
36   //! Builds axis according to internal parameters.
37   //! NOTE: it should be called after Init() method
38   Standard_EXPORT virtual void Build() Standard_OVERRIDE;
39
40   //! IMPORTANT: Scaling doesn't make sense for this intersector.
41   //! Returns a copy of the intersector transformed using the matrix given.
42   //! Builder is an optional argument that represents corresponding settings for re-constructing transformed
43   //! frustum from scratch. Can be null if reconstruction is not expected furthermore.
44   Standard_EXPORT virtual Handle(SelectMgr_BaseIntersector)
45     ScaleAndTransform (const Standard_Integer theScaleFactor,
46                        const gp_GTrsf& theTrsf,
47                        const Handle(SelectMgr_FrustumBuilder)& theBuilder = Handle(SelectMgr_FrustumBuilder)()) const Standard_OVERRIDE;
48
49 public:
50
51   //! Intersection test between defined axis and given axis-aligned box
52   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
53                                                         const SelectMgr_Vec3& theBoxMax,
54                                                         const SelectMgr_ViewClipRange& theClipRange,
55                                                         SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
56
57   //! Returns true if selecting axis intersects axis-aligned bounding box
58   //! with minimum corner at point theMinPt and maximum at point theMaxPt
59   Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
60                                                         const SelectMgr_Vec3& theBoxMax,
61                                                         Standard_Boolean*     theInside) const Standard_OVERRIDE;
62
63   //! Intersection test between defined axis and given point
64   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
65                                                           const SelectMgr_ViewClipRange& theClipRange,
66                                                           SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
67
68   //! Intersection test between defined axis and given point
69   Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt) const Standard_OVERRIDE;
70
71   //! Intersection test between defined axis and given ordered set of points,
72   //! representing line segments. The test may be considered of interior part or
73   //! boundary line defined by segments depending on given sensitivity type
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   //! Checks if selecting axis intersects line segment
80   Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
81                                                             const gp_Pnt& thePnt2,
82                                                             const SelectMgr_ViewClipRange& theClipRange,
83                                                             SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
84
85   //! Intersection test between defined axis and given triangle. The test may
86   //! be considered of interior part or boundary line defined by triangle vertices
87   //! depending on given sensitivity type
88   Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
89                                                              const gp_Pnt& thePnt2,
90                                                              const gp_Pnt& thePnt3,
91                                                              Select3D_TypeOfSensitivity theSensType,
92                                                              const SelectMgr_ViewClipRange& theClipRange,
93                                                              SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
94
95 public:
96
97   //! Measures distance between start axis point and given point theCOG.
98   Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const Standard_OVERRIDE;
99
100   //! Calculates the point on a axis ray that was detected during the run of selection algo by given depth
101   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
102
103   //! Returns near point along axis.
104   Standard_EXPORT virtual const gp_Pnt& GetNearPnt() const Standard_OVERRIDE;
105
106   //! Returns far point along axis (infinite).
107   Standard_EXPORT virtual const gp_Pnt& GetFarPnt() const Standard_OVERRIDE;
108
109   //! Returns axis direction.
110   Standard_EXPORT virtual const gp_Dir& GetViewRayDirection() const Standard_OVERRIDE;
111
112   //! Dumps the content of me into the stream
113   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
114
115 protected:
116
117   //! Returns true if selecting axis intersects axis-aligned bounding box
118   //! with minimum corner at point theBoxMin and maximum at point theBoxMax.
119   //! Also returns enter and leave time of axis-box intersection.
120   Standard_EXPORT Standard_Boolean hasIntersection (const SelectMgr_Vec3& theBoxMin,
121                                                     const SelectMgr_Vec3& theBoxMax,
122                                                     Standard_Real& theTimeEnter,
123                                                     Standard_Real& theTimeLeave) const;
124
125   //! Returns true if selecting axis intersects point.
126   //! Also returns time of axis-point intersection.
127   Standard_EXPORT Standard_Boolean hasIntersection (const gp_Pnt& thePnt,
128                                                     Standard_Real& theDepth) const;
129
130   //! Returns true if selecting axis intersects segment.
131   //! Also saves time of axis-segment intersection and intersection point as pick result.
132   Standard_EXPORT Standard_Boolean raySegmentDistance (const gp_Pnt& theSegPnt1,
133                                                        const gp_Pnt& theSegPnt2,
134                                                        SelectBasics_PickResult& thePickResult) const;
135
136   //! Returns true if selecting axis intersects plane.
137   //! Also saves time of axis-plane intersection and intersection point as pick result.
138   Standard_EXPORT Standard_Boolean rayPlaneIntersection (const gp_Vec& thePlane,
139                                                          const gp_Pnt& thePntOnPlane,
140                                                          SelectBasics_PickResult& thePickResult) const;
141 private:
142
143   gp_Ax1 myAxis;
144
145 };
146
147 #endif // _SelectMgr_AxisIntersector_HeaderFile