f751596e |
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_RectangularFrustum_HeaderFile |
17 | #define _SelectMgr_RectangularFrustum_HeaderFile |
18 | |
19 | #include <SelectMgr_Frustum.hxx> |
20 | |
21 | //! This class contains representation of rectangular selecting frustum, created in case |
22 | //! of point and box selection, and algorithms for overlap detection between selecting |
23 | //! frustum and sensitive entities. The principle of frustum calculation: |
24 | //! - for point selection: on a near view frustum plane rectangular neighborhood of |
25 | //! user-picked point is created according to the pixel tolerance |
26 | //! given and then this rectangle is projected onto far view frustum |
27 | //! plane. This rectangles define the parallel bases of selecting frustum; |
28 | //! - for box selection: box points are projected onto near and far view frustum planes. |
29 | //! These 2 projected rectangles define parallel bases of selecting frustum. |
30 | //! Overlap detection tests are implemented according to the terms of separating axis |
31 | //! theorem (SAT). |
32 | class SelectMgr_RectangularFrustum : public SelectMgr_Frustum<4> |
33 | { |
34 | public: |
35 | |
fe525c6f |
36 | SelectMgr_RectangularFrustum() : myScale (1.0) {}; |
f751596e |
37 | |
38 | //! Builds volume according to the point and given pixel tolerance |
1f3913c6 |
39 | Standard_EXPORT virtual void Build (const gp_Pnt2d& thePoint) Standard_OVERRIDE; |
f751596e |
40 | |
41 | //! Builds volume according to the selected rectangle |
1f3913c6 |
42 | Standard_EXPORT virtual void Build (const gp_Pnt2d& theMinPnt, |
43 | const gp_Pnt2d& theMaxPnt) Standard_OVERRIDE; |
f751596e |
44 | |
3bf9a45f |
45 | //! IMPORTANT: Scaling makes sense only for frustum built on a single point! |
46 | //! Note that this method does not perform any checks on type of the frustum. |
28ee613b |
47 | //! Returns a copy of the frustum resized according to the scale factor given |
3bf9a45f |
48 | //! and transforms it using the matrix given. |
49 | //! There are no default parameters, but in case if: |
50 | //! - transformation only is needed: @theScaleFactor must be initialized as any negative value; |
51 | //! - scale only is needed: @theTrsf must be set to gp_Identity. |
099f3513 |
52 | Standard_EXPORT virtual Handle(SelectMgr_BaseFrustum) ScaleAndTransform (const Standard_Integer theScaleFactor, |
53 | const gp_GTrsf& theTrsf) const Standard_OVERRIDE; |
28ee613b |
54 | |
f751596e |
55 | |
56 | // SAT Tests for different objects |
57 | |
58 | //! SAT intersection test between defined volume and given axis-aligned box |
3bf9a45f |
59 | Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin, |
60 | const SelectMgr_Vec3& theBoxMax, |
d7fa57a7 |
61 | const SelectMgr_ViewClipRange& theClipRange, |
4a056d20 |
62 | SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE; |
f751596e |
63 | |
64 | //! Returns true if selecting volume is overlapped by axis-aligned bounding box |
65 | //! with minimum corner at point theMinPt and maximum at point theMaxPt |
1f3913c6 |
66 | Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin, |
67 | const SelectMgr_Vec3& theBoxMax, |
4a056d20 |
68 | Standard_Boolean* theInside) const Standard_OVERRIDE; |
f751596e |
69 | |
70 | //! Intersection test between defined volume and given point |
1f3913c6 |
71 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt, |
d7fa57a7 |
72 | const SelectMgr_ViewClipRange& theClipRange, |
4a056d20 |
73 | SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE; |
f751596e |
74 | |
3bf9a45f |
75 | //! Intersection test between defined volume and given point |
4a056d20 |
76 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt) const Standard_OVERRIDE; |
3bf9a45f |
77 | |
f751596e |
78 | //! SAT intersection test between defined volume and given ordered set of points, |
79 | //! representing line segments. The test may be considered of interior part or |
80 | //! boundary line defined by segments depending on given sensitivity type |
114b7bf1 |
81 | Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPnts, |
1f3913c6 |
82 | Select3D_TypeOfSensitivity theSensType, |
d7fa57a7 |
83 | const SelectMgr_ViewClipRange& theClipRange, |
4a056d20 |
84 | SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE; |
f751596e |
85 | |
86 | //! Checks if line segment overlaps selecting frustum |
1f3913c6 |
87 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1, |
88 | const gp_Pnt& thePnt2, |
d7fa57a7 |
89 | const SelectMgr_ViewClipRange& theClipRange, |
4a056d20 |
90 | SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE; |
f751596e |
91 | |
92 | //! SAT intersection test between defined volume and given triangle. The test may |
93 | //! be considered of interior part or boundary line defined by triangle vertices |
94 | //! depending on given sensitivity type |
1f3913c6 |
95 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1, |
96 | const gp_Pnt& thePnt2, |
97 | const gp_Pnt& thePnt3, |
98 | Select3D_TypeOfSensitivity theSensType, |
d7fa57a7 |
99 | const SelectMgr_ViewClipRange& theClipRange, |
4a056d20 |
100 | SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE; |
f751596e |
101 | |
102 | //! Measures distance between 3d projection of user-picked |
103 | //! screen point and given point theCOG |
4a056d20 |
104 | Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const Standard_OVERRIDE; |
f751596e |
105 | |
106 | //! Calculates the point on a view ray that was detected during the run of selection algo by given depth |
3bf9a45f |
107 | Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE; |
f751596e |
108 | |
3bf9a45f |
109 | //! A set of helper functions that return rectangular selecting frustum data |
110 | inline const gp_Pnt* GetVertices() const { return myVertices; } |
111 | |
21a8e275 |
112 | //! Returns projection of 2d mouse picked point or projection |
113 | //! of center of 2d rectangle (for point and rectangular selection |
114 | //! correspondingly) onto near view frustum plane |
115 | inline const gp_Pnt& GetNearPnt() const { return myNearPickedPnt; } |
116 | |
117 | //! Returns projection of 2d mouse picked point or projection |
118 | //! of center of 2d rectangle (for point and rectangular selection |
119 | //! correspondingly) onto far view frustum plane |
120 | inline const gp_Pnt& GetFarPnt() const { return myFarPickedPnt; } |
871dcdc2 |
121 | |
d7fa57a7 |
122 | //! Return view ray direction. |
2ff1d580 |
123 | const gp_Dir& GetViewRayDirection() const { return myViewRayDir; } |
d7fa57a7 |
124 | |
b30b2c13 |
125 | //! Return mouse coordinates. |
126 | const gp_Pnt2d& GetMousePosition() const { return myMousePos; } |
127 | |
871dcdc2 |
128 | //! Stores plane equation coefficients (in the following form: |
129 | //! Ax + By + Cz + D = 0) to the given vector |
130 | Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE; |
131 | |
f751596e |
132 | protected: |
133 | |
1f3913c6 |
134 | Standard_EXPORT void segmentSegmentDistance (const gp_Pnt& theSegPnt1, |
135 | const gp_Pnt& theSegPnt2, |
4a056d20 |
136 | SelectBasics_PickResult& thePickResult) const; |
f751596e |
137 | |
17017555 |
138 | Standard_EXPORT bool segmentPlaneIntersection (const gp_Vec& thePlane, |
1f3913c6 |
139 | const gp_Pnt& thePntOnPlane, |
4a056d20 |
140 | SelectBasics_PickResult& thePickResult) const; |
f751596e |
141 | |
142 | private: |
143 | |
099f3513 |
144 | void cacheVertexProjections (SelectMgr_RectangularFrustum* theFrustum) const; |
3bf9a45f |
145 | |
146 | private: |
147 | enum { LeftTopNear, LeftTopFar, |
148 | LeftBottomNear, LeftBottomFar, |
149 | RightTopNear, RightTopFar, |
150 | RightBottomNear, RightBottomFar }; |
151 | |
152 | private: |
153 | |
e9312c0f |
154 | gp_Pnt myNearPickedPnt; //!< 3d projection of user-picked selection point onto near view plane |
155 | gp_Pnt myFarPickedPnt; //!< 3d projection of user-picked selection point onto far view plane |
2ff1d580 |
156 | gp_Dir myViewRayDir; |
e9312c0f |
157 | gp_Pnt2d myMousePos; //!< Mouse coordinates |
158 | Standard_Real myScale; //!< Scale factor of applied transformation, if there was any |
3202bf1e |
159 | |
f751596e |
160 | }; |
161 | |
162 | #endif // _SelectMgr_RectangularFrustum_HeaderFile |