1 // Created on: 1992-05-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <IntPatch_ImpPrmIntersection.ixx>
24 #include <Standard_ConstructionError.hxx>
25 #include <IntPatch_SequenceOfLine.hxx>
26 #include <TColStd_Array1OfInteger.hxx>
27 #include <IntSurf_PntOn2S.hxx>
28 #include <IntSurf_LineOn2S.hxx>
29 #include <IntSurf.hxx>
31 #include <Adaptor2d_HCurve2d.hxx>
32 #include <IntSurf_PathPoint.hxx>
33 #include <IntSurf_SequenceOfPathPoint.hxx>
34 #include <IntPatch_TheIWalking.hxx>
35 #include <IntPatch_TheIWLineOfTheIWalking.hxx>
36 #include <IntPatch_ThePathPointOfTheSOnBounds.hxx>
37 #include <IntPatch_TheSegmentOfTheSOnBounds.hxx>
38 #include <IntPatch_TheSurfFunction.hxx>
39 #include <IntPatch_RLine.hxx>
40 #include <IntPatch_WLine.hxx>
41 #include <IntPatch_ArcFunction.hxx>
42 #include <IntPatch_RstInt.hxx>
44 //=======================================================================
45 //function : IntPatch_ImpPrmIntersection
47 //=======================================================================
49 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
50 : done(Standard_False),
52 myIsStartPnt(Standard_False),
58 //=======================================================================
59 //function : IntPatch_ImpPrmIntersection
61 //=======================================================================
63 IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection
64 (const Handle(Adaptor3d_HSurface)& Surf1,
65 const Handle(Adaptor3d_TopolTool)& D1,
66 const Handle(Adaptor3d_HSurface)& Surf2,
67 const Handle(Adaptor3d_TopolTool)& D2,
68 const Standard_Real TolArc,
69 const Standard_Real TolTang,
70 const Standard_Real Fleche,
71 const Standard_Real Pas)
72 : done(Standard_False),
74 myIsStartPnt(Standard_False),
78 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
82 //=======================================================================
83 //function : SetStartPoint
85 //=======================================================================
87 void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
88 const Standard_Real V)
90 myIsStartPnt = Standard_True;
91 myUStart = U; myVStart = V;
95 #define No_Standard_RangeError
96 #define No_Standard_OutOfRange
100 #include <math_Vector.hxx>
101 #include <math_Matrix.hxx>
102 #include <TopTrans_CurveTransition.hxx>
103 #include <TopAbs_State.hxx>
104 #include <TopAbs_Orientation.hxx>
105 #include <TColStd_Array1OfInteger.hxx>
106 #include <TColStd_Array1OfReal.hxx>
108 #include <IntSurf_SequenceOfInteriorPoint.hxx>
109 #include <IntSurf_QuadricTool.hxx>
110 #include <GeomAbs_SurfaceType.hxx>
113 static void DecomposeResult(Handle(IntPatch_Line)& Line,
114 Standard_Boolean IsReversed,
115 IntSurf_Quadric& Quad,
116 Handle(Adaptor3d_TopolTool)& PDomain,
117 Handle(Adaptor3d_HSurface)& QSurf,
118 Standard_Real TolArc,
119 IntPatch_SequenceOfLine& Lines);
121 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
122 IntSurf_SequenceOfPathPoint& seqpdep,
123 const Handle(Adaptor3d_TopolTool)& Domain,
124 IntPatch_TheSurfFunction& Func,
125 const Handle(Adaptor3d_HSurface)& PSurf,
126 TColStd_Array1OfInteger& Destination);
128 void Recadre(const Standard_Boolean ,
129 GeomAbs_SurfaceType typeS1,
130 GeomAbs_SurfaceType typeS2,
132 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
133 Standard_Integer Param,
139 //=======================================================================
140 //function : ComputeTangency
142 //=======================================================================
143 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
144 IntSurf_SequenceOfPathPoint& seqpdep,
145 const Handle(Adaptor3d_TopolTool)& Domain,
146 IntPatch_TheSurfFunction& Func,
147 const Handle(Adaptor3d_HSurface)& PSurf,
148 TColStd_Array1OfInteger& Destination)
150 Standard_Integer i,k, NbPoints, seqlength;
151 Standard_Real theparam,test;
152 Standard_Boolean fairpt, ispassing;
153 TopAbs_Orientation arcorien,vtxorien;
154 Handle(Adaptor2d_HCurve2d) thearc;
155 Handle(Adaptor3d_HVertex) vtx,vtxbis;
156 //Standard_Boolean ispassing;
157 IntPatch_ThePathPointOfTheSOnBounds PStart;
158 IntSurf_PathPoint PPoint;
162 gp_Vec d1u,d1v,v1,v2;
166 double aX[2], aF[1], aD[1][2];
167 math_Vector X(aX, 1, 2);
168 math_Vector F(aF, 1, 1);
169 math_Matrix D(aD, 1, 1, 1, 2);
172 NbPoints = solrst.NbPoints();
173 for (i=1; i<= NbPoints; i++) {
174 if (Destination(i) == 0) {
175 PStart = solrst.Point(i);
176 thearc = PStart.Arc();
177 theparam = PStart.Parameter();
178 arcorien = Domain->Orientation(thearc);
179 ispassing = (arcorien == TopAbs_INTERNAL ||
180 arcorien == TopAbs_EXTERNAL);
182 thearc->D0(theparam,p2d);
185 PPoint.SetValue(PStart.Value(),X(1),X(2));
188 if (Func.IsTangent()) {
189 PPoint.SetTangency(Standard_True);
190 Destination(i) = seqlength+1;
191 if (!PStart.IsNew()) {
192 vtx = PStart.Vertex();
193 for (k=i+1; k<=NbPoints; k++) {
194 if (Destination(k) ==0) {
195 PStart = solrst.Point(k);
196 if (!PStart.IsNew()) {
197 vtxbis = PStart.Vertex();
198 if (Domain->Identical(vtx,vtxbis)) {
199 thearc = PStart.Arc();
200 theparam = PStart.Parameter();
201 arcorien = Domain->Orientation(thearc);
202 ispassing = ispassing && (arcorien == TopAbs_INTERNAL ||
203 arcorien == TopAbs_EXTERNAL);
205 thearc->D0(theparam,p2d);
206 PPoint.AddUV(p2d.X(),p2d.Y());
207 Destination(k) = seqlength+1;
213 PPoint.SetPassing(ispassing);
214 seqpdep.Append(PPoint);
217 else { // on a un point de depart potentiel
219 vectg = Func.Direction3d();
220 dirtg = Func.Direction2d();
222 PSurf->D1(X(1),X(2),ptbid,d1u,d1v);
223 thearc->D1(theparam,p2d,d2d);
224 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
225 v1 = d1u.Crossed(d1v);
227 test = vectg.Dot(v1.Crossed(v2));
228 if (PStart.IsNew()) {
229 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
230 (test > 0. && arcorien == TopAbs_REVERSED)) {
234 PPoint.SetDirections(vectg,dirtg);
235 PPoint.SetPassing(ispassing);
236 Destination(i) = seqlength+1;
237 seqpdep.Append(PPoint);
240 else { // traiter la transition complexe
241 gp_Dir bidnorm(1.,1.,1.);
242 Standard_Real tole = 1.e-8;
243 TopAbs_Orientation LocTrans;
244 TopTrans_CurveTransition comptrans;
245 comptrans.Reset(vectg,bidnorm,0.);
246 if (arcorien == TopAbs_FORWARD ||
247 arcorien == TopAbs_REVERSED) {
250 vtx = PStart.Vertex();
251 vtxorien = Domain->Orientation(vtx);
252 if (Abs(test) <= tole) {
253 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
256 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
257 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
258 LocTrans = TopAbs_FORWARD;
261 LocTrans = TopAbs_REVERSED;
263 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
266 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
268 Destination(i) = seqlength+1;
269 for (k= i+1; k<=NbPoints; k++) {
270 if (Destination(k) == 0) {
271 PStart = solrst.Point(k);
272 if (!PStart.IsNew()) {
273 vtxbis = PStart.Vertex();
274 if (Domain->Identical(vtx,vtxbis)) {
275 thearc = PStart.Arc();
276 theparam = PStart.Parameter();
277 arcorien = Domain->Orientation(thearc);
279 PPoint.AddUV(X(1),X(2));
281 thearc->D1(theparam,p2d,d2d);
282 PPoint.AddUV(p2d.X(),p2d.Y());
284 if (arcorien == TopAbs_FORWARD ||
285 arcorien == TopAbs_REVERSED) {
286 ispassing = Standard_False;
287 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
289 test = vectg.Dot(v1.Crossed(v2));
290 vtxorien = Domain->Orientation(PStart.Vertex());
291 if (Abs(test) <= tole) {
292 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
295 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
296 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
297 LocTrans = TopAbs_FORWARD;
300 LocTrans = TopAbs_REVERSED;
302 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
305 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
307 Destination(k) = seqlength+1;
312 fairpt = Standard_True;
314 TopAbs_State Before = comptrans.StateBefore();
315 TopAbs_State After = comptrans.StateAfter();
316 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
317 fairpt = Standard_False;
319 else if (Before == TopAbs_IN) {
320 if (After == TopAbs_IN) {
321 ispassing = Standard_True;
329 if (After !=TopAbs_IN) {
330 fairpt = Standard_False;
335 PPoint.SetDirections(vectg,dirtg);
336 PPoint.SetPassing(ispassing);
337 seqpdep.Append(PPoint);
340 else { // il faut remettre en "ordre" si on ne garde pas le point.
341 for (k=i; k <=NbPoints ; k++) {
342 if (Destination(k)==seqlength + 1) {
343 Destination(k) = -Destination(k);
352 //=======================================================================
355 //=======================================================================
356 void Recadre(const Standard_Boolean ,
357 GeomAbs_SurfaceType typeS1,
358 GeomAbs_SurfaceType typeS2,
360 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
361 Standard_Integer Param,
367 Standard_Real U1p,V1p,U2p,V2p;
368 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
372 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
373 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
374 case GeomAbs_Cylinder:
377 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
378 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
385 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
386 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
387 case GeomAbs_Cylinder:
390 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
391 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
395 pt.SetParameters(U1,V1,U2,V2);
398 //=======================================================================
401 //=======================================================================
402 void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
403 const Handle(Adaptor3d_TopolTool)& D1,
404 const Handle(Adaptor3d_HSurface)& Surf2,
405 const Handle(Adaptor3d_TopolTool)& D2,
406 const Standard_Real TolArc,
407 const Standard_Real TolTang,
408 const Standard_Real Fleche,
409 const Standard_Real Pas)
411 Standard_Boolean reversed, procf, procl, dofirst, dolast;
412 Standard_Integer indfirst = 0, indlast = 0, ind2, i,j,k, NbSegm;
413 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
414 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
416 IntPatch_TheSegmentOfTheSOnBounds thesegm;
417 IntSurf_PathPoint PPoint;
419 Handle(IntPatch_RLine) rline;
420 Handle(IntPatch_WLine) wline;
421 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
422 IntPatch_Point ptdeb,ptfin,ptbis;
425 IntSurf_Transition TLine,TArc;
426 IntSurf_TypeTrans trans1,trans2;
428 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
435 Handle(Adaptor2d_HCurve2d) currentarc;
436 GeomAbs_SurfaceType typeS1, typeS2;
437 IntSurf_Quadric Quad;
438 IntPatch_TheSurfFunction Func;
439 IntPatch_ArcFunction AFunc;
441 typeS1 = Surf1->GetType();
442 typeS2 = Surf2->GetType();
446 trans1 = IntSurf_Undecided;
447 trans2 = IntSurf_Undecided;
449 done = Standard_False;
450 empt = Standard_True;
454 reversed = Standard_False;
457 Quad.SetValue(Surf1->Plane());
460 case GeomAbs_Cylinder:
461 Quad.SetValue(Surf1->Cylinder());
465 Quad.SetValue(Surf1->Sphere());
469 Quad.SetValue(Surf1->Cone());
473 reversed = Standard_True;
476 Quad.SetValue(Surf2->Plane());
479 case GeomAbs_Cylinder:
480 Quad.SetValue(Surf2->Cylinder());
484 Quad.SetValue(Surf2->Sphere());
488 Quad.SetValue(Surf2->Cone());
491 Standard_ConstructionError::Raise();
499 Func.SetImplicitSurface(Quad);
500 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
501 AFunc.SetQuadric(Quad);
513 solrst.Perform(AFunc,D2,TolArc,TolTang);
516 solrst.Perform(AFunc,D1,TolArc,TolTang);
518 if (!solrst.IsDone()) {
522 IntSurf_SequenceOfPathPoint seqpdep;
523 IntSurf_SequenceOfInteriorPoint seqpins;
525 NbPointRst = solrst.NbPoints();
526 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
529 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
532 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
536 // Recherche des points interieurs
539 solins.Perform(Func,Surf2,myUStart,myVStart);
541 solins.Perform(Func,Surf2,D2,TolTang);
545 solins.Perform(Func,Surf1,myUStart,myVStart);
547 solins.Perform(Func,Surf1,D1,TolTang);
550 NbPointIns = solins.NbPoints();
551 for (i=1; i <= NbPointIns; i++) {
552 seqpins.Append(solins.Value(i));
554 NbPointDep=seqpdep.Length();
556 if (NbPointDep || NbPointIns) {
557 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
559 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
562 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
564 if(!iwalk.IsDone()) {
568 Standard_Real Vmin, Vmax, TolV = 1.e-14;
569 if (!reversed) { //Surf1 is quadric
570 Vmin = Surf1->FirstVParameter();
571 Vmax = Surf1->LastVParameter();
573 else { //Surf2 is quadric
574 Vmin = Surf2->FirstVParameter();
575 Vmax = Surf2->LastVParameter();
578 Nblines = iwalk.NbLines();
579 for (j=1; j<=Nblines; j++) {
580 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
581 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
583 Nbpts = thelin->NbPoints();
586 tgline = iwline->TangentVector(k);
587 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
588 valpt = thelin->Value(k).Value();
591 thelin->Value(k).ParametersOnS2(U2,V2);
592 norm1 = Quad.Normale(valpt);
593 Surf2->D1(U2,V2,ptbid,d1u,d1v);
594 norm2 = d1u.Crossed(d1v);
597 thelin->Value(k).ParametersOnS1(U2,V2);
598 norm2 = Quad.Normale(valpt);
599 Surf1->D1(U2,V2,ptbid,d1u,d1v);
600 norm1 = d1u.Crossed(d1v);
602 if (tgline.DotCross(norm2,norm1) > 0.) {
603 trans1 = IntSurf_Out;
608 trans2 = IntSurf_Out;
612 Standard_Real AnU1,AnU2,AnV2;
614 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
615 Standard_Boolean arecadr=Standard_False;
616 valpt = thelin->Value(1).Value();
617 Quad.Parameters(valpt,AnU1,V1);
619 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
620 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
623 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
624 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
627 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
628 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
631 if(typQuad==GeomAbs_Cylinder ||
632 typQuad==GeomAbs_Cone ||
633 typQuad==GeomAbs_Sphere) {
634 arecadr=Standard_True;
637 for (k=2; k<=Nbpts; ++k) {
638 valpt = thelin->Value(k).Value();
639 Quad.Parameters(valpt,U1,V1);
641 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
644 if((V1 > Vmax) && (V1-Vmax < TolV)) {
649 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
650 Standard_Real aCf, aTwoPI;
654 if ((U1-AnU1) > 1.5*M_PI) {
655 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
662 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
668 //if ((U1-AnU1) > 1.5*M_PI) {
671 //else if ((U1-AnU1) < -1.5*M_PI) {
674 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
678 thelin->SetUV(k,Standard_False,U1,V1);
680 thelin->Value(k).ParametersOnS1(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_True,U2,V2);
699 thelin->SetUV(k,Standard_True,U1,V1);
701 thelin->Value(k).ParametersOnS2(U2,V2);
703 case GeomAbs_Cylinder:
707 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
708 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
713 if(typeS2==GeomAbs_Torus) {
714 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
715 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
717 thelin->SetUV(k,Standard_False,U2,V2);
726 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
728 if ( iwline->HasFirstPoint()
729 && iwline->IsTangentAtBegining() == Standard_False) {
730 indfirst = iwline->FirstPointIndex();
731 PPoint = seqpdep(indfirst);
732 tgline = PPoint.Direction3d();
733 Standard_Integer themult = PPoint.Multiplicity();
734 for (i=NbPointRst; i>=1; i--) {
735 if (Destination(i) == indfirst) {
736 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
737 Quad.Parameters(PPoint.Value(),U1,V1);
739 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
740 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
742 PPoint.Parameters(themult,U2,V2);
743 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
745 else { //-- typeS1 != Pln && Cyl && Sph && Cone
746 Quad.Parameters(PPoint.Value(),U2,V2);
748 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
749 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
751 PPoint.Parameters(themult,U1,V1);
752 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
755 VecNormale = d1u.Crossed(d1v);
756 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
757 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
758 ptdeb.SetParameters(U1,V1,U2,V2);
759 ptdeb.SetParameter(1.);
761 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
763 currentarc = solrst.Point(i).Arc();
764 currentparam = solrst.Point(i).Parameter();
765 currentarc->D1(currentparam,p2d,d2d);
766 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
768 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
769 if(squaremagnitudeVecNormale > 1e-13) {
770 DirNormale=VecNormale;
771 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
774 TLine.SetValue(Standard_True,IntSurf_Undecided);
775 TArc.SetValue(Standard_True,IntSurf_Undecided);
778 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
779 if (!solrst.Point(i).IsNew()) {
780 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
782 wline->AddVertex(ptdeb);
784 wline->SetFirstPoint(wline->NbVertex());
791 else if (iwline->IsTangentAtBegining()) {
792 gp_Pnt psol = thelin->Value(1).Value();
793 thelin->Value(1).ParametersOnS1(U1,V1);
794 thelin->Value(1).ParametersOnS2(U2,V2);
795 ptdeb.SetValue(psol,TolArc,Standard_True);
796 ptdeb.SetParameters(U1,V1,U2,V2);
797 ptdeb.SetParameter(1.);
798 wline->AddVertex(ptdeb);
799 wline->SetFirstPoint(wline->NbVertex());
802 gp_Pnt psol = thelin->Value(1).Value();
803 thelin->Value(1).ParametersOnS1(U1,V1);
804 thelin->Value(1).ParametersOnS2(U2,V2);
805 ptdeb.SetValue(psol,TolArc,Standard_False);
806 ptdeb.SetParameters(U1,V1,U2,V2);
807 ptdeb.SetParameter(1.);
808 wline->AddVertex(ptdeb);
809 wline->SetFirstPoint(wline->NbVertex());
813 if ( iwline->HasLastPoint()
814 && iwline->IsTangentAtEnd() == Standard_False) {
815 indlast = iwline->LastPointIndex();
816 PPoint = seqpdep(indlast);
817 tgline = PPoint.Direction3d().Reversed();
818 Standard_Integer themult = PPoint.Multiplicity();
819 for (i=NbPointRst; i >=1; i--) {
820 if (Destination(i) == indlast) {
822 Quad.Parameters(PPoint.Value(),U1,V1);
824 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
825 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
827 PPoint.Parameters(themult,U2,V2);
828 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
829 VecNormale = d1u.Crossed(d1v); //-- @@@@
832 Quad.Parameters(PPoint.Value(),U2,V2);
834 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
835 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
837 PPoint.Parameters(themult,U1,V1);
838 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
839 VecNormale = d1u.Crossed(d1v); //-- @@@@
842 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
843 ptfin.SetParameters(U1,V1,U2,V2);
844 ptfin.SetParameter(Nbpts);
846 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
848 currentarc = solrst.Point(i).Arc();
849 currentparam = solrst.Point(i).Parameter();
850 currentarc->D1(currentparam,p2d,d2d);
851 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
854 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
855 if(squaremagnitudeVecNormale > 1e-13) {
856 DirNormale=VecNormale;
857 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
860 TLine.SetValue(Standard_True,IntSurf_Undecided);
861 TArc.SetValue(Standard_True,IntSurf_Undecided);
865 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
866 if (!solrst.Point(i).IsNew()) {
867 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
869 wline->AddVertex(ptfin);
871 wline->SetLastPoint(wline->NbVertex());
878 else if (iwline->IsTangentAtEnd()) {
879 gp_Pnt psol = thelin->Value(Nbpts).Value();
880 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
881 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
882 ptfin.SetValue(psol,TolArc,Standard_True);
883 ptfin.SetParameters(U1,V1,U2,V2);
884 ptfin.SetParameter(Nbpts);
885 wline->AddVertex(ptfin);
886 wline->SetLastPoint(wline->NbVertex());
889 gp_Pnt psol = thelin->Value(Nbpts).Value();
890 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
891 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
892 ptfin.SetValue(psol,TolArc,Standard_False);
893 ptfin.SetParameters(U1,V1,U2,V2);
894 ptfin.SetParameter(Nbpts);
895 wline->AddVertex(ptfin);
896 wline->SetLastPoint(wline->NbVertex());
899 // Il faut traiter les points de passage.
902 }// for (j=1; j<=Nblines; j++) {
904 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
905 // QUE SUR DES POINTS DE TANGENCE
908 Nblines = slin.Length();
909 for (j=1; j<=Nblines-1; j++) {
910 dofirst = dolast = Standard_False;
911 const Handle(IntPatch_Line)& slinj = slin(j);
912 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
913 if (wlin1->HasFirstPoint()) {
914 ptdeb = wlin1->FirstPoint(indfirst);
915 if (ptdeb.IsTangencyPoint()) {
916 dofirst = Standard_True;
919 if (wlin1->HasLastPoint()) {
920 ptfin = wlin1->LastPoint(indlast);
921 if (ptfin.IsTangencyPoint()) {
922 dolast = Standard_True;
926 if (dofirst || dolast) {
927 for (k=j+1; k<=Nblines;k++) {
928 const Handle(IntPatch_Line)& slink = slin(k);
929 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
930 if (wlin2->HasFirstPoint()) {
931 ptbis = wlin2->FirstPoint(ind2);
932 if (ptbis.IsTangencyPoint()) {
934 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
935 ptdeb.SetMultiple(Standard_True);
936 if (!ptbis.IsMultiple()) {
937 ptbis.SetMultiple(Standard_True);
938 wlin2->Replace(ind2,ptbis);
943 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
944 ptfin.SetMultiple(Standard_True);
945 if (!ptbis.IsMultiple()) {
946 ptbis.SetMultiple(Standard_True);
947 wlin2->Replace(ind2,ptbis);
953 if (wlin2->HasLastPoint()) {
954 ptbis = wlin2->LastPoint(ind2);
955 if (ptbis.IsTangencyPoint()) {
957 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
958 ptdeb.SetMultiple(Standard_True);
959 if (!ptbis.IsMultiple()) {
960 ptbis.SetMultiple(Standard_True);
961 wlin2->Replace(ind2,ptbis);
966 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
967 ptfin.SetMultiple(Standard_True);
968 if (!ptbis.IsMultiple()) {
969 ptbis.SetMultiple(Standard_True);
970 wlin2->Replace(ind2,ptbis);
978 wlin1->Replace(indfirst,ptdeb);
980 wlin1->Replace(indlast,ptfin);
983 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
985 // Treatment the segments
986 NbSegm = solrst.NbSegments();
988 for(i=1; i<=NbSegm; i++) {
989 thesegm = solrst.Segment(i);
990 //----------------------------------------------------------------------
991 // on cree une ligne d intersection contenant uniquement le segment.
992 // VOIR POUR LA TRANSITION DE LA LIGNE
993 // On ajoute aussi un polygone pour le traitement des intersections
994 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
995 //----------------------------------------------------------------------
996 //-- Calcul de la transition sur la rline (12 fev 97)
997 //-- reversed a le sens de OnFirst
999 dofirst = dolast = Standard_False;
1000 procf = Standard_False;
1001 procl = Standard_False;
1002 IntSurf_Transition TLineUnk,TArcUnk;
1004 IntPatch_Point _thepointAtBeg;
1005 IntPatch_Point _thepointAtEnd;
1007 Standard_Boolean TransitionOK=Standard_False;
1009 if(thesegm.HasFirstPoint()) {
1010 Standard_Real _u1,_v1,_u2,_v2;
1012 dofirst = Standard_True;
1013 PStartf = thesegm.FirstPoint();
1014 paramf = PStartf.Parameter();
1016 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
1017 Handle(Adaptor3d_HVertex) _vtx;
1018 if(PStartf.IsNew()==Standard_False)
1019 _vtx= PStartf.Vertex();
1020 const gp_Pnt& _Pp = PStartf.Value();
1021 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1022 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1023 Quad.Parameters(_Pp,_u1,_v1);
1024 _u2=_p2d.X(); _v2=_p2d.Y();
1026 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1027 Quad.Parameters(_Pp,_u2,_v2);
1028 _u1=_p2d.X(); _v1=_p2d.Y();
1030 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1031 _thepointAtBeg.SetParameter(paramf);
1032 if(PStartf.IsNew()==Standard_False)
1033 _thepointAtBeg.SetVertex(reversed,_vtx);
1034 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1037 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1038 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1039 norm1 = d1u1.Crossed(d1v1);
1040 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1041 norm2 = d1u2.Crossed(d1v2);
1043 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1045 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1048 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1050 _u1=tgline.DotCross(norm2,norm1);
1051 TransitionOK=Standard_True;
1052 if (_u1 > 0.00000001) {
1053 trans1 = IntSurf_Out;
1054 trans2 = IntSurf_In;
1056 else if(_u1 < -0.00000001) {
1057 trans1 = IntSurf_In;
1058 trans2 = IntSurf_Out;
1061 TransitionOK=Standard_False;
1064 if(thesegm.HasLastPoint()) {
1065 Standard_Real _u1,_v1,_u2,_v2;
1067 dolast = Standard_True;
1068 PStartl = thesegm.LastPoint();
1069 paraml = PStartl.Parameter();
1071 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1072 Handle(Adaptor3d_HVertex) _vtx;
1073 if(PStartl.IsNew()==Standard_False)
1074 _vtx = PStartl.Vertex();
1075 const gp_Pnt& _Pp = PStartl.Value();
1076 IntPatch_Point _thepoint;
1077 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1078 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1079 Quad.Parameters(_Pp,_u1,_v1);
1080 _u2=_p2d.X(); _v2=_p2d.Y();
1082 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1083 Quad.Parameters(_Pp,_u2,_v2);
1084 _u1=_p2d.X(); _v1=_p2d.Y();
1086 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1087 _thepointAtEnd.SetParameter(paraml);
1088 if(PStartl.IsNew()==Standard_False)
1089 _thepointAtEnd.SetVertex(reversed,_vtx);
1090 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1094 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1095 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1096 norm1 = d1u1.Crossed(d1v1);
1097 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1098 norm2 = d1u2.Crossed(d1v2);
1100 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1102 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1105 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1107 _u1=tgline.DotCross(norm2,norm1);
1108 TransitionOK=Standard_True;
1109 if (_u1 > 0.00000001) {
1110 trans1 = IntSurf_Out;
1111 trans2 = IntSurf_In;
1113 else if(_u1 < -0.00000001) {
1114 trans1 = IntSurf_In;
1115 trans2 = IntSurf_Out;
1118 TransitionOK=Standard_False;
1121 if(TransitionOK==Standard_False) {
1122 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1123 rline = new IntPatch_RLine (Standard_False);
1125 rline->SetArcOnS1(thesegm.Curve());
1128 rline->SetArcOnS2(thesegm.Curve());
1132 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1133 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1135 rline->SetArcOnS1(thesegm.Curve());
1138 rline->SetArcOnS2(thesegm.Curve());
1142 //------------------------------
1143 //-- Ajout des points
1145 if (thesegm.HasFirstPoint()) {
1146 rline->AddVertex(_thepointAtBeg);
1147 rline->SetFirstPoint(rline->NbVertex());
1150 if (thesegm.HasLastPoint()) {
1151 rline->AddVertex(_thepointAtEnd);
1152 rline->SetLastPoint(rline->NbVertex());
1155 // Polygone sur restriction solution
1156 if (dofirst && dolast) {
1159 IntSurf_PntOn2S p2s;
1160 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1161 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1162 Standard_Integer nbsample = 100;
1165 for (j=1; j<=nbsample; j++) {
1166 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1167 arcsegm->D0(prm,p2d);
1168 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1170 Quad.Parameters(ptpoly,U1,V1);
1171 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1176 for (j=1; j<=nbsample; j++) {
1177 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1178 arcsegm->D0(prm,p2d);
1179 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1181 Quad.Parameters(ptpoly,U2,V2);
1182 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1189 if (dofirst || dolast) {
1190 Nblines = slin.Length();
1191 for (j=1; j<=Nblines; j++) {
1192 const Handle(IntPatch_Line)& slinj = slin(j);
1193 typ = slinj->ArcType();
1194 if (typ == IntPatch_Walking) {
1195 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1198 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1200 for (k=1; k<=Nbpts;k++) {
1201 if (typ == IntPatch_Walking) {
1202 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1205 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1209 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1210 ptdeb.SetMultiple(Standard_True);
1211 if (typ == IntPatch_Walking) {
1212 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1215 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1217 ptdeb.SetParameter(paramf);
1218 rline->AddVertex(ptdeb);
1220 procf=Standard_True;
1221 rline->SetFirstPoint(rline->NbVertex());
1226 if(dofirst) { //-- on recharge le ptdeb
1227 if (typ == IntPatch_Walking) {
1228 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1231 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1234 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1235 ptdeb.SetMultiple(Standard_True);
1236 if (typ == IntPatch_Walking) {
1237 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1240 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1242 ptdeb.SetParameter(paraml);
1243 rline->AddVertex(ptdeb);
1245 procl=Standard_True;
1246 rline->SetLastPoint(rline->NbVertex());
1257 // on traite les restrictions de la surface implicite
1258 for (i=1; i<=slin.Length(); i++)
1261 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1263 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1265 empt = (slin.Length() == 0 && spnt.Length() == 0);
1266 done = Standard_True;
1268 // post processing for cones and spheres
1269 if((Quad.TypeQuadric() == GeomAbs_Cone ||
1270 Quad.TypeQuadric() == GeomAbs_Sphere) &&
1273 Handle(Adaptor3d_TopolTool) PDomain = (reversed) ? D1 : D2;
1274 Handle(Adaptor3d_HSurface) QSurf = (reversed) ? Surf2 : Surf1;
1276 IntPatch_SequenceOfLine dslin;
1277 for(i = 1; i <= slin.Length(); i++ )
1278 DecomposeResult(slin(i),reversed,Quad,PDomain,QSurf,TolArc,dslin);
1281 for(i = 1; i <= dslin.Length(); i++ )
1282 slin.Append(dslin(i));
1286 //==================================================================
1287 // Decomposition of WLine goes through seam and/or apex routines
1288 //==================================================================
1290 // reject all points and vertices not in V range on Quadric
1291 static Handle(IntSurf_LineOn2S) VSplitLine(Handle(IntSurf_LineOn2S)& Line,
1292 Standard_Boolean IsReversed,
1293 Handle(Adaptor3d_HSurface)& QSurf,
1294 Handle(IntSurf_LineOn2S)& Vertices)
1296 Handle(IntSurf_LineOn2S) line = new IntSurf_LineOn2S();
1298 Standard_Real VF = QSurf->FirstVParameter();
1299 Standard_Real VL = QSurf->LastVParameter();
1301 Standard_Integer i = 0;
1302 Standard_Real U = 0., V = 0.;
1304 for(i = 1; i <= Line->NbPoints(); i++) {
1306 const IntSurf_PntOn2S& aP = Line->Value(i);
1308 aP.ParametersOnS2(U,V); // S2 - quadric
1310 aP.ParametersOnS1(U,V); // S1 - quadric
1312 if(VF <= V && V <= VL)
1316 Standard_Boolean isDeleted = Standard_True;
1317 Standard_Integer k = 0;
1320 isDeleted = Standard_False;
1323 for(i = 1; i <= Vertices->NbPoints(); i++) {
1325 const IntSurf_PntOn2S& aV = Vertices->Value(i);
1327 aV.ParametersOnS2(U,V); // S2 - quadric
1329 aV.ParametersOnS1(U,V); // S1 - quadric
1331 if(VF <= V && V <= VL)
1340 isDeleted = Standard_True;
1341 Vertices->RemovePoint(k);
1350 // correct U parameter of the start point of line on Quadric
1351 // (change 0->2PI or vs, if necessary)
1352 static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1354 Standard_Real u = U1;
1356 // case: no adjustment
1357 if( U1 > 0. && U1 < (2.*M_PI) )
1361 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
1362 if( U2 > 0. && U2 < (2.*M_PI) )
1363 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1365 Standard_Real uu = U2;
1366 if( U2 > (2.*M_PI) )
1367 while( uu > (2.*M_PI) )
1373 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1377 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1378 if( U2 > 0. && U2 < (2.*M_PI) )
1379 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1381 Standard_Real uu = U2;
1382 if( U2 > (2.*M_PI) )
1383 while( uu > (2.*M_PI) )
1389 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1392 // case: '<0. || >2PI'
1398 while(u > (2.*M_PI))
1405 // collect vertices, reject equals
1406 static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1407 const Standard_Boolean ,//IsReversed,
1408 const Standard_Real TOL3D,
1409 const Standard_Real TOL2D)
1411 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1413 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1415 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1416 Standard_Integer i = 0, k = 0;
1417 Standard_Integer NbVrt = WLine->NbVertex();
1419 TColStd_Array1OfInteger anVrts(1,NbVrt);
1422 // check equal vertices
1423 for(i = 1; i <= NbVrt; i++) {
1425 if( anVrts(i) == -1 ) continue;
1427 const IntPatch_Point& Pi = WLine->Vertex(i);
1429 for(k = (i+1); k <= NbVrt; k++) {
1431 if( anVrts(k) == -1 ) continue;
1433 const IntPatch_Point& Pk = WLine->Vertex(k);
1435 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
1436 // suggest the points are equal;
1437 // test 2d parameters on surface
1438 Standard_Boolean sameU1 = Standard_False;
1439 Standard_Boolean sameV1 = Standard_False;
1440 Standard_Boolean sameU2 = Standard_False;
1441 Standard_Boolean sameV2 = Standard_False;
1443 Pi.ParametersOnS1(U1,V1);
1444 Pk.ParametersOnS1(U2,V2);
1445 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1446 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1448 Pi.ParametersOnS2(U1,V1);
1449 Pk.ParametersOnS2(U2,V2);
1450 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1451 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1453 if((sameU1 && sameV1) && (sameU2 && sameV2))
1459 // copy further processed vertices
1460 for(i = 1; i <= NbVrt; i++) {
1461 if( anVrts(i) == -1 ) continue;
1462 vertices->Add(WLine->Vertex(i).PntOn2S());
1467 static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1468 const IntSurf_PntOn2S& P2)
1470 Standard_Boolean result = Standard_False;
1471 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1472 const gp_Pnt& P3D1 = P1.Value();
1473 const gp_Pnt& P3D2 = P2.Value();
1474 if(P3D1.Distance(P3D2) <= T3D) {
1475 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1476 P1.ParametersOnS1(U1,V1);
1477 P1.ParametersOnS2(U2,V2);
1478 P2.ParametersOnS1(U3,V3);
1479 P2.ParametersOnS2(U4,V4);
1480 gp_Pnt2d P2D11(U1,V1);
1481 gp_Pnt2d P2D12(U2,V2);
1482 gp_Pnt2d P2D21(U3,V3);
1483 gp_Pnt2d P2D22(U4,V4);
1484 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1485 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1486 if(sameS1 && sameS2)
1487 result = Standard_True;
1492 static void ForcedPurgePoints(Handle(IntSurf_LineOn2S)& Result,
1493 Standard_Boolean IsReversed,
1494 IntSurf_Quadric& Quad)
1496 if(Result->NbPoints() <= 30) return;
1497 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1499 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1501 Result->Value(1).ParametersOnS2(U1,V1);
1502 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1505 Result->Value(1).ParametersOnS1(U1,V1);
1506 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
1509 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1510 Standard_Real Uapx = 0., Vapx = 0.;
1511 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1513 if(fabs(V1-Vapx) <= 1.e-3)
1515 if(fabs(V2-Vapx) <= 1.e-3)
1519 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
1520 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
1522 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1524 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1528 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1529 Result->RemovePoint(2);
1533 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1534 Result->RemovePoint(Result->NbPoints()-1);
1539 // DEBUG FUNCTION !!!
1541 static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1542 Standard_Boolean IsReversed,
1543 Standard_Integer Number)
1545 cout << "DUMP LINE" << endl;
1548 for(i = 1; i <= Line->NbPoints(); i++) {
1549 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1551 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1553 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1554 cout << "point p" << i << " " << U << " " << V << endl;
1560 // DEBUG FUNCTION !!!
1562 static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1563 const Handle(IntSurf_LineOn2S)& Vertices,
1564 TColStd_Array1OfInteger& PTypes)
1566 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1567 Standard_Integer ip = 0, iv = 0;
1568 for(ip = 1; ip <= nbp; ip++) {
1569 const IntSurf_PntOn2S& aP = Line->Value(ip);
1570 Standard_Integer type = 0;
1571 for(iv = 1; iv <= nbv; iv++) {
1572 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1573 if(AreSamePoints(aP,aV)) {
1582 static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1583 const Standard_Real TOL2D)
1585 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
1588 static inline Standard_Real AdjustU(const Standard_Real U)
1590 Standard_Real u = U, DBLPI = 2.*M_PI;
1591 if(u < 0. || u > DBLPI) {
1602 static inline void Correct2DBounds(const Standard_Real UF,
1603 const Standard_Real UL,
1604 const Standard_Real VF,
1605 const Standard_Real VL,
1606 const Standard_Real TOL2D,
1610 Standard_Real Eps = 1.e-16;
1611 Standard_Real dUF = fabs(U - UF);
1612 Standard_Real dUL = fabs(U - UL);
1613 Standard_Real dVF = fabs(V - VF);
1614 Standard_Real dVL = fabs(V - VL);
1615 if(dUF <= TOL2D && dUF > Eps) U = UF;
1616 if(dUL <= TOL2D && dUL > Eps) U = UL;
1617 if(dVF <= TOL2D && dVF > Eps) V = VF;
1618 if(dVL <= TOL2D && dVL > Eps) V = VL;
1621 static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1622 const Standard_Boolean IsReversed,
1623 const Handle(Adaptor3d_HSurface)& QSurf,
1624 const Standard_Real TOL2D)
1626 Standard_Real VF = QSurf->FirstVParameter();
1627 Standard_Real VL = QSurf->LastVParameter();
1628 Standard_Real UF = QSurf->FirstUParameter();
1629 Standard_Real UL = QSurf->LastUParameter();
1631 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1632 Standard_Real U = 0., V = 0.;
1633 for(ip = 1; ip <= nbp; ip++) {
1635 Line->Value(ip).ParametersOnS2(U,V);
1637 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1638 Line->SetUV(ip,Standard_False,U,V);
1641 Line->Value(ip).ParametersOnS1(U,V);
1643 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1644 Line->SetUV(ip,Standard_True,U,V);
1649 static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
1650 const Standard_Boolean IsReversed,
1651 Handle(IntSurf_LineOn2S)& Vertices,
1652 const TColStd_Array1OfInteger& PTypes,
1653 const Standard_Real TOL2D)
1655 Standard_Boolean result = Standard_False;
1656 Standard_Integer ip = 0, nbp = Line->NbPoints();
1657 Standard_Real U = 0., V = 0.;
1658 for(ip = 1; ip <= nbp; ip++) {
1659 Standard_Integer ipt = PTypes(ip);
1661 const IntSurf_PntOn2S& aP = Line->Value(ip);
1663 aP.ParametersOnS2(U,V); // S2 - quadric
1665 aP.ParametersOnS1(U,V); // S1 - quadric
1667 if(IsSeamParameter(U,TOL2D)) {
1668 if(ip == 1 || ip == nbp) {
1669 Standard_Real U1 = 0., V1 = 0.;
1670 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1672 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1674 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1675 Standard_Real u = AdjustUFirst(U,U1);
1676 if(fabs(u-U) >= 1.5*M_PI) {
1677 Standard_Real U2 = 0., V2 = 0.;
1679 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1680 Line->SetUV(ip,Standard_False,u,V);
1681 Line->SetUV(ip,Standard_True,U2,V2);
1684 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1685 Line->SetUV(ip,Standard_True,u,V);
1686 Line->SetUV(ip,Standard_False,U2,V2);
1691 Standard_Integer ipp = ip - 1;
1692 Standard_Integer ipn = ip + 1;
1693 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1695 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1696 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1699 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1700 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1704 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1705 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1706 if(pnearZero == cnearZero) {
1707 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1708 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1710 nP.SetValue(aP.Value());
1711 Standard_Real U3 = 0., V3 = 0.;
1713 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1714 nP.SetValue(Standard_False,nU,V);
1715 nP.SetValue(Standard_True,U3,V3);
1718 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1719 nP.SetValue(Standard_True,nU,V);
1720 nP.SetValue(Standard_False,U3,V3);
1722 Line->InsertBefore(ipn,nP);
1724 result = Standard_True;
1729 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1730 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1732 nP.SetValue(aP.Value());
1733 Standard_Real U3 = 0., V3 = 0.;
1735 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1736 nP.SetValue(Standard_False,nU,V);
1737 nP.SetValue(Standard_True,U3,V3);
1740 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1741 nP.SetValue(Standard_True,nU,V);
1742 nP.SetValue(Standard_False,U3,V3);
1744 Line->InsertBefore(ip,nP);
1746 result = Standard_True;
1750 // Line->InsertBefore(ip,Line->Value(ipn));
1751 // Line->RemovePoint(ip+2);
1752 // result = Standard_True;
1753 // cout << "swap vertex " << endl;
1764 static void ToSmooth(Handle(IntSurf_LineOn2S)& Line,
1765 Standard_Boolean IsReversed,
1766 IntSurf_Quadric& Quad,
1767 Standard_Boolean IsFirst,
1770 if(Line->NbPoints() <= 10)
1774 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1775 if(NbTestPnts < 5) NbTestPnts = 5;
1777 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1778 Standard_Integer ip = 0;
1779 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1781 for(ip = startp; ip <= NbTestPnts; ip++) {
1783 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1784 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1787 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1788 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1790 DDU += fabs(fabs(Uc)-fabs(Un));
1791 DDV += fabs(fabs(Vc)-fabs(Vn));
1794 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1799 DDU /= (Standard_Real) NbTestPnts + 1;
1800 DDV /= (Standard_Real) NbTestPnts + 1;
1802 D3D /= (Standard_Real) NbTestPnts + 1;
1805 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1806 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1807 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1809 Standard_Boolean doU = Standard_False;
1810 Standard_Boolean doV = Standard_False;
1812 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1815 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1816 Line->Value(Index2).ParametersOnS2(U2,V2);
1817 Line->Value(Index3).ParametersOnS2(U3,V3);
1820 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1821 Line->Value(Index2).ParametersOnS1(U2,V2);
1822 Line->Value(Index3).ParametersOnS1(U3,V3);
1825 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
1826 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
1828 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1829 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
1831 doU = Standard_False;
1836 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1837 Standard_Real Uapx = 0., Vapx = 0.;
1838 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1840 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
1842 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1843 if(fabs(V1-Vapx) <= 1.e-9) {}
1845 doU = Standard_False;
1850 if(fabs(fabs(V1)-fabs(V2)) > DDV) doV = Standard_True;
1853 Standard_Real dU = Min((DDU/10.),5.e-8);
1854 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1856 Line->SetUV(Index1,Standard_False,U,V1);
1858 Line->SetUV(Index1,Standard_True,U,V1);
1863 static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
1864 const IntSurf_PntOn2S& aV,
1865 const Standard_Boolean IsReversed,
1866 const Standard_Real ArcTol,
1867 Handle(Adaptor3d_TopolTool)& PDomain)
1870 Standard_Boolean result = Standard_False;
1871 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1873 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1874 aV.ParametersOnS1(Uv,Vv);
1877 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1878 aV.ParametersOnS2(Uv,Vv);
1880 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
1881 gp_Pnt2d a2DPntM(Um,Vm);
1882 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
1883 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
1884 result = Standard_True;
1888 static void VerifyVertices(Handle(IntSurf_LineOn2S)& Line,
1889 Standard_Boolean IsReversed,
1890 Handle(IntSurf_LineOn2S)& Vertices,
1891 Standard_Real TOL2D,
1892 const Standard_Real ArcTol,
1893 Handle(Adaptor3d_TopolTool)& PDomain,
1894 IntSurf_PntOn2S& VrtF,
1895 Standard_Boolean& AddFirst,
1896 IntSurf_PntOn2S& VrtL,
1897 Standard_Boolean& AddLast)
1899 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1900 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
1901 const IntSurf_PntOn2S& aPF = Line->Value(1);
1902 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
1903 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
1905 aPF.ParametersOnS2(UF,VF);
1906 aPL.ParametersOnS2(UL,VL);
1909 aPF.ParametersOnS1(UF,VF);
1910 aPL.ParametersOnS1(UL,VL);
1912 gp_Pnt2d a2DPF(UF,VF);
1913 gp_Pnt2d a2DPL(UL,VL);
1914 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
1915 Standard_Integer FConjugated = 0, LConjugated = 0;
1917 Standard_Integer iv = 0;
1919 for(iv = 1; iv <= nbv; iv++) {
1920 Standard_Real Uv = 0., Vv = 0.;
1922 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1924 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1927 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1929 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1933 for(iv = 1; iv <= nbv; iv++) {
1934 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1935 if(AreSamePoints(aPF,aV)) {
1940 Standard_Real Uv = 0., Vv = 0.;
1942 aV.ParametersOnS2(Uv,Vv);
1944 aV.ParametersOnS1(Uv,Vv);
1945 gp_Pnt2d a2DV(Uv,Vv);
1946 Standard_Real Dist = a2DV.Distance(a2DPF);
1947 if(Dist < DistMinF) {
1950 if(FConjugated != 0)
1953 if(IsSeamParameter(Uv,TOL2D)) {
1954 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1955 gp_Pnt2d a2DCV(Ucv,Vv);
1956 Standard_Real CDist = a2DCV.Distance(a2DPF);
1957 if(CDist < DistMinF) {
1966 for(iv = 1; iv <= nbv; iv++) {
1967 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1968 if(AreSamePoints(aPL,aV)) {
1973 Standard_Real Uv = 0., Vv = 0.;
1975 aV.ParametersOnS2(Uv,Vv);
1977 aV.ParametersOnS1(Uv,Vv);
1978 gp_Pnt2d a2DV(Uv,Vv);
1979 Standard_Real Dist = a2DV.Distance(a2DPL);
1980 if(Dist < DistMinL) {
1983 if(LConjugated != 0)
1986 if(IsSeamParameter(Uv,TOL2D)) {
1987 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1988 gp_Pnt2d a2DCV(Ucv,Vv);
1989 Standard_Real CDist = a2DCV.Distance(a2DPL);
1990 if(CDist < DistMinL) {
1999 AddFirst = Standard_False;
2000 AddLast = Standard_False;
2002 if(FIndexSame == 0) {
2003 if(FIndexNear != 0) {
2004 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2005 Standard_Real Uv = 0., Vv = 0.;
2007 aV.ParametersOnS2(Uv,Vv);
2009 aV.ParametersOnS1(Uv,Vv);
2010 if(IsSeamParameter(Uv,TOL2D)) {
2011 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2012 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2014 VrtF.SetValue(aV.Value());
2016 Standard_Real U2 = 0., V2 = 0.;
2017 aV.ParametersOnS1(U2,V2); // S1 - prm
2018 VrtF.SetValue(Standard_True,U2,V2);
2019 if(FConjugated == 0)
2020 VrtF.SetValue(Standard_False,Uv,Vv);
2022 VrtF.SetValue(Standard_False,Ucv,Vv);
2025 Standard_Real U2 = 0., V2 = 0.;
2026 aV.ParametersOnS2(U2,V2); // S2 - prm
2027 VrtF.SetValue(Standard_False,U2,V2);
2028 if(FConjugated == 0)
2029 VrtF.SetValue(Standard_True,Uv,Vv);
2031 VrtF.SetValue(Standard_True,Ucv,Vv);
2033 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2034 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2035 AddFirst = Standard_True;
2040 // to do: analyze internal vertex
2045 if(LIndexSame == 0) {
2046 if(LIndexNear != 0) {
2047 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2048 Standard_Real Uv = 0., Vv = 0.;
2050 aV.ParametersOnS2(Uv,Vv);
2052 aV.ParametersOnS1(Uv,Vv);
2053 if(IsSeamParameter(Uv,TOL2D)) {
2054 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2055 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2057 VrtL.SetValue(aV.Value());
2059 Standard_Real U2 = 0., V2 = 0.;
2060 aV.ParametersOnS1(U2,V2); // S1 - prm
2061 VrtL.SetValue(Standard_True,U2,V2);
2062 if(LConjugated == 0)
2063 VrtL.SetValue(Standard_False,Uv,Vv);
2065 VrtL.SetValue(Standard_False,Ucv,Vv);
2068 Standard_Real U2 = 0., V2 = 0.;
2069 aV.ParametersOnS2(U2,V2); // S2 - prm
2070 VrtL.SetValue(Standard_False,U2,V2);
2071 if(LConjugated == 0)
2072 VrtL.SetValue(Standard_True,Uv,Vv);
2074 VrtL.SetValue(Standard_True,Ucv,Vv);
2076 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2077 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2078 AddLast = Standard_True;
2083 // to do: analyze internal vertex
2089 static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
2090 const IntSurf_PntOn2S& VrtF,
2091 const Standard_Boolean AddFirst,
2092 const IntSurf_PntOn2S& VrtL,
2093 const Standard_Boolean AddLast,
2094 const Standard_Real D3DF,
2095 const Standard_Real D3DL)
2097 Standard_Boolean result = Standard_False;
2099 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2100 if((D3DF*2.) > DF && DF > 1.5e-7) {
2101 Line->InsertBefore(1,VrtF);
2102 result = Standard_True;
2106 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2107 if((D3DL*2.) > DL && DL > 1.5e-7) {
2109 result = Standard_True;
2116 static void PutIntVertices(Handle(IntPatch_Line)& Line,
2117 Handle(IntSurf_LineOn2S)& Result,
2118 Standard_Boolean ,//IsReversed,
2119 Handle(IntSurf_LineOn2S)& Vertices,
2120 const Standard_Real ArcTol)
2122 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2127 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2128 Standard_Integer ip = 0, iv = 0;
2130 IntPatch_Point thePnt;
2131 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2133 for(ip = 2; ip <= (nbp-1); ip++) {
2134 const IntSurf_PntOn2S& aP = Result->Value(ip);
2135 for(iv = 1; iv <= nbv; iv++) {
2136 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2137 if(AreSamePoints(aP,aV)) {
2138 aPnt = Result->Value(ip).Value();
2139 Result->Value(ip).ParametersOnS1(U1,V1);
2140 Result->Value(ip).ParametersOnS2(U2,V2);
2141 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2142 thePnt.SetParameters(U1,V1,U2,V2);
2143 thePnt.SetParameter((Standard_Real)ip);
2144 WLine->AddVertex(thePnt);
2150 static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2151 Handle(IntSurf_LineOn2S)& Vertices)
2153 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2154 Standard_Integer ip = 0, iv = 0;
2155 Standard_Boolean result = Standard_False;
2160 for(ip = 2; ip <= (nbp-1); ip++) {
2161 const IntSurf_PntOn2S& aP = Line->Value(ip);
2162 for(iv = 1; iv <= nbv; iv++) {
2163 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2164 if(AreSamePoints(aP,aV)) {
2165 result = Standard_True;
2175 static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
2176 Standard_Boolean Tang,
2177 IntSurf_TypeTrans Trans1,
2178 IntSurf_TypeTrans Trans2,
2179 Standard_Real ArcTol,
2180 Standard_Integer ParFirst,
2181 Standard_Integer ParLast)
2183 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2184 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2186 Standard_Integer ip = 0;
2187 for(ip = ParFirst; ip <= ParLast; ip++)
2188 sline->Add(SLine->Value(ip));
2190 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2193 IntPatch_Point TPntF,TPntL;
2194 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2196 aSPnt = sline->Value(1).Value();
2197 sline->Value(1).ParametersOnS1(uu1,vv1);
2198 sline->Value(1).ParametersOnS2(uu2,vv2);
2199 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2200 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2201 TPntF.SetParameter(1.);
2202 wline->AddVertex(TPntF);
2203 wline->SetFirstPoint(1);
2205 aSPnt = sline->Value(sline->NbPoints()).Value();
2206 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2207 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2208 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2209 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2210 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2211 wline->AddVertex(TPntL);
2212 wline->SetLastPoint(sline->NbPoints());
2217 static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
2218 Standard_Boolean Tang,
2219 IntSurf_TypeTrans Trans1,
2220 IntSurf_TypeTrans Trans2,
2221 Standard_Real ArcTol,
2222 IntPatch_SequenceOfLine& Segments)
2224 Standard_Boolean result = Standard_False;
2227 Standard_Integer nbv = WLine->NbVertex();
2229 Standard_Integer iv = 0;
2230 for(iv = 1; iv < nbv; iv++) {
2231 Standard_Integer firstPar = (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2232 Standard_Integer lastPar = (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
2233 if((lastPar - firstPar) <= 1)
2236 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,ArcTol,firstPar,lastPar);
2237 Segments.Append(splitwline);
2239 result = Standard_True;
2246 void DecomposeResult(Handle(IntPatch_Line)& Line,
2247 Standard_Boolean IsReversed,
2248 IntSurf_Quadric& Quad,
2249 Handle(Adaptor3d_TopolTool)& PDomain,
2250 Handle(Adaptor3d_HSurface)& QSurf,
2251 Standard_Real ArcTol,
2252 IntPatch_SequenceOfLine& Lines)
2254 if( Line->ArcType() != IntPatch_Walking ) {
2259 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2260 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2262 if(SLine->NbPoints() <= 2) {
2267 Standard_Real TOL3D = 1.e-10, TOL2D = 1.e-8, TOL2DS = 1.e-5;
2269 Handle(IntSurf_LineOn2S) vline = GetVertices(WLine,IsReversed,TOL3D,TOL2D);
2270 Handle(IntSurf_LineOn2S) SSLine = VSplitLine(SLine,IsReversed,QSurf,vline);
2272 if(SSLine->NbPoints() <= 1)
2275 AdjustLine(SSLine,IsReversed,QSurf,TOL2D);
2277 Standard_Boolean isInserted = Standard_True;
2279 Standard_Integer NbPnts = SSLine->NbPoints();
2280 TColStd_Array1OfInteger ptypes(1,NbPnts);
2281 SearchVertices(SSLine,vline,ptypes);
2282 isInserted = InsertSeamVertices(SSLine,IsReversed,vline,ptypes,TOL2D);
2285 if(SSLine->NbPoints() == 2) {
2286 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2288 SSLine->Value(1).ParametersOnS2(uu1,vv1);
2289 SSLine->Value(2).ParametersOnS2(uu2,vv2);
2292 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2293 SSLine->Value(2).ParametersOnS1(uu2,vv2);
2295 gp_Pnt2d p1(uu1,vv1);
2296 gp_Pnt2d p2(uu2,vv2);
2297 if(p1.Distance(p2) > 2.e-7) {
2298 Standard_Real Dist3D = SSLine->Value(1).Value().Distance(SSLine->Value(2).Value());
2299 if(Dist3D > 3.e-7) {
2301 IntPatch_Point TPntF,TPntL;
2302 Handle(IntPatch_WLine) wline = new IntPatch_WLine(SSLine,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2303 aSPnt = SSLine->Value(1).Value();
2304 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2305 SSLine->Value(1).ParametersOnS2(uu2,vv2);
2306 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2307 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2308 TPntF.SetParameter(1.);
2309 wline->AddVertex(TPntF);
2310 wline->SetFirstPoint(1);
2311 aSPnt = SSLine->Value(SSLine->NbPoints()).Value();
2312 SSLine->Value(SSLine->NbPoints()).ParametersOnS1(uu1,vv1);
2313 SSLine->Value(SSLine->NbPoints()).ParametersOnS2(uu2,vv2);
2314 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2315 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2316 TPntL.SetParameter(SSLine->NbPoints());
2317 wline->AddVertex(TPntL);
2318 wline->SetLastPoint(SSLine->NbPoints());
2319 Lines.Append(wline);
2329 Standard_Integer NbPnts = SSLine->NbPoints();
2331 Standard_Real BSEAM = 1.5*M_PI; // delta U crossing seam
2332 Standard_Real BAPEX = M_PI/16.; // delta U crossing apex
2334 Standard_Integer k = 0;
2335 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0., AnV1 = 0., DU1 = 0., DV1 = 0.;
2336 Standard_Integer Findex = 1, Lindex = NbPnts, Bindex = 0;
2339 IntPatch_Point TPntF,TPntL,TPntS;
2341 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2342 Handle(IntPatch_WLine) wline;
2343 IntPatch_SequenceOfLine lines;
2345 // build WLine parts (if any)
2348 //if((Lindex-Findex+1) <= 2 )
2349 if((Lindex-Findex+1) <= 1 )
2353 Standard_Boolean isDecomposited = Standard_False;
2354 Standard_Boolean is2PIDecomposed = Standard_False;
2355 U1 = 0.; V1 = 0.; U2 = 0.; V2 = 0.; AnU1 = 0.; AnV1 = 0.; DU1 = 0.; DV1 = 0.;
2357 // analyze other points
2358 for(k = Findex; k <= Lindex; k++) {
2363 SSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2366 SSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2368 sline->Add(SSLine->Value(k));
2374 SSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2377 SSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2380 Standard_Real DeltaU = fabs(U1-AnU1);
2381 if(DeltaU > BSEAM) {
2383 isDecomposited = Standard_True;
2384 is2PIDecomposed = Standard_True;
2387 else if((DeltaU > BAPEX) && (k >= (Findex+10) && k <= (Lindex-10))) {
2389 isDecomposited = Standard_True;
2394 sline->Add(SSLine->Value(k));
2399 IntSurf_PntOn2S aVF,aVL;
2400 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2401 VerifyVertices(sline,IsReversed,vline,TOL2DS,ArcTol,PDomain,aVF,addVF,aVL,addVL);
2403 Standard_Boolean hasInternals = HasInternals(sline,vline);
2405 Standard_Real D3F = 0., D3L = 0.;
2406 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2407 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2409 if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2410 D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2412 if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2413 D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->Value(sline->NbPoints()-2).Value());
2416 if(addVF || addVL) {
2417 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2419 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2420 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2425 ForcedPurgePoints(sline,IsReversed,Quad);
2428 wline = new IntPatch_WLine(sline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2430 aSPnt = sline->Value(1).Value();
2431 sline->Value(1).ParametersOnS1(U1,V1);
2432 sline->Value(1).ParametersOnS2(U2,V2);
2433 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2434 TPntF.SetParameters(U1,V1,U2,V2);
2435 TPntF.SetParameter(1.);
2436 wline->AddVertex(TPntF);
2437 wline->SetFirstPoint(1);
2440 PutIntVertices(wline,sline,IsReversed,vline,ArcTol);
2443 aSPnt = sline->Value(sline->NbPoints()).Value();
2444 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2445 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2446 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2447 TPntL.SetParameters(U1,V1,U2,V2);
2448 TPntL.SetParameter(sline->NbPoints());
2449 wline->AddVertex(TPntL);
2450 wline->SetLastPoint(sline->NbPoints());
2452 IntPatch_SequenceOfLine segm;
2453 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2(),ArcTol,segm);
2456 Lines.Append(wline);
2458 Standard_Integer nbsegms = segm.Length();
2459 Standard_Integer iseg = 0;
2460 for(iseg = 1; iseg <= nbsegms; iseg++)
2461 Lines.Append(segm(iseg));
2464 if(isDecomposited) {
2466 sline = new IntSurf_LineOn2S();
2473 Standard_Integer aNbPnts;
2474 Standard_Real aU1,aV1,aU2,aV2;
2477 aNbPnts=thelin->NbPoints();
2478 printf(" WLine: aNbPnts=%d\n", aNbPnts);
2479 for(i=1; i <= aNbPnts; ++i) {
2480 const IntSurf_PntOn2S& aPoint = thelin->Value(i);
2482 aPoint.Parameters(aU1, aV1, aU2, aV2);
2483 printf(" point %d %lf %lf %lf %lf %lf %lf %lf\n",
2484 i, aPx.X(), aPx.Y(), aPx.Z(), aU1, aV1, aU2, aV2);