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
44 #include <math_Vector.hxx>
45 #include <math_Matrix.hxx>
46 #include <TopTrans_CurveTransition.hxx>
47 #include <TopAbs_State.hxx>
48 #include <TopAbs_Orientation.hxx>
49 #include <TColStd_Array1OfInteger.hxx>
50 #include <TColStd_Array1OfReal.hxx>
52 #include <IntSurf_SequenceOfInteriorPoint.hxx>
53 #include <IntSurf_QuadricTool.hxx>
54 #include <GeomAbs_SurfaceType.hxx>
55 #include <IntAna2d_AnaIntersection.hxx>
56 #include <gp_Lin2d.hxx>
59 #include <Bnd_Box2d.hxx>
60 #include <IntPatch_PointLine.hxx>
62 static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& Line,
63 const Standard_Boolean IsReversed,
64 const IntSurf_Quadric& Quad,
65 const Handle(Adaptor3d_TopolTool)& PDomain,
66 const Handle(Adaptor3d_HSurface)& QSurf,
67 const Standard_Real ArcTol,
68 IntPatch_SequenceOfLine& Lines);
70 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
71 IntSurf_SequenceOfPathPoint& seqpdep,
72 const Handle(Adaptor3d_TopolTool)& Domain,
73 IntPatch_TheSurfFunction& Func,
74 const Handle(Adaptor3d_HSurface)& PSurf,
75 TColStd_Array1OfInteger& Destination);
77 void Recadre(const Standard_Boolean ,
78 GeomAbs_SurfaceType typeS1,
79 GeomAbs_SurfaceType typeS2,
81 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
82 Standard_Integer Param,
88 static Standard_Boolean IsIn2DBox(const Bnd_Box2d& theBox,
89 const Handle(IntPatch_PointLine)& theLine,
90 const Standard_Real theUPeriod,
91 const Standard_Real theVPeriod,
92 const Standard_Boolean isTheSurface1Using);
94 //=======================================================================
95 //function : IntPatch_ImpPrmIntersection
97 //=======================================================================
98 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
99 : done(Standard_False),
100 empt(Standard_False),
101 myIsStartPnt(Standard_False),
107 //=======================================================================
108 //function : IntPatch_ImpPrmIntersection
110 //=======================================================================
112 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection
113 (const Handle(Adaptor3d_HSurface)& Surf1,
114 const Handle(Adaptor3d_TopolTool)& D1,
115 const Handle(Adaptor3d_HSurface)& Surf2,
116 const Handle(Adaptor3d_TopolTool)& D2,
117 const Standard_Real TolArc,
118 const Standard_Real TolTang,
119 const Standard_Real Fleche,
120 const Standard_Real Pas)
121 : done(Standard_False),
122 empt(Standard_False),
123 myIsStartPnt(Standard_False),
127 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
131 //=======================================================================
132 //function : SetStartPoint
134 //=======================================================================
136 void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
137 const Standard_Real V)
139 myIsStartPnt = Standard_True;
140 myUStart = U; myVStart = V;
143 //=======================================================================
144 //function : ComputeTangency
146 //=======================================================================
147 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
148 IntSurf_SequenceOfPathPoint& seqpdep,
149 const Handle(Adaptor3d_TopolTool)& Domain,
150 IntPatch_TheSurfFunction& Func,
151 const Handle(Adaptor3d_HSurface)& PSurf,
152 TColStd_Array1OfInteger& Destination)
154 Standard_Integer i,k, NbPoints, seqlength;
155 Standard_Real theparam,test;
156 Standard_Boolean fairpt, ispassing;
157 TopAbs_Orientation arcorien,vtxorien;
158 Handle(Adaptor2d_HCurve2d) thearc;
159 Handle(Adaptor3d_HVertex) vtx,vtxbis;
160 //Standard_Boolean ispassing;
161 IntPatch_ThePathPointOfTheSOnBounds PStart;
162 IntSurf_PathPoint PPoint;
166 gp_Vec d1u,d1v,v1,v2;
170 double aX[2], aF[1], aD[1][2];
171 math_Vector X(aX, 1, 2);
172 math_Vector F(aF, 1, 1);
173 math_Matrix D(aD, 1, 1, 1, 2);
176 NbPoints = solrst.NbPoints();
177 for (i=1; i<= NbPoints; i++) {
178 if (Destination(i) == 0) {
179 PStart = solrst.Point(i);
180 thearc = PStart.Arc();
181 theparam = PStart.Parameter();
182 arcorien = Domain->Orientation(thearc);
183 ispassing = (arcorien == TopAbs_INTERNAL ||
184 arcorien == TopAbs_EXTERNAL);
186 thearc->D0(theparam,p2d);
189 PPoint.SetValue(PStart.Value(),X(1),X(2));
192 if (Func.IsTangent()) {
193 PPoint.SetTangency(Standard_True);
194 Destination(i) = seqlength+1;
195 if (!PStart.IsNew()) {
196 vtx = PStart.Vertex();
197 for (k=i+1; k<=NbPoints; k++) {
198 if (Destination(k) ==0) {
199 PStart = solrst.Point(k);
200 if (!PStart.IsNew()) {
201 vtxbis = PStart.Vertex();
202 if (Domain->Identical(vtx,vtxbis)) {
203 thearc = PStart.Arc();
204 theparam = PStart.Parameter();
205 arcorien = Domain->Orientation(thearc);
206 ispassing = ispassing && (arcorien == TopAbs_INTERNAL ||
207 arcorien == TopAbs_EXTERNAL);
209 thearc->D0(theparam,p2d);
210 PPoint.AddUV(p2d.X(),p2d.Y());
211 Destination(k) = seqlength+1;
217 PPoint.SetPassing(ispassing);
218 seqpdep.Append(PPoint);
221 else { // on a un point de depart potentiel
223 vectg = Func.Direction3d();
224 dirtg = Func.Direction2d();
226 PSurf->D1(X(1),X(2),ptbid,d1u,d1v);
227 thearc->D1(theparam,p2d,d2d);
228 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
229 v1 = d1u.Crossed(d1v);
231 test = vectg.Dot(v1.Crossed(v2));
232 if (PStart.IsNew()) {
233 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
234 (test > 0. && arcorien == TopAbs_REVERSED)) {
238 PPoint.SetDirections(vectg,dirtg);
239 PPoint.SetPassing(ispassing);
240 Destination(i) = seqlength+1;
241 seqpdep.Append(PPoint);
244 else { // traiter la transition complexe
245 gp_Dir bidnorm(1.,1.,1.);
246 Standard_Real tole = 1.e-8;
247 TopAbs_Orientation LocTrans;
248 TopTrans_CurveTransition comptrans;
249 comptrans.Reset(vectg,bidnorm,0.);
250 if (arcorien == TopAbs_FORWARD ||
251 arcorien == TopAbs_REVERSED) {
254 vtx = PStart.Vertex();
255 vtxorien = Domain->Orientation(vtx);
256 if (Abs(test) <= tole) {
257 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
260 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
261 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
262 LocTrans = TopAbs_FORWARD;
265 LocTrans = TopAbs_REVERSED;
267 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
270 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
272 Destination(i) = seqlength+1;
273 for (k= i+1; k<=NbPoints; k++) {
274 if (Destination(k) == 0) {
275 PStart = solrst.Point(k);
276 if (!PStart.IsNew()) {
277 vtxbis = PStart.Vertex();
278 if (Domain->Identical(vtx,vtxbis)) {
279 thearc = PStart.Arc();
280 theparam = PStart.Parameter();
281 arcorien = Domain->Orientation(thearc);
283 PPoint.AddUV(X(1),X(2));
285 thearc->D1(theparam,p2d,d2d);
286 PPoint.AddUV(p2d.X(),p2d.Y());
288 if (arcorien == TopAbs_FORWARD ||
289 arcorien == TopAbs_REVERSED) {
290 ispassing = Standard_False;
291 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
293 test = vectg.Dot(v1.Crossed(v2));
294 vtxorien = Domain->Orientation(PStart.Vertex());
295 if (Abs(test) <= tole) {
296 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
299 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
300 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
301 LocTrans = TopAbs_FORWARD;
304 LocTrans = TopAbs_REVERSED;
306 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
309 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
311 Destination(k) = seqlength+1;
316 fairpt = Standard_True;
318 TopAbs_State Before = comptrans.StateBefore();
319 TopAbs_State After = comptrans.StateAfter();
320 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
321 fairpt = Standard_False;
323 else if (Before == TopAbs_IN) {
324 if (After == TopAbs_IN) {
325 ispassing = Standard_True;
333 if (After !=TopAbs_IN) {
334 fairpt = Standard_False;
339 PPoint.SetDirections(vectg,dirtg);
340 PPoint.SetPassing(ispassing);
341 seqpdep.Append(PPoint);
344 else { // il faut remettre en "ordre" si on ne garde pas le point.
345 for (k=i; k <=NbPoints ; k++) {
346 if (Destination(k)==seqlength + 1) {
347 Destination(k) = -Destination(k);
356 //=======================================================================
359 //=======================================================================
360 void Recadre(const Standard_Boolean ,
361 GeomAbs_SurfaceType typeS1,
362 GeomAbs_SurfaceType typeS2,
364 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
365 Standard_Integer Param,
371 Standard_Real U1p,V1p,U2p,V2p;
372 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
376 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
377 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
378 case GeomAbs_Cylinder:
381 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
382 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
389 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
390 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
391 case GeomAbs_Cylinder:
394 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
395 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
399 pt.SetParameters(U1,V1,U2,V2);
402 //=======================================================================
405 //=======================================================================
406 void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
407 const Handle(Adaptor3d_TopolTool)& D1,
408 const Handle(Adaptor3d_HSurface)& Surf2,
409 const Handle(Adaptor3d_TopolTool)& D2,
410 const Standard_Real TolArc,
411 const Standard_Real TolTang,
412 const Standard_Real Fleche,
413 const Standard_Real Pas)
415 Standard_Boolean reversed, procf, procl, dofirst, dolast;
416 Standard_Integer indfirst = 0, indlast = 0, ind2, NbSegm;
417 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
418 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
420 IntPatch_TheSegmentOfTheSOnBounds thesegm;
421 IntSurf_PathPoint PPoint;
423 Handle(IntPatch_RLine) rline;
424 Handle(IntPatch_WLine) wline;
425 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
426 IntPatch_Point ptdeb,ptfin,ptbis;
429 IntSurf_Transition TLine,TArc;
430 IntSurf_TypeTrans trans1,trans2;
432 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
439 Handle(Adaptor2d_HCurve2d) currentarc;
440 GeomAbs_SurfaceType typeS1, typeS2;
441 IntSurf_Quadric Quad;
442 IntPatch_TheSurfFunction Func;
443 IntPatch_ArcFunction AFunc;
445 typeS1 = Surf1->GetType();
446 typeS2 = Surf2->GetType();
450 trans1 = IntSurf_Undecided;
451 trans2 = IntSurf_Undecided;
453 done = Standard_False;
454 empt = Standard_True;
458 reversed = Standard_False;
462 Quad.SetValue(Surf1->Plane());
465 case GeomAbs_Cylinder:
466 Quad.SetValue(Surf1->Cylinder());
470 Quad.SetValue(Surf1->Sphere());
474 Quad.SetValue(Surf1->Cone());
479 reversed = Standard_True;
483 Quad.SetValue(Surf2->Plane());
486 case GeomAbs_Cylinder:
487 Quad.SetValue(Surf2->Cylinder());
491 Quad.SetValue(Surf2->Sphere());
495 Quad.SetValue(Surf2->Cone());
499 Standard_ConstructionError::Raise();
507 Func.SetImplicitSurface(Quad);
508 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
509 AFunc.SetQuadric(Quad);
521 solrst.Perform(AFunc,D2,TolArc,TolTang);
524 solrst.Perform(AFunc,D1,TolArc,TolTang);
526 if (!solrst.IsDone()) {
530 IntSurf_SequenceOfPathPoint seqpdep;
531 IntSurf_SequenceOfInteriorPoint seqpins;
533 NbPointRst = solrst.NbPoints();
534 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
537 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
540 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
544 Standard_Boolean SearchIns = Standard_True;
545 if(Quad.TypeQuadric() == GeomAbs_Plane && solrst.NbSegments() > 0)
547 //For such kind of cases it is possible that whole surface is on one side of plane,
548 //plane only touches surface and does not cross it,
549 //so no inner points exist.
550 SearchIns = Standard_False;
551 Handle(Adaptor3d_TopolTool) T;
560 Standard_Integer aNbSamples = 0;
561 aNbSamples = T->NbSamples();
564 Standard_Real aValf[1], aUVap[2];
565 math_Vector Valf(aValf,1,1), UVap(aUVap,1,2);
566 T->SamplePoint(1,s2d, s3d);
569 Func.Value(UVap,Valf);
570 Standard_Real rvalf = Sign(1.,Valf(1));
571 for(Standard_Integer i = 2; i <= aNbSamples; ++i)
573 T->SamplePoint(i,s2d, s3d);
576 Func.Value(UVap,Valf);
577 if(rvalf * Valf(1) < 0.)
579 SearchIns = Standard_True;
584 // Recherche des points interieurs
589 solins.Perform(Func,Surf2,myUStart,myVStart);
591 solins.Perform(Func,Surf2,D2,TolTang);
595 solins.Perform(Func,Surf1,myUStart,myVStart);
597 solins.Perform(Func,Surf1,D1,TolTang);
599 NbPointIns = solins.NbPoints();
600 for (Standard_Integer i=1; i <= NbPointIns; i++) {
601 seqpins.Append(solins.Value(i));
605 NbPointDep=seqpdep.Length();
607 if (NbPointDep || NbPointIns) {
608 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
610 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
613 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
615 if(!iwalk.IsDone()) {
619 Standard_Real Vmin, Vmax, TolV = 1.e-14;
620 if (!reversed) { //Surf1 is quadric
621 Vmin = Surf1->FirstVParameter();
622 Vmax = Surf1->LastVParameter();
624 else { //Surf2 is quadric
625 Vmin = Surf2->FirstVParameter();
626 Vmax = Surf2->LastVParameter();
629 Nblines = iwalk.NbLines();
630 for (Standard_Integer j=1; j<=Nblines; j++) {
631 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
632 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
634 Nbpts = thelin->NbPoints();
636 Standard_Integer k = 0;
637 tgline = iwline->TangentVector(k);
638 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
639 valpt = thelin->Value(k).Value();
642 thelin->Value(k).ParametersOnS2(U2,V2);
643 norm1 = Quad.Normale(valpt);
644 Surf2->D1(U2,V2,ptbid,d1u,d1v);
645 norm2 = d1u.Crossed(d1v);
648 thelin->Value(k).ParametersOnS1(U2,V2);
649 norm2 = Quad.Normale(valpt);
650 Surf1->D1(U2,V2,ptbid,d1u,d1v);
651 norm1 = d1u.Crossed(d1v);
653 if (tgline.DotCross(norm2,norm1) > 0.) {
654 trans1 = IntSurf_Out;
659 trans2 = IntSurf_Out;
663 Standard_Real AnU1,AnU2,AnV2;
665 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
666 Standard_Boolean arecadr=Standard_False;
667 valpt = thelin->Value(1).Value();
668 Quad.Parameters(valpt,AnU1,V1);
670 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
671 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
674 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
675 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
678 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
679 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
682 if(typQuad==GeomAbs_Cylinder ||
683 typQuad==GeomAbs_Cone ||
684 typQuad==GeomAbs_Sphere) {
685 arecadr=Standard_True;
688 for (k=2; k<=Nbpts; ++k) {
689 valpt = thelin->Value(k).Value();
690 Quad.Parameters(valpt,U1,V1);
692 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
695 if((V1 > Vmax) && (V1-Vmax < TolV)) {
700 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
701 Standard_Real aCf, aTwoPI;
705 if ((U1-AnU1) > 1.5*M_PI) {
706 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
713 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
719 //if ((U1-AnU1) > 1.5*M_PI) {
722 //else if ((U1-AnU1) < -1.5*M_PI) {
725 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
729 thelin->SetUV(k,Standard_False,U1,V1);
731 thelin->Value(k).ParametersOnS1(U2,V2);
733 case GeomAbs_Cylinder:
737 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
738 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
743 if(typeS2==GeomAbs_Torus) {
744 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
745 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
747 thelin->SetUV(k,Standard_True,U2,V2);
750 thelin->SetUV(k,Standard_True,U1,V1);
752 thelin->Value(k).ParametersOnS2(U2,V2);
754 case GeomAbs_Cylinder:
758 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
759 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
764 if(typeS2==GeomAbs_Torus) {
765 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
766 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
768 thelin->SetUV(k,Standard_False,U2,V2);
777 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
779 if ( iwline->HasFirstPoint()
780 && iwline->IsTangentAtBegining() == Standard_False)
782 indfirst = iwline->FirstPointIndex();
783 PPoint = seqpdep(indfirst);
784 tgline = PPoint.Direction3d();
785 Standard_Integer themult = PPoint.Multiplicity();
786 for (Standard_Integer i=NbPointRst; i>=1; i--) {
787 if (Destination(i) == indfirst) {
788 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
789 Quad.Parameters(PPoint.Value(),U1,V1);
791 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
792 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
794 PPoint.Parameters(themult,U2,V2);
795 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
797 else { //-- typeS1 != Pln && Cyl && Sph && Cone
798 Quad.Parameters(PPoint.Value(),U2,V2);
800 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
801 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
803 PPoint.Parameters(themult,U1,V1);
804 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
807 VecNormale = d1u.Crossed(d1v);
808 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
809 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
810 ptdeb.SetParameters(U1,V1,U2,V2);
811 ptdeb.SetParameter(1.);
813 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
815 currentarc = solrst.Point(i).Arc();
816 currentparam = solrst.Point(i).Parameter();
817 currentarc->D1(currentparam,p2d,d2d);
818 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
820 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
821 if(squaremagnitudeVecNormale > 1e-13) {
822 DirNormale=VecNormale;
823 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
826 TLine.SetValue(Standard_True,IntSurf_Undecided);
827 TArc.SetValue(Standard_True,IntSurf_Undecided);
830 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
831 if (!solrst.Point(i).IsNew()) {
832 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
834 wline->AddVertex(ptdeb);
836 wline->SetFirstPoint(wline->NbVertex());
843 else if (iwline->IsTangentAtBegining())
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_True);
849 ptdeb.SetParameters(U1,V1,U2,V2);
850 ptdeb.SetParameter(1.);
851 wline->AddVertex(ptdeb);
852 wline->SetFirstPoint(wline->NbVertex());
856 gp_Pnt psol = thelin->Value(1).Value();
857 thelin->Value(1).ParametersOnS1(U1,V1);
858 thelin->Value(1).ParametersOnS2(U2,V2);
859 ptdeb.SetValue(psol,TolArc,Standard_False);
860 ptdeb.SetParameters(U1,V1,U2,V2);
861 ptdeb.SetParameter(1.);
862 wline->AddVertex(ptdeb);
863 wline->SetFirstPoint(wline->NbVertex());
867 if ( iwline->HasLastPoint()
868 && iwline->IsTangentAtEnd() == Standard_False)
870 indlast = iwline->LastPointIndex();
871 PPoint = seqpdep(indlast);
872 tgline = PPoint.Direction3d().Reversed();
873 Standard_Integer themult = PPoint.Multiplicity();
874 for (Standard_Integer i=NbPointRst; i >=1; i--) {
875 if (Destination(i) == indlast) {
877 Quad.Parameters(PPoint.Value(),U1,V1);
879 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
880 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
882 PPoint.Parameters(themult,U2,V2);
883 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
884 VecNormale = d1u.Crossed(d1v); //-- @@@@
887 Quad.Parameters(PPoint.Value(),U2,V2);
889 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
890 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
892 PPoint.Parameters(themult,U1,V1);
893 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
894 VecNormale = d1u.Crossed(d1v); //-- @@@@
897 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
898 ptfin.SetParameters(U1,V1,U2,V2);
899 ptfin.SetParameter(Nbpts);
901 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
903 currentarc = solrst.Point(i).Arc();
904 currentparam = solrst.Point(i).Parameter();
905 currentarc->D1(currentparam,p2d,d2d);
906 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
909 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
910 if(squaremagnitudeVecNormale > 1e-13) {
911 DirNormale=VecNormale;
912 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
915 TLine.SetValue(Standard_True,IntSurf_Undecided);
916 TArc.SetValue(Standard_True,IntSurf_Undecided);
920 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
921 if (!solrst.Point(i).IsNew()) {
922 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
924 wline->AddVertex(ptfin);
926 wline->SetLastPoint(wline->NbVertex());
933 else if (iwline->IsTangentAtEnd())
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_True);
939 ptfin.SetParameters(U1,V1,U2,V2);
940 ptfin.SetParameter(Nbpts);
941 wline->AddVertex(ptfin);
942 wline->SetLastPoint(wline->NbVertex());
946 gp_Pnt psol = thelin->Value(Nbpts).Value();
947 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
948 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
949 ptfin.SetValue(psol,TolArc,Standard_False);
950 ptfin.SetParameters(U1,V1,U2,V2);
951 ptfin.SetParameter(Nbpts);
952 wline->AddVertex(ptfin);
953 wline->SetLastPoint(wline->NbVertex());
956 // Il faut traiter les points de passage.
959 }// for (j=1; j<=Nblines; j++) {
961 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
962 // QUE SUR DES POINTS DE TANGENCE
965 Nblines = slin.Length();
966 for (Standard_Integer j=1; j<=Nblines-1; j++) {
967 dofirst = dolast = Standard_False;
968 const Handle(IntPatch_Line)& slinj = slin(j);
969 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
970 if (wlin1->HasFirstPoint()) {
971 ptdeb = wlin1->FirstPoint(indfirst);
972 if (ptdeb.IsTangencyPoint()) {
973 dofirst = Standard_True;
976 if (wlin1->HasLastPoint()) {
977 ptfin = wlin1->LastPoint(indlast);
978 if (ptfin.IsTangencyPoint()) {
979 dolast = Standard_True;
983 if (dofirst || dolast) {
984 for (Standard_Integer k=j+1; k<=Nblines;k++) {
985 const Handle(IntPatch_Line)& slink = slin(k);
986 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
987 if (wlin2->HasFirstPoint()) {
988 ptbis = wlin2->FirstPoint(ind2);
989 if (ptbis.IsTangencyPoint()) {
991 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
992 ptdeb.SetMultiple(Standard_True);
993 if (!ptbis.IsMultiple()) {
994 ptbis.SetMultiple(Standard_True);
995 wlin2->Replace(ind2,ptbis);
1000 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
1001 ptfin.SetMultiple(Standard_True);
1002 if (!ptbis.IsMultiple()) {
1003 ptbis.SetMultiple(Standard_True);
1004 wlin2->Replace(ind2,ptbis);
1010 if (wlin2->HasLastPoint()) {
1011 ptbis = wlin2->LastPoint(ind2);
1012 if (ptbis.IsTangencyPoint()) {
1014 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
1015 ptdeb.SetMultiple(Standard_True);
1016 if (!ptbis.IsMultiple()) {
1017 ptbis.SetMultiple(Standard_True);
1018 wlin2->Replace(ind2,ptbis);
1023 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
1024 ptfin.SetMultiple(Standard_True);
1025 if (!ptbis.IsMultiple()) {
1026 ptbis.SetMultiple(Standard_True);
1027 wlin2->Replace(ind2,ptbis);
1035 wlin1->Replace(indfirst,ptdeb);
1037 wlin1->Replace(indlast,ptfin);
1040 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
1042 // Treatment the segments
1043 NbSegm = solrst.NbSegments();
1045 for(Standard_Integer i=1; i<=NbSegm; i++) {
1046 thesegm = solrst.Segment(i);
1047 //Check if segment is degenerated
1048 if(thesegm.HasFirstPoint() && thesegm.HasLastPoint())
1050 Standard_Real tol2 = Precision::Confusion();
1052 const gp_Pnt& aPf = thesegm.FirstPoint().Value();
1053 const gp_Pnt& aPl = thesegm.LastPoint().Value();
1054 if(aPf.SquareDistance(aPl) <= tol2)
1056 //segment can be degenerated - check inner point
1057 paramf = thesegm.FirstPoint().Parameter();
1058 paraml = thesegm.LastPoint().Parameter();
1060 thesegm.Curve()->Value(.57735 * paramf + 0.42265 * paraml);
1064 Surf1->D0(_p2d.X(), _p2d.Y(), aPm);
1068 Surf2->D0(_p2d.X(), _p2d.Y(), aPm);
1070 if(aPm.SquareDistance(aPf) <= tol2)
1079 //----------------------------------------------------------------------
1080 // on cree une ligne d intersection contenant uniquement le segment.
1081 // VOIR POUR LA TRANSITION DE LA LIGNE
1082 // On ajoute aussi un polygone pour le traitement des intersections
1083 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
1084 //----------------------------------------------------------------------
1085 //-- Calcul de la transition sur la rline (12 fev 97)
1086 //-- reversed a le sens de OnFirst
1088 dofirst = dolast = Standard_False;
1089 procf = Standard_False;
1090 procl = Standard_False;
1091 IntSurf_Transition TLineUnk,TArcUnk;
1093 IntPatch_Point _thepointAtBeg;
1094 IntPatch_Point _thepointAtEnd;
1096 Standard_Boolean TransitionOK=Standard_False;
1098 if(thesegm.HasFirstPoint()) {
1099 Standard_Real _u1,_v1,_u2,_v2;
1101 dofirst = Standard_True;
1102 PStartf = thesegm.FirstPoint();
1103 paramf = PStartf.Parameter();
1105 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
1106 Handle(Adaptor3d_HVertex) _vtx;
1107 if(PStartf.IsNew()==Standard_False)
1108 _vtx= PStartf.Vertex();
1109 const gp_Pnt& _Pp = PStartf.Value();
1110 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1111 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1112 Quad.Parameters(_Pp,_u1,_v1);
1113 _u2=_p2d.X(); _v2=_p2d.Y();
1115 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1116 Quad.Parameters(_Pp,_u2,_v2);
1117 _u1=_p2d.X(); _v1=_p2d.Y();
1119 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1120 _thepointAtBeg.SetParameter(paramf);
1121 if(PStartf.IsNew()==Standard_False)
1122 _thepointAtBeg.SetVertex(reversed,_vtx);
1123 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1126 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1127 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1128 norm1 = d1u1.Crossed(d1v1);
1129 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1130 norm2 = d1u2.Crossed(d1v2);
1132 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1134 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1137 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1139 _u1=tgline.DotCross(norm2,norm1);
1140 TransitionOK=Standard_True;
1141 if (_u1 > 0.00000001) {
1142 trans1 = IntSurf_Out;
1143 trans2 = IntSurf_In;
1145 else if(_u1 < -0.00000001) {
1146 trans1 = IntSurf_In;
1147 trans2 = IntSurf_Out;
1150 TransitionOK=Standard_False;
1153 if(thesegm.HasLastPoint()) {
1154 Standard_Real _u1,_v1,_u2,_v2;
1156 dolast = Standard_True;
1157 PStartl = thesegm.LastPoint();
1158 paraml = PStartl.Parameter();
1160 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1161 Handle(Adaptor3d_HVertex) _vtx;
1162 if(PStartl.IsNew()==Standard_False)
1163 _vtx = PStartl.Vertex();
1164 const gp_Pnt& _Pp = PStartl.Value();
1165 IntPatch_Point _thepoint;
1166 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1167 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1168 Quad.Parameters(_Pp,_u1,_v1);
1169 _u2=_p2d.X(); _v2=_p2d.Y();
1171 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1172 Quad.Parameters(_Pp,_u2,_v2);
1173 _u1=_p2d.X(); _v1=_p2d.Y();
1175 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1176 _thepointAtEnd.SetParameter(paraml);
1177 if(PStartl.IsNew()==Standard_False)
1178 _thepointAtEnd.SetVertex(reversed,_vtx);
1179 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1183 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1184 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1185 norm1 = d1u1.Crossed(d1v1);
1186 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1187 norm2 = d1u2.Crossed(d1v2);
1189 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1191 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1194 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1196 _u1=tgline.DotCross(norm2,norm1);
1197 TransitionOK=Standard_True;
1198 if (_u1 > 0.00000001) {
1199 trans1 = IntSurf_Out;
1200 trans2 = IntSurf_In;
1202 else if(_u1 < -0.00000001) {
1203 trans1 = IntSurf_In;
1204 trans2 = IntSurf_Out;
1207 TransitionOK=Standard_False;
1210 if(TransitionOK==Standard_False) {
1211 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1212 rline = new IntPatch_RLine (Standard_False);
1214 rline->SetArcOnS1(thesegm.Curve());
1217 rline->SetArcOnS2(thesegm.Curve());
1221 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1222 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1224 rline->SetArcOnS1(thesegm.Curve());
1227 rline->SetArcOnS2(thesegm.Curve());
1231 //------------------------------
1232 //-- Ajout des points
1234 if (thesegm.HasFirstPoint()) {
1235 rline->AddVertex(_thepointAtBeg);
1236 rline->SetFirstPoint(rline->NbVertex());
1239 if (thesegm.HasLastPoint()) {
1240 rline->AddVertex(_thepointAtEnd);
1241 rline->SetLastPoint(rline->NbVertex());
1244 // Polygone sur restriction solution
1245 if (dofirst && dolast) {
1248 IntSurf_PntOn2S p2s;
1249 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1250 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1251 Standard_Integer nbsample = 100;
1254 for (Standard_Integer j=1; j<=nbsample; j++) {
1255 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1256 arcsegm->D0(prm,p2d);
1257 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1259 Quad.Parameters(ptpoly,U1,V1);
1260 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1265 for (Standard_Integer j=1; j<=nbsample; j++) {
1266 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1267 arcsegm->D0(prm,p2d);
1268 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1270 Quad.Parameters(ptpoly,U2,V2);
1271 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1278 if (dofirst || dolast) {
1279 Nblines = slin.Length();
1280 for (Standard_Integer j=1; j<=Nblines; j++) {
1281 const Handle(IntPatch_Line)& slinj = slin(j);
1282 typ = slinj->ArcType();
1283 if (typ == IntPatch_Walking) {
1284 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1287 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1289 for (Standard_Integer k=1; k<=Nbpts;k++) {
1290 if (typ == IntPatch_Walking) {
1291 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1294 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1298 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1299 ptdeb.SetMultiple(Standard_True);
1300 if (typ == IntPatch_Walking) {
1301 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1304 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1306 ptdeb.SetParameter(paramf);
1307 rline->AddVertex(ptdeb);
1309 procf=Standard_True;
1310 rline->SetFirstPoint(rline->NbVertex());
1315 if(dofirst) { //-- on recharge le ptdeb
1316 if (typ == IntPatch_Walking) {
1317 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1320 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1323 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1324 ptdeb.SetMultiple(Standard_True);
1325 if (typ == IntPatch_Walking) {
1326 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1329 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1331 ptdeb.SetParameter(paraml);
1332 rline->AddVertex(ptdeb);
1334 procl=Standard_True;
1335 rline->SetLastPoint(rline->NbVertex());
1346 // on traite les restrictions de la surface implicite
1347 for (Standard_Integer i=1; i<=slin.Length(); i++)
1349 Handle(IntPatch_Line)& aL = slin(i);
1352 IntPatch_RstInt::PutVertexOnLine(aL,Surf1,D1,Surf2,Standard_True,TolTang);
1354 IntPatch_RstInt::PutVertexOnLine(aL,Surf2,D2,Surf1,Standard_False,TolTang);
1357 const Standard_Real aUPeriodOfSurf1 = Surf1->IsUPeriodic() ? Surf1->UPeriod() : 0.0,
1358 aUPeriodOfSurf2 = Surf2->IsUPeriodic() ? Surf2->UPeriod() : 0.0,
1359 aVPeriodOfSurf1 = Surf1->IsVPeriodic() ? Surf1->VPeriod() : 0.0,
1360 aVPeriodOfSurf2 = Surf2->IsVPeriodic() ? Surf2->VPeriod() : 0.0;
1362 for (Standard_Integer i = 1; i <= slin.Length(); i++)
1364 //BndBox of the points in Restriction line
1366 for(Standard_Integer j = i + 1; j <= slin.Length(); j++)
1368 Handle(IntPatch_PointLine) aL1 = Handle(IntPatch_PointLine)::DownCast(slin(i));
1369 Handle(IntPatch_PointLine) aL2 = Handle(IntPatch_PointLine)::DownCast(slin(j));
1371 Handle(IntPatch_RLine) aRL1 = Handle(IntPatch_RLine)::DownCast(aL1);
1372 Handle(IntPatch_RLine) aRL2 = Handle(IntPatch_RLine)::DownCast(aL2);
1374 if(aRL1.IsNull() && aRL2.IsNull())
1375 {//If Walking-Walking
1378 else if(aRL1.IsNull())
1379 {// i-th line is not restriction,
1380 // but j-th is restriction
1382 slin.SetValue(i, aL2);
1388 //Here aL1 (i-th line) is Restriction-line and aL2 (j-th line) is not Restriction
1392 for(Standard_Integer aPRID = 1; aPRID <= aRL1->NbPnts(); aPRID++)
1394 Standard_Real u = 0.0, v = 0.0;
1396 aRL1->Point(aPRID).ParametersOnS1(u, v);
1398 aRL1->Point(aPRID).ParametersOnS2(u, v);
1400 aBRL.Add(gp_Pnt2d(u, v));
1403 Standard_Real aXmin = 0.0, aYmin = 0.0, aXMax = 0.0, aYMax = 0.0;
1404 aBRL.Get(aXmin, aYmin, aXMax, aYMax);
1405 const Standard_Real aDX = aXMax - aXmin,
1406 aDY = aYMax - aYmin;
1408 const Standard_Real aTolU = reversed? Surf1->UResolution(TolArc) : Surf2->UResolution(TolArc);
1409 const Standard_Real aTolV = reversed? Surf1->VResolution(TolArc) : Surf2->VResolution(TolArc);
1411 if((aDX > aTolU) && (aDY > aTolV))
1412 {//Delete restriction line because it is not isoline.
1423 aBRL.Update(aXmin, aYmin, aXMax, aYMax);
1426 const Standard_Boolean isCoincide = IsIn2DBox(aBRL, aL2,
1427 (reversed? aUPeriodOfSurf1 : aUPeriodOfSurf2),
1428 (reversed? aVPeriodOfSurf1 : aVPeriodOfSurf2), reversed);
1431 {//Delete Walking-line
1438 empt = (slin.Length() == 0 && spnt.Length() == 0);
1439 done = Standard_True;
1442 if(slin.Length() == 0)
1445 Standard_Boolean isDecomposeRequired = (Quad.TypeQuadric() == GeomAbs_Cone) ||
1446 (Quad.TypeQuadric() == GeomAbs_Sphere);
1448 if(!isDecomposeRequired)
1451 // post processing for cones and spheres
1453 const Handle(Adaptor3d_TopolTool)& PDomain = (reversed) ? D1 : D2;
1454 const Handle(Adaptor3d_HSurface)& aQSurf = (reversed) ? Surf2 : Surf1;
1456 IntPatch_SequenceOfLine dslin;
1457 Standard_Boolean isDecompose = Standard_False;
1458 for(Standard_Integer i = 1; i <= slin.Length(); i++ )
1460 if(DecomposeResult(slin(i),reversed,Quad,PDomain,aQSurf,TolArc,dslin))
1462 isDecompose = Standard_True;
1470 for(Standard_Integer i = 1; i <= dslin.Length(); i++ )
1471 slin.Append(dslin(i));
1474 // correct U parameter of the start point of line on Quadric
1475 // (change 0->2PI or vs, if necessary)
1476 static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1478 Standard_Real u = U1;
1480 // case: no adjustment
1481 if( U1 > 0. && U1 < (2.*M_PI) )
1485 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
1486 if( U2 > 0. && U2 < (2.*M_PI) )
1487 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1489 Standard_Real uu = U2;
1490 if( U2 > (2.*M_PI) )
1491 while( uu > (2.*M_PI) )
1497 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1501 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1502 if( U2 > 0. && U2 < (2.*M_PI) )
1503 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1505 Standard_Real uu = U2;
1506 if( U2 > (2.*M_PI) )
1507 while( uu > (2.*M_PI) )
1513 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1516 // case: '<0. || >2PI'
1522 while(u > (2.*M_PI))
1529 // collect vertices, reject equals
1530 static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1531 const Standard_Real TOL3D,
1532 const Standard_Real TOL2D)
1534 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1536 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1538 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1539 Standard_Integer i = 0, k = 0;
1540 Standard_Integer NbVrt = WLine->NbVertex();
1542 TColStd_Array1OfInteger anVrts(1,NbVrt);
1545 // check equal vertices
1546 for(i = 1; i <= NbVrt; i++) {
1548 if( anVrts(i) == -1 ) continue;
1550 const IntPatch_Point& Pi = WLine->Vertex(i);
1552 for(k = (i+1); k <= NbVrt; k++) {
1554 if( anVrts(k) == -1 ) continue;
1556 const IntPatch_Point& Pk = WLine->Vertex(k);
1558 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
1559 // suggest the points are equal;
1560 // test 2d parameters on surface
1561 Standard_Boolean sameU1 = Standard_False;
1562 Standard_Boolean sameV1 = Standard_False;
1563 Standard_Boolean sameU2 = Standard_False;
1564 Standard_Boolean sameV2 = Standard_False;
1566 Pi.ParametersOnS1(U1,V1);
1567 Pk.ParametersOnS1(U2,V2);
1568 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1569 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1571 Pi.ParametersOnS2(U1,V1);
1572 Pk.ParametersOnS2(U2,V2);
1573 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1574 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1576 if((sameU1 && sameV1) && (sameU2 && sameV2))
1582 // copy further processed vertices
1583 for(i = 1; i <= NbVrt; i++) {
1584 if( anVrts(i) == -1 ) continue;
1585 vertices->Add(WLine->Vertex(i).PntOn2S());
1590 static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1591 const IntSurf_PntOn2S& P2)
1593 Standard_Boolean result = Standard_False;
1594 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1595 const gp_Pnt& P3D1 = P1.Value();
1596 const gp_Pnt& P3D2 = P2.Value();
1597 if(P3D1.Distance(P3D2) <= T3D) {
1598 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1599 P1.ParametersOnS1(U1,V1);
1600 P1.ParametersOnS2(U2,V2);
1601 P2.ParametersOnS1(U3,V3);
1602 P2.ParametersOnS2(U4,V4);
1603 gp_Pnt2d P2D11(U1,V1);
1604 gp_Pnt2d P2D12(U2,V2);
1605 gp_Pnt2d P2D21(U3,V3);
1606 gp_Pnt2d P2D22(U4,V4);
1607 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1608 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1609 if(sameS1 && sameS2)
1610 result = Standard_True;
1615 static void ForcedPurgePoints(const Handle(IntSurf_LineOn2S)& Result,
1616 const Standard_Boolean IsReversed,
1617 const IntSurf_Quadric& Quad)
1619 if(Result->NbPoints() <= 30) return;
1620 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1622 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1624 Result->Value(1).ParametersOnS2(U1,V1);
1625 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1628 Result->Value(1).ParametersOnS1(U1,V1);
1629 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
1632 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1633 Standard_Real Uapx = 0., Vapx = 0.;
1634 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1636 if(fabs(V1-Vapx) <= 1.e-3)
1638 if(fabs(V2-Vapx) <= 1.e-3)
1642 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
1643 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
1645 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1647 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1651 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1652 Result->RemovePoint(2);
1656 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1657 Result->RemovePoint(Result->NbPoints()-1);
1662 // DEBUG FUNCTION !!!
1664 static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1665 Standard_Boolean IsReversed,
1666 Standard_Integer Number)
1668 cout << "DUMP LINE" << endl;
1671 for(i = 1; i <= Line->NbPoints(); i++) {
1672 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1674 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1676 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1677 cout << "point p" << i << " " << U << " " << V << endl;
1683 // DEBUG FUNCTION !!!
1685 static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1686 const Handle(IntSurf_LineOn2S)& Vertices,
1687 TColStd_Array1OfInteger& PTypes)
1689 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1690 Standard_Integer ip = 0, iv = 0;
1691 for(ip = 1; ip <= nbp; ip++) {
1692 const IntSurf_PntOn2S& aP = Line->Value(ip);
1693 Standard_Integer type = 0;
1694 for(iv = 1; iv <= nbv; iv++) {
1695 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1696 if(AreSamePoints(aP,aV)) {
1705 static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1706 const Standard_Real TOL2D)
1708 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
1711 static inline Standard_Real AdjustU(const Standard_Real U)
1713 Standard_Real u = U, DBLPI = 2.*M_PI;
1714 if(u < 0. || u > DBLPI) {
1725 static inline void Correct2DBounds(const Standard_Real UF,
1726 const Standard_Real UL,
1727 const Standard_Real VF,
1728 const Standard_Real VL,
1729 const Standard_Real TOL2D,
1733 Standard_Real Eps = 1.e-16;
1734 Standard_Real dUF = fabs(U - UF);
1735 Standard_Real dUL = fabs(U - UL);
1736 Standard_Real dVF = fabs(V - VF);
1737 Standard_Real dVL = fabs(V - VL);
1738 if(dUF <= TOL2D && dUF > Eps) U = UF;
1739 if(dUL <= TOL2D && dUL > Eps) U = UL;
1740 if(dVF <= TOL2D && dVF > Eps) V = VF;
1741 if(dVL <= TOL2D && dVL > Eps) V = VL;
1744 static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1745 const Standard_Boolean IsReversed,
1746 const Handle(Adaptor3d_HSurface)& QSurf,
1747 const Standard_Real TOL2D)
1749 Standard_Real VF = QSurf->FirstVParameter();
1750 Standard_Real VL = QSurf->LastVParameter();
1751 Standard_Real UF = QSurf->FirstUParameter();
1752 Standard_Real UL = QSurf->LastUParameter();
1754 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1755 Standard_Real U = 0., V = 0.;
1756 for(ip = 1; ip <= nbp; ip++) {
1758 Line->Value(ip).ParametersOnS2(U,V);
1760 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1761 Line->SetUV(ip,Standard_False,U,V);
1764 Line->Value(ip).ParametersOnS1(U,V);
1766 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1767 Line->SetUV(ip,Standard_True,U,V);
1772 static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
1773 const Standard_Boolean IsReversed,
1774 Handle(IntSurf_LineOn2S)& Vertices,
1775 const TColStd_Array1OfInteger& PTypes,
1776 const Standard_Real TOL2D)
1778 Standard_Boolean result = Standard_False;
1779 Standard_Integer ip = 0, nbp = Line->NbPoints();
1780 Standard_Real U = 0., V = 0.;
1781 for(ip = 1; ip <= nbp; ip++) {
1782 Standard_Integer ipt = PTypes(ip);
1784 const IntSurf_PntOn2S& aP = Line->Value(ip);
1786 aP.ParametersOnS2(U,V); // S2 - quadric
1788 aP.ParametersOnS1(U,V); // S1 - quadric
1790 if(IsSeamParameter(U,TOL2D)) {
1791 if(ip == 1 || ip == nbp) {
1792 Standard_Real U1 = 0., V1 = 0.;
1793 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1795 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1797 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1798 Standard_Real u = AdjustUFirst(U,U1);
1799 if(fabs(u-U) >= 1.5*M_PI) {
1800 Standard_Real U2 = 0., V2 = 0.;
1802 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1803 Line->SetUV(ip,Standard_False,u,V);
1804 Line->SetUV(ip,Standard_True,U2,V2);
1807 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1808 Line->SetUV(ip,Standard_True,u,V);
1809 Line->SetUV(ip,Standard_False,U2,V2);
1814 Standard_Integer ipp = ip - 1;
1815 Standard_Integer ipn = ip + 1;
1816 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1818 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1819 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1822 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1823 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1827 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1828 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1829 if(pnearZero == cnearZero) {
1830 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1831 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1833 nP.SetValue(aP.Value());
1834 Standard_Real U3 = 0., V3 = 0.;
1836 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1837 nP.SetValue(Standard_False,nU,V);
1838 nP.SetValue(Standard_True,U3,V3);
1841 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1842 nP.SetValue(Standard_True,nU,V);
1843 nP.SetValue(Standard_False,U3,V3);
1845 Line->InsertBefore(ipn,nP);
1847 result = Standard_True;
1852 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1853 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1855 nP.SetValue(aP.Value());
1856 Standard_Real U3 = 0., V3 = 0.;
1858 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1859 nP.SetValue(Standard_False,nU,V);
1860 nP.SetValue(Standard_True,U3,V3);
1863 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1864 nP.SetValue(Standard_True,nU,V);
1865 nP.SetValue(Standard_False,U3,V3);
1867 Line->InsertBefore(ip,nP);
1869 result = Standard_True;
1873 // Line->InsertBefore(ip,Line->Value(ipn));
1874 // Line->RemovePoint(ip+2);
1875 // result = Standard_True;
1876 // cout << "swap vertex " << endl;
1887 static void ToSmooth( const Handle(IntSurf_LineOn2S)& Line,
1888 const Standard_Boolean IsReversed,
1889 const IntSurf_Quadric& Quad,
1890 const Standard_Boolean IsFirst,
1893 if(Line->NbPoints() <= 10)
1897 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1898 if(NbTestPnts < 5) NbTestPnts = 5;
1900 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1901 Standard_Integer ip = 0;
1902 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1904 for(ip = startp; ip <= NbTestPnts; ip++) {
1906 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1907 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1910 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1911 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1913 DDU += fabs(fabs(Uc)-fabs(Un));
1914 DDV += fabs(fabs(Vc)-fabs(Vn));
1917 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1922 DDU /= (Standard_Real) NbTestPnts + 1;
1923 DDV /= (Standard_Real) NbTestPnts + 1;
1925 D3D /= (Standard_Real) NbTestPnts + 1;
1928 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1929 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1930 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1932 Standard_Boolean doU = Standard_False;
1934 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1937 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1938 Line->Value(Index2).ParametersOnS2(U2,V2);
1939 Line->Value(Index3).ParametersOnS2(U3,V3);
1942 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1943 Line->Value(Index2).ParametersOnS1(U2,V2);
1944 Line->Value(Index3).ParametersOnS1(U3,V3);
1947 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
1948 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
1950 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1951 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
1953 doU = Standard_False;
1958 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1959 Standard_Real Uapx = 0., Vapx = 0.;
1960 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1962 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
1964 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1965 if(fabs(V1-Vapx) <= 1.e-9) {}
1967 doU = Standard_False;
1973 Standard_Real dU = Min((DDU/10.),5.e-8);
1974 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1976 Line->SetUV(Index1,Standard_False,U,V1);
1978 Line->SetUV(Index1,Standard_True,U,V1);
1983 static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
1984 const IntSurf_PntOn2S& aV,
1985 const Standard_Boolean IsReversed,
1986 const Standard_Real ArcTol,
1987 const Handle(Adaptor3d_TopolTool)& PDomain)
1990 Standard_Boolean result = Standard_False;
1991 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1993 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1994 aV.ParametersOnS1(Uv,Vv);
1997 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1998 aV.ParametersOnS2(Uv,Vv);
2000 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
2001 gp_Pnt2d a2DPntM(Um,Vm);
2002 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
2003 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
2004 result = Standard_True;
2008 static void VerifyVertices( const Handle(IntSurf_LineOn2S)& Line,
2009 const Standard_Boolean IsReversed,
2010 const Handle(IntSurf_LineOn2S)& Vertices,
2011 const Standard_Real TOL2D,
2012 const Standard_Real ArcTol,
2013 const Handle(Adaptor3d_TopolTool)& PDomain,
2014 IntSurf_PntOn2S& VrtF,
2015 Standard_Boolean& AddFirst,
2016 IntSurf_PntOn2S& VrtL,
2017 Standard_Boolean& AddLast)
2019 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2020 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
2021 const IntSurf_PntOn2S& aPF = Line->Value(1);
2022 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
2023 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
2025 aPF.ParametersOnS2(UF,VF);
2026 aPL.ParametersOnS2(UL,VL);
2029 aPF.ParametersOnS1(UF,VF);
2030 aPL.ParametersOnS1(UL,VL);
2032 gp_Pnt2d a2DPF(UF,VF);
2033 gp_Pnt2d a2DPL(UL,VL);
2034 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
2035 Standard_Integer FConjugated = 0, LConjugated = 0;
2037 Standard_Integer iv = 0;
2039 for(iv = 1; iv <= nbv; iv++) {
2040 Standard_Real Uv = 0., Vv = 0.;
2042 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
2044 Vertices->SetUV(iv,Standard_False,Uv,Vv);
2047 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
2049 Vertices->SetUV(iv,Standard_True,Uv,Vv);
2053 for(iv = 1; iv <= nbv; iv++) {
2054 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2055 if(AreSamePoints(aPF,aV)) {
2060 Standard_Real Uv = 0., Vv = 0.;
2062 aV.ParametersOnS2(Uv,Vv);
2064 aV.ParametersOnS1(Uv,Vv);
2065 gp_Pnt2d a2DV(Uv,Vv);
2066 Standard_Real Dist = a2DV.Distance(a2DPF);
2067 if(Dist < DistMinF) {
2070 if(FConjugated != 0)
2073 if(IsSeamParameter(Uv,TOL2D)) {
2074 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2075 gp_Pnt2d a2DCV(Ucv,Vv);
2076 Standard_Real CDist = a2DCV.Distance(a2DPF);
2077 if(CDist < DistMinF) {
2086 for(iv = 1; iv <= nbv; iv++) {
2087 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2088 if(AreSamePoints(aPL,aV)) {
2093 Standard_Real Uv = 0., Vv = 0.;
2095 aV.ParametersOnS2(Uv,Vv);
2097 aV.ParametersOnS1(Uv,Vv);
2098 gp_Pnt2d a2DV(Uv,Vv);
2099 Standard_Real Dist = a2DV.Distance(a2DPL);
2100 if(Dist < DistMinL) {
2103 if(LConjugated != 0)
2106 if(IsSeamParameter(Uv,TOL2D)) {
2107 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2108 gp_Pnt2d a2DCV(Ucv,Vv);
2109 Standard_Real CDist = a2DCV.Distance(a2DPL);
2110 if(CDist < DistMinL) {
2119 AddFirst = Standard_False;
2120 AddLast = Standard_False;
2122 if(FIndexSame == 0) {
2123 if(FIndexNear != 0) {
2124 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2125 Standard_Real Uv = 0., Vv = 0.;
2127 aV.ParametersOnS2(Uv,Vv);
2129 aV.ParametersOnS1(Uv,Vv);
2130 if(IsSeamParameter(Uv,TOL2D)) {
2131 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2132 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2134 VrtF.SetValue(aV.Value());
2136 Standard_Real U2 = 0., V2 = 0.;
2137 aV.ParametersOnS1(U2,V2); // S1 - prm
2138 VrtF.SetValue(Standard_True,U2,V2);
2139 if(FConjugated == 0)
2140 VrtF.SetValue(Standard_False,Uv,Vv);
2142 VrtF.SetValue(Standard_False,Ucv,Vv);
2145 Standard_Real U2 = 0., V2 = 0.;
2146 aV.ParametersOnS2(U2,V2); // S2 - prm
2147 VrtF.SetValue(Standard_False,U2,V2);
2148 if(FConjugated == 0)
2149 VrtF.SetValue(Standard_True,Uv,Vv);
2151 VrtF.SetValue(Standard_True,Ucv,Vv);
2153 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2154 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2155 AddFirst = Standard_True;
2160 // to do: analyze internal vertex
2165 if(LIndexSame == 0) {
2166 if(LIndexNear != 0) {
2167 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2168 Standard_Real Uv = 0., Vv = 0.;
2170 aV.ParametersOnS2(Uv,Vv);
2172 aV.ParametersOnS1(Uv,Vv);
2173 if(IsSeamParameter(Uv,TOL2D)) {
2174 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2175 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2177 VrtL.SetValue(aV.Value());
2179 Standard_Real U2 = 0., V2 = 0.;
2180 aV.ParametersOnS1(U2,V2); // S1 - prm
2181 VrtL.SetValue(Standard_True,U2,V2);
2182 if(LConjugated == 0)
2183 VrtL.SetValue(Standard_False,Uv,Vv);
2185 VrtL.SetValue(Standard_False,Ucv,Vv);
2188 Standard_Real U2 = 0., V2 = 0.;
2189 aV.ParametersOnS2(U2,V2); // S2 - prm
2190 VrtL.SetValue(Standard_False,U2,V2);
2191 if(LConjugated == 0)
2192 VrtL.SetValue(Standard_True,Uv,Vv);
2194 VrtL.SetValue(Standard_True,Ucv,Vv);
2196 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2197 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2198 AddLast = Standard_True;
2203 // to do: analyze internal vertex
2209 static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
2210 const IntSurf_PntOn2S& VrtF,
2211 const Standard_Boolean AddFirst,
2212 const IntSurf_PntOn2S& VrtL,
2213 const Standard_Boolean AddLast,
2214 const Standard_Real D3DF,
2215 const Standard_Real D3DL)
2217 Standard_Boolean result = Standard_False;
2219 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2220 if((D3DF*2.) > DF && DF > 1.5e-7) {
2221 Line->InsertBefore(1,VrtF);
2222 result = Standard_True;
2226 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2227 if((D3DL*2.) > DL && DL > 1.5e-7) {
2229 result = Standard_True;
2236 static void PutIntVertices(Handle(IntPatch_Line)& Line,
2237 Handle(IntSurf_LineOn2S)& Result,
2238 Standard_Boolean ,//IsReversed,
2239 Handle(IntSurf_LineOn2S)& Vertices,
2240 const Standard_Real ArcTol)
2242 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2247 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2248 Standard_Integer ip = 0, iv = 0;
2250 IntPatch_Point thePnt;
2251 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2253 for(ip = 2; ip <= (nbp-1); ip++) {
2254 const IntSurf_PntOn2S& aP = Result->Value(ip);
2255 for(iv = 1; iv <= nbv; iv++) {
2256 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2257 if(AreSamePoints(aP,aV)) {
2258 aPnt = Result->Value(ip).Value();
2259 Result->Value(ip).ParametersOnS1(U1,V1);
2260 Result->Value(ip).ParametersOnS2(U2,V2);
2261 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2262 thePnt.SetParameters(U1,V1,U2,V2);
2263 thePnt.SetParameter((Standard_Real)ip);
2264 WLine->AddVertex(thePnt);
2270 static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2271 Handle(IntSurf_LineOn2S)& Vertices)
2273 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2274 Standard_Integer ip = 0, iv = 0;
2275 Standard_Boolean result = Standard_False;
2280 for(ip = 2; ip <= (nbp-1); ip++) {
2281 const IntSurf_PntOn2S& aP = Line->Value(ip);
2282 for(iv = 1; iv <= nbv; iv++) {
2283 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2284 if(AreSamePoints(aP,aV)) {
2285 result = Standard_True;
2295 static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
2296 Standard_Boolean Tang,
2297 IntSurf_TypeTrans Trans1,
2298 IntSurf_TypeTrans Trans2,
2299 Standard_Real ArcTol,
2300 Standard_Integer ParFirst,
2301 Standard_Integer ParLast)
2303 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2304 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2306 Standard_Integer ip = 0;
2307 for(ip = ParFirst; ip <= ParLast; ip++)
2308 sline->Add(SLine->Value(ip));
2310 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2313 IntPatch_Point TPntF,TPntL;
2314 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2316 aSPnt = sline->Value(1).Value();
2317 sline->Value(1).ParametersOnS1(uu1,vv1);
2318 sline->Value(1).ParametersOnS2(uu2,vv2);
2319 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2320 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2321 TPntF.SetParameter(1.);
2322 wline->AddVertex(TPntF);
2323 wline->SetFirstPoint(1);
2325 aSPnt = sline->Value(sline->NbPoints()).Value();
2326 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2327 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2328 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2329 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2330 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2331 wline->AddVertex(TPntL);
2332 wline->SetLastPoint(sline->NbPoints());
2337 static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
2338 Standard_Boolean Tang,
2339 IntSurf_TypeTrans Trans1,
2340 IntSurf_TypeTrans Trans2,
2341 Standard_Real ArcTol,
2342 IntPatch_SequenceOfLine& Segments)
2344 Standard_Boolean result = Standard_False;
2347 Standard_Integer nbv = WLine->NbVertex();
2349 Standard_Integer iv = 0;
2350 for(iv = 1; iv < nbv; iv++) {
2351 Standard_Integer firstPar =
2352 (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2353 Standard_Integer lastPar =
2354 (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
2355 if((lastPar - firstPar) <= 1)
2358 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,
2359 ArcTol,firstPar,lastPar);
2360 Segments.Append(splitwline);
2362 result = Standard_True;
2369 static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& theLine,
2370 const Standard_Boolean IsReversed,
2371 const IntSurf_Quadric& theQuad,
2372 const Handle(Adaptor3d_TopolTool)& thePDomain,
2373 const Handle(Adaptor3d_HSurface)& theQSurf,
2374 const Standard_Real theArcTol,
2375 IntPatch_SequenceOfLine& theLines)
2377 // Split <theLine> in the places where it passes through seam edge or singularity
2378 // (apex of cone or pole of sphere). This passage is detected by jump of U-parameter
2379 // from point to point.
2381 const Standard_Real aDeltaUmax = 0.5*M_PI;
2382 const Standard_Real aTOL3D = 1.e-10,
2383 aTOL2D = Precision::PConfusion(),
2384 aTOL2DS = Precision::PConfusion();
2386 if( theLine->ArcType() != IntPatch_Walking )
2388 return Standard_False;
2391 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&theLine));
2392 const Handle(IntSurf_LineOn2S)& aSLine = aWLine->Curve();
2394 if(aSLine->NbPoints() <= 2)
2396 return Standard_False;
2399 //Deletes repeated vertices
2400 Handle(IntSurf_LineOn2S) aVLine = GetVertices(aWLine,aTOL3D,aTOL2D);
2402 Handle(IntSurf_LineOn2S) aSSLine(aSLine);
2404 if(aSSLine->NbPoints() <= 1)
2405 return Standard_False;
2407 AdjustLine(aSSLine,IsReversed,theQSurf,aTOL2D);
2410 Standard_Boolean isInserted = Standard_True;
2413 const Standard_Integer aNbPnts = aSSLine->NbPoints();
2414 TColStd_Array1OfInteger aPTypes(1,aNbPnts);
2415 SearchVertices(aSSLine,aVLine,aPTypes);
2416 isInserted = InsertSeamVertices(aSSLine,IsReversed,aVLine,aPTypes,aTOL2D);
2420 const Standard_Integer aLindex = aSSLine->NbPoints();
2421 Standard_Integer aFindex = 1, aBindex = 0;
2423 IntPatch_Point aTPntF, aTPntL;
2425 // build WLine parts (if any)
2426 Standard_Boolean flNextLine = Standard_True;
2427 Standard_Boolean hasBeenDecomposed = Standard_False;
2428 Standard_Boolean PrePointExist = Standard_False;
2429 IntSurf_PntOn2S PrePoint;
2433 flNextLine = Standard_False;
2434 Standard_Boolean isDecomposited = Standard_False;
2435 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0.;
2437 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2439 //if((Lindex-Findex+1) <= 2 )
2440 if(aLindex <= aFindex)
2441 return hasBeenDecomposed;
2445 sline->Add(PrePoint);
2446 PrePointExist = Standard_False;
2449 // analyze other points
2450 for(Standard_Integer k = aFindex; k <= aLindex; k++)
2456 aSSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2460 aSSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2463 sline->Add(aSSLine->Value(k));
2464 PrePoint = aSSLine->Value(k);
2470 aSSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2474 aSSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2477 if(Abs(U1-AnU1) > aDeltaUmax)
2480 isDecomposited = Standard_True;
2482 if (Abs(U1) <= Precision::PConfusion() ||
2483 Abs(U1 - 2*M_PI) <= Precision::PConfusion())
2485 IntSurf_PntOn2S NewPoint;
2486 IntSurf_PntOn2S CurPoint = aSSLine->Value(k);
2487 gp_Pnt thePnt = CurPoint.Value();
2488 Standard_Real theU1, theV1, theU2, theV2;
2489 theU1 = (Abs(U1) <= Precision::PConfusion())? 2*M_PI : 0.;
2491 NewPoint.SetValue(thePnt);
2494 CurPoint.ParametersOnS2(theU2, theV2);
2495 NewPoint.SetValue(theU1, theV1, theU2, theV2);
2499 CurPoint.ParametersOnS1(theU2, theV2);
2500 NewPoint.SetValue(theU2, theV2, theU1, theV1);
2502 sline->Add(NewPoint);
2504 else if (Abs(AnU1) <= Precision::PConfusion() ||
2505 Abs(AnU1 - 2*M_PI) <= Precision::PConfusion())
2508 PrePointExist = Standard_True;
2509 Standard_Real theU1, theV1;
2512 PrePoint.ParametersOnS1(theU1, theV1);
2513 theU1 = (Abs(AnU1) <= Precision::PConfusion())? 2*M_PI : 0.;
2514 PrePoint.SetValue(Standard_True, //on first
2519 PrePoint.ParametersOnS2(theU1, theV1);
2520 theU1 = (Abs(AnU1) <= Precision::PConfusion())? 2*M_PI : 0.;
2521 PrePoint.SetValue(Standard_False, //on second
2529 sline->Add(aSSLine->Value(k));
2530 PrePoint = aSSLine->Value(k);
2534 IntSurf_PntOn2S aVF, aVL;
2535 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2536 VerifyVertices(sline,IsReversed,aVLine,aTOL2DS,theArcTol,
2537 thePDomain,aVF,addVF,aVL,addVL);
2539 Standard_Boolean hasInternals = HasInternals(sline,aVLine);
2541 Standard_Real D3F = 0., D3L = 0.;
2542 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2543 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2545 //if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2546 // D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2548 //if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2549 // D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->
2550 // Value(sline->NbPoints()-2).Value());
2555 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2558 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2559 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2565 ForcedPurgePoints(sline,IsReversed,theQuad);
2568 Handle(IntPatch_WLine) wline =
2569 new IntPatch_WLine(sline,Standard_False,
2570 theLine->TransitionOnS1(),theLine->TransitionOnS2());
2572 gp_Pnt aSPnt(sline->Value(1).Value());
2573 sline->Value(1).ParametersOnS1(U1,V1);
2574 sline->Value(1).ParametersOnS2(U2,V2);
2575 aTPntF.SetValue(aSPnt,theArcTol,Standard_False);
2576 aTPntF.SetParameters(U1,V1,U2,V2);
2577 aTPntF.SetParameter(1.);
2578 wline->AddVertex(aTPntF);
2579 wline->SetFirstPoint(1);
2583 PutIntVertices(wline,sline,IsReversed,aVLine,theArcTol);
2586 aSPnt = sline->Value(sline->NbPoints()).Value();
2587 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2588 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2589 aTPntL.SetValue(aSPnt,theArcTol,Standard_False);
2590 aTPntL.SetParameters(U1,V1,U2,V2);
2591 aTPntL.SetParameter(sline->NbPoints());
2592 wline->AddVertex(aTPntL);
2593 wline->SetLastPoint(sline->NbPoints());
2595 IntPatch_SequenceOfLine segm;
2596 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,
2597 theLine->TransitionOnS1(),theLine->TransitionOnS2(),theArcTol,segm);
2601 theLines.Append(wline);
2605 Standard_Integer nbsegms = segm.Length();
2606 Standard_Integer iseg = 0;
2607 for(iseg = 1; iseg <= nbsegms; iseg++)
2608 theLines.Append(segm(iseg));
2614 flNextLine = hasBeenDecomposed = Standard_True;
2618 return hasBeenDecomposed;
2621 static Standard_Boolean IsIn2DBox(const Bnd_Box2d& theBox,
2622 const Handle(IntPatch_PointLine)& theLine,
2623 const Standard_Real theUPeriod,
2624 const Standard_Real theVPeriod,
2625 const Standard_Boolean isTheSurface1Using)
2627 const Standard_Integer aNbPnts = theLine->NbPnts();
2629 const Standard_Real aDeltaUPeriod[] = {0.0, -theUPeriod, 2.0*theUPeriod};
2630 const Standard_Real aDeltaVPeriod[] = {0.0, -theVPeriod, 2.0*theVPeriod};
2632 const Standard_Integer aSzOfUPArr = sizeof(aDeltaUPeriod)/sizeof(aDeltaUPeriod[0]);
2633 const Standard_Integer aSzOfVPArr = sizeof(aDeltaVPeriod)/sizeof(aDeltaVPeriod[0]);
2635 for(Standard_Integer aPtID = 1; aPtID <= aNbPnts; aPtID++)
2637 Standard_Real aU = 0.0, aV = 0.0;
2638 if(isTheSurface1Using)
2639 theLine->Point(aPtID).ParametersOnS1(aU, aV);
2641 theLine->Point(aPtID).ParametersOnS2(aU, aV);
2643 if(!theBox.IsOut(gp_Pnt2d(aU, aV)))
2646 Standard_Boolean isInscribe = Standard_False;
2648 for(Standard_Integer aUind = 0; !isInscribe && (aUind < aSzOfUPArr); aUind++)
2650 if((aUind > 0) && (aDeltaUPeriod[aUind] == 0.0))
2655 aU += aDeltaUPeriod[aUind];
2657 for(Standard_Integer aVind = 0; !isInscribe && (aVind < aSzOfVPArr); aVind++)
2659 if((aVind > 0) && (aDeltaVPeriod[aVind] == 0.0))
2664 aV += aDeltaVPeriod[aVind];
2666 isInscribe = !theBox.IsOut(gp_Pnt2d(aU, aV));
2671 return Standard_False;
2673 return Standard_True;