1 // File: IntPatch_RstInt.cxx
2 // Created: Fri May 7 12:45:18 1993
3 // Author: Jacques GOUSSARD
4 // Copyright: Matra Datavision 1993
6 // ----------------------------------------------------------------------
7 //-- lbr: Modifs importantes du 16-17 Nov 95
8 //-- - Chercher APointOnRstStillExist et OnDifferentRst
9 //-- On veut pouvoir creer un Vtx (A1 sur S1, A2 sur S2)
10 //-- et le Vtx (A1 sur S1, A2bis sur S2)
11 //-- ce qui revient a distinguer un point deja pose sur une
12 //-- restriction de S avec un point pose sur une nouvelle
13 //-- restriction de S.
14 //-- - Pour rester coherent avec cette facon de faire,
15 //-- Chercher(Nbvtx++).
17 #include <IntPatch_RstInt.ixx>
19 #include <IntSurf.hxx>
21 #include <TColgp_SequenceOfPnt.hxx>
22 #include <TColgp_SequenceOfPnt2d.hxx>
23 #include <Intf_SectionPoint.hxx>
24 #include <Intf_TangentZone.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <Precision.hxx>
28 #include <Adaptor2d_HCurve2d.hxx>
29 #include <IntPatch_PolygoTool.hxx>
30 #include <IntPatch_WLine.hxx>
31 #include <IntPatch_RLine.hxx>
32 #include <IntPatch_HInterTool.hxx>
33 #include <IntPatch_SearchPnt.hxx>
34 #include <IntPatch_PolyLine.hxx>
35 #include <IntPatch_PolyArc.hxx>
36 #include <IntPatch_CSFunction.hxx>
37 #include <IntPatch_CurvIntSurf.hxx>
40 static void Recadre(GeomAbs_SurfaceType typeS1,
41 GeomAbs_SurfaceType typeS2,
42 const Handle(IntPatch_WLine)& wlin,
43 Standard_Integer Param,
49 Standard_Integer nbpnts = wlin->NbPnts();
50 if(Param<1) Param=1; else if(Param>nbpnts) Param=nbpnts;
51 Standard_Real U1p,V1p,U2p,V2p;
53 wlin->Point(Param).Parameters(U1p,V1p,U2p,V2p);
55 case GeomAbs_Cylinder:
59 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
60 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
65 if(typeS1==GeomAbs_Torus) {
66 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
67 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
71 case GeomAbs_Cylinder:
75 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
76 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
81 if(typeS2==GeomAbs_Torus) {
82 while(V2<(V1p-1.5*M_PI)) V2+=M_PI+M_PI;
83 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
87 const Standard_Real Confusion = Precision::Confusion();
89 inline Standard_Real Tol3d (const Handle(Adaptor3d_HVertex)& vtx,
90 const Handle(Adaptor3d_TopolTool)& Domain,
91 const Standard_Real tolDef = 0.)
93 return (Domain->Has3d() ? Domain->Tol3d(vtx)
94 : tolDef < Confusion ? Confusion
98 inline Standard_Real Tol3d (const Handle(Adaptor2d_HCurve2d)& arc,
99 const Handle(Adaptor3d_TopolTool)& Domain,
100 const Standard_Real tolDef = 0.)
102 return (Domain->Has3d() ? Domain->Tol3d(arc)
103 : tolDef < Confusion ? Confusion
107 static Standard_Boolean CoincideOnArc(const gp_Pnt& Ptsommet,
108 const Handle(Adaptor2d_HCurve2d)& A,
109 const Handle(Adaptor3d_HSurface)& Surf,
110 const Standard_Real Toler,
111 const Handle(Adaptor3d_TopolTool)& Domain,
112 Handle(Adaptor3d_HVertex)& Vtx)
114 Standard_Real distmin = RealLast();
115 Standard_Real tolarc = Max(Toler,Tol3d(A,Domain));
117 Domain->Initialize(A);
118 Domain->InitVertexIterator();
119 while (Domain->MoreVertex()) {
120 Handle(Adaptor3d_HVertex) vtx1 = Domain->Vertex();
121 Standard_Real prm = IntPatch_HInterTool::Parameter(vtx1,A);
122 gp_Pnt2d p2d = A->Value(prm);
123 gp_Pnt point = Surf->Value(p2d.X(),p2d.Y());
124 const Standard_Real dist = point.Distance(Ptsommet);
125 Standard_Real tol = Max (tolarc, Tol3d(vtx1,Domain));
127 if (dist <= tol && dist <= distmin) { // the best coincidence
131 Domain->NextVertex();
133 return distmin < RealLast();
137 static void VerifyTgline(const Handle(IntPatch_WLine)& wlin,
138 const Standard_Integer param,
139 const Standard_Real Tol,
144 && Abs(Tgl.Z())<Tol) {
145 //-- On construit une tangente plus grande
146 //-- (Eviter des points tres proches ds Walking)
147 Standard_Integer i, n, nbpt=wlin->NbPnts();
148 Standard_Boolean forward = (nbpt-param) >= (param-1);
149 for (n = 2; n > 0; n--, forward = !forward) {
151 for(i=param+1; i<=nbpt; i++) {
152 gp_Vec T(wlin->Point(param).Value(),wlin->Point(i).Value());
155 || Abs(T.Z())>=Tol) {
162 for(i=param-1; i>=1; i--) {
163 gp_Vec T(wlin->Point(i).Value(),wlin->Point(param).Value());
166 || Abs(T.Z())>=Tol) {
176 static void GetLinePoint2d (const Handle(IntPatch_Line)& L,
177 const Standard_Real param,
178 const Standard_Boolean OnFirst,
179 Standard_Real& U, Standard_Real& V)
181 IntPatch_IType typL = L->ArcType();
182 const Handle(IntPatch_WLine)& wlin = (const Handle(IntPatch_WLine)&)L;
183 const Handle(IntPatch_RLine)& rlin = (const Handle(IntPatch_RLine)&)L;
184 Standard_Integer Nbptlin = (typL == IntPatch_Walking
188 Standard_Real par = IntegerPart(param);
189 Standard_Integer Irang = Standard_Integer(par);
190 if (Irang == Nbptlin) {
195 par = Abs(param-par);
197 Standard_Real us1,vs1,us2,vs2;
198 if (typL == IntPatch_Walking) {
200 wlin->Point(Irang).ParametersOnS1(us1,vs1);
201 wlin->Point(Irang+1).ParametersOnS1(us2,vs2);
204 wlin->Point(Irang).ParametersOnS2(us1,vs1);
205 wlin->Point(Irang+1).ParametersOnS2(us2,vs2);
210 rlin->Point(Irang).ParametersOnS1(us1,vs1);
211 rlin->Point(Irang+1).ParametersOnS1(us2,vs2);
214 rlin->Point(Irang).ParametersOnS2(us1,vs1);
215 rlin->Point(Irang+1).ParametersOnS2(us2,vs2);
219 U = (1.-par)*us1+par*us2;
220 V = (1.-par)*vs1+par*vs2;
223 static void GetWLinePoint (const Handle(IntPatch_WLine)& wlin,
224 const Standard_Real param,
225 Standard_Real& U1, Standard_Real& V1,
226 Standard_Real& U2, Standard_Real& V2,
229 Standard_Integer Nbptlin = wlin->NbPnts();
230 Standard_Real par = IntegerPart(param);
231 Standard_Integer Irang = Standard_Integer(par);
232 if (Irang == Nbptlin) {
237 par = Abs(param-par);
239 const IntSurf_PntOn2S& p2s1 = wlin->Point(Irang);
240 const IntSurf_PntOn2S& p2s2 = wlin->Point(Irang+1);
241 const gp_Pnt& p1 = p2s1.Value();
242 const gp_Pnt& p2 = p2s2.Value();
243 P.ChangeCoord().SetLinearForm(1.-par, p1.XYZ(), par, p2.XYZ());
245 Standard_Real us1,vs1,us2,vs2;
246 p2s1.ParametersOnS1(us1,vs1);
247 p2s2.ParametersOnS1(us2,vs2);
248 U1 = (1.-par)*us1+par*us2;
249 V1 = (1.-par)*vs1+par*vs2;
251 p2s1.ParametersOnS2(us1,vs1);
252 p2s2.ParametersOnS2(us2,vs2);
253 U2 = (1.-par)*us1+par*us2;
254 V2 = (1.-par)*vs1+par*vs2;
257 static Standard_Boolean FindParameter(const Handle(IntPatch_Line)& L,
258 const Handle(Adaptor3d_HSurface)& OtherSurf,
259 const Standard_Real Tol,
261 const gp_Pnt2d& Ptsom2d,
262 Standard_Real& Param,
264 const Standard_Integer ParamApproche,
265 const Standard_Boolean OnFirst)
268 // MSV 28.03.2002: find parameter on WLine in 2d space
270 //Si la ligne est de type restriction, c est qu on provient necessairement
271 // du cas implicite/parametree, et que la ligne est restriction de
272 // la surface bi-parametree. Cette surface bi-parametree est necessairement
273 // passee en argument a PutVertexOnline dans la variable OtherSurf.
275 // Dans le cas d une ligne de cheminement, il faudrait voir la projection
276 // et le calcul de la tangente.
278 const Handle(IntPatch_RLine)& rlin = (*((Handle(IntPatch_RLine)*)&L)); //-- aucune verification n est
279 const Handle(IntPatch_WLine)& wlin = (*((Handle(IntPatch_WLine)*)&L)); //-- faite au cast.
284 Standard_Real Tol2 = Tol*Tol;
285 IntPatch_IType typL = L->ArcType();
286 Tgl.SetCoord(0.0,0.0,0.0);
288 if ( typL == IntPatch_Restriction) {
289 if (!OnFirst && rlin->IsArcOnS1()) {
290 IntPatch_HInterTool::Project(rlin->ArcOnS1(),Ptsom2d,Param,p2d);
291 rlin->ArcOnS1()->D1(Param,p2d,d2d);
293 else if (OnFirst && rlin->IsArcOnS2()) {
294 IntPatch_HInterTool::Project(rlin->ArcOnS2(),Ptsom2d,Param,p2d);
295 rlin->ArcOnS2()->D1(Param,p2d,d2d);
298 return(Standard_False);
300 OtherSurf->D1(p2d.X(),p2d.Y(),ptbid,d1u,d1v);
301 if (ptbid.SquareDistance(Ptsom) > Tol2) {
302 return Standard_False;
304 Tgl.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
305 return(Standard_True);
308 else if (typL == IntPatch_Walking) {
309 Standard_Integer i, is, nbpt=wlin->NbPnts();
310 Standard_Real norm1,norm2;
311 Standard_Integer ParamSearchInf=1;
312 Standard_Integer ParamSearchSup=nbpt;
314 if((ParamApproche-2) > ParamSearchInf) {
315 ParamSearchInf = ParamApproche-2;
317 if((ParamApproche+2) < ParamSearchSup) {
318 ParamSearchSup = ParamApproche+2;
321 Standard_Integer inf[3],sup[3];
322 // first search inside close bounding around ParamApproche;
323 // then search to the nearest end of line;
324 // and then search to the farest end of line.
325 inf[0] = ParamSearchInf; sup[0] = ParamSearchSup;
326 if (ParamSearchInf-1 < nbpt-ParamSearchSup) {
327 inf[1] = 1; sup[1] = ParamSearchInf;
328 inf[2] = ParamSearchSup; sup[2] = nbpt;
331 inf[1] = ParamSearchSup; sup[1] = nbpt;
332 inf[2] = 1; sup[2] = ParamSearchInf;
335 Standard_Boolean found = Standard_False;
336 for (is=0; is < 3 && !found; is++) {
339 p1 = wlin->Point(inf[is]).Value();
340 v1 = gp_Vec (Ptsom,p1);
341 norm1 = v1.SquareMagnitude();
342 Standard_Real normmin = Tol2;
343 Standard_Integer ibest = 0;
344 if (norm1 <= normmin) {
348 for (i=inf[is]+1; i <= sup[is] && !found; i++) {
349 p2 = wlin->Point(i).Value();
350 v2 = gp_Vec (Ptsom,p2);
351 norm2 = v2.SquareMagnitude();
352 if (v1.Dot(v2) < 0.) {
353 Param = (Standard_Real)(i-1) + 1./(1.+Sqrt(norm2/norm1));
354 Tgl = gp_Vec (p1,p2);
355 found = Standard_True;
357 else if (norm2 < normmin) {
361 v1 = v2; p1 = p2; norm1 = norm2;
363 if (!found && ibest) {
364 Param = (Standard_Real)ibest;
365 found = Standard_True;
368 if (found) return Standard_True;
371 Standard_DomainError::Raise();
373 return Standard_False;
376 inline Standard_Boolean ArePnt2dEqual(const gp_Pnt2d& p1, const gp_Pnt2d& p2,
377 const Standard_Real tolU,
378 const Standard_Real tolV)
380 return Abs(p1.X()-p2.X()) < tolU && Abs(p1.Y()-p2.Y()) < tolV;
383 static gp_Pnt2d GetPointOnPolygo(const IntPatch_Polygo& Pol,
384 const Standard_Real param)
386 Standard_Real par = IntegerPart(param);
387 Standard_Integer irang = Standard_Integer(par) + 1;
388 if (irang == Pol.NbPoints()) {
393 par = Abs(param-par);
395 gp_Pnt2d p1 = Pol.Point(irang);
396 gp_Pnt2d p2 = Pol.Point(irang+1);
398 p.ChangeCoord().SetLinearForm(1.-par,p1.XY(),par,p2.XY());
402 static Standard_Boolean IsSegment2dSmall(const IntPatch_Polygo& Pol,
403 const Standard_Real parmin,
404 const Standard_Real parmax,
405 const Standard_Real URes,
406 const Standard_Real VRes)
408 Standard_Integer irang1 = Standard_Integer(IntegerPart(parmin)) + 2;
409 Standard_Integer irang2 = Standard_Integer(IntegerPart(parmax)) + 1;
411 Standard_Real du=0.,dv=0.;
412 p1 = GetPointOnPolygo(Pol,parmin);
413 for (Standard_Integer i=irang1; i <= irang2 && du <= URes && dv <= VRes; i++) {
415 du += Abs(p2.X()-p1.X());
416 dv += Abs(p2.Y()-p1.Y());
419 if (du <= URes && dv <= VRes) {
420 p2 = GetPointOnPolygo(Pol,parmax);
421 du += Abs(p2.X()-p1.X());
422 dv += Abs(p2.Y()-p1.Y());
424 return du <= URes && dv <= VRes;
427 //=======================================================================
428 //function : PutVertexOnLine
430 //=======================================================================
432 void IntPatch_RstInt::PutVertexOnLine (Handle(IntPatch_Line)& L,
433 const Handle(Adaptor3d_HSurface)& Surf,
434 const Handle(Adaptor3d_TopolTool)& Domain,
435 const Handle(Adaptor3d_HSurface)& OtherSurf,
436 const Standard_Boolean OnFirst,
437 const Standard_Real Tol )
440 // Domain est le domaine de restriction de la surface Surf.
441 // On intersectera un arc de Surf avec la surface OtherSurf.
442 // Si OnFirst = True, c est que la surface Surf correspond a la 1ere
443 // surface donnee aux algo d intersection.
445 static IntPatch_SearchPnt Commun;
448 Standard_Real U1,V1,U2,V2;
449 Standard_Real paramarc=0.,paramline=0.;
450 Standard_Integer i,j,k;
451 TColgp_SequenceOfPnt locpt;
452 TColgp_SequenceOfPnt2d locpt2;
453 const Handle(IntPatch_RLine)& rlin = (*((Handle(IntPatch_RLine)*)&L)); //-- aucune verification n est
454 const Handle(IntPatch_WLine)& wlin = (*((Handle(IntPatch_WLine)*)&L)); //-- faite au cast.
455 Standard_Integer Nbvtx =0;
456 Standard_Integer Nbptlin =0;
457 Standard_Real tolPLin = Surf->UResolution(Precision::Confusion());
458 tolPLin = Max (tolPLin, Surf->VResolution(Precision::Confusion()));
459 tolPLin = Min (tolPLin, Precision::Confusion());
460 IntPatch_PolyLine PLin(tolPLin);
462 Standard_Real PFirst,PLast;
463 Standard_Integer NbEchant;
464 gp_Pnt ptsommet, ptbid;
465 gp_Vec tgline, tgrst, d1u, d1v, normsurf;
470 IntPatch_Point Sommet, ptline;
471 Handle(Adaptor3d_HVertex) vtxarc,vtxline;
472 Handle(Adaptor2d_HCurve2d) arc;
473 Standard_Boolean VtxOnArc, duplicate, found;
474 IntSurf_Transition transarc,transline;
476 IntPatch_IType typL = L->ArcType();
477 if (typL == IntPatch_Walking) {
478 Nbvtx = wlin->NbVertex();
479 PLin.SetWLine(OnFirst,wlin);
480 Nbptlin = wlin->NbPnts();
482 else if ( typL == IntPatch_Restriction) {
483 Nbvtx = rlin->NbVertex();
484 PLin.SetRLine(OnFirst,rlin);
485 Nbptlin = rlin->NbPnts();
488 Standard_DomainError::Raise();
490 if (!Domain->Has3d())
491 // don't use computed deflection in the mode of pure geometric intersection
494 const Standard_Boolean SurfaceIsUClosed = Surf->IsUClosed();
495 const Standard_Boolean SurfaceIsVClosed = Surf->IsVClosed();
496 const Standard_Boolean OSurfaceIsUClosed = OtherSurf->IsUClosed();
497 const Standard_Boolean OSurfaceIsVClosed = OtherSurf->IsVClosed();
498 const Standard_Boolean possiblyClosed = (SurfaceIsUClosed || SurfaceIsVClosed ||
499 OSurfaceIsUClosed || OSurfaceIsVClosed);
500 Standard_Real tolUClosed=0., tolVClosed=0., tolOUClosed=0., tolOVClosed=0.;
501 if (possiblyClosed) {
502 if (SurfaceIsUClosed)
503 tolUClosed = (Surf->LastUParameter() - Surf->FirstUParameter()) * 0.01;
504 if (SurfaceIsVClosed)
505 tolVClosed = (Surf->LastVParameter() - Surf->FirstVParameter()) * 0.01;
506 if (OSurfaceIsUClosed)
507 tolOUClosed = (OtherSurf->LastUParameter() - OtherSurf->FirstUParameter()) * 0.01;
508 if (OSurfaceIsVClosed)
509 tolOVClosed = (OtherSurf->LastVParameter() - OtherSurf->FirstVParameter()) * 0.01;
512 //------------------------------------------------------------------------
513 //-- On traite le cas ou la surface est periodique --
514 //-- il faut dans ce cas considerer la restriction --
515 //-- la restriction decalee de +-2PI --
516 //------------------------------------------------------------------------
517 const Handle(Adaptor3d_HSurface)& Surf1 = (OnFirst ? Surf : OtherSurf);
518 const Handle(Adaptor3d_HSurface)& Surf2 = (OnFirst ? OtherSurf : Surf);
519 GeomAbs_SurfaceType TypeS1 = Surf1->GetType();
520 GeomAbs_SurfaceType TypeS2 = Surf2->GetType();
521 Standard_Boolean SurfaceIsPeriodic = Standard_False;
522 Standard_Boolean SurfaceIsBiPeriodic = Standard_False;
523 GeomAbs_SurfaceType surfacetype = (OnFirst ? TypeS1 : TypeS2);
524 if( surfacetype == GeomAbs_Cylinder
525 || surfacetype == GeomAbs_Cone
526 || surfacetype == GeomAbs_Torus
527 || surfacetype == GeomAbs_Sphere) {
528 SurfaceIsPeriodic = Standard_True;
529 if(surfacetype == GeomAbs_Torus) {
530 SurfaceIsBiPeriodic = Standard_True;
534 Standard_Integer NumeroEdge=0;
536 while (Domain->More()) {
538 arc = Domain->Value();
540 // MSV Oct 15, 2001: use tolerance of this edge if possible
541 Standard_Real edgeTol = Tol3d(arc,Domain,Tol);
542 Standard_Real URes = Surf->UResolution(edgeTol);
543 Standard_Real VRes = Surf->VResolution(edgeTol);
545 IntPatch_HInterTool::Bounds(arc,PFirst,PLast);
546 if (Precision::IsNegativeInfinite(PFirst) ||
547 Precision::IsPositiveInfinite(PLast)) {
548 //-- cout<<" IntPatch_RstInt::PutVertexOnLine ---> Restrictions Infinies :"<<endl;
552 Standard_Boolean isVFirst = Standard_False, isVLast = Standard_False;
553 gp_Pnt2d p2dFirst,p2dLast;
554 Standard_Real tolUFirst=0.,tolVFirst=0.,tolULast=0.,tolVLast=0.;
555 Domain->Initialize(arc);
556 for (Domain->InitVertexIterator(); Domain->MoreVertex(); Domain->NextVertex()) {
557 Handle(Adaptor3d_HVertex) vtx = Domain->Vertex();
558 Standard_Real prm = IntPatch_HInterTool::Parameter(vtx,arc);
559 if (Abs(prm - PFirst) < Precision::PConfusion()) {
560 arc->D0(PFirst,p2dFirst);
561 Standard_Real tol3d = Max (Tol3d(vtx,Domain), edgeTol);
562 tolUFirst = Surf->UResolution(tol3d);
563 tolVFirst = Surf->VResolution(tol3d);
564 isVFirst = Standard_True;
566 else if (Abs(prm - PLast) < Precision::PConfusion()) {
567 arc->D0(PLast,p2dLast);
568 Standard_Real tol3d = Max (edgeTol, Tol3d(vtx,Domain));
569 tolULast = Surf->UResolution(tol3d);
570 tolVLast = Surf->VResolution(tol3d);
571 isVLast = Standard_True;
575 Bnd_Box2d BPLin = IntPatch_PolygoTool::Bounding(PLin);
577 if(SurfaceIsPeriodic) {
578 Standard_Real xmin,ymin,xmax,ymax,g;
579 BPLin.Get(xmin,ymin,xmax,ymax);
582 BPLin.Update(xmin-M_PI-M_PI,ymin,
583 xmax+M_PI+M_PI,ymax);
586 if(SurfaceIsBiPeriodic) {
587 Standard_Real xmin,ymin,xmax,ymax,g;
588 BPLin.Get(xmin,ymin,xmax,ymax);
591 BPLin.Update(xmin,ymin-M_PI-M_PI,
592 xmax,ymax+M_PI+M_PI);
596 switch(arc->GetType())
598 case GeomAbs_Line: NbEchant=10; break;
599 case GeomAbs_BezierCurve:
601 NbEchant = (3 + arc->NbPoles());
602 if(NbEchant<10) NbEchant=10;
603 else if(NbEchant>50) NbEchant=50;
606 case GeomAbs_BSplineCurve:
608 //szv:const Standard_Real nbs = (arc->NbKnots() * arc->Degree())*(arc->LastParameter() - arc->FirstParameter())/(PLast-PFirst);
609 const Standard_Real nbs = (arc->NbKnots() * arc->Degree())*(PLast-PFirst)/(arc->LastParameter() - arc->FirstParameter());
610 NbEchant = (nbs < 2.0 ? 2 : (Standard_Integer)nbs);
611 if(NbEchant<10) NbEchant=10;
612 else if (NbEchant>50) NbEchant=50;
621 IntPatch_PolyArc Brise(arc,NbEchant,PFirst,PLast,BPLin);
623 Standard_Integer IndiceOffsetBiPeriodic = 0;
624 Standard_Integer IndiceOffsetPeriodic = 0;
625 Standard_Real OffsetV = 0.0;
626 Standard_Real OffsetU = 0.0;
629 if(IndiceOffsetBiPeriodic == 1)
630 OffsetV = -M_PI-M_PI;
631 else if(IndiceOffsetBiPeriodic == 2)
635 if(IndiceOffsetPeriodic == 1)
636 OffsetU = -M_PI-M_PI;
637 else if(IndiceOffsetPeriodic == 2)
640 Brise.SetOffset(OffsetU,OffsetV);
642 static int debug_polygon2d =0;
643 if(debug_polygon2d) {
644 cout<<" ***** Numero Restriction : "<<NumeroEdge<<" *****"<<endl;
645 IntPatch_PolygoTool::Dump(PLin);
646 IntPatch_PolygoTool::Dump(Brise);
649 Commun.Perform(PLin,Brise);
652 Standard_Integer Commun_NbSectionPoints = Commun.NbSectionPoints();
653 Standard_Integer Commun_NbTangentZones = Commun.NbTangentZones();
654 Standard_Integer Commun_Section_Tangent = Commun_NbSectionPoints
655 + Commun_NbTangentZones;
656 for (i=1;i<=Commun_Section_Tangent;i++) {
657 Standard_Real W1[2],W2[2];
658 Standard_Boolean refine[2],useWL[2];
659 Standard_Integer nbpt = 1;
660 if(i<=Commun_NbSectionPoints) {
661 // intersection point
662 W1[0] = Commun.PntValue(i).ParamOnFirst();
663 W2[0] = Commun.PntValue(i).ParamOnSecond();
664 refine[0] = Standard_True;
668 Standard_Real UMinCh,UMaxCh; //-- ligne de cheminement 0..(Nbptlin-1)
669 Standard_Real UMinAr,UMaxAr; //-- polyline of arc 0..(NbEchant-1)
670 Commun.ZoneValue(i-Commun_NbSectionPoints).ParamOnFirst(UMinCh,UMaxCh);
671 Commun.ZoneValue(i-Commun_NbSectionPoints).ParamOnSecond(UMinAr,UMaxAr);
672 gp_Pnt2d p1Ar = GetPointOnPolygo(Brise,UMinAr);
673 gp_Pnt2d p2Ar = GetPointOnPolygo(Brise,UMaxAr);
674 Standard_Real tolU = URes*2.;
675 Standard_Real tolV = VRes*2.;
676 if (isVFirst && ArePnt2dEqual(p1Ar,p2dFirst,tolUFirst,tolVFirst)) {
677 tolU = Max(tolUFirst,tolU); tolV = Max(tolVFirst,tolV);
679 if (isVLast && ArePnt2dEqual(p2Ar,p2dLast,tolULast,tolVLast)) {
680 tolU = Max(tolULast,tolU); tolV = Max(tolVLast,tolV);
682 Standard_Real nptCh = UMaxCh-UMinCh;
683 Standard_Boolean isNptLow = nptCh < 10. && nptCh < Nbptlin/100. ||
684 !Domain->Has3d() && Standard_Integer(nptCh)+1 < Nbptlin;
685 if (!isNptLow && !IsSegment2dSmall(Brise,UMinAr,UMaxAr,tolU,tolV)) {
687 Standard_Real UMinChP,UMaxChP,UMinArP,UMaxArP;
688 UMinChP = IntegerPart(UMinCh); UMinArP = IntegerPart(UMinAr);
689 UMaxChP = IntegerPart(UMaxCh); UMaxArP = IntegerPart(UMaxAr);
690 Standard_Integer irangCh1,irangCh2,irangAr1,irangAr2;
691 irangCh1 = Standard_Integer(UMinChP)+1; irangCh2 = Standard_Integer(UMaxChP)+1;
692 irangAr1 = Standard_Integer(UMinArP)+1; irangAr2 = Standard_Integer(UMaxArP)+1;
693 UMinChP = UMinCh - UMinChP; UMinArP = UMinAr - UMinArP;
694 //UMaxChP = UMaxCh - UMaxChP; UMaxArP = UMaxAr - UMaxArP;
695 const Standard_Real eps = 1e-10;
696 // Standard_Boolean isChExtr1 = irangCh1==1 && UMinChP<eps;
697 // Standard_Boolean isChExtr2 = irangCh2==Nbptlin;
698 Standard_Boolean isArExtr1 = irangAr1==1 && UMinArP<eps;
699 Standard_Boolean isArExtr2 = irangAr2==NbEchant;
700 // detect orientation
701 gp_Pnt2d p1Ch = GetPointOnPolygo(PLin,UMinCh);
702 Standard_Real d11 = p1Ch.SquareDistance(p1Ar);
703 Standard_Real d12 = p1Ch.SquareDistance(p2Ar);
704 Standard_Boolean sameOri = d11 < d12;
706 Standard_Boolean itmp=isArExtr1; isArExtr1=isArExtr2; isArExtr2=itmp;
707 Standard_Real dtmp=UMinAr; UMinAr=UMaxAr; UMaxAr=dtmp;
709 W1[0] = UMinCh; W1[1] = UMaxCh;
710 W2[0] = UMinAr; W2[1] = UMaxAr;
711 //refine[0] = ! (isChExtr1 || isArExtr1);
712 //refine[1] = ! (isChExtr2 || isArExtr2);
713 refine[0] = refine[1] = Standard_False;
714 useWL[0] = !isArExtr1;
715 useWL[1] = !isArExtr2;
719 // treat the middle point as an intersection point
720 W1[0] = 0.5*(UMinCh+UMaxCh);
721 W2[0] = 0.5*(UMinAr+UMaxAr);
722 refine[0] = Standard_True;
726 Standard_Boolean nbTreated = 0;
727 for (Standard_Integer ip=0; ip < nbpt; ip++) {
728 GetLinePoint2d (L, W1[ip]+1, !OnFirst, U,V);
730 if (!refine[ip] && useWL[ip]) {
731 Standard_Real aU1,aV1;
732 GetLinePoint2d (L, W1[ip]+1, OnFirst, aU1,aV1);
733 p2d.SetCoord(aU1,aV1);
734 Standard_Real paramProj;
735 if (!IntPatch_HInterTool::Project(arc,p2d,paramProj,p2d)) continue;
739 Standard_Real par = IntegerPart(W2[ip]);
740 Standard_Integer Irang = Standard_Integer(par) + 1;
741 if (Irang == Brise.NbPoints()) {
746 par =Abs(W2[ip]-par);
748 W = (1.-par)*Brise.Parameter(Irang) + par*Brise.Parameter(Irang+1);
751 Standard_Boolean refined = Standard_False;
753 //------------------------------------------------------------------------
754 //-- On a trouve un point 2d approche Ua,Va intersection de la ligne
755 //-- de cheminement et de la restriction.
757 //-- On injecte ce point ds les intersections Courbe-Surface
759 IntPatch_CSFunction thefunc(OtherSurf,arc,Surf);
760 // MSV: extend UV bounds to not miss solution near the boundary
761 Standard_Real margCoef = 0.004;
762 IntPatch_CurvIntSurf IntCS(U,V,W,thefunc,edgeTol,margCoef);
763 if (IntCS.IsDone()) {
764 if (!IntCS.IsEmpty()) {
765 ptsommet = IntCS.Point();
766 IntCS.ParameterOnSurface(U2,V2);
767 paramarc = IntCS.ParameterOnCurve();
768 refined = Standard_True;
775 arc->D0(paramarc,p2d);
776 Surf->D0(p2d.X(),p2d.Y(),ptsommet);
779 if (!refine[ip] || refined) {
780 duplicate = Standard_False;
781 for (j=1; j<=locpt.Length();j++) {
782 if (ptsommet.Distance(locpt(j)) <= edgeTol) {
783 if (possiblyClosed) {
784 locpt2(j).Coord(U,V);
785 if (OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed ||
786 OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)
789 duplicate = Standard_True;
795 Standard_Integer ParamApproxOnLine = Standard_Integer(W1[ip])+1;
797 arc->D1(paramarc,p2d,d2d);
798 U1 = p2d.X(); V1 = p2d.Y();
799 if (typL == IntPatch_Walking && SurfaceIsPeriodic)
801 Recadre(TypeS1,TypeS2,wlin,ParamApproxOnLine,U1,V1,U2,V2);
803 Recadre(TypeS1,TypeS2,wlin,ParamApproxOnLine,U2,V2,U1,V1);
805 locpt.Append(ptsommet);
806 locpt2.Append(gp_Pnt2d(U2,V2));
808 found = FindParameter(L,OtherSurf,edgeTol,ptsommet,gp_Pnt2d(U2,V2),
809 paramline,tgline,ParamApproxOnLine,OnFirst);
811 if (typL == IntPatch_Walking && found && possiblyClosed) {
813 if (SurfaceIsUClosed || SurfaceIsVClosed) {
814 GetLinePoint2d (L, paramline, OnFirst, U,V);
815 if (SurfaceIsUClosed && Abs(U-U1) > tolUClosed ||
816 SurfaceIsVClosed && Abs(V-V1) > tolVClosed)
817 found = Standard_False;
819 if (found && (OSurfaceIsUClosed || OSurfaceIsVClosed)) {
820 GetLinePoint2d (L, paramline, !OnFirst, U,V);
821 if (OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed ||
822 OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)
823 found = Standard_False;
830 VtxOnArc = CoincideOnArc(ptsommet,arc,Surf,edgeTol,Domain,vtxarc);
831 Standard_Real vtxTol;
833 vtxTol = Tol3d(vtxarc,Domain);
834 if (edgeTol > vtxTol) vtxTol = edgeTol;
836 else vtxTol = edgeTol;
838 //-- It is necessary to test that the point does not already exist
839 //-- - It can be already a point on arc
840 //-- BUT on a different arc
841 // MSV 27.03.2002: find the nearest point; add check in 2d
842 Standard_Integer ivtx = 0;
843 Standard_Real dmin = RealLast();
844 for (j=1; j<=Nbvtx; j++) {
845 const IntPatch_Point& Rptline = (typL == IntPatch_Walking
848 Standard_Boolean APointOnRstStillExist =
849 (OnFirst && Rptline.IsOnDomS1() && Rptline.ArcOnS1() == arc ||
850 !OnFirst && Rptline.IsOnDomS2() && Rptline.ArcOnS2() == arc);
851 if(!APointOnRstStillExist) {
852 if (possiblyClosed) {
853 if (SurfaceIsUClosed || SurfaceIsVClosed) {
854 if (OnFirst) Rptline.ParametersOnS1(U,V);
855 else Rptline.ParametersOnS2(U,V);
856 if (SurfaceIsUClosed && Abs(U-U1) > tolUClosed ||
857 SurfaceIsVClosed && Abs(V-V1) > tolVClosed)
860 if (OSurfaceIsUClosed || OSurfaceIsVClosed) {
861 if (OnFirst) Rptline.ParametersOnS2(U,V);
862 else Rptline.ParametersOnS1(U,V);
863 if (OSurfaceIsUClosed && Abs(U-U2) > tolOUClosed ||
864 OSurfaceIsVClosed && Abs(V-V2) > tolOVClosed)
868 Standard_Real dist = ptsommet.Distance(Rptline.Value());
869 Standard_Real dt = Max(vtxTol, Rptline.Tolerance());
874 if( surfacetype == GeomAbs_Cone ) {
879 // cancel previous solution because this point is better
880 // but its tolerance is not large enough
888 if (ptline.Tolerance() > vtxTol) {
889 vtxTol = ptline.Tolerance();
891 // now we should repeat attempt to coincide on a bound of arc
892 VtxOnArc = CoincideOnArc(ptsommet,arc,Surf,vtxTol,Domain,vtxarc);
894 Standard_Real tol = Tol3d(vtxarc,Domain);
895 if (tol > vtxTol) vtxTol = tol;
901 if (typL == IntPatch_Walking)
902 VerifyTgline(wlin,(Standard_Integer)paramline,edgeTol,tgline);
904 Surf->D1(U1,V1,ptbid,d1u,d1v);
905 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
907 normsurf = d1u.Crossed(d1v);
908 if (normsurf.Magnitude() < gp::Resolution()) {
909 transline.SetValue(Standard_True,IntSurf_Undecided);
910 transarc.SetValue(Standard_True,IntSurf_Undecided);
913 IntSurf::MakeTransition(tgline,tgrst,normsurf,transline,transarc);
915 if (typL == IntPatch_Walking && !refine[ip]) {
916 // for new vertex use coordinates from Line
918 GetWLinePoint (wlin, paramline, U1,V1,U2,V2,ptsommet);
920 GetWLinePoint (wlin, paramline, U2,V2,U1,V1,ptsommet);
925 Sommet.SetValue(ptsommet,vtxTol,Standard_False); // pour tangence
927 Sommet.SetParameters(U1,V1,U2,V2);
929 Sommet.SetParameters(U2,V2,U1,V1);
932 Sommet.SetVertex(OnFirst,vtxarc);
934 //---------------------------------------------------------
935 //-- lbr : On remplace le point d indice paramline sur la -
936 //-- ligne par le vertex . -
937 //---------------------------------------------------------
938 Sommet.SetParameter(paramline); // sur ligne d intersection
939 Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc);
941 if (typL == IntPatch_Walking) {
942 wlin->AddVertex(Sommet);
946 rlin->AddVertex(Sommet);
951 // CAS DE FIGURE : en appelant s1 la surf sur laquelle on
952 // connait les pts sur restriction, et s2 celle sur laquelle
953 // on les cherche. Le point trouve verifie necessairement
955 // Pas vtxS1, pas vtxS2 :
956 // on recupere le point et on applique SetArcOnS2 et
957 // eventuellement SetVertexOnS2. Si on a deja IsOnDomS2,
958 // on considere que le point est deja traite, mais ne devrait
960 // vtxS1, pas vtxS2 :
961 // si pas IsOnDomS2 : pour chaque occurrence, faire SetArcOnS2,
962 // et eventuellement SetVertexOnS2.
963 // si IsOnDomS2 : impossible, on doit avoir IsVtxOnS2.
965 // on doit avoir VtxOnArc = True. On duplique chaque occurrence
966 // "sur S1" du point en changeant ArcOnS2.
967 // pas vtxS1, vtxS2 :
968 // on doit avoir VtxOnArc = True. On duplique le point sur S1
969 // en changeant ArcOnS2.
970 Standard_Boolean OnDifferentRst =
971 (OnFirst && ptline.IsOnDomS1() && ptline.ArcOnS1() != arc ||
972 !OnFirst && ptline.IsOnDomS2() && ptline.ArcOnS2() != arc);
973 ptline.SetTolerance(vtxTol);
974 if ( (!ptline.IsVertexOnS1() && OnFirst)
975 || (!ptline.IsVertexOnS2() && !OnFirst)
976 || (OnDifferentRst)) {
977 if ( (!ptline.IsOnDomS2() && !OnFirst)
978 ||(!ptline.IsOnDomS1() && OnFirst)
979 ||(OnDifferentRst)) {
980 ptline.SetArc(OnFirst,arc,paramarc,transline,transarc);
981 //ptline.SetParameter(paramline); //-- rajout lbr le 20 nov 97
983 ptline.SetVertex(OnFirst,vtxarc);
984 if (typL == IntPatch_Walking) {
986 wlin->AddVertex(ptline);
990 wlin->Replace(ivtx,ptline);
995 rlin->AddVertex(ptline);
999 rlin->Replace(ivtx,ptline);
1003 else if ( ( OnFirst && ptline.IsVertexOnS2())
1004 ||(!OnFirst && ptline.IsVertexOnS1())) {
1006 Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc);
1008 Sommet.SetVertex(OnFirst,vtxarc);
1009 if (typL == IntPatch_Walking) {
1010 wlin->AddVertex(Sommet);
1014 rlin->AddVertex(Sommet);
1019 //-- cout << "pb dans RstInt Type 1 " << endl;
1023 Handle(Adaptor3d_HVertex) vtxref = (OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()) ;
1024 if ( ( OnFirst && !ptline.IsOnDomS2())
1025 ||(!OnFirst && !ptline.IsOnDomS1())) {
1026 ptline.SetArc(OnFirst,arc,paramarc,transline,transarc);
1028 ptline.SetVertex(OnFirst,vtxarc);
1029 if (typL == IntPatch_Walking) {
1030 wlin->Replace(ivtx,ptline);
1033 rlin->Replace(ivtx,ptline);
1036 for (k=1; k<=Nbvtx; k++) if (k != ivtx) {
1037 if (typL == IntPatch_Walking) {
1038 ptline = wlin->Vertex(k);
1041 ptline = rlin->Vertex(k);
1043 if ( ( OnFirst && ptline.IsVertexOnS1())
1044 || (!OnFirst && ptline.IsVertexOnS2())) {
1045 if (Domain->Identical(vtxref, (OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()))) {
1046 if (ptline.Tolerance() < vtxTol) ptline.SetTolerance(vtxTol);
1047 ptline.SetArc(OnFirst,arc,paramarc,transline,transarc);
1049 ptline.SetVertex(OnFirst,vtxarc);
1050 if (typL == IntPatch_Walking) {
1051 wlin->Replace(k,ptline);
1054 rlin->Replace(k,ptline);
1060 else if( ( OnFirst && ptline.IsVertexOnS2())
1061 || (!OnFirst && ptline.IsVertexOnS1())) {
1062 // on doit avoir vtxons2 = vtxarc... pas de verif...
1064 Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc);
1065 if (typL == IntPatch_Walking) {
1066 wlin->AddVertex(Sommet);
1070 rlin->AddVertex(Sommet);
1073 for (k=1; k<=Nbvtx; k++) if (k != ivtx) {
1074 if (typL == IntPatch_Walking) {
1075 ptline = wlin->Vertex(k);
1078 ptline = rlin->Vertex(k);
1080 if ( ( OnFirst && ptline.IsVertexOnS1())
1081 ||(!OnFirst && ptline.IsVertexOnS2())) {
1082 if (Domain->Identical(vtxref,(OnFirst)? (ptline.VertexOnS1()) : (ptline.VertexOnS2()))) {
1083 if (ptline.Tolerance() < vtxTol) ptline.SetTolerance(vtxTol);
1085 Sommet.SetArc(OnFirst,arc,paramarc,transline,transarc);
1086 if (typL == IntPatch_Walking) {
1087 wlin->Replace(k,ptline);
1088 wlin->AddVertex(Sommet);
1092 rlin->Replace(k,ptline);
1093 rlin->AddVertex(Sommet);
1102 //-- cout << "pb dans RstInt Type 2 " << endl;
1109 if (nbTreated == 2 && typL == IntPatch_Walking) {
1110 // We processed a tangent zone, and both ends have been treated.
1111 // So mark WLine as having arc
1112 if(OnFirst) wlin->SetArcOnS1(arc);
1113 else wlin->SetArcOnS2(arc);
1117 IndiceOffsetPeriodic++;
1119 while(SurfaceIsPeriodic && IndiceOffsetPeriodic<=2);
1121 IndiceOffsetBiPeriodic++;
1123 while(SurfaceIsBiPeriodic && IndiceOffsetBiPeriodic<=2);
1127 //--------------------------------------------------------------------------------
1128 //-- On reprend la ligne et on recale les parametres des vertex.
1130 if (typL == IntPatch_Walking) {
1131 Standard_Real pu1,pv1,pu2,pv2;
1132 pu1=pv1=pu2=pv2=0.0;
1134 case GeomAbs_Cylinder:
1136 case GeomAbs_Sphere:
1144 if( Surf1->IsUPeriodic()) {
1145 pu1=Surf1->UPeriod();
1147 else if(Surf1->IsUClosed()) {
1148 pu1=Surf1->LastUParameter() - Surf1->FirstUParameter();
1149 //cout<<" UClosed1 "<<pu1<<endl;
1151 if( Surf1->IsVPeriodic()) {
1152 pv1=Surf1->VPeriod();
1154 else if(Surf1->IsVClosed()) {
1155 pv1=Surf1->LastVParameter() - Surf1->FirstVParameter();
1156 //cout<<" VClosed1 "<<pv1<<endl;
1164 case GeomAbs_Cylinder:
1166 case GeomAbs_Sphere:
1175 if( Surf2->IsUPeriodic()) {
1176 pu2=Surf2->UPeriod();
1178 else if(Surf2->IsUClosed()) {
1179 pu2=Surf2->LastUParameter() - Surf2->FirstUParameter();
1180 //cout<<" UClosed2 "<<pu2<<endl;
1183 if( Surf2->IsVPeriodic()) {
1184 pv2=Surf2->VPeriod();
1186 else if(Surf2->IsVClosed()) {
1187 pv2=Surf2->LastVParameter() - Surf2->FirstVParameter();
1188 //cout<<" VClosed2 "<<pv2<<endl;
1197 pu1=Surf1->LastUParameter() - Surf1->FirstUParameter();
1201 pu2=Surf2->LastUParameter() - Surf2->FirstUParameter();
1205 pv1=Surf1->LastVParameter() - Surf1->FirstVParameter();
1209 pv2=Surf2->LastVParameter() - Surf2->FirstVParameter();
1214 wlin->SetPeriod(pu1,pv1,pu2,pv2);
1215 wlin->ComputeVertexParameters(Tol);
1219 //if(rlin->NbVertex()==0) {
1220 // cout<<" \n *** IntPatch RstInt.gxx : nbvtx = 0 sur rline *** \n"<<endl;
1223 rlin->ComputeVertexParameters(Tol);