88ac8d7a5daa63e4c83e5f998b63f7e5e1c871ab
[occt.git] / src / SelectMgr / SelectMgr_BaseFrustum.cxx
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 #include <SelectMgr_BaseFrustum.hxx>
17
18 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient)
19
20 //=======================================================================
21 // function : SelectMgr_SelectingVolume
22 // purpose  : Creates new selecting volume with pixel toletance set to 2,
23 //            orthographic camera and empty frustum builder
24 //=======================================================================
25 SelectMgr_BaseFrustum::SelectMgr_BaseFrustum()
26 : myPixelTolerance (2),
27   myIsOrthographic (Standard_True)
28 {
29   myBuilder = new SelectMgr_FrustumBuilder();
30 }
31
32 //=======================================================================
33 // function : SetCamera
34 // purpose  : Passes camera projection and orientation matrices to builder
35 //=======================================================================
36 void SelectMgr_BaseFrustum::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
37 {
38   myBuilder->SetWorldViewMatrix (theCamera->OrientationMatrix());
39   myBuilder->SetProjectionMatrix (theCamera->ProjectionMatrix());
40   myBuilder->SetWorldViewProjState (theCamera->WorldViewProjState());
41   myIsOrthographic = theCamera->IsOrthographic();
42   myBuilder->InvalidateViewport();
43 }
44
45 //=======================================================================
46 // function : SetCamera
47 // purpose  : Passes camera projection and orientation matrices to builder
48 //=======================================================================
49 void SelectMgr_BaseFrustum::SetCamera (const Graphic3d_Mat4d& theProjection,
50                                        const Graphic3d_Mat4d& theWorldView,
51                                        const Standard_Integer theIsOrthographic,
52                                        const Graphic3d_WorldViewProjState& theWVPState)
53 {
54   myBuilder->SetWorldViewMatrix (theWorldView);
55   myBuilder->SetProjectionMatrix (theProjection);
56   myBuilder->SetWorldViewProjState (theWVPState);
57   myIsOrthographic = theIsOrthographic;
58 }
59
60 //=======================================================================
61 // function : ProjectionMatrix
62 // purpose  : Returns current camera projection transformation common for
63 //            all selecting volumes
64 //=======================================================================
65 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::ProjectionMatrix() const
66 {
67   return myBuilder->ProjectionMatrix();
68 }
69
70 //=======================================================================
71 // function : WorldViewMatrix
72 // purpose  : Returns current camera world view transformation common for
73 //            all selecting volumes
74 //=======================================================================
75 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::WorldViewMatrix() const
76 {
77   return myBuilder->WorldViewMatrix();
78 }
79
80 //=======================================================================
81 // function : WorldViewProjState
82 // purpose  : Returns current camera world view projection transformation
83 //            state
84 //=======================================================================
85 const Graphic3d_WorldViewProjState& SelectMgr_BaseFrustum::WorldViewProjState() const
86 {
87   return myBuilder->WorldViewProjState();
88 }
89
90 //=======================================================================
91 // function : SetViewport
92 // purpose  : Passes viewport parameters to builder
93 //=======================================================================
94 void SelectMgr_BaseFrustum::SetViewport (const Standard_Real theX,
95                                          const Standard_Real theY,
96                                          const Standard_Real theWidth,
97                                          const Standard_Real theHeight)
98 {
99   myBuilder->SetViewport (theX, theY, theWidth, theHeight);
100 }
101
102 //=======================================================================
103 // function : SetPixelTolerance
104 // purpose  :
105 //=======================================================================
106 void SelectMgr_BaseFrustum::SetPixelTolerance (const Standard_Integer theTol)
107 {
108   myPixelTolerance = theTol;
109 }
110
111 //=======================================================================
112 // function : SetWindowSize
113 // purpose  :
114 //=======================================================================
115 void SelectMgr_BaseFrustum::SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight)
116 {
117   myBuilder->SetWindowSize (theWidth, theHeight);
118 }
119
120 //=======================================================================
121 // function : SetBuilder
122 // purpose  :
123 //=======================================================================
124 void SelectMgr_BaseFrustum::SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder)
125 {
126   myBuilder.Nullify();
127   myBuilder = theBuilder;
128 }
129
130 //=======================================================================
131 // function : Overlaps
132 // purpose  : SAT intersection test between defined volume and
133 //            given axis-aligned box
134 //=======================================================================
135 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const SelectMgr_Vec3& /*theBoxMin*/,
136                                                   const SelectMgr_Vec3& /*theBoxMax*/,
137                                                   Standard_Real& /*theDepth*/)
138 {
139   return Standard_False;
140 }
141
142 //=======================================================================
143 // function : Overlaps
144 // purpose  : Intersection test between defined volume and given point
145 //=======================================================================
146 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const SelectMgr_Vec3& /*theBoxMin*/,
147                                                   const SelectMgr_Vec3& /*theBoxMax*/,
148                                                   Standard_Boolean*     /*theInside*/)
149 {
150   return Standard_False;
151 }
152
153 //=======================================================================
154 // function : Overlaps
155 // purpose  : Intersection test between defined volume and given point
156 //=======================================================================
157 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt*/,
158                                                   Standard_Real& /*theDepth*/)
159 {
160   return Standard_False;
161 }
162
163 //=======================================================================
164 // function : Overlaps
165 // purpose  : Intersection test between defined volume and given point
166 //=======================================================================
167 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt*/)
168 {
169   return Standard_False;
170 }
171
172 //=======================================================================
173 // function : Overlaps
174 // purpose  : SAT intersection test between defined volume and given
175 //            ordered set of points, representing line segments. The test
176 //            may be considered of interior part or boundary line defined
177 //            by segments depending on given sensitivity type
178 //=======================================================================
179 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const Handle(TColgp_HArray1OfPnt)& /*theArrayOfPnts*/,
180                                                   Select3D_TypeOfSensitivity /*theSensType*/,
181                                                   Standard_Real& /*theDepth*/)
182 {
183   return Standard_False;
184 }
185
186 //=======================================================================
187 // function : Overlaps
188 // purpose  : SAT intersection test between defined volume and given
189 //            triangle. The test may be considered of interior part or
190 //            boundary line defined by triangle vertices depending on
191 //            given sensitivity type
192 //=======================================================================
193 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePt1*/,
194                                                   const gp_Pnt& /*thePt2*/,
195                                                   const gp_Pnt& /*thePt3*/,
196                                                   Select3D_TypeOfSensitivity /*theSensType*/,
197                                                   Standard_Real& /*theDepth*/)
198 {
199   return Standard_False;
200 }
201
202 //=======================================================================
203 // function : Overlaps
204 // purpose  : Checks if line segment overlaps selecting volume
205 //=======================================================================
206 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt1*/,
207                                                   const gp_Pnt& /*thePnt2*/,
208                                                   Standard_Real& /*theDepth*/)
209 {
210   return Standard_False;
211 }
212
213 //=======================================================================
214 // function : DistToGeometryCenter
215 // purpose  : Measures distance between 3d projection of user-picked
216 //            screen point and given point theCOG
217 //=======================================================================
218 Standard_Real SelectMgr_BaseFrustum::DistToGeometryCenter (const gp_Pnt& /*theCOG*/)
219 {
220   return DBL_MAX;
221 }
222
223 gp_Pnt SelectMgr_BaseFrustum::DetectedPoint (const Standard_Real /*theDepth*/) const
224 {
225   return gp_Pnt (RealLast(), RealLast(), RealLast());
226 }
227
228 //=======================================================================
229 // function : IsClipped
230 // purpose  : Checks if the point of sensitive in which selection was
231 //            detected belongs to the region defined by clipping planes
232 //=======================================================================
233 Standard_Boolean SelectMgr_BaseFrustum::IsClipped (const Graphic3d_SequenceOfHClipPlane& /*thePlanes*/,
234                                                    const Standard_Real /*theDepth*/)
235 {
236   return Standard_True;
237 }