summaryrefslogtreecommitdiff
path: root/src/GeomAPI/GeomAPI_ProjectPointOnSurf.cxx
blob: 7276230fdf03cea638f638327f12cf8039132587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
// File:	GeomAPI_ProjectPointOnSurf.cxx
// Created:	Thu Mar 17 16:00:37 1994
// Author:	Bruno DUMORTIER


#include <GeomAPI_ProjectPointOnSurf.ixx>

#include <GeomAdaptor_Surface.hxx>

#include <Precision.hxx>

//=======================================================================
//function : GeomAPI_ProjectPointOnSurf
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf() 
: myIsDone (Standard_False) { }


//=======================================================================
//function : GeomAPI_ProjectPointOnSurf
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt&               P, 
							  const Handle(Geom_Surface)& Surface)
{ 
  Init (P, Surface); 
}
//=======================================================================
//function : GeomAPI_ProjectPointOnSurf
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf (const gp_Pnt&               P, 
							  const Handle(Geom_Surface)& Surface,
							  const Standard_Real         Tolerance)
{ 
  Init (P, Surface, Tolerance); 
}
//=======================================================================
//function : GeomAPI_ProjectPointOnSurf
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf(const gp_Pnt&               P, 
							 const Handle(Geom_Surface)& Surface,
							 const Standard_Real         Umin,
							 const Standard_Real         Usup,
							 const Standard_Real         Vmin,
							 const Standard_Real         Vsup)

{ 
  Init (P, Surface, Umin, Usup, Vmin, Vsup); 
}
//=======================================================================
//function : GeomAPI_ProjectPointOnSurf
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::GeomAPI_ProjectPointOnSurf  (const gp_Pnt&               P, 
							   const Handle(Geom_Surface)& Surface,
							   const Standard_Real         Umin,
							   const Standard_Real         Usup,
							   const Standard_Real         Vmin,
							   const Standard_Real         Vsup,
							   const Standard_Real         Tolerance)

{ 
  Init (P, Surface, Umin, Usup, Vmin, Vsup, Tolerance); 
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init ()
{
  myIsDone = myExtPS.IsDone() && ( myExtPS.NbExt() > 0);

  if ( myIsDone) {
    // evaluate the lower distance and its index;
    Standard_Real Dist2, Dist2Min = myExtPS.SquareDistance(1);
    myIndex = 1;
    
    for ( Standard_Integer i = 2; i <= myExtPS.NbExt(); i++) {
      Dist2 = myExtPS.SquareDistance(i);
      if (Dist2 < Dist2Min) {
	Dist2Min = Dist2;
	myIndex = i;
      }
    }
  }
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
					 const Handle(Geom_Surface)& Surface)

{ 
  Init (P, Surface, Precision::Confusion()); 
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init(const gp_Pnt&               P,
					const Handle(Geom_Surface)& Surface,
					const Standard_Real         Tolerance)

{
  //modified by NIZNHY-PKV Thu Apr  4 10:37:55 2002 f
  //GeomAdaptor_Surface TheSurface (Surface);
  //myExtPS = Extrema_ExtPS (P, TheSurface, Tolerance, Tolerance);
  
  //modified by NIZNHY-PKV Mon Apr  8 11:13:37 2002 f XXX
  Standard_Real Umin, Usup, Vmin, Vsup;
  Surface->Bounds(Umin, Usup, Vmin, Vsup);
  myGeomAdaptor.Load(Surface, Umin, Usup, Vmin, Vsup);
  //
  //myExtPS = Extrema_ExtPS();
  myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  myExtPS.Perform(P);
  //XXXmyExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance);
  //modified by NIZNHY-PKV Mon Apr  8 11:13:44 2002 t XXX
  
  //modified by NIZNHY-PKV Thu Apr  4 10:37:58 2002 t
  Init ();
}


//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
					 const Handle(Geom_Surface)& Surface,
					 const Standard_Real         Umin,
					 const Standard_Real         Usup,
					 const Standard_Real         Vmin,
					 const Standard_Real         Vsup )
{
  Standard_Real Tolerance = Precision::PConfusion();
  //modified by NIZNHY-PKV Thu Apr  4 10:38:23 2002 f
  //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
  //myExtPS = Extrema_ExtPS (P, TheSurface, Tol, Tol);
  myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
  //myExtPS = Extrema_ExtPS();
  myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  myExtPS.Perform(P);
  //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tol, Tol);
  //modified by NIZNHY-PKV Thu Apr  4 10:38:30 2002 t
  Init ();
}

//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init (const gp_Pnt&               P,
					 const Handle(Geom_Surface)& Surface,
					 const Standard_Real         Umin,
					 const Standard_Real         Usup,
					 const Standard_Real         Vmin,
					 const Standard_Real         Vsup,
					 const Standard_Real         Tolerance)
{
  //modified by NIZNHY-PKV Thu Apr  4 10:39:10 2002 f
  //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
  //myExtPS = Extrema_ExtPS (P, TheSurface, Tolerance, Tolerance);
  myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
  //myExtPS = Extrema_ExtPS();
  myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  myExtPS.Perform(P);
  //XXX myExtPS = Extrema_ExtPS (P, myGeomAdaptor, Tolerance, Tolerance);
  //modified by NIZNHY-PKV Thu Apr  4 10:39:14 2002 t
  Init ();
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface,
					 const Standard_Real       Umin,
					 const Standard_Real       Usup,
					 const Standard_Real       Vmin,
					 const Standard_Real       Vsup )
{
  Standard_Real Tolerance = Precision::PConfusion();
  //modified by NIZNHY-PKV Thu Apr  4 10:41:50 2002 f
  //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
  myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
  //modified by NIZNHY-PKV Thu Apr  4 10:42:29 2002 t
  //myExtPS = Extrema_ExtPS();
  //modified by NIZNHY-PKV Thu Apr  4 10:42:32 2002 f
  //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tol, Tol);
  myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  //modified by NIZNHY-PKV Thu Apr  4 10:42:39 2002 t
  myIsDone = Standard_False;
}
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Init (const Handle(Geom_Surface)& Surface,
					 const Standard_Real         Umin,
					 const Standard_Real         Usup,
					 const Standard_Real         Vmin,
					 const Standard_Real         Vsup, 
					 const Standard_Real         Tolerance)
{
  //modified by NIZNHY-PKV Thu Apr  4 10:43:00 2002 f
  //GeomAdaptor_Surface TheSurface (Surface,Umin,Usup,Vmin,Vsup);
  myGeomAdaptor.Load(Surface, Umin,Usup,Vmin,Vsup);
  //modified by NIZNHY-PKV Thu Apr  4 10:43:16 2002 t
  //myExtPS = Extrema_ExtPS();
  //modified by NIZNHY-PKV Thu Apr  4 10:43:18 2002 f
  //myExtPS.Initialize(TheSurface, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  myExtPS.Initialize(myGeomAdaptor, Umin, Usup, Vmin, Vsup, Tolerance, Tolerance);
  //modified by NIZNHY-PKV Thu Apr  4 10:43:26 2002 t
  myIsDone = Standard_False;
}
//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Perform(const gp_Pnt& P)
{
  myExtPS.Perform(P);
  Init ();
}
//=======================================================================
//function : IsDone
//purpose  : 
//=======================================================================
  Standard_Boolean GeomAPI_ProjectPointOnSurf::IsDone () const 
{ 
  return myIsDone; 
}
//=======================================================================
//function : NbPoints
//purpose  : 
//=======================================================================
  Standard_Integer GeomAPI_ProjectPointOnSurf::NbPoints() const 
{
  if ( myIsDone){
    return myExtPS.NbExt();
  }
  else{
    return 0;
  }
}
//=======================================================================
//function : Point
//purpose  : 
//=======================================================================
  gp_Pnt GeomAPI_ProjectPointOnSurf::Point(const Standard_Integer Index) const 
{
  Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
			       "GeomAPI_ProjectPointOnSurf::Point");
  return (myExtPS.Point(Index)).Value();
}
//=======================================================================
//function : Parameters
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::Parameters(const Standard_Integer Index,
					      Standard_Real&   U,
					      Standard_Real&   V) const
{
  Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
			       "GeomAPI_ProjectPointOnSurf::Parameter");
  (myExtPS.Point(Index)).Parameter(U,V);
}
//=======================================================================
//function : Distance
//purpose  : 
//=======================================================================
  Standard_Real GeomAPI_ProjectPointOnSurf::Distance  (const Standard_Integer Index) const 
{
  Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
			       "GeomAPI_ProjectPointOnSurf::Distance");
  return sqrt (myExtPS.SquareDistance(Index));
}
//=======================================================================
//function : NearestPoint
//purpose  : 
//=======================================================================
  gp_Pnt GeomAPI_ProjectPointOnSurf::NearestPoint() const 
{
  StdFail_NotDone_Raise_if
    (!myIsDone, "GeomAPI_ProjectPointOnSurf::NearestPoint");

  return (myExtPS.Point(myIndex)).Value();
}
//=======================================================================
//function : Standard_Integer
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::operator Standard_Integer() const
{
  return NbPoints();
}
//=======================================================================
//function : gp_Pnt
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::operator gp_Pnt() const
{
  return NearestPoint();
}
//=======================================================================
//function : LowerDistanceParameters
//purpose  : 
//=======================================================================
  void GeomAPI_ProjectPointOnSurf::LowerDistanceParameters (Standard_Real& U,
							    Standard_Real& V ) const
{
  StdFail_NotDone_Raise_if
    (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistanceParameters");

  (myExtPS.Point(myIndex)).Parameter(U,V);
}
//=======================================================================
//function : LowerDistance
//purpose  : 
//=======================================================================
  Standard_Real GeomAPI_ProjectPointOnSurf::LowerDistance() const
{
  StdFail_NotDone_Raise_if
    (!myIsDone, "GeomAPI_ProjectPointOnSurf::LowerDistance");

  return sqrt (myExtPS.SquareDistance(myIndex));
}
//=======================================================================
//function : Standard_Real
//purpose  : 
//=======================================================================
  GeomAPI_ProjectPointOnSurf::operator Standard_Real() const
{
  return LowerDistance();
}