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