0023803: Mess with snapshot images in the test case reports
[occt.git] / src / IntPatch / IntPatch_PrmPrmIntersection.cxx
CommitLineData
b311480e 1// Created on: 1993-02-02
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// modified by Edward AGAPOV (eap) Tue Jan 22 12:29:55 2002
23// modified by Oleg FEDYAED (ofv) Fri Nov 29 16:08:02 2002
24
25#include <IntPatch_PrmPrmIntersection.ixx>
26
27#include <IntPatch_TheInterfPolyhedron.hxx>
28#include <IntPatch_ThePWalkingInter.hxx>
29#include <IntPatch_WLine.hxx>
30#include <IntPatch_RstInt.hxx>
31
32#include <IntPatch_Line.hxx>
33
34#include <Handle_IntSurf_LineOn2S.hxx>
35#include <IntSurf_PntOn2S.hxx>
36#include <IntSurf_LineOn2S.hxx>
37#include <TColStd_Array1OfReal.hxx>
38#include <Intf_PIType.hxx>
39#include <Intf_SectionLine.hxx>
40#include <Intf_TangentZone.hxx>
41#include <Intf_SectionPoint.hxx>
42#include <gp_Pnt.hxx>
43#include <gp_Dir.hxx>
44#include <IntPolyh_Intersection.hxx>
45
46#include <TColStd_SequenceOfInteger.hxx>
47#include <IntSurf_ListIteratorOfListOfPntOn2S.hxx>
48#include <TColStd_HArray1OfReal.hxx>
49
50static void SectionPointToParameters(const Intf_SectionPoint& Sp,
51 const IntPatch_Polyhedron& Surf1,
52 const IntPatch_Polyhedron& Surf2,
53 Standard_Real& u1,
54 Standard_Real& v1,
55 Standard_Real& u2,
56 Standard_Real& v2);
57
58
59static
60 void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
61 const Handle(Adaptor3d_HSurface)& Surf2,
62 IntPatch_SequenceOfLine& aSLin);
63
64//==================================================================================
65// function :
66// purpose :
67//==================================================================================
68IntPatch_PrmPrmIntersection::IntPatch_PrmPrmIntersection(): done(Standard_False)
69{
70}
71
72//==================================================================================
73// function : Perform
74// purpose :
75//==================================================================================
76void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
77 const Handle(Adaptor3d_TopolTool)& D1,
78 const Standard_Real TolTangency,
79 const Standard_Real Epsilon,
80 const Standard_Real Deflection,
81 const Standard_Real Increment)
82{
83 IntPatch_Polyhedron Poly1( Surf1, D1->NbSamplesU(), D1->NbSamplesV() );
84 Perform( Surf1, Poly1, D1, TolTangency, Epsilon, Deflection, Increment );
85}
86
87//==================================================================================
88// function : Perform
89// purpose :
90//==================================================================================
91void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
92 const IntPatch_Polyhedron& Poly1,
93 const Handle(Adaptor3d_TopolTool)& D1,
94 const Handle(Adaptor3d_HSurface)& Surf2,
95 const Handle(Adaptor3d_TopolTool)& D2,
96 const Standard_Real TolTangency,
97 const Standard_Real Epsilon,
98 const Standard_Real Deflection,
99 const Standard_Real Increment)
100{
101 IntPatch_Polyhedron Poly2( Surf2 );
102 Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment);
103}
104
105//==================================================================================
106// function : Perform
107// purpose :
108//==================================================================================
109void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
110 const Handle(Adaptor3d_TopolTool)& D1,
111 const Handle(Adaptor3d_HSurface)& Surf2,
112 const IntPatch_Polyhedron& Poly2,
113 const Handle(Adaptor3d_TopolTool)& D2,
114 const Standard_Real TolTangency,
115 const Standard_Real Epsilon,
116 const Standard_Real Deflection,
117 const Standard_Real Increment)
118{
119 IntPatch_Polyhedron Poly1( Surf1 );
120 Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment );
121}
122
123//==================================================================================
124// function : Perform
125// purpose :
126//==================================================================================
127void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
128 const IntPatch_Polyhedron& Poly1,
129 const Handle(Adaptor3d_TopolTool)& D1,
130 const Handle(Adaptor3d_HSurface)& Surf2,
131 const IntPatch_Polyhedron& Poly2,
132 const Handle(Adaptor3d_TopolTool)& D2,
133 const Standard_Real TolTangency,
134 const Standard_Real Epsilon,
135 const Standard_Real Deflection,
136 const Standard_Real Increment)
137{
138 IntPatch_TheInterfPolyhedron Interference(Poly1,Poly2);
139 empt = Standard_True;
140 done = Standard_True;
141 SLin.Clear();
142
143 Standard_Real Deflection2 = Deflection*Deflection;
144 Standard_Integer nbLigSec = Interference.NbSectionLines();
145 Standard_Integer nbTanZon = Interference.NbTangentZones();
146
147 Standard_Integer NbPntOn2SOnLine;
148 Standard_Integer NbLigCalculee = 0;
149
150 Standard_Real U1,U2,V1,V2;
151 Standard_Real pu1,pu2,pv1,pv2;
152
153 TColStd_Array1OfReal StartParams(1,4);
154
155 IntPatch_ThePWalkingInter PW( Surf1, Surf2, TolTangency, Epsilon, Deflection, Increment );
156
157 Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
158 Standard_Real incidence;
159 Standard_Real dminiPointLigne;
160
161 Standard_Boolean HasStartPoint,RejetLigne;
162
163 IntSurf_PntOn2S StartPOn2S;
164
165 Standard_Integer ver;
166
167 gp_Pnt Point3dDebut,Point3dFin;
168
169 if( nbLigSec >= 1 ) {
170 Standard_Integer *TabL = new Standard_Integer [nbLigSec+1];
171 Standard_Integer ls;
172 for( ls = 1; ls <= nbLigSec; ls++ )
173 TabL[ls]=ls;
174
175 Standard_Boolean triok;
176 do {
177 triok=Standard_True;
178 for(Standard_Integer b=2; b<=nbLigSec; b++) {
179 Standard_Integer nb_B = Interference.LineValue(TabL[b]).NumberOfPoints();
180 Standard_Integer nb_A = Interference.LineValue(TabL[b-1]).NumberOfPoints();
181 if( nb_B > nb_A ) {
182 Standard_Integer tyu=TabL[b];
183 TabL[b]=TabL[b-1];
184 TabL[b-1]=tyu;
185 triok=Standard_False;
186 }
187 }
188 } while( triok==Standard_False );
189
190 for( ls = 1; ls <= nbLigSec; ls++) {
191 const Intf_SectionLine& LineSec=Interference.LineValue(TabL[ls]);
192 Standard_Integer nbp = LineSec.NumberOfPoints();
193
194 Standard_Integer *TabPtDep = new Standard_Integer [nbp+1];
195 Standard_Integer ilig;
196 for( ilig = 1; ilig <= nbp; ilig++)
197 TabPtDep[ilig]=0;
198
199 Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
200 Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
201
202 SectionPointToParameters(LineSec.GetPoint(1),Poly1,Poly2,UminLig1,VminLig1,UminLig2,VminLig2);
203
204 UmaxLig1=UminLig1;
205 VmaxLig1=VminLig1;
206 UmaxLig2=UminLig2;
207 VmaxLig2=VminLig2;
208
209 for( ilig = 2; ilig <= nbp; ilig++ ) {
210 SectionPointToParameters(LineSec.GetPoint(ilig),Poly1,Poly2,U1,V1,U2,V2);
211
212 if(U1>UmaxLig1) UmaxLig1=U1;
213 if(V1>VmaxLig1) VmaxLig1=V1;
214 if(U2>UmaxLig2) UmaxLig2=U2;
215 if(V2>VmaxLig2) VmaxLig2=V2;
216
217 if(U1<UminLig1) UminLig1=U1;
218 if(V1<VminLig1) VminLig1=V1;
219 if(U2<UminLig2) UminLig2=U2;
220 if(V2<VminLig2) VminLig2=V2;
221 }
222
223 Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1;
224 Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
225 Standard_Integer IndicePointdeDepart1 = 0,IndicePointdeDepart2 = 0;
226 Standard_Boolean lignetrouvee=Standard_False;
227
228 do {
229 NombreDePointsDeDepartDuCheminement++;
230 if(NombreDePointsDeDepartDuCheminement == 1) {
231 incidence=3.0;
232 Standard_Integer nbp1_4=nbp/4;
233 Standard_Integer nbp3_4=nbp-nbp1_4;
234
235 Standard_Integer nsp;
236 for(nsp=nbp/2; nsp<nbp3_4; nsp++) {
237 Standard_Real CurrentIncidence = LineSec.GetPoint(nsp).Incidence();
238 if(CurrentIncidence < incidence) {
239 nbps2 = nsp;
240 incidence = 0.9*CurrentIncidence;
241 }
242 }
243
244 for(nsp=nbp/2; nsp>nbp1_4; nsp--) {
245 Standard_Real CurrentIncidence = LineSec.GetPoint(nsp).Incidence();
246 if(CurrentIncidence < incidence) {
247 nbps2 = nsp;
248 incidence = 0.9*CurrentIncidence;
249 }
250 }
251
252 if(nbp<3)
253 NombreDePointsDeDepartDuCheminement=3;
254
255 IndicePointdeDepart1 = nbps2;
256 }
257 else if(NombreDePointsDeDepartDuCheminement == 2) {
258 if(IndicePointdeDepart1 == 1) {
259 nbps2 = nbp/2;
260 IndicePointdeDepart2 = nbps2;
261 }
262 else {
263 nbps2 = 1;
264 IndicePointdeDepart2 = 1;
265 }
266 }
267 else if(NombreDePointsDeDepartDuCheminement == 3) {
268 if(IndicePointdeDepart1 == nbp)
269 nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
270 else
271 nbps2 = nbp;
272 }
273 else {
274 nbps2 = NombreDePointsDeDepartDuCheminement-3;
275 NombreDePointsDeDepartDuCheminement++;
276 }
277
278 if(TabPtDep[nbps2]==0) {
279 TabPtDep[nbps2]=1;
280 SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly2,U1,V1,U2,V2);
281
282 StartParams(1) = U1;
283 StartParams(2) = V1;
284 StartParams(3) = U2;
285 StartParams(4) = V2;
286
287 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
288 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
289
290 if(HasStartPoint) {
291 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
292 NbLigCalculee = SLin.Length();
293 Standard_Integer l;
294 for( l=1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
295 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
296 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
297 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
298 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
299 NbPntOn2SOnLine = testwline->NbPnts();
300 Standard_Integer ll;
301 for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
302 const gp_Pnt &Pa = testwline->Point(ll).Value();
303 const gp_Pnt &Pb = testwline->Point(ll+1).Value();
304 const gp_Pnt &PStart = StartPOn2S.Value();
305 gp_Vec AM(Pa,PStart);
306 gp_Vec MB(PStart,Pb);
307 Standard_Real AMMB = AM.Dot(MB);
308 if(AMMB > 0.0) {
309 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
310 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
311 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
312 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
313 Standard_Real d = 0.0;
314 if(HM.X() < Deflection) {
315 d+=HM.X()*HM.X();
316 if(HM.Y() < Deflection) {
317 d+=HM.Y()*HM.Y();
318 if(HM.Z() < Deflection)
319 d+=HM.Z()*HM.Z();
320 else
321 d=Deflection2;
322 }
323 else
324 d=Deflection2;
325 }
326 else
327 d=Deflection2;
328
329 if(d<Deflection2)
330 dminiPointLigne = 0.0;
331 }
332 else {
333 Standard_Real dab = Pa.SquareDistance(Pb);
334 Standard_Real dap = Pa.SquareDistance(PStart);
335 if(dap < dab)
336 dminiPointLigne=0;
337 else {
338 Standard_Real dbp = Pb.SquareDistance(PStart);
339 if(dbp < dab)
340 dminiPointLigne=0;
341 }
342 }
343 }
344 }
345 } // for ( l ...
346
347 if(dminiPointLigne > SeuildPointLigne) {
348 PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
349 if(PW.IsDone()) {
350 if(PW.NbPoints()>2) {
351 RejetLigne = Standard_False;
352 Point3dDebut = PW.Value(1).Value();
353 Point3dFin = PW.Value(PW.NbPoints()).Value();
354 for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
355 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
356 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
357 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
358 if( Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency ) {
359 if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency)
360 RejetLigne = Standard_True;
361 }
362 }
363
364 if(!RejetLigne) {
365 // Calculation transition
366 IntSurf_TypeTrans trans1,trans2;
367 Standard_Real locu,locv;
368 gp_Vec norm1,norm2,d1u,d1v;
369 gp_Pnt ptbid;
370 Standard_Integer indextg;
371 gp_Vec tgline(PW.TangentAtLine(indextg));
372 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
373 Surf1->D1(locu,locv,ptbid,d1u,d1v);
374 norm1 = d1u.Crossed(d1v);
375 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
376 Surf2->D1(locu,locv,ptbid,d1u,d1v);
377 norm2 = d1u.Crossed(d1v);
378 if(tgline.DotCross(norm2,norm1)>0.) {
379 trans1 = IntSurf_Out;
380 trans2 = IntSurf_In;
381 }
382 else {
383 trans1 = IntSurf_In;
384 trans2 = IntSurf_Out;
385 }
386
387 Standard_Real TolTang = TolTangency;
388 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
389 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
390 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
391
392 if(wline->NbVertex() == 0) {
393 IntPatch_Point vtx;
394 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
395 POn2S.Parameters(pu1,pv1,pu2,pv2);
396 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
397 vtx.SetParameters(pu1,pv1,pu2,pv2);
398 vtx.SetParameter(1);
399 wline->AddVertex(vtx);
400
401 POn2S = PW.Line()->Value(wline->NbPnts());
402 POn2S.Parameters(pu1,pv1,pu2,pv2);
403 vtx.SetValue(Point3dFin,TolTang,Standard_False);
404 vtx.SetParameters(pu1,pv1,pu2,pv2);
405 vtx.SetParameter(wline->NbPnts());
406 wline->AddVertex(vtx);
407 }
408
409 lignetrouvee = Standard_True;
410 SLin.Append(wline);
411 empt = Standard_False;
412 }// !RejetLigne
413 }// PW.NbPoints()>2
414 }// done is True
415 }// dminiPointLigne > SeuildPointLigne
416 }// HasStartPoint
417 }// TabPtDep[nbps2]==0
418 } while( nbp>5 && ( !( ( (NombreDePointsDeDepartDuCheminement >= 3) && lignetrouvee ) ||
419 ( (NombreDePointsDeDepartDuCheminement-3>=nbp) && !lignetrouvee ) ) ) );
420
421 delete [] TabPtDep;
422 }// for( ls ...
423
424 delete [] TabL;
425 }// nbLigSec >= 1
426
427 Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
428 Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
429
430 UminLig1=VminLig1=UminLig2=VminLig2=RealLast();
431 UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1;
432
433 Standard_Integer z;
434 for(z=1; z <= nbTanZon; z++) {
435 const Intf_TangentZone& TangentZone=Interference.ZoneValue(z);
436 for(Standard_Integer pz=1; pz<=TangentZone.NumberOfPoints(); pz++) {
437 SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly2,U1,V1,U2,V2);
438
439 if(U1>UmaxLig1) UmaxLig1=U1;
440 if(V1>VmaxLig1) VmaxLig1=V1;
441 if(U2>UmaxLig2) UmaxLig2=U2;
442 if(V2>VmaxLig2) VmaxLig2=V2;
443
444 if(U1<UminLig1) UminLig1=U1;
445 if(V1<VminLig1) VminLig1=V1;
446 if(U2<UminLig2) UminLig2=U2;
447 if(V2<VminLig2) VminLig2=V2;
448 }
449 }
450
451 for(z=1; z <= nbTanZon; z++) {
452 const Intf_TangentZone& TangentZone=Interference.ZoneValue(z);
453 Standard_Integer pz;
454 for( pz=1; pz<=TangentZone.NumberOfPoints(); pz++) {
455 SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly2,U1,V1,U2,V2);
456
457 StartParams(1) = U1;
458 StartParams(2) = V1;
459 StartParams(3) = U2;
460 StartParams(4) = V2;
461
462 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
463 if(HasStartPoint) {
464 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
465 NbLigCalculee = SLin.Length();
466 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
467 Standard_Integer l;
468 for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
469 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
470 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
471 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
472 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
473 NbPntOn2SOnLine = testwline->NbPnts();
474 Standard_Integer ll;
475 for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
476 const gp_Pnt& Pa = testwline->Point(ll).Value();
477 const gp_Pnt& Pb = testwline->Point(ll+1).Value();
478 const gp_Pnt& PStart=StartPOn2S.Value();
479 gp_Vec AM(Pa,PStart);
480 gp_Vec MB(PStart,Pb);
481 Standard_Real AMMB = AM.Dot(MB);
482 if(AMMB > 0.0) {
483 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
484 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
485 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
486 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
487 Standard_Real d = 0.0;
488 if(HM.X() < Deflection) {
489 d+=HM.X()*HM.X();
490 if(HM.Y() < Deflection) {
491 d+=HM.Y()*HM.Y();
492 if(HM.Z() < Deflection)
493 d+=HM.Z()*HM.Z();
494 else
495 d=Deflection2;
496 }
497 else
498 d=Deflection2;
499 }
500 else
501 d=Deflection2;
502
503 if(d<Deflection2)
504 dminiPointLigne = 0.0;
505 }
506 else {
507 Standard_Real dab = Pa.Distance(Pb);
508 Standard_Real dap = Pa.Distance(PStart);
509 if(dap < dab)
510 dminiPointLigne=0;
511 else {
512 Standard_Real dbp = Pb.Distance(PStart);
513 if(dbp < dab)
514 dminiPointLigne=0;
515 }
516 }
517 }// for( ll ...
518 }// if ...
519 }// for( l ...
520
521 if(dminiPointLigne > SeuildPointLigne) {
522 PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
523 if(PW.IsDone()) {
524 if(PW.NbPoints()>2) {
525 RejetLigne = Standard_False;
526 Point3dDebut = PW.Value(1).Value();
527 Point3dFin = PW.Value(PW.NbPoints()).Value();
528 for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
529 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
530 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
531 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
532 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
533 RejetLigne = Standard_True;
534 else {
535 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
536 RejetLigne = Standard_True;
537 }
538 }
539
540 if(!RejetLigne) {
541 IntSurf_TypeTrans trans1,trans2;
542 Standard_Real locu,locv;
543 gp_Vec norm1,norm2,d1u,d1v;
544 gp_Pnt ptbid;
545 Standard_Integer indextg;
546 gp_Vec tgline(PW.TangentAtLine(indextg));
547 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
548 Surf1->D1(locu,locv,ptbid,d1u,d1v);
549 norm1 = d1u.Crossed(d1v);
550 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
551 Surf2->D1(locu,locv,ptbid,d1u,d1v);
552 norm2 = d1u.Crossed(d1v);
553 if(tgline.DotCross(norm2,norm1)>0.) {
554 trans1 = IntSurf_Out;
555 trans2 = IntSurf_In;
556 }
557 else {
558 trans1 = IntSurf_In;
559 trans2 = IntSurf_Out;
560 }
561
562 Standard_Real TolTang = TolTangency;
563 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
564 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
565 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
566
567 if(wline->NbVertex() == 0) {
568 IntPatch_Point vtx;
569 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
570 POn2S.Parameters(pu1,pv1,pu2,pv2);
571 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
572 vtx.SetParameters(pu1,pv1,pu2,pv2);
573 vtx.SetParameter(1);
574 wline->AddVertex(vtx);
575
576 POn2S = PW.Line()->Value(wline->NbPnts());
577 POn2S.Parameters(pu1,pv1,pu2,pv2);
578 vtx.SetValue(Point3dFin,TolTang,Standard_False);
579 vtx.SetParameters(pu1,pv1,pu2,pv2);
580 vtx.SetParameter(wline->NbPnts());
581 wline->AddVertex(vtx);
582 }
583
584 SLin.Append(wline);
585 empt = Standard_False;
586 }// if !RejetLigne
587 }// PW.NbPoints()>2
588 }// done is True
589 }// dminiPointLigne > SeuildPointLigne
590 }// HasStartPoint
591 }// for( pz ...
592 }// for( z ...
593}
594
595//==================================================================================
596// function : Perform
597// purpose :
598//==================================================================================
599void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
600 const IntPatch_Polyhedron& Poly1,
601 const Handle(Adaptor3d_TopolTool)& D1,
602 const Standard_Real TolTangency,
603 const Standard_Real Epsilon,
604 const Standard_Real Deflection,
605 const Standard_Real Increment)
606{
607 IntPatch_TheInterfPolyhedron Interference(Poly1);
608 empt = Standard_True;
609 done = Standard_True;
610 SLin.Clear();
611
612 Standard_Integer nbLigSec = Interference.NbSectionLines();
613 Standard_Integer nbTanZon = Interference.NbTangentZones();
614
615 Standard_Integer NbPntOn2SOnLine;
616 Standard_Integer NbLigCalculee = 0;
617
618 Standard_Real U1,U2,V1,V2;
619 Standard_Real pu1,pu2,pv1,pv2;
620
621 TColStd_Array1OfReal StartParams(1,4);
622 IntPatch_ThePWalkingInter PW(Surf1,Surf1,TolTangency,Epsilon,Deflection,Increment);
623
624 Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
625 Standard_Real incidence;
626 Standard_Real dminiPointLigne;
627
628 Standard_Boolean HasStartPoint,RejetLigne;
629
630 IntSurf_PntOn2S StartPOn2S;
631
632 Standard_Integer ver;
633
634 gp_Pnt Point3dDebut,Point3dFin;
635
636 if(nbLigSec>=1) {
637 Standard_Integer ls;
638 for( ls = 1; ls <= nbLigSec; ls++) {
639 const Intf_SectionLine& LineSec=Interference.LineValue(ls);
640 Standard_Integer nbp = LineSec.NumberOfPoints();
641 Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1;
642 Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
643 Standard_Integer IndicePointdeDepart1 = 0, IndicePointdeDepart2 = 0;
644 do {
645 NombreDePointsDeDepartDuCheminement++;
646 if(NombreDePointsDeDepartDuCheminement == 1) {
647 incidence = 0.0;
648 Standard_Integer nsp1;
649 for( nsp1= nbp/2; nsp1 >= 1; nsp1--) {
650 SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
651 Standard_Real CurrentIncidence = Abs(U1-U2)+Abs(V1-V2);
652 if(CurrentIncidence > incidence) {
653 nbps2 = nsp1;
654 incidence = CurrentIncidence;
655 }
656 }
657 for( nsp1 = nbp/2; nsp1 <= nbp; nsp1++) {
658 SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
659 Standard_Real CurrentIncidence = Abs(U1-U2)+Abs(V1-V2);
660 if(CurrentIncidence > incidence) {
661 nbps2 = nsp1;
662 incidence = CurrentIncidence;
663 }
664 }
665
666 if(nbp<3)
667 NombreDePointsDeDepartDuCheminement=3;
668
669 IndicePointdeDepart1 = nbps2;
670 }
671 else if(NombreDePointsDeDepartDuCheminement == 2) {
672 if(IndicePointdeDepart1 == 1) {
673 nbps2 = nbp/2;
674 IndicePointdeDepart2 = nbps2;
675 }
676 else {
677 nbps2 = 1;
678 IndicePointdeDepart2 = 1;
679 }
680 }
681 else {
682 if(IndicePointdeDepart1 == nbp)
683 nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
684 else
685 nbps2 = nbp;
686 }
687
688 SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly1,U1,V1,U2,V2);
689
690 StartParams(1) = U1;
691 StartParams(2) = V1;
692 StartParams(3) = U2;
693 StartParams(4) = V2;
694
695 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
696 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
697 if(HasStartPoint) {
698 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
699 if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) {
700 NbLigCalculee = SLin.Length();
701 Standard_Integer l;
702 for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
703 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
704 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
705 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
706 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
707 NbPntOn2SOnLine = testwline->NbPnts();
708 Standard_Integer ll;
709 for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
710 Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
711 testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
712 testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
713 if(Au1>Bu1) {
714 t=Au1;
715 Au1=Bu1;
716 Bu1=t;
717 }
718 if(Av1>Bv1) {
719 t=Av1;
720 Av1=Bv1;
721 Bv1=t;
722 }
723 Au1-=1.0e-7;
724 Av1-=1.0e-7;
725 Bu1+=1.0e-7;
726 Bv1+=1.0e-7;
727
728 if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
729 dminiPointLigne = 0.0;
730 else {
731 if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
732 dminiPointLigne = 0.0;
733 }
734 }// for( ll ...
735 }// if ...
736 }// for( l ...
737
738 if(dminiPointLigne > SeuildPointLigne) {
739 PW.Perform(StartParams);
740 if(PW.IsDone()) {
741 if(PW.NbPoints()>2) {
742 RejetLigne = Standard_False;
743 Point3dDebut = PW.Value(1).Value();
744 Point3dFin = PW.Value(PW.NbPoints()).Value();
745 for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
746 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
747 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
748 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
749 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
750 RejetLigne = Standard_True;
751 else {
752 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
753 RejetLigne = Standard_True;
754 }
755 }
756
757 if(!RejetLigne) {
758 IntSurf_TypeTrans trans1,trans2;
759 Standard_Real locu,locv;
760 gp_Vec norm1,norm2,d1u,d1v;
761 gp_Pnt ptbid;
762 Standard_Integer indextg;
763 gp_Vec tgline(PW.TangentAtLine(indextg));
764 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
765 Surf1->D1(locu,locv,ptbid,d1u,d1v);
766 norm1 = d1u.Crossed(d1v);
767 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
768 Surf1->D1(locu,locv,ptbid,d1u,d1v);
769 norm2 = d1u.Crossed(d1v);
770 if (tgline.DotCross(norm2,norm1)>0.) {
771 trans1 = IntSurf_Out;
772 trans2 = IntSurf_In;
773 }
774 else {
775 trans1 = IntSurf_In;
776 trans2 = IntSurf_Out;
777 }
778
779 IntSurf_LineOn2S LineOn2S;
780 Standard_Integer nbpw,imin,imax,i;
781 nbpw = PW.Line()->NbPoints();
782 Standard_Real u1,v1,u2,v2;
783 i=0;
784 do {
785 i++;
786 imin=i;
787 const IntSurf_PntOn2S& Pi = PW.Line()->Value(i);
788 Pi.Parameters(u1,v1,u2,v2);
789 } while((i<nbpw)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
790
791 if(imin>2)
792 imin--;
793
794 i=nbpw+1;
795 do {
796 i--;
797 imax=i;
798 const IntSurf_PntOn2S& Pi = PW.Line()->Value(i);
799 Pi.Parameters(u1,v1,u2,v2);
800 } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
801
802 if(imax<nbpw)
803 imax++;
804
805 if(imin<imax) {
806 Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
807 for(i=imin;i<=imax;i++)
808 PWLine->Add(PW.Line()->Value(i));
809
810 Standard_Real TolTang = TolTangency;
811 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
812 const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
813 const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
814 if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) {
815 Standard_Real u1t,v1t,u2t,v2t;
816 POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
817 IntPatch_Point vtx;
818 vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
819 vtx.SetParameters(u2t,v2t,u1t,v1t);
820 vtx.SetParameter(wline->NbPnts());
821 wline->SetPoint(wline->NbPnts(),vtx);
822 }
823 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
824 if(wline->NbVertex() == 0) {
825 IntPatch_Point vtx;
826 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
827 POn2S.Parameters(pu1,pv1,pu2,pv2);
828 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
829 vtx.SetParameters(pu1,pv1,pu2,pv2);
830 vtx.SetParameter(1);
831 wline->AddVertex(vtx);
832
833 POn2S = PW.Line()->Value(wline->NbPnts());
834 POn2S.Parameters(pu1,pv1,pu2,pv2);
835 vtx.SetValue(Point3dFin,TolTang,Standard_False);
836 vtx.SetParameters(pu1,pv1,pu2,pv2);
837 vtx.SetParameter(wline->NbPnts());
838 wline->AddVertex(vtx);
839 }
840 SLin.Append(wline);
841 empt = Standard_False;
842 }// imin<imax
843 }// !RejetLigne
844 }// PW.NbPoints()>2
845 }// done is True
846 }// dminiPointLigne > SeuildPointLigne
847 }// Abs || Abs
848 }// HasStartPoint
849 } while(nbp>5 && NombreDePointsDeDepartDuCheminement<3);
850 }// for( ls ...
851 }// nbLigSec>=1
852
853 Standard_Integer z;
854 for( z = 1; z <= nbTanZon; z++) {
855 const Intf_TangentZone& TangentZone=Interference.ZoneValue(z);
856 for(Standard_Integer pz=1; pz<=TangentZone.NumberOfPoints(); pz++) {
857 SectionPointToParameters(TangentZone.GetPoint(pz),Poly1,Poly1,U1,V1,U2,V2);
858
859 StartParams(1) = U1;
860 StartParams(2) = V1;
861 StartParams(3) = U2;
862 StartParams(4) = V2;
863
864 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
865 if(HasStartPoint) {
866 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
867 if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) {
868 NbLigCalculee = SLin.Length();
869 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
870 Standard_Integer l;
871 for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
872 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
873 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
874 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
875 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
876 NbPntOn2SOnLine = testwline->NbPnts();
877 Standard_Integer ll;
878 for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
879 Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
880 testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
881 testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
882 if(Au1>Bu1) {
883 t=Au1;
884 Au1=Bu1;
885 Bu1=t;
886 }
887 if(Av1>Bv1) {
888 t=Av1;
889 Av1=Bv1;
890 Bv1=t;
891 }
892 Au1-=1.0e-7;
893 Av1-=1.0e-7;
894 Bu1+=1.0e-7;
895 Bv1+=1.0e-7;
896 if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
897 dminiPointLigne = 0.0;
898 else {
899 if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
900 dminiPointLigne = 0.0;
901 }
902 }// for( ll ...
903 }// if ...
904 }// for( l ...
905
906 if(dminiPointLigne > SeuildPointLigne) {
907 PW.Perform(StartParams);
908 if(PW.IsDone()) {
909 if(PW.NbPoints()>2) {
910 RejetLigne = Standard_False;
911 Point3dDebut = PW.Value(1).Value();
912 Point3dFin = PW.Value(PW.NbPoints()).Value();
913 for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
914 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
915 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
916 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
917 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
918 RejetLigne = Standard_True;
919 else {
920 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
921 RejetLigne = Standard_True;
922 }
923 }
924
925 if(!RejetLigne) {
926 IntSurf_TypeTrans trans1,trans2;
927 Standard_Real locu,locv;
928 gp_Vec norm1,norm2,d1u,d1v;
929 gp_Pnt ptbid;
930 Standard_Integer indextg;
931 gp_Vec tgline(PW.TangentAtLine(indextg));
932 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
933 Surf1->D1(locu,locv,ptbid,d1u,d1v);
934 norm1 = d1u.Crossed(d1v);
935 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
936 Surf1->D1(locu,locv,ptbid,d1u,d1v);
937 norm2 = d1u.Crossed(d1v);
938 if(tgline.DotCross(norm2,norm1)>0.) {
939 trans1 = IntSurf_Out;
940 trans2 = IntSurf_In;
941 }
942 else {
943 trans1 = IntSurf_In;
944 trans2 = IntSurf_Out;
945 }
946
947 IntSurf_LineOn2S LineOn2S;
948 Standard_Integer nbp,imin,imax,i;
949 nbp = PW.Line()->NbPoints();
950 Standard_Real u1,v1,u2,v2;
951 i=0;
952 do {
953 i++;
954 imin=i;
955 const IntSurf_PntOn2S& Pi = PW.Line()->Value(i);
956 Pi.Parameters(u1,v1,u2,v2);
957 } while((i<nbp)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
958
959 if(imin>2)
960 imin--;
961
962 i=nbp+1;
963 do {
964 i--;
965 imax=i;
966 const IntSurf_PntOn2S& Pi = PW.Line()->Value(i);
967 Pi.Parameters(u1,v1,u2,v2);
968 } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
969
970 if(imax<nbp)
971 imax++;
972
973 if(imin<imax) {
974 Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
975 for(i=imin;i<=imax;i++)
976 PWLine->Add(PW.Line()->Value(i));
977
978 Standard_Real TolTang = TolTangency;
979 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
980 const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
981 const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
982 if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) {
983 Standard_Real u1t,v1t,u2t,v2t;
984 POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
985 IntPatch_Point vtx;
986 vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
987 vtx.SetParameters(u2t,v2t,u1t,v1t);
988 vtx.SetParameter(wline->NbPnts());
989 wline->SetPoint(wline->NbPnts(),vtx);
990 }
991
992 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
993
994 if(wline->NbVertex() == 0) {
995 IntPatch_Point vtx;
996 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
997 POn2S.Parameters(pu1,pv1,pu2,pv2);
998 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
999 vtx.SetParameters(pu1,pv1,pu2,pv2);
1000 vtx.SetParameter(1);
1001 wline->AddVertex(vtx);
1002
1003 POn2S = PW.Line()->Value(wline->NbPnts());
1004 POn2S.Parameters(pu1,pv1,pu2,pv2);
1005 vtx.SetValue(Point3dFin,TolTang,Standard_False);
1006 vtx.SetParameters(pu1,pv1,pu2,pv2);
1007 vtx.SetParameter(wline->NbPnts());
1008 wline->AddVertex(vtx);
1009 }
1010
1011 SLin.Append(wline);
1012 empt = Standard_False;
1013 }// imin<imax
1014 }// !RejetLigne
1015 }// PW.NbPoints()>2
1016 }// done a True
1017 }// dminiPointLigne > SeuildPointLigne
1018 }// Abs || Abs
1019 }// HasStartPoint
1020 }// for ( pz ...
1021 }// for( z ...
1022}
1023
1024//==================================================================================
1025// function : NewLine
1026// purpose :
1027//==================================================================================
1028Handle_IntPatch_Line IntPatch_PrmPrmIntersection::NewLine (const Handle(Adaptor3d_HSurface)& Surf1,
1029 const Handle(Adaptor3d_HSurface)& Surf2,
1030 const Standard_Integer NumLine,
1031 const Standard_Integer Low,
1032 const Standard_Integer High,
1033 const Standard_Integer NbPntsToInsert) const
1034{
1035 Standard_Integer NbPnts = NbPntsToInsert + High - Low;
1036 if(NumLine>NbLines() || NumLine<1 || Low>=High )
1037 Standard_OutOfRange::Raise(" IntPatch_PrmPrmIntersection NewLine ");
1038 //------------------------------------------------------------------
1039 //-- Indice : Low Low+1 I I+1 High --
1040 //-- --
1041 //-- Abs.Curv. : S(Low) S(I) S(I+1) S(High) --
1042 //-- --
1043 //-- On echantillonne a abcisse curviligne --
1044 //-- constante. --
1045 //-- L abcisse est calculee sur les params U1,V1 --
1046 //------------------------------------------------------------------
1047 TColStd_Array1OfReal U1(Low,High);
1048 TColStd_Array1OfReal V1(Low,High);
1049 TColStd_Array1OfReal U2(Low,High);
1050 TColStd_Array1OfReal V2(Low,High);
1051 TColStd_Array1OfReal AC(Low,High);
1052
1053 Standard_Real s,ds;
1054 Handle(IntPatch_WLine) TheLine = Handle(IntPatch_WLine)::DownCast(Line(NumLine));
1055 const IntSurf_PntOn2S& Point=TheLine->Point(Low);
1056 Standard_Real u1,v1,u2,v2;
1057 Point.Parameters(u1,v1,u2,v2);
1058 U1(Low) = u1;
1059 V1(Low) = v1;
1060 U2(Low) = u2;
1061 V2(Low) = v2;
1062 AC(Low) =0.0;
1063
1064 IntPatch_ThePWalkingInter PW(Surf1,Surf2,0.000001,0.000001,0.001,0.001);
1065
1066 Standard_Integer i;
1067 for(i=Low+1; i<=High; i++)
1068 {
1069 const IntSurf_PntOn2S& Pointi=TheLine->Point(i);
1070 Pointi.Parameters(u1,v1,u2,v2);
1071 U1(i) = u1;
1072 V1(i) = v1;
1073 U2(i) = u2;
1074 V2(i) = v2;
1075
1076 Standard_Real du1=u1-U1(i-1);
1077 Standard_Real dv1=v1-V1(i-1);
1078
1079 AC(i) = AC(i-1) + Sqrt((du1*du1)+(dv1*dv1));
1080 }
1081
1082 Handle(IntSurf_LineOn2S) ResultPntOn2SLine = new IntSurf_LineOn2S();
1083
1084 IntSurf_PntOn2S StartPOn2S;
1085 TColStd_Array1OfReal StartParams(1,4);
1086
1087 ResultPntOn2SLine->Add(TheLine->Point(Low));
1088
1089 ds = AC(High) / (NbPnts-1);
1090 Standard_Integer Indice = Low;
1091
1092 Standard_Real dsmin = ds*0.3;
1093 Standard_Real smax = AC(High);
1094
1095 for(i=2,s=ds; (i<NbPnts)&&(s<smax); i++,s+=ds)
1096 {
1097 while(AC(Indice+1) <= s)
1098 {
1099 ResultPntOn2SLine->Add(TheLine->Point(Indice));
1100 Indice++;
1101 }
1102 Standard_Real a = s - AC(Indice);
1103 Standard_Real b = AC(Indice+1) - s;
1104 Standard_Real nab = 1.0/(a+b);
1105 //----------------------------------------------------------
1106 //-- Verification : Si Dist au prochain point < dsmin --
1107 //-- Si Dist au precedent point < dsmin --
1108 //-- --
1109 //----------------------------------------------------------
1110 if((nab > ds)&&(a>dsmin)&&(b>dsmin))
1111 {
1112 StartParams(1) = (U1(Indice) * b + U1(Indice+1) * a) * nab;
1113 StartParams(2) = (V1(Indice) * b + V1(Indice+1) * a) * nab;
1114 StartParams(3) = (U2(Indice) * b + U2(Indice+1) * a) * nab;
1115 StartParams(4) = (V2(Indice) * b + V2(Indice+1) * a) * nab;
1116
1117 Standard_Boolean HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
1118 if(HasStartPoint)
1119 ResultPntOn2SLine->Add(StartPOn2S);
1120 }
1121 else
1122 s+=dsmin;
1123 }
1124
1125 ResultPntOn2SLine->Add(TheLine->Point(High));
1126
1127 return(new IntPatch_WLine(ResultPntOn2SLine,Standard_False));
1128}
1129
1130//==================================================================================
1131// function : SectionPointToParameters
1132// purpose :
1133//==================================================================================
1134void SectionPointToParameters(const Intf_SectionPoint& Sp,
1135 const IntPatch_Polyhedron& Poly1,
1136 const IntPatch_Polyhedron& Poly2,
1137 Standard_Real& u1,
1138 Standard_Real& v1,
1139 Standard_Real& u2,
1140 Standard_Real& v2)
1141{
1142 Intf_PIType typ;
1143 Standard_Integer Adr1,Adr2;
1144 Standard_Real Param,u,v;
1145 gp_Pnt P(Sp.Pnt());
1146
1147 Standard_Integer Pt1,Pt2,Pt3;
1148
1149 Sp.InfoFirst(typ,Adr1,Adr2,Param);
1150 switch(typ) {
1151 case Intf_VERTEX: //-- Adr1 est le numero du vertex
1152 {
1153 Poly1.Parameters(Adr1,u1,v1);
1154 break;
1155 }
1156 case Intf_EDGE:
1157 {
1158 Poly1.Parameters(Adr1,u1,v1);
1159 Poly1.Parameters(Adr2,u,v);
1160 u1+= Param * (u-u1);
1161 v1+= Param * (v-v1);
1162 break;
1163 }
1164 case Intf_FACE:
1165 {
1166 Standard_Real ua,va,ub,vb,uc,vc,ca,cb,cc,cabc;
1167 Poly1.Triangle(Adr1,Pt1,Pt2,Pt3);
1168 gp_Pnt PA(Poly1.Point(Pt1));
1169 gp_Pnt PB(Poly1.Point(Pt2));
1170 gp_Pnt PC(Poly1.Point(Pt3));
1171 Poly1.Parameters(Pt1,ua,va);
1172 Poly1.Parameters(Pt2,ub,vb);
1173 Poly1.Parameters(Pt3,uc,vc);
1174 gp_Vec Normale(gp_Vec(PA,PB).Crossed(gp_Vec(PA,PC)));
1175 cc = (gp_Vec(PA,PB).Crossed(gp_Vec(PA,P))).Dot(Normale);
1176 ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale);
1177 cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale);
1178 cabc = ca + cb + cc;
1179
1180 ca/=cabc; cb/=cabc; cc/=cabc;
1181
1182 u1 = ca * ua + cb * ub + cc * uc;
1183 v1 = ca * va + cb * vb + cc * vc;
1184 break;
1185 }
1186 default:
1187 {
1188 //-- cout<<" Default dans SectionPointToParameters "<<endl;
1189 break;
1190 }
1191 }
1192
1193
1194 Sp.InfoSecond(typ,Adr1,Adr2,Param);
1195 switch(typ) {
1196 case Intf_VERTEX: //-- Adr1 est le numero du vertex
1197 {
1198 Poly2.Parameters(Adr1,u2,v2);
1199 break;
1200 }
1201 case Intf_EDGE:
1202 {
1203 Poly2.Parameters(Adr1,u2,v2);
1204 Poly2.Parameters(Adr2,u,v);
1205 u2+= Param * (u-u2);
1206 v2+= Param * (v-v2);
1207 break;
1208 }
1209 case Intf_FACE:
1210 {
1211 Standard_Real ua,va,ub,vb,uc,vc,ca,cb,cc,cabc;
1212 Poly2.Triangle(Adr1,Pt1,Pt2,Pt3);
1213 gp_Pnt PA(Poly2.Point(Pt1));
1214 gp_Pnt PB(Poly2.Point(Pt2));
1215 gp_Pnt PC(Poly2.Point(Pt3));
1216 Poly2.Parameters(Pt1,ua,va);
1217 Poly2.Parameters(Pt2,ub,vb);
1218 Poly2.Parameters(Pt3,uc,vc);
1219 gp_Vec Normale(gp_Vec(PA,PB).Crossed(gp_Vec(PA,PC)));
1220 cc = (gp_Vec(PA,PB).Crossed(gp_Vec(PA,P))).Dot(Normale);
1221 ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale);
1222 cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale);
1223 cabc = ca + cb + cc;
1224
1225 ca/=cabc; cb/=cabc; cc/=cabc;
1226
1227 u2 = ca * ua + cb * ub + cc * uc;
1228 v2 = ca * va + cb * vb + cc * vc;
1229 break;
1230 }
1231 default:
1232 {
1233 //-- cout<<" Default dans SectionPointToParameters "<<endl;
1234 break;
1235 }
1236 }
1237}
1238
7fd59977 1239//==================================================================================
1240// function : RemplitLin
1241// purpose :
1242//==================================================================================
1243void IntPatch_PrmPrmIntersection::RemplitLin(const Standard_Integer x1,
1244 const Standard_Integer y1,
1245 const Standard_Integer z1,
1246 const Standard_Integer x2,
1247 const Standard_Integer y2,
1248 const Standard_Integer z2,
1249 IntPatch_PrmPrmIntersection_T3Bits& Map) const
1250{
1251 int xg,yg,zg;
1252 xg=x1-x2; if(xg<0) xg=-xg;
1253 yg=y1-y2; if(yg<0) yg=-yg;
1254 zg=z1-z2; if(zg<0) zg=-zg;
1255 if(DansGrille(x1) && DansGrille(y1) && DansGrille(z1)) {
1256 Standard_Integer t = GrilleInteger(x1,y1,z1);
1257 Map.Add(t);
1258 }
1259 if(xg<=1 && yg<=1 && zg<=1) return;
1260 xg = (x1+x2)>>1;
1261 yg = (y1+y2)>>1;
1262 zg = (z1+z2)>>1;
1263 RemplitLin(x1,y1,z1,xg,yg,zg,Map);
1264 RemplitLin(x2,y2,z2,xg,yg,zg,Map);
1265}
1266
1267//==================================================================================
1268// function : RemplitTri
1269// purpose :
1270//==================================================================================
1271void IntPatch_PrmPrmIntersection::RemplitTri(const Standard_Integer x1,
1272 const Standard_Integer y1,
1273 const Standard_Integer z1,
1274 const Standard_Integer x2,
1275 const Standard_Integer y2,
1276 const Standard_Integer z2,
1277 const Standard_Integer x3,
1278 const Standard_Integer y3,
1279 const Standard_Integer z3,
1280 IntPatch_PrmPrmIntersection_T3Bits& Map) const
1281{
1282 if(x1==x2 && x1==x3 && y1==y2 && y1==y3 && z1==z2 && z1==z3) {
1283 if(DansGrille(x1) && DansGrille(y1) && DansGrille(z1)) {
1284 Standard_Integer t = GrilleInteger(x1,y1,z1);
1285 Map.Add(t);
1286 }
1287 return;
1288 }
1289 else {
1290 Standard_Integer xg=(x1+x2+x3)/3;
1291 Standard_Integer yg=(y1+y2+y3)/3;
1292 Standard_Integer zg=(z1+z2+z3)/3;
1293 if(xg==x1 && yg==y1 && zg==z1) {
1294 RemplitLin(x1,y1,z1,x2,y2,z2,Map);
1295 RemplitLin(x1,y1,z1,x3,y3,z3,Map);
1296 return;
1297 }
1298 if(xg==x2 && yg==y2 && zg==z2) {
1299 RemplitLin(x2,y2,z2,x1,y1,z1,Map);
1300 RemplitLin(x2,y2,z2,x3,y3,z3,Map);
1301 return;
1302 }
1303 if(xg==x3 && yg==y3 && zg==z3) {
1304 RemplitLin(x3,y3,z3,x2,y2,z2,Map);
1305 RemplitLin(x3,y3,z3,x1,y1,z1,Map);
1306 return;
1307 }
1308 if(DansGrille(xg) && DansGrille(yg) && DansGrille(zg)) {
1309 Standard_Integer t = GrilleInteger(xg,yg,zg);
1310 Map.Add(t);
1311 }
1312 if(xg!=x3 || yg!=y3 || zg!=z3) RemplitTri(x1,y1,z1, x2,y2,z2, xg,yg,zg, Map);
1313 if(xg!=x1 || yg!=y1 || zg!=z1) RemplitTri(xg,yg,zg, x2,y2,z2, x3,y3,z3, Map);
1314 if(xg!=x2 || yg!=y2 || zg!=z2) RemplitTri(x1,y1,z1, xg,yg,zg, x3,y3,z3, Map);
1315 }
1316}
1317
1318//==================================================================================
1319// function : Remplit
1320// purpose :
1321//==================================================================================
1322void IntPatch_PrmPrmIntersection::Remplit(const Standard_Integer a,
1323 const Standard_Integer b,
1324 const Standard_Integer c,
1325 IntPatch_PrmPrmIntersection_T3Bits& Map) const
1326{
1327 int iax,iay,iaz,ibx,iby,ibz,icx,icy,icz;
1328 if(a!=-1) Map.Add(a);
1329 if(b!=-1) Map.Add(b);
1330 if(c!=-1) Map.Add(c);
1331
1332 if(a!=-1 && b!=-1 && c!=-1 ) {
1333 IntegerGrille(a,iax,iay,iaz);
1334 IntegerGrille(b,ibx,iby,ibz);
1335 IntegerGrille(c,icx,icy,icz);
1336 RemplitTri(iax,iay,iaz,ibx,iby,ibz,icx,icy,icz,Map);
1337 }
1338}
1339
7fd59977 1340
7fd59977 1341
c66d7156
P
1342//=======================================================================
1343//function : Perform
1344//purpose :
1345//=======================================================================
1346void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
1347 const Handle(Adaptor3d_TopolTool)& D1,
1348 const Handle(Adaptor3d_HSurface)& Surf2,
1349 const Handle(Adaptor3d_TopolTool)& D2,
1350 const Standard_Real TolTangency,
1351 const Standard_Real Epsilon,
1352 const Standard_Real Deflection,
1353 const Standard_Real Increment,
1354 IntSurf_ListOfPntOn2S& LOfPnts,
1355 const Standard_Boolean RestrictLine)
1356{
1357 if (LOfPnts.IsEmpty()){
1358 done = Standard_True;
7fd59977 1359 return;
1360 }
c66d7156
P
1361
1362 empt = Standard_True;
1363 SLin.Clear();
7fd59977 1364
c66d7156
P
1365 Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
1366 Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
1367 Standard_Real U1,U2,V1,V2;
7fd59977 1368
c66d7156
P
1369 UminLig1 = Surf1->FirstUParameter();
1370 VminLig1 = Surf1->FirstVParameter();
1371 UmaxLig1 = Surf1->LastUParameter();
1372 VmaxLig1 = Surf1->LastVParameter();
1373 UminLig2 = Surf2->FirstUParameter();
1374 VminLig2 = Surf2->FirstVParameter();
1375 UmaxLig2 = Surf2->LastUParameter();
1376 VmaxLig2 = Surf2->LastVParameter();
7fd59977 1377
c66d7156 1378 IntSurf_ListIteratorOfListOfPntOn2S IterLOP1(LOfPnts);
7fd59977 1379
c66d7156
P
1380 for(; IterLOP1.More(); IterLOP1.Next()){
1381 IntSurf_PntOn2S Pnt = IterLOP1.Value();
1382 Pnt.Parameters(U1, V1, U2, V2);
1383 if(U1>UmaxLig1) UmaxLig1=U1;
1384 if(V1>VmaxLig1) VmaxLig1=V1;
1385 if(U2>UmaxLig2) UmaxLig2=U2;
1386 if(V2>VmaxLig2) VmaxLig2=V2;
1387
1388 if(U1<UminLig1) UminLig1=U1;
1389 if(V1<VminLig1) VminLig1=V1;
1390 if(U2<UminLig2) UminLig2=U2;
1391 if(V2<VminLig2) VminLig2=V2;
7fd59977 1392 }
7fd59977 1393
c66d7156 1394 Standard_Real Deflection2 = Deflection*Deflection;
7fd59977 1395
c66d7156
P
1396 Standard_Real SeuildPointLigne = 15.0 * Increment * Increment;
1397
1398 Standard_Integer NbPntOn2SOnLine = 0, NbLigCalculee = 0, ver;
1399 Standard_Real pu1,pu2,pv1,pv2, dminiPointLigne;
1400 Standard_Boolean HasStartPoint,RejetLigne;
1401 IntSurf_PntOn2S StartPOn2S;
1402 gp_Pnt Point3dDebut,Point3dFin;
7fd59977 1403
c66d7156
P
1404 TColStd_Array1OfReal StartParams(1,4);
1405 IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment);
7fd59977 1406
c66d7156
P
1407 IntSurf_ListIteratorOfListOfPntOn2S IterLOP2(LOfPnts);
1408 for(; IterLOP2.More(); IterLOP2.Next() ){
1409
1410 IntSurf_PntOn2S cPnt = IterLOP2.Value();
1411 cPnt.Parameters(U1, V1, U2, V2);
1412
1413 StartParams(1) = U1;
1414 StartParams(2) = V1;
1415 StartParams(3) = U2;
1416 StartParams(4) = V2;
1417
1418 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
1419 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
1420 if(HasStartPoint) {
1421 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
1422 NbLigCalculee = SLin.Length();
1423 Standard_Integer l;
1424 for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
1425 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
1426 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
1427 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
1428 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
1429 NbPntOn2SOnLine = testwline->NbPnts();
1430 Standard_Integer ll;
1431 for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
1432 const gp_Pnt &Pa = testwline->Point(ll).Value();
1433 const gp_Pnt &Pb = testwline->Point(ll+1).Value();
1434 const gp_Pnt &PStart = StartPOn2S.Value();
1435 gp_Vec AM(Pa,PStart);
1436 gp_Vec MB(PStart,Pb);
1437 Standard_Real AMMB = AM.Dot(MB);
1438 if(AMMB > 0.0) {
1439 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
1440 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
1441 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
1442 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
1443 Standard_Real d = 0.0;
1444 if(HM.X() < Deflection) {
1445 d+=HM.X()*HM.X();
1446 if(HM.Y() < Deflection) {
1447 d+=HM.Y()*HM.Y();
1448 if(HM.Z() < Deflection)
1449 d+=HM.Z()*HM.Z();
1450 else
1451 d=Deflection2;
1452 }
1453 else
1454 d=Deflection2;
1455 }
1456 else
1457 d=Deflection2;
1458
1459 if(d<Deflection2)
1460 dminiPointLigne = 0.0;
1461 }
1462 else {
1463 Standard_Real dab = Pa.SquareDistance(Pb);
1464 Standard_Real dap = Pa.SquareDistance(PStart);
1465 if(dap < dab)
1466 dminiPointLigne=0;
1467 else {
1468 Standard_Real dbp = Pb.SquareDistance(PStart);
1469 if(dbp < dab)
1470 dminiPointLigne=0;
1471 }
1472 }
1473 }// for( ll ...
1474 }// if ...
1475 }// for( l ...
1476
1477 if(dminiPointLigne > SeuildPointLigne) {
1478 PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
1479 if(PW.IsDone()) {
1480 if(PW.NbPoints()>2) {
1481 RejetLigne = Standard_False;
1482 Point3dDebut = PW.Value(1).Value();
1483 Point3dFin = PW.Value(PW.NbPoints()).Value();
1484 for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
1485 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
1486 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
1487 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
1488 if(Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency) {
1489 if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency)
1490 RejetLigne = Standard_True;
1491 }
1492 }
1493
1494 if(!RejetLigne) {
1495 IntSurf_TypeTrans trans1,trans2;
1496 Standard_Real locu,locv;
1497 gp_Vec norm1,norm2,d1u,d1v;
1498 gp_Pnt ptbid;
1499 Standard_Integer indextg;
1500 gp_Vec tgline(PW.TangentAtLine(indextg));
1501 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
1502 Surf1->D1(locu,locv,ptbid,d1u,d1v);
1503 norm1 = d1u.Crossed(d1v);
1504 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
1505 Surf2->D1(locu,locv,ptbid,d1u,d1v);
1506 norm2 = d1u.Crossed(d1v);
1507 if( tgline.DotCross(norm2,norm1) >= 0. ) {
1508 trans1 = IntSurf_Out;
1509 trans2 = IntSurf_In;
1510 }
1511 else {
1512 trans1 = IntSurf_In;
1513 trans2 = IntSurf_Out;
1514 }
1515
1516 Standard_Real TolTang = TolTangency;
1517 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
1518 if (RestrictLine){
1519 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
1520 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
1521 }
1522
1523 if(wline->NbVertex() == 0) {
1524 IntPatch_Point vtx;
1525 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
1526 POn2S.Parameters(pu1,pv1,pu2,pv2);
1527 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
1528 vtx.SetParameters(pu1,pv1,pu2,pv2);
1529 vtx.SetParameter(1);
1530 wline->AddVertex(vtx);
1531
1532 POn2S = PW.Line()->Value(wline->NbPnts());
1533 POn2S.Parameters(pu1,pv1,pu2,pv2);
1534 vtx.SetValue(Point3dFin,TolTang,Standard_False);
1535 vtx.SetParameters(pu1,pv1,pu2,pv2);
1536 vtx.SetParameter(wline->NbPnts());
1537 wline->AddVertex(vtx);
1538 }
7fd59977 1539
c66d7156
P
1540 Standard_Integer slinlen = SLin.Length();
1541 if( slinlen > 0 ) {
1542 Standard_Integer cnbV = wline->NbVertex();
1543 Standard_Integer ciV;
1544 for( ciV = 1; ciV <= cnbV; ciV++ ) {
1545 Standard_Real pntDMin = 1.e+100;
1546 Standard_Integer VDMin = 0;
1547 Standard_Integer WLDMin = 0;
1548 gp_Pnt cPV = wline->Vertex(ciV).Value();
1549 Standard_Integer iL;
1550 for( iL = 1; iL <= slinlen; iL++) {
1551 const Handle(IntPatch_Line)& aSLine = SLin.Value(iL);
1552 IntPatch_IType aType = aSLine->ArcType();
1553 if( aType != IntPatch_Walking)
1554 continue;
1555 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
1556 Standard_Integer tnbV = aWLine->NbVertex();
1557 Standard_Integer tiV;
1558 for( tiV = 1; tiV <= tnbV; tiV++ ) {
1559 gp_Pnt tPV = aWLine->Vertex(tiV).Value();
1560 Standard_Real tDistance = cPV.Distance(tPV);
1561 Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance);
1562 Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance);
1563 Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance);
1564 Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance);
1565 Standard_Real RmaxS1 = Max(uRs1,vRs1);
1566 Standard_Real RmaxS2 = Max(uRs2,vRs2);
1567 if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4) {
1568 if( pntDMin > tDistance && tDistance > 1.e-9) {
1569 pntDMin = tDistance;
1570 VDMin = tiV;
1571 WLDMin = iL;
1572 }
1573 }
1574 }
1575 }
1576
1577 if( VDMin != 0 ) {
1578 const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin);
1579 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
1580 Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine();
1581 Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine();
1582 Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.;
1583 Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.;
1584 wline->Point(ciVpar).Parameters(u11,v11,u12,v12);
1585 aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22);
1586
1587 Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S();
1588 IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar);
1589 Standard_Integer cNbP = wline->NbPnts();
1590
1591 TColStd_SequenceOfInteger VPold;
1592 Standard_Integer iPo;
1593 for( iPo = 1; iPo <= cnbV; iPo++ ) {
1594 Standard_Real Po = wline->Vertex(iPo).ParameterOnLine();
1595 Standard_Integer IPo = (Standard_Integer) Po;
1596 VPold.Append(IPo);
1597 }
1598
1599 Standard_Boolean removeNext = Standard_False;
1600 Standard_Boolean removePrev = Standard_False;
1601 if( ciV == 1) {
1602 Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
1603 if(dPar > 10) {
1604 removeNext = Standard_True;
1605 for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
1606 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
1607 }
1608 }
1609 else if( ciV == cnbV) {
1610 Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
1611 if(dPar > 10) {
1612 removePrev = Standard_True;
1613 VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
1614 }
1615 }
1616 else {
1617 Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
1618 Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
1619 if(dParMi > 10) {
1620 removePrev = Standard_True;
1621 VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
1622 }
1623 if(dParMa > 10) {
1624 removeNext = Standard_True;
1625 for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) {
1626 if(dParMi > 10)
1627 VPold.SetValue(iPo, VPold.Value(iPo) - 2 );
1628 else
1629 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
1630 }
1631 }
1632 else {
1633 if(dParMi > 10)
1634 for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
1635 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
1636 }
1637 }
1638 Standard_Integer pI = (Standard_Integer) ciVpar;
1639
1640 Standard_Integer iP;
1641 for( iP = 1; iP <= cNbP; iP++) {
1642 if( pI == iP )
1643 newL2s->Add(replacePnt);
1644 else if(removeNext && iP == (pI + 1))
1645 continue;
1646 else if(removePrev && iP == (pI - 1))
1647 continue;
1648 else
1649 newL2s->Add(wline->Point(iP));
1650 }
1651
1652 IntPatch_Point newVtx;
1653 gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value();
1654 newVtx.SetValue(Pnt3dV,TolTang,Standard_False);
1655 newVtx.SetParameters(u21,v21,u22,v22);
1656 newVtx.SetParameter(VPold.Value(ciV));
1657
1658 Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2);
1659
1660 Standard_Integer iV;
1661 for( iV = 1; iV <= cnbV; iV++ ) {
1662 if( iV == ciV )
1663 NWLine->AddVertex(newVtx);
1664 else {
1665 IntPatch_Point theVtx = wline->Vertex(iV);
1666 theVtx.SetParameter(VPold.Value(iV));
1667 NWLine->AddVertex(theVtx);
1668 }
1669 }
1670
1671 wline = NWLine;
1672 }
1673 }
1674 }// SLin.Length > 0
1675
1676 SLin.Append(wline);
1677 empt = Standard_False;
1678 }// !RejetLigne
1679 }// PW points > 2
1680 }// done is True
1681 }// dminiPointLigne > SeuildPointLigne
1682 }// HasStartPoint
1683 }// for( IterLOP ...
1684 done = Standard_True;
1685 return;
1686}
1687//=======================================================================
1688//function : Perform
1689//purpose :
1690//=======================================================================
1691void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)& Surf1,
1692 const Handle(Adaptor3d_TopolTool)& D1,
1693 const Handle(Adaptor3d_HSurface)& Surf2,
1694 const Handle(Adaptor3d_TopolTool)& D2,
1695 const Standard_Real U1Depart,
1696 const Standard_Real V1Depart,
1697 const Standard_Real U2Depart,
1698 const Standard_Real V2Depart,
1699 const Standard_Real TolTangency,
1700 const Standard_Real Epsilon,
1701 const Standard_Real Deflection,
1702 const Standard_Real Increment) {
1703
1704
1705
1706// Standard_Integer NbU1 = D1->NbSamplesU();
1707// Standard_Integer NbV1 = D1->NbSamplesV();
1708// Standard_Integer NbU2 = D2->NbSamplesU();
1709// Standard_Integer NbV2 = D2->NbSamplesV();
7fd59977 1710
c66d7156
P
1711 //-- Traitement des Lignes de sections
1712 empt = Standard_True;
1713 done = Standard_True;
1714 SLin.Clear();
1715
1716 //------------------------------------------------------------
7fd59977 1717
c66d7156
P
1718 Standard_Real pu1,pu2,pv1,pv2;
1719
1720 TColStd_Array1OfReal StartParams(1,4);
1721
1722// Standard_Integer MaxOscill = NbU1;
1723// if(MaxOscill < NbU2) MaxOscill=NbU2;
1724// if(MaxOscill < NbV1) MaxOscill=NbV1;
1725// if(MaxOscill < NbV2) MaxOscill=NbV2;
1726
1727// Standard_Real nIncrement=Increment;
1728// if(MaxOscill>10) {
1729// #ifdef DEB
1730// cout<<"\n IntPatch_PrmPrmIntersection.gxx : Increment:"<<Increment<<" -> "<<Increment/(0.5*MaxOscill)<<endl;
1731// #endif
1732// nIncrement/=0.5*MaxOscill;
1733// }
1734
1735 IntPatch_ThePWalkingInter PW(Surf1,Surf2,
1736 TolTangency,
1737 Epsilon,
1738 Deflection,
1739 Increment); //nIncrement);
1740
1741
1742 //Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
1743 //Standard_Real incidence;
1744 //Standard_Real dminiPointLigne;
1745
1746 Standard_Boolean HasStartPoint;//,RejetLigne;
1747
1748 IntSurf_PntOn2S StartPOn2S;
1749
1750 //Standard_Integer ver;
1751
1752 gp_Pnt Point3dDebut,Point3dFin;
1753
1754 //------------------------------------------------------------
1755
1756 StartParams(1) = U1Depart;
1757 StartParams(2) = V1Depart;
1758 StartParams(3) = U2Depart;
1759 StartParams(4) = V2Depart;
1760
1761 //-----------------------------------------------------------------------
1762 //-- Calcul du premier point de cheminement a partir du point approche --
1763 //-----------------------------------------------------------------------
1764 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
1765 if(HasStartPoint) {
1766 //-------------------------------------------------
1767 //-- Un point a ete trouve --
1768 //-- On verifie qu il n appartient pas --
1769 //-- a une ligne de cheminement deja calculee. --
1770 //-------------------------------------------------
1771
1772 PW.Perform(StartParams);
1773 if(PW.IsDone()) {
1774
1775 Point3dDebut = PW.Value(1).Value();
1776 Point3dFin = PW.Value(PW.NbPoints()).Value();
7fd59977 1777
c66d7156
P
1778 IntSurf_TypeTrans trans1,trans2;
1779 Standard_Real locu,locv;
1780 gp_Vec norm1,norm2,d1u,d1v;
1781 gp_Pnt ptbid;
1782 Standard_Integer indextg;
1783 gp_Vec tgline(PW.TangentAtLine(indextg));
1784 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
1785 Surf1->D1(locu,locv,ptbid,d1u,d1v);
1786 norm1 = d1u.Crossed(d1v);
1787 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
1788 Surf2->D1(locu,locv,ptbid,d1u,d1v);
1789 norm2 = d1u.Crossed(d1v);
1790 if (tgline.DotCross(norm2,norm1)>0.) {
1791 trans1 = IntSurf_Out;
1792 trans2 = IntSurf_In;
1793 }
1794 else {
1795 trans1 = IntSurf_In;
1796 trans2 = IntSurf_Out;
1797 }
1798
1799
1800
1801 Standard_Real TolTang = TolTangency;
1802 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
1803 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
1804 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
1805
1806 //---------------
1807 if(wline->NbVertex() == 0) {
1808 IntPatch_Point vtx;
1809 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
1810 POn2S.Parameters(pu1,pv1,pu2,pv2);
1811 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
1812 vtx.SetParameters(pu1,pv1,pu2,pv2);
1813 vtx.SetParameter(1);
1814 wline->AddVertex(vtx);
1815
1816 POn2S = PW.Line()->Value(wline->NbPnts());
1817 POn2S.Parameters(pu1,pv1,pu2,pv2);
1818 vtx.SetValue(Point3dFin,TolTang,Standard_False);
1819 vtx.SetParameters(pu1,pv1,pu2,pv2);
1820 vtx.SetParameter(wline->NbPnts());
1821 wline->AddVertex(vtx);
1822 }
1823
1824 //---------------
1825 SLin.Append(wline);
1826 empt = Standard_False;
1827
1828 }
1829 }
1830}
1831//==================================================================================
1832// function : AdjustOnPeriodic
1833// purpose :
1834//==================================================================================
1835void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
1836 const Handle(Adaptor3d_HSurface)& Surf2,
1837 IntPatch_SequenceOfLine& aSLin)
1838{
1839 Standard_Boolean bIsPeriodic[4], bModified, bIsNull, bIsPeriod;
1840 Standard_Integer i, j, k, aNbLines, aNbPx, aIndx, aIndq;
1841 Standard_Real aPeriod[4], dPeriod[4], ux[4], uq[4], aEps, du;
1842 //
1843 aEps=Precision::Confusion();
1844 //
1845 for (k=0; k<4; ++k) {
1846 aPeriod[k]=0.;
1847 }
1848 //
1849 bIsPeriodic[0]=Surf1->IsUPeriodic();
1850 bIsPeriodic[1]=Surf1->IsVPeriodic();
1851 bIsPeriodic[2]=Surf2->IsUPeriodic();
1852 bIsPeriodic[3]=Surf2->IsVPeriodic();
1853 //
1854 if (bIsPeriodic[0]){
1855 aPeriod[0]=Surf1->UPeriod();
1856 }
1857 if (bIsPeriodic[1]){
1858 aPeriod[1]=Surf1->VPeriod();
1859 }
1860 if (bIsPeriodic[2]){
1861 aPeriod[2]=Surf2->UPeriod();
1862 }
1863 if (bIsPeriodic[3]){
1864 aPeriod[3]=Surf2->VPeriod();
1865 }
1866 //
1867 for (k=0; k<4; ++k) {
1868 dPeriod[k]=0.25*aPeriod[k];
1869 }
1870 //
1871 aNbLines=aSLin.Length();
1872 for (i=1; i<=aNbLines; ++i) {
1873 Handle(IntPatch_WLine) aIL=Handle(IntPatch_WLine)::DownCast(aSLin.Value(i));
1874 Handle(IntSurf_LineOn2S) aL=aIL->Curve();
1875
1876 aNbPx=aL->NbPoints();
1877 if (aNbPx<10) {
1878 continue;
1879 }
1880 //
1881 for (j=0; j<2; ++j) {
1882 bModified=Standard_False;
1883 aIndx=1;
1884 aIndq=2;
1885 if (j) {
1886 aIndx=aNbPx;
1887 aIndq=aNbPx-1;
1888 }
1889 //
1890 const IntSurf_PntOn2S& aPSx=aL->Value(aIndx);
1891 const IntSurf_PntOn2S& aPSq=aL->Value(aIndq);
1892 //
1893 aPSx.Parameters(ux[0], ux[1], ux[2], ux[3]);
1894 aPSq.Parameters(uq[0], uq[1], uq[2], uq[3]);
1895 //
1896 for (k=0; k<4; ++k) {
1897 bIsNull=Standard_False;
1898 bIsPeriod=Standard_False;
1899 //
1900 if (!bIsPeriodic[k]) {
1901 continue;
1902 }
1903 //
1904 if (fabs(ux[k])<aEps) {
1905 bModified=Standard_True;
1906 bIsNull=Standard_True;
1907 }
1908 //
1909 else if (fabs(ux[k]-aPeriod[k])<aEps) {
1910 bModified=Standard_True;
1911 bIsPeriod=Standard_True;
1912 }
1913 //
1914 if (bModified) {
1915 du=fabs(ux[k]-uq[k]);
1916 if (du > dPeriod[k]) {
1917 if(bIsNull){
1918 ux[k]=aPeriod[k];
1919 }
1920 if(bIsPeriod) {
1921 ux[k]=0.;
1922 }
1923 }
1924 }
1925 }//for (k=0; k<4; ++k)
1926 if (bModified) {
1927 IntSurf_PntOn2S aPntOn2S;
1928 //
1929 aPntOn2S=aPSx;
1930 aPntOn2S.SetValue(ux[0], ux[1], ux[2], ux[3]);
1931 aL->Value(aIndx, aPntOn2S);
1932 }
1933 }//for (j=0; j<1; ++j) {
1934 }//for (i=1; i<=aNbLines; ++i)
1935}
1936//==================================================================================
1937// function : Perform
1938// purpose : base SS Int. function
1939//==================================================================================
1940void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
1941 const Handle(Adaptor3d_TopolTool)& D1,
1942 const Handle(Adaptor3d_HSurface)& Surf2,
1943 const Handle(Adaptor3d_TopolTool)& D2,
1944 const Standard_Real TolTangency,
1945 const Standard_Real Epsilon,
1946 const Standard_Real Deflection,
1947 const Standard_Real Increment,
1948 const Standard_Boolean ClearFlag)
1949{
1950 Standard_Integer NbU1, NbV1, NbU2, NbV2, Limit;
1951 //
1952 D1->SamplePnts(Deflection, 10, 10);
1953 D2->SamplePnts(Deflection, 10, 10);
1954 //
1955 NbU1 = D1->NbSamplesU();
1956 NbV1 = D1->NbSamplesV();
1957 NbU2 = D2->NbSamplesU();
1958 NbV2 = D2->NbSamplesV();
1959 TColStd_Array1OfReal anUpars1(1, NbU1), aVpars1(1, NbV1);
1960 TColStd_Array1OfReal anUpars2(1, NbU2), aVpars2(1, NbV2);
1961 //
1962 D1->UParameters(anUpars1);
1963 D1->VParameters(aVpars1);
1964 D2->UParameters(anUpars2);
1965 D2->VParameters(aVpars2);
1966 //---------------------------------------------
1967 Limit = 2500;
1968 if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit)) {
1969 empt = Standard_True;
1970 if (ClearFlag){
1971 SLin.Clear();
1972 }
1973 //
1974 IntPolyh_Intersection* pInterference = NULL;
1975
1976 if ( D1->IsUniformSampling() || D2->IsUniformSampling() ) {
1977 pInterference = new IntPolyh_Intersection(Surf1,NbU1,NbV1,Surf2,NbU2,NbV2);
1978 }
1979 else {
1980 pInterference = new IntPolyh_Intersection(Surf1, anUpars1, aVpars1,
1981 Surf2, anUpars2, aVpars2 );
1982 }
1983 if ( !pInterference ) {
1984 done = Standard_False;
1985 return;
1986 }
1987 //
1988 IntPolyh_Intersection& Interference = *pInterference;
1989 //
1990 done = Interference.IsDone();
1991 if( !done ) {
1992 if (pInterference) {
1993 delete pInterference;
1994 pInterference = NULL;
1995 }
1996 return;
1997 }
1998
1999 Standard_Real Deflection2 = Deflection*Deflection;
2000 Standard_Integer nbLigSec = Interference.NbSectionLines();
2001 Standard_Integer nbTanZon = Interference.NbTangentZones();
2002 Standard_Real SeuildPointLigne = 15.0 * Increment * Increment;
2003
2004 Standard_Integer NbPntOn2SOnLine = 0, NbLigCalculee = 0, ver;
2005 Standard_Real U1,U2,V1,V2, pu1,pu2,pv1,pv2, incidence, dminiPointLigne;
2006 Standard_Boolean HasStartPoint,RejetLigne;
2007 IntSurf_PntOn2S StartPOn2S;
2008 gp_Pnt Point3dDebut,Point3dFin;
2009
2010 TColStd_Array1OfReal StartParams(1,4);
2011 IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment);
2012
2013 if(nbLigSec>=1) {
2014 Standard_Integer *TabL = new Standard_Integer [nbLigSec+1];
2015 Standard_Integer ls;
2016 for(ls=1; ls<=nbLigSec; ++ls){
2017 TabL[ls]=ls;
2018 }
2019 //----------------------------------------1.1
2020 Standard_Boolean triok;
2021 do {
2022 Standard_Integer b, nb_B, nb_A, tyu;
2023 //
2024 triok=Standard_True;
2025 for( b = 2; b <= nbLigSec; ++b ) {
2026 nb_B = Interference.NbPointsInLine(TabL[b]);
2027 nb_A = Interference.NbPointsInLine(TabL[b-1]);
2028 if( nb_B > nb_A ) {
2029 tyu=TabL[b];
2030 TabL[b]=TabL[b-1];
2031 TabL[b-1]=tyu;
2032 triok=Standard_False;
2033 }
2034 }
2035 } while(triok==Standard_False);
2036 //----------------------------------------
2037 // 1.2 For the line "ls" get 2D-bounds U,V for surfaces 1,2
2038 //
2039 for( ls = 1; ls <= nbLigSec; ++ls) {
2040 Standard_Integer nbp, ilig, *TabPtDep;
2041 //
2042 nbp = Interference.NbPointsInLine(TabL[ls]);
7fd59977 2043 if (!nbp) {
2044 continue;
2045 }
7fd59977 2046 //
c66d7156
P
2047 TabPtDep = new Standard_Integer [nbp+1];
2048 for( ilig = 1; ilig <= nbp; ++ilig ) {
7fd59977 2049 TabPtDep[ilig]=0;
c66d7156
P
2050 }
2051 //
7fd59977 2052 Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
2053 Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
2054 Standard_Real _x,_y,_z;
c66d7156
P
2055 //
2056 Interference.GetLinePoint(TabL[ls], 1,
2057 _x,_y,_z,
2058 UminLig1, VminLig1, UminLig2, VminLig2,
2059 incidence);
7fd59977 2060
2061 UmaxLig1=UminLig1;
2062 VmaxLig1=VminLig1;
2063 UmaxLig2=UminLig2;
2064 VmaxLig2=VminLig2;
c66d7156 2065 //
7fd59977 2066 for( ilig = 2; ilig <= nbp; ilig++ ) {
2067 Interference.GetLinePoint(TabL[ls],ilig,_x,_y,_z,U1,V1,U2,V2,incidence);
c66d7156 2068 //
7fd59977 2069 if(U1>UmaxLig1) UmaxLig1=U1;
2070 if(V1>VmaxLig1) VmaxLig1=V1;
2071 if(U2>UmaxLig2) UmaxLig2=U2;
2072 if(V2>VmaxLig2) VmaxLig2=V2;
c66d7156 2073 //
7fd59977 2074 if(U1<UminLig1) UminLig1=U1;
2075 if(V1<VminLig1) VminLig1=V1;
2076 if(U2<UminLig2) UminLig2=U2;
2077 if(V2<VminLig2) VminLig2=V2;
c66d7156
P
2078 }//for( ilig = 2; ilig <= nbp; ilig++ ) {
2079 //
2080 //----------------------------------------
2081 // 1.3
7fd59977 2082 Standard_Integer nbps2 = (nbp>3)? (nbp/2) : 1;
2083 Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
2084 Standard_Boolean lignetrouvee=Standard_False;
2085 const Standard_Integer NbDePointsDeDepartDuChmLimit = 5;
2086 //
2087 do {
2088 NombreDePointsDeDepartDuCheminement++;
2089 switch (NombreDePointsDeDepartDuCheminement) {
2090 case 1:
2091 nbps2 = (nbp > 1) ? nbp/2 : 1;
2092 if(nbp<3)
2093 NombreDePointsDeDepartDuCheminement = NbDePointsDeDepartDuChmLimit;
2094 break;
2095 case 2:
2096 nbps2 = 1;
2097 break;
2098 case 3:
2099 nbps2 = nbp-1;
2100 break;
2101 case 4:
2102 nbps2 = 3 * nbp / 4;
2103 break;
2104 case 5:
2105 nbps2 = nbp / 4;
2106 break;
2107 default:
2108 nbps2 = NombreDePointsDeDepartDuCheminement-3;
2109 NombreDePointsDeDepartDuCheminement++;
2110 }
2111 //
2112 if(TabPtDep[nbps2] == 0) {
2113 TabPtDep[nbps2] = 1;
2114 Interference.GetLinePoint(TabL[ls],nbps2,_x,_y,_z,U1,V1,U2,V2,incidence);
2115
2116 StartParams(1) = U1;
2117 StartParams(2) = V1;
2118 StartParams(3) = U2;
2119 StartParams(4) = V2;
2120
2121 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
2122 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
2123 if(HasStartPoint) {
2124 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
2125 NbLigCalculee = SLin.Length();
2126 Standard_Integer l;
2127 for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) {
2128 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
2129 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
2130 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
2131 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) {
2132 NbPntOn2SOnLine = testwline->NbPnts();
2133 Standard_Integer ll;
2134 for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) {
2135 const gp_Pnt &Pa = testwline->Point(ll).Value();
2136 const gp_Pnt &Pb = testwline->Point(ll+1).Value();
2137 const gp_Pnt &PStart = StartPOn2S.Value();
2138 gp_Vec AM(Pa,PStart);
2139 gp_Vec MB(PStart,Pb);
2140 Standard_Real AMMB = AM.Dot(MB);
2141 if(AMMB > 0.0) {
2142 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
2143 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
2144 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
2145 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
2146 Standard_Real d = 0.0;
2147 if(HM.X() < Deflection) {
2148 d+=HM.X()*HM.X();
2149 if(HM.Y() < Deflection) {
2150 d+=HM.Y()*HM.Y();
2151 if(HM.Z() < Deflection)
2152 d+=HM.Z()*HM.Z();
2153 else
2154 d=Deflection2;
2155 }
2156 else
2157 d=Deflection2;
2158 }
2159 else
2160 d=Deflection2;
2161
2162 if(d<Deflection2)
2163 dminiPointLigne = 0.0;
2164 }
2165 else {
2166 Standard_Real dab = Pa.SquareDistance(Pb);
2167 Standard_Real dap = Pa.SquareDistance(PStart);
2168 if(dap < dab)
2169 dminiPointLigne=0;
2170 else {
2171 Standard_Real dbp = Pb.SquareDistance(PStart);
2172 if(dbp < dab)
2173 dminiPointLigne=0;
2174 }
2175 }
2176 }// for( ll ...
2177 }// if ...
2178 }// for( l ...
2179
2180 if(dminiPointLigne > SeuildPointLigne) {
2181 PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
c66d7156 2182 //
7fd59977 2183 Standard_Boolean bPWIsDone;
2184 Standard_Integer iPWNbPoints, aNbPointsVer;
2185 Standard_Real aD11, aD12, aD21, aD22, aDx;
2186 //
2187 bPWIsDone=PW.IsDone();
7fd59977 2188 if(bPWIsDone) {
2189 iPWNbPoints=PW.NbPoints();
2190 //
2191 if( iPWNbPoints > 2 ) {
2192 RejetLigne = Standard_False;
2193 Point3dDebut = PW.Value(1).Value();
c66d7156
P
2194 Point3dFin = PW.Value(iPWNbPoints).Value();
2195 for( ver = 1; (!RejetLigne) && (ver<= NbLigCalculee); ++ver) {
7fd59977 2196 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
2197 //
2198 aNbPointsVer=verwline->NbPnts();
2199 if (aNbPointsVer<3) {
2200 continue;
2201 }
2202 //
2203 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
2204 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
2205 //xf
2206 const gp_Pnt& aP21=verPointDebut.Value();
2207 const gp_Pnt& aP22=verPointFin.Value();
2208 //
2209 aD11=Point3dDebut.Distance(aP21);
2210 aD12=Point3dDebut.Distance(aP22);
2211 aD21=Point3dFin.Distance(aP21);
2212 aD22=Point3dFin.Distance(aP22);
2213 //
2214 if((aD11<=TolTangency && aD22<=TolTangency) ||
2215 (aD12<=TolTangency && aD21<=TolTangency)) {
2216 Standard_Integer m, mx;
2217 //
2218 mx=aNbPointsVer/2;
2219 if (aNbPointsVer%2) {
2220 ++mx;
2221 }
2222 //
2223 const gp_Pnt& aPx=verwline->Point(mx).Value();
2224 for(m=1; m<iPWNbPoints; ++m){
2225 const gp_Pnt& aP1=PW.Value(m).Value();
2226 const gp_Pnt& aP2=PW.Value(m+1).Value();
2227 gp_Vec aVec12(aP1, aP2);
2228 if (aVec12.SquareMagnitude()<1.e-20){
2229 continue;
2230 }
2231 //
2232 gp_Dir aDir12(aVec12);
2233 gp_Lin aLin12(aP1, aDir12);
2234 aDx=aLin12.Distance(aPx);
c66d7156
P
2235 //modified by NIZNHY-PKV Tue May 10 11:08:07 2011f
2236 if (aDx<=2.*Epsilon) {
2237 //if (aDx<=TolTangency) {
2238 //modified by NIZNHY-PKV Tue May 10 11:08:13 2011t
7fd59977 2239 RejetLigne = Standard_True;
2240 break;
2241 }
c66d7156
P
2242 }//for(m=1; m<iPWNbPoints; ++m){
2243 }//if((aD11<=TolTangency && aD22<=TolTangency) ||...
2244 }// for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
7fd59977 2245 //
2246 if(!RejetLigne) {
2247 IntSurf_TypeTrans trans1,trans2;
2248 Standard_Real locu,locv;
2249 gp_Vec norm1,norm2,d1u,d1v;
2250 gp_Pnt ptbid;
2251 Standard_Integer indextg;
2252 gp_Vec tgline(PW.TangentAtLine(indextg));
2253 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
2254 Surf1->D1(locu,locv,ptbid,d1u,d1v);
2255 norm1 = d1u.Crossed(d1v);
2256 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
2257 Surf2->D1(locu,locv,ptbid,d1u,d1v);
2258 norm2 = d1u.Crossed(d1v);
2259 if( tgline.DotCross(norm2,norm1) >= 0. ) {
2260 trans1 = IntSurf_Out;
2261 trans2 = IntSurf_In;
2262 }
2263 else {
2264 trans1 = IntSurf_In;
2265 trans2 = IntSurf_Out;
2266 }
2267
2268 Standard_Real TolTang = TolTangency;
2269 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
2270 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
2271 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
2272
2273 if(wline->NbVertex() == 0) {
2274 IntPatch_Point vtx;
2275 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
2276 POn2S.Parameters(pu1,pv1,pu2,pv2);
2277 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
2278 vtx.SetParameters(pu1,pv1,pu2,pv2);
2279 vtx.SetParameter(1);
2280 wline->AddVertex(vtx);
2281
2282 POn2S = PW.Line()->Value(wline->NbPnts());
2283 POn2S.Parameters(pu1,pv1,pu2,pv2);
2284 vtx.SetValue(Point3dFin,TolTang,Standard_False);
2285 vtx.SetParameters(pu1,pv1,pu2,pv2);
2286 vtx.SetParameter(wline->NbPnts());
2287 wline->AddVertex(vtx);
2288 }
2289
2290 lignetrouvee = Standard_True;
2291
2292 Standard_Integer slinlen = SLin.Length();
2293 if( slinlen > 0 ) {
2294 Standard_Integer cnbV = wline->NbVertex();
2295 Standard_Integer ciV;
2296 for( ciV = 1; ciV <= cnbV; ciV++ ) {
2297 Standard_Real pntDMin = 1.e+100;
2298 Standard_Integer VDMin = 0;
2299 Standard_Integer WLDMin = 0;
2300 gp_Pnt cPV = wline->Vertex(ciV).Value();
2301 Standard_Integer iL;
2302 for( iL = 1; iL <= slinlen; iL++) {
2303 const Handle(IntPatch_Line)& aSLine = SLin.Value(iL);
2304 IntPatch_IType aType = aSLine->ArcType();
2305 if( aType != IntPatch_Walking)
2306 continue;
2307 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
2308 Standard_Integer tnbV = aWLine->NbVertex();
2309 Standard_Integer tiV;
2310 for( tiV = 1; tiV <= tnbV; tiV++ ) {
2311 gp_Pnt tPV = aWLine->Vertex(tiV).Value();
2312 Standard_Real tDistance = cPV.Distance(tPV);
2313 Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance);
2314 Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance);
2315 Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance);
2316 Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance);
2317 Standard_Real RmaxS1 = Max(uRs1,vRs1);
2318 Standard_Real RmaxS2 = Max(uRs2,vRs2);
2319 if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4) {
2320 if( pntDMin > tDistance && tDistance > 1.e-9) {
2321 pntDMin = tDistance;
2322 VDMin = tiV;
2323 WLDMin = iL;
2324 }
2325 }
2326 }
2327 }
2328
2329 if( VDMin != 0 ) {
2330 const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin);
2331 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
2332 Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine();
2333 Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine();
2334 Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.;
2335 Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.;
2336 wline->Point(ciVpar).Parameters(u11,v11,u12,v12);
2337 aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22);
2338
2339 Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S();
2340 IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar);
2341 Standard_Integer cNbP = wline->NbPnts();
2342
2343 TColStd_SequenceOfInteger VPold;
2344 Standard_Integer iPo;
2345 for( iPo = 1; iPo <= cnbV; iPo++ ) {
2346 Standard_Real Po = wline->Vertex(iPo).ParameterOnLine();
2347 Standard_Integer IPo = (Standard_Integer) Po;
2348 VPold.Append(IPo);
2349 }
2350
2351 Standard_Boolean removeNext = Standard_False;
2352 Standard_Boolean removePrev = Standard_False;
2353 if( ciV == 1) {
2354 Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
2355 if(dPar > 10) {
2356 removeNext = Standard_True;
2357 for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
2358 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
2359 }
2360 }
2361 else if( ciV == cnbV) {
2362 Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
2363 if(dPar > 10) {
2364 removePrev = Standard_True;
2365 VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
2366 }
2367 }
2368 else {
2369 Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
2370 Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
2371 if(dParMi > 10) {
2372 removePrev = Standard_True;
2373 VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
2374 }
2375 if(dParMa > 10) {
2376 removeNext = Standard_True;
2377 for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) {
2378 if(dParMi > 10)
2379 VPold.SetValue(iPo, VPold.Value(iPo) - 2 );
2380 else
2381 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
2382 }
2383 }
2384 else {
2385 if(dParMi > 10)
2386 for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
2387 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
2388 }
2389 }
2390 Standard_Integer pI = (Standard_Integer) ciVpar;
2391
2392 Standard_Integer iP;
2393 for( iP = 1; iP <= cNbP; iP++) {
2394 if( pI == iP )
2395 newL2s->Add(replacePnt);
2396 else if(removeNext && iP == (pI + 1))
2397 continue;
2398 else if(removePrev && iP == (pI - 1))
2399 continue;
2400 else
2401 newL2s->Add(wline->Point(iP));
2402 }
2403
2404 IntPatch_Point newVtx;
2405 gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value();
2406 newVtx.SetValue(Pnt3dV,TolTang,Standard_False);
2407 newVtx.SetParameters(u21,v21,u22,v22);
2408 newVtx.SetParameter(VPold.Value(ciV));
2409
2410 Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2);
2411
2412 Standard_Integer iV;
2413 for( iV = 1; iV <= cnbV; iV++ ) {
2414 if( iV == ciV )
2415 NWLine->AddVertex(newVtx);
2416 else {
2417 IntPatch_Point theVtx = wline->Vertex(iV);
2418 theVtx.SetParameter(VPold.Value(iV));
2419 NWLine->AddVertex(theVtx);
2420 }
2421 }
2422
2423 wline = NWLine;
2424 }
2425 }
2426 }// SLin.Length > 0
2427
2428 SLin.Append(wline);
2429 empt = Standard_False;
2430 }// !RejetLigne
2431 }// PW points > 2
2432 }// done is True
2433 }// dminiPointLigne > SeuildPointLigne
2434 }// HasStartPoint
2435 }// if TabPtDep[nbps2] == 0
2436 } while(nbp>5 && !( (NombreDePointsDeDepartDuCheminement >= NbDePointsDeDepartDuChmLimit && lignetrouvee) ||
2437 (NombreDePointsDeDepartDuCheminement-3 >= nbp && (!lignetrouvee))));
2438 delete [] TabPtDep;
2439 }// for( ls ...
2440
2441 delete [] TabL;
2442
2443 }// if nbLigSec >= 1
2444 //
2445 AdjustOnPeriodic(Surf1, Surf2, SLin);
2446 //
2447
2448 //--------------------------------------------------------------------
2449 //-- Calcul des parametres approches a partir des Zones De Tangence --
2450 //--------------------------------------------------------------------
2451 Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
2452 Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
2453
2454 UminLig1=VminLig1=UminLig2=VminLig2=RealLast();
2455 UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1;
2456
2457 // NbPointsInTangentZone always == 1 (eap)
2458
2459 Standard_Integer z;
2460 for( z=1; z <= nbTanZon; z++) {
2461 //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z);
2462 //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) {
2463 Standard_Integer pz=1;
2464 Standard_Real _x,_y,_z;
2465 Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
2466
2467 if(U1>UmaxLig1) UmaxLig1=U1;
2468 if(V1>VmaxLig1) VmaxLig1=V1;
2469 if(U2>UmaxLig2) UmaxLig2=U2;
2470 if(V2>VmaxLig2) VmaxLig2=V2;
2471
2472 if(U1<UminLig1) UminLig1=U1;
2473 if(V1<VminLig1) VminLig1=V1;
2474 if(U2<UminLig2) UminLig2=U2;
2475 if(V2<VminLig2) VminLig2=V2;
2476 //}
2477 }
2478 for(z=1; z <= nbTanZon; z++) {
2479
2480 //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z);
2481 //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) {
2482 Standard_Integer pz=1;
2483 Standard_Real _x,_y,_z;
2484 Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
2485
2486 StartParams(1) = U1;
2487 StartParams(2) = V1;
2488 StartParams(3) = U2;
2489 StartParams(4) = V2;
2490
2491 //-----------------------------------------------------------------------
2492 //-- Calcul du premier point de cheminement a partir du point approche --
2493 //-----------------------------------------------------------------------
2494 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
2495 if(HasStartPoint) {
2496 //-------------------------------------------------
2497 //-- Un point a ete trouve --
2498 //-- On verifie qu il n appartient pas --
2499 //-- a une ligne de cheminement deja calculee. --
2500 //-------------------------------------------------
2501 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
2502
2503 NbLigCalculee = SLin.Length();
2504 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
2505
2506 for(Standard_Integer l=1;
2507 (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne);
2508 l++) {
2509 Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.ChangeValue(l));
2510
2511 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False)
2512 &&(testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False)
2513 &&(testwline->IsOutBox(StartPOn2S.Value())==Standard_False)) {
2514
2515
2516 //-- Handle(IntPatch_WLine) testwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(l));
2517 NbPntOn2SOnLine = testwline->NbPnts();
2518 for(Standard_Integer ll=1;
2519 (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne);
2520 ll++) {
2521 const gp_Pnt& Pa = testwline->Point(ll).Value();
2522 const gp_Pnt& Pb = testwline->Point(ll+1).Value();
2523 const gp_Pnt& PStart=StartPOn2S.Value();
2524 gp_Vec AM(Pa,PStart);
2525 gp_Vec MB(PStart,Pb);
2526 Standard_Real AMMB = AM.Dot(MB);
2527 if(AMMB > 0.0) {
2528 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
2529 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
2530 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
2531 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
2532
2533 Standard_Real d = 0.0;
2534 if(HM.X() < Deflection) {
2535 d+=HM.X()*HM.X();
2536 if(HM.Y() < Deflection) {
2537 d+=HM.Y()*HM.Y();
2538 if(HM.Z() < Deflection) {
2539 d+=HM.Z()*HM.Z();
2540 }
2541 else {
2542 d=Deflection2;
2543 }
2544 }
2545 else {
2546 d=Deflection2;
2547 }
2548 }
2549 else {
2550 d=Deflection2;
2551 }
2552 if(d<Deflection2) {
2553 dminiPointLigne = 0.0;
2554 }
2555 }
2556 else {
2557 Standard_Real dab = Pa.Distance(Pb);
2558 Standard_Real dap = Pa.Distance(PStart);
2559 if(dap < dab) {
2560 dminiPointLigne=0;
2561 }
2562 else {
2563 Standard_Real dbp = Pb.Distance(PStart);
2564 if(dbp < dab) {
2565 dminiPointLigne=0;
2566 }
2567 }
2568 }
2569 }
2570 } //-- rejection sur les boites
2571 }
2572
2573
2574 //-- Fin d exploration des lignes
c66d7156
P
2575 if(dminiPointLigne > SeuildPointLigne) {
2576 //---------------------------------------------------
2577 //-- Le point de depart du nouveau cheminement --
2578 //-- n est present dans aucune ligne deja calculee.--
2579 //---------------------------------------------------
2580 PW.Perform(StartParams,
2581 UminLig1,VminLig1,UminLig2,VminLig2,
2582 UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
2583 if(PW.IsDone()) {
2584 if(PW.NbPoints()>2) {
2585 //-----------------------------------------------
2586 //-- Verification a posteriori :
2587 //-- On teste si le point de depart et de fin de
2588 //-- la ligne de cheminement est present dans une
2589 //-- autre ligne .
2590 //-----------------------------------------------
2591 RejetLigne = Standard_False;
2592 Point3dDebut = PW.Value(1).Value();
2593 Point3dFin = PW.Value(PW.NbPoints()).Value();
2594
2595 for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
2596 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
2597 //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
2598 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
2599 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
2600 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) {
2601 RejetLigne = Standard_True;
2602 }
2603 else {
2604 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) {
2605 RejetLigne = Standard_True;
2606 }
2607 }
2608 }
2609
2610 if(!RejetLigne) {
7fd59977 2611
c66d7156
P
2612 IntSurf_TypeTrans trans1,trans2;
2613 Standard_Real locu,locv;
2614 gp_Vec norm1,norm2,d1u,d1v;
2615 gp_Pnt ptbid;
2616 Standard_Integer indextg;
2617 gp_Vec tgline(PW.TangentAtLine(indextg));
2618 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
2619 Surf1->D1(locu,locv,ptbid,d1u,d1v);
2620 norm1 = d1u.Crossed(d1v);
2621 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
2622 Surf2->D1(locu,locv,ptbid,d1u,d1v);
2623 norm2 = d1u.Crossed(d1v);
2624 if (tgline.DotCross(norm2,norm1)>0.) {
2625 trans1 = IntSurf_Out;
2626 trans2 = IntSurf_In;
2627 }
2628 else {
2629 trans1 = IntSurf_In;
2630 trans2 = IntSurf_Out;
2631 }
2632
2633
2634
2635 Standard_Real TolTang = TolTangency;
2636 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
2637 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
2638 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
2639
2640 //---------------
2641 if(wline->NbVertex() == 0) {
2642 IntPatch_Point vtx;
2643 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
2644 POn2S.Parameters(pu1,pv1,pu2,pv2);
2645 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
2646 vtx.SetParameters(pu1,pv1,pu2,pv2);
2647 vtx.SetParameter(1);
2648 wline->AddVertex(vtx);
2649
2650 POn2S = PW.Line()->Value(wline->NbPnts());
2651 POn2S.Parameters(pu1,pv1,pu2,pv2);
2652 vtx.SetValue(Point3dFin,TolTang,Standard_False);
2653 vtx.SetParameters(pu1,pv1,pu2,pv2);
2654 vtx.SetParameter(wline->NbPnts());
2655 wline->AddVertex(vtx);
2656 }
2657
2658 //---------------
2659 SLin.Append(wline);
2660 empt = Standard_False;
2661
2662 }
2663 else {
2664 //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
2665 }
2666 //------------------------------------------------------------
2667 }
2668 } //-- le cheminement a reussi (done a True)
2669 } //-- le point approche ne renvoie pas sur une ligne existante
2670 } //-- Si HasStartPoint
2671 //} //-- Boucle Sur les Points de la Tangent Zone
2672 } //-- Boucle sur Les Tangent Zones
7fd59977 2673
c66d7156
P
2674 if ( pInterference ) {
2675 delete pInterference;
2676 pInterference = NULL;
2677 }
2678 return;
2679 }// if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit)) {
2680
2681 Handle(IntSurf_LineOn2S) LOn2S = new IntSurf_LineOn2S();
2682 PointDepart( LOn2S, Surf1, NbU1, NbV1, Surf2, NbU2, NbV2 );
7fd59977 2683 empt = Standard_True;
2684 done = Standard_True;
2685 SLin.Clear();
c66d7156 2686 Standard_Real Deflection2 = Deflection*Deflection;
7fd59977 2687
c66d7156
P
2688 Standard_Integer NbPntOn2SOnLine;
2689 Standard_Integer NbLigCalculee = 0;
2690 Standard_Real U1,U2,V1,V2;
7fd59977 2691 Standard_Real pu1,pu2,pv1,pv2;
2692
2693 TColStd_Array1OfReal StartParams(1,4);
c66d7156
P
2694 Standard_Integer MaxOscill = NbU1;
2695 if(MaxOscill < NbU2) MaxOscill=NbU2;
2696 if(MaxOscill < NbV1) MaxOscill=NbV1;
2697 if(MaxOscill < NbV2) MaxOscill=NbV2;
7fd59977 2698
c66d7156
P
2699 Standard_Real nIncrement=Increment;
2700 //if(MaxOscill>10)
2701 //nIncrement/=0.5*MaxOscill;
2702
2703 IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,nIncrement);
2704 Standard_Real SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
2705 Standard_Real dminiPointLigne;
2706 Standard_Boolean HasStartPoint,RejetLigne;
7fd59977 2707 IntSurf_PntOn2S StartPOn2S;
c66d7156 2708 Standard_Integer ver;
7fd59977 2709 gp_Pnt Point3dDebut,Point3dFin;
c66d7156 2710
7fd59977 2711 //------------------------------------------------------------
c66d7156
P
2712 //-- Calcul des parametres approches a partir des Zones De Tangence --
2713 //--------------------------------------------------------------------
2714 Standard_Integer nbTanZon = LOn2S->NbPoints();
2715 for(Standard_Integer z=1; z <= nbTanZon; z++) {
2716 const IntSurf_PntOn2S& POn2S = LOn2S->Value(z);
2717 POn2S.Parameters(U1,V1,U2,V2);
2718 StartParams(1) = U1;
2719 StartParams(2) = V1;
2720 StartParams(3) = U2;
2721 StartParams(4) = V2;
7fd59977 2722
c66d7156
P
2723 //-----------------------------------------------------------------------
2724 //-- Calcul du premier point de cheminement a partir du point approche --
2725 //-----------------------------------------------------------------------
2726 HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
2727 if(HasStartPoint) {
2728 //-------------------------------------------------
2729 //-- Un point a ete trouve --
2730 //-- On verifie qu il n appartient pas --
2731 //-- a une ligne de cheminement deja calculee. --
2732 //-------------------------------------------------
2733 StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
7fd59977 2734
c66d7156
P
2735 NbLigCalculee = SLin.Length();
2736 dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
7fd59977 2737
c66d7156
P
2738 for(Standard_Integer l=1;
2739 (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne);
2740 l++) {
2741 const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
7fd59977 2742
c66d7156
P
2743 if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False)
2744 &&(testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False)
2745 &&(testwline->IsOutBox(StartPOn2S.Value())==Standard_False)) {
2746
2747 NbPntOn2SOnLine = testwline->NbPnts();
2748 for(Standard_Integer ll=1;
2749 (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne);
2750 ll++) {
2751
2752 const gp_Pnt& Pa = testwline->Point(ll).Value();
2753 const gp_Pnt& Pb = testwline->Point(ll+1).Value();
2754 const gp_Pnt& PStart=StartPOn2S.Value();
2755 gp_Vec AM(Pa,PStart);
2756 gp_Vec MB(PStart,Pb);
2757 Standard_Real AMMB = AM.Dot(MB);
2758 if(AMMB > 0.0) {
2759 gp_Dir ABN(Pb.X()-Pa.X(),Pb.Y()-Pa.Y(),Pb.Z()-Pa.Z());
2760 Standard_Real lan = ABN.X()*AM.X()+ABN.Y()*AM.Y()+ABN.Z()*AM.Z();
2761 gp_Vec AH(lan*ABN.X(),lan*ABN.Y(),lan*ABN.Z());
2762 gp_Vec HM(AM.X()-AH.X(),AM.Y()-AH.Y(),AM.Z()-AH.Z());
2763
2764 Standard_Real d = 0.0;
2765 if(HM.X() < Deflection) {
2766 d+=HM.X()*HM.X();
2767 if(HM.Y() < Deflection) {
2768 d+=HM.Y()*HM.Y();
2769 if(HM.Z() < Deflection) {
2770 d+=HM.Z()*HM.Z();
2771 }
2772 else {
2773 d=Deflection2;
2774 }
2775 }
2776 else {
2777 d=Deflection2;
2778 }
2779 }
2780 else {
2781 d=Deflection2;
2782 }
2783 if(d<Deflection2) {
2784 dminiPointLigne = 0.0;
2785 }
2786 }
2787 else {
2788 Standard_Real dab = Pa.Distance(Pb);
2789 Standard_Real dap = Pa.Distance(PStart);
2790 if(dap < dab) {
2791 dminiPointLigne=0;
2792 }
2793 else {
2794 Standard_Real dbp = Pb.Distance(PStart);
2795 if(dbp < dab) {
2796 dminiPointLigne=0;
2797 }
2798 }
2799 }
2800 }
2801 } //-- Rejections Boites
2802 //-- else {
2803 //-- cout<<" Rejet Boites "<<endl;
2804 //-- }
7fd59977 2805 }
2806
7fd59977 2807
c66d7156
P
2808 //-- Fin d exploration des lignes
2809 if(dminiPointLigne > SeuildPointLigne) {
2810 //---------------------------------------------------
2811 //-- Le point de depart du nouveau cheminement --
2812 //-- n est present dans aucune ligne deja calculee.--
2813 //---------------------------------------------------
2814 PW.Perform(StartParams);
2815 if(PW.IsDone()) {
2816 if(PW.NbPoints()>2) {
2817 //-----------------------------------------------
2818 //-- Verification a posteriori :
2819 //-- On teste si le point de depart et de fin de
2820 //-- la ligne de cheminement est present dans une
2821 //-- autre ligne .
2822 //-----------------------------------------------
2823 RejetLigne = Standard_False;
2824 Point3dDebut = PW.Value(1).Value();
2825 Point3dFin = PW.Value(PW.NbPoints()).Value();
2826
2827 for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) {
2828 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
2829 //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
2830 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
2831 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
2832 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) {
2833 RejetLigne = Standard_True;
2834 }
2835 else {
2836 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) {
2837 RejetLigne = Standard_True;
2838 }
2839 }
2840 }
2841
2842 if(!RejetLigne) {
2843
2844 IntSurf_TypeTrans trans1,trans2;
2845 Standard_Real locu,locv;
2846 gp_Vec norm1,norm2,d1u,d1v;
2847 gp_Pnt ptbid;
2848 Standard_Integer indextg;
2849 gp_Vec tgline(PW.TangentAtLine(indextg));
2850 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
2851 Surf1->D1(locu,locv,ptbid,d1u,d1v);
2852 norm1 = d1u.Crossed(d1v);
2853 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
2854 Surf2->D1(locu,locv,ptbid,d1u,d1v);
2855 norm2 = d1u.Crossed(d1v);
2856 if (tgline.DotCross(norm2,norm1)>0.) {
2857 trans1 = IntSurf_Out;
2858 trans2 = IntSurf_In;
2859 }
2860 else {
2861 trans1 = IntSurf_In;
2862 trans2 = IntSurf_Out;
2863 }
2864
2865
2866
2867 Standard_Real TolTang = TolTangency;
2868 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
2869 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
2870 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
2871
2872 //---------------
2873 if(wline->NbVertex() == 0) {
2874 IntPatch_Point vtx;
2875 const IntSurf_PntOn2S& POn2Sf = PW.Line()->Value(1);
2876 POn2Sf.Parameters(pu1,pv1,pu2,pv2);
2877 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
2878 vtx.SetParameters(pu1,pv1,pu2,pv2);
2879 vtx.SetParameter(1);
2880 wline->AddVertex(vtx);
2881
2882 const IntSurf_PntOn2S& POn2Sl = PW.Line()->Value(wline->NbPnts());
2883 POn2Sl.Parameters(pu1,pv1,pu2,pv2);
2884 vtx.SetValue(Point3dFin,TolTang,Standard_False);
2885 vtx.SetParameters(pu1,pv1,pu2,pv2);
2886 vtx.SetParameter(wline->NbPnts());
2887 wline->AddVertex(vtx);
2888 }
2889
2890 //---------------
2891 SLin.Append(wline);
2892 empt = Standard_False;
2893
2894 }
2895 else {
2896 //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
2897 }
2898 //------------------------------------------------------------
2899 }
2900 } //-- le cheminement a reussi (done a True)
2901 } //-- le point approche ne renvoie pas sur une ligne existante
2902 } //-- Si HasStartPoint
2903 } //-- Boucle sur Les Tangent Zones
2904
7fd59977 2905}
c66d7156
P
2906//modified by NIZNHY-PKV Wed May 25 09:39:07 2011f
2907//=======================================================================
2908//class : IntPatch_InfoPD
2909//purpose :
2910//=======================================================================
2911class IntPatch_InfoPD {
2912 public:
2913 //----------------------------------------C-tor
2914 IntPatch_InfoPD(const Standard_Integer aNBI) {
2915 Standard_Integer aNBI2, i, j;
2916 myNBI=aNBI;
2917 //
2918 aNBI2=aNBI*aNBI;
2919 myP1DS2=new char[aNBI2];
2920 myP2DS1=new char[aNBI2];
2921 myIP1=new Standard_Integer[aNBI2];
2922 myIP2=new Standard_Integer[aNBI2];
2923 myP1=new gp_Pnt[aNBI2];
2924 myP2=new gp_Pnt[aNBI2];
2925 //
2926 for (i=0; i<myNBI; ++i) {
2927 for (j=0; j<myNBI; ++j) {
2928 xP1DS2(i, j)=0;
2929 xP2DS1(i, j)=0;
2930 xIP1(i, j)=0;
2931 xIP2(i, j)=0;
2932 xP1(i, j).SetCoord(0., 0., 0.);
2933 xP2(i, j).SetCoord(0., 0., 0.);
2934 }
2935 }
2936 };
2937 //---------------------------------------- D-tor
2938 ~IntPatch_InfoPD() {
2939 delete [] (char*) myP1DS2;
2940 delete [] (char*) myP2DS1;
2941 delete [] (Standard_Integer*) myIP1;
2942 delete [] (Standard_Integer*) myIP2;
2943 delete [] (gp_Pnt*)myP1;
2944 delete [] (gp_Pnt*)myP2;
2945 };
2946 //---------------------------------------- Index
2947 Standard_Integer Index(const Standard_Integer i,
2948 const Standard_Integer j) const {
2949 return i*myNBI+j;
2950 };
2951 //---------------------------------------- NBI
2952 Standard_Integer NBI() const {
2953 return myNBI;
2954 };
2955 //----------------------------------------xP1DS2
2956 char& xP1DS2(const Standard_Integer i,
2957 const Standard_Integer j) {
2958 return myP1DS2[Index(i,j)];
2959 };
2960 //----------------------------------------xP2DS1
2961 char& xP2DS1(const Standard_Integer i,
2962 const Standard_Integer j) {
2963 return myP2DS1[Index(i,j)];
2964 };
2965 //----------------------------------------xIP1
2966 Standard_Integer& xIP1(const Standard_Integer i,
2967 const Standard_Integer j) {
2968 return myIP1[Index(i,j)];
2969 };
2970 //----------------------------------------xIP2
2971 Standard_Integer& xIP2(const Standard_Integer i,
2972 const Standard_Integer j) {
2973 return myIP2[Index(i,j)];
2974 };
2975 //----------------------------------------xP1
2976 gp_Pnt& xP1(const Standard_Integer i,
2977 const Standard_Integer j) {
2978 return myP1[Index(i,j)];
2979 };
2980 //----------------------------------------xP1
2981 gp_Pnt& xP2(const Standard_Integer i,
2982 const Standard_Integer j) {
2983 return myP2[Index(i,j)];
2984 };
2985 protected:
2986 Standard_Integer myNBI;
2987 char *myP1DS2;
2988 char *myP2DS1;
2989 Standard_Integer *myIP1;
2990 Standard_Integer *myIP2;
2991 gp_Pnt *myP1;
2992 gp_Pnt *myP2;
2993};
2994//modified by NIZNHY-PKV Tue May 24 11:38:55 2011t
7fd59977 2995//==================================================================================
c66d7156 2996// function : PointDepart
7fd59977 2997// purpose :
2998//==================================================================================
c66d7156
P
2999void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S,
3000 const Handle(Adaptor3d_HSurface)& S1,
3001 const Standard_Integer SU_1,
3002 const Standard_Integer SV_1,
3003 const Handle(Adaptor3d_HSurface)& S2,
3004 const Standard_Integer SU_2,
3005 const Standard_Integer SV_2) const
3006{
3007 Standard_Integer i, j, xNBI;
3008 //modified by NIZNHY-PKV Tue May 24 11:37:38 2011f
3009 xNBI=200;
3010 IntPatch_InfoPD aIPD(xNBI);
3011 //modified by NIZNHY-PKV Wed May 25 06:47:12 2011t
3012 Standard_Integer iC15, SU1, SV1, SU2, SV2;
3013 Standard_Real U0, U1, V0, V1, U, V;
3014 Standard_Real resu0,resu1,resv0,resv1;
3015 Standard_Real du1,du2,dv1,dv2, dmaxOn1, dmaxOn2;
3016 Standard_Real x0,y0,z0, x1,y1,z1,d;
3017 Bnd_Box Box1, Box2;
7fd59977 3018 //
c66d7156
P
3019 iC15=15;
3020 SU1 =iC15*SU_1 ;
3021 SV1 =iC15*SV_1 ;
3022 SU2 =iC15*SU_2 ;
3023 SV2 =iC15*SV_2 ;
7fd59977 3024 //
c66d7156
P
3025 if(xNBI<SU1) {
3026 SU1 = xNBI;
3027 }
3028 if(xNBI<SV1){
3029 SV1 = xNBI;
3030 }
3031 if(xNBI<SU2){
3032 SU2 = xNBI;
3033 }
3034 if(xNBI<SV2){
3035 SV2 = xNBI;
3036 }
3037 //
3038 U0 = S1->FirstUParameter();
3039 U1 = S1->LastUParameter();
3040 V0 = S1->FirstVParameter();
3041 V1 = S1->LastVParameter();
3042 //
3043 resu0=U0;
3044 resu1=U1;
3045 resv1=V1;
3046 resv0=V0;
3047 //
3048 dmaxOn1 = 0.0;
3049 dmaxOn2 = 0.0;
3050 //-----
3051 du1 = (U1-U0)/(SU1-1);
3052 dv1 = (V1-V0)/(SV1-1);
3053 for(U=U0,i=0; i<SU1; i++,U+=du1) {
3054 for(V=V0,j=0; j<SV1; V+=dv1,j++) {
3055 aIPD.xP1(i, j)= S1->Value(U,V);
3056 Box1.Add(aIPD.xP1(i, j));
3057 if(i>0 && j>0) {
3058 aIPD.xP1(i, j) .Coord(x0,y0,z0);
3059 aIPD.xP1(i-1, j-1).Coord(x1,y1,z1);
3060 //
3061 d=Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
3062 if(d>dmaxOn1) {
3063 dmaxOn1 = d;
3064 }
3065 }
3066 }
3067 }
3068 Box1.Enlarge(1.e-8);
3069 //
3070 U0 = S2->FirstUParameter();
3071 U1 = S2->LastUParameter();
3072 V0 = S2->FirstVParameter();
3073 V1 = S2->LastVParameter();
3074 //
3075 du2 = (U1-U0)/(SU2-1);
3076 dv2 = (V1-V0)/(SV2-1);
3077 for(U=U0,i=0; i<SU2; i++,U+=du2) {
3078 for(V=V0,j=0; j<SV2; V+=dv2,j++) {
3079 aIPD.xP2(i, j) = S2->Value(U,V);
3080 Box2.Add(aIPD.xP2(i, j));
3081 if(i>0 && j>0) {
3082 aIPD.xP2(i, j) .Coord(x0,y0,z0);
3083 aIPD.xP2(i-1, j-1).Coord(x1,y1,z1);
3084 d = Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
3085 if(d>dmaxOn2) {
3086 dmaxOn2 = d;
3087 }
3088 }
3089 }
3090 }
3091 Box2.Enlarge(1.e-8);
3092 //--------
3093 //
3094 if(Box1.IsOut(Box2)) {
3095
3096 return;
3097 }
3098 //
3099 Standard_Integer aNbPG;
3100 Standard_Real x10,y10,z10,x11,y11,z11;
3101 Standard_Real x20,y20,z20,x21,y21,z21;
3102 Standard_Real dx, dy, dz, dmax;
3103 Standard_Real dx2, dy2, dz2;
3104 //
3105 Box1.Get(x10,y10,z10,x11,y11,z11);
3106 Box2.Get(x20,y20,z20,x21,y21,z21);
3107 //
3108 x0 = (x10>x20)? x10 : x20;
3109 y0 = (y10>y20)? y10 : y20;
3110 z0 = (z10>z20)? z10 : z20;
3111 //
3112 x1 = (x11<x21)? x11 : x21;
3113 y1 = (y11<y21)? y11 : y21;
3114 z1 = (z11<z21)? z11 : z21;
3115 //
3116 if(dmaxOn2 > dmaxOn1) {
3117 dmaxOn1 = dmaxOn2;
7fd59977 3118 }
3119 //
c66d7156
P
3120 dmaxOn1+=dmaxOn1;
3121 x0-=dmaxOn1;
3122 y0-=dmaxOn1;
3123 z0-=dmaxOn1;
3124 x1+=dmaxOn1;
3125 y1+=dmaxOn1;
3126 z1+=dmaxOn1;
3127 //
3128 x10-=dmaxOn1; y10-=dmaxOn1; z10-=dmaxOn1;
3129 x11+=dmaxOn1; y11+=dmaxOn1; z11+=dmaxOn1;
3130
3131 x20-=dmaxOn1; y20-=dmaxOn1; z20-=dmaxOn1;
3132 x21+=dmaxOn1; y21+=dmaxOn1; z21+=dmaxOn1;
3133
3134 aNbPG=NbPointsGrille();
3135 dx = (x1-x0)/aNbPG;
3136 dy = (y1-y0)/aNbPG;
3137 dz = (z1-z0)/aNbPG;
7fd59977 3138 //
c66d7156
P
3139 dmax = dx;
3140 if(dy>dmax) {
3141 dmax = dy;
7fd59977 3142 }
c66d7156
P
3143 if(dz>dmax){
3144 dmax = dz;
7fd59977 3145 }
c66d7156
P
3146 //
3147 if(dx<dmax*0.01) {
3148 dx = dmax*0.01;
7fd59977 3149 }
c66d7156
P
3150 if(dy<dmax*0.01) {
3151 dy = dmax*0.01;
3152 }
3153 if(dz<dmax*0.01) {
3154 dz = dmax*0.01;
7fd59977 3155 }
3156 //
c66d7156
P
3157 dx2 = dx*0.5;
3158 dy2 = dy*0.5;
3159 dz2 = dz*0.5 ;
3160 //
3161 IntPatch_PrmPrmIntersection_T3Bits M1(_BASE);
3162 IntPatch_PrmPrmIntersection_T3Bits M2(_BASE);
3163 //
3164 for(i=0;i<SU1;i++) {
3165 for(j=0;j<SV1;j++) {
3166 aIPD.xIP1(i, j)=-1;
3167 const gp_Pnt& P=aIPD.xP1(i, j);
3168 aIPD.xP1DS2(i, j) = CodeReject(x20,y20,z20,x21,y21,z21,P.X(),P.Y(),P.Z());
3169 int ix = (int)((P.X()-x0 + dx2 )/dx);
3170 if(DansGrille(ix)) {
3171 int iy = (int)((P.Y()-y0 + dy2)/dy);
3172 if(DansGrille(iy)) {
3173 int iz = (int)((P.Z()-z0 + dz2)/dz);
3174 if(DansGrille(iz)) {
3175 aIPD.xIP1(i, j) = GrilleInteger(ix,iy,iz);
3176 }
3177 }
3178 }
3179 }
3180 }
3181 //-- cout<<" Grille du 1 fini "<<endl;
3182 for(i=0;i<SU2;i++) {
3183 for(j=0;j<SV2;j++) {
3184 aIPD.xIP2(i, j)=-1;
3185 const gp_Pnt& P=aIPD.xP2(i, j);
3186 aIPD.xP2DS1(i, j) = CodeReject(x10,y10,z10,x11,y11,z11,P.X(),P.Y(),P.Z());
3187 int ix = (int)((P.X()-x0 + dx2)/dx);
3188 if(DansGrille(ix)) {
3189 int iy = (int)((P.Y()-y0 + dy2)/dy);
3190 if(DansGrille(iy)) {
3191 int iz = (int)((P.Z()-z0 + dz2)/dz);
3192 if(DansGrille(iz)) {
3193 aIPD.xIP2(i, j) = GrilleInteger(ix,iy,iz);
3194 }
3195 }
3196 }
3197 }
7fd59977 3198 }
3199 //
c66d7156
P
3200 for(i=0;i<SU1-1;i+=1) {
3201 for(j=0;j<SV1-1;j+=1) {
3202 if(!((aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j)) ||
3203 (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))){
3204 Remplit(aIPD.xIP1(i, j),
3205 aIPD.xIP1(i+1, j),
3206 aIPD.xIP1(i+1, j+1),
3207 M1);
3208 }
3209 if(!((aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i, j+1)) ||
3210 (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))) {
3211 Remplit(aIPD.xIP1(i, j),
3212 aIPD.xIP1(i, j+1),
3213 aIPD.xIP1(i+1, j+1),
3214 M1);
3215 }
7fd59977 3216 }
c66d7156
P
3217 }
3218 //
3219 for(i=0;i<SU2-1;i+=1) {
3220 for(j=0;j<SV2-1;j+=1) {
3221 if(!((aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j)) ||
3222 (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
3223 Remplit(aIPD.xIP2(i, j),
3224 aIPD.xIP2(i+1, j),
3225 aIPD.xIP2(i+1, j+1),
3226 M2);
3227 }
3228 if(!((aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i, j+1)) ||
3229 (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
3230 Remplit(aIPD.xIP2(i, j),
3231 aIPD.xIP2(i, j+1),
3232 aIPD.xIP2(i+1, j+1),
3233 M2);
3234 }
3235 }
3236 }
3237 //
3238 M1.ResetAnd();
3239 M2.ResetAnd();
3240 //
3241 int newind=0;
3242 long unsigned Compt=0;
3243 int ok=0;
3244 int indicepointtraite = 0;
3245 Standard_Integer k,nu,nv;
3246 //
3247 do {
3248 indicepointtraite--;
3249 ok = M1.And(M2,newind);
3250 if(ok) {
3251 IntegerGrille(newind,i,j,k);
3252 int nb=0;
3253 int LIM=3;
3254 if( DansGrille(i-1) && DansGrille(j-1) && DansGrille(k-1)
3255 && DansGrille(i+1) && DansGrille(j+1) && DansGrille(k+1)) {
3256 int si,sj,sk;
3257 for(si=-1; si<= 1 && nb<LIM; si++) {
3258 for(sj=-1; sj<= 1 && nb<LIM; sj++) {
3259 for(sk=-1; sk<= 1 && nb<LIM; sk++) {
3260 long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
3261 if(M1.Val(lu) && M2.Val(lu)) {
3262 nb++;
3263 }
3264 }
3265 }
3266 }
3267 if(nb>=LIM) {
3268 for(si=-1; si<= 1; si++) {
3269 for(sj=-1; sj<= 1; sj++) {
3270 for(sk=-1; sk<= 1; sk++) {
3271 if(si || sj || sk) {
3272 long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
3273 M1.Raz(lu);
3274 }
3275 }
3276 }
3277 }
3278 }
7fd59977 3279 }
3280 //
c66d7156 3281 gp_Pnt P(dx*i + x0, dy*j + y0, dz*k+z0);
7fd59977 3282 //
c66d7156
P
3283 Standard_Integer nu1=-1,nu2=-1;
3284 Standard_Integer nv1=0, nv2=0;
3285 int nbsur1 = 0;
3286 for(nu=0;nu1<0 && nu<SU1;nu++) {
3287 for(nv=0;nu1<0 && nv<SV1;nv++) {
3288 if( aIPD.xIP1(nu, nv) ==(Standard_Integer) newind ) {
3289 nbsur1++;
3290 aIPD.xIP1(nu, nv)=indicepointtraite;
3291 nu1=nu; nv1=nv;
3292 }
7fd59977 3293 }
c66d7156
P
3294 }
3295 if(nu1>=0) {
3296 int nbsur2 = 0;
3297 for(nu=0;nu2<0 && nu<SU2;nu++) {
3298 for(nv=0;nu2<0 && nv<SV2;nv++) {
3299 if( aIPD.xIP2(nu, nv)==(Standard_Integer) newind ) {
3300 nbsur2++;
3301 aIPD.xIP2(nu, nv)=indicepointtraite;
3302 nu2=nu; nv2=nv;
3303 }
3304 }
7fd59977 3305 }
c66d7156
P
3306 }
3307 if(nu1>=0 && nu2>=0) {
3308 IntSurf_PntOn2S POn2S;
3309 POn2S.SetValue(P,
3310 S1->FirstUParameter()+nu1*du1,
3311 S1->FirstVParameter()+nv1*dv1,
3312 S2->FirstUParameter()+nu2*du2,
3313 S2->FirstVParameter()+nv2*dv2);
3314 LineOn2S->Add(POn2S);
3315 Compt++;
3316 }
3317 else {
3318 //-- aucun point du triangle n a ete trouve assez proche
3319 //-- on recherche les 3 points les plus proches de P
3320 //-- dans chacun des tableaux
3321 Standard_Real Dist3[3],u3[3],v3[3];
3322 Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
3323 for(U=resu0,i=0; i<SU1; i++,U+=du1) {
3324 for(V=resv0,j=0; j<SV1; V+=dv1,j++) {
3325 //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
3326 Standard_Real t = aIPD.xP1(i, j).SquareDistance(P);
3327 //-- On remplace la plus grande valeur ds Dist[.] par la val courante
3328 if(Dist3[0]<Dist3[1]) {
3329 Standard_Real z;
3330 z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
3331 z=u3[0]; u3[0]=u3[1]; u3[1]=z;
3332 z=v3[0]; v3[0]=v3[1]; v3[1]=z;
3333 }
3334 if(Dist3[1]<Dist3[2]) {
3335 Standard_Real z;
3336 z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
3337 z=u3[1]; u3[1]=u3[2]; u3[2]=z;
3338 z=v3[1]; v3[1]=v3[2]; v3[2]=z;
3339 }
3340 if(Dist3[0]<Dist3[1]) {
3341 Standard_Real z;
3342 z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
3343 z=u3[0]; u3[0]=u3[1]; u3[1]=z;
3344 z=v3[0]; v3[0]=v3[1]; v3[1]=z;
3345 }
3346 //-- la plus grande valeur est dans Dist3[0]
3347 if(t<Dist3[0]) {
3348 Dist3[0]=t; u3[0]=U; v3[0]=V;
3349 }
3350 }
7fd59977 3351 }
3352 //
c66d7156
P
3353 Standard_Real U1_3 = (u3[0]+u3[1]+u3[2])/3.0;
3354 Standard_Real V1_3 = (v3[0]+v3[1]+v3[2])/3.0;
3355
3356 Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
3357 for(U=U0,i=0; i<SU2; i++,U+=du2) {
3358 for(V=V0,j=0; j<SV2; V+=dv2,j++) {
3359 //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
3360 Standard_Real t = aIPD.xP2(i, j).SquareDistance(P);
3361 //-- On remplace la plus grande valeur ds Dist3[.] par la val courante
3362 if(Dist3[0]<Dist3[1]) {
3363 Standard_Real z;
3364 z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
3365 z=u3[0]; u3[0]=u3[1]; u3[1]=z;
3366 z=v3[0]; v3[0]=v3[1]; v3[1]=z;
7fd59977 3367 }
c66d7156
P
3368 if(Dist3[1]<Dist3[2]) {
3369 Standard_Real z;
3370 z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
3371 z=u3[1]; u3[1]=u3[2]; u3[2]=z;
3372 z=v3[1]; v3[1]=v3[2]; v3[2]=z;
3373 }
3374 if(Dist3[0]<Dist3[1]) {
3375 Standard_Real z;
3376 z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
3377 z=u3[0]; u3[0]=u3[1]; u3[1]=z;
3378 z=v3[0]; v3[0]=v3[1]; v3[1]=z;
3379 }
3380 //-- la plus grande valeur est dans Dist3[0]
3381 if(t<Dist3[0]) {
3382 Dist3[0]=t; u3[0]=U; v3[0]=V;
7fd59977 3383 }
3384 }
3385 }
7fd59977 3386 //
c66d7156
P
3387 Standard_Real U2_3 = (u3[0]+u3[1]+u3[2])/3.0;
3388 Standard_Real V2_3 = (v3[0]+v3[1]+v3[2])/3.0;
3389 //
3390 IntSurf_PntOn2S POn2S;
3391 POn2S.SetValue(P,U1_3,V1_3,U2_3,V2_3);
3392 LineOn2S->Add(POn2S);
3393 Compt++;
7fd59977 3394 }
c66d7156
P
3395 }
3396 }
3397 while(ok);
7fd59977 3398}