0025106: Command "splitshape" does not split attached face by attached edge
[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
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <IntPatch_ImpPrmIntersection.ixx>
18
19#include <Standard_ConstructionError.hxx>
20#include <IntPatch_SequenceOfLine.hxx>
21#include <TColStd_Array1OfInteger.hxx>
22#include <IntSurf_PntOn2S.hxx>
23#include <IntSurf_LineOn2S.hxx>
24#include <IntSurf.hxx>
e618b526 25#include <IntSurf_InteriorPoint.hxx>
7fd59977 26
27#include <Adaptor2d_HCurve2d.hxx>
28#include <IntSurf_PathPoint.hxx>
29#include <IntSurf_SequenceOfPathPoint.hxx>
30#include <IntPatch_TheIWalking.hxx>
31#include <IntPatch_TheIWLineOfTheIWalking.hxx>
32#include <IntPatch_ThePathPointOfTheSOnBounds.hxx>
33#include <IntPatch_TheSegmentOfTheSOnBounds.hxx>
34#include <IntPatch_TheSurfFunction.hxx>
35#include <IntPatch_RLine.hxx>
36#include <IntPatch_WLine.hxx>
37#include <IntPatch_ArcFunction.hxx>
38#include <IntPatch_RstInt.hxx>
191478a5 39#ifndef DEB
40#define No_Standard_RangeError
41#define No_Standard_OutOfRange
42#endif
43
44
45#include <math_Vector.hxx>
46#include <math_Matrix.hxx>
47#include <TopTrans_CurveTransition.hxx>
48#include <TopAbs_State.hxx>
49#include <TopAbs_Orientation.hxx>
50#include <TColStd_Array1OfInteger.hxx>
51#include <TColStd_Array1OfReal.hxx>
52
53#include <IntSurf_SequenceOfInteriorPoint.hxx>
54#include <IntSurf_QuadricTool.hxx>
55#include <GeomAbs_SurfaceType.hxx>
56
57static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& Line,
58 const Standard_Boolean IsReversed,
59 const IntSurf_Quadric& Quad,
60 const Handle(Adaptor3d_TopolTool)& PDomain,
61 const Handle(Adaptor3d_HSurface)& QSurf,
62 const Standard_Real ArcTol,
63 IntPatch_SequenceOfLine& Lines);
64static
65 void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
66 IntSurf_SequenceOfPathPoint& seqpdep,
67 const Handle(Adaptor3d_TopolTool)& Domain,
68 IntPatch_TheSurfFunction& Func,
69 const Handle(Adaptor3d_HSurface)& PSurf,
70 TColStd_Array1OfInteger& Destination);
71static
72 void Recadre(const Standard_Boolean ,
73 GeomAbs_SurfaceType typeS1,
74 GeomAbs_SurfaceType typeS2,
75 IntPatch_Point& pt,
76 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
77 Standard_Integer Param,
78 Standard_Real U1,
79 Standard_Real V1,
80 Standard_Real U2,
81 Standard_Real V2);
7fd59977 82
83//=======================================================================
84//function : IntPatch_ImpPrmIntersection
85//purpose :
86//=======================================================================
7fd59977 87IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection ()
191478a5 88 : done(Standard_False),
89 empt(Standard_False),
90 myIsStartPnt(Standard_False),
91 myUStart(0.0),
92 myVStart(0.0)
7fd59977 93{ }
94
95
96//=======================================================================
97//function : IntPatch_ImpPrmIntersection
98//purpose :
99//=======================================================================
100
101IntPatch_ImpPrmIntersection::IntPatch_ImpPrmIntersection
191478a5 102 (const Handle(Adaptor3d_HSurface)& Surf1,
103 const Handle(Adaptor3d_TopolTool)& D1,
104 const Handle(Adaptor3d_HSurface)& Surf2,
105 const Handle(Adaptor3d_TopolTool)& D2,
106 const Standard_Real TolArc,
107 const Standard_Real TolTang,
108 const Standard_Real Fleche,
109 const Standard_Real Pas)
110 : done(Standard_False),
111 empt(Standard_False),
112 myIsStartPnt(Standard_False),
113 myUStart(0.0),
114 myVStart(0.0)
7fd59977 115{
116 Perform(Surf1,D1,Surf2,D2,TolArc,TolTang,Fleche,Pas);
117}
118
119
120//=======================================================================
121//function : SetStartPoint
122//purpose :
123//=======================================================================
124
125void IntPatch_ImpPrmIntersection::SetStartPoint(const Standard_Real U,
191478a5 126 const Standard_Real V)
7fd59977 127{
128 myIsStartPnt = Standard_True;
129 myUStart = U; myVStart = V;
130}
131
7fd59977 132//=======================================================================
133//function : ComputeTangency
134//purpose :
135//=======================================================================
136void ComputeTangency (const IntPatch_TheSOnBounds& solrst,
191478a5 137 IntSurf_SequenceOfPathPoint& seqpdep,
138 const Handle(Adaptor3d_TopolTool)& Domain,
139 IntPatch_TheSurfFunction& Func,
140 const Handle(Adaptor3d_HSurface)& PSurf,
141 TColStd_Array1OfInteger& Destination)
7fd59977 142{
143 Standard_Integer i,k, NbPoints, seqlength;
144 Standard_Real theparam,test;
145 Standard_Boolean fairpt, ispassing;
146 TopAbs_Orientation arcorien,vtxorien;
147 Handle(Adaptor2d_HCurve2d) thearc;
148 Handle(Adaptor3d_HVertex) vtx,vtxbis;
149 //Standard_Boolean ispassing;
150 IntPatch_ThePathPointOfTheSOnBounds PStart;
151 IntSurf_PathPoint PPoint;
152 gp_Vec vectg;
153 gp_Dir2d dirtg;
154 gp_Pnt ptbid;
155 gp_Vec d1u,d1v,v1,v2;
156 gp_Pnt2d p2d;
157 gp_Vec2d d2d;
158 //
1ef32e96
RL
159 double aX[2], aF[1], aD[1][2];
160 math_Vector X(aX, 1, 2);
161 math_Vector F(aF, 1, 1);
162 math_Matrix D(aD, 1, 1, 1, 2);
7fd59977 163 //
164 seqlength = 0;
165 NbPoints = solrst.NbPoints();
166 for (i=1; i<= NbPoints; i++) {
167 if (Destination(i) == 0) {
168 PStart = solrst.Point(i);
169 thearc = PStart.Arc();
170 theparam = PStart.Parameter();
171 arcorien = Domain->Orientation(thearc);
172 ispassing = (arcorien == TopAbs_INTERNAL ||
191478a5 173 arcorien == TopAbs_EXTERNAL);
174
7fd59977 175 thearc->D0(theparam,p2d);
176 X(1) = p2d.X();
177 X(2) = p2d.Y();
178 PPoint.SetValue(PStart.Value(),X(1),X(2));
191478a5 179
7fd59977 180 Func.Values(X,F,D);
181 if (Func.IsTangent()) {
191478a5 182 PPoint.SetTangency(Standard_True);
7fd59977 183 Destination(i) = seqlength+1;
191478a5 184 if (!PStart.IsNew()) {
185 vtx = PStart.Vertex();
186 for (k=i+1; k<=NbPoints; k++) {
187 if (Destination(k) ==0) {
188 PStart = solrst.Point(k);
189 if (!PStart.IsNew()) {
190 vtxbis = PStart.Vertex();
191 if (Domain->Identical(vtx,vtxbis)) {
192 thearc = PStart.Arc();
193 theparam = PStart.Parameter();
194 arcorien = Domain->Orientation(thearc);
195 ispassing = ispassing && (arcorien == TopAbs_INTERNAL ||
196 arcorien == TopAbs_EXTERNAL);
197
198 thearc->D0(theparam,p2d);
199 PPoint.AddUV(p2d.X(),p2d.Y());
200 Destination(k) = seqlength+1;
201 }
202 }
203 }
204 }
205 }
206 PPoint.SetPassing(ispassing);
207 seqpdep.Append(PPoint);
208 seqlength++;
7fd59977 209 }
210 else { // on a un point de depart potentiel
211
191478a5 212 vectg = Func.Direction3d();
213 dirtg = Func.Direction2d();
214
215 PSurf->D1(X(1),X(2),ptbid,d1u,d1v);
216 thearc->D1(theparam,p2d,d2d);
217 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
218 v1 = d1u.Crossed(d1v);
219
220 test = vectg.Dot(v1.Crossed(v2));
221 if (PStart.IsNew()) {
222 if ((test < 0. && arcorien == TopAbs_FORWARD) ||
223 (test > 0. && arcorien == TopAbs_REVERSED)) {
224 vectg.Reverse();
225 dirtg.Reverse();
226 }
227 PPoint.SetDirections(vectg,dirtg);
228 PPoint.SetPassing(ispassing);
7fd59977 229 Destination(i) = seqlength+1;
191478a5 230 seqpdep.Append(PPoint);
231 seqlength++;
232 }
233 else { // traiter la transition complexe
234 gp_Dir bidnorm(1.,1.,1.);
235 Standard_Real tole = 1.e-8;
236 TopAbs_Orientation LocTrans;
237 TopTrans_CurveTransition comptrans;
238 comptrans.Reset(vectg,bidnorm,0.);
239 if (arcorien == TopAbs_FORWARD ||
240 arcorien == TopAbs_REVERSED) {
241 // pour essai
242
243 vtx = PStart.Vertex();
244 vtxorien = Domain->Orientation(vtx);
245 if (Abs(test) <= tole) {
246 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
247 }
248 else {
249 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
250 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
251 LocTrans = TopAbs_FORWARD;
252 }
253 else {
254 LocTrans = TopAbs_REVERSED;
255 }
256 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
257 }
258
259 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
260 }
7fd59977 261 Destination(i) = seqlength+1;
191478a5 262 for (k= i+1; k<=NbPoints; k++) {
263 if (Destination(k) == 0) {
264 PStart = solrst.Point(k);
265 if (!PStart.IsNew()) {
266 vtxbis = PStart.Vertex();
267 if (Domain->Identical(vtx,vtxbis)) {
268 thearc = PStart.Arc();
269 theparam = PStart.Parameter();
270 arcorien = Domain->Orientation(thearc);
271
272 PPoint.AddUV(X(1),X(2));
273
274 thearc->D1(theparam,p2d,d2d);
275 PPoint.AddUV(p2d.X(),p2d.Y());
276
277 if (arcorien == TopAbs_FORWARD ||
278 arcorien == TopAbs_REVERSED) {
279 ispassing = Standard_False;
280 v2.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
281
282 test = vectg.Dot(v1.Crossed(v2));
283 vtxorien = Domain->Orientation(PStart.Vertex());
284 if (Abs(test) <= tole) {
285 LocTrans = TopAbs_EXTERNAL; // et pourquoi pas INTERNAL
286 }
287 else {
288 if (((test > 0.)&& arcorien == TopAbs_FORWARD) ||
289 ((test < 0.)&& arcorien == TopAbs_REVERSED)){
290 LocTrans = TopAbs_FORWARD;
291 }
292 else {
293 LocTrans = TopAbs_REVERSED;
294 }
295 if (arcorien == TopAbs_REVERSED) {v2.Reverse();}
296 }
297
298 comptrans.Compare(tole,v2,bidnorm,0.,LocTrans,vtxorien);
299 }
300 Destination(k) = seqlength+1;
301 }
302 }
303 }
304 }
7fd59977 305 fairpt = Standard_True;
191478a5 306 if (!ispassing) {
307 TopAbs_State Before = comptrans.StateBefore();
308 TopAbs_State After = comptrans.StateAfter();
309 if ((Before == TopAbs_UNKNOWN)||(After == TopAbs_UNKNOWN)) {
310 fairpt = Standard_False;
311 }
312 else if (Before == TopAbs_IN) {
313 if (After == TopAbs_IN) {
314 ispassing = Standard_True;
315 }
316 else {
317 vectg.Reverse();
318 dirtg.Reverse();
319 }
320 }
321 else {
322 if (After !=TopAbs_IN) {
323 fairpt = Standard_False;
324 }
325 }
326 }
327 if (fairpt) {
328 PPoint.SetDirections(vectg,dirtg);
329 PPoint.SetPassing(ispassing);
330 seqpdep.Append(PPoint);
331 seqlength++;
332 }
333 else { // il faut remettre en "ordre" si on ne garde pas le point.
334 for (k=i; k <=NbPoints ; k++) {
335 if (Destination(k)==seqlength + 1) {
336 Destination(k) = -Destination(k);
337 }
338 }
339 }
340 }
7fd59977 341 }
342 }
343 }
344}
345//=======================================================================
346//function : Recadre
347//purpose :
348//=======================================================================
349void Recadre(const Standard_Boolean ,
191478a5 350 GeomAbs_SurfaceType typeS1,
351 GeomAbs_SurfaceType typeS2,
352 IntPatch_Point& pt,
353 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline,
354 Standard_Integer Param,
355 Standard_Real U1,
356 Standard_Real V1,
357 Standard_Real U2,
358 Standard_Real V2)
7fd59977 359{
360 Standard_Real U1p,V1p,U2p,V2p;
361 iwline->Line()->Value(Param).Parameters(U1p,V1p,U2p,V2p);
362 switch(typeS1)
363 {
191478a5 364 case GeomAbs_Torus:
365 while(V1<(V1p-1.5*M_PI)) V1+=M_PI+M_PI;
366 while(V1>(V1p+1.5*M_PI)) V1-=M_PI+M_PI;
367 case GeomAbs_Cylinder:
368 case GeomAbs_Cone:
369 case GeomAbs_Sphere:
370 while(U1<(U1p-1.5*M_PI)) U1+=M_PI+M_PI;
371 while(U1>(U1p+1.5*M_PI)) U1-=M_PI+M_PI;
372 default:
373 break;
7fd59977 374 }
375 switch(typeS2)
376 {
191478a5 377 case GeomAbs_Torus:
378 while(V2<(V2p-1.5*M_PI)) V2+=M_PI+M_PI;
379 while(V2>(V2p+1.5*M_PI)) V2-=M_PI+M_PI;
380 case GeomAbs_Cylinder:
381 case GeomAbs_Cone:
382 case GeomAbs_Sphere:
383 while(U2<(U2p-1.5*M_PI)) U2+=M_PI+M_PI;
384 while(U2>(U2p+1.5*M_PI)) U2-=M_PI+M_PI;
385 default:
386 break;
7fd59977 387 }
388 pt.SetParameters(U1,V1,U2,V2);
389}
390
391//=======================================================================
392//function : Perform
393//purpose :
394//=======================================================================
395void IntPatch_ImpPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
191478a5 396 const Handle(Adaptor3d_TopolTool)& D1,
397 const Handle(Adaptor3d_HSurface)& Surf2,
398 const Handle(Adaptor3d_TopolTool)& D2,
399 const Standard_Real TolArc,
400 const Standard_Real TolTang,
401 const Standard_Real Fleche,
402 const Standard_Real Pas)
7fd59977 403{
404 Standard_Boolean reversed, procf, procl, dofirst, dolast;
1d47d8d0 405 Standard_Integer indfirst = 0, indlast = 0, ind2, i,j,k, NbSegm;
7fd59977 406 Standard_Integer NbPointIns, NbPointRst, Nblines, Nbpts, NbPointDep;
407 Standard_Real U1,V1,U2,V2,paramf,paraml,currentparam;
191478a5 408
7fd59977 409 IntPatch_TheSegmentOfTheSOnBounds thesegm;
410 IntSurf_PathPoint PPoint;
411
412 Handle(IntPatch_RLine) rline;
413 Handle(IntPatch_WLine) wline;
414 IntPatch_ThePathPointOfTheSOnBounds PStart,PStartf,PStartl;
415 IntPatch_Point ptdeb,ptfin,ptbis;
191478a5 416
7fd59977 417 IntPatch_IType typ;
418 IntSurf_Transition TLine,TArc;
419 IntSurf_TypeTrans trans1,trans2;
420 gp_Pnt valpt,ptbid;
421 gp_Vec tgline,tgrst,norm1,norm2,d1u,d1v;
422 gp_Dir DirNormale;
423 gp_Vec VecNormale;
191478a5 424
7fd59977 425 gp_Pnt2d p2d;
426 gp_Vec2d d2d;
191478a5 427
7fd59977 428 Handle(Adaptor2d_HCurve2d) currentarc;
429 GeomAbs_SurfaceType typeS1, typeS2;
430 IntSurf_Quadric Quad;
431 IntPatch_TheSurfFunction Func;
432 IntPatch_ArcFunction AFunc;
433 //
434 typeS1 = Surf1->GetType();
435 typeS2 = Surf2->GetType();
191478a5 436
7fd59977 437 paramf =0.;
438 paraml =0.;
439 trans1 = IntSurf_Undecided;
440 trans2 = IntSurf_Undecided;
441 //
442 done = Standard_False;
443 empt = Standard_True;
444 slin.Clear();
445 spnt.Clear();
446 //
447 reversed = Standard_False;
191478a5 448 switch (typeS1)
449 {
450 case GeomAbs_Plane:
451 Quad.SetValue(Surf1->Plane());
452 break;
7fd59977 453
191478a5 454 case GeomAbs_Cylinder:
455 Quad.SetValue(Surf1->Cylinder());
456 break;
7fd59977 457
191478a5 458 case GeomAbs_Sphere:
459 Quad.SetValue(Surf1->Sphere());
460 break;
7fd59977 461
191478a5 462 case GeomAbs_Cone:
463 Quad.SetValue(Surf1->Cone());
464 break;
7fd59977 465
191478a5 466 default:
467 {
7fd59977 468 reversed = Standard_True;
191478a5 469 switch (typeS2)
470 {
471 case GeomAbs_Plane:
472 Quad.SetValue(Surf2->Plane());
473 break;
474
475 case GeomAbs_Cylinder:
476 Quad.SetValue(Surf2->Cylinder());
477 break;
478
479 case GeomAbs_Sphere:
480 Quad.SetValue(Surf2->Sphere());
481 break;
482
483 case GeomAbs_Cone:
484 Quad.SetValue(Surf2->Cone());
485 break;
486 default:
487 {
488 Standard_ConstructionError::Raise();
489 break;
490 }
7fd59977 491 }
492 }
493 break;
494 }
495 //
496 Func.SetImplicitSurface(Quad);
497 Func.Set(IntSurf_QuadricTool::Tolerance(Quad));
498 AFunc.SetQuadric(Quad);
499 //
500 if (!reversed) {
501 Func.Set(Surf2);
502 AFunc.Set(Surf2);
503 }
504 else {
505 Func.Set(Surf1);
506 AFunc.Set(Surf1);
507 }
508 //
509 if (!reversed) {
510 solrst.Perform(AFunc,D2,TolArc,TolTang);
511 }
512 else {
513 solrst.Perform(AFunc,D1,TolArc,TolTang);
514 }
515 if (!solrst.IsDone()) {
516 return;
517 }
518 //
519 IntSurf_SequenceOfPathPoint seqpdep;
520 IntSurf_SequenceOfInteriorPoint seqpins;
521 //
522 NbPointRst = solrst.NbPoints();
523 TColStd_Array1OfInteger Destination(1,NbPointRst+1); Destination.Init(0);
524 if (NbPointRst) {
525 if (!reversed) {
526 ComputeTangency(solrst,seqpdep,D2,Func,Surf2,Destination);
527 }
528 else {
529 ComputeTangency(solrst,seqpdep,D1,Func,Surf1,Destination);
530 }
531 }
532 //
e618b526 533 Standard_Boolean SearchIns = Standard_True;
534 if(Quad.TypeQuadric() == GeomAbs_Plane && solrst.NbSegments() > 0)
535 {
536 //For such kind of cases it is possible that whole surface is on one side of plane,
537 //plane only touches surface and does not cross it,
538 //so no inner points exist.
539 SearchIns = Standard_False;
540 Handle(Adaptor3d_TopolTool) T;
541 if(reversed)
542 {
543 T = D1;
544 }
7fd59977 545 else
e618b526 546 {
547 T = D2;
548 }
549 Standard_Integer aNbSamples = 0;
550 aNbSamples = T->NbSamples();
551 gp_Pnt2d s2d;
552 gp_Pnt s3d;
553 Standard_Real aValf[1], aUVap[2];
554 math_Vector Valf(aValf,1,1), UVap(aUVap,1,2);
555 T->SamplePoint(1,s2d, s3d);
556 UVap(1)=s2d.X();
557 UVap(2)=s2d.Y();
558 Func.Value(UVap,Valf);
559 Standard_Real rvalf = Sign(1.,Valf(1));
560 for(i = 2; i <= aNbSamples; ++i)
561 {
562 D1->SamplePoint(i,s2d, s3d);
563 UVap(1)=s2d.X();
564 UVap(2)=s2d.Y();
565 Func.Value(UVap,Valf);
566 if(rvalf * Valf(1) < 0.)
567 {
568 SearchIns = Standard_True;
569 break;
570 }
571 }
7fd59977 572 }
e618b526 573 // Recherche des points interieurs
574 NbPointIns = 0;
575 if(SearchIns) {
576 if (!reversed) {
577 if (myIsStartPnt)
578 solins.Perform(Func,Surf2,myUStart,myVStart);
579 else
580 solins.Perform(Func,Surf2,D2,TolTang);
581 }
582 else {
583 if (myIsStartPnt)
584 solins.Perform(Func,Surf1,myUStart,myVStart);
585 else
586 solins.Perform(Func,Surf1,D1,TolTang);
587 }
588 NbPointIns = solins.NbPoints();
589 for (i=1; i <= NbPointIns; i++) {
590 seqpins.Append(solins.Value(i));
591 }
7fd59977 592 }
593 //
7fd59977 594 NbPointDep=seqpdep.Length();
595 //
596 if (NbPointDep || NbPointIns) {
597 IntPatch_TheIWalking iwalk(TolTang,Fleche,Pas);
598 if (!reversed) {
599 iwalk.Perform(seqpdep,seqpins,Func,Surf2);
600 }
601 else {
602 iwalk.Perform(seqpdep,seqpins,Func,Surf1,Standard_True);
603 }
604 if(!iwalk.IsDone()) {
605 return;
606 }
191478a5 607
7fd59977 608 Standard_Real Vmin, Vmax, TolV = 1.e-14;
609 if (!reversed) { //Surf1 is quadric
610 Vmin = Surf1->FirstVParameter();
611 Vmax = Surf1->LastVParameter();
612 }
613 else { //Surf2 is quadric
614 Vmin = Surf2->FirstVParameter();
615 Vmax = Surf2->LastVParameter();
616 }
617 //
618 Nblines = iwalk.NbLines();
619 for (j=1; j<=Nblines; j++) {
620 const Handle(IntPatch_TheIWLineOfTheIWalking)& iwline = iwalk.Value(j);
621 const Handle(IntSurf_LineOn2S)& thelin = iwline->Line();
191478a5 622
7fd59977 623 Nbpts = thelin->NbPoints();
624 if(Nbpts>=2) {
191478a5 625
626 tgline = iwline->TangentVector(k);
627 if(k>=1 && k<=Nbpts) { } else { k=Nbpts>>1; }
628 valpt = thelin->Value(k).Value();
629
630 if (!reversed) {
631 thelin->Value(k).ParametersOnS2(U2,V2);
632 norm1 = Quad.Normale(valpt);
633 Surf2->D1(U2,V2,ptbid,d1u,d1v);
634 norm2 = d1u.Crossed(d1v);
635 }
636 else {
637 thelin->Value(k).ParametersOnS1(U2,V2);
638 norm2 = Quad.Normale(valpt);
639 Surf1->D1(U2,V2,ptbid,d1u,d1v);
640 norm1 = d1u.Crossed(d1v);
641 }
642 if (tgline.DotCross(norm2,norm1) > 0.) {
643 trans1 = IntSurf_Out;
644 trans2 = IntSurf_In;
645 }
646 else {
647 trans1 = IntSurf_In;
648 trans2 = IntSurf_Out;
649 }
650
651 //
652 Standard_Real AnU1,AnU2,AnV2;
653
654 GeomAbs_SurfaceType typQuad = Quad.TypeQuadric();
655 Standard_Boolean arecadr=Standard_False;
656 valpt = thelin->Value(1).Value();
657 Quad.Parameters(valpt,AnU1,V1);
658
659 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
660 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
661
662 if(reversed) {
663 thelin->SetUV(1,Standard_False,AnU1,V1); //-- on va lire u2,v2
664 thelin->Value(1).ParametersOnS1(AnU2,AnV2);
665 }
666 else {
667 thelin->SetUV(1,Standard_True,AnU1,V1); //-- on va lire u1,v1
668 thelin->Value(1).ParametersOnS2(AnU2,AnV2);
669 }
670
671 if(typQuad==GeomAbs_Cylinder ||
672 typQuad==GeomAbs_Cone ||
673 typQuad==GeomAbs_Sphere) {
674 arecadr=Standard_True;
675 }
676 //
677 for (k=2; k<=Nbpts; ++k) {
678 valpt = thelin->Value(k).Value();
679 Quad.Parameters(valpt,U1,V1);
680 //
681 if((V1 < Vmin) && (Vmin-V1 < TolV)) {
682 V1 = Vmin;
683 }
684 if((V1 > Vmax) && (V1-Vmax < TolV)) {
685 V1 = Vmax;
686 }
687 //
688 if(arecadr) {
689 //modified by NIZNHY-PKV Fri Mar 28 15:06:01 2008f
690 Standard_Real aCf, aTwoPI;
691 //
692 aCf=0.;
693 aTwoPI=M_PI+M_PI;
694 if ((U1-AnU1) > 1.5*M_PI) {
695 while ((U1-AnU1) > (1.5*M_PI+aCf*aTwoPI)) {
696 aCf=aCf+1.;
697 }
698 U1=U1-aCf*aTwoPI;
699 }
700 //
701 else {
702 while ((U1-AnU1) < (-1.5*M_PI-aCf*aTwoPI)) {
703 aCf=aCf+1.;
704 }
705 U1=U1+aCf*aTwoPI;
706 }
707 // was:
708 //if ((U1-AnU1) > 1.5*M_PI) {
709 // U1-=M_PI+M_PI;
710 //}
711 //else if ((U1-AnU1) < -1.5*M_PI) {
712 // U1+=M_PI+M_PI;
713 //}
714 //modified by NIZNHY-PKV Fri Mar 28 15:06:11 2008t
715 }
716 //
717 if(reversed) {
718 thelin->SetUV(k,Standard_False,U1,V1);
719
720 thelin->Value(k).ParametersOnS1(U2,V2);
721 switch(typeS1) {
722 case GeomAbs_Cylinder:
723 case GeomAbs_Cone:
724 case GeomAbs_Sphere:
725 case GeomAbs_Torus:
726 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
727 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
728 break;
729 default:
730 break;
731 }
732 if(typeS2==GeomAbs_Torus) {
733 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
734 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
735 }
736 thelin->SetUV(k,Standard_True,U2,V2);
737 }
738 else {
739 thelin->SetUV(k,Standard_True,U1,V1);
740
741 thelin->Value(k).ParametersOnS2(U2,V2);
742 switch(typeS2) {
743 case GeomAbs_Cylinder:
744 case GeomAbs_Cone:
745 case GeomAbs_Sphere:
746 case GeomAbs_Torus:
747 while(U2<(AnU2-1.5*M_PI)) U2+=M_PI+M_PI;
748 while(U2>(AnU2+1.5*M_PI)) U2-=M_PI+M_PI;
749 break;
750 default:
751 break;
752 }
753 if(typeS2==GeomAbs_Torus) {
754 while(V2<(AnV2-1.5*M_PI)) V2+=M_PI+M_PI;
755 while(V2>(AnV2+1.5*M_PI)) V2-=M_PI+M_PI;
756 }
757 thelin->SetUV(k,Standard_False,U2,V2);
758
759 }
760
761 AnU1=U1;
762 AnU2=U2;
763 AnV2=V2;
764 }
765 // <-A
766 wline = new IntPatch_WLine(thelin,Standard_False,trans1,trans2);
767
768 if ( iwline->HasFirstPoint()
e618b526 769 && iwline->IsTangentAtBegining() == Standard_False)
770 {
771 indfirst = iwline->FirstPointIndex();
772 PPoint = seqpdep(indfirst);
773 tgline = PPoint.Direction3d();
774 Standard_Integer themult = PPoint.Multiplicity();
775 for (i=NbPointRst; i>=1; i--) {
776 if (Destination(i) == indfirst) {
777 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
778 Quad.Parameters(PPoint.Value(),U1,V1);
779
780 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
781 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
782
783 PPoint.Parameters(themult,U2,V2);
784 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
785 }
786 else { //-- typeS1 != Pln && Cyl && Sph && Cone
787 Quad.Parameters(PPoint.Value(),U2,V2);
191478a5 788
e618b526 789 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
790 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
191478a5 791
e618b526 792 PPoint.Parameters(themult,U1,V1);
793 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
794 }
191478a5 795
e618b526 796 VecNormale = d1u.Crossed(d1v);
797 //-- Modif du 27 Septembre 94 (Recadrage des pts U,V)
798 ptdeb.SetValue(PPoint.Value(),TolArc,Standard_False);
799 ptdeb.SetParameters(U1,V1,U2,V2);
800 ptdeb.SetParameter(1.);
191478a5 801
e618b526 802 Recadre(reversed,typeS1,typeS2,ptdeb,iwline,1,U1,V1,U2,V2);
191478a5 803
e618b526 804 currentarc = solrst.Point(i).Arc();
805 currentparam = solrst.Point(i).Parameter();
806 currentarc->D1(currentparam,p2d,d2d);
807 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
191478a5 808
e618b526 809 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
810 if(squaremagnitudeVecNormale > 1e-13) {
811 DirNormale=VecNormale;
812 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
813 }
814 else {
815 TLine.SetValue(Standard_True,IntSurf_Undecided);
816 TArc.SetValue(Standard_True,IntSurf_Undecided);
817 }
191478a5 818
e618b526 819 ptdeb.SetArc(reversed,currentarc,currentparam,TLine,TArc);
820 if (!solrst.Point(i).IsNew()) {
821 ptdeb.SetVertex(reversed,solrst.Point(i).Vertex());
822 }
823 wline->AddVertex(ptdeb);
824 if (themult == 0) {
825 wline->SetFirstPoint(wline->NbVertex());
191478a5 826 }
e618b526 827
828 themult--;
191478a5 829 }
e618b526 830 }
191478a5 831 }
e618b526 832 else if (iwline->IsTangentAtBegining())
833 {
191478a5 834 gp_Pnt psol = thelin->Value(1).Value();
835 thelin->Value(1).ParametersOnS1(U1,V1);
836 thelin->Value(1).ParametersOnS2(U2,V2);
837 ptdeb.SetValue(psol,TolArc,Standard_True);
838 ptdeb.SetParameters(U1,V1,U2,V2);
839 ptdeb.SetParameter(1.);
840 wline->AddVertex(ptdeb);
841 wline->SetFirstPoint(wline->NbVertex());
842 }
e618b526 843 else
844 {
191478a5 845 gp_Pnt psol = thelin->Value(1).Value();
846 thelin->Value(1).ParametersOnS1(U1,V1);
847 thelin->Value(1).ParametersOnS2(U2,V2);
848 ptdeb.SetValue(psol,TolArc,Standard_False);
849 ptdeb.SetParameters(U1,V1,U2,V2);
850 ptdeb.SetParameter(1.);
851 wline->AddVertex(ptdeb);
852 wline->SetFirstPoint(wline->NbVertex());
853 }
854
855
856 if ( iwline->HasLastPoint()
e618b526 857 && iwline->IsTangentAtEnd() == Standard_False)
858 {
859 indlast = iwline->LastPointIndex();
860 PPoint = seqpdep(indlast);
861 tgline = PPoint.Direction3d().Reversed();
862 Standard_Integer themult = PPoint.Multiplicity();
863 for (i=NbPointRst; i >=1; i--) {
864 if (Destination(i) == indlast) {
865 if (!reversed) {
866 Quad.Parameters(PPoint.Value(),U1,V1);
867
868 if((V1 < Vmin) && (Vmin-V1 < TolV)) V1 = Vmin;
869 if((V1 > Vmax) && (V1-Vmax < TolV)) V1 = Vmax;
870
871 PPoint.Parameters(themult,U2,V2);
872 Surf2->D1(U2,V2,ptbid,d1u,d1v); //-- @@@@
873 VecNormale = d1u.Crossed(d1v); //-- @@@@
874 }
875 else {
876 Quad.Parameters(PPoint.Value(),U2,V2);
191478a5 877
e618b526 878 if((V2 < Vmin) && (Vmin-V2 < TolV)) V2 = Vmin;
879 if((V2 > Vmax) && (V2-Vmax < TolV)) V2 = Vmax;
191478a5 880
e618b526 881 PPoint.Parameters(themult,U1,V1);
882 Surf1->D1(U1,V1,ptbid,d1u,d1v); //-- @@@@
883 VecNormale = d1u.Crossed(d1v); //-- @@@@
884 }
191478a5 885
e618b526 886 ptfin.SetValue(PPoint.Value(),TolArc,Standard_False);
887 ptfin.SetParameters(U1,V1,U2,V2);
888 ptfin.SetParameter(Nbpts);
191478a5 889
e618b526 890 Recadre(reversed,typeS1,typeS2,ptfin,iwline,Nbpts-1,U1,V1,U2,V2);
191478a5 891
e618b526 892 currentarc = solrst.Point(i).Arc();
893 currentparam = solrst.Point(i).Parameter();
894 currentarc->D1(currentparam,p2d,d2d);
895 tgrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
191478a5 896
191478a5 897
e618b526 898 Standard_Real squaremagnitudeVecNormale = VecNormale.SquareMagnitude();
899 if(squaremagnitudeVecNormale > 1e-13) {
900 DirNormale=VecNormale;
901 IntSurf::MakeTransition(tgline,tgrst,DirNormale,TLine,TArc);
902 }
903 else {
904 TLine.SetValue(Standard_True,IntSurf_Undecided);
905 TArc.SetValue(Standard_True,IntSurf_Undecided);
906 }
191478a5 907
191478a5 908
e618b526 909 ptfin.SetArc(reversed,currentarc,currentparam,TLine,TArc);
910 if (!solrst.Point(i).IsNew()) {
911 ptfin.SetVertex(reversed,solrst.Point(i).Vertex());
191478a5 912 }
e618b526 913 wline->AddVertex(ptfin);
914 if (themult == 0) {
915 wline->SetLastPoint(wline->NbVertex());
916 }
917
918 themult--;
191478a5 919 }
e618b526 920 }
191478a5 921 }
e618b526 922 else if (iwline->IsTangentAtEnd())
923 {
191478a5 924 gp_Pnt psol = thelin->Value(Nbpts).Value();
925 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
926 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
927 ptfin.SetValue(psol,TolArc,Standard_True);
928 ptfin.SetParameters(U1,V1,U2,V2);
929 ptfin.SetParameter(Nbpts);
930 wline->AddVertex(ptfin);
931 wline->SetLastPoint(wline->NbVertex());
932 }
e618b526 933 else
934 {
191478a5 935 gp_Pnt psol = thelin->Value(Nbpts).Value();
936 thelin->Value(Nbpts).ParametersOnS1(U1,V1);
937 thelin->Value(Nbpts).ParametersOnS2(U2,V2);
938 ptfin.SetValue(psol,TolArc,Standard_False);
939 ptfin.SetParameters(U1,V1,U2,V2);
940 ptfin.SetParameter(Nbpts);
941 wline->AddVertex(ptfin);
942 wline->SetLastPoint(wline->NbVertex());
943 }
944 //
945 // Il faut traiter les points de passage.
946 slin.Append(wline);
7fd59977 947 }// if(Nbpts>=2) {
948 }// for (j=1; j<=Nblines; j++) {
949
950 // ON GERE LES RACCORDS ENTRE LIGNES. ELLE NE PEUVENT SE RACCORDER
951 // QUE SUR DES POINTS DE TANGENCE
952
953
954 Nblines = slin.Length();
955 for (j=1; j<=Nblines-1; j++) {
956 dofirst = dolast = Standard_False;
957 const Handle(IntPatch_Line)& slinj = slin(j);
958 const Handle(IntPatch_WLine)& wlin1 = *((Handle(IntPatch_WLine)*)&slinj);
959 if (wlin1->HasFirstPoint()) {
191478a5 960 ptdeb = wlin1->FirstPoint(indfirst);
961 if (ptdeb.IsTangencyPoint()) {
962 dofirst = Standard_True;
963 }
7fd59977 964 }
965 if (wlin1->HasLastPoint()) {
191478a5 966 ptfin = wlin1->LastPoint(indlast);
967 if (ptfin.IsTangencyPoint()) {
968 dolast = Standard_True;
969 }
7fd59977 970 }
191478a5 971
7fd59977 972 if (dofirst || dolast) {
191478a5 973 for (k=j+1; k<=Nblines;k++) {
974 const Handle(IntPatch_Line)& slink = slin(k);
975 const Handle(IntPatch_WLine)& wlin2 = *((Handle(IntPatch_WLine)*)&slink);
976 if (wlin2->HasFirstPoint()) {
977 ptbis = wlin2->FirstPoint(ind2);
978 if (ptbis.IsTangencyPoint()) {
979 if (dofirst ) {
980 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
981 ptdeb.SetMultiple(Standard_True);
982 if (!ptbis.IsMultiple()) {
983 ptbis.SetMultiple(Standard_True);
984 wlin2->Replace(ind2,ptbis);
985 }
986 }
987 }
988 if (dolast ) {
989 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
990 ptfin.SetMultiple(Standard_True);
991 if (!ptbis.IsMultiple()) {
992 ptbis.SetMultiple(Standard_True);
993 wlin2->Replace(ind2,ptbis);
994 }
995 }
996 }
997 }
998 }
999 if (wlin2->HasLastPoint()) {
1000 ptbis = wlin2->LastPoint(ind2);
1001 if (ptbis.IsTangencyPoint()) {
1002 if (dofirst ) {
1003 if (ptdeb.Value().Distance(ptbis.Value()) <= TolArc) {
1004 ptdeb.SetMultiple(Standard_True);
1005 if (!ptbis.IsMultiple()) {
1006 ptbis.SetMultiple(Standard_True);
1007 wlin2->Replace(ind2,ptbis);
1008 }
1009 }
1010 }
1011 if (dolast ) {
1012 if (ptfin.Value().Distance(ptbis.Value()) <= TolArc) {
1013 ptfin.SetMultiple(Standard_True);
1014 if (!ptbis.IsMultiple()) {
1015 ptbis.SetMultiple(Standard_True);
1016 wlin2->Replace(ind2,ptbis);
1017 }
1018 }
1019 }
1020 }
1021 }
1022 }
1023 if(dofirst)
1024 wlin1->Replace(indfirst,ptdeb);
1025 if(dolast)
1026 wlin1->Replace(indlast,ptfin);
7fd59977 1027 }
1028 }
1029 }// if (seqpdep.Length() != 0 || seqpins.Length() != 0) {
1030 //
1031 // Treatment the segments
1032 NbSegm = solrst.NbSegments();
1033 if (NbSegm) {
1034 for(i=1; i<=NbSegm; i++) {
1035 thesegm = solrst.Segment(i);
e618b526 1036 //Check if segment is degenerated
1037 if(thesegm.HasFirstPoint() && thesegm.HasLastPoint())
1038 {
1039 Standard_Real tol2 = Precision::Confusion();
1040 tol2 *= tol2;
1041 const gp_Pnt& aPf = thesegm.FirstPoint().Value();
1042 const gp_Pnt& aPl = thesegm.LastPoint().Value();
1043 if(aPf.SquareDistance(aPl) <= tol2)
1044 {
1045 //segment can be degenerated - check inner point
1046 paramf = thesegm.FirstPoint().Parameter();
1047 paraml = thesegm.LastPoint().Parameter();
1048 gp_Pnt2d _p2d =
1049 thesegm.Curve()->Value(.57735 * paramf + 0.42265 * paraml);
1050 gp_Pnt aPm;
1051 if(reversed)
1052 {
1053 Surf1->D0(_p2d.X(), _p2d.Y(), aPm);
1054 }
1055 else
1056 {
1057 Surf2->D0(_p2d.X(), _p2d.Y(), aPm);
1058 }
1059 if(aPm.SquareDistance(aPf) <= tol2)
1060 {
1061 //Degenerated
1062 continue;
1063 }
1064 }
1065 }
1066
1067
7fd59977 1068 //----------------------------------------------------------------------
1069 // on cree une ligne d intersection contenant uniquement le segment.
1070 // VOIR POUR LA TRANSITION DE LA LIGNE
1071 // On ajoute aussi un polygone pour le traitement des intersections
1072 // entre ligne et restrictions de la surface implicite (PutVertexOnLine)
1073 //----------------------------------------------------------------------
1074 //-- Calcul de la transition sur la rline (12 fev 97)
1075 //-- reversed a le sens de OnFirst
1076 //--
1077 dofirst = dolast = Standard_False;
1078 procf = Standard_False;
1079 procl = Standard_False;
1080 IntSurf_Transition TLineUnk,TArcUnk;
1081
1082 IntPatch_Point _thepointAtBeg;
1083 IntPatch_Point _thepointAtEnd;
191478a5 1084
7fd59977 1085 Standard_Boolean TransitionOK=Standard_False;
1086
1087 if(thesegm.HasFirstPoint()) {
191478a5 1088 Standard_Real _u1,_v1,_u2,_v2;
1089
1090 dofirst = Standard_True;
1091 PStartf = thesegm.FirstPoint();
1092 paramf = PStartf.Parameter();
1093
1094 gp_Pnt2d _p2d = thesegm.Curve()->Value(paramf);
1095 Handle(Adaptor3d_HVertex) _vtx;
1096 if(PStartf.IsNew()==Standard_False)
1097 _vtx= PStartf.Vertex();
1098 const gp_Pnt& _Pp = PStartf.Value();
1099 _thepointAtBeg.SetValue(_Pp,PStartf.Tolerance(),Standard_False);
1100 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1101 Quad.Parameters(_Pp,_u1,_v1);
1102 _u2=_p2d.X(); _v2=_p2d.Y();
1103 }
1104 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1105 Quad.Parameters(_Pp,_u2,_v2);
1106 _u1=_p2d.X(); _v1=_p2d.Y();
1107 }
1108 _thepointAtBeg.SetParameters(_u1,_v1,_u2,_v2);
1109 _thepointAtBeg.SetParameter(paramf);
1110 if(PStartf.IsNew()==Standard_False)
1111 _thepointAtBeg.SetVertex(reversed,_vtx);
1112 _thepointAtBeg.SetArc(reversed,thesegm.Curve(),paramf,TLineUnk,TArcUnk);
1113
1114
1115 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1116 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1117 norm1 = d1u1.Crossed(d1v1);
1118 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1119 norm2 = d1u2.Crossed(d1v2);
1120
1121 thesegm.Curve()->D1(paramf,_p2d,_d2d);
1122 if(reversed) {
1123 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1124 }
1125 else {
1126 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1127 }
1128 _u1=tgline.DotCross(norm2,norm1);
1129 TransitionOK=Standard_True;
1130 if (_u1 > 0.00000001) {
1131 trans1 = IntSurf_Out;
1132 trans2 = IntSurf_In;
1133 }
1134 else if(_u1 < -0.00000001) {
1135 trans1 = IntSurf_In;
1136 trans2 = IntSurf_Out;
1137 }
1138 else {
1139 TransitionOK=Standard_False;
1140 }
7fd59977 1141 }
1142 if(thesegm.HasLastPoint()) {
191478a5 1143 Standard_Real _u1,_v1,_u2,_v2;
1144
1145 dolast = Standard_True;
1146 PStartl = thesegm.LastPoint();
1147 paraml = PStartl.Parameter();
1148
1149 gp_Pnt2d _p2d = thesegm.Curve()->Value(paraml);
1150 Handle(Adaptor3d_HVertex) _vtx;
1151 if(PStartl.IsNew()==Standard_False)
1152 _vtx = PStartl.Vertex();
1153 const gp_Pnt& _Pp = PStartl.Value();
1154 IntPatch_Point _thepoint;
1155 _thepointAtEnd.SetValue(_Pp,PStartl.Tolerance(),Standard_False);
1156 if (!reversed) { //-- typeS1 = Pln || Cyl || Sph || Cone
1157 Quad.Parameters(_Pp,_u1,_v1);
1158 _u2=_p2d.X(); _v2=_p2d.Y();
1159 }
1160 else { //-- typeS1 != Pln && Cyl && Sph && Cone
1161 Quad.Parameters(_Pp,_u2,_v2);
1162 _u1=_p2d.X(); _v1=_p2d.Y();
1163 }
1164 _thepointAtEnd.SetParameters(_u1,_v1,_u2,_v2);
1165 _thepointAtEnd.SetParameter(paraml);
1166 if(PStartl.IsNew()==Standard_False)
1167 _thepointAtEnd.SetVertex(reversed,_vtx);
1168 _thepointAtEnd.SetArc(reversed,thesegm.Curve(),paraml,TLineUnk,TArcUnk);
1169
1170
1171
1172 gp_Vec d1u1,d1v1,d1u2,d1v2; gp_Vec2d _d2d;
1173 Surf1->D1(_u1,_v1,ptbid,d1u1,d1v1);
1174 norm1 = d1u1.Crossed(d1v1);
1175 Surf2->D1(_u2,_v2,ptbid,d1u2,d1v2);
1176 norm2 = d1u2.Crossed(d1v2);
1177
1178 thesegm.Curve()->D1(paraml,_p2d,_d2d);
1179 if(reversed) {
1180 tgline.SetLinearForm(_d2d.X(),d1u1,_d2d.Y(),d1v1);
1181 }
1182 else {
1183 tgline.SetLinearForm(_d2d.X(),d1u2,_d2d.Y(),d1v2);
1184 }
1185 _u1=tgline.DotCross(norm2,norm1);
1186 TransitionOK=Standard_True;
1187 if (_u1 > 0.00000001) {
1188 trans1 = IntSurf_Out;
1189 trans2 = IntSurf_In;
1190 }
1191 else if(_u1 < -0.00000001) {
1192 trans1 = IntSurf_In;
1193 trans2 = IntSurf_Out;
1194 }
1195 else {
1196 TransitionOK=Standard_False;
1197 }
7fd59977 1198 }
1199 if(TransitionOK==Standard_False) {
191478a5 1200 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False);
1201 rline = new IntPatch_RLine (Standard_False);
1202 if(reversed) {
1203 rline->SetArcOnS1(thesegm.Curve());
1204 }
1205 else {
1206 rline->SetArcOnS2(thesegm.Curve());
1207 }
7fd59977 1208 }
1209 else {
191478a5 1210 //-- rline = new IntPatch_RLine (thesegm.Curve(),reversed,Standard_False,trans1,trans2);
1211 rline = new IntPatch_RLine (Standard_False,trans1,trans2);
1212 if(reversed) {
1213 rline->SetArcOnS1(thesegm.Curve());
1214 }
1215 else {
1216 rline->SetArcOnS2(thesegm.Curve());
1217 }
7fd59977 1218 }
1219
1220 //------------------------------
1221 //-- Ajout des points
1222 //--
1223 if (thesegm.HasFirstPoint()) {
191478a5 1224 rline->AddVertex(_thepointAtBeg);
1225 rline->SetFirstPoint(rline->NbVertex());
7fd59977 1226 }
191478a5 1227
7fd59977 1228 if (thesegm.HasLastPoint()) {
191478a5 1229 rline->AddVertex(_thepointAtEnd);
1230 rline->SetLastPoint(rline->NbVertex());
7fd59977 1231 }
1232
1233 // Polygone sur restriction solution
1234 if (dofirst && dolast) {
191478a5 1235 Standard_Real prm;
1236 gp_Pnt ptpoly;
1237 IntSurf_PntOn2S p2s;
1238 Handle(IntSurf_LineOn2S) Thelin = new IntSurf_LineOn2S ();
1239 Handle(Adaptor2d_HCurve2d) arcsegm = thesegm.Curve();
1240 Standard_Integer nbsample = 100;
1241
1242 if (!reversed) {
1243 for (j=1; j<=nbsample; j++) {
1244 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1245 arcsegm->D0(prm,p2d);
1246 Surf2->D0(p2d.X(),p2d.Y(),ptpoly);
1247
1248 Quad.Parameters(ptpoly,U1,V1);
1249 p2s.SetValue(ptpoly,U1,V1,p2d.X(),p2d.Y());
1250 Thelin->Add(p2s);
1251 }
1252 }
1253 else {
1254 for (j=1; j<=nbsample; j++) {
1255 prm = paramf + (j-1)*(paraml-paramf)/(nbsample-1);
1256 arcsegm->D0(prm,p2d);
1257 Surf1->D0(p2d.X(),p2d.Y(),ptpoly);
1258
1259 Quad.Parameters(ptpoly,U2,V2);
1260 p2s.SetValue(ptpoly,p2d.X(),p2d.Y(),U2,V2);
1261 Thelin->Add(p2s);
1262 }
1263 }
1264 rline->Add(Thelin);
7fd59977 1265 }
1266
1267 if (dofirst || dolast) {
191478a5 1268 Nblines = slin.Length();
1269 for (j=1; j<=Nblines; j++) {
1270 const Handle(IntPatch_Line)& slinj = slin(j);
1271 typ = slinj->ArcType();
1272 if (typ == IntPatch_Walking) {
1273 Nbpts = (*((Handle(IntPatch_WLine)*)&slinj))->NbVertex();
1274 }
1275 else {
1276 Nbpts = (*((Handle(IntPatch_RLine)*)&slinj))->NbVertex();
1277 }
1278 for (k=1; k<=Nbpts;k++) {
1279 if (typ == IntPatch_Walking) {
1280 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1281 }
1282 else {
1283 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1284 }
1285 if (dofirst) {
1286
1287 if (ptdeb.Value().Distance(PStartf.Value()) <=TolArc) {
1288 ptdeb.SetMultiple(Standard_True);
1289 if (typ == IntPatch_Walking) {
1290 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1291 }
1292 else {
1293 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1294 }
1295 ptdeb.SetParameter(paramf);
1296 rline->AddVertex(ptdeb);
1297 if (!procf){
1298 procf=Standard_True;
1299 rline->SetFirstPoint(rline->NbVertex());
1300 }
1301 }
1302 }
1303 if (dolast) {
1304 if(dofirst) { //-- on recharge le ptdeb
1305 if (typ == IntPatch_Walking) {
1306 ptdeb = (*((Handle(IntPatch_WLine)*)&slinj))->Vertex(k);
1307 }
1308 else {
1309 ptdeb = (*((Handle(IntPatch_RLine)*)&slinj))->Vertex(k);
1310 }
1311 }
1312 if (ptdeb.Value().Distance(PStartl.Value()) <=TolArc) {
1313 ptdeb.SetMultiple(Standard_True);
1314 if (typ == IntPatch_Walking) {
1315 (*((Handle(IntPatch_WLine)*)&slinj))->Replace(k,ptdeb);
1316 }
1317 else {
1318 (*((Handle(IntPatch_RLine)*)&slinj))->Replace(k,ptdeb);
1319 }
1320 ptdeb.SetParameter(paraml);
1321 rline->AddVertex(ptdeb);
1322 if (!procl){
1323 procl=Standard_True;
1324 rline->SetLastPoint(rline->NbVertex());
1325 }
1326 }
1327 }
1328 }
1329 }
7fd59977 1330 }
1331 slin.Append(rline);
1332 }
1333 }// if (NbSegm)
1334 //
1335 // on traite les restrictions de la surface implicite
1336 for (i=1; i<=slin.Length(); i++)
1337 {
1338 if (!reversed)
1339 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf1,D1,Surf2,Standard_True,TolTang);
1340 else
1341 IntPatch_RstInt::PutVertexOnLine(slin(i),Surf2,D2,Surf1,Standard_False,TolTang);
1342 }
1343 empt = (slin.Length() == 0 && spnt.Length() == 0);
1344 done = Standard_True;
191478a5 1345
1346
7fd59977 1347 // post processing for cones and spheres
7fd59977 1348
191478a5 1349 if(slin.Length() == 0)
1350 return;
7fd59977 1351
191478a5 1352 Standard_Boolean isDecomposeRequired = (Quad.TypeQuadric() == GeomAbs_Cone) ||
1353 (Quad.TypeQuadric() == GeomAbs_Sphere);
7fd59977 1354
191478a5 1355 if(!isDecomposeRequired)
1356 return;
7fd59977 1357
191478a5 1358 const Handle(Adaptor3d_TopolTool)& PDomain = (reversed) ? D1 : D2;
1359 const Handle(Adaptor3d_HSurface)& aQSurf = (reversed) ? Surf2 : Surf1;
7fd59977 1360
191478a5 1361 IntPatch_SequenceOfLine dslin;
1362 Standard_Boolean isDecompose = Standard_False;
1363 for(i = 1; i <= slin.Length(); i++ )
1364 {
1365 if(DecomposeResult(slin(i),reversed,Quad,PDomain,aQSurf,TolArc,dslin))
1366 {
1367 isDecompose = Standard_True;
7fd59977 1368 }
7fd59977 1369 }
1370
191478a5 1371 if(!isDecompose)
1372 return;
1373
1374 slin.Clear();
1375 for(i = 1; i <= dslin.Length(); i++ )
1376 slin.Append(dslin(i));
7fd59977 1377}
1378
1379// correct U parameter of the start point of line on Quadric
1380// (change 0->2PI or vs, if necessary)
1381static Standard_Real AdjustUFirst(Standard_Real U1,Standard_Real U2)
1382{
1383 Standard_Real u = U1;
1384
1385 // case: no adjustment
c6541a0c 1386 if( U1 > 0. && U1 < (2.*M_PI) )
7fd59977 1387 return u;
1388
1389 // case: near '0'
1390 if( U1 == 0. || fabs(U1) <= 1.e-9 ) {
c6541a0c
D
1391 if( U2 > 0. && U2 < (2.*M_PI) )
1392 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
7fd59977 1393 else {
1394 Standard_Real uu = U2;
c6541a0c 1395 if( U2 > (2.*M_PI) )
191478a5 1396 while( uu > (2.*M_PI) )
1397 uu -= (2.*M_PI);
7fd59977 1398 else
191478a5 1399 while( uu < 0.)
1400 uu += (2.*M_PI);
1401
c6541a0c 1402 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
7fd59977 1403 }
1404 }
1405 // case: near '2PI'
c6541a0c
D
1406 else if( U1 == (2.*M_PI) || fabs((2.*M_PI)-fabs(U1)) <= 1.e-9 ) {
1407 if( U2 > 0. && U2 < (2.*M_PI) )
1408 u = ( U2 < ((2.*M_PI)-U2) ) ? 0. : (2.*M_PI);
7fd59977 1409 else {
1410 Standard_Real uu = U2;
c6541a0c 1411 if( U2 > (2.*M_PI) )
191478a5 1412 while( uu > (2.*M_PI) )
1413 uu -= (2.*M_PI);
7fd59977 1414 else
191478a5 1415 while( uu < 0.)
1416 uu += (2.*M_PI);
1417
c6541a0c 1418 u = ( uu < ((2.*M_PI)-uu) ) ? 0. : (2.*M_PI);
7fd59977 1419 }
1420 }
1421 // case: '<0. || >2PI'
1422 else {
1423 if(U1 < 0.)
1424 while(u < 0.)
191478a5 1425 u += 2.*M_PI;
c6541a0c
D
1426 if(U1 > (2.*M_PI))
1427 while(u > (2.*M_PI))
191478a5 1428 u -= (2.*M_PI);
7fd59977 1429 }
1430
1431 return u;
1432}
1433
7fd59977 1434// collect vertices, reject equals
1435static Handle(IntSurf_LineOn2S) GetVertices(const Handle(IntPatch_WLine)& WLine,
191478a5 1436 const Standard_Real TOL3D,
1437 const Standard_Real TOL2D)
7fd59977 1438{
191478a5 1439 // Standard_Real TOL3D = 1.e-12, TOL2D = 1.e-8;
7fd59977 1440
1441 Handle(IntSurf_LineOn2S) vertices = new IntSurf_LineOn2S();
1442
1443 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0.;
1444 Standard_Integer i = 0, k = 0;
1445 Standard_Integer NbVrt = WLine->NbVertex();
191478a5 1446
7fd59977 1447 TColStd_Array1OfInteger anVrts(1,NbVrt);
1448 anVrts.Init(0);
1449
1450 // check equal vertices
1451 for(i = 1; i <= NbVrt; i++) {
1452
1453 if( anVrts(i) == -1 ) continue;
1454
1455 const IntPatch_Point& Pi = WLine->Vertex(i);
1456
1457 for(k = (i+1); k <= NbVrt; k++) {
1458
1459 if( anVrts(k) == -1 ) continue;
1460
1461 const IntPatch_Point& Pk = WLine->Vertex(k);
1462
1463 if(Pi.Value().Distance(Pk.Value()) <= TOL3D) {
191478a5 1464 // suggest the points are equal;
1465 // test 2d parameters on surface
1466 Standard_Boolean sameU1 = Standard_False;
1467 Standard_Boolean sameV1 = Standard_False;
1468 Standard_Boolean sameU2 = Standard_False;
1469 Standard_Boolean sameV2 = Standard_False;
1470
1471 Pi.ParametersOnS1(U1,V1);
1472 Pk.ParametersOnS1(U2,V2);
1473 if(fabs(U1-U2) <= TOL2D) sameU1 = Standard_True;
1474 if(fabs(V1-V2) <= TOL2D) sameV1 = Standard_True;
1475
1476 Pi.ParametersOnS2(U1,V1);
1477 Pk.ParametersOnS2(U2,V2);
1478 if(fabs(U1-U2) <= TOL2D) sameU2 = Standard_True;
1479 if(fabs(V1-V2) <= TOL2D) sameV2 = Standard_True;
1480
1481 if((sameU1 && sameV1) && (sameU2 && sameV2))
1482 anVrts(k) = -1;
7fd59977 1483 }
1484 }
1485 }
1486
1487 // copy further processed vertices
1488 for(i = 1; i <= NbVrt; i++) {
1489 if( anVrts(i) == -1 ) continue;
1490 vertices->Add(WLine->Vertex(i).PntOn2S());
1491 }
1492 return vertices;
1493}
1494
1495static Standard_Boolean AreSamePoints(const IntSurf_PntOn2S& P1,
191478a5 1496 const IntSurf_PntOn2S& P2)
7fd59977 1497{
1498 Standard_Boolean result = Standard_False;
1499 Standard_Real T2D = 1.e-9, T3D = 1.e-8;
1500 const gp_Pnt& P3D1 = P1.Value();
1501 const gp_Pnt& P3D2 = P2.Value();
1502 if(P3D1.Distance(P3D2) <= T3D) {
1503 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0., U3 = 0., V3 = 0., U4 = 0., V4 = 0.;
1504 P1.ParametersOnS1(U1,V1);
1505 P1.ParametersOnS2(U2,V2);
1506 P2.ParametersOnS1(U3,V3);
1507 P2.ParametersOnS2(U4,V4);
1508 gp_Pnt2d P2D11(U1,V1);
1509 gp_Pnt2d P2D12(U2,V2);
1510 gp_Pnt2d P2D21(U3,V3);
1511 gp_Pnt2d P2D22(U4,V4);
1512 Standard_Boolean sameS1 = (P2D11.Distance(P2D21) <= T2D) ? Standard_True : Standard_False;
1513 Standard_Boolean sameS2 = (P2D12.Distance(P2D22) <= T2D) ? Standard_True : Standard_False;
1514 if(sameS1 && sameS2)
1515 result = Standard_True;
1516 }
1517 return result;
1518}
1519
191478a5 1520static void ForcedPurgePoints(const Handle(IntSurf_LineOn2S)& Result,
1521 const Standard_Boolean IsReversed,
1522 const IntSurf_Quadric& Quad)
7fd59977 1523{
1524 if(Result->NbPoints() <= 30) return;
1525 Standard_Integer Index = 0, IndexLimF = 8, IndexLimL = 8;
1526
3fa7e3e7 1527 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
191478a5 1528 if(IsReversed) {
1529 Result->Value(1).ParametersOnS2(U1,V1);
1530 Result->Value(Result->NbPoints()).ParametersOnS2(U2,V2);
1531 }
1532 else {
1533 Result->Value(1).ParametersOnS1(U1,V1);
1534 Result->Value(Result->NbPoints()).ParametersOnS1(U2,V2);
1535 }
7fd59977 1536
3fa7e3e7 1537 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1538 Standard_Real Uapx = 0., Vapx = 0.;
1539 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
191478a5 1540
7fd59977 1541 if(fabs(V1-Vapx) <= 1.e-3)
1542 IndexLimF = 12;
1543 if(fabs(V2-Vapx) <= 1.e-3)
1544 IndexLimL = 12;
1545 }
1546
1547 if(Quad.TypeQuadric() == GeomAbs_Sphere) {
c6541a0c 1548 Standard_Real Vapx1 = M_PI/2., Vapx2 = -M_PI/2.;
191478a5 1549
7fd59977 1550 if(fabs(V1-Vapx1) <= 1.e-3 || fabs(V1-Vapx2) <= 1.e-3)
1551 IndexLimF = 12;
1552 if(fabs(V2-Vapx1) <= 1.e-3 || fabs(V2-Vapx2) <= 1.e-3)
1553 IndexLimL = 12;
1554 }
1555
1556 while(Result->NbPoints() > 2 && Index < IndexLimF) {
1557 Result->RemovePoint(2);
1558 Index++;
1559 }
1560 Index = 0;
1561 while(Result->NbPoints() > 2 && Index < IndexLimL) {
1562 Result->RemovePoint(Result->NbPoints()-1);
1563 Index++;
1564 }
1565}
1566
1567// DEBUG FUNCTION !!!
1568#if 0
1569static void DumpLine(Handle(IntSurf_LineOn2S)& Line,
191478a5 1570 Standard_Boolean IsReversed,
1571 Standard_Integer Number)
7fd59977 1572{
1573 cout << "DUMP LINE" << endl;
1574 Standard_Integer i;
1575 Standard_Real U,V;
1576 for(i = 1; i <= Line->NbPoints(); i++) {
1577 if(i <= Number || i >= (Line->NbPoints()-Number)) {
1578 if(IsReversed)
1579 Line->Value(i).ParametersOnS2(U,V); // S2 - quadric
1580 else
1581 Line->Value(i).ParametersOnS1(U,V); // S1 - quadric
1582 cout << "point p" << i << " " << U << " " << V << endl;
1583 }
1584 }
1585 cout << endl;
1586}
1587#endif
1588// DEBUG FUNCTION !!!
1589
1590static void SearchVertices(const Handle(IntSurf_LineOn2S)& Line,
191478a5 1591 const Handle(IntSurf_LineOn2S)& Vertices,
1592 TColStd_Array1OfInteger& PTypes)
7fd59977 1593{
1594 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1595 Standard_Integer ip = 0, iv = 0;
1596 for(ip = 1; ip <= nbp; ip++) {
1597 const IntSurf_PntOn2S& aP = Line->Value(ip);
1598 Standard_Integer type = 0;
1599 for(iv = 1; iv <= nbv; iv++) {
1600 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1601 if(AreSamePoints(aP,aV)) {
191478a5 1602 type = iv;
1603 break;
7fd59977 1604 }
1605 }
1606 PTypes(ip) = type;
1607 }
1608}
1609
1610static inline Standard_Boolean IsSeamParameter(const Standard_Real U,
191478a5 1611 const Standard_Real TOL2D)
7fd59977 1612{
c6541a0c 1613 return (fabs(U) <= TOL2D || fabs(2.*M_PI - U) <= TOL2D);
7fd59977 1614}
1615
1616static inline Standard_Real AdjustU(const Standard_Real U)
1617{
c6541a0c 1618 Standard_Real u = U, DBLPI = 2.*M_PI;
7fd59977 1619 if(u < 0. || u > DBLPI) {
1620 if(u < 0.)
1621 while(u < 0.)
191478a5 1622 u += DBLPI;
7fd59977 1623 else
1624 while(u > DBLPI)
191478a5 1625 u -= DBLPI;
7fd59977 1626 }
1627 return u;
1628}
1629
1630static inline void Correct2DBounds(const Standard_Real UF,
191478a5 1631 const Standard_Real UL,
1632 const Standard_Real VF,
1633 const Standard_Real VL,
1634 const Standard_Real TOL2D,
1635 Standard_Real& U,
1636 Standard_Real& V)
7fd59977 1637{
1638 Standard_Real Eps = 1.e-16;
1639 Standard_Real dUF = fabs(U - UF);
1640 Standard_Real dUL = fabs(U - UL);
1641 Standard_Real dVF = fabs(V - VF);
1642 Standard_Real dVL = fabs(V - VL);
1643 if(dUF <= TOL2D && dUF > Eps) U = UF;
1644 if(dUL <= TOL2D && dUL > Eps) U = UL;
1645 if(dVF <= TOL2D && dVF > Eps) V = VF;
1646 if(dVL <= TOL2D && dVL > Eps) V = VL;
1647}
1648
1649static void AdjustLine(Handle(IntSurf_LineOn2S)& Line,
191478a5 1650 const Standard_Boolean IsReversed,
1651 const Handle(Adaptor3d_HSurface)& QSurf,
1652 const Standard_Real TOL2D)
7fd59977 1653{
1654 Standard_Real VF = QSurf->FirstVParameter();
1655 Standard_Real VL = QSurf->LastVParameter();
1656 Standard_Real UF = QSurf->FirstUParameter();
1657 Standard_Real UL = QSurf->LastUParameter();
1658
1659 Standard_Integer nbp = Line->NbPoints(), ip = 0;
1660 Standard_Real U = 0., V = 0.;
1661 for(ip = 1; ip <= nbp; ip++) {
1662 if(IsReversed) {
1663 Line->Value(ip).ParametersOnS2(U,V);
1664 U = AdjustU(U);
1665 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1666 Line->SetUV(ip,Standard_False,U,V);
1667 }
1668 else {
1669 Line->Value(ip).ParametersOnS1(U,V);
1670 U = AdjustU(U);
1671 Correct2DBounds(UF,UL,VF,VL,TOL2D,U,V);
1672 Line->SetUV(ip,Standard_True,U,V);
1673 }
1674 }
1675}
1676
1677static Standard_Boolean InsertSeamVertices(Handle(IntSurf_LineOn2S)& Line,
191478a5 1678 const Standard_Boolean IsReversed,
1679 Handle(IntSurf_LineOn2S)& Vertices,
1680 const TColStd_Array1OfInteger& PTypes,
1681 const Standard_Real TOL2D)
7fd59977 1682{
1683 Standard_Boolean result = Standard_False;
1684 Standard_Integer ip = 0, nbp = Line->NbPoints();
1685 Standard_Real U = 0., V = 0.;
1686 for(ip = 1; ip <= nbp; ip++) {
1687 Standard_Integer ipt = PTypes(ip);
1688 if(ipt != 0) {
1689 const IntSurf_PntOn2S& aP = Line->Value(ip);
1690 if(IsReversed)
191478a5 1691 aP.ParametersOnS2(U,V); // S2 - quadric
7fd59977 1692 else
191478a5 1693 aP.ParametersOnS1(U,V); // S1 - quadric
7fd59977 1694 U = AdjustU(U);
1695 if(IsSeamParameter(U,TOL2D)) {
191478a5 1696 if(ip == 1 || ip == nbp) {
1697 Standard_Real U1 = 0., V1 = 0.;
1698 Standard_Integer ipp = (ip == 1) ? (ip+1) : (ip-1);
1699 if(IsReversed)
1700 Line->Value(ipp).ParametersOnS2(U1,V1); // S2 - quadric
1701 else
1702 Line->Value(ipp).ParametersOnS1(U1,V1); // S1 - quadric
1703 Standard_Real u = AdjustUFirst(U,U1);
1704 if(fabs(u-U) >= 1.5*M_PI) {
1705 Standard_Real U2 = 0., V2 = 0.;
1706 if(IsReversed) {
1707 Line->Value(ip).ParametersOnS1(U2,V2); // prm
1708 Line->SetUV(ip,Standard_False,u,V);
1709 Line->SetUV(ip,Standard_True,U2,V2);
1710 }
1711 else {
1712 Line->Value(ip).ParametersOnS2(U2,V2); // prm
1713 Line->SetUV(ip,Standard_True,u,V);
1714 Line->SetUV(ip,Standard_False,U2,V2);
1715 }
1716 }
1717 }
1718 else {
1719 Standard_Integer ipp = ip - 1;
1720 Standard_Integer ipn = ip + 1;
1721 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
1722 if(IsReversed) {
1723 Line->Value(ipp).ParametersOnS2(U1,V1); // quad
1724 Line->Value(ipn).ParametersOnS2(U2,V2); // quad
1725 }
1726 else {
1727 Line->Value(ipp).ParametersOnS1(U1,V1); // quad
1728 Line->Value(ipn).ParametersOnS1(U2,V2); // quad
1729 }
1730 U1 = AdjustU(U1);
1731 U2 = AdjustU(U2);
1732 Standard_Boolean pnearZero = (fabs(U1) < fabs(2.*M_PI-U1)) ? Standard_True : Standard_False;
1733 Standard_Boolean cnearZero = (fabs(U) < fabs(2.*M_PI-U)) ? Standard_True : Standard_False;
1734 if(pnearZero == cnearZero) {
1735 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1736 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1737 IntSurf_PntOn2S nP;
1738 nP.SetValue(aP.Value());
1739 Standard_Real U3 = 0., V3 = 0.;
1740 if(IsReversed) {
1741 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1742 nP.SetValue(Standard_False,nU,V);
1743 nP.SetValue(Standard_True,U3,V3);
1744 }
1745 else {
1746 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1747 nP.SetValue(Standard_True,nU,V);
1748 nP.SetValue(Standard_False,U3,V3);
1749 }
1750 Line->InsertBefore(ipn,nP);
1751 Vertices->Add(nP);
1752 result = Standard_True;
1753 break;
1754 }
1755 }
1756 else {
1757 if(!IsSeamParameter(U2,TOL2D) && !IsSeamParameter(U1,TOL2D)) {
1758 Standard_Real nU = (cnearZero) ? (2.*M_PI) : 0.;
1759 IntSurf_PntOn2S nP;
1760 nP.SetValue(aP.Value());
1761 Standard_Real U3 = 0., V3 = 0.;
1762 if(IsReversed) {
1763 Line->Value(ip).ParametersOnS1(U3,V3); // prm
1764 nP.SetValue(Standard_False,nU,V);
1765 nP.SetValue(Standard_True,U3,V3);
1766 }
1767 else {
1768 Line->Value(ip).ParametersOnS2(U3,V3); // prm
1769 nP.SetValue(Standard_True,nU,V);
1770 nP.SetValue(Standard_False,U3,V3);
1771 }
1772 Line->InsertBefore(ip,nP);
1773 Vertices->Add(nP);
1774 result = Standard_True;
1775 break;
1776 }
1777 else {
1778 // Line->InsertBefore(ip,Line->Value(ipn));
1779 // Line->RemovePoint(ip+2);
1780 // result = Standard_True;
1781 // cout << "swap vertex " << endl;
1782 // break;
1783 }
1784 }
1785 }
7fd59977 1786 }
1787 }
1788 }
1789 return result;
1790}
1791
191478a5 1792static void ToSmooth( const Handle(IntSurf_LineOn2S)& Line,
1793 const Standard_Boolean IsReversed,
1794 const IntSurf_Quadric& Quad,
1795 const Standard_Boolean IsFirst,
1796 Standard_Real& D3D)
7fd59977 1797{
1798 if(Line->NbPoints() <= 10)
1799 return;
191478a5 1800
7fd59977 1801 D3D = 0.;
1802 Standard_Integer NbTestPnts = Line->NbPoints() / 5;
1803 if(NbTestPnts < 5) NbTestPnts = 5;
1804
1805 Standard_Integer startp = (IsFirst) ? 2 : (Line->NbPoints() - NbTestPnts - 2);
1806 Standard_Integer ip = 0;
1807 Standard_Real Uc = 0., Vc = 0., Un = 0., Vn = 0., DDU = 0., DDV = 0.;
1808
1809 for(ip = startp; ip <= NbTestPnts; ip++) {
1810 if(IsReversed) {
1811 Line->Value(ip).ParametersOnS2(Uc,Vc); // S2 - quadric
1812 Line->Value(ip+1).ParametersOnS2(Un,Vn);
1813 }
1814 else {
1815 Line->Value(ip).ParametersOnS1(Uc,Vc); // S1 - quadric
1816 Line->Value(ip+1).ParametersOnS1(Un,Vn);
1817 }
1818 DDU += fabs(fabs(Uc)-fabs(Un));
1819 DDV += fabs(fabs(Vc)-fabs(Vn));
191478a5 1820
7fd59977 1821 if(ip > startp) {
1822 Standard_Real DP = Line->Value(ip).Value().Distance(Line->Value(ip-1).Value());
1823 D3D += DP;
1824 }
1825 }
1826
1827 DDU /= (Standard_Real) NbTestPnts + 1;
1828 DDV /= (Standard_Real) NbTestPnts + 1;
191478a5 1829
7fd59977 1830 D3D /= (Standard_Real) NbTestPnts + 1;
1831
1832
1833 Standard_Integer Index1 = (IsFirst) ? 1 : (Line->NbPoints());
1834 Standard_Integer Index2 = (IsFirst) ? 2 : (Line->NbPoints()-1);
1835 Standard_Integer Index3 = (IsFirst) ? 3 : (Line->NbPoints()-2);
1836
1837 Standard_Boolean doU = Standard_False;
7fd59977 1838
1839 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., U3 = 0., V3 = 0.;
1840
1841 if(IsReversed) {
1842 Line->Value(Index1).ParametersOnS2(U1,V1); // S2 - quadric
1843 Line->Value(Index2).ParametersOnS2(U2,V2);
1844 Line->Value(Index3).ParametersOnS2(U3,V3);
1845 }
1846 else {
1847 Line->Value(Index1).ParametersOnS1(U1,V1); // S1 - quadric
1848 Line->Value(Index2).ParametersOnS1(U2,V2);
1849 Line->Value(Index3).ParametersOnS1(U3,V3);
1850 }
1851
1852 if(!doU && Quad.TypeQuadric() == GeomAbs_Sphere) {
c6541a0c 1853 if(fabs(fabs(U1)-fabs(U2)) > (M_PI/16.)) doU = Standard_True;
191478a5 1854
c6541a0c
D
1855 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
1856 if(fabs(V1-M_PI/2.) <= 1.e-9 || fabs(V1+M_PI/2.) <= 1.e-9) {}
7fd59977 1857 else {
191478a5 1858 doU = Standard_False;
7fd59977 1859 }
1860 }
1861 }
191478a5 1862
7fd59977 1863 if(Quad.TypeQuadric() == GeomAbs_Cone) {
1864 Standard_Real Uapx = 0., Vapx = 0.;
1865 Quad.Parameters(Quad.Cone().Apex(),Uapx,Vapx);
1866
c6541a0c 1867 if(fabs(fabs(U1)-fabs(U2)) > M_PI/32.) doU = Standard_True;
7fd59977 1868
c6541a0c 1869 if(doU && (fabs(U1) <= 1.e-9 || fabs(U1-2.*M_PI) <= 1.e-9)) {
7fd59977 1870 if(fabs(V1-Vapx) <= 1.e-9) {}
1871 else {
191478a5 1872 doU = Standard_False;
7fd59977 1873 }
1874 }
1875 }
1876
7fd59977 1877 if(doU) {
1878 Standard_Real dU = Min((DDU/10.),5.e-8);
1879 Standard_Real U = (U2 > U3) ? (U2 + dU) : (U2 - dU);
1880 if(IsReversed)
1881 Line->SetUV(Index1,Standard_False,U,V1);
1882 else
1883 Line->SetUV(Index1,Standard_True,U,V1);
1884 U1 = U;
1885 }
1886}
1887
1888static Standard_Boolean TestMiddleOnPrm(const IntSurf_PntOn2S& aP,
191478a5 1889 const IntSurf_PntOn2S& aV,
1890 const Standard_Boolean IsReversed,
1891 const Standard_Real ArcTol,
1892 const Handle(Adaptor3d_TopolTool)& PDomain)
1893
7fd59977 1894{
1895 Standard_Boolean result = Standard_False;
1896 Standard_Real Up = 0., Vp = 0., Uv = 0., Vv = 0.;
1897 if(IsReversed) {
1898 aP.ParametersOnS1(Up,Vp); //S1 - parametric
1899 aV.ParametersOnS1(Uv,Vv);
1900 }
1901 else {
1902 aP.ParametersOnS2(Up,Vp); // S2 - parametric
1903 aV.ParametersOnS2(Uv,Vv);
1904 }
1905 Standard_Real Um = (Up + Uv)*0.5, Vm = (Vp + Vv)*0.5;
1906 gp_Pnt2d a2DPntM(Um,Vm);
1907 TopAbs_State PosM = PDomain->Classify(a2DPntM,ArcTol);
1908 if(PosM == TopAbs_ON || PosM == TopAbs_IN )
1909 result = Standard_True;
1910 return result;
1911}
1912
191478a5 1913static void VerifyVertices( const Handle(IntSurf_LineOn2S)& Line,
1914 const Standard_Boolean IsReversed,
1915 const Handle(IntSurf_LineOn2S)& Vertices,
1916 const Standard_Real TOL2D,
1917 const Standard_Real ArcTol,
1918 const Handle(Adaptor3d_TopolTool)& PDomain,
1919 IntSurf_PntOn2S& VrtF,
1920 Standard_Boolean& AddFirst,
1921 IntSurf_PntOn2S& VrtL,
1922 Standard_Boolean& AddLast)
7fd59977 1923{
1924 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
1925 Standard_Integer FIndexSame = 0, FIndexNear = 0, LIndexSame = 0, LIndexNear = 0;
1926 const IntSurf_PntOn2S& aPF = Line->Value(1);
1927 const IntSurf_PntOn2S& aPL = Line->Value(nbp);
1928 Standard_Real UF = 0., VF = 0., UL = 0., VL = 0.;
1929 if(IsReversed) {
1930 aPF.ParametersOnS2(UF,VF);
1931 aPL.ParametersOnS2(UL,VL);
1932 }
1933 else {
1934 aPF.ParametersOnS1(UF,VF);
1935 aPL.ParametersOnS1(UL,VL);
1936 }
1937 gp_Pnt2d a2DPF(UF,VF);
1938 gp_Pnt2d a2DPL(UL,VL);
1939 Standard_Real DistMinF = 1.e+100, DistMinL = 1.e+100;
1940 Standard_Integer FConjugated = 0, LConjugated = 0;
1941
1942 Standard_Integer iv = 0;
1943
1944 for(iv = 1; iv <= nbv; iv++) {
1945 Standard_Real Uv = 0., Vv = 0.;
1946 if(IsReversed) {
1947 Vertices->Value(iv).ParametersOnS2(Uv,Vv);
1948 Uv = AdjustU(Uv);
1949 Vertices->SetUV(iv,Standard_False,Uv,Vv);
1950 }
1951 else {
1952 Vertices->Value(iv).ParametersOnS1(Uv,Vv);
1953 Uv = AdjustU(Uv);
1954 Vertices->SetUV(iv,Standard_True,Uv,Vv);
1955 }
1956 }
1957
1958 for(iv = 1; iv <= nbv; iv++) {
1959 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1960 if(AreSamePoints(aPF,aV)) {
1961 FIndexSame = iv;
1962 break;
1963 }
1964 else {
1965 Standard_Real Uv = 0., Vv = 0.;
1966 if(IsReversed)
1967 aV.ParametersOnS2(Uv,Vv);
1968 else
1969 aV.ParametersOnS1(Uv,Vv);
1970 gp_Pnt2d a2DV(Uv,Vv);
1971 Standard_Real Dist = a2DV.Distance(a2DPF);
1972 if(Dist < DistMinF) {
1973 DistMinF = Dist;
1974 FIndexNear = iv;
1975 if(FConjugated != 0)
1976 FConjugated = 0;
1977 }
1978 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 1979 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 1980 gp_Pnt2d a2DCV(Ucv,Vv);
1981 Standard_Real CDist = a2DCV.Distance(a2DPF);
1982 if(CDist < DistMinF) {
1983 DistMinF = CDist;
1984 FConjugated = iv;
1985 FIndexNear = iv;
1986 }
1987 }
1988 }
1989 }
1990
1991 for(iv = 1; iv <= nbv; iv++) {
1992 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
1993 if(AreSamePoints(aPL,aV)) {
1994 LIndexSame = iv;
1995 break;
1996 }
1997 else {
1998 Standard_Real Uv = 0., Vv = 0.;
1999 if(IsReversed)
2000 aV.ParametersOnS2(Uv,Vv);
2001 else
2002 aV.ParametersOnS1(Uv,Vv);
2003 gp_Pnt2d a2DV(Uv,Vv);
2004 Standard_Real Dist = a2DV.Distance(a2DPL);
2005 if(Dist < DistMinL) {
2006 DistMinL = Dist;
2007 LIndexNear = iv;
2008 if(LConjugated != 0)
2009 LConjugated = 0;
2010 }
2011 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 2012 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 2013 gp_Pnt2d a2DCV(Ucv,Vv);
2014 Standard_Real CDist = a2DCV.Distance(a2DPL);
2015 if(CDist < DistMinL) {
2016 DistMinL = CDist;
2017 LConjugated = iv;
2018 LIndexNear = iv;
2019 }
2020 }
2021 }
2022 }
2023
2024 AddFirst = Standard_False;
2025 AddLast = Standard_False;
2026
2027 if(FIndexSame == 0) {
2028 if(FIndexNear != 0) {
2029 const IntSurf_PntOn2S& aV = Vertices->Value(FIndexNear);
2030 Standard_Real Uv = 0., Vv = 0.;
2031 if(IsReversed)
2032 aV.ParametersOnS2(Uv,Vv);
2033 else
2034 aV.ParametersOnS1(Uv,Vv);
2035 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 2036 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 2037 Standard_Boolean test = TestMiddleOnPrm(aPF,aV,IsReversed,ArcTol,PDomain);
2038 if(test) {
2039 VrtF.SetValue(aV.Value());
2040 if(IsReversed) {
2041 Standard_Real U2 = 0., V2 = 0.;
2042 aV.ParametersOnS1(U2,V2); // S1 - prm
2043 VrtF.SetValue(Standard_True,U2,V2);
2044 if(FConjugated == 0)
2045 VrtF.SetValue(Standard_False,Uv,Vv);
2046 else
2047 VrtF.SetValue(Standard_False,Ucv,Vv);
2048 }
2049 else {
2050 Standard_Real U2 = 0., V2 = 0.;
2051 aV.ParametersOnS2(U2,V2); // S2 - prm
2052 VrtF.SetValue(Standard_False,U2,V2);
2053 if(FConjugated == 0)
2054 VrtF.SetValue(Standard_True,Uv,Vv);
2055 else
2056 VrtF.SetValue(Standard_True,Ucv,Vv);
2057 }
2058 Standard_Real Dist3D = VrtF.Value().Distance(aPF.Value());
2059 if(Dist3D > 1.5e-7 && DistMinF > TOL2D) {
2060 AddFirst = Standard_True;
2061 }
2062 }
2063 }
2064 else {
2065 // to do: analyze internal vertex
2066 }
2067 }
2068 }
191478a5 2069
7fd59977 2070 if(LIndexSame == 0) {
2071 if(LIndexNear != 0) {
2072 const IntSurf_PntOn2S& aV = Vertices->Value(LIndexNear);
2073 Standard_Real Uv = 0., Vv = 0.;
2074 if(IsReversed)
2075 aV.ParametersOnS2(Uv,Vv);
2076 else
2077 aV.ParametersOnS1(Uv,Vv);
2078 if(IsSeamParameter(Uv,TOL2D)) {
c6541a0c 2079 Standard_Real Ucv = (fabs(Uv) < fabs(2.*M_PI-Uv)) ? (2.*M_PI) : 0.;
7fd59977 2080 Standard_Boolean test = TestMiddleOnPrm(aPL,aV,IsReversed,ArcTol,PDomain);
2081 if(test) {
2082 VrtL.SetValue(aV.Value());
2083 if(IsReversed) {
2084 Standard_Real U2 = 0., V2 = 0.;
2085 aV.ParametersOnS1(U2,V2); // S1 - prm
2086 VrtL.SetValue(Standard_True,U2,V2);
2087 if(LConjugated == 0)
2088 VrtL.SetValue(Standard_False,Uv,Vv);
2089 else
2090 VrtL.SetValue(Standard_False,Ucv,Vv);
2091 }
2092 else {
2093 Standard_Real U2 = 0., V2 = 0.;
2094 aV.ParametersOnS2(U2,V2); // S2 - prm
2095 VrtL.SetValue(Standard_False,U2,V2);
2096 if(LConjugated == 0)
2097 VrtL.SetValue(Standard_True,Uv,Vv);
2098 else
2099 VrtL.SetValue(Standard_True,Ucv,Vv);
2100 }
2101 Standard_Real Dist3D = VrtL.Value().Distance(aPL.Value());
2102 if(Dist3D > 1.5e-7 && DistMinL > TOL2D) {
2103 AddLast = Standard_True;
2104 }
2105 }
2106 }
2107 else {
2108 // to do: analyze internal vertex
2109 }
2110 }
2111 }
2112}
2113
2114static Standard_Boolean AddVertices(Handle(IntSurf_LineOn2S)& Line,
191478a5 2115 const IntSurf_PntOn2S& VrtF,
2116 const Standard_Boolean AddFirst,
2117 const IntSurf_PntOn2S& VrtL,
2118 const Standard_Boolean AddLast,
2119 const Standard_Real D3DF,
2120 const Standard_Real D3DL)
7fd59977 2121{
2122 Standard_Boolean result = Standard_False;
2123 if(AddFirst) {
2124 Standard_Real DF = Line->Value(1).Value().Distance(VrtF.Value());
2125 if((D3DF*2.) > DF && DF > 1.5e-7) {
2126 Line->InsertBefore(1,VrtF);
2127 result = Standard_True;
2128 }
2129 }
2130 if(AddLast) {
2131 Standard_Real DL = Line->Value(Line->NbPoints()).Value().Distance(VrtL.Value());
2132 if((D3DL*2.) > DL && DL > 1.5e-7) {
2133 Line->Add(VrtL);
2134 result = Standard_True;
2135 }
2136 }
2137 return result;
2138}
191478a5 2139
7fd59977 2140
2141static void PutIntVertices(Handle(IntPatch_Line)& Line,
191478a5 2142 Handle(IntSurf_LineOn2S)& Result,
2143 Standard_Boolean ,//IsReversed,
2144 Handle(IntSurf_LineOn2S)& Vertices,
2145 const Standard_Real ArcTol)
7fd59977 2146{
2147 Standard_Integer nbp = Result->NbPoints(), nbv = Vertices->NbPoints();
2148
2149 if(nbp < 3)
2150 return;
2151
2152 Handle(IntPatch_WLine)& WLine = (*((Handle(IntPatch_WLine)*)&Line));
2153 Standard_Integer ip = 0, iv = 0;
2154 gp_Pnt aPnt;
2155 IntPatch_Point thePnt;
2156 Standard_Real U1 = 0., V1 = 0., U2 = 0., V2 = 0.;
191478a5 2157
7fd59977 2158 for(ip = 2; ip <= (nbp-1); ip++) {
2159 const IntSurf_PntOn2S& aP = Result->Value(ip);
2160 for(iv = 1; iv <= nbv; iv++) {
2161 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2162 if(AreSamePoints(aP,aV)) {
2163 aPnt = Result->Value(ip).Value();
191478a5 2164 Result->Value(ip).ParametersOnS1(U1,V1);
2165 Result->Value(ip).ParametersOnS2(U2,V2);
2166 thePnt.SetValue(aPnt,ArcTol,Standard_False);
2167 thePnt.SetParameters(U1,V1,U2,V2);
2168 thePnt.SetParameter((Standard_Real)ip);
2169 WLine->AddVertex(thePnt);
7fd59977 2170 }
2171 }
2172 }
2173}
2174
2175static Standard_Boolean HasInternals(Handle(IntSurf_LineOn2S)& Line,
191478a5 2176 Handle(IntSurf_LineOn2S)& Vertices)
7fd59977 2177{
2178 Standard_Integer nbp = Line->NbPoints(), nbv = Vertices->NbPoints();
2179 Standard_Integer ip = 0, iv = 0;
2180 Standard_Boolean result = Standard_False;
191478a5 2181
7fd59977 2182 if(nbp < 3)
2183 return result;
2184
2185 for(ip = 2; ip <= (nbp-1); ip++) {
2186 const IntSurf_PntOn2S& aP = Line->Value(ip);
2187 for(iv = 1; iv <= nbv; iv++) {
2188 const IntSurf_PntOn2S& aV = Vertices->Value(iv);
2189 if(AreSamePoints(aP,aV)) {
2190 result = Standard_True;
2191 break;
2192 }
2193 }
2194 if(result)
2195 break;
2196 }
191478a5 2197
7fd59977 2198 return result;
2199}
2200static Handle(IntPatch_WLine) MakeSplitWLine (Handle(IntPatch_WLine)& WLine,
191478a5 2201 Standard_Boolean Tang,
2202 IntSurf_TypeTrans Trans1,
2203 IntSurf_TypeTrans Trans2,
2204 Standard_Real ArcTol,
2205 Standard_Integer ParFirst,
2206 Standard_Integer ParLast)
7fd59977 2207{
2208 Handle(IntSurf_LineOn2S) SLine = WLine->Curve();
2209 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
191478a5 2210
2211 Standard_Integer ip = 0;
7fd59977 2212 for(ip = ParFirst; ip <= ParLast; ip++)
2213 sline->Add(SLine->Value(ip));
2214
2215 Handle(IntPatch_WLine) wline = new IntPatch_WLine(sline,Tang,Trans1,Trans2);
2216
2217 gp_Pnt aSPnt;
2218 IntPatch_Point TPntF,TPntL;
2219 Standard_Real uu1 = 0., vv1 = 0., uu2 = 0., vv2 = 0.;
2220
2221 aSPnt = sline->Value(1).Value();
2222 sline->Value(1).ParametersOnS1(uu1,vv1);
2223 sline->Value(1).ParametersOnS2(uu2,vv2);
2224 TPntF.SetValue(aSPnt,ArcTol,Standard_False);
2225 TPntF.SetParameters(uu1,vv1,uu2,vv2);
2226 TPntF.SetParameter(1.);
2227 wline->AddVertex(TPntF);
2228 wline->SetFirstPoint(1);
191478a5 2229
7fd59977 2230 aSPnt = sline->Value(sline->NbPoints()).Value();
2231 sline->Value(sline->NbPoints()).ParametersOnS1(uu1,vv1);
2232 sline->Value(sline->NbPoints()).ParametersOnS2(uu2,vv2);
2233 TPntL.SetValue(aSPnt,ArcTol,Standard_False);
2234 TPntL.SetParameters(uu1,vv1,uu2,vv2);
2235 TPntL.SetParameter((Standard_Real)sline->NbPoints());
2236 wline->AddVertex(TPntL);
2237 wline->SetLastPoint(sline->NbPoints());
2238
2239 return wline;
2240}
2241
2242static Standard_Boolean SplitOnSegments(Handle(IntPatch_WLine)& WLine,
191478a5 2243 Standard_Boolean Tang,
2244 IntSurf_TypeTrans Trans1,
2245 IntSurf_TypeTrans Trans2,
2246 Standard_Real ArcTol,
2247 IntPatch_SequenceOfLine& Segments)
7fd59977 2248{
2249 Standard_Boolean result = Standard_False;
2250 Segments.Clear();
2251
2252 Standard_Integer nbv = WLine->NbVertex();
2253 if(nbv > 3) {
2254 Standard_Integer iv = 0;
2255 for(iv = 1; iv < nbv; iv++) {
191478a5 2256 Standard_Integer firstPar =
2257 (Standard_Integer) WLine->Vertex(iv).ParameterOnLine();
2258 Standard_Integer lastPar =
2259 (Standard_Integer) WLine->Vertex(iv+1).ParameterOnLine();
7fd59977 2260 if((lastPar - firstPar) <= 1)
2261 continue;
2262 else {
191478a5 2263 Handle(IntPatch_WLine) splitwline = MakeSplitWLine(WLine,Tang,Trans1,Trans2,
2264 ArcTol,firstPar,lastPar);
7fd59977 2265 Segments.Append(splitwline);
2266 if(!result)
2267 result = Standard_True;
2268 }
2269 }
2270 }
2271 return result;
2272}
2273
191478a5 2274static Standard_Boolean DecomposeResult(const Handle(IntPatch_Line)& theLine,
2275 const Standard_Boolean IsReversed,
2276 const IntSurf_Quadric& theQuad,
2277 const Handle(Adaptor3d_TopolTool)& thePDomain,
2278 const Handle(Adaptor3d_HSurface)& theQSurf,
2279 const Standard_Real theArcTol,
2280 IntPatch_SequenceOfLine& theLines)
7fd59977 2281{
191478a5 2282 // Split <theLine> in the places where it passes through seam edge or singularity
2283 // (apex of cone or pole of sphere). This passage is detected by jump of U-parameter
2284 // from point to point.
2285
2286 const Standard_Real aDeltaUmax = 0.5*M_PI;
2287 const Standard_Real aTOL3D = 1.e-10,
2288 aTOL2D = Precision::PConfusion(),
2289 aTOL2DS = Precision::PConfusion();
7fd59977 2290
191478a5 2291 if( theLine->ArcType() != IntPatch_Walking )
2292 {
2293 return Standard_False;
7fd59977 2294 }
2295
191478a5 2296 const Handle(IntPatch_WLine)& aWLine = (*((Handle(IntPatch_WLine)*)&theLine));
2297 const Handle(IntSurf_LineOn2S)& aSLine = aWLine->Curve();
7fd59977 2298
191478a5 2299 if(aSLine->NbPoints() <= 2)
2300 {
2301 return Standard_False;
2302 }
2303
2304 //Deletes repeated vertices
2305 Handle(IntSurf_LineOn2S) aVLine = GetVertices(aWLine,aTOL3D,aTOL2D);
2306
2307 Handle(IntSurf_LineOn2S) aSSLine(aSLine);
7fd59977 2308
191478a5 2309 if(aSSLine->NbPoints() <= 1)
2310 return Standard_False;
7fd59977 2311
191478a5 2312 AdjustLine(aSSLine,IsReversed,theQSurf,aTOL2D);
7fd59977 2313
191478a5 2314 {
2315 Standard_Boolean isInserted = Standard_True;
2316 while(isInserted)
2317 {
2318 const Standard_Integer aNbPnts = aSSLine->NbPoints();
2319 TColStd_Array1OfInteger aPTypes(1,aNbPnts);
2320 SearchVertices(aSSLine,aVLine,aPTypes);
2321 isInserted = InsertSeamVertices(aSSLine,IsReversed,aVLine,aPTypes,aTOL2D);
7fd59977 2322 }
7fd59977 2323 }
2324
191478a5 2325 const Standard_Integer aLindex = aSSLine->NbPoints();
2326 Standard_Integer aFindex = 1, aBindex = 0;
7fd59977 2327
191478a5 2328 IntPatch_Point aTPntF, aTPntL;
7fd59977 2329
2330 // build WLine parts (if any)
191478a5 2331 Standard_Boolean flNextLine = Standard_True;
2332 Standard_Boolean hasBeenDecomposed = Standard_False;
2333 while(flNextLine)
2334 {
2335 // reset variables
2336 flNextLine = Standard_False;
2337 Standard_Boolean isDecomposited = Standard_False;
2338 Standard_Real U1 = 0., U2 = 0., V1 = 0., V2 = 0., AnU1 = 0.;
7fd59977 2339
191478a5 2340 Handle(IntSurf_LineOn2S) sline = new IntSurf_LineOn2S();
7fd59977 2341
191478a5 2342 //if((Lindex-Findex+1) <= 2 )
2343 if(aLindex <= aFindex)
2344 return hasBeenDecomposed;
2345
2346 // analyze other points
2347 for(Standard_Integer k = aFindex; k <= aLindex; k++)
2348 {
2349 if( k == aFindex )
2350 {
2351 if(IsReversed)
2352 {
2353 aSSLine->Value(k).ParametersOnS2(AnU1,V1); // S2 - quadric, set U,V by Pnt3D
2354 }
2355 else
2356 {
2357 aSSLine->Value(k).ParametersOnS1(AnU1,V1); // S1 - quadric, set U,V by Pnt3D
2358 }
7fd59977 2359
191478a5 2360 sline->Add(aSSLine->Value(k));
2361 continue;
2362 }
7fd59977 2363
191478a5 2364 if(IsReversed)
2365 {
2366 aSSLine->Value(k).ParametersOnS2(U1,V1); // S2 - quadric, set U,V by Pnt3D
7fd59977 2367 }
191478a5 2368 else
2369 {
2370 aSSLine->Value(k).ParametersOnS1(U1,V1); // S1 - quadric, set U,V by Pnt3D
7fd59977 2371 }
7fd59977 2372
191478a5 2373 if(Abs(U1-AnU1) > aDeltaUmax)
2374 {
2375 aBindex = k;
2376 isDecomposited = Standard_True;
2377 break;
2378 }
7fd59977 2379
191478a5 2380 sline->Add(aSSLine->Value(k));
2381 AnU1=U1;
7fd59977 2382 }
7fd59977 2383
191478a5 2384 IntSurf_PntOn2S aVF, aVL;
2385 Standard_Boolean addVF = Standard_False, addVL = Standard_False;
2386 VerifyVertices(sline,IsReversed,aVLine,aTOL2DS,theArcTol,
2387 thePDomain,aVF,addVF,aVL,addVL);
2388
2389 Standard_Boolean hasInternals = HasInternals(sline,aVLine);
2390
2391 Standard_Real D3F = 0., D3L = 0.;
2392 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2393 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2394
2395 //if(D3F <= 1.5e-7 && sline->NbPoints() >=3) {
2396 // D3F = sline->Value(2).Value().Distance(sline->Value(3).Value());
2397 //}
2398 //if(D3L <= 1.5e-7 && sline->NbPoints() >=3) {
2399 // D3L = sline->Value(sline->NbPoints()-1).Value().Distance(sline->
2400 // Value(sline->NbPoints()-2).Value());
2401 //}
2402
2403 if(addVF || addVL)
2404 {
2405 Standard_Boolean isAdded = AddVertices(sline,aVF,addVF,aVL,addVL,D3F,D3L);
2406 if(isAdded)
2407 {
2408 ToSmooth(sline,IsReversed,theQuad,Standard_True,D3F);
2409 ToSmooth(sline,IsReversed,theQuad,Standard_False,D3L);
2410 }
7fd59977 2411 }
7fd59977 2412
191478a5 2413 if(!hasInternals)
2414 {
2415 ForcedPurgePoints(sline,IsReversed,theQuad);
2416 }
7fd59977 2417
191478a5 2418 Handle(IntPatch_WLine) wline =
2419 new IntPatch_WLine(sline,Standard_False,
2420 theLine->TransitionOnS1(),theLine->TransitionOnS2());
2421
2422 gp_Pnt aSPnt(sline->Value(1).Value());
2423 sline->Value(1).ParametersOnS1(U1,V1);
2424 sline->Value(1).ParametersOnS2(U2,V2);
2425 aTPntF.SetValue(aSPnt,theArcTol,Standard_False);
2426 aTPntF.SetParameters(U1,V1,U2,V2);
2427 aTPntF.SetParameter(1.);
2428 wline->AddVertex(aTPntF);
2429 wline->SetFirstPoint(1);
2430
2431 if(hasInternals)
2432 {
2433 PutIntVertices(wline,sline,IsReversed,aVLine,theArcTol);
2434 }
7fd59977 2435
191478a5 2436 aSPnt = sline->Value(sline->NbPoints()).Value();
2437 sline->Value(sline->NbPoints()).ParametersOnS1(U1,V1);
2438 sline->Value(sline->NbPoints()).ParametersOnS2(U2,V2);
2439 aTPntL.SetValue(aSPnt,theArcTol,Standard_False);
2440 aTPntL.SetParameters(U1,V1,U2,V2);
2441 aTPntL.SetParameter(sline->NbPoints());
2442 wline->AddVertex(aTPntL);
2443 wline->SetLastPoint(sline->NbPoints());
2444
2445 IntPatch_SequenceOfLine segm;
2446 Standard_Boolean isSplited = SplitOnSegments(wline,Standard_False,
2447 theLine->TransitionOnS1(),theLine->TransitionOnS2(),theArcTol,segm);
2448
2449 if(!isSplited)
2450 {
2451 theLines.Append(wline);
2452 }
2453 else
2454 {
2455 Standard_Integer nbsegms = segm.Length();
2456 Standard_Integer iseg = 0;
2457 for(iseg = 1; iseg <= nbsegms; iseg++)
2458 theLines.Append(segm(iseg));
2459 }
7fd59977 2460
191478a5 2461 if(isDecomposited)
2462 {
2463 aFindex = aBindex;
2464 flNextLine = hasBeenDecomposed = Standard_True;
2465 }
7fd59977 2466 }
2467
191478a5 2468 return hasBeenDecomposed;
7fd59977 2469}
2470/*
2471// <-A
191478a5 2472{
2473Standard_Integer aNbPnts;
2474Standard_Real aU1,aV1,aU2,aV2;
2475gp_Pnt aPx;
2476//
2477aNbPnts=thelin->NbPoints();
2478printf(" WLine: aNbPnts=%d\n", aNbPnts);
2479for(i=1; i <= aNbPnts; ++i) {
2480const IntSurf_PntOn2S& aPoint = thelin->Value(i);
2481aPx=aPoint.Value();
2482aPoint.Parameters(aU1, aV1, aU2, aV2);
2483printf(" point %d %lf %lf %lf %lf %lf %lf %lf\n",
2484i, aPx.X(), aPx.Y(), aPx.Z(), aU1, aV1, aU2, aV2);
2485}
2486}
7fd59977 2487*/