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