1 // File: IntPatch_ImpPrmIntersection.cxx
2 // Created: Thu May 7 08:47:45 1992
3 // Author: Jacques GOUSSARD
4 // Copyright: Matra Datavision 1992
6 #include <IntPatch_ImpPrmIntersection.ixx>
8 #include <Standard_ConstructionError.hxx>
9 #include <IntPatch_SequenceOfLine.hxx>
10 #include <TColStd_Array1OfInteger.hxx>
11 #include <IntSurf_PntOn2S.hxx>
12 #include <IntSurf_LineOn2S.hxx>
13 #include <IntSurf.hxx>
15 #include <Adaptor2d_HCurve2d.hxx>
16 #include <IntSurf_PathPoint.hxx>
17 #include <IntSurf_SequenceOfPathPoint.hxx>
18 #include <IntPatch_TheIWalking.hxx>
19 #include <IntPatch_TheIWLineOfTheIWalking.hxx>
20 #include <IntPatch_ThePathPointOfTheSOnBounds.hxx>
21 #include <IntPatch_TheSegmentOfTheSOnBounds.hxx>
22 #include <IntPatch_TheSurfFunction.hxx>
23 #include <IntPatch_RLine.hxx>
24 #include <IntPatch_WLine.hxx>
25 #include <IntPatch_ArcFunction.hxx>
26 #include <IntPatch_RstInt.hxx>
28 //=======================================================================
29 //function : IntPatch_ImpPrmIntersection
31 //=======================================================================
33 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
34 : done(Standard_False),
36 myIsStartPnt(Standard_False),
42 //=======================================================================
43 //function : IntPatch_ImpPrmIntersection
45 //=======================================================================
47 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection
48 (const Handle(Adaptor3d_HSurface)& Surf1,
49 const Handle(Adaptor3d_TopolTool)& D1,
50 const Handle(Adaptor3d_HSurface)& Surf2,
51 const Handle(Adaptor3d_TopolTool)& D2,
52 const Standard_Real TolArc,
53 const Standard_Real TolTang,
54 const Standard_Real Fleche,
55 const Standard_Real Pas)
56 : done(Standard_False),
58 myIsStartPnt(Standard_False),
62 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
66 //=======================================================================
67 //function : SetStartPoint
69 //=======================================================================
71 void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
72 const Standard_Real V)
74 myIsStartPnt = Standard_True;
75 myUStart = U; myVStart = V;
79 #define No_Standard_RangeError
80 #define No_Standard_OutOfRange
84 #include <math_Vector.hxx>
85 #include <math_Matrix.hxx>
86 #include <TopTrans_CurveTransition.hxx>
87 #include <TopAbs_State.hxx>
88 #include <TopAbs_Orientation.hxx>
89 #include <TColStd_Array1OfInteger.hxx>
90 #include <TColStd_Array1OfReal.hxx>
92 #include <IntSurf_SequenceOfInteriorPoint.hxx>
93 #include <IntSurf_QuadricTool.hxx>
94 #include <GeomAbs_SurfaceType.hxx>
97 static void DecomposeResult(Handle(IntPatch_Line)& Line,
98 Standard_Boolean IsReversed,
99 IntSurf_Quadric& Quad,
100 Handle(Adaptor3d_TopolTool)& PDomain,
101 Handle(Adaptor3d_HSurface)& QSurf,
102 Standard_Real TolArc,
103 IntPatch_SequenceOfLine& Lines);
105 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
106 IntSurf_SequenceOfPathPoint& seqpdep,
107 const Handle(Adaptor3d_TopolTool)& Domain,
108 IntPatch_TheSurfFunction& Func,
109 const Handle(Adaptor3d_HSurface)& PSurf,
110 TColStd_Array1OfInteger& Destination);
112 void Recadre(const Standard_Boolean ,
113 GeomAbs_SurfaceType typeS1,
114 GeomAbs_SurfaceType typeS2,
116 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
117 Standard_Integer Param,
123 //=======================================================================
124 //function : ComputeTangency
126 //=======================================================================
127 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
128 IntSurf_SequenceOfPathPoint& seqpdep,
129 const Handle(Adaptor3d_TopolTool)& Domain,
130 IntPatch_TheSurfFunction& Func,
131 const Handle(Adaptor3d_HSurface)& PSurf,
132 TColStd_Array1OfInteger& Destination)
134 Standard_Integer i,k, NbPoints, seqlength;
135 Standard_Real theparam,test;
136 Standard_Boolean fairpt, ispassing;
137 TopAbs_Orientation arcorien,vtxorien;
138 Handle(Adaptor2d_HCurve2d) thearc;
139 Handle(Adaptor3d_HVertex) vtx,vtxbis;
140 //Standard_Boolean ispassing;
141 IntPatch_ThePathPointOfTheSOnBounds PStart;
142 IntSurf_PathPoint PPoint;
146 gp_Vec d1u,d1v,v1,v2;
150 static math_Vector X(1, 2);
151 static math_Vector F(1, 1);
152 static math_Matrix D(1, 1, 1, 2);
155 NbPoints = solrst.NbPoints();
156 for (i=1; i<= NbPoints; i++) {
157 if (Destination(i) == 0) {
158 PStart = solrst.Point(i);
159 thearc = PStart.Arc();
160 theparam = PStart.Parameter();
161 arcorien = Domain->Orientation(thearc);
162 ispassing = (arcorien == TopAbs_INTERNAL ||
163 arcorien == TopAbs_EXTERNAL);
165 thearc->D0(theparam,p2d);
168 PPoint.SetValue(PStart.Value(),X(1),X(2));
171 if (Func.IsTangent()) {
172 PPoint.SetTangency(Standard_True);
173 Destination(i) = seqlength+1;
174 if (!PStart.IsNew()) {
175 vtx = PStart.Vertex();
176 for (k=i+1; k<=NbPoints; k++) {
177 if (Destination(k) ==0) {
178 PStart = solrst.Point(k);
179 if (!PStart.IsNew()) {
180 vtxbis = PStart.Vertex();
181 if (Domain->Identical(vtx,vtxbis)) {
182 thearc = PStart.Arc();
183 theparam = PStart.Parameter();
184 arcorien = Domain->Orientation(thearc);
185 ispassing = ispassing && (arcorien == TopAbs_INTERNAL ||
186 arcorien == TopAbs_EXTERNAL);
188 thearc->D0(theparam,p2d);
189 PPoint.AddUV(p2d.X(),p2d.Y());
190 Destination(k) = seqlength+1;
196 PPoint.SetPassing(ispassing);
197 seqpdep.Append(PPoint);
200 else { // on a un point de depart potentiel
202 vectg = Func.Direction3d();
203 dirtg = Func.Direction2d();
205 PSurf->D1(X(1),X(2),ptbid,d1u,d1v);
206 thearc->D1(theparam,p2d,d2d);
207 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
208 v1 = d1u.Crossed(d1v);
210 test = vectg.Dot(v1.Crossed(v2));
211 if (PStart.IsNew()) {
212 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
213 (test > 0. && arcorien == TopAbs_REVERSED)) {
217 PPoint.SetDirections(vectg,dirtg);
218 PPoint.SetPassing(ispassing);
219 Destination(i) = seqlength+1;
220 seqpdep.Append(PPoint);
223 else { // traiter la transition complexe
224 gp_Dir bidnorm(1.,1.,1.);
225 Standard_Real tole = 1.e-8;
226 TopAbs_Orientation LocTrans;
227 TopTrans_CurveTransition comptrans;
228 comptrans.Reset(vectg,bidnorm,0.);
229 if (arcorien == TopAbs_FORWARD ||
230 arcorien == TopAbs_REVERSED) {
233 vtx = PStart.Vertex();
234 vtxorien = Domain->Orientation(vtx);
235 if (Abs(test) <= tole) {
236 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
239 if ((test > 0.)&& arcorien == TopAbs_FORWARD ||
240 (test < 0.)&& arcorien == TopAbs_REVERSED){
241 LocTrans = TopAbs_FORWARD;
244 LocTrans = TopAbs_REVERSED;
246 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
249 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
251 Destination(i) = seqlength+1;
252 for (k= i+1; k<=NbPoints; k++) {
253 if (Destination(k) == 0) {
254 PStart = solrst.Point(k);
255 if (!PStart.IsNew()) {
256 vtxbis = PStart.Vertex();
257 if (Domain->Identical(vtx,vtxbis)) {
258 thearc = PStart.Arc();
259 theparam = PStart.Parameter();
260 arcorien = Domain->Orientation(thearc);
262 PPoint.AddUV(X(1),X(2));
264 thearc->D1(theparam,p2d,d2d);
265 PPoint.AddUV(p2d.X(),p2d.Y());
267 if (arcorien == TopAbs_FORWARD ||
268 arcorien == TopAbs_REVERSED) {
269 ispassing = Standard_False;
270 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
272 test = vectg.Dot(v1.Crossed(v2));
273 vtxorien = Domain->Orientation(PStart.Vertex());
274 if (Abs(test) <= tole) {
275 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
278 if ((test > 0.)&& arcorien == TopAbs_FORWARD ||
279 (test < 0.)&& arcorien == TopAbs_REVERSED){
280 LocTrans = TopAbs_FORWARD;
283 LocTrans = TopAbs_REVERSED;
285 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
288 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
290 Destination(k) = seqlength+1;
295 fairpt = Standard_True;
297 TopAbs_State Before = comptrans.StateBefore();
298 TopAbs_State After = comptrans.StateAfter();
299 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
300 fairpt = Standard_False;
302 else if (Before == TopAbs_IN) {
303 if (After == TopAbs_IN) {
304 ispassing = Standard_True;
312 if (After !=TopAbs_IN) {
313 fairpt = Standard_False;
318 PPoint.SetDirections(vectg,dirtg);
319 PPoint.SetPassing(ispassing);
320 seqpdep.Append(PPoint);
323 else { // il faut remettre en "ordre" si on ne garde pas le point.
324 for (k=i; k <=NbPoints ; k++) {
325 if (Destination(k)==seqlength + 1) {
326 Destination(k) = -Destination(k);
335 //=======================================================================
338 //=======================================================================
339 void Recadre(const Standard_Boolean ,
340 GeomAbs_SurfaceType typeS1,
341 GeomAbs_SurfaceType typeS2,
343 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
344 Standard_Integer Param,
350 Standard_Real U1p,V1p,U2p,V2p;
351 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
355 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
356 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
357 case GeomAbs_Cylinder:
360 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
361 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
366 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
367 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
368 case GeomAbs_Cylinder:
371 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
372 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
374 pt.SetParameters(U1,V1,U2,V2);
377 //=======================================================================
380 //=======================================================================
381 void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
382 const Handle(Adaptor3d_TopolTool)& D1,
383 const Handle(Adaptor3d_HSurface)& Surf2,
384 const Handle(Adaptor3d_TopolTool)& D2,
385 const Standard_Real TolArc,
386 const Standard_Real TolTang,
387 const Standard_Real Fleche,
388 const Standard_Real Pas)
390 Standard_Boolean reversed, procf, procl, dofirst, dolast;
391 Standard_Integer indfirst, indlast, ind2, i,j,k, NbSegm;
392 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
393 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
395 IntPatch_TheSegmentOfTheSOnBounds thesegm;
396 IntSurf_PathPoint PPoint;
398 Handle(IntPatch_RLine) rline;
399 Handle(IntPatch_WLine) wline;
400 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
401 IntPatch_Point ptdeb,ptfin,ptbis;
404 IntSurf_Transition TLine,TArc;
405 IntSurf_TypeTrans trans1,trans2;
407 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
414 Handle(Adaptor2d_HCurve2d) currentarc;
415 GeomAbs_SurfaceType typeS1, typeS2;
416 IntSurf_Quadric Quad;
417 IntPatch_TheSurfFunction Func;
418 IntPatch_ArcFunction AFunc;
420 typeS1 = Surf1->GetType();
421 typeS2 = Surf2->GetType();
425 trans1 = IntSurf_Undecided;
426 trans2 = IntSurf_Undecided;
428 done = Standard_False;
429 empt = Standard_True;
433 reversed = Standard_False;
436 Quad.SetValue(Surf1->Plane());
439 case GeomAbs_Cylinder:
440 Quad.SetValue(Surf1->Cylinder());
444 Quad.SetValue(Surf1->Sphere());
448 Quad.SetValue(Surf1->Cone());
452 reversed = Standard_True;
455 Quad.SetValue(Surf2->Plane());
458 case GeomAbs_Cylinder:
459 Quad.SetValue(Surf2->Cylinder());
463 Quad.SetValue(Surf2->Sphere());
467 Quad.SetValue(Surf2->Cone());
470 Standard_ConstructionError::Raise();
478 Func.SetImplicitSurface(Quad);
479 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
480 AFunc.SetQuadric(Quad);
492 solrst.Perform(AFunc,D2,TolArc,TolTang);
495 solrst.Perform(AFunc,D1,TolArc,TolTang);
497 if (!solrst.IsDone()) {
501 IntSurf_SequenceOfPathPoint seqpdep;
502 IntSurf_SequenceOfInteriorPoint seqpins;
504 NbPointRst = solrst.NbPoints();
505 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
508 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
511 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
515 // Recherche des points interieurs
518 solins.Perform(Func,Surf2,myUStart,myVStart);
520 solins.Perform(Func,Surf2,D2,TolTang);
524 solins.Perform(Func,Surf1,myUStart,myVStart);
526 solins.Perform(Func,Surf1,D1,TolTang);
529 NbPointIns = solins.NbPoints();
530 for (i=1; i <= NbPointIns; i++) {
531 seqpins.Append(solins.Value(i));
533 NbPointDep=seqpdep.Length();
535 if (NbPointDep || NbPointIns) {
536 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
538 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
541 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
543 if(!iwalk.IsDone()) {
547 Standard_Real Vmin, Vmax, TolV = 1.e-14;
548 if (!reversed) { //Surf1 is quadric
549 Vmin = Surf1->FirstVParameter();
550 Vmax = Surf1->LastVParameter();
552 else { //Surf2 is quadric
553 Vmin = Surf2->FirstVParameter();
554 Vmax = Surf2->LastVParameter();
557 Nblines = iwalk.NbLines();
558 for (j=1; j<=Nblines; j++) {
559 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
560 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
562 Nbpts = thelin->NbPoints();
565 tgline = iwline->TangentVector(k);
566 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
567 valpt = thelin->Value(k).Value();
570 thelin->Value(k).ParametersOnS2(U2,V2);
571 norm1 = Quad.Normale(valpt);
572 Surf2->D1(U2,V2,ptbid,d1u,d1v);
573 norm2 = d1u.Crossed(d1v);
576 thelin->Value(k).ParametersOnS1(U2,V2);
577 norm2 = Quad.Normale(valpt);
578 Surf1->D1(U2,V2,ptbid,d1u,d1v);
579 norm1 = d1u.Crossed(d1v);
581 if (tgline.DotCross(norm2,norm1) > 0.) {
582 trans1 = IntSurf_Out;
587 trans2 = IntSurf_Out;
591 Standard_Real AnU1,AnU2,AnV2;
593 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
594 Standard_Boolean arecadr=Standard_False;
595 valpt = thelin->Value(1).Value();
596 Quad.Parameters(valpt,AnU1,V1);
598 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
599 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
602 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
603 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
606 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
607 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
610 if(typQuad==GeomAbs_Cylinder ||
611 typQuad==GeomAbs_Cone ||
612 typQuad==GeomAbs_Sphere) {
613 arecadr=Standard_True;
616 for (k=2; k<=Nbpts; ++k) {
617 valpt = thelin->Value(k).Value();
618 Quad.Parameters(valpt,U1,V1);
620 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
623 if((V1 > Vmax) && (V1-Vmax < TolV)) {
628 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
629 Standard_Real aCf, aTwoPI;
633 if ((U1-AnU1) > 1.5*M_PI) {
634 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
641 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
647 //if ((U1-AnU1) > 1.5*M_PI) {
650 //else if ((U1-AnU1) < -1.5*M_PI) {
653 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
657 thelin->SetUV(k,Standard_False,U1,V1);
659 thelin->Value(k).ParametersOnS1(U2,V2);
661 case GeomAbs_Cylinder:
665 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
666 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
671 if(typeS2==GeomAbs_Torus) {
672 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
673 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
675 thelin->SetUV(k,Standard_True,U2,V2);
678 thelin->SetUV(k,Standard_True,U1,V1);
680 thelin->Value(k).ParametersOnS2(U2,V2);
682 case GeomAbs_Cylinder:
686 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
687 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
692 if(typeS2==GeomAbs_Torus) {
693 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
694 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
696 thelin->SetUV(k,Standard_False,U2,V2);
705 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
707 if ( iwline->HasFirstPoint()
708 && iwline->IsTangentAtBegining() == Standard_False) {
709 indfirst = iwline->FirstPointIndex();
710 PPoint = seqpdep(indfirst);
711 tgline = PPoint.Direction3d();
712 Standard_Integer themult = PPoint.Multiplicity();
713 for (i=NbPointRst; i>=1; i--) {
714 if (Destination(i) == indfirst) {
715 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
716 Quad.Parameters(PPoint.Value(),U1,V1);
718 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
719 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
721 PPoint.Parameters(themult,U2,V2);
722 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
724 else { //-- typeS1 != Pln && Cyl && Sph && Cone
725 Quad.Parameters(PPoint.Value(),U2,V2);
727 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
728 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
730 PPoint.Parameters(themult,U1,V1);
731 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
734 VecNormale = d1u.Crossed(d1v);
735 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
736 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
737 ptdeb.SetParameters(U1,V1,U2,V2);
738 ptdeb.SetParameter(1.);
740 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
742 currentarc = solrst.Point(i).Arc();
743 currentparam = solrst.Point(i).Parameter();
744 currentarc->D1(currentparam,p2d,d2d);
745 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
747 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
748 if(squaremagnitudeVecNormale > 1e-13) {
749 DirNormale=VecNormale;
750 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
753 TLine.SetValue(Standard_True,IntSurf_Undecided);
754 TArc.SetValue(Standard_True,IntSurf_Undecided);
757 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
758 if (!solrst.Point(i).IsNew()) {
759 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
761 wline->AddVertex(ptdeb);
763 wline->SetFirstPoint(wline->NbVertex());
770 else if (iwline->IsTangentAtBegining()) {
771 gp_Pnt psol = thelin->Value(1).Value();
772 thelin->Value(1).ParametersOnS1(U1,V1);
773 thelin->Value(1).ParametersOnS2(U2,V2);
774 ptdeb.SetValue(psol,TolArc,Standard_True);
775 ptdeb.SetParameters(U1,V1,U2,V2);
776 ptdeb.SetParameter(1.);
777 wline->AddVertex(ptdeb);
778 wline->SetFirstPoint(wline->NbVertex());
781 gp_Pnt psol = thelin->Value(1).Value();
782 thelin->Value(1).ParametersOnS1(U1,V1);
783 thelin->Value(1).ParametersOnS2(U2,V2);
784 ptdeb.SetValue(psol,TolArc,Standard_False);
785 ptdeb.SetParameters(U1,V1,U2,V2);
786 ptdeb.SetParameter(1.);
787 wline->AddVertex(ptdeb);
788 wline->SetFirstPoint(wline->NbVertex());
792 if ( iwline->HasLastPoint()
793 && iwline->IsTangentAtEnd() == Standard_False) {
794 indlast = iwline->LastPointIndex();
795 PPoint = seqpdep(indlast);
796 tgline = PPoint.Direction3d().Reversed();
797 Standard_Integer themult = PPoint.Multiplicity();
798 for (i=NbPointRst; i >=1; i--) {
799 if (Destination(i) == indlast) {
801 Quad.Parameters(PPoint.Value(),U1,V1);
803 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
804 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
806 PPoint.Parameters(themult,U2,V2);
807 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
808 VecNormale = d1u.Crossed(d1v); //-- @@@@
811 Quad.Parameters(PPoint.Value(),U2,V2);
813 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
814 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
816 PPoint.Parameters(themult,U1,V1);
817 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
818 VecNormale = d1u.Crossed(d1v); //-- @@@@
821 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
822 ptfin.SetParameters(U1,V1,U2,V2);
823 ptfin.SetParameter(Nbpts);
825 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
827 currentarc = solrst.Point(i).Arc();
828 currentparam = solrst.Point(i).Parameter();
829 currentarc->D1(currentparam,p2d,d2d);
830 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
833 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
834 if(squaremagnitudeVecNormale > 1e-13) {
835 DirNormale=VecNormale;
836 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
839 TLine.SetValue(Standard_True,IntSurf_Undecided);
840 TArc.SetValue(Standard_True,IntSurf_Undecided);
844 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
845 if (!solrst.Point(i).IsNew()) {
846 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
848 wline->AddVertex(ptfin);
850 wline->SetLastPoint(wline->NbVertex());
857 else if (iwline->IsTangentAtEnd()) {
858 gp_Pnt psol = thelin->Value(Nbpts).Value();
859 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
860 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
861 ptfin.SetValue(psol,TolArc,Standard_True);
862 ptfin.SetParameters(U1,V1,U2,V2);
863 ptfin.SetParameter(Nbpts);
864 wline->AddVertex(ptfin);
865 wline->SetLastPoint(wline->NbVertex());
868 gp_Pnt psol = thelin->Value(Nbpts).Value();
869 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
870 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
871 ptfin.SetValue(psol,TolArc,Standard_False);
872 ptfin.SetParameters(U1,V1,U2,V2);
873 ptfin.SetParameter(Nbpts);
874 wline->AddVertex(ptfin);
875 wline->SetLastPoint(wline->NbVertex());
878 // Il faut traiter les points de passage.
881 }// for (j=1; j<=Nblines; j++) {
883 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
884 // QUE SUR DES POINTS DE TANGENCE
887 Nblines = slin.Length();
888 for (j=1; j<=Nblines-1; j++) {
889 dofirst = dolast = Standard_False;
890 const Handle(IntPatch_Line)& slinj = slin(j);
891 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
892 if (wlin1->HasFirstPoint()) {
893 ptdeb = wlin1->FirstPoint(indfirst);
894 if (ptdeb.IsTangencyPoint()) {
895 dofirst = Standard_True;
898 if (wlin1->HasLastPoint()) {
899 ptfin = wlin1->LastPoint(indlast);
900 if (ptfin.IsTangencyPoint()) {
901 dolast = Standard_True;
905 if (dofirst || dolast) {
906 for (k=j+1; k<=Nblines;k++) {
907 const Handle(IntPatch_Line)& slink = slin(k);
908 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
909 if (wlin2->HasFirstPoint()) {
910 ptbis = wlin2->FirstPoint(ind2);
911 if (ptbis.IsTangencyPoint()) {
913 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
914 ptdeb.SetMultiple(Standard_True);
915 if (!ptbis.IsMultiple()) {
916 ptbis.SetMultiple(Standard_True);
917 wlin2->Replace(ind2,ptbis);
922 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
923 ptfin.SetMultiple(Standard_True);
924 if (!ptbis.IsMultiple()) {
925 ptbis.SetMultiple(Standard_True);
926 wlin2->Replace(ind2,ptbis);
932 if (wlin2->HasLastPoint()) {
933 ptbis = wlin2->LastPoint(ind2);
934 if (ptbis.IsTangencyPoint()) {
936 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
937 ptdeb.SetMultiple(Standard_True);
938 if (!ptbis.IsMultiple()) {
939 ptbis.SetMultiple(Standard_True);
940 wlin2->Replace(ind2,ptbis);
945 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
946 ptfin.SetMultiple(Standard_True);
947 if (!ptbis.IsMultiple()) {
948 ptbis.SetMultiple(Standard_True);
949 wlin2->Replace(ind2,ptbis);
957 wlin1->Replace(indfirst,ptdeb);
959 wlin1->Replace(indlast,ptfin);
962 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
964 // Treatment the segments
965 NbSegm = solrst.NbSegments();
967 for(i=1; i<=NbSegm; i++) {
968 thesegm = solrst.Segment(i);
969 //----------------------------------------------------------------------
970 // on cree une ligne d intersection contenant uniquement le segment.
971 // VOIR POUR LA TRANSITION DE LA LIGNE
972 // On ajoute aussi un polygone pour le traitement des intersections
973 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
974 //----------------------------------------------------------------------
975 //-- Calcul de la transition sur la rline (12 fev 97)
976 //-- reversed a le sens de OnFirst
978 dofirst = dolast = Standard_False;
979 procf = Standard_False;
980 procl = Standard_False;
981 IntSurf_Transition TLineUnk,TArcUnk;
983 IntPatch_Point _thepointAtBeg;
984 IntPatch_Point _thepointAtEnd;
986 Standard_Boolean TransitionOK=Standard_False;
988 if(thesegm.HasFirstPoint()) {
989 Standard_Real _u1,_v1,_u2,_v2;
991 dofirst = Standard_True;
992 PStartf = thesegm.FirstPoint();
993 paramf = PStartf.Parameter();
995 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
996 Handle(Adaptor3d_HVertex) _vtx;
997 if(PStartf.IsNew()==Standard_False)
998 _vtx= PStartf.Vertex();
999 const gp_Pnt& _Pp = PStartf.Value();
1000 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1001 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1002 Quad.Parameters(_Pp,_u1,_v1);
1003 _u2=_p2d.X(); _v2=_p2d.Y();
1005 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1006 Quad.Parameters(_Pp,_u2,_v2);
1007 _u1=_p2d.X(); _v1=_p2d.Y();
1009 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1010 _thepointAtBeg.SetParameter(paramf);
1011 if(PStartf.IsNew()==Standard_False)
1012 _thepointAtBeg.SetVertex(reversed,_vtx);
1013 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1016 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1017 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1018 norm1 = d1u1.Crossed(d1v1);
1019 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1020 norm2 = d1u2.Crossed(d1v2);
1022 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1024 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1027 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1029 _u1=tgline.DotCross(norm2,norm1);
1030 TransitionOK=Standard_True;
1031 if (_u1 > 0.00000001) {
1032 trans1 = IntSurf_Out;
1033 trans2 = IntSurf_In;
1035 else if(_u1 < -0.00000001) {
1036 trans1 = IntSurf_In;
1037 trans2 = IntSurf_Out;
1040 TransitionOK=Standard_False;
1043 if(thesegm.HasLastPoint()) {
1044 Standard_Real _u1,_v1,_u2,_v2;
1046 dolast = Standard_True;
1047 PStartl = thesegm.LastPoint();
1048 paraml = PStartl.Parameter();
1050 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1051 Handle(Adaptor3d_HVertex) _vtx;
1052 if(PStartl.IsNew()==Standard_False)
1053 _vtx = PStartl.Vertex();
1054 const gp_Pnt& _Pp = PStartl.Value();
1055 IntPatch_Point _thepoint;
1056 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1057 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1058 Quad.Parameters(_Pp,_u1,_v1);
1059 _u2=_p2d.X(); _v2=_p2d.Y();
1061 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1062 Quad.Parameters(_Pp,_u2,_v2);
1063 _u1=_p2d.X(); _v1=_p2d.Y();
1065 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1066 _thepointAtEnd.SetParameter(paraml);
1067 if(PStartl.IsNew()==Standard_False)
1068 _thepointAtEnd.SetVertex(reversed,_vtx);
1069 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1073 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1074 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1075 norm1 = d1u1.Crossed(d1v1);
1076 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1077 norm2 = d1u2.Crossed(d1v2);
1079 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1081 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1084 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1086 _u1=tgline.DotCross(norm2,norm1);
1087 TransitionOK=Standard_True;
1088 if (_u1 > 0.00000001) {
1089 trans1 = IntSurf_Out;
1090 trans2 = IntSurf_In;
1092 else if(_u1 < -0.00000001) {
1093 trans1 = IntSurf_In;
1094 trans2 = IntSurf_Out;
1097 TransitionOK=Standard_False;
1100 if(TransitionOK==Standard_False) {
1101 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1102 rline = new IntPatch_RLine (Standard_False);
1104 rline->SetArcOnS1(thesegm.Curve());
1107 rline->SetArcOnS2(thesegm.Curve());
1111 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1112 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1114 rline->SetArcOnS1(thesegm.Curve());
1117 rline->SetArcOnS2(thesegm.Curve());
1121 //------------------------------
1122 //-- Ajout des points
1124 if (thesegm.HasFirstPoint()) {
1125 rline->AddVertex(_thepointAtBeg);
1126 rline->SetFirstPoint(rline->NbVertex());
1129 if (thesegm.HasLastPoint()) {
1130 rline->AddVertex(_thepointAtEnd);
1131 rline->SetLastPoint(rline->NbVertex());
1134 // Polygone sur restriction solution
1135 if (dofirst && dolast) {
1138 IntSurf_PntOn2S p2s;
1139 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1140 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1141 Standard_Integer nbsample = 100;
1144 for (j=1; j<=nbsample; j++) {
1145 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1146 arcsegm->D0(prm,p2d);
1147 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1149 Quad.Parameters(ptpoly,U1,V1);
1150 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1155 for (j=1; j<=nbsample; j++) {
1156 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1157 arcsegm->D0(prm,p2d);
1158 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1160 Quad.Parameters(ptpoly,U2,V2);
1161 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1168 if (dofirst || dolast) {
1169 Nblines = slin.Length();
1170 for (j=1; j<=Nblines; j++) {
1171 const Handle(IntPatch_Line)& slinj = slin(j);
1172 typ = slinj->ArcType();
1173 if (typ == IntPatch_Walking) {
1174 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1177 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1179 for (k=1; k<=Nbpts;k++) {
1180 if (typ == IntPatch_Walking) {
1181 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1184 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1188 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1189 ptdeb.SetMultiple(Standard_True);
1190 if (typ == IntPatch_Walking) {
1191 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1194 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1196 ptdeb.SetParameter(paramf);
1197 rline->AddVertex(ptdeb);
1199 procf=Standard_True;
1200 rline->SetFirstPoint(rline->NbVertex());
1205 if(dofirst) { //-- on recharge le ptdeb
1206 if (typ == IntPatch_Walking) {
1207 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1210 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1213 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1214 ptdeb.SetMultiple(Standard_True);
1215 if (typ == IntPatch_Walking) {
1216 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1219 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1221 ptdeb.SetParameter(paraml);
1222 rline->AddVertex(ptdeb);
1224 procl=Standard_True;
1225 rline->SetLastPoint(rline->NbVertex());
1236 // on traite les restrictions de la surface implicite
1237 for (i=1; i<=slin.Length(); i++)
1240 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1242 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1244 empt = (slin.Length() == 0 && spnt.Length() == 0);
1245 done = Standard_True;
1247 // post processing for cones and spheres
1248 if((Quad.TypeQuadric() == GeomAbs_Cone ||
1249 Quad.TypeQuadric() == GeomAbs_Sphere) &&
1252 Handle(Adaptor3d_TopolTool) PDomain = (reversed) ? D1 : D2;
1253 Handle(Adaptor3d_HSurface) QSurf = (reversed) ? Surf2 : Surf1;
1255 IntPatch_SequenceOfLine dslin;
1256 for(i = 1; i <= slin.Length(); i++ )
1257 DecomposeResult(slin(i),reversed,Quad,PDomain,QSurf,TolArc,dslin);
1260 for(i = 1; i <= dslin.Length(); i++ )
1261 slin.Append(dslin(i));
1265 //==================================================================
1266 // Decomposition of WLine goes through seam and/or apex routines
1267 //==================================================================
1269 // reject all points and vertices not in V range on Quadric
1270 static Handle(IntSurf_LineOn2S) VSplitLine(Handle(IntSurf_LineOn2S)& Line,
1271 Standard_Boolean IsReversed,
1272 Handle(Adaptor3d_HSurface)& QSurf,
1273 Handle(IntSurf_LineOn2S)& Vertices)
1275 Handle(IntSurf_LineOn2S) line = new IntSurf_LineOn2S();
1277 Standard_Real VF = QSurf->FirstVParameter();
1278 Standard_Real VL = QSurf->LastVParameter();
1280 Standard_Integer i = 0;
1281 Standard_Real U = 0., V = 0.;
1283 for(i = 1; i <= Line->NbPoints(); i++) {
1285 const IntSurf_PntOn2S& aP = Line->Value(i);
1287 aP.ParametersOnS2(U,V); // S2 - quadric
1289 aP.ParametersOnS1(U,V); // S1 - quadric
1291 if(VF <= V && V <= VL)
1295 Standard_Boolean isDeleted = Standard_True;
1296 Standard_Integer k = 0;
1299 isDeleted = Standard_False;
1302 for(i = 1; i <= Vertices->NbPoints(); i++) {
1304 const IntSurf_PntOn2S& aV = Vertices->Value(i);
1306 aV.ParametersOnS2(U,V); // S2 - quadric
1308 aV.ParametersOnS1(U,V); // S1 - quadric
1310 if(VF <= V && V <= VL)
1319 isDeleted = Standard_True;
1320 Vertices->RemovePoint(k);
1329 // correct U parameter of the start point of line on Quadric
1330 // (change 0->2PI or vs, if necessary)
1331 static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1333 Standard_Real u = U1;
1335 // case: no adjustment
1336 if( U1 > 0. && U1 < (2.*M_PI) )
1340 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
1341 if( U2 > 0. && U2 < (2.*M_PI) )
1342 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1344 Standard_Real uu = U2;
1345 if( U2 > (2.*M_PI) )
1346 while( uu > (2.*M_PI) )
1352 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1356 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1357 if( U2 > 0. && U2 < (2.*M_PI) )
1358 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1360 Standard_Real uu = U2;
1361 if( U2 > (2.*M_PI) )
1362 while( uu > (2.*M_PI) )
1368 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1371 // case: '<0. || >2PI'
1377 while(u > (2.*M_PI))
1384 // adjust U parameters on Quadric
1385 static Standard_Real AdjustUNext(Standard_Real Un,Standard_Real Up)
1387 Standard_Real u = Un;
1391 else if( Un > (2.*M_PI) )
1392 while( u > (2.*M_PI) )
1394 else if(Un == 0. || fabs(Un) <= 1.e-9)
1395 u = (fabs(Up) < fabs(2.*M_PI-Up)) ? 0. : (2.*M_PI);
1396 else if(Un == (2.*M_PI) || fabs(Un-(2.*M_PI)) <= 1.e-9)
1397 u = (fabs(Up) < fabs(2.*M_PI-Up)) ? 0. : (2.*M_PI);
1398 else //( Un > 0. && Un < (2.*M_PI) )
1403 // collect vertices, reject equals
1404 static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1405 const Standard_Boolean ,//IsReversed,
1406 const Standard_Real TOL3D,
1407 const Standard_Real TOL2D)
1409 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1411 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1413 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1414 Standard_Integer i = 0, k = 0;
1415 Standard_Integer NbVrt = WLine->NbVertex();
1417 TColStd_Array1OfInteger anVrts(1,NbVrt);
1420 // check equal vertices
1421 for(i = 1; i <= NbVrt; i++) {
1423 if( anVrts(i) == -1 ) continue;
1425 const IntPatch_Point& Pi = WLine->Vertex(i);
1427 for(k = (i+1); k <= NbVrt; k++) {
1429 if( anVrts(k) == -1 ) continue;
1431 const IntPatch_Point& Pk = WLine->Vertex(k);
1433 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
1434 // suggest the points are equal;
1435 // test 2d parameters on surface
1436 Standard_Boolean sameU1 = Standard_False;
1437 Standard_Boolean sameV1 = Standard_False;
1438 Standard_Boolean sameU2 = Standard_False;
1439 Standard_Boolean sameV2 = Standard_False;
1441 Pi.ParametersOnS1(U1,V1);
1442 Pk.ParametersOnS1(U2,V2);
1443 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1444 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1446 Pi.ParametersOnS2(U1,V1);
1447 Pk.ParametersOnS2(U2,V2);
1448 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1449 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1451 if((sameU1 && sameV1) && (sameU2 && sameV2))
1457 // copy further processed vertices
1458 for(i = 1; i <= NbVrt; i++) {
1459 if( anVrts(i) == -1 ) continue;
1460 vertices->Add(WLine->Vertex(i).PntOn2S());
1465 static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1466 const IntSurf_PntOn2S& P2)
1468 Standard_Boolean result = Standard_False;
1469 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1470 const gp_Pnt& P3D1 = P1.Value();
1471 const gp_Pnt& P3D2 = P2.Value();
1472 if(P3D1.Distance(P3D2) <= T3D) {
1473 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1474 P1.ParametersOnS1(U1,V1);
1475 P1.ParametersOnS2(U2,V2);
1476 P2.ParametersOnS1(U3,V3);
1477 P2.ParametersOnS2(U4,V4);
1478 gp_Pnt2d P2D11(U1,V1);
1479 gp_Pnt2d P2D12(U2,V2);
1480 gp_Pnt2d P2D21(U3,V3);
1481 gp_Pnt2d P2D22(U4,V4);
1482 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1483 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1484 if(sameS1 && sameS2)
1485 result = Standard_True;
1490 static void ForcedPurgePoints(Handle(IntSurf_LineOn2S)& Result,
1491 Standard_Boolean IsReversed,
1492 IntSurf_Quadric& Quad)
1494 if(Result->NbPoints() <= 30) return;
1495 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1497 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1498 Standard_Real Uapx = 0., Vapx = 0.;
1499 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1500 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1502 Result->Value(1).ParametersOnS2(U1,V1);
1503 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1506 Result->Value(1).ParametersOnS2(U1,V1);
1507 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1510 if(fabs(V1-Vapx) <= 1.e-3)
1512 if(fabs(V2-Vapx) <= 1.e-3)
1516 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
1517 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
1518 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1520 Result->Value(1).ParametersOnS2(U1,V1);
1521 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1524 Result->Value(1).ParametersOnS2(U1,V1);
1525 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1528 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1530 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1534 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1535 Result->RemovePoint(2);
1539 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1540 Result->RemovePoint(Result->NbPoints()-1);
1545 // DEBUG FUNCTION !!!
1547 static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1548 Standard_Boolean IsReversed,
1549 Standard_Integer Number)
1551 cout << "DUMP LINE" << endl;
1554 for(i = 1; i <= Line->NbPoints(); i++) {
1555 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1557 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1559 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1560 cout << "point p" << i << " " << U << " " << V << endl;
1566 // DEBUG FUNCTION !!!
1568 static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1569 const Handle(IntSurf_LineOn2S)& Vertices,
1570 TColStd_Array1OfInteger& PTypes)
1572 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1573 Standard_Integer ip = 0, iv = 0;
1574 for(ip = 1; ip <= nbp; ip++) {
1575 const IntSurf_PntOn2S& aP = Line->Value(ip);
1576 Standard_Integer type = 0;
1577 for(iv = 1; iv <= nbv; iv++) {
1578 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1579 if(AreSamePoints(aP,aV)) {
1588 static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1589 const Standard_Real TOL2D)
1591 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
1594 static inline Standard_Real AdjustU(const Standard_Real U)
1596 Standard_Real u = U, DBLPI = 2.*M_PI;
1597 if(u < 0. || u > DBLPI) {
1608 static inline void Correct2DBounds(const Standard_Real UF,
1609 const Standard_Real UL,
1610 const Standard_Real VF,
1611 const Standard_Real VL,
1612 const Standard_Real TOL2D,
1616 Standard_Real Eps = 1.e-16;
1617 Standard_Real dUF = fabs(U - UF);
1618 Standard_Real dUL = fabs(U - UL);
1619 Standard_Real dVF = fabs(V - VF);
1620 Standard_Real dVL = fabs(V - VL);
1621 if(dUF <= TOL2D && dUF > Eps) U = UF;
1622 if(dUL <= TOL2D && dUL > Eps) U = UL;
1623 if(dVF <= TOL2D && dVF > Eps) V = VF;
1624 if(dVL <= TOL2D && dVL > Eps) V = VL;
1627 static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1628 const Standard_Boolean IsReversed,
1629 const Handle(Adaptor3d_HSurface)& QSurf,
1630 const Standard_Real TOL2D)
1632 Standard_Real VF = QSurf->FirstVParameter();
1633 Standard_Real VL = QSurf->LastVParameter();
1634 Standard_Real UF = QSurf->FirstUParameter();
1635 Standard_Real UL = QSurf->LastUParameter();
1637 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1638 Standard_Real U = 0., V = 0.;
1639 for(ip = 1; ip <= nbp; ip++) {
1641 Line->Value(ip).ParametersOnS2(U,V);
1643 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1644 Line->SetUV(ip,Standard_False,U,V);
1647 Line->Value(ip).ParametersOnS1(U,V);
1649 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1650 Line->SetUV(ip,Standard_True,U,V);
1655 static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
1656 const Standard_Boolean IsReversed,
1657 Handle(IntSurf_LineOn2S)& Vertices,
1658 const TColStd_Array1OfInteger& PTypes,
1659 const Standard_Real TOL2D)
1661 Standard_Boolean result = Standard_False;
1662 Standard_Integer ip = 0, nbp = Line->NbPoints();
1663 Standard_Real U = 0., V = 0.;
1664 for(ip = 1; ip <= nbp; ip++) {
1665 Standard_Integer ipt = PTypes(ip);
1667 const IntSurf_PntOn2S& aP = Line->Value(ip);
1669 aP.ParametersOnS2(U,V); // S2 - quadric
1671 aP.ParametersOnS1(U,V); // S1 - quadric
1673 if(IsSeamParameter(U,TOL2D)) {
1674 if(ip == 1 || ip == nbp) {
1675 Standard_Real U1 = 0., V1 = 0.;
1676 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1678 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1680 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1681 Standard_Real u = AdjustUFirst(U,U1);
1682 if(fabs(u-U) >= 1.5*M_PI) {
1683 Standard_Real U2 = 0., V2 = 0.;
1685 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1686 Line->SetUV(ip,Standard_False,u,V);
1687 Line->SetUV(ip,Standard_True,U2,V2);
1690 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1691 Line->SetUV(ip,Standard_True,u,V);
1692 Line->SetUV(ip,Standard_False,U2,V2);
1697 Standard_Integer ipp = ip - 1;
1698 Standard_Integer ipn = ip + 1;
1699 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1701 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1702 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1705 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1706 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1710 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1711 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1712 if(pnearZero == cnearZero) {
1713 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1714 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1716 nP.SetValue(aP.Value());
1717 Standard_Real U3 = 0., V3 = 0.;
1719 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1720 nP.SetValue(Standard_False,nU,V);
1721 nP.SetValue(Standard_True,U3,V3);
1724 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1725 nP.SetValue(Standard_True,nU,V);
1726 nP.SetValue(Standard_False,U3,V3);
1728 Line->InsertBefore(ipn,nP);
1730 result = Standard_True;
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(ip,nP);
1752 result = Standard_True;
1756 // Line->InsertBefore(ip,Line->Value(ipn));
1757 // Line->RemovePoint(ip+2);
1758 // result = Standard_True;
1759 // cout << "swap vertex " << endl;
1770 static void ToSmooth(Handle(IntSurf_LineOn2S)& Line,
1771 Standard_Boolean IsReversed,
1772 IntSurf_Quadric& Quad,
1773 Standard_Boolean IsFirst,
1776 if(Line->NbPoints() <= 10)
1780 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1781 if(NbTestPnts < 5) NbTestPnts = 5;
1783 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1784 Standard_Integer ip = 0;
1785 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1787 for(ip = startp; ip <= NbTestPnts; ip++) {
1789 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1790 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1793 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1794 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1796 DDU += fabs(fabs(Uc)-fabs(Un));
1797 DDV += fabs(fabs(Vc)-fabs(Vn));
1800 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1805 DDU /= (Standard_Real) NbTestPnts + 1;
1806 DDV /= (Standard_Real) NbTestPnts + 1;
1808 D3D /= (Standard_Real) NbTestPnts + 1;
1811 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1812 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1813 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1815 Standard_Boolean doU = Standard_False;
1816 Standard_Boolean doV = Standard_False;
1818 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1821 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1822 Line->Value(Index2).ParametersOnS2(U2,V2);
1823 Line->Value(Index3).ParametersOnS2(U3,V3);
1826 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1827 Line->Value(Index2).ParametersOnS1(U2,V2);
1828 Line->Value(Index3).ParametersOnS1(U3,V3);
1831 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
1832 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
1834 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1835 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
1837 doU = Standard_False;
1842 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1843 Standard_Real Uapx = 0., Vapx = 0.;
1844 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1846 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
1848 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1849 if(fabs(V1-Vapx) <= 1.e-9) {}
1851 doU = Standard_False;
1856 if(fabs(fabs(V1)-fabs(V2)) > DDV) doV = Standard_True;
1859 Standard_Real dU = Min((DDU/10.),5.e-8);
1860 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1862 Line->SetUV(Index1,Standard_False,U,V1);
1864 Line->SetUV(Index1,Standard_True,U,V1);
1869 static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
1870 const IntSurf_PntOn2S& aV,
1871 const Standard_Boolean IsReversed,
1872 const Standard_Real ArcTol,
1873 Handle(Adaptor3d_TopolTool)& PDomain)
1876 Standard_Boolean result = Standard_False;
1877 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1879 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1880 aV.ParametersOnS1(Uv,Vv);
1883 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1884 aV.ParametersOnS2(Uv,Vv);
1886 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
1887 gp_Pnt2d a2DPntM(Um,Vm);
1888 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
1889 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
1890 result = Standard_True;
1894 static void VerifyVertices(Handle(IntSurf_LineOn2S)& Line,
1895 Standard_Boolean IsReversed,
1896 Handle(IntSurf_LineOn2S)& Vertices,
1897 Standard_Real TOL2D,
1898 const Standard_Real ArcTol,
1899 Handle(Adaptor3d_TopolTool)& PDomain,
1900 IntSurf_PntOn2S& VrtF,
1901 Standard_Boolean& AddFirst,
1902 IntSurf_PntOn2S& VrtL,
1903 Standard_Boolean& AddLast)
1905 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1906 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
1907 const IntSurf_PntOn2S& aPF = Line->Value(1);
1908 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
1909 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
1911 aPF.ParametersOnS2(UF,VF);
1912 aPL.ParametersOnS2(UL,VL);
1915 aPF.ParametersOnS1(UF,VF);
1916 aPL.ParametersOnS1(UL,VL);
1918 gp_Pnt2d a2DPF(UF,VF);
1919 gp_Pnt2d a2DPL(UL,VL);
1920 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
1921 Standard_Integer FConjugated = 0, LConjugated = 0;
1923 Standard_Integer iv = 0;
1925 for(iv = 1; iv <= nbv; iv++) {
1926 Standard_Real Uv = 0., Vv = 0.;
1928 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1930 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1933 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1935 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1939 for(iv = 1; iv <= nbv; iv++) {
1940 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1941 if(AreSamePoints(aPF,aV)) {
1946 Standard_Real Uv = 0., Vv = 0.;
1948 aV.ParametersOnS2(Uv,Vv);
1950 aV.ParametersOnS1(Uv,Vv);
1951 gp_Pnt2d a2DV(Uv,Vv);
1952 Standard_Real Dist = a2DV.Distance(a2DPF);
1953 if(Dist < DistMinF) {
1956 if(FConjugated != 0)
1959 if(IsSeamParameter(Uv,TOL2D)) {
1960 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1961 gp_Pnt2d a2DCV(Ucv,Vv);
1962 Standard_Real CDist = a2DCV.Distance(a2DPF);
1963 if(CDist < DistMinF) {
1972 for(iv = 1; iv <= nbv; iv++) {
1973 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1974 if(AreSamePoints(aPL,aV)) {
1979 Standard_Real Uv = 0., Vv = 0.;
1981 aV.ParametersOnS2(Uv,Vv);
1983 aV.ParametersOnS1(Uv,Vv);
1984 gp_Pnt2d a2DV(Uv,Vv);
1985 Standard_Real Dist = a2DV.Distance(a2DPL);
1986 if(Dist < DistMinL) {
1989 if(LConjugated != 0)
1992 if(IsSeamParameter(Uv,TOL2D)) {
1993 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1994 gp_Pnt2d a2DCV(Ucv,Vv);
1995 Standard_Real CDist = a2DCV.Distance(a2DPL);
1996 if(CDist < DistMinL) {
2005 AddFirst = Standard_False;
2006 AddLast = Standard_False;
2008 if(FIndexSame == 0) {
2009 if(FIndexNear != 0) {
2010 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2011 Standard_Real Uv = 0., Vv = 0.;
2013 aV.ParametersOnS2(Uv,Vv);
2015 aV.ParametersOnS1(Uv,Vv);
2016 if(IsSeamParameter(Uv,TOL2D)) {
2017 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2018 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2020 VrtF.SetValue(aV.Value());
2022 Standard_Real U2 = 0., V2 = 0.;
2023 aV.ParametersOnS1(U2,V2); // S1 - prm
2024 VrtF.SetValue(Standard_True,U2,V2);
2025 if(FConjugated == 0)
2026 VrtF.SetValue(Standard_False,Uv,Vv);
2028 VrtF.SetValue(Standard_False,Ucv,Vv);
2031 Standard_Real U2 = 0., V2 = 0.;
2032 aV.ParametersOnS2(U2,V2); // S2 - prm
2033 VrtF.SetValue(Standard_False,U2,V2);
2034 if(FConjugated == 0)
2035 VrtF.SetValue(Standard_True,Uv,Vv);
2037 VrtF.SetValue(Standard_True,Ucv,Vv);
2039 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2040 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2041 AddFirst = Standard_True;
2046 // to do: analyze internal vertex
2051 if(LIndexSame == 0) {
2052 if(LIndexNear != 0) {
2053 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2054 Standard_Real Uv = 0., Vv = 0.;
2056 aV.ParametersOnS2(Uv,Vv);
2058 aV.ParametersOnS1(Uv,Vv);
2059 if(IsSeamParameter(Uv,TOL2D)) {
2060 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2061 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2063 VrtL.SetValue(aV.Value());
2065 Standard_Real U2 = 0., V2 = 0.;
2066 aV.ParametersOnS1(U2,V2); // S1 - prm
2067 VrtL.SetValue(Standard_True,U2,V2);
2068 if(LConjugated == 0)
2069 VrtL.SetValue(Standard_False,Uv,Vv);
2071 VrtL.SetValue(Standard_False,Ucv,Vv);
2074 Standard_Real U2 = 0., V2 = 0.;
2075 aV.ParametersOnS2(U2,V2); // S2 - prm
2076 VrtL.SetValue(Standard_False,U2,V2);
2077 if(LConjugated == 0)
2078 VrtL.SetValue(Standard_True,Uv,Vv);
2080 VrtL.SetValue(Standard_True,Ucv,Vv);
2082 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2083 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2084 AddLast = Standard_True;
2089 // to do: analyze internal vertex
2095 static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
2096 const IntSurf_PntOn2S& VrtF,
2097 const Standard_Boolean AddFirst,
2098 const IntSurf_PntOn2S& VrtL,
2099 const Standard_Boolean AddLast,
2100 const Standard_Real D3DF,
2101 const Standard_Real D3DL)
2103 Standard_Boolean result = Standard_False;
2105 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2106 if((D3DF*2.) > DF && DF > 1.5e-7) {
2107 Line->InsertBefore(1,VrtF);
2108 result = Standard_True;
2112 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2113 if((D3DL*2.) > DL && DL > 1.5e-7) {
2115 result = Standard_True;
2122 static void PutIntVertices(Handle(IntPatch_Line)& Line,
2123 Handle(IntSurf_LineOn2S)& Result,
2124 Standard_Boolean ,//IsReversed,
2125 Handle(IntSurf_LineOn2S)& Vertices,
2126 const Standard_Real ArcTol)
2128 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2133 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2134 Standard_Integer ip = 0, iv = 0;
2136 IntPatch_Point thePnt;
2137 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2139 for(ip = 2; ip <= (nbp-1); ip++) {
2140 const IntSurf_PntOn2S& aP = Result->Value(ip);
2141 for(iv = 1; iv <= nbv; iv++) {
2142 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2143 if(AreSamePoints(aP,aV)) {
2144 aPnt = Result->Value(ip).Value();
2145 Result->Value(ip).ParametersOnS1(U1,V1);
2146 Result->Value(ip).ParametersOnS2(U2,V2);
2147 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2148 thePnt.SetParameters(U1,V1,U2,V2);
2149 thePnt.SetParameter((Standard_Real)ip);
2150 WLine->AddVertex(thePnt);
2156 static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2157 Handle(IntSurf_LineOn2S)& Vertices)
2159 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2160 Standard_Integer ip = 0, iv = 0;
2161 Standard_Boolean result = Standard_False;
2166 for(ip = 2; ip <= (nbp-1); ip++) {
2167 const IntSurf_PntOn2S& aP = Line->Value(ip);
2168 for(iv = 1; iv <= nbv; iv++) {
2169 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2170 if(AreSamePoints(aP,aV)) {
2171 result = Standard_True;
2181 static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
2182 Standard_Boolean Tang,
2183 IntSurf_TypeTrans Trans1,
2184 IntSurf_TypeTrans Trans2,
2185 Standard_Real ArcTol,
2186 Standard_Integer ParFirst,
2187 Standard_Integer ParLast)
2189 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2190 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2192 Standard_Integer ip = 0;
2193 for(ip = ParFirst; ip <= ParLast; ip++)
2194 sline->Add(SLine->Value(ip));
2196 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2199 IntPatch_Point TPntF,TPntL;
2200 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2202 aSPnt = sline->Value(1).Value();
2203 sline->Value(1).ParametersOnS1(uu1,vv1);
2204 sline->Value(1).ParametersOnS2(uu2,vv2);
2205 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2206 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2207 TPntF.SetParameter(1.);
2208 wline->AddVertex(TPntF);
2209 wline->SetFirstPoint(1);
2211 aSPnt = sline->Value(sline->NbPoints()).Value();
2212 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2213 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2214 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2215 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2216 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2217 wline->AddVertex(TPntL);
2218 wline->SetLastPoint(sline->NbPoints());
2223 static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
2224 Standard_Boolean Tang,
2225 IntSurf_TypeTrans Trans1,
2226 IntSurf_TypeTrans Trans2,
2227 Standard_Real ArcTol,
2228 IntPatch_SequenceOfLine& Segments)
2230 Standard_Boolean result = Standard_False;
2233 Standard_Integer nbv = WLine->NbVertex();
2235 Standard_Integer iv = 0;
2236 for(iv = 1; iv < nbv; iv++) {
2237 Standard_Integer firstPar = (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2238 Standard_Integer lastPar = (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
2239 if((lastPar - firstPar) <= 1)
2242 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,ArcTol,firstPar,lastPar);
2243 Segments.Append(splitwline);
2245 result = Standard_True;
2252 void DecomposeResult(Handle(IntPatch_Line)& Line,
2253 Standard_Boolean IsReversed,
2254 IntSurf_Quadric& Quad,
2255 Handle(Adaptor3d_TopolTool)& PDomain,
2256 Handle(Adaptor3d_HSurface)& QSurf,
2257 Standard_Real ArcTol,
2258 IntPatch_SequenceOfLine& Lines)
2260 if( Line->ArcType() != IntPatch_Walking ) {
2265 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2266 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2268 if(SLine->NbPoints() <= 2) {
2273 Standard_Real TOL3D = 1.e-10, TOL2D = 1.e-8, TOL2DS = 1.e-5;
2275 Handle(IntSurf_LineOn2S) vline = GetVertices(WLine,IsReversed,TOL3D,TOL2D);
2276 Handle(IntSurf_LineOn2S) SSLine = VSplitLine(SLine,IsReversed,QSurf,vline);
2278 if(SSLine->NbPoints() <= 1)
2281 AdjustLine(SSLine,IsReversed,QSurf,TOL2D);
2283 Standard_Boolean isInserted = Standard_True;
2285 Standard_Integer NbPnts = SSLine->NbPoints();
2286 TColStd_Array1OfInteger ptypes(1,NbPnts);
2287 SearchVertices(SSLine,vline,ptypes);
2288 isInserted = InsertSeamVertices(SSLine,IsReversed,vline,ptypes,TOL2D);
2291 if(SSLine->NbPoints() == 2) {
2292 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2294 SSLine->Value(1).ParametersOnS2(uu1,vv1);
2295 SSLine->Value(2).ParametersOnS2(uu2,vv2);
2298 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2299 SSLine->Value(2).ParametersOnS1(uu2,vv2);
2301 gp_Pnt2d p1(uu1,vv1);
2302 gp_Pnt2d p2(uu2,vv2);
2303 if(p1.Distance(p2) > 2.e-7) {
2304 Standard_Real Dist3D = SSLine->Value(1).Value().Distance(SSLine->Value(2).Value());
2305 if(Dist3D > 3.e-7) {
2307 IntPatch_Point TPntF,TPntL;
2308 Handle(IntPatch_WLine) wline = new IntPatch_WLine(SSLine,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2309 aSPnt = SSLine->Value(1).Value();
2310 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2311 SSLine->Value(1).ParametersOnS2(uu2,vv2);
2312 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2313 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2314 TPntF.SetParameter(1.);
2315 wline->AddVertex(TPntF);
2316 wline->SetFirstPoint(1);
2317 aSPnt = SSLine->Value(SSLine->NbPoints()).Value();
2318 SSLine->Value(SSLine->NbPoints()).ParametersOnS1(uu1,vv1);
2319 SSLine->Value(SSLine->NbPoints()).ParametersOnS2(uu2,vv2);
2320 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2321 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2322 TPntL.SetParameter(SSLine->NbPoints());
2323 wline->AddVertex(TPntL);
2324 wline->SetLastPoint(SSLine->NbPoints());
2325 Lines.Append(wline);
2335 Standard_Integer NbPnts = SSLine->NbPoints();
2337 Standard_Real BSEAM = 1.5*M_PI; // delta U crossing seam
2338 Standard_Real BAPEX = M_PI/16.; // delta U crossing apex
2340 Standard_Integer i = 0, k = 0;
2341 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0., AnV1 = 0., DU1 = 0., DV1 = 0.;
2342 Standard_Integer Findex = 1, Lindex = NbPnts, Bindex = 0;
2345 IntPatch_Point TPntF,TPntL,TPntS;
2347 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2348 Handle(IntPatch_WLine) wline;
2349 IntPatch_SequenceOfLine lines;
2351 // build WLine parts (if any)
2354 //if((Lindex-Findex+1) <= 2 )
2355 if((Lindex-Findex+1) <= 1 )
2359 Standard_Boolean isDecomposited = Standard_False;
2360 Standard_Boolean is2PIDecomposed = Standard_False;
2361 U1 = 0.; V1 = 0.; U2 = 0.; V2 = 0.; AnU1 = 0.; AnV1 = 0.; DU1 = 0.; DV1 = 0.;
2363 // analyze other points
2364 for(k = Findex; k <= Lindex; k++) {
2369 SSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2372 SSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2374 sline->Add(SSLine->Value(k));
2380 SSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2383 SSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2386 Standard_Real DeltaU = fabs(U1-AnU1);
2387 if(DeltaU > BSEAM) {
2389 isDecomposited = Standard_True;
2390 is2PIDecomposed = Standard_True;
2393 else if((DeltaU > BAPEX) && (k >= (Findex+10) && k <= (Lindex-10))) {
2395 isDecomposited = Standard_True;
2400 sline->Add(SSLine->Value(k));
2405 IntSurf_PntOn2S aVF,aVL;
2406 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2407 VerifyVertices(sline,IsReversed,vline,TOL2DS,ArcTol,PDomain,aVF,addVF,aVL,addVL);
2409 Standard_Boolean hasInternals = HasInternals(sline,vline);
2411 Standard_Real D3F = 0., D3L = 0.;
2412 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2413 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2415 if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2416 D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2418 if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2419 D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->Value(sline->NbPoints()-2).Value());
2422 if(addVF || addVL) {
2423 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2425 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2426 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2431 ForcedPurgePoints(sline,IsReversed,Quad);
2434 wline = new IntPatch_WLine(sline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2436 aSPnt = sline->Value(1).Value();
2437 sline->Value(1).ParametersOnS1(U1,V1);
2438 sline->Value(1).ParametersOnS2(U2,V2);
2439 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2440 TPntF.SetParameters(U1,V1,U2,V2);
2441 TPntF.SetParameter(1.);
2442 wline->AddVertex(TPntF);
2443 wline->SetFirstPoint(1);
2446 PutIntVertices(wline,sline,IsReversed,vline,ArcTol);
2449 aSPnt = sline->Value(sline->NbPoints()).Value();
2450 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2451 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2452 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2453 TPntL.SetParameters(U1,V1,U2,V2);
2454 TPntL.SetParameter(sline->NbPoints());
2455 wline->AddVertex(TPntL);
2456 wline->SetLastPoint(sline->NbPoints());
2458 IntPatch_SequenceOfLine segm;
2459 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2(),ArcTol,segm);
2462 Lines.Append(wline);
2464 Standard_Integer nbsegms = segm.Length();
2465 Standard_Integer iseg = 0;
2466 for(iseg = 1; iseg <= nbsegms; iseg++)
2467 Lines.Append(segm(iseg));
2470 if(isDecomposited) {
2472 sline = new IntSurf_LineOn2S();
2479 Standard_Integer aNbPnts;
2480 Standard_Real aU1,aV1,aU2,aV2;
2483 aNbPnts=thelin->NbPoints();
2484 printf(" WLine: aNbPnts=%d\n", aNbPnts);
2485 for(i=1; i <= aNbPnts; ++i) {
2486 const IntSurf_PntOn2S& aPoint = thelin->Value(i);
2488 aPoint.Parameters(aU1, aV1, aU2, aV2);
2489 printf(" point %d %lf %lf %lf %lf %lf %lf %lf\n",
2490 i, aPx.X(), aPx.Y(), aPx.Z(), aU1, aV1, aU2, aV2);