1 // File: IntPatch_ImpImpIntersection_0.gxx
2 // Created: Thu May 7 08:47:45 1992
3 // Author: Jacques GOUSSARD
4 // Copyright: OPEN CASCADE 1992
6 // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455
8 static void PutPointsOnLine(const Handle(Adaptor3d_HSurface)& S1,
9 const Handle(Adaptor3d_HSurface)& S2,
10 const IntPatch_SequenceOfPathPointOfTheSOnBounds&,
11 const IntPatch_SequenceOfLine&,
12 const Standard_Boolean,
13 const Handle(Adaptor3d_TopolTool)&,
14 const IntSurf_Quadric&,
15 const IntSurf_Quadric&,
16 const Standard_Boolean,
19 static Standard_Boolean MultiplePoint (const IntPatch_SequenceOfPathPointOfTheSOnBounds&,
20 const Handle(Adaptor3d_TopolTool)&,
21 const IntSurf_Quadric&,
23 const IntPatch_SequenceOfLine&,
24 TColStd_Array1OfInteger&,
25 TColStd_Array1OfInteger&,
26 const Standard_Integer,
27 const Standard_Boolean);
29 static Standard_Boolean PointOnSecondDom (const IntPatch_SequenceOfPathPointOfTheSOnBounds&,
30 const Handle(Adaptor3d_TopolTool)&,
31 const IntSurf_Quadric&,
34 const Handle(IntPatch_Line)&,
35 TColStd_Array1OfInteger&,
36 const Standard_Integer);
38 static Standard_Boolean SingleLine (const gp_Pnt&,
39 const Handle(IntPatch_Line)&,
45 static Standard_Boolean FindLine (gp_Pnt&,
46 const IntPatch_SequenceOfLine&,
52 const Handle(Adaptor2d_HCurve2d)&,
55 const IntSurf_Quadric&);
57 static void ProcessSegments (const IntPatch_SequenceOfSegmentOfTheSOnBounds&,
58 IntPatch_SequenceOfLine&,
59 const IntSurf_Quadric&,
60 const IntSurf_Quadric&,
61 const Standard_Boolean,
64 static void ProcessRLine (IntPatch_SequenceOfLine&,
66 const IntSurf_Quadric&,
67 const IntSurf_Quadric&,
69 const Handle(Adaptor3d_HSurface)&,
70 const Handle(Adaptor3d_HSurface)&,
77 //-- le calcul de dist est completement faux ds la routine ci dessous a revoir (lbr le 18 nov 97)
78 Standard_Boolean IntersectionWithAnArc(gp_Pnt& PSurf,
79 const Handle(IntPatch_ALine)& alin,
81 const Handle(Adaptor2d_HCurve2d)& thearc,
82 Standard_Real& _theparameteronarc,
83 gp_Pnt& thepointonarc,
84 const IntSurf_Quadric& QuadSurf,
85 const Standard_Real u0alin,
86 const Standard_Real u1alin,
87 Standard_Real& actualdist) {
88 Standard_Real dtheta,theta;
90 //Standard_Real u,v,A,B,C,cost,sint,sign;
92 //-- recherche bete du point le plus proche de thearc->Value(...)
93 dtheta = (u1alin-u0alin)*0.01;
94 Standard_Real du=0.000000001;
95 Standard_Real distmin = RealLast();
97 Standard_Real thetamin = 0.;
99 Standard_Real thetamin;
101 Standard_Real theparameteronarc = _theparameteronarc;
102 for(Standard_Real _theta=u0alin+dtheta; _theta<=u1alin-dtheta; _theta+=dtheta) {
103 gp_Pnt P=alin->Value(_theta);
104 Standard_Real d=P.Distance(PSurf);
111 Standard_Real bestpara =0., besttheta =0., bestdist =0., distinit =0. ;
113 Standard_Real bestpara,besttheta,bestdist,distinit;
115 //-- Distance initiale
117 gp_Pnt pp0 = alin->Value(thetamin);
118 Standard_Real ua0,va0;
119 QuadSurf.Parameters(pp0,ua0,va0);
122 thearc->D1(theparameteronarc,p2d,d2d);
123 gp_Vec2d PaPr(gp_Pnt2d(ua0,va0),p2d);
124 distinit=PaPr.Magnitude();
127 //-- recherche a partir de theta et theparameteronarc
128 Standard_Boolean cpasok=Standard_True;
129 Standard_Integer nbiter=0;
130 Standard_Real drmax = (thearc->LastParameter() - thearc->FirstParameter())*0.05;
131 Standard_Real damax = (u1alin-u0alin)*0.05;
135 bestdist = RealLast();
138 Standard_Real ua0,va0,ua1,va1;
139 //-- alin->Curve().InternalUVValue(theta,ua0,va0,A,B,C,cost,sint,sign);
140 //-- alin->Curve().InternalUVValue(theta+du,ua1,va1,A,B,C,cost,sint,sign);
141 gp_Pnt pp0 = alin->Value(theta);
142 gp_Pnt pp1 = alin->Value(theta+du);
143 QuadSurf.Parameters(pp0,ua0,va0);
144 QuadSurf.Parameters(pp1,ua1,va1);
147 gp_Vec2d D1a((ua1-ua0)/du,(va1-va0)/du);
150 thearc->D1(theparameteronarc,p2d,d2d);
151 gp_Vec2d PaPr(gp_Pnt2d(ua0,va0),p2d);
153 Standard_Real pbd=PaPr.Magnitude();
156 bestpara = theparameteronarc;
160 D1a.SetCoord(-D1a.X(),-D1a.Y());
162 Standard_Real d = D1a.X() * d2d.Y() - D1a.Y() * d2d.X();
164 Standard_Real da = (-PaPr.X())* d2d.Y() - (-PaPr.Y()) * d2d.X();
165 Standard_Real dr = D1a.X() * (-PaPr.Y()) - D1a.Y() * (-PaPr.X());
171 if(Abs(PaPr.X())>Abs(PaPr.Y())) {
172 Standard_Real xx=PaPr.X();
182 Standard_Real yy=PaPr.Y();
192 //-- Standard_Real da = -PaPr.Dot(D1a);
193 //-- Standard_Real dr = -PaPr.Dot(d2d);
195 if(da<-damax) da=-damax;
196 else if(da>damax) da=damax;
197 if(dr<-drmax) dr=-drmax;
198 else if(dr>drmax) dr=drmax;
200 if(Abs(da)<1e-10 && Abs(dr)<1e-10) {
202 PSurf = alin->Value(para);
203 _theparameteronarc=theparameteronarc;
204 thepointonarc = alin->Value(para);
205 cpasok=Standard_False;
206 //-- printf("\nt:%d",nbiter);
207 actualdist = bestdist;
208 return(Standard_True);
212 theparameteronarc+=dr;
213 if( theparameteronarc>thearc->LastParameter() ) {
214 theparameteronarc = thearc->LastParameter();
216 if( theparameteronarc<thearc->FirstParameter() ) {
217 theparameteronarc = thearc->FirstParameter();
219 if( theta < u0alin) {
222 if( theta > u1alin-du) {
223 theta = u1alin-du-du;
228 while(cpasok && nbiter<20);
229 if(bestdist < distinit) {
231 PSurf = alin->Value(para);
232 _theparameteronarc=bestpara;
233 thepointonarc = alin->Value(para);
234 //-- printf("\nT:%d",nbiter);
236 return(Standard_True);
238 //-- printf("\nF:%d",nbiter);
239 return(Standard_False);
246 //-- ======================================================================
247 static void Recadre(const Handle(Adaptor3d_HSurface)& myHS1,
248 const Handle(Adaptor3d_HSurface)& myHS2,
253 Standard_Real f,l,lmf,fpls2;
254 GeomAbs_SurfaceType typs1 = myHS1->GetType();
255 GeomAbs_SurfaceType typs2 = myHS2->GetType();
257 Standard_Boolean myHS1IsUPeriodic,myHS1IsVPeriodic;
259 case GeomAbs_Cylinder:
263 myHS1IsUPeriodic = Standard_True;
264 myHS1IsVPeriodic = Standard_False;
269 myHS1IsUPeriodic = myHS1IsVPeriodic = Standard_True;
274 //-- Le cas de biparametrees periodiques est gere en amont
275 myHS1IsUPeriodic = myHS1IsVPeriodic = Standard_False;
280 Standard_Boolean myHS2IsUPeriodic,myHS2IsVPeriodic;
282 case GeomAbs_Cylinder:
286 myHS2IsUPeriodic = Standard_True;
287 myHS2IsVPeriodic = Standard_False;
292 myHS2IsUPeriodic = myHS2IsVPeriodic = Standard_True;
297 //-- Le cas de biparametrees periodiques est gere en amont
298 myHS2IsUPeriodic = myHS2IsVPeriodic = Standard_False;
302 if(myHS1IsUPeriodic) {
303 lmf = M_PI+M_PI; //-- myHS1->UPeriod();
304 f = myHS1->FirstUParameter();
305 l = myHS1->LastUParameter();
307 while((u1 < f)&&((fpls2-u1) > (u1+lmf-fpls2) )) { u1+=lmf; }
308 while((u1 > l)&&((u1-fpls2) > (fpls2-(u1-lmf)) )) { u1-=lmf; }
311 if(myHS1IsVPeriodic) {
312 lmf = M_PI+M_PI; //-- myHS1->VPeriod();
313 f = myHS1->FirstVParameter();
314 l = myHS1->LastVParameter();
316 while((v1 < f)&&((fpls2-v1) > (v1+lmf-fpls2) )) { v1+=lmf; }
317 while((v1 > l)&&((v1-fpls2) > (fpls2-(v1-lmf)) )) { v1-=lmf; }
318 //-- while(v1 < f) { v1+=lmf; }
319 //-- while(v1 > l) { v1-=lmf; }
321 if(myHS2IsUPeriodic) {
322 lmf = M_PI+M_PI; //-- myHS2->UPeriod();
323 f = myHS2->FirstUParameter();
324 l = myHS2->LastUParameter();
326 while((u2 < f)&&((fpls2-u2) > (u2+lmf-fpls2) )) { u2+=lmf; }
327 while((u2 > l)&&((u2-fpls2) > (fpls2-(u2-lmf)) )) { u2-=lmf; }
328 //-- while(u2 < f) { u2+=lmf; }
329 //-- while(u2 > l) { u2-=lmf; }
331 if(myHS2IsVPeriodic) {
332 lmf = M_PI+M_PI; //-- myHS2->VPeriod();
333 f = myHS2->FirstVParameter();
334 l = myHS2->LastVParameter();
336 while((v2 < f)&&((fpls2-v2) > (v2+lmf-fpls2) )) { v2+=lmf; }
337 while((v2 > l)&&((v2-fpls2) > (fpls2-(v2-lmf)) )) { v2-=lmf; }
338 //-- while(v2 < f) { v2+=lmf; }
339 //-- while(v2 > l) { v2-=lmf; }
342 //=======================================================================
343 //function : PutPointsOnLine
345 //=======================================================================
346 void PutPointsOnLine(const Handle(Adaptor3d_HSurface)& S1,
347 const Handle(Adaptor3d_HSurface)& S2,
348 const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt,
349 const IntPatch_SequenceOfLine& slin,
350 const Standard_Boolean OnFirst,
351 const Handle(Adaptor3d_TopolTool)& Domain,
352 const IntSurf_Quadric& QuadSurf,
353 const IntSurf_Quadric& OtherQuad,
354 const Standard_Boolean multpoint,
355 const Standard_Real Tolarc) {
357 // Traitement des point (de listpnt) de depart. On les replace sur
358 // la ligne d intersection, en leur affectant la transition correcte sur
360 Standard_Integer nbpnt = listpnt.Length();
361 Standard_Integer nblin=slin.Length();
363 if (!slin.Length() || !nbpnt) {
367 Standard_Integer i,k;
368 Standard_Integer linenumber;
369 Standard_Real paraint,currentparameter,tolerance;
370 Standard_Real U1,V1,U2,V2;
371 Standard_Boolean goon;
375 gp_Vec Normale, Vtgint, Vtgrst;
381 IntSurf_Transition Transline,Transarc;
383 Handle(Adaptor2d_HCurve2d) currentarc;
384 Handle(Adaptor3d_HVertex) vtx,vtxbis;
386 IntPatch_Point solpnt;
387 IntPatch_ThePathPointOfTheSOnBounds currentpointonrst;
388 IntPatch_IType TheType;
390 TColStd_Array1OfInteger UsedLine(1,nblin);
391 TColStd_Array1OfInteger Done(1,nbpnt);
392 for(i=1;i<=nbpnt;i++) Done(i) = 0; //-- Initialisation a la main
394 for (i=1; i<=nbpnt; i++) {
397 currentpointonrst = listpnt.Value(i);
398 Psurf = currentpointonrst.Value(); // Point dans l espace
399 tolerance = currentpointonrst.Tolerance();
401 // On recherche d abord si on a correspondance avec un "point multiple"
404 goon = Standard_True;
407 Normale = QuadSurf.Normale(Psurf); // Normale a la surface au point
408 currentarc = currentpointonrst.Arc();
409 currentparameter = currentpointonrst.Parameter();
410 currentarc->D1(currentparameter,p2d,d2d);
411 QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v);
412 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
414 goon = MultiplePoint(listpnt,Domain,QuadSurf,Normale,slin,Done, UsedLine,
418 Standard_Boolean linefound;
420 for(Standard_Integer indiceline = 1; indiceline <=slin.Length(); indiceline++) {
421 if( UsedLine(indiceline) != 0 )
423 linenumber = indiceline;
425 //-- Attention , les points peuvent etre deplaces
426 //-- il faut reprendre le point original
427 currentpointonrst = listpnt.Value(i);
428 currentarc = currentpointonrst.Arc();
429 currentparameter = currentpointonrst.Parameter();
430 Psurf = currentpointonrst.Value(); // Point dans l espace
431 tolerance = currentpointonrst.Tolerance();
435 // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455 Begin
436 if (! currentpointonrst.IsNew()) {
437 Handle(Adaptor3d_HVertex) aVtx = currentpointonrst.Vertex();
438 Standard_Real aVtxTol = aVtx->Resolution(currentarc);
439 Standard_Real aTolAng = 0.01*tolerance;
441 tolerance = Max(tolerance, aVtxTol);
443 gp_Vec aNorm1 = QuadSurf.Normale(Psurf);
444 gp_Vec aNorm2 = OtherQuad.Normale(Psurf);
446 if (aNorm1.Magnitude()>gp::Resolution() &&
447 aNorm2.Magnitude()>gp::Resolution()) {
449 if (aNorm1.IsParallel(aNorm2, aTolAng))
450 tolerance = Sqrt(tolerance);
453 // Modified by skv - Thu Jan 15 15:57:15 2004 OCC4455 End
455 Vtgint.SetCoord(0,0,0);
456 linefound = FindLine(Psurf,slin,tolerance,paraint,Vtgint,linenumber,indiceline,
457 currentarc,currentparameter,pointonarc,QuadSurf);
461 Normale = QuadSurf.Normale(Psurf); // Normale a la surface au point
462 currentarc = currentpointonrst.Arc();
463 //-- currentparameter = currentpointonrst.Parameter();
464 currentarc->D1(currentparameter,p2d,d2d);
465 QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v);
466 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
471 const Handle(IntPatch_Line)& lin = slin.Value(linenumber);
472 TheType = lin->ArcType();
474 if (!OnFirst) { // on cherche la correspondance entre point sur domaine
475 // de la premiere surface et point sur domaine de la
478 goon = PointOnSecondDom (listpnt, Domain, QuadSurf, Normale,
479 Vtgint, lin, Done, i);
483 //-- Modification du 4 avril 97 tolerance->Tolarc
484 //-- on replace sur le vertex la tolerance d entree et
485 //-- non la tolerance qui a servi au FindLine
486 solpnt.SetValue(Psurf,Tolarc,Standard_False);
488 U1 = p2d.X(); V1 = p2d.Y();
489 OtherQuad.Parameters(Psurf,U2,V2);
492 Recadre(S1,S2,U1,V1,U2,V2);
493 solpnt.SetParameters(U1,V1,U2,V2);
496 Recadre(S1,S2,U2,V2,U1,V1);
497 solpnt.SetParameters(U2,V2,U1,V1);
499 solpnt.SetParameter(paraint);
501 if (! currentpointonrst.IsNew()) {
502 vtx = currentpointonrst.Vertex();
503 solpnt.SetVertex(OnFirst,vtx);
506 //-- goon = Standard_False; ????
509 if(Normale.SquareMagnitude()<1e-16) {
510 Transline.SetValue(Standard_True,IntSurf_Undecided);
511 Transarc.SetValue(Standard_True,IntSurf_Undecided);
514 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc);
516 solpnt.SetArc(OnFirst,currentarc, currentparameter,
518 if (TheType == IntPatch_Analytic) {
519 (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(solpnt);
522 (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(solpnt);
527 for (k=i+1; k<= nbpnt; k++) {
529 currentpointonrst = listpnt.Value(k);
530 if (!currentpointonrst.IsNew()) {
531 vtxbis = currentpointonrst.Vertex();
534 else if (Domain->Identical(vtx, vtxbis)) {
535 solpnt.SetVertex(OnFirst,vtxbis);
536 currentarc = currentpointonrst.Arc();
537 currentparameter = currentpointonrst.Parameter();
539 // currentarc->D1(currentparameter,ptbid,Vtgrst);
540 currentarc->D1(currentparameter,p2d,d2d);
541 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
542 if(Normale.SquareMagnitude()<1e-16) {
543 Transline.SetValue(Standard_True,IntSurf_Undecided);
544 Transarc.SetValue(Standard_True,IntSurf_Undecided);
547 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,
550 solpnt.SetArc(OnFirst,currentarc,currentparameter,
552 if (TheType == IntPatch_Analytic) {
553 (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(solpnt);
556 (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(solpnt);
567 Done(i) = 1; // il faudra tester si IsNew ou pas
568 // et traiter en consequence
577 Standard_Boolean MultiplePoint (const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt,
578 const Handle(Adaptor3d_TopolTool)& Domain,
579 const IntSurf_Quadric& QuadSurf,
580 const gp_Vec& Normale,
581 const IntPatch_SequenceOfLine& slin,
582 TColStd_Array1OfInteger& Done,
583 TColStd_Array1OfInteger& UsedLine,
584 const Standard_Integer Index,
585 const Standard_Boolean OnFirst) {
587 // Traitement des points "multiples".
590 Standard_Integer k,ii,jj,nbvtx;
591 Standard_Integer nblin = slin.Length();
592 IntPatch_IType TheType;
595 IntSurf_Transition Transline,Transarc;
598 IntPatch_Point intpt;
599 Handle(Adaptor2d_HCurve2d) currentarc;
600 Handle(Adaptor3d_HVertex) vtx,vtxbis;
602 Standard_Integer nbpnt = listpnt.Length();
603 IntPatch_ThePathPointOfTheSOnBounds currentpointonrst = listpnt.Value(Index);
604 IntPatch_ThePathPointOfTheSOnBounds otherpt;
605 gp_Pnt Point = currentpointonrst.Value();
606 TColStd_Array1OfInteger localdone(1,nbpnt); localdone.Init(0);
607 for (ii=1; ii<=nbpnt; ii++) {
608 localdone(ii)=Done(ii);
611 Standard_Real currentparameter;
612 Standard_Real Paraint;
613 gp_Vec Vtgint,Vtgrst;
620 Standard_Boolean goon;
622 Standard_Boolean Retvalue = Standard_True;
624 for (ii = 1; ii <= nblin; ii++) {
625 const Handle(IntPatch_Line)& slinValueii = slin.Value(ii);
626 TheType = slinValueii->ArcType();
627 if (TheType == IntPatch_Analytic) {
628 nbvtx = (*((Handle(IntPatch_ALine)*)&slinValueii))->NbVertex();
631 nbvtx = (*((Handle(IntPatch_GLine)*)&slinValueii))->NbVertex();
634 while (jj <= nbvtx) {
635 if (TheType == IntPatch_Analytic) {
636 intpt = (*((Handle(IntPatch_ALine)*)&slinValueii))->Vertex(jj);
639 intpt = (*((Handle(IntPatch_GLine)*)&slinValueii))->Vertex(jj);
641 if (intpt.IsMultiple() &&
642 (( OnFirst && !intpt.IsOnDomS1()) ||
643 (!OnFirst && !intpt.IsOnDomS2()))) {
644 if (Point.Distance(intpt.Value()) <= intpt.Tolerance()) {
645 Retvalue = Standard_False;
646 Standard_Boolean foo = SingleLine(Point,slinValueii,
647 intpt.Tolerance(),Paraint,Vtgint);
649 return Standard_False; // ne doit pas se produire
652 if (!currentpointonrst.IsNew()) {
653 goon = Standard_True;
654 vtx = currentpointonrst.Vertex();
655 intpt.SetVertex(OnFirst,vtx);
658 goon = Standard_False;
660 currentarc = currentpointonrst.Arc();
661 currentparameter = currentpointonrst.Parameter();
662 currentarc->D1(currentparameter,p2d,d2d);
663 QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v);
664 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
666 //-- Si la normale est nulle (apex d un cone) On simule une transition UNKNOWN
667 if(Normale.SquareMagnitude()<1e-16) {
668 Transline.SetValue(Standard_True,IntSurf_Undecided);
669 Transarc.SetValue(Standard_True,IntSurf_Undecided);
672 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc);
675 //-- Avant, on ne mettait pas ce point (17 nov 97)
676 //--printf("\n ImpImp_0 : Point(%g,%g,%g) intpt(%g,%g,%g) \n",
677 //-- Point.X(),Point.Y(),Point.Z(),intpt.Value().X(),intpt.Value().Y(),intpt.Value().Z());
678 intpt.SetValue(Point);
680 intpt.SetArc(OnFirst,currentarc,currentparameter,
684 if (TheType == IntPatch_Analytic) {
685 (*((Handle(IntPatch_ALine)*)&slinValueii))->Replace(jj,intpt);
688 (*((Handle(IntPatch_GLine)*)&slinValueii))->Replace(jj,intpt);
690 localdone(Index) = 1;
692 for (k=Index+1; k<= nbpnt; k++) {
694 otherpt= listpnt.Value(k);
695 if (!otherpt.IsNew()) {
696 vtxbis = otherpt.Vertex();
697 if (Domain->Identical(vtx, vtxbis)) {
698 intpt.SetVertex(OnFirst,vtxbis);
699 currentarc = otherpt.Arc();
700 currentparameter = otherpt.Parameter();
702 currentarc->D1(currentparameter,p2d,d2d);
703 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
704 if(Normale.SquareMagnitude()<1e-16) {
705 Transline.SetValue(Standard_True,IntSurf_Undecided);
706 Transarc.SetValue(Standard_True,IntSurf_Undecided);
709 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,
712 intpt.SetArc(OnFirst,currentarc,currentparameter,
714 if (TheType == IntPatch_Analytic) {
715 (*((Handle(IntPatch_ALine)*)&slinValueii))->AddVertex(intpt);
718 (*((Handle(IntPatch_GLine)*)&slinValueii))->AddVertex(intpt);
721 Retvalue = Standard_True;
740 for (ii=1; ii<=nbpnt;ii++) {
741 Done(ii) = localdone(ii);
749 Standard_Boolean PointOnSecondDom (const IntPatch_SequenceOfPathPointOfTheSOnBounds& listpnt,
750 const Handle(Adaptor3d_TopolTool)& Domain,
751 const IntSurf_Quadric& QuadSurf,
752 const gp_Vec& Normale,
753 const gp_Vec& Vtgint,
754 const Handle(IntPatch_Line)& lin,
755 TColStd_Array1OfInteger& Done,
756 const Standard_Integer Index)
759 // Duplication des points sur domaine de l autre surface.
760 // On sait que le vertex sous-jacent est PntRef
765 Standard_Integer k,jj,nbvtx;
766 IntPatch_IType TheType;
768 IntSurf_Transition Transline,Transarc;
769 IntPatch_Point intpt;
770 Handle(Adaptor2d_HCurve2d) currentarc;
771 Handle(Adaptor3d_HVertex) vtx,vtxbis;
779 Standard_Integer nbpnt = listpnt.Length();
780 IntPatch_ThePathPointOfTheSOnBounds currentpointonrst = listpnt.Value(Index);
781 Standard_Real currentparameter;
783 Standard_Boolean goon;
784 Standard_Boolean Retvalue = Standard_True;
786 TheType = lin->ArcType();
787 if (TheType == IntPatch_Analytic) {
788 nbvtx = (*((Handle(IntPatch_ALine)*)&lin))->NbVertex();
791 nbvtx = (*((Handle(IntPatch_GLine)*)&lin))->NbVertex();
794 while (jj <= nbvtx) {
795 if (TheType == IntPatch_Analytic) {
796 intpt = (*((Handle(IntPatch_ALine)*)&lin))->Vertex(jj);
799 intpt = (*((Handle(IntPatch_GLine)*)&lin))->Vertex(jj);
801 if (!intpt.IsOnDomS2()) {
802 if (currentpointonrst.Value().Distance(intpt.Value()) <=
804 Retvalue = Standard_False;
805 if (!currentpointonrst.IsNew()) {
806 goon = Standard_True;
807 vtx = currentpointonrst.Vertex();
808 intpt.SetVertex(Standard_False,vtx);
811 goon = Standard_False;
813 currentarc = currentpointonrst.Arc();
814 currentparameter = currentpointonrst.Parameter();
815 currentarc->D1(currentparameter,p2d,d2d);
816 QuadSurf.D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v);
817 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
818 if(Normale.SquareMagnitude()<1e-16) {
819 Transline.SetValue(Standard_True,IntSurf_Undecided);
820 Transarc.SetValue(Standard_True,IntSurf_Undecided);
823 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,Transline,Transarc);
825 intpt.SetArc(Standard_False,currentarc,currentparameter,
827 if (TheType == IntPatch_Analytic) {
828 (*((Handle(IntPatch_ALine)*)&lin))->Replace(jj,intpt);
831 (*((Handle(IntPatch_GLine)*)&lin))->Replace(jj,intpt);
836 for (k=Index+1; k<= nbpnt; k++) {
838 currentpointonrst = listpnt.Value(k);
839 if (!currentpointonrst.IsNew()) {
840 vtxbis = currentpointonrst.Vertex();
841 if (Domain->Identical(vtx, vtxbis)) {
842 intpt.SetVertex(Standard_False,vtxbis);
843 currentarc = currentpointonrst.Arc();
844 currentparameter = currentpointonrst.Parameter();
845 currentarc->D1(currentparameter,p2d,d2d);
846 Vtgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
847 if(Normale.SquareMagnitude()<1e-16) {
848 Transline.SetValue(Standard_True,IntSurf_Undecided);
849 Transarc.SetValue(Standard_True,IntSurf_Undecided);
852 IntSurf::MakeTransition(Vtgint,Vtgrst,Normale,
855 intpt.SetArc(Standard_False,currentarc,currentparameter,
857 if (TheType == IntPatch_Analytic) {
858 (*((Handle(IntPatch_ALine)*)&lin))->AddVertex(intpt);
861 (*((Handle(IntPatch_GLine)*)&lin))->AddVertex(intpt);
879 if (TheType == IntPatch_Analytic) {
880 nbvtx = (*((Handle(IntPatch_ALine)*)&lin))->NbVertex();
883 nbvtx = (*((Handle(IntPatch_GLine)*)&lin))->NbVertex();
891 Standard_Boolean FindLine (gp_Pnt& Psurf,
892 const IntPatch_SequenceOfLine& slin,
893 const Standard_Real Tol,
894 Standard_Real& Paraint,
896 Standard_Integer& Range,
897 Standard_Integer OnlyThisLine,
898 const Handle(Adaptor2d_HCurve2d)& thearc,
899 Standard_Real& theparameteronarc,
900 gp_Pnt& thepointonarc,
901 const IntSurf_Quadric& QuadSurf)
904 // Traitement du point de depart ayant pour representation Psurf
905 // dans l espace. On recherche la ligne d intersection contenant ce point.
906 // On a en sortie la ligne, et le parametre et sa tangente du point sur
907 // la ligne d intersection.
909 Standard_Real distmin = RealLast();
910 Standard_Real dist,para;
911 Standard_Real lower,upper;
914 IntPatch_IType typarc;
916 Standard_Integer nblin = slin.Length();
917 for (i=1; i<=nblin; i++) {
918 if(OnlyThisLine) { i=OnlyThisLine; nblin=0; }
919 const Handle(IntPatch_Line)& lin = slin.Value(i);
920 typarc = lin->ArcType();
921 if (typarc == IntPatch_Analytic) {
922 Standard_Boolean foo;
923 lower = (*((Handle(IntPatch_ALine)*)&lin))->FirstParameter(foo);
924 upper = (*((Handle(IntPatch_ALine)*)&lin))->LastParameter(foo);
927 if ((*((Handle(IntPatch_GLine)*)&lin))->HasFirstPoint()) {
928 lower = (*((Handle(IntPatch_GLine)*)&lin))->FirstPoint().ParameterOnLine();
933 if ((*((Handle(IntPatch_GLine)*)&lin))->HasLastPoint()) {
934 upper = (*((Handle(IntPatch_GLine)*)&lin))->LastPoint().ParameterOnLine();
944 para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Line(),Psurf);
945 if (para <= upper && para >= lower) {
946 pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Line());
947 dist = Psurf.Distance(pt);
956 case IntPatch_Circle :
958 para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Circle(),Psurf);
959 if ((para <= upper && para >= lower) ||
960 (para + 2.*M_PI <=upper && para + 2.*M_PI >= lower) ||
961 (para - 2.*M_PI <=upper && para - 2.*M_PI >= lower)) {
962 pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Circle());
963 dist = Psurf.Distance(pt);
972 case IntPatch_Ellipse :
974 para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),Psurf);
975 if ((para <= upper && para >= lower) ||
976 (para + 2.*M_PI <=upper && para + 2.*M_PI >= lower) ||
977 (para - 2.*M_PI <=upper && para - 2.*M_PI >= lower)) {
978 pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Ellipse());
979 dist = Psurf.Distance(pt);
988 case IntPatch_Parabola :
992 para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Parabola(),Psurf);
993 if (para <= upper && para >= lower) {
994 pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Parabola());
995 dist = Psurf.Distance(pt);
1003 //-- Le calcul du parametre sur une parabole est mal fait ds ElCLib. Il ne tient pas compte
1004 //-- de la meilleure facon de calculer (axe X ou axe Y). Bilan : Si la parabole est tres
1005 //-- pointue (focal de l'ordre de 1e-2 et si le point est a un parametre grand, ca foire. )
1006 //-- On ne peut pas modifier faciolement ds ElCLib car on ne passe pas la focale. ...
1007 const gp_Parab& Parab=(*((Handle(IntPatch_GLine)*)&lin))->Parabola();
1008 para = ElCLib::Parameter(Parab,Psurf);
1009 if (para <= upper && para >= lower) {
1010 Standard_Integer amelioration=0;
1011 //-- cout<<"\n ****** \n";
1013 Standard_Real parabis = para+0.0000001;
1015 pt = ElCLib::Value(para,Parab);
1016 dist = Psurf.Distance(pt);
1018 gp_Pnt ptbis = ElCLib::Value(parabis,Parab);
1019 Standard_Real distbis = Psurf.Distance(ptbis);
1021 Standard_Real ddist = distbis-dist;
1023 //--cout<<" para: "<<para<<" dist:"<<dist<<" ddist:"<<ddist<<endl;
1025 if (dist< distmin) {
1030 if(dist<1.0e-9 && dist>-1.0e-9) { amelioration=100; }
1032 if(ddist>1.0e-9 || ddist<-1.0e-9 ) {
1033 para=para-dist*(parabis-para)/ddist;
1039 while(++amelioration < 5);
1046 case IntPatch_Hyperbola :
1048 para = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),Psurf);
1049 if (para <= upper && para >= lower) {
1050 pt = ElCLib::Value(para,(*((Handle(IntPatch_GLine)*)&lin))->Hyperbola());
1051 dist = Psurf.Distance(pt);
1052 if (dist< distmin) {
1061 case IntPatch_Analytic :
1063 const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&lin));
1064 Standard_Boolean ok = alin->FindParameter(Psurf,para);
1066 pt = alin->Value(para);
1067 dist = Psurf.Distance(pt);
1068 if (dist< distmin) {
1075 //-- le point n a pas ete trouve par bete projection.
1076 //-- on essaie l intersection avec la restriction en 2d
1077 Standard_Real theparamonarc = theparameteronarc;
1079 // Standard_Real anpara=para;
1081 gp_Pnt CopiePsurf=Psurf;
1082 Standard_Boolean ok=IntersectionWithAnArc(CopiePsurf,alin,para,thearc,theparamonarc,thepointonarc,QuadSurf,lower,upper,dist);
1084 //--printf("\nIntersectionWithAnArc %d \n Psurf(%g,%g,%g)->(%g,%g,%g) dist=%g\n para(%g)->(%g)\n paraonarc(%g)->(%g)",
1085 //-- ok,Psurf.X(),Psurf.Y(),Psurf.Z(),thepointonarc.X(),thepointonarc.Y(),thepointonarc.Z(),dist,
1086 //-- anpara,para,theparameteronarc,theparamonarc);
1087 dist = CopiePsurf.Distance(Psurf);
1090 theparameteronarc = theparamonarc;
1091 Psurf = thepointonarc;
1101 case IntPatch_Walking: // impossible . c est pour eviter les warnings
1104 case IntPatch_Restriction: // impossible . c est pour eviter les warnings
1110 if (distmin > Tol) {
1111 return Standard_False;
1114 typarc = slin.Value(Range)->ArcType();
1116 // Calcul de la tangente.
1119 Vtgtint = (*((Handle(IntPatch_GLine)*)&slin(Range)))->Line().Direction();
1121 case IntPatch_Circle :
1122 Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Circle(),1);
1124 case IntPatch_Ellipse :
1125 Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Ellipse(),1);
1127 case IntPatch_Parabola :
1128 Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Parabola(),1);
1130 case IntPatch_Hyperbola :
1131 Vtgtint = ElCLib::DN(Paraint,(*((Handle(IntPatch_GLine)*)&slin(Range)))->Hyperbola(),1);
1134 case IntPatch_Analytic:
1136 const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&slin(Range)));
1137 Standard_Boolean abid = alin->D1(Paraint,pt,Vtgtint);
1139 Standard_Real domaininf,domainsup,paramproche;
1140 Standard_Boolean boolbid;
1141 domaininf = alin->FirstParameter(boolbid);
1142 domainsup = alin->LastParameter(boolbid);
1143 if(Paraint>=domaininf && Paraint<=domainsup) {
1144 Standard_Real DeltaParam = 0.001 * (domainsup-domaininf);
1145 if(Paraint-domaininf >= domainsup-Paraint) {
1146 //-- On decale le point vers le parametre le plus eloigne.
1147 DeltaParam = -DeltaParam;
1149 Standard_Integer kountbid = 0;
1150 Standard_Boolean bornok = Standard_True;
1151 paramproche = Paraint;
1153 paramproche+=DeltaParam;
1156 if(paramproche>=domaininf && paramproche<=domainsup) {
1157 abid = alin->D1(paramproche,ptbid,Vtgtint);
1160 bornok = Standard_False;
1163 while(abid==Standard_False && kountbid<5 && bornok);
1164 //-- Attention aux points de tangence (croisement de 4 lignes )
1165 bornok = Standard_True;
1167 gp_Vec OVtgtint(0.0,0.0,0.0);
1168 paramproche = Paraint;
1170 paramproche-=DeltaParam;
1173 if(paramproche>=domaininf && paramproche<=domainsup) {
1174 abid = alin->D1(paramproche,ptbid,OVtgtint);
1177 bornok = Standard_False;
1180 while(abid==Standard_False && kountbid<5 && bornok);
1182 paramproche = Vtgtint.Dot(OVtgtint);
1183 if(paramproche<=0.0) abid = Standard_False;
1187 //-- cout << "Pb sur Calcul de derivee 111 " << endl;
1188 Vtgtint.SetCoord(0.,0.,0.);
1193 case IntPatch_Walking: // impossible . c est pour eviter les warnings
1196 case IntPatch_Restriction: // impossible . c est pour eviter les warnings
1201 return Standard_True;
1205 Standard_Boolean SingleLine (const gp_Pnt& Psurf,
1206 const Handle(IntPatch_Line)& lin,
1207 const Standard_Real Tol,
1208 Standard_Real& Paraint,
1211 // Traitement du point de depart ayant pour representation Psurf
1212 // dans l espace. On le replace sur la ligne d intersection; On a en sortie
1213 // son parametre et sa tangente sur la ligne d intersection.
1214 // La fonction renvoie False si le point projete est a une distance
1215 // superieure a Tol du point a projeter.
1217 IntPatch_IType typarc = lin->ArcType();
1219 Standard_Real parproj;
1222 Standard_Boolean retvalue;
1227 parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Line(),Psurf);
1228 ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Line(),ptproj,tgint);
1230 case IntPatch_Circle :
1231 parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Circle(),Psurf);
1232 ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Circle(),ptproj,tgint);
1234 case IntPatch_Ellipse :
1235 parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),Psurf);
1236 ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Ellipse(),ptproj,tgint);
1238 case IntPatch_Parabola :
1239 parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Parabola(),Psurf);
1240 ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Parabola(),ptproj,tgint);
1242 case IntPatch_Hyperbola :
1243 parproj = ElCLib::Parameter((*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),Psurf);
1244 ElCLib::D1(parproj,(*((Handle(IntPatch_GLine)*)&lin))->Hyperbola(),ptproj,tgint);
1246 case IntPatch_Analytic :
1248 const Handle(IntPatch_ALine)& alin = (*((Handle(IntPatch_ALine)*)&lin));
1249 Standard_Boolean ok = alin->FindParameter(Psurf,parproj);
1252 Standard_Boolean bid = alin->D1(parproj,ptbid,tgint);
1254 Standard_Real domaininf,domainsup,paramproche;
1255 Standard_Boolean boolbid;
1256 domaininf = alin->FirstParameter(boolbid);
1257 domainsup = alin->LastParameter(boolbid);
1258 if(parproj>=domaininf && parproj<=domainsup) {
1259 Standard_Real DeltaParam = 0.001 * (domainsup-domaininf);
1260 if(parproj-domaininf >= domainsup-parproj) {
1261 //-- On decale le point vers le parametre le plus eloigne.
1262 DeltaParam = -DeltaParam;
1264 Standard_Integer kountbid = 0;
1265 paramproche = parproj;
1267 paramproche+=DeltaParam;
1269 bid = alin->D1(paramproche,ptbid,tgint);
1271 while(bid==Standard_False && kountbid<5);
1275 //-- cout << "Pb sur Calcul de derivee ALine " << endl;
1276 tgint.SetCoord(0.,0.,0.);
1277 return(Standard_False);
1285 //-- cout << "---- Pb sur ligne analytique dans SingleLine" << endl;
1286 //-- cout << " Find Parameter"<<endl;
1287 return Standard_False;
1291 case IntPatch_Walking: // impossible . c est pour eviter les warnings
1294 case IntPatch_Restriction: // impossible . c est pour eviter les warnings
1299 if (Psurf.Distance(ptproj) <= Tol) {
1302 retvalue = Standard_True;
1305 retvalue = Standard_False;
1311 void ProcessSegments (const IntPatch_SequenceOfSegmentOfTheSOnBounds& listedg,
1312 IntPatch_SequenceOfLine& slin,
1313 const IntSurf_Quadric& Quad1,
1314 const IntSurf_Quadric& Quad2,
1315 const Standard_Boolean OnFirst,
1316 const Standard_Real TolArc) {
1318 Standard_Integer i,j,k;
1319 Standard_Integer nbedg = listedg.Length();
1320 Standard_Integer Nblines,Nbpts;
1322 Handle(Adaptor2d_HCurve2d) arcRef;
1323 IntPatch_Point ptvtx, newptvtx;
1325 Handle(IntPatch_RLine) rline; //-- On fait rline = new ... par la suite
1327 IntPatch_TheSegmentOfTheSOnBounds thesegsol;
1328 IntPatch_ThePathPointOfTheSOnBounds PStartf,PStartl;
1329 Standard_Boolean dofirst,dolast,procf,procl;
1331 Standard_Real paramf =0.,paraml =0.,U1 =0.,V1 =0.,U2 =0.,V2 =0.;
1333 Standard_Real paramf,paraml,U1,V1,U2,V2;
1336 IntSurf_TypeTrans trans1,trans2;
1337 IntSurf_Transition TRest,TArc;
1338 gp_Vec tgline,norm1,norm2,tgarc;
1346 for (i = 1; i <= nbedg; i++) {
1347 Standard_Boolean EdgeDegenere=Standard_False;
1348 thesegsol = listedg.Value(i);
1349 arcRef = thesegsol.Curve();
1352 rline = new IntPatch_RLine(Standard_False);
1354 rline->SetArcOnS1(arcRef);
1357 rline->SetArcOnS2(arcRef);
1360 // Traitement des points debut/fin du segment solution.
1362 dofirst = Standard_False;
1363 dolast = Standard_False;
1364 procf = Standard_False;
1365 procl = Standard_False;
1367 if (thesegsol.HasFirstPoint()) {
1368 dofirst = Standard_True;
1369 PStartf = thesegsol.FirstPoint();
1370 paramf = PStartf.Parameter();
1372 if (thesegsol.HasLastPoint()) {
1373 dolast = Standard_True;
1374 PStartl = thesegsol.LastPoint();
1375 paraml = PStartl.Parameter();
1378 if (dofirst && dolast) { // determination de la transition de la ligne
1379 arcRef->D1(0.5*(paramf+paraml),p2d,d2d);
1381 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1384 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1386 tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1388 if(d1u.Magnitude()<1e-7) { //-- edge degenere ?
1389 EdgeDegenere=Standard_True;
1390 for(Standard_Integer edg=0;edg<=10;edg++) {
1391 arcRef->D1(paramf+(paraml-paramf)*edg*0.1,p2d,d2d);
1393 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1396 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1399 if(d1u.Magnitude()>1e-7) {
1400 EdgeDegenere=Standard_False;
1403 rline = new IntPatch_RLine(Standard_False);
1405 rline->SetArcOnS1(arcRef);
1408 rline->SetArcOnS2(arcRef);
1412 norm2 = Quad2.Normale(valpt);
1413 norm1 = Quad1.Normale(valpt);
1415 if (tgline.DotCross(norm2,norm1) > 0.000000001) {
1416 trans1 = IntSurf_Out;
1417 trans2 = IntSurf_In;
1419 else if (tgline.DotCross(norm2,norm1) < -0.000000001){
1420 trans1 = IntSurf_In;
1421 trans2 = IntSurf_Out;
1424 trans1 = trans2 = IntSurf_Undecided;
1426 rline = new IntPatch_RLine(Standard_False,trans1,trans2);
1428 rline->SetArcOnS1(arcRef);
1431 rline->SetArcOnS2(arcRef);
1436 rline = new IntPatch_RLine(Standard_False);
1438 rline->SetArcOnS1(arcRef);
1441 rline->SetArcOnS2(arcRef);
1445 if (dofirst || dolast) {
1446 Nblines = slin.Length();
1447 for (j=1; j<=Nblines; j++) {
1448 const Handle(IntPatch_Line)& slinj = slin(j);
1449 typ = slinj->ArcType();
1450 if (typ == IntPatch_Analytic) {
1451 Nbpts = (*((Handle(IntPatch_ALine)*)&slinj))->NbVertex();
1453 else if (typ == IntPatch_Restriction) {
1454 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1457 Nbpts = (*((Handle(IntPatch_GLine)*)&slinj))->NbVertex();
1459 for (k=1; k<=Nbpts;k++) {
1460 if (typ == IntPatch_Analytic) {
1461 ptvtx = (*((Handle(IntPatch_ALine)*)&slinj))->Vertex(k);
1463 else if (typ == IntPatch_Restriction) {
1464 ptvtx = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1467 ptvtx = (*((Handle(IntPatch_GLine)*)&slinj))->Vertex(k);
1470 if (EdgeDegenere==Standard_False && dofirst) {
1471 if (ptvtx.Value().Distance(PStartf.Value()) <=TolArc) {
1472 ptvtx.SetMultiple(Standard_True);
1473 if (typ == IntPatch_Analytic) {
1474 (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,ptvtx);
1476 else if (typ == IntPatch_Restriction) {
1477 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptvtx);
1480 (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,ptvtx);
1483 newptvtx.SetParameter(paramf);
1484 //Recalcul des transitions si point sur restriction
1486 arcRef->D1(paramf,p2d,d2d);
1488 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1491 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1493 tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1494 if (ptvtx.IsOnDomS1()) {
1495 const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS1();
1496 thearc->D1(ptvtx.ParameterOnArc1(),p2d,d2d);
1497 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1498 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1499 norm1 = d1u.Crossed(d1v);
1500 if(norm1.SquareMagnitude()<1e-16) {
1501 TRest.SetValue(Standard_True,IntSurf_Undecided);
1502 TArc.SetValue(Standard_True,IntSurf_Undecided);
1505 IntSurf::MakeTransition(tgline,tgarc,norm1,TRest,TArc);
1507 newptvtx.SetArc(Standard_True,thearc,ptvtx.ParameterOnArc1(),
1510 if (ptvtx.IsOnDomS2()) {
1511 const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS2();
1512 thearc->D1(ptvtx.ParameterOnArc2(),p2d,d2d);
1513 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1514 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1515 norm2 = d1u.Crossed(d1v);
1516 if(norm2.SquareMagnitude()<1e-16) {
1517 TRest.SetValue(Standard_True,IntSurf_Undecided);
1518 TArc.SetValue(Standard_True,IntSurf_Undecided);
1521 IntSurf::MakeTransition(tgline,tgarc,norm2,TRest,TArc);
1523 newptvtx.SetArc(Standard_False,thearc,ptvtx.ParameterOnArc2(),
1527 rline->AddVertex(newptvtx);
1529 procf=Standard_True;
1530 rline->SetFirstPoint(rline->NbVertex());
1534 if (EdgeDegenere==Standard_False && dolast) {
1535 if (ptvtx.Value().Distance(PStartl.Value()) <=TolArc) {
1536 ptvtx.SetMultiple(Standard_True);
1537 if (typ == IntPatch_Analytic) {
1538 (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,ptvtx);
1540 else if (typ == IntPatch_Restriction) {
1541 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptvtx);
1544 (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,ptvtx);
1548 newptvtx.SetParameter(paraml);
1549 //Recalcul des transitions si point sur restriction
1551 arcRef->D1(paraml,p2d,d2d);
1553 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1556 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1558 tgline.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1559 if (ptvtx.IsOnDomS1()) {
1560 const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS1();
1561 thearc->D1(ptvtx.ParameterOnArc1(),p2d,d2d);
1562 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1563 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1564 norm1 = d1u.Crossed(d1v);
1565 if(norm1.SquareMagnitude()<1e-16) {
1566 TRest.SetValue(Standard_True,IntSurf_Undecided);
1567 TArc.SetValue(Standard_True,IntSurf_Undecided);
1570 IntSurf::MakeTransition(tgline,tgarc,norm1,TRest,TArc);
1572 newptvtx.SetArc(Standard_True,thearc,ptvtx.ParameterOnArc1(),
1575 if (ptvtx.IsOnDomS2()) {
1576 const Handle(Adaptor2d_HCurve2d)& thearc = ptvtx.ArcOnS2();
1577 thearc->D1(ptvtx.ParameterOnArc2(),p2d,d2d);
1578 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1579 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1580 norm2 = d1u.Crossed(d1v);
1581 if(norm2.SquareMagnitude()<1e-16) {
1582 TRest.SetValue(Standard_True,IntSurf_Undecided);
1583 TArc.SetValue(Standard_True,IntSurf_Undecided);
1586 IntSurf::MakeTransition(tgline,tgarc,norm2,TRest,TArc);
1588 newptvtx.SetArc(Standard_False,thearc,ptvtx.ParameterOnArc2(),
1592 rline->AddVertex(newptvtx);
1594 procl=Standard_True;
1595 rline->SetLastPoint(rline->NbVertex());
1600 // Si on a traite le pt debut et/ou fin, on ne doit pas recommencer si
1601 // il (ils) correspond(ent) a un point multiple.
1604 dofirst = Standard_False;
1607 dolast = Standard_False;
1611 // Si on n a pas trouve le point debut et./ou fin sur une des lignes
1612 // d intersection, il faut quand-meme le placer sur la restriction solution
1615 ptvtx.SetValue(PStartf.Value(),PStartf.Tolerance(),Standard_False);
1616 Quad1.Parameters(PStartf.Value(),U1,V1);
1617 Quad2.Parameters(PStartf.Value(),U2,V2);
1618 ptvtx.SetParameters(U1,V1,U2,V2);
1619 ptvtx.SetParameter(paramf);
1620 if (! PStartf.IsNew()) {
1621 IntSurf_Transition Transline;
1622 IntSurf_Transition Transarc;
1623 ptvtx.SetVertex(OnFirst,PStartf.Vertex());
1624 ptvtx.SetArc(OnFirst,PStartf.Arc(),PStartf.Parameter(),
1625 Transline,Transarc);
1628 rline->AddVertex(ptvtx);
1629 rline->SetFirstPoint(rline->NbVertex());
1632 ptvtx.SetValue(PStartl.Value(),PStartl.Tolerance(),Standard_False);
1633 Quad1.Parameters(PStartl.Value(),U1,V1);
1634 Quad2.Parameters(PStartl.Value(),U2,V2);
1635 ptvtx.SetParameters(U1,V1,U2,V2);
1636 ptvtx.SetParameter(paraml);
1637 if (! PStartl.IsNew()) {
1638 IntSurf_Transition Transline;
1639 IntSurf_Transition Transarc;
1641 ptvtx.SetVertex(OnFirst,PStartl.Vertex());
1642 ptvtx.SetArc(OnFirst,PStartl.Arc(),PStartl.Parameter(),
1643 Transline,Transarc);
1646 rline->AddVertex(ptvtx);
1647 rline->SetLastPoint(rline->NbVertex());
1654 void ProcessRLine (IntPatch_SequenceOfLine& slin,
1655 // const Handle(Adaptor3d_HSurface)& Surf1,
1656 // const Handle(Adaptor3d_HSurface)& Surf2,
1657 const IntSurf_Quadric& Quad1,
1658 const IntSurf_Quadric& Quad2,
1659 const Standard_Real _TolArc) {
1661 // On cherche a placer sur les restrictions solutions les points "multiples"
1662 // des autres lignes d intersection
1663 // Pas forcemment le plus efficace : on rique de projeter plusieurs fois
1664 // le meme point sur la meme restriction...
1666 Standard_Real TolArc=100.0*_TolArc;
1667 if(TolArc>0.1) TolArc=0.1;
1669 Standard_Integer i,j,k;
1670 Standard_Integer Nblin,Nbvtx, Nbpt;
1672 Standard_Boolean OnFirst = Standard_False,project = Standard_False,keeppoint = Standard_False;
1674 Standard_Boolean OnFirst,project,keeppoint;
1676 Handle(Adaptor2d_HCurve2d) arcref;
1677 Standard_Real paramproj,paramf,paraml;
1679 TColgp_SequenceOfPnt seq_Pnt3d;
1680 TColStd_SequenceOfReal seq_Real;
1682 gp_Pnt ptproj,toproj,valpt;
1686 gp_Vec d1u,d1v,tgrest,tgarc,norm;
1687 IntSurf_Transition TRest,TArc;
1689 Standard_Real U =0.,V =0.;
1693 IntPatch_Point Ptvtx,newptvtx;
1695 IntPatch_IType typ1,typ2;
1698 Nblin = slin.Length();
1699 for (i=1; i<=Nblin; i++) {
1700 const Handle(IntPatch_Line)& slini = slin(i);
1701 typ1 = slini->ArcType();
1702 if (typ1 == IntPatch_Restriction) {
1705 for (j=1; j<=Nblin; j++) {
1706 const Handle(IntPatch_Line)& slinj = slin(j);
1707 Nbpt = seq_Pnt3d.Length(); // important que ce soit ici
1708 typ2 = slinj->ArcType();
1709 if (typ2 != IntPatch_Restriction) {
1711 //-- arcref = (*((Handle(IntPatch_RLine)*)&slini))->Arc();
1712 //-- OnFirst = (*((Handle(IntPatch_RLine)*)&slini))->IsOnFirstSurface();
1714 //-- DES CHOSES A FAIRE ICI
1715 if((*((Handle(IntPatch_RLine)*)&slini))->IsArcOnS1()) {
1716 OnFirst=Standard_True;
1717 arcref= (*((Handle(IntPatch_RLine)*)&slini))->ArcOnS1();
1719 else if((*((Handle(IntPatch_RLine)*)&slini))->IsArcOnS2()) {
1720 arcref= (*((Handle(IntPatch_RLine)*)&slini))->ArcOnS2();
1721 OnFirst=Standard_False;
1723 if ((*((Handle(IntPatch_RLine)*)&slini))->HasFirstPoint()) {
1724 paramf = (*((Handle(IntPatch_RLine)*)&slini))->FirstPoint().ParameterOnLine();
1727 // cout << "Pas de param debut sur rst solution" << endl;
1728 paramf = RealFirst();
1730 if ((*((Handle(IntPatch_RLine)*)&slini))->HasLastPoint()) {
1731 paraml = (*((Handle(IntPatch_RLine)*)&slini))->LastPoint().ParameterOnLine();
1734 // cout << "Pas de param debut sur rst solution" << endl;
1735 paraml = RealLast();
1738 if (typ2 == IntPatch_Analytic) {
1739 Nbvtx = (*((Handle(IntPatch_ALine)*)&slinj))->NbVertex();
1742 Nbvtx = (*((Handle(IntPatch_GLine)*)&slinj))->NbVertex();
1746 Standard_Boolean EdgeDegenere=Standard_True;
1747 for(Standard_Integer edg=0;EdgeDegenere && edg<=10;edg++) {
1748 arcref->D1(paramf+(paraml-paramf)*edg*0.1,p2d,d2d);
1750 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1753 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1755 if(d1u.Magnitude()>1e-7) {
1756 EdgeDegenere=Standard_False;
1760 for (k=1; EdgeDegenere==Standard_False && k<=Nbvtx; k++) {
1761 if (typ2 == IntPatch_Analytic) {
1762 Ptvtx = (*((Handle(IntPatch_ALine)*)&slinj))->Vertex(k);
1765 Ptvtx = (*((Handle(IntPatch_GLine)*)&slinj))->Vertex(k);
1767 if ((OnFirst && !Ptvtx.IsOnDomS1()) ||
1768 (!OnFirst && !Ptvtx.IsOnDomS2())) {
1769 // Si OnFirst && OnDomS1, c est qu on est a une extremite
1770 // ca doit etre traite par Process Segment...
1771 project = Standard_True;
1772 keeppoint = Standard_False;
1773 toproj = Ptvtx.Value();
1775 Standard_Integer jj;
1776 for (jj = 1; jj <= Nbpt; jj++) {
1777 //for (Standard_Integer jj = 1; jj <= Nbpt; jj++) {
1778 if (toproj.Distance(seq_Pnt3d(jj)) < _TolArc) {
1779 project = Standard_False;
1783 if (project) { //-- il faut projeter pour trouver le point sur la rline.
1785 Ptvtx.ParametersOnS1(U,V);
1788 Ptvtx.ParametersOnS2(U,V);
1791 project = IntPatch_HInterTool::Project(arcref,gp_Pnt2d(U,V),
1796 ptproj = Quad1.Value(p2d.X(),p2d.Y());
1799 ptproj = Quad2.Value(p2d.X(),p2d.Y());
1801 if ((toproj.Distance(ptproj) <=100*TolArc) &&
1802 (paramproj >= paramf) && (paramproj <= paraml)){
1804 newptvtx.SetParameter(paramproj);
1805 keeppoint = Standard_True;
1806 seq_Pnt3d.Append(toproj);
1807 seq_Real.Append(paramproj);
1809 //-- verifier que si la restriction arcref est trouvee, elle porte ce vertex
1810 for (int ri=1; ri<=Nblin; ri++) {
1811 const Handle(IntPatch_Line)& slinri = slin(ri);
1812 if (slinri->ArcType() == IntPatch_Restriction) {
1813 if(OnFirst && (*((Handle(IntPatch_RLine)*)&slinri))->IsArcOnS1()) {
1814 if(arcref == (*((Handle(IntPatch_RLine)*)&slinri))->ArcOnS1()) {
1815 (*((Handle(IntPatch_RLine)*)&slinri))->AddVertex(newptvtx);
1816 //printf("\n ImpImpIntersection_0.gxx CAS1 \n");
1819 else if(OnFirst==Standard_False && (*((Handle(IntPatch_RLine)*)&slinri))->IsArcOnS2()) {
1820 if(arcref == (*((Handle(IntPatch_RLine)*)&slinri))->ArcOnS2()) {
1821 (*((Handle(IntPatch_RLine)*)&slinri))->AddVertex(newptvtx);
1822 //printf("\n ImpImpIntersection_0.gxx CAS2 \n");
1827 // -- --------------------------------------------------
1832 keeppoint = Standard_True;
1834 newptvtx.SetParameter(seq_Real(jj));
1837 Ptvtx.SetMultiple(Standard_True);
1838 newptvtx.SetMultiple(Standard_True);
1840 if (typ2 == IntPatch_Analytic) {
1841 (*((Handle(IntPatch_ALine)*)&slinj))->Replace(k,Ptvtx);
1844 (*((Handle(IntPatch_GLine)*)&slinj))->Replace(k,Ptvtx);
1847 if (Ptvtx.IsOnDomS1() || Ptvtx.IsOnDomS2()) {
1849 arcref->D1(newptvtx.ParameterOnLine(),p2d,d2d);
1851 if (OnFirst) { // donc OnDomS2
1852 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1853 tgrest.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1855 const Handle(Adaptor2d_HCurve2d)& thearc = Ptvtx.ArcOnS2();
1856 thearc->D1(Ptvtx.ParameterOnArc2(),p2d,d2d);
1857 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1858 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1859 norm = d1u.Crossed(d1v); //Quad2.Normale(valpt);
1860 if(norm.SquareMagnitude()<1e-16) {
1861 TRest.SetValue(Standard_True,IntSurf_Undecided);
1862 TArc.SetValue(Standard_True,IntSurf_Undecided);
1865 IntSurf::MakeTransition(tgrest,tgarc,norm,TRest,TArc);
1867 newptvtx.SetArc(Standard_False,thearc,
1868 Ptvtx.ParameterOnArc2(),TRest,TArc);
1871 else { // donc OnDomS1
1872 Quad2.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1873 tgrest.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1875 const Handle(Adaptor2d_HCurve2d)& thearc = Ptvtx.ArcOnS1();
1876 thearc->D1(Ptvtx.ParameterOnArc1(),p2d,d2d);
1877 Quad1.D1(p2d.X(),p2d.Y(),valpt,d1u,d1v);
1878 tgarc.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
1879 norm = d1u.Crossed(d1v); //Quad1.Normale(valpt);
1880 if(norm.SquareMagnitude()<1e-16) {
1881 TRest.SetValue(Standard_True,IntSurf_Undecided);
1882 TArc.SetValue(Standard_True,IntSurf_Undecided);
1885 IntSurf::MakeTransition(tgrest,tgarc,norm,TRest,TArc);
1887 newptvtx.SetArc(Standard_True,thearc,
1888 Ptvtx.ParameterOnArc1(),TRest,TArc);
1890 } //-- if (Ptvtx.IsOnDomS1() || Ptvtx.IsOnDomS2())
1892 (*((Handle(IntPatch_RLine)*)&slini))->AddVertex(newptvtx);
1894 } //-- if (keeppoint)
1895 } //-- if ((OnFirst && !Ptvtx.IsOnDomS1())||(!OnFirst && !Ptvtx.IsOnDomS2()))
1896 } //-- boucle sur les vertex
1897 } //-- if (typ2 != IntPatch_Restriction)
1898 } //-- for (j=1; j<=Nblin; j++)
1899 } //-- if (typ1 == IntPatch_Restriction)
1900 } //-- for (i=1; i<=Nblin; i++)