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