0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / IntPatch / IntPatch_ImpPrmIntersection.cxx
CommitLineData
b311480e 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
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22#include <IntPatch_ImpPrmIntersection.ixx>
23
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>
30
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>
43
44//=======================================================================
45//function : IntPatch_ImpPrmIntersection
46//purpose :
47//=======================================================================
48
49IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
50 : done(Standard_False),
51 empt(Standard_False),
52 myIsStartPnt(Standard_False),
53 myUStart(0.0),
54 myVStart(0.0)
55{ }
56
57
58//=======================================================================
59//function : IntPatch_ImpPrmIntersection
60//purpose :
61//=======================================================================
62
63IntPatch_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),
73 empt(Standard_False),
74 myIsStartPnt(Standard_False),
75 myUStart(0.0),
76 myVStart(0.0)
77{
78 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
79}
80
81
82//=======================================================================
83//function : SetStartPoint
84//purpose :
85//=======================================================================
86
87void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
88 const Standard_Real V)
89{
90 myIsStartPnt = Standard_True;
91 myUStart = U; myVStart = V;
92}
93
94#ifndef DEB
95#define No_Standard_RangeError
96#define No_Standard_OutOfRange
97#endif
98
99
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>
107
108#include <IntSurf_SequenceOfInteriorPoint.hxx>
109#include <IntSurf_QuadricTool.hxx>
110#include <GeomAbs_SurfaceType.hxx>
111
112
113static 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);
120static
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);
127static
128 void Recadre(const Standard_Boolean ,
129 GeomAbs_SurfaceType typeS1,
130 GeomAbs_SurfaceType typeS2,
131 IntPatch_Point& pt,
132 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
133 Standard_Integer Param,
134 Standard_Real U1,
135 Standard_Real V1,
136 Standard_Real U2,
137 Standard_Real V2);
138
139//=======================================================================
140//function : ComputeTangency
141//purpose :
142//=======================================================================
143void 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)
149{
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;
159 gp_Vec vectg;
160 gp_Dir2d dirtg;
161 gp_Pnt ptbid;
162 gp_Vec d1u,d1v,v1,v2;
163 gp_Pnt2d p2d;
164 gp_Vec2d d2d;
165 //
1ef32e96
RL
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);
7fd59977 170 //
171 seqlength = 0;
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);
181
182 thearc->D0(theparam,p2d);
183 X(1) = p2d.X();
184 X(2) = p2d.Y();
185 PPoint.SetValue(PStart.Value(),X(1),X(2));
186
187 Func.Values(X,F,D);
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);
204
205 thearc->D0(theparam,p2d);
206 PPoint.AddUV(p2d.X(),p2d.Y());
207 Destination(k) = seqlength+1;
208 }
209 }
210 }
211 }
212 }
213 PPoint.SetPassing(ispassing);
214 seqpdep.Append(PPoint);
215 seqlength++;
216 }
217 else { // on a un point de depart potentiel
218
219 vectg = Func.Direction3d();
220 dirtg = Func.Direction2d();
221
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);
226
227 test = vectg.Dot(v1.Crossed(v2));
228 if (PStart.IsNew()) {
229 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
230 (test > 0. && arcorien == TopAbs_REVERSED)) {
231 vectg.Reverse();
232 dirtg.Reverse();
233 }
234 PPoint.SetDirections(vectg,dirtg);
235 PPoint.SetPassing(ispassing);
236 Destination(i) = seqlength+1;
237 seqpdep.Append(PPoint);
238 seqlength++;
239 }
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) {
248 // pour essai
249
250 vtx = PStart.Vertex();
251 vtxorien = Domain->Orientation(vtx);
252 if (Abs(test) <= tole) {
253 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
254 }
255 else {
0ebaa4db 256 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
257 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
7fd59977 258 LocTrans = TopAbs_FORWARD;
259 }
260 else {
261 LocTrans = TopAbs_REVERSED;
262 }
263 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
264 }
265
266 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
267 }
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);
278
279 PPoint.AddUV(X(1),X(2));
280
281 thearc->D1(theparam,p2d,d2d);
282 PPoint.AddUV(p2d.X(),p2d.Y());
283
284 if (arcorien == TopAbs_FORWARD ||
285 arcorien == TopAbs_REVERSED) {
286 ispassing = Standard_False;
287 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
288
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
293 }
294 else {
0ebaa4db 295 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
296 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
7fd59977 297 LocTrans = TopAbs_FORWARD;
298 }
299 else {
300 LocTrans = TopAbs_REVERSED;
301 }
302 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
303 }
304
305 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
306 }
307 Destination(k) = seqlength+1;
308 }
309 }
310 }
311 }
312 fairpt = Standard_True;
313 if (!ispassing) {
314 TopAbs_State Before = comptrans.StateBefore();
315 TopAbs_State After = comptrans.StateAfter();
316 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
317 fairpt = Standard_False;
318 }
319 else if (Before == TopAbs_IN) {
320 if (After == TopAbs_IN) {
321 ispassing = Standard_True;
322 }
323 else {
324 vectg.Reverse();
325 dirtg.Reverse();
326 }
327 }
328 else {
329 if (After !=TopAbs_IN) {
330 fairpt = Standard_False;
331 }
332 }
333 }
334 if (fairpt) {
335 PPoint.SetDirections(vectg,dirtg);
336 PPoint.SetPassing(ispassing);
337 seqpdep.Append(PPoint);
338 seqlength++;
339 }
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);
344 }
345 }
346 }
347 }
348 }
349 }
350 }
351}
352//=======================================================================
353//function : Recadre
354//purpose :
355//=======================================================================
356void Recadre(const Standard_Boolean ,
357 GeomAbs_SurfaceType typeS1,
358 GeomAbs_SurfaceType typeS2,
359 IntPatch_Point& pt,
360 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
361 Standard_Integer Param,
362 Standard_Real U1,
363 Standard_Real V1,
364 Standard_Real U2,
365 Standard_Real V2)
366{
367 Standard_Real U1p,V1p,U2p,V2p;
368 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
369 switch(typeS1)
370 {
371 case GeomAbs_Torus:
c6541a0c
D
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;
7fd59977 374 case GeomAbs_Cylinder:
375 case GeomAbs_Cone:
376 case GeomAbs_Sphere:
c6541a0c
D
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;
566f8441 379 default:
380 break;
7fd59977 381 }
382 switch(typeS2)
383 {
384 case GeomAbs_Torus:
c6541a0c
D
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;
7fd59977 387 case GeomAbs_Cylinder:
388 case GeomAbs_Cone:
389 case GeomAbs_Sphere:
c6541a0c
D
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;
566f8441 392 default:
393 break;
7fd59977 394 }
395 pt.SetParameters(U1,V1,U2,V2);
396}
397
398//=======================================================================
399//function : Perform
400//purpose :
401//=======================================================================
402void 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)
410{
411 Standard_Boolean reversed, procf, procl, dofirst, dolast;
1d47d8d0 412 Standard_Integer indfirst = 0, indlast = 0, ind2, i,j,k, NbSegm;
7fd59977 413 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
414 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
415
416 IntPatch_TheSegmentOfTheSOnBounds thesegm;
417 IntSurf_PathPoint PPoint;
418
419 Handle(IntPatch_RLine) rline;
420 Handle(IntPatch_WLine) wline;
421 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
422 IntPatch_Point ptdeb,ptfin,ptbis;
423
424 IntPatch_IType typ;
425 IntSurf_Transition TLine,TArc;
426 IntSurf_TypeTrans trans1,trans2;
427 gp_Pnt valpt,ptbid;
428 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
429 gp_Dir DirNormale;
430 gp_Vec VecNormale;
431
432 gp_Pnt2d p2d;
433 gp_Vec2d d2d;
434
435 Handle(Adaptor2d_HCurve2d) currentarc;
436 GeomAbs_SurfaceType typeS1, typeS2;
437 IntSurf_Quadric Quad;
438 IntPatch_TheSurfFunction Func;
439 IntPatch_ArcFunction AFunc;
440 //
441 typeS1 = Surf1->GetType();
442 typeS2 = Surf2->GetType();
443
444 paramf =0.;
445 paraml =0.;
446 trans1 = IntSurf_Undecided;
447 trans2 = IntSurf_Undecided;
448 //
449 done = Standard_False;
450 empt = Standard_True;
451 slin.Clear();
452 spnt.Clear();
453 //
454 reversed = Standard_False;
455 switch (typeS1) {
456 case GeomAbs_Plane:
457 Quad.SetValue(Surf1->Plane());
458 break;
459
460 case GeomAbs_Cylinder:
461 Quad.SetValue(Surf1->Cylinder());
462 break;
463
464 case GeomAbs_Sphere:
465 Quad.SetValue(Surf1->Sphere());
466 break;
467
468 case GeomAbs_Cone:
469 Quad.SetValue(Surf1->Cone());
470 break;
471
472 default: {
473 reversed = Standard_True;
474 switch (typeS2) {
475 case GeomAbs_Plane:
476 Quad.SetValue(Surf2->Plane());
477 break;
478
479 case GeomAbs_Cylinder:
480 Quad.SetValue(Surf2->Cylinder());
481 break;
482
483 case GeomAbs_Sphere:
484 Quad.SetValue(Surf2->Sphere());
485 break;
486
487 case GeomAbs_Cone:
488 Quad.SetValue(Surf2->Cone());
489 break;
490 default: {
491 Standard_ConstructionError::Raise();
492 break;
493 }
494 }
495 }
496 break;
497 }
498 //
499 Func.SetImplicitSurface(Quad);
500 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
501 AFunc.SetQuadric(Quad);
502 //
503 if (!reversed) {
504 Func.Set(Surf2);
505 AFunc.Set(Surf2);
506 }
507 else {
508 Func.Set(Surf1);
509 AFunc.Set(Surf1);
510 }
511 //
512 if (!reversed) {
513 solrst.Perform(AFunc,D2,TolArc,TolTang);
514 }
515 else {
516 solrst.Perform(AFunc,D1,TolArc,TolTang);
517 }
518 if (!solrst.IsDone()) {
519 return;
520 }
521 //
522 IntSurf_SequenceOfPathPoint seqpdep;
523 IntSurf_SequenceOfInteriorPoint seqpins;
524 //
525 NbPointRst = solrst.NbPoints();
526 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
527 if (NbPointRst) {
528 if (!reversed) {
529 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
530 }
531 else {
532 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
533 }
534 }
535 //
536 // Recherche des points interieurs
537 if (!reversed) {
538 if (myIsStartPnt)
539 solins.Perform(Func,Surf2,myUStart,myVStart);
540 else
541 solins.Perform(Func,Surf2,D2,TolTang);
542 }
543 else {
544 if (myIsStartPnt)
545 solins.Perform(Func,Surf1,myUStart,myVStart);
546 else
547 solins.Perform(Func,Surf1,D1,TolTang);
548 }
549 //
550 NbPointIns = solins.NbPoints();
551 for (i=1; i <= NbPointIns; i++) {
552 seqpins.Append(solins.Value(i));
553 }
554 NbPointDep=seqpdep.Length();
555 //
556 if (NbPointDep || NbPointIns) {
557 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
558 if (!reversed) {
559 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
560 }
561 else {
562 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
563 }
564 if(!iwalk.IsDone()) {
565 return;
566 }
567
568 Standard_Real Vmin, Vmax, TolV = 1.e-14;
569 if (!reversed) { //Surf1 is quadric
570 Vmin = Surf1->FirstVParameter();
571 Vmax = Surf1->LastVParameter();
572 }
573 else { //Surf2 is quadric
574 Vmin = Surf2->FirstVParameter();
575 Vmax = Surf2->LastVParameter();
576 }
577 //
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();
582
583 Nbpts = thelin->NbPoints();
584 if(Nbpts>=2) {
585
586 tgline = iwline->TangentVector(k);
587 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
588 valpt = thelin->Value(k).Value();
589
590 if (!reversed) {
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);
595 }
596 else {
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);
601 }
602 if (tgline.DotCross(norm2,norm1) > 0.) {
603 trans1 = IntSurf_Out;
604 trans2 = IntSurf_In;
605 }
606 else {
607 trans1 = IntSurf_In;
608 trans2 = IntSurf_Out;
609 }
610
611 //
612 Standard_Real AnU1,AnU2,AnV2;
613
614 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
615 Standard_Boolean arecadr=Standard_False;
616 valpt = thelin->Value(1).Value();
617 Quad.Parameters(valpt,AnU1,V1);
618
619 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
620 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
621
622 if(reversed) {
623 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
624 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
625 }
626 else {
627 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
628 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
629 }
630
631 if(typQuad==GeomAbs_Cylinder ||
632 typQuad==GeomAbs_Cone ||
633 typQuad==GeomAbs_Sphere) {
634 arecadr=Standard_True;
635 }
636 //
637 for (k=2; k<=Nbpts; ++k) {
638 valpt = thelin->Value(k).Value();
639 Quad.Parameters(valpt,U1,V1);
640 //
641 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
642 V1 = Vmin;
643 }
644 if((V1 > Vmax) && (V1-Vmax < TolV)) {
645 V1 = Vmax;
646 }
647 //
648 if(arecadr) {
649 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
650 Standard_Real aCf, aTwoPI;
651 //
652 aCf=0.;
c6541a0c
D
653 aTwoPI=M_PI+M_PI;
654 if ((U1-AnU1) > 1.5*M_PI) {
655 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
7fd59977 656 aCf=aCf+1.;
657 }
658 U1=U1-aCf*aTwoPI;
659 }
660 //
661 else {
c6541a0c 662 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
7fd59977 663 aCf=aCf+1.;
664 }
665 U1=U1+aCf*aTwoPI;
666 }
667 // was:
c6541a0c
D
668 //if ((U1-AnU1) > 1.5*M_PI) {
669 // U1-=M_PI+M_PI;
7fd59977 670 //}
c6541a0c
D
671 //else if ((U1-AnU1) < -1.5*M_PI) {
672 // U1+=M_PI+M_PI;
7fd59977 673 //}
674 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
675 }
676 //
677 if(reversed) {
678 thelin->SetUV(k,Standard_False,U1,V1);
679
680 thelin->Value(k).ParametersOnS1(U2,V2);
681 switch(typeS1) {
682 case GeomAbs_Cylinder:
683 case GeomAbs_Cone:
684 case GeomAbs_Sphere:
685 case GeomAbs_Torus:
c6541a0c
D
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;
7fd59977 688 break;
689 default:
690 break;
691 }
692 if(typeS2==GeomAbs_Torus) {
c6541a0c
D
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;
7fd59977 695 }
696 thelin->SetUV(k,Standard_True,U2,V2);
697 }
698 else {
699 thelin->SetUV(k,Standard_True,U1,V1);
700
701 thelin->Value(k).ParametersOnS2(U2,V2);
702 switch(typeS2) {
703 case GeomAbs_Cylinder:
704 case GeomAbs_Cone:
705 case GeomAbs_Sphere:
706 case GeomAbs_Torus:
c6541a0c
D
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;
7fd59977 709 break;
710 default:
711 break;
712 }
713 if(typeS2==GeomAbs_Torus) {
c6541a0c
D
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;
7fd59977 716 }
717 thelin->SetUV(k,Standard_False,U2,V2);
718
719 }
720
721 AnU1=U1;
722 AnU2=U2;
723 AnV2=V2;
724 }
725 // <-A
726 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
727
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);
738
739 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
740 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
741
742 PPoint.Parameters(themult,U2,V2);
743 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
744 }
745 else { //-- typeS1 != Pln && Cyl && Sph && Cone
746 Quad.Parameters(PPoint.Value(),U2,V2);
747
748 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
749 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
750
751 PPoint.Parameters(themult,U1,V1);
752 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
753 }
754
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.);
760
761 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
762
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);
767
768 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
769 if(squaremagnitudeVecNormale > 1e-13) {
770 DirNormale=VecNormale;
771 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
772 }
773 else {
774 TLine.SetValue(Standard_True,IntSurf_Undecided);
775 TArc.SetValue(Standard_True,IntSurf_Undecided);
776 }
777
778 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
779 if (!solrst.Point(i).IsNew()) {
780 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
781 }
782 wline->AddVertex(ptdeb);
783 if (themult == 0) {
784 wline->SetFirstPoint(wline->NbVertex());
785 }
786
787 themult--;
788 }
789 }
790 }
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());
800 }
801 else {
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());
810 }
811
812
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) {
821 if (!reversed) {
822 Quad.Parameters(PPoint.Value(),U1,V1);
823
824 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
825 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
826
827 PPoint.Parameters(themult,U2,V2);
828 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
829 VecNormale = d1u.Crossed(d1v); //-- @@@@
830 }
831 else {
832 Quad.Parameters(PPoint.Value(),U2,V2);
833
834 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
835 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
836
837 PPoint.Parameters(themult,U1,V1);
838 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
839 VecNormale = d1u.Crossed(d1v); //-- @@@@
840 }
841
842 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
843 ptfin.SetParameters(U1,V1,U2,V2);
844 ptfin.SetParameter(Nbpts);
845
846 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
847
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);
852
853
854 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
855 if(squaremagnitudeVecNormale > 1e-13) {
856 DirNormale=VecNormale;
857 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
858 }
859 else {
860 TLine.SetValue(Standard_True,IntSurf_Undecided);
861 TArc.SetValue(Standard_True,IntSurf_Undecided);
862 }
863
864
865 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
866 if (!solrst.Point(i).IsNew()) {
867 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
868 }
869 wline->AddVertex(ptfin);
870 if (themult == 0) {
871 wline->SetLastPoint(wline->NbVertex());
872 }
873
874 themult--;
875 }
876 }
877 }
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());
887 }
888 else {
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());
897 }
898 //
899 // Il faut traiter les points de passage.
900 slin.Append(wline);
901 }// if(Nbpts>=2) {
902 }// for (j=1; j<=Nblines; j++) {
903
904 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
905 // QUE SUR DES POINTS DE TANGENCE
906
907
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;
917 }
918 }
919 if (wlin1->HasLastPoint()) {
920 ptfin = wlin1->LastPoint(indlast);
921 if (ptfin.IsTangencyPoint()) {
922 dolast = Standard_True;
923 }
924 }
925
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()) {
933 if (dofirst ) {
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);
939 }
940 }
941 }
942 if (dolast ) {
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);
948 }
949 }
950 }
951 }
952 }
953 if (wlin2->HasLastPoint()) {
954 ptbis = wlin2->LastPoint(ind2);
955 if (ptbis.IsTangencyPoint()) {
956 if (dofirst ) {
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);
962 }
963 }
964 }
965 if (dolast ) {
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);
971 }
972 }
973 }
974 }
975 }
976 }
977 if(dofirst)
978 wlin1->Replace(indfirst,ptdeb);
979 if(dolast)
980 wlin1->Replace(indlast,ptfin);
981 }
982 }
983 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
984 //
985 // Treatment the segments
986 NbSegm = solrst.NbSegments();
987 if (NbSegm) {
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
998 //--
999 dofirst = dolast = Standard_False;
1000 procf = Standard_False;
1001 procl = Standard_False;
1002 IntSurf_Transition TLineUnk,TArcUnk;
1003
1004 IntPatch_Point _thepointAtBeg;
1005 IntPatch_Point _thepointAtEnd;
1006
1007 Standard_Boolean TransitionOK=Standard_False;
1008
1009 if(thesegm.HasFirstPoint()) {
1010 Standard_Real _u1,_v1,_u2,_v2;
1011
1012 dofirst = Standard_True;
1013 PStartf = thesegm.FirstPoint();
1014 paramf = PStartf.Parameter();
1015
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();
1025 }
1026 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1027 Quad.Parameters(_Pp,_u2,_v2);
1028 _u1=_p2d.X(); _v1=_p2d.Y();
1029 }
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);
1035
1036
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);
1042
1043 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1044 if(reversed) {
1045 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1046 }
1047 else {
1048 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1049 }
1050 _u1=tgline.DotCross(norm2,norm1);
1051 TransitionOK=Standard_True;
1052 if (_u1 > 0.00000001) {
1053 trans1 = IntSurf_Out;
1054 trans2 = IntSurf_In;
1055 }
1056 else if(_u1 < -0.00000001) {
1057 trans1 = IntSurf_In;
1058 trans2 = IntSurf_Out;
1059 }
1060 else {
1061 TransitionOK=Standard_False;
1062 }
1063 }
1064 if(thesegm.HasLastPoint()) {
1065 Standard_Real _u1,_v1,_u2,_v2;
1066
1067 dolast = Standard_True;
1068 PStartl = thesegm.LastPoint();
1069 paraml = PStartl.Parameter();
1070
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();
1081 }
1082 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1083 Quad.Parameters(_Pp,_u2,_v2);
1084 _u1=_p2d.X(); _v1=_p2d.Y();
1085 }
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);
1091
1092
1093
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);
1099
1100 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1101 if(reversed) {
1102 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1103 }
1104 else {
1105 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1106 }
1107 _u1=tgline.DotCross(norm2,norm1);
1108 TransitionOK=Standard_True;
1109 if (_u1 > 0.00000001) {
1110 trans1 = IntSurf_Out;
1111 trans2 = IntSurf_In;
1112 }
1113 else if(_u1 < -0.00000001) {
1114 trans1 = IntSurf_In;
1115 trans2 = IntSurf_Out;
1116 }
1117 else {
1118 TransitionOK=Standard_False;
1119 }
1120 }
1121 if(TransitionOK==Standard_False) {
1122 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1123 rline = new IntPatch_RLine (Standard_False);
1124 if(reversed) {
1125 rline->SetArcOnS1(thesegm.Curve());
1126 }
1127 else {
1128 rline->SetArcOnS2(thesegm.Curve());
1129 }
1130 }
1131 else {
1132 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1133 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1134 if(reversed) {
1135 rline->SetArcOnS1(thesegm.Curve());
1136 }
1137 else {
1138 rline->SetArcOnS2(thesegm.Curve());
1139 }
1140 }
1141
1142 //------------------------------
1143 //-- Ajout des points
1144 //--
1145 if (thesegm.HasFirstPoint()) {
1146 rline->AddVertex(_thepointAtBeg);
1147 rline->SetFirstPoint(rline->NbVertex());
1148 }
1149
1150 if (thesegm.HasLastPoint()) {
1151 rline->AddVertex(_thepointAtEnd);
1152 rline->SetLastPoint(rline->NbVertex());
1153 }
1154
1155 // Polygone sur restriction solution
1156 if (dofirst && dolast) {
1157 Standard_Real prm;
1158 gp_Pnt ptpoly;
1159 IntSurf_PntOn2S p2s;
1160 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1161 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1162 Standard_Integer nbsample = 100;
1163
1164 if (!reversed) {
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);
1169
1170 Quad.Parameters(ptpoly,U1,V1);
1171 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1172 Thelin->Add(p2s);
1173 }
1174 }
1175 else {
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);
1180
1181 Quad.Parameters(ptpoly,U2,V2);
1182 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1183 Thelin->Add(p2s);
1184 }
1185 }
1186 rline->Add(Thelin);
1187 }
1188
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();
1196 }
1197 else {
1198 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1199 }
1200 for (k=1; k<=Nbpts;k++) {
1201 if (typ == IntPatch_Walking) {
1202 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1203 }
1204 else {
1205 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1206 }
1207 if (dofirst) {
1208
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);
1213 }
1214 else {
1215 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1216 }
1217 ptdeb.SetParameter(paramf);
1218 rline->AddVertex(ptdeb);
1219 if (!procf){
1220 procf=Standard_True;
1221 rline->SetFirstPoint(rline->NbVertex());
1222 }
1223 }
1224 }
1225 if (dolast) {
1226 if(dofirst) { //-- on recharge le ptdeb
1227 if (typ == IntPatch_Walking) {
1228 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1229 }
1230 else {
1231 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1232 }
1233 }
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);
1238 }
1239 else {
1240 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1241 }
1242 ptdeb.SetParameter(paraml);
1243 rline->AddVertex(ptdeb);
1244 if (!procl){
1245 procl=Standard_True;
1246 rline->SetLastPoint(rline->NbVertex());
1247 }
1248 }
1249 }
1250 }
1251 }
1252 }
1253 slin.Append(rline);
1254 }
1255 }// if (NbSegm)
1256 //
1257 // on traite les restrictions de la surface implicite
1258 for (i=1; i<=slin.Length(); i++)
1259 {
1260 if (!reversed)
1261 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1262 else
1263 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1264 }
1265 empt = (slin.Length() == 0 && spnt.Length() == 0);
1266 done = Standard_True;
1267 //
1268 // post processing for cones and spheres
1269 if((Quad.TypeQuadric() == GeomAbs_Cone ||
1270 Quad.TypeQuadric() == GeomAbs_Sphere) &&
1271 slin.Length()) {
1272
1273 Handle(Adaptor3d_TopolTool) PDomain = (reversed) ? D1 : D2;
1274 Handle(Adaptor3d_HSurface) QSurf = (reversed) ? Surf2 : Surf1;
1275
1276 IntPatch_SequenceOfLine dslin;
1277 for(i = 1; i <= slin.Length(); i++ )
1278 DecomposeResult(slin(i),reversed,Quad,PDomain,QSurf,TolArc,dslin);
1279
1280 slin.Clear();
1281 for(i = 1; i <= dslin.Length(); i++ )
1282 slin.Append(dslin(i));
1283 }
1284}
1285
1286//==================================================================
1287// Decomposition of WLine goes through seam and/or apex routines
1288//==================================================================
1289
1290// reject all points and vertices not in V range on Quadric
1291static Handle(IntSurf_LineOn2S) VSplitLine(Handle(IntSurf_LineOn2S)& Line,
1292 Standard_Boolean IsReversed,
1293 Handle(Adaptor3d_HSurface)& QSurf,
1294 Handle(IntSurf_LineOn2S)& Vertices)
1295{
1296 Handle(IntSurf_LineOn2S) line = new IntSurf_LineOn2S();
1297
1298 Standard_Real VF = QSurf->FirstVParameter();
1299 Standard_Real VL = QSurf->LastVParameter();
1300
1301 Standard_Integer i = 0;
1302 Standard_Real U = 0., V = 0.;
1303
1304 for(i = 1; i <= Line->NbPoints(); i++) {
1305
1306 const IntSurf_PntOn2S& aP = Line->Value(i);
1307 if(IsReversed)
1308 aP.ParametersOnS2(U,V); // S2 - quadric
1309 else
1310 aP.ParametersOnS1(U,V); // S1 - quadric
1311
1312 if(VF <= V && V <= VL)
1313 line->Add(aP);
1314 }
1315
1316 Standard_Boolean isDeleted = Standard_True;
1317 Standard_Integer k = 0;
1318 while(isDeleted) {
1319
1320 isDeleted = Standard_False;
1321 k = 0;
1322
1323 for(i = 1; i <= Vertices->NbPoints(); i++) {
1324
1325 const IntSurf_PntOn2S& aV = Vertices->Value(i);
1326 if(IsReversed)
1327 aV.ParametersOnS2(U,V); // S2 - quadric
1328 else
1329 aV.ParametersOnS1(U,V); // S1 - quadric
1330
1331 if(VF <= V && V <= VL)
1332 continue;
1333 else {
1334 k = i;
1335 break;
1336 }
1337 }
1338
1339 if(k != 0) {
1340 isDeleted = Standard_True;
1341 Vertices->RemovePoint(k);
1342 }
1343 else
1344 break;
1345 }
1346
1347 return line;
1348}
1349
1350// correct U parameter of the start point of line on Quadric
1351// (change 0->2PI or vs, if necessary)
1352static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1353{
1354 Standard_Real u = U1;
1355
1356 // case: no adjustment
c6541a0c 1357 if( U1 > 0. && U1 < (2.*M_PI) )
7fd59977 1358 return u;
1359
1360 // case: near '0'
1361 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
c6541a0c
D
1362 if( U2 > 0. && U2 < (2.*M_PI) )
1363 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
7fd59977 1364 else {
1365 Standard_Real uu = U2;
c6541a0c
D
1366 if( U2 > (2.*M_PI) )
1367 while( uu > (2.*M_PI) )
1368 uu -= (2.*M_PI);
7fd59977 1369 else
1370 while( uu < 0.)
c6541a0c 1371 uu += (2.*M_PI);
7fd59977 1372
c6541a0c 1373 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
7fd59977 1374 }
1375 }
1376 // case: near '2PI'
c6541a0c
D
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);
7fd59977 1380 else {
1381 Standard_Real uu = U2;
c6541a0c
D
1382 if( U2 > (2.*M_PI) )
1383 while( uu > (2.*M_PI) )
1384 uu -= (2.*M_PI);
7fd59977 1385 else
1386 while( uu < 0.)
c6541a0c 1387 uu += (2.*M_PI);
7fd59977 1388
c6541a0c 1389 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
7fd59977 1390 }
1391 }
1392 // case: '<0. || >2PI'
1393 else {
1394 if(U1 < 0.)
1395 while(u < 0.)
c6541a0c
D
1396 u += 2.*M_PI;
1397 if(U1 > (2.*M_PI))
1398 while(u > (2.*M_PI))
1399 u -= (2.*M_PI);
7fd59977 1400 }
1401
1402 return u;
1403}
1404
7fd59977 1405// collect vertices, reject equals
1406static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
1407 const Standard_Boolean ,//IsReversed,
1408 const Standard_Real TOL3D,
1409 const Standard_Real TOL2D)
1410{
1411// Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
1412
1413 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1414
1415 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1416 Standard_Integer i = 0, k = 0;
1417 Standard_Integer NbVrt = WLine->NbVertex();
1418
1419 TColStd_Array1OfInteger anVrts(1,NbVrt);
1420 anVrts.Init(0);
1421
1422 // check equal vertices
1423 for(i = 1; i <= NbVrt; i++) {
1424
1425 if( anVrts(i) == -1 ) continue;
1426
1427 const IntPatch_Point& Pi = WLine->Vertex(i);
1428
1429 for(k = (i+1); k <= NbVrt; k++) {
1430
1431 if( anVrts(k) == -1 ) continue;
1432
1433 const IntPatch_Point& Pk = WLine->Vertex(k);
1434
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;
1442
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;
1447
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;
1452
1453 if((sameU1 && sameV1) && (sameU2 && sameV2))
1454 anVrts(k) = -1;
1455 }
1456 }
1457 }
1458
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());
1463 }
1464 return vertices;
1465}
1466
1467static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
1468 const IntSurf_PntOn2S& P2)
1469{
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;
1488 }
1489 return result;
1490}
1491
1492static void ForcedPurgePoints(Handle(IntSurf_LineOn2S)& Result,
1493 Standard_Boolean IsReversed,
1494 IntSurf_Quadric& Quad)
1495{
1496 if(Result->NbPoints() <= 30) return;
1497 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1498
3fa7e3e7 1499 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
7fd59977 1500 if(IsReversed) {
1501 Result->Value(1).ParametersOnS2(U1,V1);
1502 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1503 }
1504 else {
3fa7e3e7 1505 Result->Value(1).ParametersOnS1(U1,V1);
1506 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
7fd59977 1507 }
1508
3fa7e3e7 1509 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1510 Standard_Real Uapx = 0., Vapx = 0.;
1511 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1512
7fd59977 1513 if(fabs(V1-Vapx) <= 1.e-3)
1514 IndexLimF = 12;
1515 if(fabs(V2-Vapx) <= 1.e-3)
1516 IndexLimL = 12;
1517 }
1518
1519 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
c6541a0c 1520 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
3fa7e3e7 1521
7fd59977 1522 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1523 IndexLimF = 12;
1524 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1525 IndexLimL = 12;
1526 }
1527
1528 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1529 Result->RemovePoint(2);
1530 Index++;
1531 }
1532 Index = 0;
1533 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1534 Result->RemovePoint(Result->NbPoints()-1);
1535 Index++;
1536 }
1537}
1538
1539// DEBUG FUNCTION !!!
1540#if 0
1541static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
1542 Standard_Boolean IsReversed,
1543 Standard_Integer Number)
1544{
1545 cout << "DUMP LINE" << endl;
1546 Standard_Integer i;
1547 Standard_Real U,V;
1548 for(i = 1; i <= Line->NbPoints(); i++) {
1549 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1550 if(IsReversed)
1551 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1552 else
1553 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1554 cout << "point p" << i << " " << U << " " << V << endl;
1555 }
1556 }
1557 cout << endl;
1558}
1559#endif
1560// DEBUG FUNCTION !!!
1561
1562static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
1563 const Handle(IntSurf_LineOn2S)& Vertices,
1564 TColStd_Array1OfInteger& PTypes)
1565{
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)) {
1574 type = iv;
1575 break;
1576 }
1577 }
1578 PTypes(ip) = type;
1579 }
1580}
1581
1582static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
1583 const Standard_Real TOL2D)
1584{
c6541a0c 1585 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
7fd59977 1586}
1587
1588static inline Standard_Real AdjustU(const Standard_Real U)
1589{
c6541a0c 1590 Standard_Real u = U, DBLPI = 2.*M_PI;
7fd59977 1591 if(u < 0. || u > DBLPI) {
1592 if(u < 0.)
1593 while(u < 0.)
1594 u += DBLPI;
1595 else
1596 while(u > DBLPI)
1597 u -= DBLPI;
1598 }
1599 return u;
1600}
1601
1602static 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,
1607 Standard_Real& U,
1608 Standard_Real& V)
1609{
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;
1619}
1620
1621static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
1622 const Standard_Boolean IsReversed,
1623 const Handle(Adaptor3d_HSurface)& QSurf,
1624 const Standard_Real TOL2D)
1625{
1626 Standard_Real VF = QSurf->FirstVParameter();
1627 Standard_Real VL = QSurf->LastVParameter();
1628 Standard_Real UF = QSurf->FirstUParameter();
1629 Standard_Real UL = QSurf->LastUParameter();
1630
1631 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1632 Standard_Real U = 0., V = 0.;
1633 for(ip = 1; ip <= nbp; ip++) {
1634 if(IsReversed) {
1635 Line->Value(ip).ParametersOnS2(U,V);
1636 U = AdjustU(U);
1637 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1638 Line->SetUV(ip,Standard_False,U,V);
1639 }
1640 else {
1641 Line->Value(ip).ParametersOnS1(U,V);
1642 U = AdjustU(U);
1643 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1644 Line->SetUV(ip,Standard_True,U,V);
1645 }
1646 }
1647}
1648
1649static 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)
1654{
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);
1660 if(ipt != 0) {
1661 const IntSurf_PntOn2S& aP = Line->Value(ip);
1662 if(IsReversed)
1663 aP.ParametersOnS2(U,V); // S2 - quadric
1664 else
1665 aP.ParametersOnS1(U,V); // S1 - quadric
1666 U = AdjustU(U);
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);
1671 if(IsReversed)
1672 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1673 else
1674 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1675 Standard_Real u = AdjustUFirst(U,U1);
c6541a0c 1676 if(fabs(u-U) >= 1.5*M_PI) {
7fd59977 1677 Standard_Real U2 = 0., V2 = 0.;
1678 if(IsReversed) {
1679 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1680 Line->SetUV(ip,Standard_False,u,V);
1681 Line->SetUV(ip,Standard_True,U2,V2);
1682 }
1683 else {
1684 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1685 Line->SetUV(ip,Standard_True,u,V);
1686 Line->SetUV(ip,Standard_False,U2,V2);
1687 }
1688 }
1689 }
1690 else {
1691 Standard_Integer ipp = ip - 1;
1692 Standard_Integer ipn = ip + 1;
1693 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1694 if(IsReversed) {
1695 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1696 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1697 }
1698 else {
1699 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1700 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1701 }
1702 U1 = AdjustU(U1);
1703 U2 = AdjustU(U2);
c6541a0c
D
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;
7fd59977 1706 if(pnearZero == cnearZero) {
1707 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
c6541a0c 1708 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
7fd59977 1709 IntSurf_PntOn2S nP;
1710 nP.SetValue(aP.Value());
1711 Standard_Real U3 = 0., V3 = 0.;
1712 if(IsReversed) {
1713 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1714 nP.SetValue(Standard_False,nU,V);
1715 nP.SetValue(Standard_True,U3,V3);
1716 }
1717 else {
1718 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1719 nP.SetValue(Standard_True,nU,V);
1720 nP.SetValue(Standard_False,U3,V3);
1721 }
1722 Line->InsertBefore(ipn,nP);
1723 Vertices->Add(nP);
1724 result = Standard_True;
1725 break;
1726 }
1727 }
1728 else {
1729 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
c6541a0c 1730 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
7fd59977 1731 IntSurf_PntOn2S nP;
1732 nP.SetValue(aP.Value());
1733 Standard_Real U3 = 0., V3 = 0.;
1734 if(IsReversed) {
1735 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1736 nP.SetValue(Standard_False,nU,V);
1737 nP.SetValue(Standard_True,U3,V3);
1738 }
1739 else {
1740 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1741 nP.SetValue(Standard_True,nU,V);
1742 nP.SetValue(Standard_False,U3,V3);
1743 }
1744 Line->InsertBefore(ip,nP);
1745 Vertices->Add(nP);
1746 result = Standard_True;
1747 break;
1748 }
1749 else {
1750// Line->InsertBefore(ip,Line->Value(ipn));
1751// Line->RemovePoint(ip+2);
1752// result = Standard_True;
1753// cout << "swap vertex " << endl;
1754// break;
1755 }
1756 }
1757 }
1758 }
1759 }
1760 }
1761 return result;
1762}
1763
1764static void ToSmooth(Handle(IntSurf_LineOn2S)& Line,
1765 Standard_Boolean IsReversed,
1766 IntSurf_Quadric& Quad,
1767 Standard_Boolean IsFirst,
1768 Standard_Real& D3D)
1769{
1770 if(Line->NbPoints() <= 10)
1771 return;
1772
1773 D3D = 0.;
1774 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1775 if(NbTestPnts < 5) NbTestPnts = 5;
1776
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.;
1780
1781 for(ip = startp; ip <= NbTestPnts; ip++) {
1782 if(IsReversed) {
1783 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1784 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1785 }
1786 else {
1787 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1788 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1789 }
1790 DDU += fabs(fabs(Uc)-fabs(Un));
1791 DDV += fabs(fabs(Vc)-fabs(Vn));
1792
1793 if(ip > startp) {
1794 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1795 D3D += DP;
1796 }
1797 }
1798
1799 DDU /= (Standard_Real) NbTestPnts + 1;
1800 DDV /= (Standard_Real) NbTestPnts + 1;
1801
1802 D3D /= (Standard_Real) NbTestPnts + 1;
1803
1804
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);
1808
1809 Standard_Boolean doU = Standard_False;
1810 Standard_Boolean doV = Standard_False;
1811
1812 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1813
1814 if(IsReversed) {
1815 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1816 Line->Value(Index2).ParametersOnS2(U2,V2);
1817 Line->Value(Index3).ParametersOnS2(U3,V3);
1818 }
1819 else {
1820 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1821 Line->Value(Index2).ParametersOnS1(U2,V2);
1822 Line->Value(Index3).ParametersOnS1(U3,V3);
1823 }
1824
1825 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
c6541a0c 1826 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
7fd59977 1827
c6541a0c
D
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) {}
7fd59977 1830 else {
1831 doU = Standard_False;
1832 }
1833 }
1834 }
1835
1836 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1837 Standard_Real Uapx = 0., Vapx = 0.;
1838 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1839
c6541a0c 1840 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
7fd59977 1841
c6541a0c 1842 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
7fd59977 1843 if(fabs(V1-Vapx) <= 1.e-9) {}
1844 else {
1845 doU = Standard_False;
1846 }
1847 }
1848 }
1849
1850 if(fabs(fabs(V1)-fabs(V2)) > DDV) doV = Standard_True;
1851
1852 if(doU) {
1853 Standard_Real dU = Min((DDU/10.),5.e-8);
1854 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1855 if(IsReversed)
1856 Line->SetUV(Index1,Standard_False,U,V1);
1857 else
1858 Line->SetUV(Index1,Standard_True,U,V1);
1859 U1 = U;
1860 }
1861}
1862
1863static 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)
1868
1869{
1870 Standard_Boolean result = Standard_False;
1871 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1872 if(IsReversed) {
1873 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1874 aV.ParametersOnS1(Uv,Vv);
1875 }
1876 else {
1877 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1878 aV.ParametersOnS2(Uv,Vv);
1879 }
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;
1885 return result;
1886}
1887
1888static 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)
1898{
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.;
1904 if(IsReversed) {
1905 aPF.ParametersOnS2(UF,VF);
1906 aPL.ParametersOnS2(UL,VL);
1907 }
1908 else {
1909 aPF.ParametersOnS1(UF,VF);
1910 aPL.ParametersOnS1(UL,VL);
1911 }
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;
1916
1917 Standard_Integer iv = 0;
1918
1919 for(iv = 1; iv <= nbv; iv++) {
1920 Standard_Real Uv = 0., Vv = 0.;
1921 if(IsReversed) {
1922 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1923 Uv = AdjustU(Uv);
1924 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1925 }
1926 else {
1927 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1928 Uv = AdjustU(Uv);
1929 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1930 }
1931 }
1932
1933 for(iv = 1; iv <= nbv; iv++) {
1934 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1935 if(AreSamePoints(aPF,aV)) {
1936 FIndexSame = iv;
1937 break;
1938 }
1939 else {
1940 Standard_Real Uv = 0., Vv = 0.;
1941 if(IsReversed)
1942 aV.ParametersOnS2(Uv,Vv);
1943 else
1944 aV.ParametersOnS1(Uv,Vv);
1945 gp_Pnt2d a2DV(Uv,Vv);
1946 Standard_Real Dist = a2DV.Distance(a2DPF);
1947 if(Dist < DistMinF) {
1948 DistMinF = Dist;
1949 FIndexNear = iv;
1950 if(FConjugated != 0)
1951 FConjugated = 0;
1952 }
1953 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 1954 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 1955 gp_Pnt2d a2DCV(Ucv,Vv);
1956 Standard_Real CDist = a2DCV.Distance(a2DPF);
1957 if(CDist < DistMinF) {
1958 DistMinF = CDist;
1959 FConjugated = iv;
1960 FIndexNear = iv;
1961 }
1962 }
1963 }
1964 }
1965
1966 for(iv = 1; iv <= nbv; iv++) {
1967 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1968 if(AreSamePoints(aPL,aV)) {
1969 LIndexSame = iv;
1970 break;
1971 }
1972 else {
1973 Standard_Real Uv = 0., Vv = 0.;
1974 if(IsReversed)
1975 aV.ParametersOnS2(Uv,Vv);
1976 else
1977 aV.ParametersOnS1(Uv,Vv);
1978 gp_Pnt2d a2DV(Uv,Vv);
1979 Standard_Real Dist = a2DV.Distance(a2DPL);
1980 if(Dist < DistMinL) {
1981 DistMinL = Dist;
1982 LIndexNear = iv;
1983 if(LConjugated != 0)
1984 LConjugated = 0;
1985 }
1986 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 1987 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 1988 gp_Pnt2d a2DCV(Ucv,Vv);
1989 Standard_Real CDist = a2DCV.Distance(a2DPL);
1990 if(CDist < DistMinL) {
1991 DistMinL = CDist;
1992 LConjugated = iv;
1993 LIndexNear = iv;
1994 }
1995 }
1996 }
1997 }
1998
1999 AddFirst = Standard_False;
2000 AddLast = Standard_False;
2001
2002 if(FIndexSame == 0) {
2003 if(FIndexNear != 0) {
2004 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2005 Standard_Real Uv = 0., Vv = 0.;
2006 if(IsReversed)
2007 aV.ParametersOnS2(Uv,Vv);
2008 else
2009 aV.ParametersOnS1(Uv,Vv);
2010 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 2011 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 2012 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2013 if(test) {
2014 VrtF.SetValue(aV.Value());
2015 if(IsReversed) {
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);
2021 else
2022 VrtF.SetValue(Standard_False,Ucv,Vv);
2023 }
2024 else {
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);
2030 else
2031 VrtF.SetValue(Standard_True,Ucv,Vv);
2032 }
2033 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2034 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2035 AddFirst = Standard_True;
2036 }
2037 }
2038 }
2039 else {
2040 // to do: analyze internal vertex
2041 }
2042 }
2043 }
2044
2045 if(LIndexSame == 0) {
2046 if(LIndexNear != 0) {
2047 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2048 Standard_Real Uv = 0., Vv = 0.;
2049 if(IsReversed)
2050 aV.ParametersOnS2(Uv,Vv);
2051 else
2052 aV.ParametersOnS1(Uv,Vv);
2053 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 2054 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 2055 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2056 if(test) {
2057 VrtL.SetValue(aV.Value());
2058 if(IsReversed) {
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);
2064 else
2065 VrtL.SetValue(Standard_False,Ucv,Vv);
2066 }
2067 else {
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);
2073 else
2074 VrtL.SetValue(Standard_True,Ucv,Vv);
2075 }
2076 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2077 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2078 AddLast = Standard_True;
2079 }
2080 }
2081 }
2082 else {
2083 // to do: analyze internal vertex
2084 }
2085 }
2086 }
2087}
2088
2089static 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)
2096{
2097 Standard_Boolean result = Standard_False;
2098 if(AddFirst) {
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;
2103 }
2104 }
2105 if(AddLast) {
2106 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2107 if((D3DL*2.) > DL && DL > 1.5e-7) {
2108 Line->Add(VrtL);
2109 result = Standard_True;
2110 }
2111 }
2112 return result;
2113}
2114
2115
2116static 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)
2121{
2122 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2123
2124 if(nbp < 3)
2125 return;
2126
2127 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2128 Standard_Integer ip = 0, iv = 0;
2129 gp_Pnt aPnt;
2130 IntPatch_Point thePnt;
2131 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
2132
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);
2145 }
2146 }
2147 }
2148}
2149
2150static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
2151 Handle(IntSurf_LineOn2S)& Vertices)
2152{
2153 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2154 Standard_Integer ip = 0, iv = 0;
2155 Standard_Boolean result = Standard_False;
2156
2157 if(nbp < 3)
2158 return result;
2159
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;
2166 break;
2167 }
2168 }
2169 if(result)
2170 break;
2171 }
2172
2173 return result;
2174}
2175static 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)
2182{
2183 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2184 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2185
2186 Standard_Integer ip = 0;
2187 for(ip = ParFirst; ip <= ParLast; ip++)
2188 sline->Add(SLine->Value(ip));
2189
2190 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2191
2192 gp_Pnt aSPnt;
2193 IntPatch_Point TPntF,TPntL;
2194 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2195
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);
2204
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());
2213
2214 return wline;
2215}
2216
2217static 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)
2223{
2224 Standard_Boolean result = Standard_False;
2225 Segments.Clear();
2226
2227 Standard_Integer nbv = WLine->NbVertex();
2228 if(nbv > 3) {
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)
2234 continue;
2235 else {
2236 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,ArcTol,firstPar,lastPar);
2237 Segments.Append(splitwline);
2238 if(!result)
2239 result = Standard_True;
2240 }
2241 }
2242 }
2243 return result;
2244}
2245
2246void 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)
2253{
2254 if( Line->ArcType() != IntPatch_Walking ) {
2255 Lines.Append(Line);
2256 return;
2257 }
2258
2259 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2260 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2261
2262 if(SLine->NbPoints() <= 2) {
2263 Lines.Append(Line);
2264 return;
2265 }
2266
2267 Standard_Real TOL3D = 1.e-10, TOL2D = 1.e-8, TOL2DS = 1.e-5;
2268
2269 Handle(IntSurf_LineOn2S) vline = GetVertices(WLine,IsReversed,TOL3D,TOL2D);
2270 Handle(IntSurf_LineOn2S) SSLine = VSplitLine(SLine,IsReversed,QSurf,vline);
2271
2272 if(SSLine->NbPoints() <= 1)
2273 return;
2274
2275 AdjustLine(SSLine,IsReversed,QSurf,TOL2D);
2276
2277 Standard_Boolean isInserted = Standard_True;
2278 while(isInserted) {
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);
2283 }
2284
2285 if(SSLine->NbPoints() == 2) {
2286 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2287 if(IsReversed) {
2288 SSLine->Value(1).ParametersOnS2(uu1,vv1);
2289 SSLine->Value(2).ParametersOnS2(uu2,vv2);
2290 }
2291 else {
2292 SSLine->Value(1).ParametersOnS1(uu1,vv1);
2293 SSLine->Value(2).ParametersOnS1(uu2,vv2);
2294 }
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) {
2300 gp_Pnt aSPnt;
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);
2320 return;
2321 }
2322 else
2323 return;
2324 }
2325 else
2326 return;
2327 }
2328
2329 Standard_Integer NbPnts = SSLine->NbPoints();
2330
c6541a0c
D
2331 Standard_Real BSEAM = 1.5*M_PI; // delta U crossing seam
2332 Standard_Real BAPEX = M_PI/16.; // delta U crossing apex
7fd59977 2333
6e6cd5d9 2334 Standard_Integer k = 0;
7fd59977 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;
2337
2338 gp_Pnt aPnt, aSPnt;
2339 IntPatch_Point TPntF,TPntL,TPntS;
2340
2341 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
2342 Handle(IntPatch_WLine) wline;
2343 IntPatch_SequenceOfLine lines;
2344
2345 // build WLine parts (if any)
2346 nextline:;
2347
2348 //if((Lindex-Findex+1) <= 2 )
2349 if((Lindex-Findex+1) <= 1 )
2350 return;
2351
2352 // reset variables
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.;
2356
2357 // analyze other points
2358 for(k = Findex; k <= Lindex; k++) {
2359
2360 if( k == Findex ) {
2361
2362 if(IsReversed) {
2363 SSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2364 }
2365 else {
2366 SSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2367 }
2368 sline->Add(SSLine->Value(k));
2369 AnV1 = V1;
2370 continue;
2371 }
2372
2373 if(IsReversed) {
2374 SSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
2375 }
2376 else {
2377 SSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
2378 }
2379
2380 Standard_Real DeltaU = fabs(U1-AnU1);
2381 if(DeltaU > BSEAM) {
2382 Bindex = k;
2383 isDecomposited = Standard_True;
2384 is2PIDecomposed = Standard_True;
2385 break;
2386 }
2387 else if((DeltaU > BAPEX) && (k >= (Findex+10) && k <= (Lindex-10))) {
2388 Bindex = k;
2389 isDecomposited = Standard_True;
2390 break;
2391 }
2392 else {}
2393
2394 sline->Add(SSLine->Value(k));
2395 AnU1=U1;
2396 AnV1=V1;
2397 }
2398
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);
2402
2403 Standard_Boolean hasInternals = HasInternals(sline,vline);
2404
2405 Standard_Real D3F = 0., D3L = 0.;
2406 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2407 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2408
2409 if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2410 D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2411 }
2412 if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2413 D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->Value(sline->NbPoints()-2).Value());
2414 }
2415
2416 if(addVF || addVL) {
2417 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2418 if(isAdded) {
2419 ToSmooth(sline,IsReversed,Quad,Standard_True,D3F);
2420 ToSmooth(sline,IsReversed,Quad,Standard_False,D3L);
2421 }
2422 }
2423
2424 if(!hasInternals) {
2425 ForcedPurgePoints(sline,IsReversed,Quad);
2426 }
2427
2428 wline = new IntPatch_WLine(sline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2());
2429
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);
2438
2439 if(hasInternals) {
2440 PutIntVertices(wline,sline,IsReversed,vline,ArcTol);
2441 }
2442
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());
2451
2452 IntPatch_SequenceOfLine segm;
2453 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,Line->TransitionOnS1(),Line->TransitionOnS2(),ArcTol,segm);
2454
2455 if(!isSplited)
2456 Lines.Append(wline);
2457 else {
2458 Standard_Integer nbsegms = segm.Length();
2459 Standard_Integer iseg = 0;
2460 for(iseg = 1; iseg <= nbsegms; iseg++)
2461 Lines.Append(segm(iseg));
2462 }
2463
2464 if(isDecomposited) {
2465 Findex = Bindex;
2466 sline = new IntSurf_LineOn2S();
2467 goto nextline;
2468 }
2469}
2470/*
2471// <-A
2472 {
2473 Standard_Integer aNbPnts;
2474 Standard_Real aU1,aV1,aU2,aV2;
2475 gp_Pnt aPx;
2476 //
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);
2481 aPx=aPoint.Value();
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);
2485 }
2486 }
2487*/