b311480e |
1 | // Created on: 1994-03-17 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <GeomAPI_ProjectPointOnSurf.ixx> |
18 | |
19 | #include <GeomAdaptor_Surface.hxx> |
20 | |
21 | #include <Precision.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : GeomAPI_ProjectPointOnSurf |
25 | //purpose : |
26 | //======================================================================= |
b311480e |
27 | GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf() |
7fd59977 |
28 | : myIsDone (Standard_False) { } |
29 | |
30 | |
31 | //======================================================================= |
32 | //function : GeomAPI_ProjectPointOnSurf |
33 | //purpose : |
34 | //======================================================================= |
35 | GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt& P, |
569aff1e |
36 | const Handle(Geom_Surface)& Surface, |
37 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
38 | { |
569aff1e |
39 | Init (P, Surface, theProjAlgo); |
7fd59977 |
40 | } |
41 | //======================================================================= |
42 | //function : GeomAPI_ProjectPointOnSurf |
43 | //purpose : |
44 | //======================================================================= |
45 | GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt& P, |
46 | const Handle(Geom_Surface)& Surface, |
569aff1e |
47 | const Standard_Real Tolerance, |
48 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
49 | { |
569aff1e |
50 | Init (P, Surface, Tolerance, theProjAlgo); |
7fd59977 |
51 | } |
52 | //======================================================================= |
53 | //function : GeomAPI_ProjectPointOnSurf |
54 | //purpose : |
55 | //======================================================================= |
56 | GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf(const gp_Pnt& P, |
57 | const Handle(Geom_Surface)& Surface, |
58 | const Standard_Real Umin, |
59 | const Standard_Real Usup, |
60 | const Standard_Real Vmin, |
569aff1e |
61 | const Standard_Real Vsup, |
62 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
63 | |
64 | { |
569aff1e |
65 | Init (P, Surface, Umin, Usup, Vmin, Vsup, theProjAlgo); |
7fd59977 |
66 | } |
67 | //======================================================================= |
68 | //function : GeomAPI_ProjectPointOnSurf |
69 | //purpose : |
70 | //======================================================================= |
71 | GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt& P, |
72 | const Handle(Geom_Surface)& Surface, |
73 | const Standard_Real Umin, |
74 | const Standard_Real Usup, |
75 | const Standard_Real Vmin, |
76 | const Standard_Real Vsup, |
569aff1e |
77 | const Standard_Real Tolerance, |
78 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
79 | |
80 | { |
569aff1e |
81 | Init (P, Surface, Umin, Usup, Vmin, Vsup, Tolerance, theProjAlgo); |
7fd59977 |
82 | } |
83 | //======================================================================= |
84 | //function : Init |
85 | //purpose : |
86 | //======================================================================= |
87 | void GeomAPI_ProjectPointOnSurf::Init () |
88 | { |
89 | myIsDone = myExtPS.IsDone() && ( myExtPS.NbExt() > 0); |
90 | |
91 | if ( myIsDone) { |
92 | // evaluate the lower distance and its index; |
93 | Standard_Real Dist2, Dist2Min = myExtPS.SquareDistance(1); |
94 | myIndex = 1; |
95 | |
96 | for ( Standard_Integer i = 2; i <= myExtPS.NbExt(); i++) { |
97 | Dist2 = myExtPS.SquareDistance(i); |
98 | if (Dist2 < Dist2Min) { |
99 | Dist2Min = Dist2; |
100 | myIndex = i; |
101 | } |
102 | } |
103 | } |
104 | } |
105 | //======================================================================= |
106 | //function : Init |
107 | //purpose : |
108 | //======================================================================= |
109 | void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt& P, |
569aff1e |
110 | const Handle(Geom_Surface)& Surface, |
111 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
112 | |
113 | { |
569aff1e |
114 | Init (P, Surface, Precision::Confusion(), theProjAlgo); |
7fd59977 |
115 | } |
116 | //======================================================================= |
117 | //function : Init |
118 | //purpose : |
119 | //======================================================================= |
120 | void GeomAPI_ProjectPointOnSurf::Init(const gp_Pnt& P, |
121 | const Handle(Geom_Surface)& Surface, |
569aff1e |
122 | const Standard_Real Tolerance, |
123 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
124 | |
125 | { |
126 | //modified by NIZNHY-PKV Thu Apr 4 10:37:55 2002 f |
127 | //GeomAdaptor_Surface TheSurface (Surface); |
128 | //myExtPS = Extrema_ExtPS (P, TheSurface, Tolerance, Tolerance); |
129 | |
130 | //modified by NIZNHY-PKV Mon Apr 8 11:13:37 2002 f XXX |
131 | Standard_Real Umin, Usup, Vmin, Vsup; |
132 | Surface->Bounds(Umin, Usup, Vmin, Vsup); |
133 | myGeomAdaptor.Load(Surface, Umin, Usup, Vmin, Vsup); |
134 | // |
135 | //myExtPS = Extrema_ExtPS(); |
569aff1e |
136 | myExtPS.SetAlgo(theProjAlgo); |
7fd59977 |
137 | myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
138 | myExtPS.Perform(P); |
139 | //XXXmyExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance); |
140 | //modified by NIZNHY-PKV Mon Apr 8 11:13:44 2002 t XXX |
141 | |
142 | //modified by NIZNHY-PKV Thu Apr 4 10:37:58 2002 t |
143 | Init (); |
144 | } |
145 | |
146 | |
147 | //======================================================================= |
148 | //function : Init |
149 | //purpose : |
150 | //======================================================================= |
151 | void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt& P, |
152 | const Handle(Geom_Surface)& Surface, |
153 | const Standard_Real Umin, |
154 | const Standard_Real Usup, |
155 | const Standard_Real Vmin, |
569aff1e |
156 | const Standard_Real Vsup, |
157 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
158 | { |
159 | Standard_Real Tolerance = Precision::PConfusion(); |
160 | //modified by NIZNHY-PKV Thu Apr 4 10:38:23 2002 f |
161 | //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup); |
162 | //myExtPS = Extrema_ExtPS (P, TheSurface, Tol, Tol); |
163 | myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup); |
164 | //myExtPS = Extrema_ExtPS(); |
569aff1e |
165 | myExtPS.SetAlgo(theProjAlgo); |
7fd59977 |
166 | myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
167 | myExtPS.Perform(P); |
168 | //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tol, Tol); |
169 | //modified by NIZNHY-PKV Thu Apr 4 10:38:30 2002 t |
170 | Init (); |
171 | } |
172 | |
173 | //======================================================================= |
174 | //function : Init |
175 | //purpose : |
176 | //======================================================================= |
177 | void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt& P, |
178 | const Handle(Geom_Surface)& Surface, |
179 | const Standard_Real Umin, |
180 | const Standard_Real Usup, |
181 | const Standard_Real Vmin, |
182 | const Standard_Real Vsup, |
569aff1e |
183 | const Standard_Real Tolerance, |
184 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
185 | { |
186 | //modified by NIZNHY-PKV Thu Apr 4 10:39:10 2002 f |
187 | //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup); |
188 | //myExtPS = Extrema_ExtPS (P, TheSurface, Tolerance, Tolerance); |
189 | myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup); |
190 | //myExtPS = Extrema_ExtPS(); |
569aff1e |
191 | myExtPS.SetAlgo(theProjAlgo); |
7fd59977 |
192 | myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
193 | myExtPS.Perform(P); |
194 | //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance); |
195 | //modified by NIZNHY-PKV Thu Apr 4 10:39:14 2002 t |
196 | Init (); |
197 | } |
198 | //======================================================================= |
199 | //function : Init |
200 | //purpose : |
201 | //======================================================================= |
202 | void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface, |
203 | const Standard_Real Umin, |
204 | const Standard_Real Usup, |
205 | const Standard_Real Vmin, |
569aff1e |
206 | const Standard_Real Vsup, |
207 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
208 | { |
209 | Standard_Real Tolerance = Precision::PConfusion(); |
210 | //modified by NIZNHY-PKV Thu Apr 4 10:41:50 2002 f |
211 | //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup); |
212 | myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup); |
213 | //modified by NIZNHY-PKV Thu Apr 4 10:42:29 2002 t |
214 | //myExtPS = Extrema_ExtPS(); |
215 | //modified by NIZNHY-PKV Thu Apr 4 10:42:32 2002 f |
216 | //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tol, Tol); |
569aff1e |
217 | myExtPS.SetAlgo(theProjAlgo); |
7fd59977 |
218 | myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
219 | //modified by NIZNHY-PKV Thu Apr 4 10:42:39 2002 t |
220 | myIsDone = Standard_False; |
221 | } |
222 | //======================================================================= |
223 | //function : Init |
224 | //purpose : |
225 | //======================================================================= |
226 | void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface, |
227 | const Standard_Real Umin, |
228 | const Standard_Real Usup, |
229 | const Standard_Real Vmin, |
230 | const Standard_Real Vsup, |
569aff1e |
231 | const Standard_Real Tolerance, |
232 | const Extrema_ExtAlgo theProjAlgo) |
7fd59977 |
233 | { |
234 | //modified by NIZNHY-PKV Thu Apr 4 10:43:00 2002 f |
235 | //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup); |
236 | myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup); |
237 | //modified by NIZNHY-PKV Thu Apr 4 10:43:16 2002 t |
238 | //myExtPS = Extrema_ExtPS(); |
239 | //modified by NIZNHY-PKV Thu Apr 4 10:43:18 2002 f |
240 | //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
569aff1e |
241 | myExtPS.SetAlgo(theProjAlgo); |
7fd59977 |
242 | myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance); |
243 | //modified by NIZNHY-PKV Thu Apr 4 10:43:26 2002 t |
244 | myIsDone = Standard_False; |
245 | } |
246 | //======================================================================= |
247 | //function : Perform |
248 | //purpose : |
249 | //======================================================================= |
250 | void GeomAPI_ProjectPointOnSurf::Perform(const gp_Pnt& P) |
251 | { |
252 | myExtPS.Perform(P); |
253 | Init (); |
254 | } |
255 | //======================================================================= |
256 | //function : IsDone |
257 | //purpose : |
258 | //======================================================================= |
259 | Standard_Boolean GeomAPI_ProjectPointOnSurf::IsDone () const |
260 | { |
261 | return myIsDone; |
262 | } |
263 | //======================================================================= |
264 | //function : NbPoints |
265 | //purpose : |
266 | //======================================================================= |
267 | Standard_Integer GeomAPI_ProjectPointOnSurf::NbPoints() const |
268 | { |
269 | if ( myIsDone){ |
270 | return myExtPS.NbExt(); |
271 | } |
272 | else{ |
273 | return 0; |
274 | } |
275 | } |
276 | //======================================================================= |
277 | //function : Point |
278 | //purpose : |
279 | //======================================================================= |
280 | gp_Pnt GeomAPI_ProjectPointOnSurf::Point(const Standard_Integer Index) const |
281 | { |
282 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
283 | "GeomAPI_ProjectPointOnSurf::Point"); |
284 | return (myExtPS.Point(Index)).Value(); |
285 | } |
286 | //======================================================================= |
287 | //function : Parameters |
288 | //purpose : |
289 | //======================================================================= |
290 | void GeomAPI_ProjectPointOnSurf::Parameters(const Standard_Integer Index, |
291 | Standard_Real& U, |
292 | Standard_Real& V) const |
293 | { |
294 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
295 | "GeomAPI_ProjectPointOnSurf::Parameter"); |
296 | (myExtPS.Point(Index)).Parameter(U,V); |
297 | } |
298 | //======================================================================= |
299 | //function : Distance |
300 | //purpose : |
301 | //======================================================================= |
302 | Standard_Real GeomAPI_ProjectPointOnSurf::Distance (const Standard_Integer Index) const |
303 | { |
304 | Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(), |
305 | "GeomAPI_ProjectPointOnSurf::Distance"); |
306 | return sqrt (myExtPS.SquareDistance(Index)); |
307 | } |
308 | //======================================================================= |
309 | //function : NearestPoint |
310 | //purpose : |
311 | //======================================================================= |
312 | gp_Pnt GeomAPI_ProjectPointOnSurf::NearestPoint() const |
313 | { |
314 | StdFail_NotDone_Raise_if |
315 | (!myIsDone, "GeomAPI_ProjectPointOnSurf::NearestPoint"); |
316 | |
317 | return (myExtPS.Point(myIndex)).Value(); |
318 | } |
319 | //======================================================================= |
320 | //function : Standard_Integer |
321 | //purpose : |
322 | //======================================================================= |
323 | GeomAPI_ProjectPointOnSurf::operator Standard_Integer() const |
324 | { |
325 | return NbPoints(); |
326 | } |
327 | //======================================================================= |
328 | //function : gp_Pnt |
329 | //purpose : |
330 | //======================================================================= |
331 | GeomAPI_ProjectPointOnSurf::operator gp_Pnt() const |
332 | { |
333 | return NearestPoint(); |
334 | } |
335 | //======================================================================= |
336 | //function : LowerDistanceParameters |
337 | //purpose : |
338 | //======================================================================= |
339 | void GeomAPI_ProjectPointOnSurf::LowerDistanceParameters (Standard_Real& U, |
340 | Standard_Real& V ) const |
341 | { |
342 | StdFail_NotDone_Raise_if |
343 | (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistanceParameters"); |
344 | |
345 | (myExtPS.Point(myIndex)).Parameter(U,V); |
346 | } |
347 | //======================================================================= |
348 | //function : LowerDistance |
349 | //purpose : |
350 | //======================================================================= |
351 | Standard_Real GeomAPI_ProjectPointOnSurf::LowerDistance() const |
352 | { |
353 | StdFail_NotDone_Raise_if |
354 | (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistance"); |
355 | |
356 | return sqrt (myExtPS.SquareDistance(myIndex)); |
357 | } |
358 | //======================================================================= |
359 | //function : Standard_Real |
360 | //purpose : |
361 | //======================================================================= |
362 | GeomAPI_ProjectPointOnSurf::operator Standard_Real() const |
363 | { |
364 | return LowerDistance(); |
365 | } |
366 | |
367 | |
368 | |
369 | |
370 | |
371 | |
372 | |
373 | |