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;
383 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
384 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
385 case GeomAbs_Cylinder:
388 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
389 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
391 pt.SetParameters(U1,V1,U2,V2);
394 //=======================================================================
397 //=======================================================================
398 void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
399 const Handle(Adaptor3d_TopolTool)& D1,
400 const Handle(Adaptor3d_HSurface)& Surf2,
401 const Handle(Adaptor3d_TopolTool)& D2,
402 const Standard_Real TolArc,
403 const Standard_Real TolTang,
404 const Standard_Real Fleche,
405 const Standard_Real Pas)
407 Standard_Boolean reversed, procf, procl, dofirst, dolast;
408 Standard_Integer indfirst = 0, indlast = 0, ind2, i,j,k, NbSegm;
409 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
410 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
412 IntPatch_TheSegmentOfTheSOnBounds thesegm;
413 IntSurf_PathPoint PPoint;
415 Handle(IntPatch_RLine) rline;
416 Handle(IntPatch_WLine) wline;
417 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
418 IntPatch_Point ptdeb,ptfin,ptbis;
421 IntSurf_Transition TLine,TArc;
422 IntSurf_TypeTrans trans1,trans2;
424 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
431 Handle(Adaptor2d_HCurve2d) currentarc;
432 GeomAbs_SurfaceType typeS1, typeS2;
433 IntSurf_Quadric Quad;
434 IntPatch_TheSurfFunction Func;
435 IntPatch_ArcFunction AFunc;
437 typeS1 = Surf1->GetType();
438 typeS2 = Surf2->GetType();
442 trans1 = IntSurf_Undecided;
443 trans2 = IntSurf_Undecided;
445 done = Standard_False;
446 empt = Standard_True;
450 reversed = Standard_False;
453 Quad.SetValue(Surf1->Plane());
456 case GeomAbs_Cylinder:
457 Quad.SetValue(Surf1->Cylinder());
461 Quad.SetValue(Surf1->Sphere());
465 Quad.SetValue(Surf1->Cone());
469 reversed = Standard_True;
472 Quad.SetValue(Surf2->Plane());
475 case GeomAbs_Cylinder:
476 Quad.SetValue(Surf2->Cylinder());
480 Quad.SetValue(Surf2->Sphere());
484 Quad.SetValue(Surf2->Cone());
487 Standard_ConstructionError::Raise();
495 Func.SetImplicitSurface(Quad);
496 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
497 AFunc.SetQuadric(Quad);
509 solrst.Perform(AFunc,D2,TolArc,TolTang);
512 solrst.Perform(AFunc,D1,TolArc,TolTang);
514 if (!solrst.IsDone()) {
518 IntSurf_SequenceOfPathPoint seqpdep;
519 IntSurf_SequenceOfInteriorPoint seqpins;
521 NbPointRst = solrst.NbPoints();
522 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
525 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
528 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
532 // Recherche des points interieurs
535 solins.Perform(Func,Surf2,myUStart,myVStart);
537 solins.Perform(Func,Surf2,D2,TolTang);
541 solins.Perform(Func,Surf1,myUStart,myVStart);
543 solins.Perform(Func,Surf1,D1,TolTang);
546 NbPointIns = solins.NbPoints();
547 for (i=1; i <= NbPointIns; i++) {
548 seqpins.Append(solins.Value(i));
550 NbPointDep=seqpdep.Length();
552 if (NbPointDep || NbPointIns) {
553 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
555 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
558 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
560 if(!iwalk.IsDone()) {
564 Standard_Real Vmin, Vmax, TolV = 1.e-14;
565 if (!reversed) { //Surf1 is quadric
566 Vmin = Surf1->FirstVParameter();
567 Vmax = Surf1->LastVParameter();
569 else { //Surf2 is quadric
570 Vmin = Surf2->FirstVParameter();
571 Vmax = Surf2->LastVParameter();
574 Nblines = iwalk.NbLines();
575 for (j=1; j<=Nblines; j++) {
576 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
577 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
579 Nbpts = thelin->NbPoints();
582 tgline = iwline->TangentVector(k);
583 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
584 valpt = thelin->Value(k).Value();
587 thelin->Value(k).ParametersOnS2(U2,V2);
588 norm1 = Quad.Normale(valpt);
589 Surf2->D1(U2,V2,ptbid,d1u,d1v);
590 norm2 = d1u.Crossed(d1v);
593 thelin->Value(k).ParametersOnS1(U2,V2);
594 norm2 = Quad.Normale(valpt);
595 Surf1->D1(U2,V2,ptbid,d1u,d1v);
596 norm1 = d1u.Crossed(d1v);
598 if (tgline.DotCross(norm2,norm1) > 0.) {
599 trans1 = IntSurf_Out;
604 trans2 = IntSurf_Out;
608 Standard_Real AnU1,AnU2,AnV2;
610 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
611 Standard_Boolean arecadr=Standard_False;
612 valpt = thelin->Value(1).Value();
613 Quad.Parameters(valpt,AnU1,V1);
615 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
616 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
619 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
620 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
623 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
624 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
627 if(typQuad==GeomAbs_Cylinder ||
628 typQuad==GeomAbs_Cone ||
629 typQuad==GeomAbs_Sphere) {
630 arecadr=Standard_True;
633 for (k=2; k<=Nbpts; ++k) {
634 valpt = thelin->Value(k).Value();
635 Quad.Parameters(valpt,U1,V1);
637 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
640 if((V1 > Vmax) && (V1-Vmax < TolV)) {
645 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
646 Standard_Real aCf, aTwoPI;
650 if ((U1-AnU1) > 1.5*M_PI) {
651 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
658 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
664 //if ((U1-AnU1) > 1.5*M_PI) {
667 //else if ((U1-AnU1) < -1.5*M_PI) {
670 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
674 thelin->SetUV(k,Standard_False,U1,V1);
676 thelin->Value(k).ParametersOnS1(U2,V2);
678 case GeomAbs_Cylinder:
682 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
683 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
688 if(typeS2==GeomAbs_Torus) {
689 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
690 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
692 thelin->SetUV(k,Standard_True,U2,V2);
695 thelin->SetUV(k,Standard_True,U1,V1);
697 thelin->Value(k).ParametersOnS2(U2,V2);
699 case GeomAbs_Cylinder:
703 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
704 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
709 if(typeS2==GeomAbs_Torus) {
710 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
711 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
713 thelin->SetUV(k,Standard_False,U2,V2);
722 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
724 if ( iwline->HasFirstPoint()
725 && iwline->IsTangentAtBegining() == Standard_False) {
726 indfirst = iwline->FirstPointIndex();
727 PPoint = seqpdep(indfirst);
728 tgline = PPoint.Direction3d();
729 Standard_Integer themult = PPoint.Multiplicity();
730 for (i=NbPointRst; i>=1; i--) {
731 if (Destination(i) == indfirst) {
732 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
733 Quad.Parameters(PPoint.Value(),U1,V1);
735 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
736 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
738 PPoint.Parameters(themult,U2,V2);
739 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
741 else { //-- typeS1 != Pln && Cyl && Sph && Cone
742 Quad.Parameters(PPoint.Value(),U2,V2);
744 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
745 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
747 PPoint.Parameters(themult,U1,V1);
748 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
751 VecNormale = d1u.Crossed(d1v);
752 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
753 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
754 ptdeb.SetParameters(U1,V1,U2,V2);
755 ptdeb.SetParameter(1.);
757 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
759 currentarc = solrst.Point(i).Arc();
760 currentparam = solrst.Point(i).Parameter();
761 currentarc->D1(currentparam,p2d,d2d);
762 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
764 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
765 if(squaremagnitudeVecNormale > 1e-13) {
766 DirNormale=VecNormale;
767 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
770 TLine.SetValue(Standard_True,IntSurf_Undecided);
771 TArc.SetValue(Standard_True,IntSurf_Undecided);
774 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
775 if (!solrst.Point(i).IsNew()) {
776 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
778 wline->AddVertex(ptdeb);
780 wline->SetFirstPoint(wline->NbVertex());
787 else if (iwline->IsTangentAtBegining()) {
788 gp_Pnt psol = thelin->Value(1).Value();
789 thelin->Value(1).ParametersOnS1(U1,V1);
790 thelin->Value(1).ParametersOnS2(U2,V2);
791 ptdeb.SetValue(psol,TolArc,Standard_True);
792 ptdeb.SetParameters(U1,V1,U2,V2);
793 ptdeb.SetParameter(1.);
794 wline->AddVertex(ptdeb);
795 wline->SetFirstPoint(wline->NbVertex());
798 gp_Pnt psol = thelin->Value(1).Value();
799 thelin->Value(1).ParametersOnS1(U1,V1);
800 thelin->Value(1).ParametersOnS2(U2,V2);
801 ptdeb.SetValue(psol,TolArc,Standard_False);
802 ptdeb.SetParameters(U1,V1,U2,V2);
803 ptdeb.SetParameter(1.);
804 wline->AddVertex(ptdeb);
805 wline->SetFirstPoint(wline->NbVertex());
809 if ( iwline->HasLastPoint()
810 && iwline->IsTangentAtEnd() == Standard_False) {
811 indlast = iwline->LastPointIndex();
812 PPoint = seqpdep(indlast);
813 tgline = PPoint.Direction3d().Reversed();
814 Standard_Integer themult = PPoint.Multiplicity();
815 for (i=NbPointRst; i >=1; i--) {
816 if (Destination(i) == indlast) {
818 Quad.Parameters(PPoint.Value(),U1,V1);
820 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
821 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
823 PPoint.Parameters(themult,U2,V2);
824 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
825 VecNormale = d1u.Crossed(d1v); //-- @@@@
828 Quad.Parameters(PPoint.Value(),U2,V2);
830 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
831 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
833 PPoint.Parameters(themult,U1,V1);
834 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
835 VecNormale = d1u.Crossed(d1v); //-- @@@@
838 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
839 ptfin.SetParameters(U1,V1,U2,V2);
840 ptfin.SetParameter(Nbpts);
842 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
844 currentarc = solrst.Point(i).Arc();
845 currentparam = solrst.Point(i).Parameter();
846 currentarc->D1(currentparam,p2d,d2d);
847 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
850 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
851 if(squaremagnitudeVecNormale > 1e-13) {
852 DirNormale=VecNormale;
853 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
856 TLine.SetValue(Standard_True,IntSurf_Undecided);
857 TArc.SetValue(Standard_True,IntSurf_Undecided);
861 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
862 if (!solrst.Point(i).IsNew()) {
863 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
865 wline->AddVertex(ptfin);
867 wline->SetLastPoint(wline->NbVertex());
874 else if (iwline->IsTangentAtEnd()) {
875 gp_Pnt psol = thelin->Value(Nbpts).Value();
876 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
877 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
878 ptfin.SetValue(psol,TolArc,Standard_True);
879 ptfin.SetParameters(U1,V1,U2,V2);
880 ptfin.SetParameter(Nbpts);
881 wline->AddVertex(ptfin);
882 wline->SetLastPoint(wline->NbVertex());
885 gp_Pnt psol = thelin->Value(Nbpts).Value();
886 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
887 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
888 ptfin.SetValue(psol,TolArc,Standard_False);
889 ptfin.SetParameters(U1,V1,U2,V2);
890 ptfin.SetParameter(Nbpts);
891 wline->AddVertex(ptfin);
892 wline->SetLastPoint(wline->NbVertex());
895 // Il faut traiter les points de passage.
898 }// for (j=1; j<=Nblines; j++) {
900 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
901 // QUE SUR DES POINTS DE TANGENCE
904 Nblines = slin.Length();
905 for (j=1; j<=Nblines-1; j++) {
906 dofirst = dolast = Standard_False;
907 const Handle(IntPatch_Line)& slinj = slin(j);
908 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
909 if (wlin1->HasFirstPoint()) {
910 ptdeb = wlin1->FirstPoint(indfirst);
911 if (ptdeb.IsTangencyPoint()) {
912 dofirst = Standard_True;
915 if (wlin1->HasLastPoint()) {
916 ptfin = wlin1->LastPoint(indlast);
917 if (ptfin.IsTangencyPoint()) {
918 dolast = Standard_True;
922 if (dofirst || dolast) {
923 for (k=j+1; k<=Nblines;k++) {
924 const Handle(IntPatch_Line)& slink = slin(k);
925 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
926 if (wlin2->HasFirstPoint()) {
927 ptbis = wlin2->FirstPoint(ind2);
928 if (ptbis.IsTangencyPoint()) {
930 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
931 ptdeb.SetMultiple(Standard_True);
932 if (!ptbis.IsMultiple()) {
933 ptbis.SetMultiple(Standard_True);
934 wlin2->Replace(ind2,ptbis);
939 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
940 ptfin.SetMultiple(Standard_True);
941 if (!ptbis.IsMultiple()) {
942 ptbis.SetMultiple(Standard_True);
943 wlin2->Replace(ind2,ptbis);
949 if (wlin2->HasLastPoint()) {
950 ptbis = wlin2->LastPoint(ind2);
951 if (ptbis.IsTangencyPoint()) {
953 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
954 ptdeb.SetMultiple(Standard_True);
955 if (!ptbis.IsMultiple()) {
956 ptbis.SetMultiple(Standard_True);
957 wlin2->Replace(ind2,ptbis);
962 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
963 ptfin.SetMultiple(Standard_True);
964 if (!ptbis.IsMultiple()) {
965 ptbis.SetMultiple(Standard_True);
966 wlin2->Replace(ind2,ptbis);
974 wlin1->Replace(indfirst,ptdeb);
976 wlin1->Replace(indlast,ptfin);
979 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
981 // Treatment the segments
982 NbSegm = solrst.NbSegments();
984 for(i=1; i<=NbSegm; i++) {
985 thesegm = solrst.Segment(i);
986 //----------------------------------------------------------------------
987 // on cree une ligne d intersection contenant uniquement le segment.
988 // VOIR POUR LA TRANSITION DE LA LIGNE
989 // On ajoute aussi un polygone pour le traitement des intersections
990 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
991 //----------------------------------------------------------------------
992 //-- Calcul de la transition sur la rline (12 fev 97)
993 //-- reversed a le sens de OnFirst
995 dofirst = dolast = Standard_False;
996 procf = Standard_False;
997 procl = Standard_False;
998 IntSurf_Transition TLineUnk,TArcUnk;
1000 IntPatch_Point _thepointAtBeg;
1001 IntPatch_Point _thepointAtEnd;
1003 Standard_Boolean TransitionOK=Standard_False;
1005 if(thesegm.HasFirstPoint()) {
1006 Standard_Real _u1,_v1,_u2,_v2;
1008 dofirst = Standard_True;
1009 PStartf = thesegm.FirstPoint();
1010 paramf = PStartf.Parameter();
1012 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
1013 Handle(Adaptor3d_HVertex) _vtx;
1014 if(PStartf.IsNew()==Standard_False)
1015 _vtx= PStartf.Vertex();
1016 const gp_Pnt& _Pp = PStartf.Value();
1017 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1018 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1019 Quad.Parameters(_Pp,_u1,_v1);
1020 _u2=_p2d.X(); _v2=_p2d.Y();
1022 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1023 Quad.Parameters(_Pp,_u2,_v2);
1024 _u1=_p2d.X(); _v1=_p2d.Y();
1026 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1027 _thepointAtBeg.SetParameter(paramf);
1028 if(PStartf.IsNew()==Standard_False)
1029 _thepointAtBeg.SetVertex(reversed,_vtx);
1030 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1033 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1034 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1035 norm1 = d1u1.Crossed(d1v1);
1036 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1037 norm2 = d1u2.Crossed(d1v2);
1039 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1041 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1044 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1046 _u1=tgline.DotCross(norm2,norm1);
1047 TransitionOK=Standard_True;
1048 if (_u1 > 0.00000001) {
1049 trans1 = IntSurf_Out;
1050 trans2 = IntSurf_In;
1052 else if(_u1 < -0.00000001) {
1053 trans1 = IntSurf_In;
1054 trans2 = IntSurf_Out;
1057 TransitionOK=Standard_False;
1060 if(thesegm.HasLastPoint()) {
1061 Standard_Real _u1,_v1,_u2,_v2;
1063 dolast = Standard_True;
1064 PStartl = thesegm.LastPoint();
1065 paraml = PStartl.Parameter();
1067 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1068 Handle(Adaptor3d_HVertex) _vtx;
1069 if(PStartl.IsNew()==Standard_False)
1070 _vtx = PStartl.Vertex();
1071 const gp_Pnt& _Pp = PStartl.Value();
1072 IntPatch_Point _thepoint;
1073 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1074 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1075 Quad.Parameters(_Pp,_u1,_v1);
1076 _u2=_p2d.X(); _v2=_p2d.Y();
1078 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1079 Quad.Parameters(_Pp,_u2,_v2);
1080 _u1=_p2d.X(); _v1=_p2d.Y();
1082 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1083 _thepointAtEnd.SetParameter(paraml);
1084 if(PStartl.IsNew()==Standard_False)
1085 _thepointAtEnd.SetVertex(reversed,_vtx);
1086 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1090 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1091 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1092 norm1 = d1u1.Crossed(d1v1);
1093 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1094 norm2 = d1u2.Crossed(d1v2);
1096 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1098 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1101 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1103 _u1=tgline.DotCross(norm2,norm1);
1104 TransitionOK=Standard_True;
1105 if (_u1 > 0.00000001) {
1106 trans1 = IntSurf_Out;
1107 trans2 = IntSurf_In;
1109 else if(_u1 < -0.00000001) {
1110 trans1 = IntSurf_In;
1111 trans2 = IntSurf_Out;
1114 TransitionOK=Standard_False;
1117 if(TransitionOK==Standard_False) {
1118 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1119 rline = new IntPatch_RLine (Standard_False);
1121 rline->SetArcOnS1(thesegm.Curve());
1124 rline->SetArcOnS2(thesegm.Curve());
1128 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1129 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1131 rline->SetArcOnS1(thesegm.Curve());
1134 rline->SetArcOnS2(thesegm.Curve());
1138 //------------------------------
1139 //-- Ajout des points
1141 if (thesegm.HasFirstPoint()) {
1142 rline->AddVertex(_thepointAtBeg);
1143 rline->SetFirstPoint(rline->NbVertex());
1146 if (thesegm.HasLastPoint()) {
1147 rline->AddVertex(_thepointAtEnd);
1148 rline->SetLastPoint(rline->NbVertex());
1151 // Polygone sur restriction solution
1152 if (dofirst && dolast) {
1155 IntSurf_PntOn2S p2s;
1156 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1157 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1158 Standard_Integer nbsample = 100;
1161 for (j=1; j<=nbsample; j++) {
1162 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1163 arcsegm->D0(prm,p2d);
1164 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1166 Quad.Parameters(ptpoly,U1,V1);
1167 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1172 for (j=1; j<=nbsample; j++) {
1173 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1174 arcsegm->D0(prm,p2d);
1175 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1177 Quad.Parameters(ptpoly,U2,V2);
1178 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1185 if (dofirst || dolast) {
1186 Nblines = slin.Length();
1187 for (j=1; j<=Nblines; j++) {
1188 const Handle(IntPatch_Line)& slinj = slin(j);
1189 typ = slinj->ArcType();
1190 if (typ == IntPatch_Walking) {
1191 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1194 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1196 for (k=1; k<=Nbpts;k++) {
1197 if (typ == IntPatch_Walking) {
1198 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1201 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1205 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1206 ptdeb.SetMultiple(Standard_True);
1207 if (typ == IntPatch_Walking) {
1208 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1211 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1213 ptdeb.SetParameter(paramf);
1214 rline->AddVertex(ptdeb);
1216 procf=Standard_True;
1217 rline->SetFirstPoint(rline->NbVertex());
1222 if(dofirst) { //-- on recharge le ptdeb
1223 if (typ == IntPatch_Walking) {
1224 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1227 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1230 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1231 ptdeb.SetMultiple(Standard_True);
1232 if (typ == IntPatch_Walking) {
1233 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1236 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1238 ptdeb.SetParameter(paraml);
1239 rline->AddVertex(ptdeb);
1241 procl=Standard_True;
1242 rline->SetLastPoint(rline->NbVertex());
1253 // on traite les restrictions de la surface implicite
1254 for (i=1; i<=slin.Length(); i++)
1257 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1259 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1261 empt = (slin.Length() == 0 && spnt.Length() == 0);
1262 done = Standard_True;
1264 // post processing for cones and spheres
1265 if((Quad.TypeQuadric() == GeomAbs_Cone ||
1266 Quad.TypeQuadric() == GeomAbs_Sphere) &&
1269 Handle(Adaptor3d_TopolTool) PDomain = (reversed) ? D1 : D2;
1270 Handle(Adaptor3d_HSurface) QSurf = (reversed) ? Surf2 : Surf1;
1272 IntPatch_SequenceOfLine dslin;
1273 for(i = 1; i <= slin.Length(); i++ )
1274 DecomposeResult(slin(i),reversed,Quad,PDomain,QSurf,TolArc,dslin);
1277 for(i = 1; i <= dslin.Length(); i++ )
1278 slin.Append(dslin(i));
1282 //==================================================================
1283 // Decomposition of WLine goes through seam and/or apex routines
1284 //==================================================================
1286 // reject all points and vertices not in V range on Quadric
1287 static Handle(IntSurf_LineOn2S) VSplitLine(Handle(IntSurf_LineOn2S)& Line,
1288 Standard_Boolean IsReversed,
1289 Handle(Adaptor3d_HSurface)& QSurf,
1290 Handle(IntSurf_LineOn2S)& Vertices)
1292 Handle(IntSurf_LineOn2S) line = new IntSurf_LineOn2S();
1294 Standard_Real VF = QSurf->FirstVParameter();
1295 Standard_Real VL = QSurf->LastVParameter();
1297 Standard_Integer i = 0;
1298 Standard_Real U = 0., V = 0.;
1300 for(i = 1; i <= Line->NbPoints(); i++) {
1302 const IntSurf_PntOn2S& aP = Line->Value(i);
1304 aP.ParametersOnS2(U,V); // S2 - quadric
1306 aP.ParametersOnS1(U,V); // S1 - quadric
1308 if(VF <= V && V <= VL)
1312 Standard_Boolean isDeleted = Standard_True;
1313 Standard_Integer k = 0;
1316 isDeleted = Standard_False;
1319 for(i = 1; i <= Vertices->NbPoints(); i++) {
1321 const IntSurf_PntOn2S& aV = Vertices->Value(i);
1323 aV.ParametersOnS2(U,V); // S2 - quadric
1325 aV.ParametersOnS1(U,V); // S1 - quadric
1327 if(VF <= V && V <= VL)
1336 isDeleted = Standard_True;
1337 Vertices->RemovePoint(k);
1346 // correct U parameter of the start point of line on Quadric
1347 // (change 0->2PI or vs, if necessary)
1348 static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1350 Standard_Real u = U1;
1352 // case: no adjustment
1353 if( U1 > 0. && U1 < (2.*M_PI) )
1357 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
1358 if( U2 > 0. && U2 < (2.*M_PI) )
1359 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1361 Standard_Real uu = U2;
1362 if( U2 > (2.*M_PI) )
1363 while( uu > (2.*M_PI) )
1369 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1373 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1374 if( U2 > 0. && U2 < (2.*M_PI) )
1375 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
1377 Standard_Real uu = U2;
1378 if( U2 > (2.*M_PI) )
1379 while( uu > (2.*M_PI) )
1385 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
1388 // case: '<0. || >2PI'
1394 while(u > (2.*M_PI))
1401 // collect vertices, reject equals
1402 static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1403 const Standard_Boolean ,//IsReversed,
1404 const Standard_Real TOL3D,
1405 const Standard_Real TOL2D)
1407 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1409 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1411 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1412 Standard_Integer i = 0, k = 0;
1413 Standard_Integer NbVrt = WLine->NbVertex();
1415 TColStd_Array1OfInteger anVrts(1,NbVrt);
1418 // check equal vertices
1419 for(i = 1; i <= NbVrt; i++) {
1421 if( anVrts(i) == -1 ) continue;
1423 const IntPatch_Point& Pi = WLine->Vertex(i);
1425 for(k = (i+1); k <= NbVrt; k++) {
1427 if( anVrts(k) == -1 ) continue;
1429 const IntPatch_Point& Pk = WLine->Vertex(k);
1431 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
1432 // suggest the points are equal;
1433 // test 2d parameters on surface
1434 Standard_Boolean sameU1 = Standard_False;
1435 Standard_Boolean sameV1 = Standard_False;
1436 Standard_Boolean sameU2 = Standard_False;
1437 Standard_Boolean sameV2 = Standard_False;
1439 Pi.ParametersOnS1(U1,V1);
1440 Pk.ParametersOnS1(U2,V2);
1441 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1442 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1444 Pi.ParametersOnS2(U1,V1);
1445 Pk.ParametersOnS2(U2,V2);
1446 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1447 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1449 if((sameU1 && sameV1) && (sameU2 && sameV2))
1455 // copy further processed vertices
1456 for(i = 1; i <= NbVrt; i++) {
1457 if( anVrts(i) == -1 ) continue;
1458 vertices->Add(WLine->Vertex(i).PntOn2S());
1463 static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1464 const IntSurf_PntOn2S& P2)
1466 Standard_Boolean result = Standard_False;
1467 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1468 const gp_Pnt& P3D1 = P1.Value();
1469 const gp_Pnt& P3D2 = P2.Value();
1470 if(P3D1.Distance(P3D2) <= T3D) {
1471 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1472 P1.ParametersOnS1(U1,V1);
1473 P1.ParametersOnS2(U2,V2);
1474 P2.ParametersOnS1(U3,V3);
1475 P2.ParametersOnS2(U4,V4);
1476 gp_Pnt2d P2D11(U1,V1);
1477 gp_Pnt2d P2D12(U2,V2);
1478 gp_Pnt2d P2D21(U3,V3);
1479 gp_Pnt2d P2D22(U4,V4);
1480 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1481 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1482 if(sameS1 && sameS2)
1483 result = Standard_True;
1488 static void ForcedPurgePoints(Handle(IntSurf_LineOn2S)& Result,
1489 Standard_Boolean IsReversed,
1490 IntSurf_Quadric& Quad)
1492 if(Result->NbPoints() <= 30) return;
1493 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1495 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1497 Result->Value(1).ParametersOnS2(U1,V1);
1498 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1501 Result->Value(1).ParametersOnS1(U1,V1);
1502 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
1505 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1506 Standard_Real Uapx = 0., Vapx = 0.;
1507 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1509 if(fabs(V1-Vapx) <= 1.e-3)
1511 if(fabs(V2-Vapx) <= 1.e-3)
1515 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
1516 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
1518 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1520 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1524 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1525 Result->RemovePoint(2);
1529 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1530 Result->RemovePoint(Result->NbPoints()-1);
1535 // DEBUG FUNCTION !!!
1537 static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1538 Standard_Boolean IsReversed,
1539 Standard_Integer Number)
1541 cout << "DUMP LINE" << endl;
1544 for(i = 1; i <= Line->NbPoints(); i++) {
1545 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1547 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1549 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1550 cout << "point p" << i << " " << U << " " << V << endl;
1556 // DEBUG FUNCTION !!!
1558 static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1559 const Handle(IntSurf_LineOn2S)& Vertices,
1560 TColStd_Array1OfInteger& PTypes)
1562 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1563 Standard_Integer ip = 0, iv = 0;
1564 for(ip = 1; ip <= nbp; ip++) {
1565 const IntSurf_PntOn2S& aP = Line->Value(ip);
1566 Standard_Integer type = 0;
1567 for(iv = 1; iv <= nbv; iv++) {
1568 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1569 if(AreSamePoints(aP,aV)) {
1578 static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1579 const Standard_Real TOL2D)
1581 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
1584 static inline Standard_Real AdjustU(const Standard_Real U)
1586 Standard_Real u = U, DBLPI = 2.*M_PI;
1587 if(u < 0. || u > DBLPI) {
1598 static inline void Correct2DBounds(const Standard_Real UF,
1599 const Standard_Real UL,
1600 const Standard_Real VF,
1601 const Standard_Real VL,
1602 const Standard_Real TOL2D,
1606 Standard_Real Eps = 1.e-16;
1607 Standard_Real dUF = fabs(U - UF);
1608 Standard_Real dUL = fabs(U - UL);
1609 Standard_Real dVF = fabs(V - VF);
1610 Standard_Real dVL = fabs(V - VL);
1611 if(dUF <= TOL2D && dUF > Eps) U = UF;
1612 if(dUL <= TOL2D && dUL > Eps) U = UL;
1613 if(dVF <= TOL2D && dVF > Eps) V = VF;
1614 if(dVL <= TOL2D && dVL > Eps) V = VL;
1617 static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1618 const Standard_Boolean IsReversed,
1619 const Handle(Adaptor3d_HSurface)& QSurf,
1620 const Standard_Real TOL2D)
1622 Standard_Real VF = QSurf->FirstVParameter();
1623 Standard_Real VL = QSurf->LastVParameter();
1624 Standard_Real UF = QSurf->FirstUParameter();
1625 Standard_Real UL = QSurf->LastUParameter();
1627 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1628 Standard_Real U = 0., V = 0.;
1629 for(ip = 1; ip <= nbp; ip++) {
1631 Line->Value(ip).ParametersOnS2(U,V);
1633 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1634 Line->SetUV(ip,Standard_False,U,V);
1637 Line->Value(ip).ParametersOnS1(U,V);
1639 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1640 Line->SetUV(ip,Standard_True,U,V);
1645 static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
1646 const Standard_Boolean IsReversed,
1647 Handle(IntSurf_LineOn2S)& Vertices,
1648 const TColStd_Array1OfInteger& PTypes,
1649 const Standard_Real TOL2D)
1651 Standard_Boolean result = Standard_False;
1652 Standard_Integer ip = 0, nbp = Line->NbPoints();
1653 Standard_Real U = 0., V = 0.;
1654 for(ip = 1; ip <= nbp; ip++) {
1655 Standard_Integer ipt = PTypes(ip);
1657 const IntSurf_PntOn2S& aP = Line->Value(ip);
1659 aP.ParametersOnS2(U,V); // S2 - quadric
1661 aP.ParametersOnS1(U,V); // S1 - quadric
1663 if(IsSeamParameter(U,TOL2D)) {
1664 if(ip == 1 || ip == nbp) {
1665 Standard_Real U1 = 0., V1 = 0.;
1666 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1668 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1670 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1671 Standard_Real u = AdjustUFirst(U,U1);
1672 if(fabs(u-U) >= 1.5*M_PI) {
1673 Standard_Real U2 = 0., V2 = 0.;
1675 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1676 Line->SetUV(ip,Standard_False,u,V);
1677 Line->SetUV(ip,Standard_True,U2,V2);
1680 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1681 Line->SetUV(ip,Standard_True,u,V);
1682 Line->SetUV(ip,Standard_False,U2,V2);
1687 Standard_Integer ipp = ip - 1;
1688 Standard_Integer ipn = ip + 1;
1689 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1691 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1692 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1695 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1696 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1700 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1701 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1702 if(pnearZero == cnearZero) {
1703 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1704 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1706 nP.SetValue(aP.Value());
1707 Standard_Real U3 = 0., V3 = 0.;
1709 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1710 nP.SetValue(Standard_False,nU,V);
1711 nP.SetValue(Standard_True,U3,V3);
1714 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1715 nP.SetValue(Standard_True,nU,V);
1716 nP.SetValue(Standard_False,U3,V3);
1718 Line->InsertBefore(ipn,nP);
1720 result = Standard_True;
1725 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1726 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1728 nP.SetValue(aP.Value());
1729 Standard_Real U3 = 0., V3 = 0.;
1731 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1732 nP.SetValue(Standard_False,nU,V);
1733 nP.SetValue(Standard_True,U3,V3);
1736 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1737 nP.SetValue(Standard_True,nU,V);
1738 nP.SetValue(Standard_False,U3,V3);
1740 Line->InsertBefore(ip,nP);
1742 result = Standard_True;
1746 // Line->InsertBefore(ip,Line->Value(ipn));
1747 // Line->RemovePoint(ip+2);
1748 // result = Standard_True;
1749 // cout << "swap vertex " << endl;
1760 static void ToSmooth(Handle(IntSurf_LineOn2S)& Line,
1761 Standard_Boolean IsReversed,
1762 IntSurf_Quadric& Quad,
1763 Standard_Boolean IsFirst,
1766 if(Line->NbPoints() <= 10)
1770 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1771 if(NbTestPnts < 5) NbTestPnts = 5;
1773 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1774 Standard_Integer ip = 0;
1775 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1777 for(ip = startp; ip <= NbTestPnts; ip++) {
1779 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1780 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1783 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1784 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1786 DDU += fabs(fabs(Uc)-fabs(Un));
1787 DDV += fabs(fabs(Vc)-fabs(Vn));
1790 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1795 DDU /= (Standard_Real) NbTestPnts + 1;
1796 DDV /= (Standard_Real) NbTestPnts + 1;
1798 D3D /= (Standard_Real) NbTestPnts + 1;
1801 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1802 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1803 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1805 Standard_Boolean doU = Standard_False;
1806 Standard_Boolean doV = Standard_False;
1808 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1811 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1812 Line->Value(Index2).ParametersOnS2(U2,V2);
1813 Line->Value(Index3).ParametersOnS2(U3,V3);
1816 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1817 Line->Value(Index2).ParametersOnS1(U2,V2);
1818 Line->Value(Index3).ParametersOnS1(U3,V3);
1821 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
1822 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
1824 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1825 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
1827 doU = Standard_False;
1832 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1833 Standard_Real Uapx = 0., Vapx = 0.;
1834 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1836 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
1838 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1839 if(fabs(V1-Vapx) <= 1.e-9) {}
1841 doU = Standard_False;
1846 if(fabs(fabs(V1)-fabs(V2)) > DDV) doV = Standard_True;
1849 Standard_Real dU = Min((DDU/10.),5.e-8);
1850 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1852 Line->SetUV(Index1,Standard_False,U,V1);
1854 Line->SetUV(Index1,Standard_True,U,V1);
1859 static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
1860 const IntSurf_PntOn2S& aV,
1861 const Standard_Boolean IsReversed,
1862 const Standard_Real ArcTol,
1863 Handle(Adaptor3d_TopolTool)& PDomain)
1866 Standard_Boolean result = Standard_False;
1867 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1869 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1870 aV.ParametersOnS1(Uv,Vv);
1873 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1874 aV.ParametersOnS2(Uv,Vv);
1876 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
1877 gp_Pnt2d a2DPntM(Um,Vm);
1878 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
1879 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
1880 result = Standard_True;
1884 static void VerifyVertices(Handle(IntSurf_LineOn2S)& Line,
1885 Standard_Boolean IsReversed,
1886 Handle(IntSurf_LineOn2S)& Vertices,
1887 Standard_Real TOL2D,
1888 const Standard_Real ArcTol,
1889 Handle(Adaptor3d_TopolTool)& PDomain,
1890 IntSurf_PntOn2S& VrtF,
1891 Standard_Boolean& AddFirst,
1892 IntSurf_PntOn2S& VrtL,
1893 Standard_Boolean& AddLast)
1895 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1896 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
1897 const IntSurf_PntOn2S& aPF = Line->Value(1);
1898 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
1899 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
1901 aPF.ParametersOnS2(UF,VF);
1902 aPL.ParametersOnS2(UL,VL);
1905 aPF.ParametersOnS1(UF,VF);
1906 aPL.ParametersOnS1(UL,VL);
1908 gp_Pnt2d a2DPF(UF,VF);
1909 gp_Pnt2d a2DPL(UL,VL);
1910 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
1911 Standard_Integer FConjugated = 0, LConjugated = 0;
1913 Standard_Integer iv = 0;
1915 for(iv = 1; iv <= nbv; iv++) {
1916 Standard_Real Uv = 0., Vv = 0.;
1918 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1920 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1923 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1925 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1929 for(iv = 1; iv <= nbv; iv++) {
1930 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1931 if(AreSamePoints(aPF,aV)) {
1936 Standard_Real Uv = 0., Vv = 0.;
1938 aV.ParametersOnS2(Uv,Vv);
1940 aV.ParametersOnS1(Uv,Vv);
1941 gp_Pnt2d a2DV(Uv,Vv);
1942 Standard_Real Dist = a2DV.Distance(a2DPF);
1943 if(Dist < DistMinF) {
1946 if(FConjugated != 0)
1949 if(IsSeamParameter(Uv,TOL2D)) {
1950 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1951 gp_Pnt2d a2DCV(Ucv,Vv);
1952 Standard_Real CDist = a2DCV.Distance(a2DPF);
1953 if(CDist < DistMinF) {
1962 for(iv = 1; iv <= nbv; iv++) {
1963 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1964 if(AreSamePoints(aPL,aV)) {
1969 Standard_Real Uv = 0., Vv = 0.;
1971 aV.ParametersOnS2(Uv,Vv);
1973 aV.ParametersOnS1(Uv,Vv);
1974 gp_Pnt2d a2DV(Uv,Vv);
1975 Standard_Real Dist = a2DV.Distance(a2DPL);
1976 if(Dist < DistMinL) {
1979 if(LConjugated != 0)
1982 if(IsSeamParameter(Uv,TOL2D)) {
1983 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
1984 gp_Pnt2d a2DCV(Ucv,Vv);
1985 Standard_Real CDist = a2DCV.Distance(a2DPL);
1986 if(CDist < DistMinL) {
1995 AddFirst = Standard_False;
1996 AddLast = Standard_False;
1998 if(FIndexSame == 0) {
1999 if(FIndexNear != 0) {
2000 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2001 Standard_Real Uv = 0., Vv = 0.;
2003 aV.ParametersOnS2(Uv,Vv);
2005 aV.ParametersOnS1(Uv,Vv);
2006 if(IsSeamParameter(Uv,TOL2D)) {
2007 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2008 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2010 VrtF.SetValue(aV.Value());
2012 Standard_Real U2 = 0., V2 = 0.;
2013 aV.ParametersOnS1(U2,V2); // S1 - prm
2014 VrtF.SetValue(Standard_True,U2,V2);
2015 if(FConjugated == 0)
2016 VrtF.SetValue(Standard_False,Uv,Vv);
2018 VrtF.SetValue(Standard_False,Ucv,Vv);
2021 Standard_Real U2 = 0., V2 = 0.;
2022 aV.ParametersOnS2(U2,V2); // S2 - prm
2023 VrtF.SetValue(Standard_False,U2,V2);
2024 if(FConjugated == 0)
2025 VrtF.SetValue(Standard_True,Uv,Vv);
2027 VrtF.SetValue(Standard_True,Ucv,Vv);
2029 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2030 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2031 AddFirst = Standard_True;
2036 // to do: analyze internal vertex
2041 if(LIndexSame == 0) {
2042 if(LIndexNear != 0) {
2043 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2044 Standard_Real Uv = 0., Vv = 0.;
2046 aV.ParametersOnS2(Uv,Vv);
2048 aV.ParametersOnS1(Uv,Vv);
2049 if(IsSeamParameter(Uv,TOL2D)) {
2050 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
2051 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2053 VrtL.SetValue(aV.Value());
2055 Standard_Real U2 = 0., V2 = 0.;
2056 aV.ParametersOnS1(U2,V2); // S1 - prm
2057 VrtL.SetValue(Standard_True,U2,V2);
2058 if(LConjugated == 0)
2059 VrtL.SetValue(Standard_False,Uv,Vv);
2061 VrtL.SetValue(Standard_False,Ucv,Vv);
2064 Standard_Real U2 = 0., V2 = 0.;
2065 aV.ParametersOnS2(U2,V2); // S2 - prm
2066 VrtL.SetValue(Standard_False,U2,V2);
2067 if(LConjugated == 0)
2068 VrtL.SetValue(Standard_True,Uv,Vv);
2070 VrtL.SetValue(Standard_True,Ucv,Vv);
2072 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2073 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2074 AddLast = Standard_True;
2079 // to do: analyze internal vertex
2085 static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
2086 const IntSurf_PntOn2S& VrtF,
2087 const Standard_Boolean AddFirst,
2088 const IntSurf_PntOn2S& VrtL,
2089 const Standard_Boolean AddLast,
2090 const Standard_Real D3DF,
2091 const Standard_Real D3DL)
2093 Standard_Boolean result = Standard_False;
2095 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2096 if((D3DF*2.) > DF && DF > 1.5e-7) {
2097 Line->InsertBefore(1,VrtF);
2098 result = Standard_True;
2102 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2103 if((D3DL*2.) > DL && DL > 1.5e-7) {
2105 result = Standard_True;
2112 static void PutIntVertices(Handle(IntPatch_Line)& Line,
2113 Handle(IntSurf_LineOn2S)& Result,
2114 Standard_Boolean ,//IsReversed,
2115 Handle(IntSurf_LineOn2S)& Vertices,
2116 const Standard_Real ArcTol)
2118 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2123 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2124 Standard_Integer ip = 0, iv = 0;
2126 IntPatch_Point thePnt;
2127 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2129 for(ip = 2; ip <= (nbp-1); ip++) {
2130 const IntSurf_PntOn2S& aP = Result->Value(ip);
2131 for(iv = 1; iv <= nbv; iv++) {
2132 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2133 if(AreSamePoints(aP,aV)) {
2134 aPnt = Result->Value(ip).Value();
2135 Result->Value(ip).ParametersOnS1(U1,V1);
2136 Result->Value(ip).ParametersOnS2(U2,V2);
2137 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2138 thePnt.SetParameters(U1,V1,U2,V2);
2139 thePnt.SetParameter((Standard_Real)ip);
2140 WLine->AddVertex(thePnt);
2146 static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2147 Handle(IntSurf_LineOn2S)& Vertices)
2149 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2150 Standard_Integer ip = 0, iv = 0;
2151 Standard_Boolean result = Standard_False;
2156 for(ip = 2; ip <= (nbp-1); ip++) {
2157 const IntSurf_PntOn2S& aP = Line->Value(ip);
2158 for(iv = 1; iv <= nbv; iv++) {
2159 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2160 if(AreSamePoints(aP,aV)) {
2161 result = Standard_True;
2171 static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
2172 Standard_Boolean Tang,
2173 IntSurf_TypeTrans Trans1,
2174 IntSurf_TypeTrans Trans2,
2175 Standard_Real ArcTol,
2176 Standard_Integer ParFirst,
2177 Standard_Integer ParLast)
2179 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2180 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2182 Standard_Integer ip = 0;
2183 for(ip = ParFirst; ip <= ParLast; ip++)
2184 sline->Add(SLine->Value(ip));
2186 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2189 IntPatch_Point TPntF,TPntL;
2190 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2192 aSPnt = sline->Value(1).Value();
2193 sline->Value(1).ParametersOnS1(uu1,vv1);
2194 sline->Value(1).ParametersOnS2(uu2,vv2);
2195 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2196 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2197 TPntF.SetParameter(1.);
2198 wline->AddVertex(TPntF);
2199 wline->SetFirstPoint(1);
2201 aSPnt = sline->Value(sline->NbPoints()).Value();
2202 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2203 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2204 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2205 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2206 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2207 wline->AddVertex(TPntL);
2208 wline->SetLastPoint(sline->NbPoints());
2213 static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
2214 Standard_Boolean Tang,
2215 IntSurf_TypeTrans Trans1,
2216 IntSurf_TypeTrans Trans2,
2217 Standard_Real ArcTol,
2218 IntPatch_SequenceOfLine& Segments)
2220 Standard_Boolean result = Standard_False;
2223 Standard_Integer nbv = WLine->NbVertex();
2225 Standard_Integer iv = 0;
2226 for(iv = 1; iv < nbv; iv++) {
2227 Standard_Integer firstPar = (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2228 Standard_Integer lastPar = (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
2229 if((lastPar - firstPar) <= 1)
2232 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,ArcTol,firstPar,lastPar);
2233 Segments.Append(splitwline);
2235 result = Standard_True;
2242 void DecomposeResult(Handle(IntPatch_Line)& Line,
2243 Standard_Boolean IsReversed,
2244 IntSurf_Quadric& Quad,
2245 Handle(Adaptor3d_TopolTool)& PDomain,
2246 Handle(Adaptor3d_HSurface)& QSurf,
2247 Standard_Real ArcTol,
2248 IntPatch_SequenceOfLine& Lines)
2250 if( Line->ArcType() != IntPatch_Walking ) {
2255 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2256 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2258 if(SLine->NbPoints() <= 2) {
2263 Standard_Real TOL3D = 1.e-10, TOL2D = 1.e-8, TOL2DS = 1.e-5;
2265 Handle(IntSurf_LineOn2S) vline = GetVertices(WLine,IsReversed,TOL3D,TOL2D);
2266 Handle(IntSurf_LineOn2S) SSLine = VSplitLine(SLine,IsReversed,QSurf,vline);
2268 if(SSLine->NbPoints() <= 1)
2271 AdjustLine(SSLine,IsReversed,QSurf,TOL2D);
2273 Standard_Boolean isInserted = Standard_True;
2275 Standard_Integer NbPnts = SSLine->NbPoints();
2276 TColStd_Array1OfInteger ptypes(1,NbPnts);
2277 SearchVertices(SSLine,vline,ptypes);
2278 isInserted = InsertSeamVertices(SSLine,IsReversed,vline,ptypes,TOL2D);
2281 if(SSLine->NbPoints() == 2) {
2282 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2284 SSLine->Value(1).ParametersOnS2(uu1,vv1);
2285 SSLine->Value(2).ParametersOnS2(uu2,vv2);
2288 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2289 SSLine->Value(2).ParametersOnS1(uu2,vv2);
2291 gp_Pnt2d p1(uu1,vv1);
2292 gp_Pnt2d p2(uu2,vv2);
2293 if(p1.Distance(p2) > 2.e-7) {
2294 Standard_Real Dist3D = SSLine->Value(1).Value().Distance(SSLine->Value(2).Value());
2295 if(Dist3D > 3.e-7) {
2297 IntPatch_Point TPntF,TPntL;
2298 Handle(IntPatch_WLine) wline = new IntPatch_WLine(SSLine,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2299 aSPnt = SSLine->Value(1).Value();
2300 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2301 SSLine->Value(1).ParametersOnS2(uu2,vv2);
2302 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2303 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2304 TPntF.SetParameter(1.);
2305 wline->AddVertex(TPntF);
2306 wline->SetFirstPoint(1);
2307 aSPnt = SSLine->Value(SSLine->NbPoints()).Value();
2308 SSLine->Value(SSLine->NbPoints()).ParametersOnS1(uu1,vv1);
2309 SSLine->Value(SSLine->NbPoints()).ParametersOnS2(uu2,vv2);
2310 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2311 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2312 TPntL.SetParameter(SSLine->NbPoints());
2313 wline->AddVertex(TPntL);
2314 wline->SetLastPoint(SSLine->NbPoints());
2315 Lines.Append(wline);
2325 Standard_Integer NbPnts = SSLine->NbPoints();
2327 Standard_Real BSEAM = 1.5*M_PI; // delta U crossing seam
2328 Standard_Real BAPEX = M_PI/16.; // delta U crossing apex
2330 Standard_Integer k = 0;
2331 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0., AnV1 = 0., DU1 = 0., DV1 = 0.;
2332 Standard_Integer Findex = 1, Lindex = NbPnts, Bindex = 0;
2335 IntPatch_Point TPntF,TPntL,TPntS;
2337 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2338 Handle(IntPatch_WLine) wline;
2339 IntPatch_SequenceOfLine lines;
2341 // build WLine parts (if any)
2344 //if((Lindex-Findex+1) <= 2 )
2345 if((Lindex-Findex+1) <= 1 )
2349 Standard_Boolean isDecomposited = Standard_False;
2350 Standard_Boolean is2PIDecomposed = Standard_False;
2351 U1 = 0.; V1 = 0.; U2 = 0.; V2 = 0.; AnU1 = 0.; AnV1 = 0.; DU1 = 0.; DV1 = 0.;
2353 // analyze other points
2354 for(k = Findex; k <= Lindex; k++) {
2359 SSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2362 SSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2364 sline->Add(SSLine->Value(k));
2370 SSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2373 SSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2376 Standard_Real DeltaU = fabs(U1-AnU1);
2377 if(DeltaU > BSEAM) {
2379 isDecomposited = Standard_True;
2380 is2PIDecomposed = Standard_True;
2383 else if((DeltaU > BAPEX) && (k >= (Findex+10) && k <= (Lindex-10))) {
2385 isDecomposited = Standard_True;
2390 sline->Add(SSLine->Value(k));
2395 IntSurf_PntOn2S aVF,aVL;
2396 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2397 VerifyVertices(sline,IsReversed,vline,TOL2DS,ArcTol,PDomain,aVF,addVF,aVL,addVL);
2399 Standard_Boolean hasInternals = HasInternals(sline,vline);
2401 Standard_Real D3F = 0., D3L = 0.;
2402 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2403 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2405 if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2406 D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2408 if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2409 D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->Value(sline->NbPoints()-2).Value());
2412 if(addVF || addVL) {
2413 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2415 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2416 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2421 ForcedPurgePoints(sline,IsReversed,Quad);
2424 wline = new IntPatch_WLine(sline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2426 aSPnt = sline->Value(1).Value();
2427 sline->Value(1).ParametersOnS1(U1,V1);
2428 sline->Value(1).ParametersOnS2(U2,V2);
2429 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2430 TPntF.SetParameters(U1,V1,U2,V2);
2431 TPntF.SetParameter(1.);
2432 wline->AddVertex(TPntF);
2433 wline->SetFirstPoint(1);
2436 PutIntVertices(wline,sline,IsReversed,vline,ArcTol);
2439 aSPnt = sline->Value(sline->NbPoints()).Value();
2440 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2441 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2442 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2443 TPntL.SetParameters(U1,V1,U2,V2);
2444 TPntL.SetParameter(sline->NbPoints());
2445 wline->AddVertex(TPntL);
2446 wline->SetLastPoint(sline->NbPoints());
2448 IntPatch_SequenceOfLine segm;
2449 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2(),ArcTol,segm);
2452 Lines.Append(wline);
2454 Standard_Integer nbsegms = segm.Length();
2455 Standard_Integer iseg = 0;
2456 for(iseg = 1; iseg <= nbsegms; iseg++)
2457 Lines.Append(segm(iseg));
2460 if(isDecomposited) {
2462 sline = new IntSurf_LineOn2S();
2469 Standard_Integer aNbPnts;
2470 Standard_Real aU1,aV1,aU2,aV2;
2473 aNbPnts=thelin->NbPoints();
2474 printf(" WLine: aNbPnts=%d\n", aNbPnts);
2475 for(i=1; i <= aNbPnts; ++i) {
2476 const IntSurf_PntOn2S& aPoint = thelin->Value(i);
2478 aPoint.Parameters(aU1, aV1, aU2, aV2);
2479 printf(" point %d %lf %lf %lf %lf %lf %lf %lf\n",
2480 i, aPx.X(), aPx.Y(), aPx.Z(), aU1, aV1, aU2, aV2);