1 // Created on: 1992-05-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <IntPatch_ImpPrmIntersection.ixx>
19 #include <Standard_ConstructionError.hxx>
20 #include <IntPatch_SequenceOfLine.hxx>
21 #include <TColStd_Array1OfInteger.hxx>
22 #include <IntSurf_PntOn2S.hxx>
23 #include <IntSurf_LineOn2S.hxx>
24 #include <IntSurf.hxx>
25 #include <IntSurf_InteriorPoint.hxx>
27 #include <Adaptor2d_HCurve2d.hxx>
28 #include <IntSurf_PathPoint.hxx>
29 #include <IntSurf_SequenceOfPathPoint.hxx>
30 #include <IntPatch_TheIWalking.hxx>
31 #include <IntPatch_TheIWLineOfTheIWalking.hxx>
32 #include <IntPatch_ThePathPointOfTheSOnBounds.hxx>
33 #include <IntPatch_TheSegmentOfTheSOnBounds.hxx>
34 #include <IntPatch_TheSurfFunction.hxx>
35 #include <IntPatch_RLine.hxx>
36 #include <IntPatch_WLine.hxx>
37 #include <IntPatch_ArcFunction.hxx>
38 #include <IntPatch_RstInt.hxx>
40 #define No_Standard_RangeError
41 #define No_Standard_OutOfRange
45 #include <math_Vector.hxx>
46 #include <math_Matrix.hxx>
47 #include <TopTrans_CurveTransition.hxx>
48 #include <TopAbs_State.hxx>
49 #include <TopAbs_Orientation.hxx>
50 #include <TColStd_Array1OfInteger.hxx>
51 #include <TColStd_Array1OfReal.hxx>
53 #include <IntSurf_SequenceOfInteriorPoint.hxx>
54 #include <IntSurf_QuadricTool.hxx>
55 #include <GeomAbs_SurfaceType.hxx>
57 static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& Line,
58 const Standard_Boolean IsReversed,
59 const IntSurf_Quadric& Quad,
60 const Handle(Adaptor3d_TopolTool)& PDomain,
61 const Handle(Adaptor3d_HSurface)& QSurf,
62 const Standard_Real ArcTol,
63 IntPatch_SequenceOfLine& Lines);
65 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
66 IntSurf_SequenceOfPathPoint& seqpdep,
67 const Handle(Adaptor3d_TopolTool)& Domain,
68 IntPatch_TheSurfFunction& Func,
69 const Handle(Adaptor3d_HSurface)& PSurf,
70 TColStd_Array1OfInteger& Destination);
72 void Recadre(const Standard_Boolean ,
73 GeomAbs_SurfaceType typeS1,
74 GeomAbs_SurfaceType typeS2,
76 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
77 Standard_Integer Param,
83 //=======================================================================
84 //function : IntPatch_ImpPrmIntersection
86 //=======================================================================
87 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
88 : done(Standard_False),
90 myIsStartPnt(Standard_False),
96 //=======================================================================
97 //function : IntPatch_ImpPrmIntersection
99 //=======================================================================
101 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection
102 (const Handle(Adaptor3d_HSurface)& Surf1,
103 const Handle(Adaptor3d_TopolTool)& D1,
104 const Handle(Adaptor3d_HSurface)& Surf2,
105 const Handle(Adaptor3d_TopolTool)& D2,
106 const Standard_Real TolArc,
107 const Standard_Real TolTang,
108 const Standard_Real Fleche,
109 const Standard_Real Pas)
110 : done(Standard_False),
111 empt(Standard_False),
112 myIsStartPnt(Standard_False),
116 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
120 //=======================================================================
121 //function : SetStartPoint
123 //=======================================================================
125 void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
126 const Standard_Real V)
128 myIsStartPnt = Standard_True;
129 myUStart = U; myVStart = V;
132 //=======================================================================
133 //function : ComputeTangency
135 //=======================================================================
136 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
137 IntSurf_SequenceOfPathPoint& seqpdep,
138 const Handle(Adaptor3d_TopolTool)& Domain,
139 IntPatch_TheSurfFunction& Func,
140 const Handle(Adaptor3d_HSurface)& PSurf,
141 TColStd_Array1OfInteger& Destination)
143 Standard_Integer i,k, NbPoints, seqlength;
144 Standard_Real theparam,test;
145 Standard_Boolean fairpt, ispassing;
146 TopAbs_Orientation arcorien,vtxorien;
147 Handle(Adaptor2d_HCurve2d) thearc;
148 Handle(Adaptor3d_HVertex) vtx,vtxbis;
149 //Standard_Boolean ispassing;
150 IntPatch_ThePathPointOfTheSOnBounds PStart;
151 IntSurf_PathPoint PPoint;
155 gp_Vec d1u,d1v,v1,v2;
159 double aX[2], aF[1], aD[1][2];
160 math_Vector X(aX, 1, 2);
161 math_Vector F(aF, 1, 1);
162 math_Matrix D(aD, 1, 1, 1, 2);
165 NbPoints = solrst.NbPoints();
166 for (i=1; i<= NbPoints; i++) {
167 if (Destination(i) == 0) {
168 PStart = solrst.Point(i);
169 thearc = PStart.Arc();
170 theparam = PStart.Parameter();
171 arcorien = Domain->Orientation(thearc);
172 ispassing = (arcorien == TopAbs_INTERNAL ||
173 arcorien == TopAbs_EXTERNAL);
175 thearc->D0(theparam,p2d);
178 PPoint.SetValue(PStart.Value(),X(1),X(2));
181 if (Func.IsTangent()) {
182 PPoint.SetTangency(Standard_True);
183 Destination(i) = seqlength+1;
184 if (!PStart.IsNew()) {
185 vtx = PStart.Vertex();
186 for (k=i+1; k<=NbPoints; k++) {
187 if (Destination(k) ==0) {
188 PStart = solrst.Point(k);
189 if (!PStart.IsNew()) {
190 vtxbis = PStart.Vertex();
191 if (Domain->Identical(vtx,vtxbis)) {
192 thearc = PStart.Arc();
193 theparam = PStart.Parameter();
194 arcorien = Domain->Orientation(thearc);
195 ispassing = ispassing && (arcorien == TopAbs_INTERNAL ||
196 arcorien == TopAbs_EXTERNAL);
198 thearc->D0(theparam,p2d);
199 PPoint.AddUV(p2d.X(),p2d.Y());
200 Destination(k) = seqlength+1;
206 PPoint.SetPassing(ispassing);
207 seqpdep.Append(PPoint);
210 else { // on a un point de depart potentiel
212 vectg = Func.Direction3d();
213 dirtg = Func.Direction2d();
215 PSurf->D1(X(1),X(2),ptbid,d1u,d1v);
216 thearc->D1(theparam,p2d,d2d);
217 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
218 v1 = d1u.Crossed(d1v);
220 test = vectg.Dot(v1.Crossed(v2));
221 if (PStart.IsNew()) {
222 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
223 (test > 0. && arcorien == TopAbs_REVERSED)) {
227 PPoint.SetDirections(vectg,dirtg);
228 PPoint.SetPassing(ispassing);
229 Destination(i) = seqlength+1;
230 seqpdep.Append(PPoint);
233 else { // traiter la transition complexe
234 gp_Dir bidnorm(1.,1.,1.);
235 Standard_Real tole = 1.e-8;
236 TopAbs_Orientation LocTrans;
237 TopTrans_CurveTransition comptrans;
238 comptrans.Reset(vectg,bidnorm,0.);
239 if (arcorien == TopAbs_FORWARD ||
240 arcorien == TopAbs_REVERSED) {
243 vtx = PStart.Vertex();
244 vtxorien = Domain->Orientation(vtx);
245 if (Abs(test) <= tole) {
246 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
249 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
250 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
251 LocTrans = TopAbs_FORWARD;
254 LocTrans = TopAbs_REVERSED;
256 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
259 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
261 Destination(i) = seqlength+1;
262 for (k= i+1; k<=NbPoints; k++) {
263 if (Destination(k) == 0) {
264 PStart = solrst.Point(k);
265 if (!PStart.IsNew()) {
266 vtxbis = PStart.Vertex();
267 if (Domain->Identical(vtx,vtxbis)) {
268 thearc = PStart.Arc();
269 theparam = PStart.Parameter();
270 arcorien = Domain->Orientation(thearc);
272 PPoint.AddUV(X(1),X(2));
274 thearc->D1(theparam,p2d,d2d);
275 PPoint.AddUV(p2d.X(),p2d.Y());
277 if (arcorien == TopAbs_FORWARD ||
278 arcorien == TopAbs_REVERSED) {
279 ispassing = Standard_False;
280 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
282 test = vectg.Dot(v1.Crossed(v2));
283 vtxorien = Domain->Orientation(PStart.Vertex());
284 if (Abs(test) <= tole) {
285 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
288 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
289 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
290 LocTrans = TopAbs_FORWARD;
293 LocTrans = TopAbs_REVERSED;
295 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
298 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
300 Destination(k) = seqlength+1;
305 fairpt = Standard_True;
307 TopAbs_State Before = comptrans.StateBefore();
308 TopAbs_State After = comptrans.StateAfter();
309 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
310 fairpt = Standard_False;
312 else if (Before == TopAbs_IN) {
313 if (After == TopAbs_IN) {
314 ispassing = Standard_True;
322 if (After !=TopAbs_IN) {
323 fairpt = Standard_False;
328 PPoint.SetDirections(vectg,dirtg);
329 PPoint.SetPassing(ispassing);
330 seqpdep.Append(PPoint);
333 else { // il faut remettre en "ordre" si on ne garde pas le point.
334 for (k=i; k <=NbPoints ; k++) {
335 if (Destination(k)==seqlength + 1) {
336 Destination(k) = -Destination(k);
345 //=======================================================================
348 //=======================================================================
349 void Recadre(const Standard_Boolean ,
350 GeomAbs_SurfaceType typeS1,
351 GeomAbs_SurfaceType typeS2,
353 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
354 Standard_Integer Param,
360 Standard_Real U1p,V1p,U2p,V2p;
361 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
365 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
366 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
367 case GeomAbs_Cylinder:
370 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
371 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
378 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
379 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
380 case GeomAbs_Cylinder:
383 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
384 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
388 pt.SetParameters(U1,V1,U2,V2);
391 //=======================================================================
394 //=======================================================================
395 void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
396 const Handle(Adaptor3d_TopolTool)& D1,
397 const Handle(Adaptor3d_HSurface)& Surf2,
398 const Handle(Adaptor3d_TopolTool)& D2,
399 const Standard_Real TolArc,
400 const Standard_Real TolTang,
401 const Standard_Real Fleche,
402 const Standard_Real Pas)
404 Standard_Boolean reversed, procf, procl, dofirst, dolast;
405 Standard_Integer indfirst = 0, indlast = 0, ind2, i,j,k, NbSegm;
406 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
407 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
409 IntPatch_TheSegmentOfTheSOnBounds thesegm;
410 IntSurf_PathPoint PPoint;
412 Handle(IntPatch_RLine) rline;
413 Handle(IntPatch_WLine) wline;
414 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
415 IntPatch_Point ptdeb,ptfin,ptbis;
418 IntSurf_Transition TLine,TArc;
419 IntSurf_TypeTrans trans1,trans2;
421 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
428 Handle(Adaptor2d_HCurve2d) currentarc;
429 GeomAbs_SurfaceType typeS1, typeS2;
430 IntSurf_Quadric Quad;
431 IntPatch_TheSurfFunction Func;
432 IntPatch_ArcFunction AFunc;
434 typeS1 = Surf1->GetType();
435 typeS2 = Surf2->GetType();
439 trans1 = IntSurf_Undecided;
440 trans2 = IntSurf_Undecided;
442 done = Standard_False;
443 empt = Standard_True;
447 reversed = Standard_False;
451 Quad.SetValue(Surf1->Plane());
454 case GeomAbs_Cylinder:
455 Quad.SetValue(Surf1->Cylinder());
459 Quad.SetValue(Surf1->Sphere());
463 Quad.SetValue(Surf1->Cone());
468 reversed = Standard_True;
472 Quad.SetValue(Surf2->Plane());
475 case GeomAbs_Cylinder:
476 Quad.SetValue(Surf2->Cylinder());
480 Quad.SetValue(Surf2->Sphere());
484 Quad.SetValue(Surf2->Cone());
488 Standard_ConstructionError::Raise();
496 Func.SetImplicitSurface(Quad);
497 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
498 AFunc.SetQuadric(Quad);
510 solrst.Perform(AFunc,D2,TolArc,TolTang);
513 solrst.Perform(AFunc,D1,TolArc,TolTang);
515 if (!solrst.IsDone()) {
519 IntSurf_SequenceOfPathPoint seqpdep;
520 IntSurf_SequenceOfInteriorPoint seqpins;
522 NbPointRst = solrst.NbPoints();
523 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
526 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
529 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
533 Standard_Boolean SearchIns = Standard_True;
534 if(Quad.TypeQuadric() == GeomAbs_Plane && solrst.NbSegments() > 0)
536 //For such kind of cases it is possible that whole surface is on one side of plane,
537 //plane only touches surface and does not cross it,
538 //so no inner points exist.
539 SearchIns = Standard_False;
540 Handle(Adaptor3d_TopolTool) T;
549 Standard_Integer aNbSamples = 0;
550 aNbSamples = T->NbSamples();
553 Standard_Real aValf[1], aUVap[2];
554 math_Vector Valf(aValf,1,1), UVap(aUVap,1,2);
555 T->SamplePoint(1,s2d, s3d);
558 Func.Value(UVap,Valf);
559 Standard_Real rvalf = Sign(1.,Valf(1));
560 for(i = 2; i <= aNbSamples; ++i)
562 D1->SamplePoint(i,s2d, s3d);
565 Func.Value(UVap,Valf);
566 if(rvalf * Valf(1) < 0.)
568 SearchIns = Standard_True;
573 // Recherche des points interieurs
578 solins.Perform(Func,Surf2,myUStart,myVStart);
580 solins.Perform(Func,Surf2,D2,TolTang);
584 solins.Perform(Func,Surf1,myUStart,myVStart);
586 solins.Perform(Func,Surf1,D1,TolTang);
588 NbPointIns = solins.NbPoints();
589 for (i=1; i <= NbPointIns; i++) {
590 seqpins.Append(solins.Value(i));
594 NbPointDep=seqpdep.Length();
596 if (NbPointDep || NbPointIns) {
597 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
599 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
602 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
604 if(!iwalk.IsDone()) {
608 Standard_Real Vmin, Vmax, TolV = 1.e-14;
609 if (!reversed) { //Surf1 is quadric
610 Vmin = Surf1->FirstVParameter();
611 Vmax = Surf1->LastVParameter();
613 else { //Surf2 is quadric
614 Vmin = Surf2->FirstVParameter();
615 Vmax = Surf2->LastVParameter();
618 Nblines = iwalk.NbLines();
619 for (j=1; j<=Nblines; j++) {
620 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
621 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
623 Nbpts = thelin->NbPoints();
626 tgline = iwline->TangentVector(k);
627 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
628 valpt = thelin->Value(k).Value();
631 thelin->Value(k).ParametersOnS2(U2,V2);
632 norm1 = Quad.Normale(valpt);
633 Surf2->D1(U2,V2,ptbid,d1u,d1v);
634 norm2 = d1u.Crossed(d1v);
637 thelin->Value(k).ParametersOnS1(U2,V2);
638 norm2 = Quad.Normale(valpt);
639 Surf1->D1(U2,V2,ptbid,d1u,d1v);
640 norm1 = d1u.Crossed(d1v);
642 if (tgline.DotCross(norm2,norm1) > 0.) {
643 trans1 = IntSurf_Out;
648 trans2 = IntSurf_Out;
652 Standard_Real AnU1,AnU2,AnV2;
654 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
655 Standard_Boolean arecadr=Standard_False;
656 valpt = thelin->Value(1).Value();
657 Quad.Parameters(valpt,AnU1,V1);
659 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
660 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
663 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
664 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
667 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
668 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
671 if(typQuad==GeomAbs_Cylinder ||
672 typQuad==GeomAbs_Cone ||
673 typQuad==GeomAbs_Sphere) {
674 arecadr=Standard_True;
677 for (k=2; k<=Nbpts; ++k) {
678 valpt = thelin->Value(k).Value();
679 Quad.Parameters(valpt,U1,V1);
681 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
684 if((V1 > Vmax) && (V1-Vmax < TolV)) {
689 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
690 Standard_Real aCf, aTwoPI;
694 if ((U1-AnU1) > 1.5*M_PI) {
695 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
702 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
708 //if ((U1-AnU1) > 1.5*M_PI) {
711 //else if ((U1-AnU1) < -1.5*M_PI) {
714 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
718 thelin->SetUV(k,Standard_False,U1,V1);
720 thelin->Value(k).ParametersOnS1(U2,V2);
722 case GeomAbs_Cylinder:
726 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
727 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
732 if(typeS2==GeomAbs_Torus) {
733 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
734 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
736 thelin->SetUV(k,Standard_True,U2,V2);
739 thelin->SetUV(k,Standard_True,U1,V1);
741 thelin->Value(k).ParametersOnS2(U2,V2);
743 case GeomAbs_Cylinder:
747 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
748 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
753 if(typeS2==GeomAbs_Torus) {
754 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
755 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
757 thelin->SetUV(k,Standard_False,U2,V2);
766 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
768 if ( iwline->HasFirstPoint()
769 && iwline->IsTangentAtBegining() == Standard_False)
771 indfirst = iwline->FirstPointIndex();
772 PPoint = seqpdep(indfirst);
773 tgline = PPoint.Direction3d();
774 Standard_Integer themult = PPoint.Multiplicity();
775 for (i=NbPointRst; i>=1; i--) {
776 if (Destination(i) == indfirst) {
777 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
778 Quad.Parameters(PPoint.Value(),U1,V1);
780 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
781 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
783 PPoint.Parameters(themult,U2,V2);
784 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
786 else { //-- typeS1 != Pln && Cyl && Sph && Cone
787 Quad.Parameters(PPoint.Value(),U2,V2);
789 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
790 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
792 PPoint.Parameters(themult,U1,V1);
793 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
796 VecNormale = d1u.Crossed(d1v);
797 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
798 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
799 ptdeb.SetParameters(U1,V1,U2,V2);
800 ptdeb.SetParameter(1.);
802 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
804 currentarc = solrst.Point(i).Arc();
805 currentparam = solrst.Point(i).Parameter();
806 currentarc->D1(currentparam,p2d,d2d);
807 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
809 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
810 if(squaremagnitudeVecNormale > 1e-13) {
811 DirNormale=VecNormale;
812 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
815 TLine.SetValue(Standard_True,IntSurf_Undecided);
816 TArc.SetValue(Standard_True,IntSurf_Undecided);
819 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
820 if (!solrst.Point(i).IsNew()) {
821 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
823 wline->AddVertex(ptdeb);
825 wline->SetFirstPoint(wline->NbVertex());
832 else if (iwline->IsTangentAtBegining())
834 gp_Pnt psol = thelin->Value(1).Value();
835 thelin->Value(1).ParametersOnS1(U1,V1);
836 thelin->Value(1).ParametersOnS2(U2,V2);
837 ptdeb.SetValue(psol,TolArc,Standard_True);
838 ptdeb.SetParameters(U1,V1,U2,V2);
839 ptdeb.SetParameter(1.);
840 wline->AddVertex(ptdeb);
841 wline->SetFirstPoint(wline->NbVertex());
845 gp_Pnt psol = thelin->Value(1).Value();
846 thelin->Value(1).ParametersOnS1(U1,V1);
847 thelin->Value(1).ParametersOnS2(U2,V2);
848 ptdeb.SetValue(psol,TolArc,Standard_False);
849 ptdeb.SetParameters(U1,V1,U2,V2);
850 ptdeb.SetParameter(1.);
851 wline->AddVertex(ptdeb);
852 wline->SetFirstPoint(wline->NbVertex());
856 if ( iwline->HasLastPoint()
857 && iwline->IsTangentAtEnd() == Standard_False)
859 indlast = iwline->LastPointIndex();
860 PPoint = seqpdep(indlast);
861 tgline = PPoint.Direction3d().Reversed();
862 Standard_Integer themult = PPoint.Multiplicity();
863 for (i=NbPointRst; i >=1; i--) {
864 if (Destination(i) == indlast) {
866 Quad.Parameters(PPoint.Value(),U1,V1);
868 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
869 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
871 PPoint.Parameters(themult,U2,V2);
872 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
873 VecNormale = d1u.Crossed(d1v); //-- @@@@
876 Quad.Parameters(PPoint.Value(),U2,V2);
878 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
879 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
881 PPoint.Parameters(themult,U1,V1);
882 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
883 VecNormale = d1u.Crossed(d1v); //-- @@@@
886 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
887 ptfin.SetParameters(U1,V1,U2,V2);
888 ptfin.SetParameter(Nbpts);
890 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
892 currentarc = solrst.Point(i).Arc();
893 currentparam = solrst.Point(i).Parameter();
894 currentarc->D1(currentparam,p2d,d2d);
895 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
898 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
899 if(squaremagnitudeVecNormale > 1e-13) {
900 DirNormale=VecNormale;
901 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
904 TLine.SetValue(Standard_True,IntSurf_Undecided);
905 TArc.SetValue(Standard_True,IntSurf_Undecided);
909 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
910 if (!solrst.Point(i).IsNew()) {
911 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
913 wline->AddVertex(ptfin);
915 wline->SetLastPoint(wline->NbVertex());
922 else if (iwline->IsTangentAtEnd())
924 gp_Pnt psol = thelin->Value(Nbpts).Value();
925 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
926 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
927 ptfin.SetValue(psol,TolArc,Standard_True);
928 ptfin.SetParameters(U1,V1,U2,V2);
929 ptfin.SetParameter(Nbpts);
930 wline->AddVertex(ptfin);
931 wline->SetLastPoint(wline->NbVertex());
935 gp_Pnt psol = thelin->Value(Nbpts).Value();
936 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
937 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
938 ptfin.SetValue(psol,TolArc,Standard_False);
939 ptfin.SetParameters(U1,V1,U2,V2);
940 ptfin.SetParameter(Nbpts);
941 wline->AddVertex(ptfin);
942 wline->SetLastPoint(wline->NbVertex());
945 // Il faut traiter les points de passage.
948 }// for (j=1; j<=Nblines; j++) {
950 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
951 // QUE SUR DES POINTS DE TANGENCE
954 Nblines = slin.Length();
955 for (j=1; j<=Nblines-1; j++) {
956 dofirst = dolast = Standard_False;
957 const Handle(IntPatch_Line)& slinj = slin(j);
958 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
959 if (wlin1->HasFirstPoint()) {
960 ptdeb = wlin1->FirstPoint(indfirst);
961 if (ptdeb.IsTangencyPoint()) {
962 dofirst = Standard_True;
965 if (wlin1->HasLastPoint()) {
966 ptfin = wlin1->LastPoint(indlast);
967 if (ptfin.IsTangencyPoint()) {
968 dolast = Standard_True;
972 if (dofirst || dolast) {
973 for (k=j+1; k<=Nblines;k++) {
974 const Handle(IntPatch_Line)& slink = slin(k);
975 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
976 if (wlin2->HasFirstPoint()) {
977 ptbis = wlin2->FirstPoint(ind2);
978 if (ptbis.IsTangencyPoint()) {
980 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
981 ptdeb.SetMultiple(Standard_True);
982 if (!ptbis.IsMultiple()) {
983 ptbis.SetMultiple(Standard_True);
984 wlin2->Replace(ind2,ptbis);
989 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
990 ptfin.SetMultiple(Standard_True);
991 if (!ptbis.IsMultiple()) {
992 ptbis.SetMultiple(Standard_True);
993 wlin2->Replace(ind2,ptbis);
999 if (wlin2->HasLastPoint()) {
1000 ptbis = wlin2->LastPoint(ind2);
1001 if (ptbis.IsTangencyPoint()) {
1003 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
1004 ptdeb.SetMultiple(Standard_True);
1005 if (!ptbis.IsMultiple()) {
1006 ptbis.SetMultiple(Standard_True);
1007 wlin2->Replace(ind2,ptbis);
1012 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
1013 ptfin.SetMultiple(Standard_True);
1014 if (!ptbis.IsMultiple()) {
1015 ptbis.SetMultiple(Standard_True);
1016 wlin2->Replace(ind2,ptbis);
1024 wlin1->Replace(indfirst,ptdeb);
1026 wlin1->Replace(indlast,ptfin);
1029 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
1031 // Treatment the segments
1032 NbSegm = solrst.NbSegments();
1034 for(i=1; i<=NbSegm; i++) {
1035 thesegm = solrst.Segment(i);
1036 //Check if segment is degenerated
1037 if(thesegm.HasFirstPoint() && thesegm.HasLastPoint())
1039 Standard_Real tol2 = Precision::Confusion();
1041 const gp_Pnt& aPf = thesegm.FirstPoint().Value();
1042 const gp_Pnt& aPl = thesegm.LastPoint().Value();
1043 if(aPf.SquareDistance(aPl) <= tol2)
1045 //segment can be degenerated - check inner point
1046 paramf = thesegm.FirstPoint().Parameter();
1047 paraml = thesegm.LastPoint().Parameter();
1049 thesegm.Curve()->Value(.57735 * paramf + 0.42265 * paraml);
1053 Surf1->D0(_p2d.X(), _p2d.Y(), aPm);
1057 Surf2->D0(_p2d.X(), _p2d.Y(), aPm);
1059 if(aPm.SquareDistance(aPf) <= tol2)
1068 //----------------------------------------------------------------------
1069 // on cree une ligne d intersection contenant uniquement le segment.
1070 // VOIR POUR LA TRANSITION DE LA LIGNE
1071 // On ajoute aussi un polygone pour le traitement des intersections
1072 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
1073 //----------------------------------------------------------------------
1074 //-- Calcul de la transition sur la rline (12 fev 97)
1075 //-- reversed a le sens de OnFirst
1077 dofirst = dolast = Standard_False;
1078 procf = Standard_False;
1079 procl = Standard_False;
1080 IntSurf_Transition TLineUnk,TArcUnk;
1082 IntPatch_Point _thepointAtBeg;
1083 IntPatch_Point _thepointAtEnd;
1085 Standard_Boolean TransitionOK=Standard_False;
1087 if(thesegm.HasFirstPoint()) {
1088 Standard_Real _u1,_v1,_u2,_v2;
1090 dofirst = Standard_True;
1091 PStartf = thesegm.FirstPoint();
1092 paramf = PStartf.Parameter();
1094 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
1095 Handle(Adaptor3d_HVertex) _vtx;
1096 if(PStartf.IsNew()==Standard_False)
1097 _vtx= PStartf.Vertex();
1098 const gp_Pnt& _Pp = PStartf.Value();
1099 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1100 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1101 Quad.Parameters(_Pp,_u1,_v1);
1102 _u2=_p2d.X(); _v2=_p2d.Y();
1104 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1105 Quad.Parameters(_Pp,_u2,_v2);
1106 _u1=_p2d.X(); _v1=_p2d.Y();
1108 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1109 _thepointAtBeg.SetParameter(paramf);
1110 if(PStartf.IsNew()==Standard_False)
1111 _thepointAtBeg.SetVertex(reversed,_vtx);
1112 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1115 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1116 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1117 norm1 = d1u1.Crossed(d1v1);
1118 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1119 norm2 = d1u2.Crossed(d1v2);
1121 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1123 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1126 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1128 _u1=tgline.DotCross(norm2,norm1);
1129 TransitionOK=Standard_True;
1130 if (_u1 > 0.00000001) {
1131 trans1 = IntSurf_Out;
1132 trans2 = IntSurf_In;
1134 else if(_u1 < -0.00000001) {
1135 trans1 = IntSurf_In;
1136 trans2 = IntSurf_Out;
1139 TransitionOK=Standard_False;
1142 if(thesegm.HasLastPoint()) {
1143 Standard_Real _u1,_v1,_u2,_v2;
1145 dolast = Standard_True;
1146 PStartl = thesegm.LastPoint();
1147 paraml = PStartl.Parameter();
1149 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1150 Handle(Adaptor3d_HVertex) _vtx;
1151 if(PStartl.IsNew()==Standard_False)
1152 _vtx = PStartl.Vertex();
1153 const gp_Pnt& _Pp = PStartl.Value();
1154 IntPatch_Point _thepoint;
1155 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1156 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1157 Quad.Parameters(_Pp,_u1,_v1);
1158 _u2=_p2d.X(); _v2=_p2d.Y();
1160 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1161 Quad.Parameters(_Pp,_u2,_v2);
1162 _u1=_p2d.X(); _v1=_p2d.Y();
1164 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1165 _thepointAtEnd.SetParameter(paraml);
1166 if(PStartl.IsNew()==Standard_False)
1167 _thepointAtEnd.SetVertex(reversed,_vtx);
1168 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1172 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1173 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1174 norm1 = d1u1.Crossed(d1v1);
1175 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1176 norm2 = d1u2.Crossed(d1v2);
1178 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1180 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1183 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1185 _u1=tgline.DotCross(norm2,norm1);
1186 TransitionOK=Standard_True;
1187 if (_u1 > 0.00000001) {
1188 trans1 = IntSurf_Out;
1189 trans2 = IntSurf_In;
1191 else if(_u1 < -0.00000001) {
1192 trans1 = IntSurf_In;
1193 trans2 = IntSurf_Out;
1196 TransitionOK=Standard_False;
1199 if(TransitionOK==Standard_False) {
1200 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1201 rline = new IntPatch_RLine (Standard_False);
1203 rline->SetArcOnS1(thesegm.Curve());
1206 rline->SetArcOnS2(thesegm.Curve());
1210 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1211 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1213 rline->SetArcOnS1(thesegm.Curve());
1216 rline->SetArcOnS2(thesegm.Curve());
1220 //------------------------------
1221 //-- Ajout des points
1223 if (thesegm.HasFirstPoint()) {
1224 rline->AddVertex(_thepointAtBeg);
1225 rline->SetFirstPoint(rline->NbVertex());
1228 if (thesegm.HasLastPoint()) {
1229 rline->AddVertex(_thepointAtEnd);
1230 rline->SetLastPoint(rline->NbVertex());
1233 // Polygone sur restriction solution
1234 if (dofirst && dolast) {
1237 IntSurf_PntOn2S p2s;
1238 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1239 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1240 Standard_Integer nbsample = 100;
1243 for (j=1; j<=nbsample; j++) {
1244 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1245 arcsegm->D0(prm,p2d);
1246 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1248 Quad.Parameters(ptpoly,U1,V1);
1249 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1254 for (j=1; j<=nbsample; j++) {
1255 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1256 arcsegm->D0(prm,p2d);
1257 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1259 Quad.Parameters(ptpoly,U2,V2);
1260 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1267 if (dofirst || dolast) {
1268 Nblines = slin.Length();
1269 for (j=1; j<=Nblines; j++) {
1270 const Handle(IntPatch_Line)& slinj = slin(j);
1271 typ = slinj->ArcType();
1272 if (typ == IntPatch_Walking) {
1273 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1276 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1278 for (k=1; k<=Nbpts;k++) {
1279 if (typ == IntPatch_Walking) {
1280 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1283 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1287 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1288 ptdeb.SetMultiple(Standard_True);
1289 if (typ == IntPatch_Walking) {
1290 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1293 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1295 ptdeb.SetParameter(paramf);
1296 rline->AddVertex(ptdeb);
1298 procf=Standard_True;
1299 rline->SetFirstPoint(rline->NbVertex());
1304 if(dofirst) { //-- on recharge le ptdeb
1305 if (typ == IntPatch_Walking) {
1306 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1309 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1312 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1313 ptdeb.SetMultiple(Standard_True);
1314 if (typ == IntPatch_Walking) {
1315 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1318 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1320 ptdeb.SetParameter(paraml);
1321 rline->AddVertex(ptdeb);
1323 procl=Standard_True;
1324 rline->SetLastPoint(rline->NbVertex());
1335 // on traite les restrictions de la surface implicite
1336 for (i=1; i<=slin.Length(); i++)
1339 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1341 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1343 empt = (slin.Length() == 0 && spnt.Length() == 0);
1344 done = Standard_True;
1347 // post processing for cones and spheres
1349 if(slin.Length() == 0)
1352 Standard_Boolean isDecomposeRequired = (Quad.TypeQuadric() == GeomAbs_Cone) ||
1353 (Quad.TypeQuadric() == GeomAbs_Sphere);
1355 if(!isDecomposeRequired)
1358 const Handle(Adaptor3d_TopolTool)& PDomain = (reversed) ? D1 : D2;
1359 const Handle(Adaptor3d_HSurface)& aQSurf = (reversed) ? Surf2 : Surf1;
1361 IntPatch_SequenceOfLine dslin;
1362 Standard_Boolean isDecompose = Standard_False;
1363 for(i = 1; i <= slin.Length(); i++ )
1365 if(DecomposeResult(slin(i),reversed,Quad,PDomain,aQSurf,TolArc,dslin))
1367 isDecompose = Standard_True;
1375 for(i = 1; i <= dslin.Length(); i++ )
1376 slin.Append(dslin(i));
1379 // correct U parameter of the start point of line on Quadric
1380 // (change 0->2PI or vs, if necessary)
1381 static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1383 Standard_Real u = U1;
1385 // case: no adjustment
1386 if( U1 > 0. && U1 < (2.*M_PI) )
1390 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
1391 if( U2 > 0. && U2 < (2.*M_PI) )
1392 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1394 Standard_Real uu = U2;
1395 if( U2 > (2.*M_PI) )
1396 while( uu > (2.*M_PI) )
1402 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1406 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1407 if( U2 > 0. && U2 < (2.*M_PI) )
1408 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1410 Standard_Real uu = U2;
1411 if( U2 > (2.*M_PI) )
1412 while( uu > (2.*M_PI) )
1418 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1421 // case: '<0. || >2PI'
1427 while(u > (2.*M_PI))
1434 // collect vertices, reject equals
1435 static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1436 const Standard_Real TOL3D,
1437 const Standard_Real TOL2D)
1439 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1441 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1443 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1444 Standard_Integer i = 0, k = 0;
1445 Standard_Integer NbVrt = WLine->NbVertex();
1447 TColStd_Array1OfInteger anVrts(1,NbVrt);
1450 // check equal vertices
1451 for(i = 1; i <= NbVrt; i++) {
1453 if( anVrts(i) == -1 ) continue;
1455 const IntPatch_Point& Pi = WLine->Vertex(i);
1457 for(k = (i+1); k <= NbVrt; k++) {
1459 if( anVrts(k) == -1 ) continue;
1461 const IntPatch_Point& Pk = WLine->Vertex(k);
1463 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
1464 // suggest the points are equal;
1465 // test 2d parameters on surface
1466 Standard_Boolean sameU1 = Standard_False;
1467 Standard_Boolean sameV1 = Standard_False;
1468 Standard_Boolean sameU2 = Standard_False;
1469 Standard_Boolean sameV2 = Standard_False;
1471 Pi.ParametersOnS1(U1,V1);
1472 Pk.ParametersOnS1(U2,V2);
1473 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1474 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1476 Pi.ParametersOnS2(U1,V1);
1477 Pk.ParametersOnS2(U2,V2);
1478 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1479 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1481 if((sameU1 && sameV1) && (sameU2 && sameV2))
1487 // copy further processed vertices
1488 for(i = 1; i <= NbVrt; i++) {
1489 if( anVrts(i) == -1 ) continue;
1490 vertices->Add(WLine->Vertex(i).PntOn2S());
1495 static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1496 const IntSurf_PntOn2S& P2)
1498 Standard_Boolean result = Standard_False;
1499 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1500 const gp_Pnt& P3D1 = P1.Value();
1501 const gp_Pnt& P3D2 = P2.Value();
1502 if(P3D1.Distance(P3D2) <= T3D) {
1503 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1504 P1.ParametersOnS1(U1,V1);
1505 P1.ParametersOnS2(U2,V2);
1506 P2.ParametersOnS1(U3,V3);
1507 P2.ParametersOnS2(U4,V4);
1508 gp_Pnt2d P2D11(U1,V1);
1509 gp_Pnt2d P2D12(U2,V2);
1510 gp_Pnt2d P2D21(U3,V3);
1511 gp_Pnt2d P2D22(U4,V4);
1512 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1513 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1514 if(sameS1 && sameS2)
1515 result = Standard_True;
1520 static void ForcedPurgePoints(const Handle(IntSurf_LineOn2S)& Result,
1521 const Standard_Boolean IsReversed,
1522 const IntSurf_Quadric& Quad)
1524 if(Result->NbPoints() <= 30) return;
1525 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1527 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1529 Result->Value(1).ParametersOnS2(U1,V1);
1530 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1533 Result->Value(1).ParametersOnS1(U1,V1);
1534 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
1537 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1538 Standard_Real Uapx = 0., Vapx = 0.;
1539 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1541 if(fabs(V1-Vapx) <= 1.e-3)
1543 if(fabs(V2-Vapx) <= 1.e-3)
1547 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
1548 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
1550 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1552 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1556 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1557 Result->RemovePoint(2);
1561 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1562 Result->RemovePoint(Result->NbPoints()-1);
1567 // DEBUG FUNCTION !!!
1569 static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1570 Standard_Boolean IsReversed,
1571 Standard_Integer Number)
1573 cout << "DUMP LINE" << endl;
1576 for(i = 1; i <= Line->NbPoints(); i++) {
1577 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1579 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1581 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1582 cout << "point p" << i << " " << U << " " << V << endl;
1588 // DEBUG FUNCTION !!!
1590 static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1591 const Handle(IntSurf_LineOn2S)& Vertices,
1592 TColStd_Array1OfInteger& PTypes)
1594 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1595 Standard_Integer ip = 0, iv = 0;
1596 for(ip = 1; ip <= nbp; ip++) {
1597 const IntSurf_PntOn2S& aP = Line->Value(ip);
1598 Standard_Integer type = 0;
1599 for(iv = 1; iv <= nbv; iv++) {
1600 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1601 if(AreSamePoints(aP,aV)) {
1610 static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1611 const Standard_Real TOL2D)
1613 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
1616 static inline Standard_Real AdjustU(const Standard_Real U)
1618 Standard_Real u = U, DBLPI = 2.*M_PI;
1619 if(u < 0. || u > DBLPI) {
1630 static inline void Correct2DBounds(const Standard_Real UF,
1631 const Standard_Real UL,
1632 const Standard_Real VF,
1633 const Standard_Real VL,
1634 const Standard_Real TOL2D,
1638 Standard_Real Eps = 1.e-16;
1639 Standard_Real dUF = fabs(U - UF);
1640 Standard_Real dUL = fabs(U - UL);
1641 Standard_Real dVF = fabs(V - VF);
1642 Standard_Real dVL = fabs(V - VL);
1643 if(dUF <= TOL2D && dUF > Eps) U = UF;
1644 if(dUL <= TOL2D && dUL > Eps) U = UL;
1645 if(dVF <= TOL2D && dVF > Eps) V = VF;
1646 if(dVL <= TOL2D && dVL > Eps) V = VL;
1649 static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1650 const Standard_Boolean IsReversed,
1651 const Handle(Adaptor3d_HSurface)& QSurf,
1652 const Standard_Real TOL2D)
1654 Standard_Real VF = QSurf->FirstVParameter();
1655 Standard_Real VL = QSurf->LastVParameter();
1656 Standard_Real UF = QSurf->FirstUParameter();
1657 Standard_Real UL = QSurf->LastUParameter();
1659 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1660 Standard_Real U = 0., V = 0.;
1661 for(ip = 1; ip <= nbp; ip++) {
1663 Line->Value(ip).ParametersOnS2(U,V);
1665 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1666 Line->SetUV(ip,Standard_False,U,V);
1669 Line->Value(ip).ParametersOnS1(U,V);
1671 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1672 Line->SetUV(ip,Standard_True,U,V);
1677 static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
1678 const Standard_Boolean IsReversed,
1679 Handle(IntSurf_LineOn2S)& Vertices,
1680 const TColStd_Array1OfInteger& PTypes,
1681 const Standard_Real TOL2D)
1683 Standard_Boolean result = Standard_False;
1684 Standard_Integer ip = 0, nbp = Line->NbPoints();
1685 Standard_Real U = 0., V = 0.;
1686 for(ip = 1; ip <= nbp; ip++) {
1687 Standard_Integer ipt = PTypes(ip);
1689 const IntSurf_PntOn2S& aP = Line->Value(ip);
1691 aP.ParametersOnS2(U,V); // S2 - quadric
1693 aP.ParametersOnS1(U,V); // S1 - quadric
1695 if(IsSeamParameter(U,TOL2D)) {
1696 if(ip == 1 || ip == nbp) {
1697 Standard_Real U1 = 0., V1 = 0.;
1698 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1700 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1702 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1703 Standard_Real u = AdjustUFirst(U,U1);
1704 if(fabs(u-U) >= 1.5*M_PI) {
1705 Standard_Real U2 = 0., V2 = 0.;
1707 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1708 Line->SetUV(ip,Standard_False,u,V);
1709 Line->SetUV(ip,Standard_True,U2,V2);
1712 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1713 Line->SetUV(ip,Standard_True,u,V);
1714 Line->SetUV(ip,Standard_False,U2,V2);
1719 Standard_Integer ipp = ip - 1;
1720 Standard_Integer ipn = ip + 1;
1721 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1723 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1724 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1727 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1728 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1732 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1733 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1734 if(pnearZero == cnearZero) {
1735 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1736 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1738 nP.SetValue(aP.Value());
1739 Standard_Real U3 = 0., V3 = 0.;
1741 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1742 nP.SetValue(Standard_False,nU,V);
1743 nP.SetValue(Standard_True,U3,V3);
1746 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1747 nP.SetValue(Standard_True,nU,V);
1748 nP.SetValue(Standard_False,U3,V3);
1750 Line->InsertBefore(ipn,nP);
1752 result = Standard_True;
1757 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1758 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1760 nP.SetValue(aP.Value());
1761 Standard_Real U3 = 0., V3 = 0.;
1763 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1764 nP.SetValue(Standard_False,nU,V);
1765 nP.SetValue(Standard_True,U3,V3);
1768 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1769 nP.SetValue(Standard_True,nU,V);
1770 nP.SetValue(Standard_False,U3,V3);
1772 Line->InsertBefore(ip,nP);
1774 result = Standard_True;
1778 // Line->InsertBefore(ip,Line->Value(ipn));
1779 // Line->RemovePoint(ip+2);
1780 // result = Standard_True;
1781 // cout << "swap vertex " << endl;
1792 static void ToSmooth( const Handle(IntSurf_LineOn2S)& Line,
1793 const Standard_Boolean IsReversed,
1794 const IntSurf_Quadric& Quad,
1795 const Standard_Boolean IsFirst,
1798 if(Line->NbPoints() <= 10)
1802 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1803 if(NbTestPnts < 5) NbTestPnts = 5;
1805 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1806 Standard_Integer ip = 0;
1807 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1809 for(ip = startp; ip <= NbTestPnts; ip++) {
1811 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1812 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1815 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1816 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1818 DDU += fabs(fabs(Uc)-fabs(Un));
1819 DDV += fabs(fabs(Vc)-fabs(Vn));
1822 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1827 DDU /= (Standard_Real) NbTestPnts + 1;
1828 DDV /= (Standard_Real) NbTestPnts + 1;
1830 D3D /= (Standard_Real) NbTestPnts + 1;
1833 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1834 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1835 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1837 Standard_Boolean doU = Standard_False;
1839 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1842 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1843 Line->Value(Index2).ParametersOnS2(U2,V2);
1844 Line->Value(Index3).ParametersOnS2(U3,V3);
1847 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1848 Line->Value(Index2).ParametersOnS1(U2,V2);
1849 Line->Value(Index3).ParametersOnS1(U3,V3);
1852 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
1853 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
1855 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1856 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
1858 doU = Standard_False;
1863 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1864 Standard_Real Uapx = 0., Vapx = 0.;
1865 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1867 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
1869 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1870 if(fabs(V1-Vapx) <= 1.e-9) {}
1872 doU = Standard_False;
1878 Standard_Real dU = Min((DDU/10.),5.e-8);
1879 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1881 Line->SetUV(Index1,Standard_False,U,V1);
1883 Line->SetUV(Index1,Standard_True,U,V1);
1888 static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
1889 const IntSurf_PntOn2S& aV,
1890 const Standard_Boolean IsReversed,
1891 const Standard_Real ArcTol,
1892 const Handle(Adaptor3d_TopolTool)& PDomain)
1895 Standard_Boolean result = Standard_False;
1896 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1898 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1899 aV.ParametersOnS1(Uv,Vv);
1902 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1903 aV.ParametersOnS2(Uv,Vv);
1905 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
1906 gp_Pnt2d a2DPntM(Um,Vm);
1907 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
1908 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
1909 result = Standard_True;
1913 static void VerifyVertices( const Handle(IntSurf_LineOn2S)& Line,
1914 const Standard_Boolean IsReversed,
1915 const Handle(IntSurf_LineOn2S)& Vertices,
1916 const Standard_Real TOL2D,
1917 const Standard_Real ArcTol,
1918 const Handle(Adaptor3d_TopolTool)& PDomain,
1919 IntSurf_PntOn2S& VrtF,
1920 Standard_Boolean& AddFirst,
1921 IntSurf_PntOn2S& VrtL,
1922 Standard_Boolean& AddLast)
1924 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1925 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
1926 const IntSurf_PntOn2S& aPF = Line->Value(1);
1927 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
1928 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
1930 aPF.ParametersOnS2(UF,VF);
1931 aPL.ParametersOnS2(UL,VL);
1934 aPF.ParametersOnS1(UF,VF);
1935 aPL.ParametersOnS1(UL,VL);
1937 gp_Pnt2d a2DPF(UF,VF);
1938 gp_Pnt2d a2DPL(UL,VL);
1939 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
1940 Standard_Integer FConjugated = 0, LConjugated = 0;
1942 Standard_Integer iv = 0;
1944 for(iv = 1; iv <= nbv; iv++) {
1945 Standard_Real Uv = 0., Vv = 0.;
1947 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1949 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1952 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1954 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1958 for(iv = 1; iv <= nbv; iv++) {
1959 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1960 if(AreSamePoints(aPF,aV)) {
1965 Standard_Real Uv = 0., Vv = 0.;
1967 aV.ParametersOnS2(Uv,Vv);
1969 aV.ParametersOnS1(Uv,Vv);
1970 gp_Pnt2d a2DV(Uv,Vv);
1971 Standard_Real Dist = a2DV.Distance(a2DPF);
1972 if(Dist < DistMinF) {
1975 if(FConjugated != 0)
1978 if(IsSeamParameter(Uv,TOL2D)) {
1979 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1980 gp_Pnt2d a2DCV(Ucv,Vv);
1981 Standard_Real CDist = a2DCV.Distance(a2DPF);
1982 if(CDist < DistMinF) {
1991 for(iv = 1; iv <= nbv; iv++) {
1992 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1993 if(AreSamePoints(aPL,aV)) {
1998 Standard_Real Uv = 0., Vv = 0.;
2000 aV.ParametersOnS2(Uv,Vv);
2002 aV.ParametersOnS1(Uv,Vv);
2003 gp_Pnt2d a2DV(Uv,Vv);
2004 Standard_Real Dist = a2DV.Distance(a2DPL);
2005 if(Dist < DistMinL) {
2008 if(LConjugated != 0)
2011 if(IsSeamParameter(Uv,TOL2D)) {
2012 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2013 gp_Pnt2d a2DCV(Ucv,Vv);
2014 Standard_Real CDist = a2DCV.Distance(a2DPL);
2015 if(CDist < DistMinL) {
2024 AddFirst = Standard_False;
2025 AddLast = Standard_False;
2027 if(FIndexSame == 0) {
2028 if(FIndexNear != 0) {
2029 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2030 Standard_Real Uv = 0., Vv = 0.;
2032 aV.ParametersOnS2(Uv,Vv);
2034 aV.ParametersOnS1(Uv,Vv);
2035 if(IsSeamParameter(Uv,TOL2D)) {
2036 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2037 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2039 VrtF.SetValue(aV.Value());
2041 Standard_Real U2 = 0., V2 = 0.;
2042 aV.ParametersOnS1(U2,V2); // S1 - prm
2043 VrtF.SetValue(Standard_True,U2,V2);
2044 if(FConjugated == 0)
2045 VrtF.SetValue(Standard_False,Uv,Vv);
2047 VrtF.SetValue(Standard_False,Ucv,Vv);
2050 Standard_Real U2 = 0., V2 = 0.;
2051 aV.ParametersOnS2(U2,V2); // S2 - prm
2052 VrtF.SetValue(Standard_False,U2,V2);
2053 if(FConjugated == 0)
2054 VrtF.SetValue(Standard_True,Uv,Vv);
2056 VrtF.SetValue(Standard_True,Ucv,Vv);
2058 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2059 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2060 AddFirst = Standard_True;
2065 // to do: analyze internal vertex
2070 if(LIndexSame == 0) {
2071 if(LIndexNear != 0) {
2072 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2073 Standard_Real Uv = 0., Vv = 0.;
2075 aV.ParametersOnS2(Uv,Vv);
2077 aV.ParametersOnS1(Uv,Vv);
2078 if(IsSeamParameter(Uv,TOL2D)) {
2079 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2080 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2082 VrtL.SetValue(aV.Value());
2084 Standard_Real U2 = 0., V2 = 0.;
2085 aV.ParametersOnS1(U2,V2); // S1 - prm
2086 VrtL.SetValue(Standard_True,U2,V2);
2087 if(LConjugated == 0)
2088 VrtL.SetValue(Standard_False,Uv,Vv);
2090 VrtL.SetValue(Standard_False,Ucv,Vv);
2093 Standard_Real U2 = 0., V2 = 0.;
2094 aV.ParametersOnS2(U2,V2); // S2 - prm
2095 VrtL.SetValue(Standard_False,U2,V2);
2096 if(LConjugated == 0)
2097 VrtL.SetValue(Standard_True,Uv,Vv);
2099 VrtL.SetValue(Standard_True,Ucv,Vv);
2101 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2102 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2103 AddLast = Standard_True;
2108 // to do: analyze internal vertex
2114 static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
2115 const IntSurf_PntOn2S& VrtF,
2116 const Standard_Boolean AddFirst,
2117 const IntSurf_PntOn2S& VrtL,
2118 const Standard_Boolean AddLast,
2119 const Standard_Real D3DF,
2120 const Standard_Real D3DL)
2122 Standard_Boolean result = Standard_False;
2124 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2125 if((D3DF*2.) > DF && DF > 1.5e-7) {
2126 Line->InsertBefore(1,VrtF);
2127 result = Standard_True;
2131 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2132 if((D3DL*2.) > DL && DL > 1.5e-7) {
2134 result = Standard_True;
2141 static void PutIntVertices(Handle(IntPatch_Line)& Line,
2142 Handle(IntSurf_LineOn2S)& Result,
2143 Standard_Boolean ,//IsReversed,
2144 Handle(IntSurf_LineOn2S)& Vertices,
2145 const Standard_Real ArcTol)
2147 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2152 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2153 Standard_Integer ip = 0, iv = 0;
2155 IntPatch_Point thePnt;
2156 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2158 for(ip = 2; ip <= (nbp-1); ip++) {
2159 const IntSurf_PntOn2S& aP = Result->Value(ip);
2160 for(iv = 1; iv <= nbv; iv++) {
2161 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2162 if(AreSamePoints(aP,aV)) {
2163 aPnt = Result->Value(ip).Value();
2164 Result->Value(ip).ParametersOnS1(U1,V1);
2165 Result->Value(ip).ParametersOnS2(U2,V2);
2166 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2167 thePnt.SetParameters(U1,V1,U2,V2);
2168 thePnt.SetParameter((Standard_Real)ip);
2169 WLine->AddVertex(thePnt);
2175 static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2176 Handle(IntSurf_LineOn2S)& Vertices)
2178 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2179 Standard_Integer ip = 0, iv = 0;
2180 Standard_Boolean result = Standard_False;
2185 for(ip = 2; ip <= (nbp-1); ip++) {
2186 const IntSurf_PntOn2S& aP = Line->Value(ip);
2187 for(iv = 1; iv <= nbv; iv++) {
2188 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2189 if(AreSamePoints(aP,aV)) {
2190 result = Standard_True;
2200 static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
2201 Standard_Boolean Tang,
2202 IntSurf_TypeTrans Trans1,
2203 IntSurf_TypeTrans Trans2,
2204 Standard_Real ArcTol,
2205 Standard_Integer ParFirst,
2206 Standard_Integer ParLast)
2208 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2209 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2211 Standard_Integer ip = 0;
2212 for(ip = ParFirst; ip <= ParLast; ip++)
2213 sline->Add(SLine->Value(ip));
2215 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2218 IntPatch_Point TPntF,TPntL;
2219 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2221 aSPnt = sline->Value(1).Value();
2222 sline->Value(1).ParametersOnS1(uu1,vv1);
2223 sline->Value(1).ParametersOnS2(uu2,vv2);
2224 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2225 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2226 TPntF.SetParameter(1.);
2227 wline->AddVertex(TPntF);
2228 wline->SetFirstPoint(1);
2230 aSPnt = sline->Value(sline->NbPoints()).Value();
2231 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2232 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2233 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2234 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2235 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2236 wline->AddVertex(TPntL);
2237 wline->SetLastPoint(sline->NbPoints());
2242 static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
2243 Standard_Boolean Tang,
2244 IntSurf_TypeTrans Trans1,
2245 IntSurf_TypeTrans Trans2,
2246 Standard_Real ArcTol,
2247 IntPatch_SequenceOfLine& Segments)
2249 Standard_Boolean result = Standard_False;
2252 Standard_Integer nbv = WLine->NbVertex();
2254 Standard_Integer iv = 0;
2255 for(iv = 1; iv < nbv; iv++) {
2256 Standard_Integer firstPar =
2257 (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2258 Standard_Integer lastPar =
2259 (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
2260 if((lastPar - firstPar) <= 1)
2263 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,
2264 ArcTol,firstPar,lastPar);
2265 Segments.Append(splitwline);
2267 result = Standard_True;
2274 static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& theLine,
2275 const Standard_Boolean IsReversed,
2276 const IntSurf_Quadric& theQuad,
2277 const Handle(Adaptor3d_TopolTool)& thePDomain,
2278 const Handle(Adaptor3d_HSurface)& theQSurf,
2279 const Standard_Real theArcTol,
2280 IntPatch_SequenceOfLine& theLines)
2282 // Split <theLine> in the places where it passes through seam edge or singularity
2283 // (apex of cone or pole of sphere). This passage is detected by jump of U-parameter
2284 // from point to point.
2286 const Standard_Real aDeltaUmax = 0.5*M_PI;
2287 const Standard_Real aTOL3D = 1.e-10,
2288 aTOL2D = Precision::PConfusion(),
2289 aTOL2DS = Precision::PConfusion();
2291 if( theLine->ArcType() != IntPatch_Walking )
2293 return Standard_False;
2296 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&theLine));
2297 const Handle(IntSurf_LineOn2S)& aSLine = aWLine->Curve();
2299 if(aSLine->NbPoints() <= 2)
2301 return Standard_False;
2304 //Deletes repeated vertices
2305 Handle(IntSurf_LineOn2S) aVLine = GetVertices(aWLine,aTOL3D,aTOL2D);
2307 Handle(IntSurf_LineOn2S) aSSLine(aSLine);
2309 if(aSSLine->NbPoints() <= 1)
2310 return Standard_False;
2312 AdjustLine(aSSLine,IsReversed,theQSurf,aTOL2D);
2315 Standard_Boolean isInserted = Standard_True;
2318 const Standard_Integer aNbPnts = aSSLine->NbPoints();
2319 TColStd_Array1OfInteger aPTypes(1,aNbPnts);
2320 SearchVertices(aSSLine,aVLine,aPTypes);
2321 isInserted = InsertSeamVertices(aSSLine,IsReversed,aVLine,aPTypes,aTOL2D);
2325 const Standard_Integer aLindex = aSSLine->NbPoints();
2326 Standard_Integer aFindex = 1, aBindex = 0;
2328 IntPatch_Point aTPntF, aTPntL;
2330 // build WLine parts (if any)
2331 Standard_Boolean flNextLine = Standard_True;
2332 Standard_Boolean hasBeenDecomposed = Standard_False;
2333 Standard_Boolean PrePointExist = Standard_False;
2334 IntSurf_PntOn2S PrePoint;
2338 flNextLine = Standard_False;
2339 Standard_Boolean isDecomposited = Standard_False;
2340 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0.;
2342 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2344 //if((Lindex-Findex+1) <= 2 )
2345 if(aLindex <= aFindex)
2346 return hasBeenDecomposed;
2350 sline->Add(PrePoint);
2351 PrePointExist = Standard_False;
2354 // analyze other points
2355 for(Standard_Integer k = aFindex; k <= aLindex; k++)
2361 aSSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2365 aSSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2368 sline->Add(aSSLine->Value(k));
2369 PrePoint = aSSLine->Value(k);
2375 aSSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2379 aSSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2382 if(Abs(U1-AnU1) > aDeltaUmax)
2385 isDecomposited = Standard_True;
2387 if (Abs(U1) <= Precision::PConfusion() ||
2388 Abs(U1 - 2*M_PI) <= Precision::PConfusion())
2390 IntSurf_PntOn2S NewPoint;
2391 IntSurf_PntOn2S CurPoint = aSSLine->Value(k);
2392 gp_Pnt thePnt = CurPoint.Value();
2393 Standard_Real theU1, theV1, theU2, theV2;
2394 theU1 = (Abs(U1) <= Precision::PConfusion())? 2*M_PI : 0.;
2396 NewPoint.SetValue(thePnt);
2399 CurPoint.ParametersOnS2(theU2, theV2);
2400 NewPoint.SetValue(theU1, theV1, theU2, theV2);
2404 CurPoint.ParametersOnS1(theU2, theV2);
2405 NewPoint.SetValue(theU2, theV2, theU1, theV1);
2407 sline->Add(NewPoint);
2409 else if (Abs(AnU1) <= Precision::PConfusion() ||
2410 Abs(AnU1 - 2*M_PI) <= Precision::PConfusion())
2413 PrePointExist = Standard_True;
2414 Standard_Real theU1, theV1;
2417 PrePoint.ParametersOnS1(theU1, theV1);
2418 theU1 = (Abs(AnU1) <= Precision::PConfusion())? 2*M_PI : 0.;
2419 PrePoint.SetValue(Standard_True, //on first
2424 PrePoint.ParametersOnS2(theU1, theV1);
2425 theU1 = (Abs(AnU1) <= Precision::PConfusion())? 2*M_PI : 0.;
2426 PrePoint.SetValue(Standard_False, //on second
2434 sline->Add(aSSLine->Value(k));
2435 PrePoint = aSSLine->Value(k);
2439 IntSurf_PntOn2S aVF, aVL;
2440 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2441 VerifyVertices(sline,IsReversed,aVLine,aTOL2DS,theArcTol,
2442 thePDomain,aVF,addVF,aVL,addVL);
2444 Standard_Boolean hasInternals = HasInternals(sline,aVLine);
2446 Standard_Real D3F = 0., D3L = 0.;
2447 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2448 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2450 //if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2451 // D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2453 //if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2454 // D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->
2455 // Value(sline->NbPoints()-2).Value());
2460 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2463 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2464 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2470 ForcedPurgePoints(sline,IsReversed,theQuad);
2473 Handle(IntPatch_WLine) wline =
2474 new IntPatch_WLine(sline,Standard_False,
2475 theLine->TransitionOnS1(),theLine->TransitionOnS2());
2477 gp_Pnt aSPnt(sline->Value(1).Value());
2478 sline->Value(1).ParametersOnS1(U1,V1);
2479 sline->Value(1).ParametersOnS2(U2,V2);
2480 aTPntF.SetValue(aSPnt,theArcTol,Standard_False);
2481 aTPntF.SetParameters(U1,V1,U2,V2);
2482 aTPntF.SetParameter(1.);
2483 wline->AddVertex(aTPntF);
2484 wline->SetFirstPoint(1);
2488 PutIntVertices(wline,sline,IsReversed,aVLine,theArcTol);
2491 aSPnt = sline->Value(sline->NbPoints()).Value();
2492 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2493 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2494 aTPntL.SetValue(aSPnt,theArcTol,Standard_False);
2495 aTPntL.SetParameters(U1,V1,U2,V2);
2496 aTPntL.SetParameter(sline->NbPoints());
2497 wline->AddVertex(aTPntL);
2498 wline->SetLastPoint(sline->NbPoints());
2500 IntPatch_SequenceOfLine segm;
2501 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,
2502 theLine->TransitionOnS1(),theLine->TransitionOnS2(),theArcTol,segm);
2506 theLines.Append(wline);
2510 Standard_Integer nbsegms = segm.Length();
2511 Standard_Integer iseg = 0;
2512 for(iseg = 1; iseg <= nbsegms; iseg++)
2513 theLines.Append(segm(iseg));
2519 flNextLine = hasBeenDecomposed = Standard_True;
2523 return hasBeenDecomposed;
2528 Standard_Integer aNbPnts;
2529 Standard_Real aU1,aV1,aU2,aV2;
2532 aNbPnts=thelin->NbPoints();
2533 printf(" WLine: aNbPnts=%d\n", aNbPnts);
2534 for(i=1; i <= aNbPnts; ++i) {
2535 const IntSurf_PntOn2S& aPoint = thelin->Value(i);
2537 aPoint.Parameters(aU1, aV1, aU2, aV2);
2538 printf(" point %d %lf %lf %lf %lf %lf %lf %lf\n",
2539 i, aPx.X(), aPx.Y(), aPx.Z(), aU1, aV1, aU2, aV2);