ecffbdcc7befd6312e272c4f1d6914d3d3301145
[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
44   Init (P, Surface); 
45 }
46 //=======================================================================
47 //function : GeomAPI_ProjectPointOnSurf
48 //purpose  : 
49 //=======================================================================
50   GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt&               P, 
51                                                           const Handle(Geom_Surface)& Surface,
52                                                           const Standard_Real         Tolerance)
53
54   Init (P, Surface, Tolerance); 
55 }
56 //=======================================================================
57 //function : GeomAPI_ProjectPointOnSurf
58 //purpose  : 
59 //=======================================================================
60   GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf(const gp_Pnt&               P, 
61                                                          const Handle(Geom_Surface)& Surface,
62                                                          const Standard_Real         Umin,
63                                                          const Standard_Real         Usup,
64                                                          const Standard_Real         Vmin,
65                                                          const Standard_Real         Vsup)
66
67
68   Init (P, Surface, Umin, Usup, Vmin, Vsup); 
69 }
70 //=======================================================================
71 //function : GeomAPI_ProjectPointOnSurf
72 //purpose  : 
73 //=======================================================================
74   GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf  (const gp_Pnt&               P, 
75                                                            const Handle(Geom_Surface)& Surface,
76                                                            const Standard_Real         Umin,
77                                                            const Standard_Real         Usup,
78                                                            const Standard_Real         Vmin,
79                                                            const Standard_Real         Vsup,
80                                                            const Standard_Real         Tolerance)
81
82
83   Init (P, Surface, Umin, Usup, Vmin, Vsup, Tolerance); 
84 }
85 //=======================================================================
86 //function : Init
87 //purpose  : 
88 //=======================================================================
89   void GeomAPI_ProjectPointOnSurf::Init ()
90 {
91   myIsDone = myExtPS.IsDone() && ( myExtPS.NbExt() > 0);
92
93   if ( myIsDone) {
94     // evaluate the lower distance and its index;
95     Standard_Real Dist2, Dist2Min = myExtPS.SquareDistance(1);
96     myIndex = 1;
97     
98     for ( Standard_Integer i = 2; i <= myExtPS.NbExt(); i++) {
99       Dist2 = myExtPS.SquareDistance(i);
100       if (Dist2 < Dist2Min) {
101         Dist2Min = Dist2;
102         myIndex = i;
103       }
104     }
105   }
106 }
107 //=======================================================================
108 //function : Init
109 //purpose  : 
110 //=======================================================================
111   void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
112                                          const Handle(Geom_Surface)& Surface)
113
114
115   Init (P, Surface, Precision::Confusion()); 
116 }
117 //=======================================================================
118 //function : Init
119 //purpose  : 
120 //=======================================================================
121   void GeomAPI_ProjectPointOnSurf::Init(const gp_Pnt&               P,
122                                         const Handle(Geom_Surface)& Surface,
123                                         const Standard_Real         Tolerance)
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();
136   myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
137   myExtPS.Perform(P);
138   //XXXmyExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance);
139   //modified by NIZNHY-PKV Mon Apr  8 11:13:44 2002 t XXX
140   
141   //modified by NIZNHY-PKV Thu Apr  4 10:37:58 2002 t
142   Init ();
143 }
144
145
146 //=======================================================================
147 //function : Init
148 //purpose  : 
149 //=======================================================================
150   void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
151                                          const Handle(Geom_Surface)& Surface,
152                                          const Standard_Real         Umin,
153                                          const Standard_Real         Usup,
154                                          const Standard_Real         Vmin,
155                                          const Standard_Real         Vsup )
156 {
157   Standard_Real Tolerance = Precision::PConfusion();
158   //modified by NIZNHY-PKV Thu Apr  4 10:38:23 2002 f
159   //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
160   //myExtPS = Extrema_ExtPS (P, TheSurface, Tol, Tol);
161   myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
162   //myExtPS = Extrema_ExtPS();
163   myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
164   myExtPS.Perform(P);
165   //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tol, Tol);
166   //modified by NIZNHY-PKV Thu Apr  4 10:38:30 2002 t
167   Init ();
168 }
169
170 //=======================================================================
171 //function : Init
172 //purpose  : 
173 //=======================================================================
174   void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
175                                          const Handle(Geom_Surface)& Surface,
176                                          const Standard_Real         Umin,
177                                          const Standard_Real         Usup,
178                                          const Standard_Real         Vmin,
179                                          const Standard_Real         Vsup,
180                                          const Standard_Real         Tolerance)
181 {
182   //modified by NIZNHY-PKV Thu Apr  4 10:39:10 2002 f
183   //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
184   //myExtPS = Extrema_ExtPS (P, TheSurface, Tolerance, Tolerance);
185   myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
186   //myExtPS = Extrema_ExtPS();
187   myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
188   myExtPS.Perform(P);
189   //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance);
190   //modified by NIZNHY-PKV Thu Apr  4 10:39:14 2002 t
191   Init ();
192 }
193 //=======================================================================
194 //function : Init
195 //purpose  : 
196 //=======================================================================
197   void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface,
198                                          const Standard_Real       Umin,
199                                          const Standard_Real       Usup,
200                                          const Standard_Real       Vmin,
201                                          const Standard_Real       Vsup )
202 {
203   Standard_Real Tolerance = Precision::PConfusion();
204   //modified by NIZNHY-PKV Thu Apr  4 10:41:50 2002 f
205   //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
206   myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
207   //modified by NIZNHY-PKV Thu Apr  4 10:42:29 2002 t
208   //myExtPS = Extrema_ExtPS();
209   //modified by NIZNHY-PKV Thu Apr  4 10:42:32 2002 f
210   //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tol, Tol);
211   myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
212   //modified by NIZNHY-PKV Thu Apr  4 10:42:39 2002 t
213   myIsDone = Standard_False;
214 }
215 //=======================================================================
216 //function : Init
217 //purpose  : 
218 //=======================================================================
219   void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface,
220                                          const Standard_Real         Umin,
221                                          const Standard_Real         Usup,
222                                          const Standard_Real         Vmin,
223                                          const Standard_Real         Vsup, 
224                                          const Standard_Real         Tolerance)
225 {
226   //modified by NIZNHY-PKV Thu Apr  4 10:43:00 2002 f
227   //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
228   myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
229   //modified by NIZNHY-PKV Thu Apr  4 10:43:16 2002 t
230   //myExtPS = Extrema_ExtPS();
231   //modified by NIZNHY-PKV Thu Apr  4 10:43:18 2002 f
232   //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
233   myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
234   //modified by NIZNHY-PKV Thu Apr  4 10:43:26 2002 t
235   myIsDone = Standard_False;
236 }
237 //=======================================================================
238 //function : Perform
239 //purpose  : 
240 //=======================================================================
241   void GeomAPI_ProjectPointOnSurf::Perform(const gp_Pnt& P)
242 {
243   myExtPS.Perform(P);
244   Init ();
245 }
246 //=======================================================================
247 //function : IsDone
248 //purpose  : 
249 //=======================================================================
250   Standard_Boolean GeomAPI_ProjectPointOnSurf::IsDone () const 
251
252   return myIsDone; 
253 }
254 //=======================================================================
255 //function : NbPoints
256 //purpose  : 
257 //=======================================================================
258   Standard_Integer GeomAPI_ProjectPointOnSurf::NbPoints() const 
259 {
260   if ( myIsDone){
261     return myExtPS.NbExt();
262   }
263   else{
264     return 0;
265   }
266 }
267 //=======================================================================
268 //function : Point
269 //purpose  : 
270 //=======================================================================
271   gp_Pnt GeomAPI_ProjectPointOnSurf::Point(const Standard_Integer Index) const 
272 {
273   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
274                                "GeomAPI_ProjectPointOnSurf::Point");
275   return (myExtPS.Point(Index)).Value();
276 }
277 //=======================================================================
278 //function : Parameters
279 //purpose  : 
280 //=======================================================================
281   void GeomAPI_ProjectPointOnSurf::Parameters(const Standard_Integer Index,
282                                               Standard_Real&   U,
283                                               Standard_Real&   V) const
284 {
285   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
286                                "GeomAPI_ProjectPointOnSurf::Parameter");
287   (myExtPS.Point(Index)).Parameter(U,V);
288 }
289 //=======================================================================
290 //function : Distance
291 //purpose  : 
292 //=======================================================================
293   Standard_Real GeomAPI_ProjectPointOnSurf::Distance  (const Standard_Integer Index) const 
294 {
295   Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
296                                "GeomAPI_ProjectPointOnSurf::Distance");
297   return sqrt (myExtPS.SquareDistance(Index));
298 }
299 //=======================================================================
300 //function : NearestPoint
301 //purpose  : 
302 //=======================================================================
303   gp_Pnt GeomAPI_ProjectPointOnSurf::NearestPoint() const 
304 {
305   StdFail_NotDone_Raise_if
306     (!myIsDone, "GeomAPI_ProjectPointOnSurf::NearestPoint");
307
308   return (myExtPS.Point(myIndex)).Value();
309 }
310 //=======================================================================
311 //function : Standard_Integer
312 //purpose  : 
313 //=======================================================================
314   GeomAPI_ProjectPointOnSurf::operator Standard_Integer() const
315 {
316   return NbPoints();
317 }
318 //=======================================================================
319 //function : gp_Pnt
320 //purpose  : 
321 //=======================================================================
322   GeomAPI_ProjectPointOnSurf::operator gp_Pnt() const
323 {
324   return NearestPoint();
325 }
326 //=======================================================================
327 //function : LowerDistanceParameters
328 //purpose  : 
329 //=======================================================================
330   void GeomAPI_ProjectPointOnSurf::LowerDistanceParameters (Standard_Real& U,
331                                                             Standard_Real& V ) const
332 {
333   StdFail_NotDone_Raise_if
334     (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistanceParameters");
335
336   (myExtPS.Point(myIndex)).Parameter(U,V);
337 }
338 //=======================================================================
339 //function : LowerDistance
340 //purpose  : 
341 //=======================================================================
342   Standard_Real GeomAPI_ProjectPointOnSurf::LowerDistance() const
343 {
344   StdFail_NotDone_Raise_if
345     (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistance");
346
347   return sqrt (myExtPS.SquareDistance(myIndex));
348 }
349 //=======================================================================
350 //function : Standard_Real
351 //purpose  : 
352 //=======================================================================
353   GeomAPI_ProjectPointOnSurf::operator Standard_Real() const
354 {
355   return LowerDistance();
356 }
357
358
359
360
361
362
363
364