Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: ApproxInt_ImpPrmSvSurfaces.gxx |
2 | // Created: Wed Mar 17 12:42:28 1993 | |
3 | // Author: Laurent BUCHARD | |
4 | // <lbr@topsn3> | |
5 | ||
6 | #include <TColStd_Array1OfReal.hxx> | |
7 | #include <math_FunctionSetRoot.hxx> | |
8 | #include <StdFail_NotDone.hxx> | |
9 | #include <GeomAbs_SurfaceType.hxx> | |
10 | #include <Precision.hxx> | |
11 | ||
12 | #define ComputeParametersOnImplicitSurface(MyISurf,P,u,v) MyISurf.Parameters(P,u,v) | |
13 | ||
14 | #define Debug(expr) cout<<" expr :"<<expr; | |
15 | #define MyISurf MyZerImpFunc.ISurface() | |
16 | #define MyPSurf MyZerImpFunc.PSurface() | |
17 | ||
18 | //-------------------------------------------------------------------------------- | |
19 | ApproxInt_ImpPrmSvSurfaces::ApproxInt_ImpPrmSvSurfaces( const TheISurface& ISurf | |
20 | ,const ThePSurface& PSurf): | |
21 | MyHasBeenComputed(Standard_False), | |
22 | MyHasBeenComputedbis(Standard_False), | |
23 | MyImplicitFirst(Standard_True), | |
24 | MyZerImpFunc(PSurf,ISurf) | |
25 | { | |
26 | } | |
27 | //-------------------------------------------------------------------------------- | |
28 | ApproxInt_ImpPrmSvSurfaces::ApproxInt_ImpPrmSvSurfaces( const ThePSurface& PSurf | |
29 | ,const TheISurface& ISurf): | |
30 | MyHasBeenComputed(Standard_False), | |
31 | MyHasBeenComputedbis(Standard_False), | |
32 | MyImplicitFirst(Standard_False), | |
33 | MyZerImpFunc(PSurf,ISurf) | |
34 | { | |
35 | } | |
36 | //-------------------------------------------------------------------------------- | |
37 | void ApproxInt_ImpPrmSvSurfaces::Pnt(const Standard_Real u1, | |
38 | const Standard_Real v1, | |
39 | const Standard_Real u2, | |
40 | const Standard_Real v2, | |
41 | gp_Pnt& P) { | |
42 | gp_Pnt aP; | |
43 | gp_Vec aT; | |
44 | gp_Vec2d aTS1,aTS2; | |
45 | Standard_Real tu1=u1; | |
46 | Standard_Real tu2=u2; | |
47 | Standard_Real tv1=v1; | |
48 | Standard_Real tv2=v2; | |
49 | #ifdef DEB | |
50 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
51 | #else | |
52 | this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
53 | #endif | |
54 | P=MyPnt; | |
55 | } | |
56 | //-------------------------------------------------------------------------------- | |
57 | Standard_Boolean ApproxInt_ImpPrmSvSurfaces::Tangency(const Standard_Real u1, | |
58 | const Standard_Real v1, | |
59 | const Standard_Real u2, | |
60 | const Standard_Real v2, | |
61 | gp_Vec& T) { | |
62 | gp_Pnt aP; | |
63 | gp_Vec aT; | |
64 | gp_Vec2d aTS1,aTS2; | |
65 | Standard_Real tu1=u1; | |
66 | Standard_Real tu2=u2; | |
67 | Standard_Real tv1=v1; | |
68 | Standard_Real tv2=v2; | |
69 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
70 | T=MyTg; | |
71 | return(t); | |
72 | } | |
73 | //-------------------------------------------------------------------------------- | |
74 | Standard_Boolean ApproxInt_ImpPrmSvSurfaces::TangencyOnSurf1(const Standard_Real u1, | |
75 | const Standard_Real v1, | |
76 | const Standard_Real u2, | |
77 | const Standard_Real v2, | |
78 | gp_Vec2d& T) { | |
79 | gp_Pnt aP; | |
80 | gp_Vec aT; | |
81 | gp_Vec2d aTS1,aTS2; | |
82 | Standard_Real tu1=u1; | |
83 | Standard_Real tu2=u2; | |
84 | Standard_Real tv1=v1; | |
85 | Standard_Real tv2=v2; | |
86 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
87 | T=MyTguv1; | |
88 | return(t); | |
89 | } | |
90 | //-------------------------------------------------------------------------------- | |
91 | Standard_Boolean ApproxInt_ImpPrmSvSurfaces::TangencyOnSurf2(const Standard_Real u1, | |
92 | const Standard_Real v1, | |
93 | const Standard_Real u2, | |
94 | const Standard_Real v2, | |
95 | gp_Vec2d& T) { | |
96 | gp_Pnt aP; | |
97 | gp_Vec aT; | |
98 | gp_Vec2d aTS1,aTS2; | |
99 | Standard_Real tu1=u1; | |
100 | Standard_Real tu2=u2; | |
101 | Standard_Real tv1=v1; | |
102 | Standard_Real tv2=v2; | |
103 | Standard_Boolean t=this->Compute(tu1,tv1,tu2,tv2,aP,aT,aTS1,aTS2); | |
104 | T=MyTguv2; | |
105 | return(t); | |
106 | } | |
107 | //-------------------------------------------------------------------------------- | |
108 | Standard_Boolean ApproxInt_ImpPrmSvSurfaces::Compute( Standard_Real& u1 | |
109 | ,Standard_Real& v1 | |
110 | ,Standard_Real& u2 | |
111 | ,Standard_Real& v2 | |
112 | ,gp_Pnt& P | |
113 | ,gp_Vec& Tg | |
114 | ,gp_Vec2d& Tguv1 | |
115 | ,gp_Vec2d& Tguv2) { | |
116 | ||
117 | Standard_Real tu1=u1; | |
118 | Standard_Real tu2=u2; | |
119 | Standard_Real tv1=v1; | |
120 | Standard_Real tv2=v2; | |
121 | ||
122 | if(MyHasBeenComputed) { | |
123 | if( (MyParOnS1.X()==u1)&&(MyParOnS1.Y()==v1) | |
124 | &&(MyParOnS2.X()==u2)&&(MyParOnS2.Y()==v2)) { | |
125 | return(MyIsTangent); | |
126 | } | |
127 | else if(MyHasBeenComputedbis == Standard_False) { | |
128 | MyTgbis = MyTg; | |
129 | MyTguv1bis = MyTguv1; | |
130 | MyTguv2bis = MyTguv2; | |
131 | MyPntbis = MyPnt; | |
132 | MyParOnS1bis = MyParOnS1; | |
133 | MyParOnS2bis = MyParOnS2; | |
134 | MyIsTangentbis = MyIsTangent; | |
135 | MyHasBeenComputedbis = MyHasBeenComputed; | |
136 | } | |
137 | } | |
138 | ||
139 | if(MyHasBeenComputedbis) { | |
140 | if( (MyParOnS1bis.X()==u1)&&(MyParOnS1bis.Y()==v1) | |
141 | &&(MyParOnS2bis.X()==u2)&&(MyParOnS2bis.Y()==v2)) { | |
142 | ||
143 | gp_Vec TV(MyTg); | |
144 | gp_Vec2d TV1(MyTguv1); | |
145 | gp_Vec2d TV2(MyTguv2); | |
146 | gp_Pnt TP(MyPnt); | |
147 | gp_Pnt2d TP1(MyParOnS1); | |
148 | gp_Pnt2d TP2(MyParOnS2); | |
149 | Standard_Boolean TB=MyIsTangent; | |
150 | ||
151 | MyTg = MyTgbis; | |
152 | MyTguv1 = MyTguv1bis; | |
153 | MyTguv2 = MyTguv2bis; | |
154 | MyPnt = MyPntbis; | |
155 | MyParOnS1 = MyParOnS1bis; | |
156 | MyParOnS2 = MyParOnS2bis; | |
157 | MyIsTangent = MyIsTangentbis; | |
158 | ||
159 | MyTgbis = TV; | |
160 | MyTguv1bis = TV1; | |
161 | MyTguv2bis = TV2; | |
162 | MyPntbis = TP; | |
163 | MyParOnS1bis = TP1; | |
164 | MyParOnS2bis = TP2; | |
165 | MyIsTangentbis = TB; | |
166 | ||
167 | return(MyIsTangent); | |
168 | } | |
169 | } | |
170 | ||
171 | ||
172 | static math_Vector BornInf(1,2),BornSup(1,2),F(1,1),X(1,2),Tolerance(1,2); | |
173 | static math_Matrix D(1, 1, 1, 2); | |
174 | ||
175 | Standard_Real binfu,bsupu,binfv,bsupv; | |
176 | binfu = ThePSurfaceTool::FirstUParameter(MyPSurf); | |
177 | binfv = ThePSurfaceTool::FirstVParameter(MyPSurf); | |
178 | bsupu = ThePSurfaceTool::LastUParameter(MyPSurf); | |
179 | bsupv = ThePSurfaceTool::LastVParameter(MyPSurf); | |
180 | BornInf(1) = binfu; BornSup(1) = bsupu; | |
181 | BornInf(2) = binfv; BornSup(2) = bsupv; | |
182 | ||
183 | //--- ThePSurfaceTool::GetResolution(MyPSurf,Tolerance(1),Tolerance(2)); | |
184 | Tolerance(1) = 1.0e-8; Tolerance(2) = 1.0e-8; | |
185 | ||
186 | Standard_Real TranslationU=0.0; | |
187 | Standard_Real TranslationV=0.0; | |
188 | ||
189 | math_FunctionSetRoot Rsnld(MyZerImpFunc); | |
190 | Rsnld.SetTolerance(Tolerance); | |
191 | if(MyImplicitFirst) { | |
192 | if(u2<binfu-0.0000000001) { | |
193 | if(ThePSurfaceTool::IsUPeriodic(MyPSurf)) { | |
194 | Standard_Real d = ThePSurfaceTool::UPeriod(MyPSurf); | |
195 | do { TranslationU+=d; } while(u2+TranslationU < binfu); | |
196 | } | |
197 | else { | |
198 | MyIsTangent=MyIsTangentbis=Standard_False; | |
199 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
200 | return(Standard_False); | |
201 | } | |
202 | } | |
203 | else if(u2>bsupu+0.0000000001) { | |
204 | if(ThePSurfaceTool::IsUPeriodic(MyPSurf)) { | |
205 | Standard_Real d = ThePSurfaceTool::UPeriod(MyPSurf); | |
206 | do { TranslationU-=d; } while(u2+TranslationU > bsupu); | |
207 | } | |
208 | else { | |
209 | MyIsTangent=MyIsTangentbis=Standard_False; | |
210 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
211 | return(Standard_False); | |
212 | } | |
213 | } | |
214 | if(v2<binfv-0.0000000001) { | |
215 | if(ThePSurfaceTool::IsVPeriodic(MyPSurf)) { | |
216 | Standard_Real d = ThePSurfaceTool::VPeriod(MyPSurf); | |
217 | do { TranslationV+=d; } while(v2+TranslationV < binfv); | |
218 | } | |
219 | else { | |
220 | MyIsTangent=MyIsTangentbis=Standard_False; | |
221 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
222 | return(Standard_False); | |
223 | } | |
224 | } | |
225 | else if(v2>bsupv+0.0000000001) { | |
226 | if(ThePSurfaceTool::IsVPeriodic(MyPSurf)) { | |
227 | Standard_Real d = ThePSurfaceTool::VPeriod(MyPSurf); | |
228 | do { TranslationV-=d; } while(v2+TranslationV > bsupv); | |
229 | } | |
230 | else { | |
231 | MyIsTangent=MyIsTangentbis=Standard_False; | |
232 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
233 | return(Standard_False); | |
234 | } | |
235 | } | |
236 | X(1) = u2+TranslationU; | |
237 | X(2) = v2+TranslationV; | |
238 | } | |
239 | else { | |
240 | if(u1<binfu-0.0000000001) { | |
241 | if(ThePSurfaceTool::IsUPeriodic(MyPSurf)) { | |
242 | Standard_Real d = ThePSurfaceTool::UPeriod(MyPSurf); | |
243 | do { TranslationU+=d; } while(u1+TranslationU < binfu); | |
244 | } | |
245 | else { | |
246 | MyIsTangent=MyIsTangentbis=Standard_False; | |
247 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
248 | return(Standard_False); | |
249 | } | |
250 | } | |
251 | else if(u1>bsupu+0.0000000001) { | |
252 | if(ThePSurfaceTool::IsUPeriodic(MyPSurf)) { | |
253 | Standard_Real d = ThePSurfaceTool::UPeriod(MyPSurf); | |
254 | do { TranslationU-=d; } while(u1+TranslationU > bsupu); | |
255 | } | |
256 | else { | |
257 | MyIsTangent=MyIsTangentbis=Standard_False; | |
258 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
259 | return(Standard_False); | |
260 | } | |
261 | } | |
262 | if(v1<binfv-0.0000000001) { | |
263 | if(ThePSurfaceTool::IsVPeriodic(MyPSurf)) { | |
264 | Standard_Real d = ThePSurfaceTool::VPeriod(MyPSurf); | |
265 | do { TranslationV+=d; } while(v1+TranslationV < binfv); | |
266 | } | |
267 | else { | |
268 | MyIsTangent=MyIsTangentbis=Standard_False; | |
269 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
270 | return(Standard_False); | |
271 | } | |
272 | } | |
273 | else if(v1>bsupv+0.0000000001) { | |
274 | if(ThePSurfaceTool::IsVPeriodic(MyPSurf)) { | |
275 | Standard_Real d = ThePSurfaceTool::VPeriod(MyPSurf); | |
276 | do { TranslationV-=d; } while(v1+TranslationV > bsupv); | |
277 | } | |
278 | else { | |
279 | MyIsTangent=MyIsTangentbis=Standard_False; | |
280 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
281 | return(Standard_False); | |
282 | } | |
283 | } | |
284 | X(1) = u1+TranslationU; | |
285 | X(2) = v1+TranslationV; | |
286 | } | |
287 | ||
288 | //---------------------------------------------------- | |
289 | //-- Pour eviter de coller le point de depart de la | |
290 | //-- recherche sur une des bornes (Rsnld -> NotDone) | |
291 | //-- | |
292 | if(X(1)-0.0000000001 <= binfu) X(1)=X(1)+0.0000001; | |
293 | if(X(1)+0.0000000001 >= bsupu) X(1)=X(1)-0.0000001; | |
294 | if(X(2)-0.0000000001 <= binfv) X(2)=X(2)+0.0000001; | |
295 | if(X(2)+0.0000000001 >= bsupv) X(2)=X(2)-0.0000001; | |
296 | ||
297 | ||
298 | Standard_Real PourTesterU = X(1); | |
299 | Standard_Real PourTesterV = X(2); | |
300 | ||
301 | ||
302 | /* *************************************************************** | |
303 | cout<<" Envoi a Rsnld : "; Debug(X(1)); Debug(X(2)); | |
304 | Debug(BornInf(1)); Debug(BornInf(2)); | |
305 | Debug(BornSup(1)); Debug(BornSup(2)); cout<<endl; | |
306 | Debug(u1); Debug(v1); Debug(u2); Debug(v2); Debug(MyImplicitFirst); | |
307 | cout<<endl; | |
308 | **************************************************************** */ | |
309 | ||
310 | Rsnld.Perform(MyZerImpFunc,X,BornInf,BornSup); | |
311 | if(Rsnld.IsDone()) { | |
312 | MyHasBeenComputed = Standard_True; | |
313 | Rsnld.Root(X); | |
314 | ||
315 | Standard_Real DistAvantApresU = Abs(PourTesterU-X(1)); | |
316 | Standard_Real DistAvantApresV = Abs(PourTesterV-X(2)); | |
317 | ||
318 | MyPnt = P = ThePSurfaceTool::Value(MyPSurf,X(1),X(2)); | |
319 | ||
320 | if( (DistAvantApresV <= 0.001 ) | |
321 | && (DistAvantApresU <= 0.001 )) { | |
322 | ||
323 | gp_Vec PD1U,PD1V; | |
324 | gp_Vec ID1U,ID1V; | |
325 | ||
326 | ||
327 | if(MyImplicitFirst) { | |
328 | u2 = X(1)-TranslationU; | |
329 | v2 = X(2)-TranslationV; | |
330 | ComputeParametersOnImplicitSurface(MyISurf,P,u1,v1); | |
331 | if(MyISurf.TypeQuadric() != GeomAbs_Plane) { | |
c6541a0c D |
332 | while(u1-tu1>M_PI) u1-=M_PI+M_PI; |
333 | while(tu1-u1>M_PI) u1+=M_PI+M_PI; | |
7fd59977 | 334 | } |
335 | MyParOnS1.SetCoord(tu1,tv1); | |
336 | MyParOnS2.SetCoord(tu2,tv2); | |
337 | ThePSurfaceTool::D1(MyPSurf,X(1),X(2),P,PD1U,PD1V); | |
338 | MyISurf.D1(u1,v1,P,ID1U,ID1V); | |
339 | } | |
340 | else { | |
341 | u1 = X(1)-TranslationU; | |
342 | v1 = X(2)-TranslationV; | |
343 | ComputeParametersOnImplicitSurface(MyISurf,P,u2,v2); | |
344 | if(MyISurf.TypeQuadric() != GeomAbs_Plane) { | |
c6541a0c D |
345 | while(u2-tu2>M_PI) u2-=M_PI+M_PI; |
346 | while(tu2-u2>M_PI) u2+=M_PI+M_PI; | |
7fd59977 | 347 | } |
348 | MyParOnS1.SetCoord(tu1,tv1); | |
349 | MyParOnS2.SetCoord(tu2,tu2); | |
350 | ThePSurfaceTool::D1(MyPSurf,X(1),X(2),P,PD1U,PD1V); | |
351 | MyISurf.D1(u2,v2,P,ID1U,ID1V); | |
352 | } | |
353 | ||
354 | ||
355 | gp_Vec VNormaleImp = MyISurf.Normale(MyPnt); | |
356 | gp_Vec VNormalePrm = PD1U.Crossed(PD1V); | |
357 | if( VNormaleImp.SquareMagnitude() <= gp::Resolution() | |
358 | || VNormalePrm.SquareMagnitude() <= gp::Resolution()) { | |
359 | MyIsTangent = Standard_False; | |
360 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
361 | return(Standard_False); | |
362 | } | |
363 | ||
364 | gp_Dir NormaleImp(VNormaleImp); | |
365 | gp_Dir NormalePrm(VNormalePrm); | |
366 | ||
367 | gp_Vec VNImp(NormaleImp); | |
368 | gp_Vec VNPrm(NormalePrm); | |
369 | MyTg = VNImp.Crossed(VNPrm); | |
370 | Standard_Real NmyTg = MyTg.Magnitude(); | |
371 | if(NmyTg < 0.000001) { | |
372 | MyIsTangent = Standard_False; | |
373 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
374 | return(Standard_False); | |
375 | } | |
376 | MyTg.SetCoord(MyTg.X()/NmyTg,MyTg.Y()/NmyTg,MyTg.Z()/NmyTg); | |
377 | ||
378 | ||
379 | MyTg = NormaleImp.Crossed(NormalePrm); | |
380 | Tg = MyTg; | |
381 | ||
382 | Standard_Real TUTV,TgTU,TgTV,TUTU,TVTV,DIS; | |
383 | Standard_Real DeltaU,DeltaV; | |
384 | TUTU = PD1U.Dot(PD1U); | |
385 | TVTV = PD1V.Dot(PD1V); | |
386 | TUTV = PD1U.Dot(PD1V); | |
387 | TgTU = MyTg.Dot(PD1U); | |
388 | TgTV = MyTg.Dot(PD1V); | |
389 | DIS = TUTU * TVTV - TUTV * TUTV; | |
390 | ||
391 | if(DIS<1e-10 && DIS>-1e-10) { | |
392 | MyIsTangent = Standard_False; | |
393 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
394 | return(Standard_False); | |
395 | } | |
396 | ||
397 | ||
398 | DeltaU = (TgTU * TVTV - TgTV * TUTV ) / DIS ; | |
399 | DeltaV = (TgTV * TUTU - TgTU * TUTV ) / DIS ; | |
400 | ||
401 | if(MyImplicitFirst) { | |
402 | MyTguv1.SetCoord( MyTg.Dot(ID1U)/(ID1U.Dot(ID1U)) | |
403 | ,MyTg.Dot(ID1V)/(ID1V.Dot(ID1V))); | |
404 | MyTguv2.SetCoord(DeltaU,DeltaV); | |
405 | Tguv1 = MyTguv1; | |
406 | Tguv2 = MyTguv2; | |
407 | } | |
408 | else { | |
409 | MyTguv1.SetCoord(DeltaU,DeltaV); | |
410 | MyTguv2.SetCoord( MyTg.Dot(ID1U)/(ID1U.Dot(ID1U)) | |
411 | ,MyTg.Dot(ID1V)/(ID1V.Dot(ID1V))); | |
412 | Tguv1 = MyTguv1; | |
413 | Tguv2 = MyTguv2; | |
414 | } | |
415 | MyIsTangent=Standard_True; | |
416 | return(Standard_True); | |
417 | } | |
418 | else { | |
419 | ||
420 | //-- cout<<" ApproxInt_ImpImpSvSurfaces.gxx : Distance apres recadrage Trop Grande "<<endl; | |
421 | ||
422 | MyIsTangent=Standard_False; | |
423 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
424 | return(Standard_False); | |
425 | } | |
426 | } | |
427 | else { | |
428 | MyIsTangent = Standard_False; | |
429 | MyHasBeenComputed = MyHasBeenComputedbis = Standard_False; | |
430 | return(Standard_False); | |
431 | } | |
432 | } | |
433 | ||
434 | //-------------------------------------------------------------------------------- | |
435 | ||
436 | ||
437 | ||
438 | ||
439 |