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_BaseFrustum_HeaderFile |
17 | #define _SelectMgr_BaseFrustum_HeaderFile |
18 | |
f751596e |
19 | #include <gp_Pnt.hxx> |
20 | #include <gp_Pln.hxx> |
21 | |
22 | #include <Graphic3d_Camera.hxx> |
23 | #include <Graphic3d_ClipPlane.hxx> |
24 | #include <Graphic3d_SequenceOfHClipPlane.hxx> |
825aa485 |
25 | #include <Graphic3d_WorldViewProjState.hxx> |
f751596e |
26 | |
f751596e |
27 | #include <TColgp_HArray1OfPnt.hxx> |
28 | #include <TColgp_Array1OfPnt2d.hxx> |
29 | |
30 | #include <Select3D_BndBox3d.hxx> |
31 | #include <SelectMgr_FrustumBuilder.hxx> |
32 | #include <Select3D_TypeOfSensitivity.hxx> |
33 | #include <SelectMgr_VectorTypes.hxx> |
34 | |
35 | //! This class is an interface for different types of selecting frustums, |
36 | //! defining different selection types, like point, box or polyline |
37 | //! selection. It contains signatures of functions for detection of |
38 | //! overlap by sensitive entity and initializes some data for building |
39 | //! the selecting frustum |
c04c30b3 |
40 | class SelectMgr_BaseFrustum : public Standard_Transient |
f751596e |
41 | { |
42 | public: |
43 | |
44 | //! Creates new selecting volume with pixel toletance set to 2, |
45 | //! orthographic camera and empty frustum builder |
1f3913c6 |
46 | Standard_EXPORT SelectMgr_BaseFrustum(); |
f751596e |
47 | |
bf3977c9 |
48 | virtual ~SelectMgr_BaseFrustum() {} |
f751596e |
49 | |
50 | //! Passes camera projection and orientation matrices to builder |
1f3913c6 |
51 | Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera); |
f751596e |
52 | |
53 | //! Passes camera projection and orientation matrices to builder |
1f3913c6 |
54 | Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection, |
55 | const Graphic3d_Mat4d& theWorldView, |
56 | const Standard_Integer theIsOrthographic, |
57 | const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState()); |
825aa485 |
58 | |
59 | //! @return current camera projection transformation common for all selecting volumes |
1f3913c6 |
60 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const; |
825aa485 |
61 | |
62 | //! @return current camera world view transformation common for all selecting volumes |
1f3913c6 |
63 | Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const; |
825aa485 |
64 | |
65 | //! @return current camera world view projection transformation state |
1f3913c6 |
66 | Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const; |
f751596e |
67 | |
3bf9a45f |
68 | Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTol); |
f751596e |
69 | |
1f3913c6 |
70 | Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, |
71 | const Standard_Integer theHeight); |
f751596e |
72 | |
73 | //! Passes viewport parameters to builder |
1f3913c6 |
74 | Standard_EXPORT void SetViewport (const Standard_Real theX, |
75 | const Standard_Real theY, |
76 | const Standard_Real theWidth, |
77 | const Standard_Real theHeight); |
f751596e |
78 | |
79 | //! Nullifies the builder created in the constructor and copies the pointer given |
1f3913c6 |
80 | Standard_EXPORT void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder); |
f751596e |
81 | |
82 | |
83 | //! Builds volume according to the point and given pixel tolerance |
bf3977c9 |
84 | virtual void Build (const gp_Pnt2d& /*thePoint*/) {} |
f751596e |
85 | |
86 | //! Builds volume according to the selected rectangle |
87 | virtual void Build (const gp_Pnt2d& /*theMinPt*/, |
bf3977c9 |
88 | const gp_Pnt2d& /*theMaxPt*/) {} |
f751596e |
89 | |
90 | //! Builds volume according to the triangle given |
91 | virtual void Build (const gp_Pnt2d& /*theP1*/, |
92 | const gp_Pnt2d& /*theP2*/, |
bf3977c9 |
93 | const gp_Pnt2d& /*theP3*/) {} |
f751596e |
94 | |
95 | //! Builds selecting volumes set according to polyline points |
bf3977c9 |
96 | virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {} |
f751596e |
97 | |
3bf9a45f |
98 | //! IMPORTANT: Scaling makes sense only for frustum built on a single point! |
99 | //! Note that this method does not perform any checks on type of the frustum. |
28ee613b |
100 | //! Returns a copy of the frustum resized according to the scale factor given |
3bf9a45f |
101 | //! and transforms it using the matrix given. |
102 | //! There are no default parameters, but in case if: |
103 | //! - transformation only is needed: @theScaleFactor must be initialized as any negative value; |
104 | //! - scale only is needed: @theTrsf must be set to gp_Identity. |
be5c3602 |
105 | virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer /*theScaleFactor*/, |
106 | const gp_Trsf& /*theTrsf*/) { return NULL; } |
28ee613b |
107 | |
f751596e |
108 | //! SAT intersection test between defined volume and given axis-aligned box |
3bf9a45f |
109 | Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin, |
110 | const SelectMgr_Vec3& theBoxMax, |
1f3913c6 |
111 | Standard_Real& theDepth); |
f751596e |
112 | |
113 | //! Returns true if selecting volume is overlapped by axis-aligned bounding box |
114 | //! with minimum corner at point theMinPt and maximum at point theMaxPt |
1f3913c6 |
115 | Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin, |
116 | const SelectMgr_Vec3& theBoxMax, |
117 | Standard_Boolean* theInside = NULL); |
f751596e |
118 | |
119 | //! Intersection test between defined volume and given point |
3bf9a45f |
120 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt, |
1f3913c6 |
121 | Standard_Real& theDepth); |
f751596e |
122 | |
3bf9a45f |
123 | //! Intersection test between defined volume and given point |
124 | //! Does not perform depth calculation, so this method is defined as |
125 | //! helper function for inclusion test. Therefore, its implementation |
126 | //! makes sense only for rectangular frustum with box selection mode activated. |
127 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt); |
128 | |
f751596e |
129 | //! SAT intersection test between defined volume and given ordered set of points, |
130 | //! representing line segments. The test may be considered of interior part or |
131 | //! boundary line defined by segments depending on given sensitivity type |
114b7bf1 |
132 | Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPnts, |
1f3913c6 |
133 | Select3D_TypeOfSensitivity theSensType, |
134 | Standard_Real& theDepth); |
f751596e |
135 | |
136 | //! Checks if line segment overlaps selecting frustum |
3bf9a45f |
137 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1, |
138 | const gp_Pnt& thePnt2, |
1f3913c6 |
139 | Standard_Real& theDepth); |
f751596e |
140 | |
141 | //! SAT intersection test between defined volume and given triangle. The test may |
142 | //! be considered of interior part or boundary line defined by triangle vertices |
143 | //! depending on given sensitivity type |
1f3913c6 |
144 | Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1, |
145 | const gp_Pnt& thePt2, |
146 | const gp_Pnt& thePt3, |
147 | Select3D_TypeOfSensitivity theSensType, |
148 | Standard_Real& theDepth); |
f751596e |
149 | |
150 | //! Measures distance between 3d projection of user-picked |
151 | //! screen point and given point theCOG |
1f3913c6 |
152 | Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG); |
f751596e |
153 | |
3bf9a45f |
154 | Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const; |
f751596e |
155 | |
156 | //! Checks if the point of sensitive in which selection was detected belongs |
157 | //! to the region defined by clipping planes |
1f3913c6 |
158 | Standard_EXPORT virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes, |
159 | const Standard_Real theDepth); |
f751596e |
160 | |
e9312c0f |
161 | //! Valid for point selection only! |
162 | //! Computes depth range for global (defined for the whole view) clipping planes. |
be5c3602 |
163 | virtual void SetViewClipping (const Graphic3d_SequenceOfHClipPlane& /*thePlanes*/) {}; |
e9312c0f |
164 | |
92efcf78 |
165 | DEFINE_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient) |
c04c30b3 |
166 | |
f751596e |
167 | protected: |
3bf9a45f |
168 | Standard_Integer myPixelTolerance; //!< Pixel tolerance |
169 | Standard_Boolean myIsOrthographic; //!< Defines if current camera is orthographic |
f751596e |
170 | |
bf3977c9 |
171 | Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build |
f751596e |
172 | }; |
173 | |
174 | #endif // _SelectMgr_BaseFrustum_HeaderFile |