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