0023388: Boolean operations hang up trying to build section of two customer's shapes
[occt.git] / src / IntPatch / IntPatch_WLine.cxx
CommitLineData
b311480e 1// Created on: 1991-05-27
2// Created by: Isabelle GRIGNON
3// Copyright (c) 1991-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_WLine.ixx>
23
24#define DEBUG 0
25#define DEBUGV 0
26
27#include <IntSurf_PntOn2S.hxx>
28#include <Precision.hxx>
29#include <stdio.h>
30
31
32IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
33 const Standard_Boolean Tang,
34 const IntSurf_TypeTrans Trans1,
35 const IntSurf_TypeTrans Trans2) :
36 IntPatch_Line(Tang,Trans1,Trans2),fipt(Standard_False),lapt(Standard_False),
37 hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
38{
39 typ = IntPatch_Walking;
40 curv = Line;
41 Buv1.SetWhole();
42 Buv2.SetWhole();
43 Bxyz.SetWhole();
44 u1period=v1period=u2period=v2period=0.0;
45}
46
47
48IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
49 const Standard_Boolean Tang,
50 const IntSurf_Situation Situ1,
51 const IntSurf_Situation Situ2) :
52 IntPatch_Line(Tang,Situ1,Situ2),fipt(Standard_False),lapt(Standard_False),
53 hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
54{
55 typ = IntPatch_Walking;
56 curv = Line;
57 Buv1.SetWhole();
58 Buv2.SetWhole();
59 Bxyz.SetWhole();
60 u1period=v1period=u2period=v2period=0.0;
61}
62
63
64IntPatch_WLine::IntPatch_WLine (const Handle(IntSurf_LineOn2S)& Line,
65 const Standard_Boolean Tang) :
66 IntPatch_Line(Tang),fipt(Standard_False),lapt(Standard_False),
67 hasArcOnS1(Standard_False),hasArcOnS2(Standard_False)
68{
69 typ = IntPatch_Walking;
70 curv = Line;
71 Buv1.SetWhole();
72 Buv2.SetWhole();
73 Bxyz.SetWhole();
74 u1period=v1period=u2period=v2period=0.0;
75}
76
77
78void IntPatch_WLine::SetPoint(const Standard_Integer Index,
79 const IntPatch_Point& thepoint)
80{
81 curv->Value(Index,thepoint.PntOn2S());
82}
83
84
85Handle(IntSurf_LineOn2S) IntPatch_WLine::Curve() const
86{
87 return(curv);
88}
89
90static void RecadreMemePeriode(Standard_Real& u1,Standard_Real& v1,
91 Standard_Real& u2,Standard_Real& v2,
92 const Standard_Real anu1,const Standard_Real anv1,
93 const Standard_Real anu2,const Standard_Real anv2,
94 const Standard_Real U1Period,const Standard_Real V1Period,
95 const Standard_Real U2Period,const Standard_Real V2Period) {
96 if(U1Period) {
97 while(anu1-u1 > 0.8*U1Period) { u1+=U1Period; }
98 while(u1-anu1 > 0.8*U1Period) { u1-=U1Period; }
99 }
100 if(U2Period) {
101 while(anu2-u2 > 0.8*U2Period) { u2+=U2Period; }
102 while(u2-anu2 > 0.8*U2Period) { u2-=U2Period; }
103 }
104 if(V1Period) {
105 while(anv1-v1 > 0.8*V1Period) { v1+=V1Period; }
106 while(v1-anv1 > 0.8*V1Period) { v1-=V1Period; }
107 }
108 if(V2Period) {
109 while(anv2-v2 > 0.8*V2Period) { v2+=V2Period; }
110 while(v2-anv2 > 0.8*V2Period) { v2-=V2Period; }
111 }
112
113}
114
115static void RecadreMemePeriode(IntSurf_PntOn2S& POn2S,const IntSurf_PntOn2S& RefPOn2S,
116 const Standard_Real up1,
117 const Standard_Real vp1,
118 const Standard_Real up2,
119 const Standard_Real vp2) {
120 Standard_Real u1,v1,u2,v2,pu1,pv1,pu2,pv2;
121 POn2S.Parameters(u1,v1,u2,v2);
122 RefPOn2S.Parameters(pu1,pv1,pu2,pv2);
123 RecadreMemePeriode(u1,v1,u2,v2,pu1,pv1,pu2,pv2,up1,vp1,up2,vp2);
124 POn2S.SetValue(u1,v1,u2,v2);
125}
126
127static Standard_Boolean CompareVertexAndPoint(const gp_Pnt& V,const gp_Pnt& P,const Standard_Real& Tol) {
128 return(V.Distance(P)<=Tol);
129}
130
131void IntPatch_WLine::SetPeriod(const Standard_Real pu1,
132 const Standard_Real pv1,
133 const Standard_Real pu2,
134 const Standard_Real pv2) {
135 u1period=pu1; v1period=pv1; u2period=pu2; v2period=pv2;
136}
137Standard_Real IntPatch_WLine::U1Period() const { return(u1period); }
138Standard_Real IntPatch_WLine::V1Period() const { return(v1period); }
139Standard_Real IntPatch_WLine::U2Period() const { return(u2period); }
140Standard_Real IntPatch_WLine::V2Period() const { return(v2period); }
141
142
143//------------------------------------------------------------------------
144//-- En Entree : Une ligne de cheminement + Une Liste de Vetex
145//--
146//-- LineOn2S : 1------2-------3-------4-----5---- ----nbp
147//--
148//-- Vertex : a b c d e f
149//--
150//--
151//-- En Sortie
152//--
153//-- 1--2-3-4--5--------6----7--8--9--10--------
154//--
155//-- avec a de parametre 1
156//-- b 3
157//--
158//-- etc ...
159//--
160//--
161//-- !!!!!!!!!!!!!!! On considere que deux vertex ne peuvent pas etre
162//-- !!!!!!!!!!!!!!! a une distance inferieure a Tol
163//------------------------------------------------------------------------
164//--
165//-- On Teste si la LineOn2S contient des points confondus.
166//-- Dans ce cas, on remove ces points.
167//--
168//------------------------------------------------------------------------
169
170Standard_Boolean SameVtxRst(const IntPatch_Point& vtx1,const IntPatch_Point& vtx2) {
171 if(vtx1.IsOnDomS1()) {
172 if(vtx2.IsOnDomS1()) {
173 if(vtx1.ArcOnS1() == vtx2.ArcOnS1()) {
174 if(vtx1.ParameterOnArc1() == vtx2.ParameterOnArc1()) {
175
176 }
177 else {
178 return(Standard_False);
179 }
180 }
181 else {
182 return(Standard_False);
183 }
184 }
185 else {
186 return(Standard_False);
187 }
188 }
189 else {
190 if(vtx2.IsOnDomS1()) {
191 return(Standard_False);
192 }
193 }
194 if(vtx1.IsOnDomS2()) {
195 if(vtx2.IsOnDomS2()) {
196 if(vtx1.ArcOnS2() == vtx2.ArcOnS2()) {
197 if(vtx1.ParameterOnArc2() == vtx2.ParameterOnArc2()) {
198
199 }
200 else {
201 return(Standard_False);
202 }
203 }
204 else {
205 return(Standard_False);
206 }
207 }
208 else {
209 return(Standard_False);
210 }
211 }
212 else {
213 if(vtx2.IsOnDomS2()) {
214 return(Standard_False);
215 }
216 }
217 return(Standard_True);
218}
219
220
221static Standard_Boolean CompareVerticesOnSurf(const IntPatch_Point& vtx1,
222 const IntPatch_Point& vtx2,
223 const Standard_Boolean onFirst)
224{
225 Standard_Real u1,v1,u2,v2, tolU, tolV;
226 if (onFirst) {
227 vtx1.ParametersOnS1(u1,v1);
228 vtx2.ParametersOnS1(u2,v2);
229 }
230 else {
231 vtx1.ParametersOnS2(u1,v1);
232 vtx2.ParametersOnS2(u2,v2);
233 }
234 tolU = Precision::PConfusion();
235 tolV = Precision::PConfusion();
236 return (Abs(u1-u2) <= tolU && Abs(v1-v2) <= tolV);
237}
238
239inline Standard_Boolean CompareVerticesOnS1(const IntPatch_Point& vtx1, const IntPatch_Point& vtx2)
240{return CompareVerticesOnSurf (vtx1, vtx2, Standard_True);}
241
242inline Standard_Boolean CompareVerticesOnS2(const IntPatch_Point& vtx1, const IntPatch_Point& vtx2)
243{return CompareVerticesOnSurf (vtx1, vtx2, Standard_False);}
244
245
246void IntPatch_WLine::ComputeVertexParameters(const Standard_Real RTol) {
247
248 // MSV Oct 15, 2001: use tolerance of vertex instead of RTol where
249 // it is possible
250
251 Standard_Integer i,j,k,nbvtx,nbponline;
252 Standard_Integer indicevertexonline;
253 Standard_Real indicevertex;
254
255 Standard_Real ParamMinOnLine,ParamMaxOnLine;
256 if(fipt) { ParamMinOnLine = Vertex(indf).ParameterOnLine(); } else { ParamMinOnLine = -100000.0; }
257 if(lapt) { ParamMaxOnLine = Vertex(indl).ParameterOnLine(); } else { ParamMaxOnLine = 100000.0; }
258 Standard_Boolean APointDeleted = Standard_False;
259 //----------------------------------------------------------
260 //-- F i l t r e s u r r e s t r i c t i o n s --
261 //----------------------------------------------------------
262 //-- deux vertex sur la meme restriction et seulement
263 //-- sur celle ci ne doivent pas avoir le meme parametre
264 //--
265 Standard_Real Tol=RTol;
266 nbvtx = NbVertex();
267
268#if DEBUGV
269 cout<<"\n----------- avant ComputeVertexParameters -------------"<<endl;
270 for(i=1;i<=nbvtx;i++) {
271 Vertex(i).Dump();
272 Standard_Real polr = Vertex(i).ParameterOnLine();
273 Standard_Real pol = (Standard_Integer)polr;
274 if(pol>=1 && pol<=nbvtx) {
275 cout<<"----> IntSurf_PntOn2S : "<<polr<<" Pnt ("<<Vertex(pol).Value().X()
276 <<","<<Vertex(pol).Value().Y()
277 <<","<<Vertex(pol).Value().Z()<<")"<<endl;
278 }
279 }
280 cout<<"\n----------------------------------------------------------"<<endl;
281#endif
282
283
284 //-- ----------------------------------------------------------------------
285 //-- Traitement des aretes de couture : On duplique les points situes
286 //-- sur des restrictions differentes
287 //--
288 //-- Phase Creation de nouveaux points sur S1
289 Standard_Boolean encoreunefois;
290 do {
291 nbvtx=NbVertex();
292 encoreunefois=Standard_False;
293 for(i=1; i<=nbvtx && encoreunefois==Standard_False; i++) {
294 IntPatch_Point& VTXi = svtx.ChangeValue(i);
295 for(j=1; j<=nbvtx && encoreunefois==Standard_False; j++) {
296 if(i!=j) {
297 IntPatch_Point& VTXj = svtx.ChangeValue(j);
298 if(VTXi.ParameterOnLine() != VTXj.ParameterOnLine()) {
299 Standard_Real d = VTXi.Value().Distance(VTXj.Value());
300 Standard_Real toli = VTXi.Tolerance();
301 Standard_Real tolj = VTXj.Tolerance();
302 Standard_Real maxtol = Max(toli,tolj);
303 // MSV Oct 30, 2001: compare in 2D space also;
304 // increase tolerances
305 if (d < maxtol ||
306 CompareVerticesOnS1(VTXi,VTXj) || CompareVerticesOnS2(VTXi,VTXj)) {
307 //-- Creation Vtx (REF:S1(i) S2(j)) (On Garde S1(i))
308 Standard_Real newtoli = Max (toli, tolj+d*1.01);
309 Standard_Real newtolj = Max (tolj, toli+d*1.01);
310 Standard_Boolean acreer=Standard_False;
311 if(VTXi.IsOnDomS1()) {
312 if(VTXj.IsOnDomS1()) {
313 if(VTXj.ArcOnS1() != VTXi.ArcOnS1()) {
314 acreer=Standard_True;
315 }
316 }
317 else {
318 acreer=Standard_True;
319 }
320 }
321 if(acreer) {
322 IntPatch_Point vtx;
323 vtx = VTXj;
324 vtx.SetArc(Standard_True,
325 VTXi.ArcOnS1(),
326 VTXi.ParameterOnArc1(),
327 VTXi.TransitionLineArc1(),
328 VTXi.TransitionOnS1());
329 for(k=1; encoreunefois==Standard_False && k<=nbvtx; k++) {
330 const IntPatch_Point& VTXk = svtx.Value(k);
331 if(SameVtxRst(VTXk,vtx)) {
332 encoreunefois=Standard_True;
333 }
334 }
335 if(encoreunefois==Standard_False) {
336 VTXi.SetTolerance(newtoli);
337 VTXj.SetTolerance(newtolj);
338 vtx.SetTolerance(newtolj);
339 svtx.Append(vtx);
340 encoreunefois=Standard_True;
341 }
342 else {
343 encoreunefois=Standard_False;
344 }
345 }
346 //-- -----------------------------------------------------
347 //-- Creation Vtx (REF:S2(i) S1(j)) (On Garde S2(i))
348 acreer=Standard_False;
349 if(VTXi.IsOnDomS2()) {
350 if(VTXj.IsOnDomS2()) {
351 if(VTXj.ArcOnS2() != VTXi.ArcOnS2()) {
352 acreer=Standard_True;
353 }
354 }
355 else {
356 acreer=Standard_True;
357 }
358 }
359 if(acreer) {
360 IntPatch_Point vtx;
361 vtx = VTXj;
362 vtx.SetArc(Standard_False,
363 VTXi.ArcOnS2(),
364 VTXi.ParameterOnArc2(),
365 VTXi.TransitionLineArc2(),
366 VTXi.TransitionOnS2());
367 for(k=1; encoreunefois==Standard_False && k<=nbvtx; k++) {
368 const IntPatch_Point& VTXk = svtx.Value(k);
369 if(SameVtxRst(VTXk,vtx)) {
370 encoreunefois=Standard_True;
371 }
372 }
373 if(encoreunefois==Standard_False) {
374 VTXi.SetTolerance(newtoli);
375 VTXj.SetTolerance(newtolj);
376 vtx.SetTolerance(newtolj);
377 svtx.Append(vtx);
378 encoreunefois=Standard_True;
379 }
380 else {
381 encoreunefois=Standard_False;
382 }
383 }
384 }
385 }
386 }
387 }
388 }
389 }
390 while(encoreunefois);
391
392
393
394 //-- ----------------------------------------------------------------------
395
396
397
398 do {
399 APointDeleted = Standard_False;
400 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
401 const IntPatch_Point& VTXi = svtx.Value(i);
402 if(VTXi.Tolerance() > Tol) Tol = VTXi.Tolerance(); //-- 9 oct 97
403 if((VTXi.IsOnDomS1()==Standard_True) && (VTXi.IsOnDomS2()==Standard_False)) {
404 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
405 if(i!=j) {
406 const IntPatch_Point& VTXj = svtx.Value(j);
407 if((VTXj.IsOnDomS1()==Standard_True) && (VTXj.IsOnDomS2()==Standard_False)) {
408 if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) {
409 if(VTXi.ArcOnS1() == VTXj.ArcOnS1()) {
410 svtx.Remove(j);
411 nbvtx--;
412 if(lapt) { if(indl>=j) indl--; }
413 if(fipt) { if(indf>=j) indf--; }
414 APointDeleted = Standard_True;
415 }
416 }
417 }
418 }
419 }
420 }
421 }
422 }
423 while(APointDeleted == Standard_True);
424
425
426 do {
427 APointDeleted = Standard_False;
428 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
429 const IntPatch_Point& VTXi = svtx.Value(i);
430 if((VTXi.IsOnDomS2()==Standard_True) && (VTXi.IsOnDomS1()==Standard_False)) {
431 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
432 if(i!=j) {
433 const IntPatch_Point& VTXj = svtx.Value(j);
434 if((VTXj.IsOnDomS2()==Standard_True) && (VTXj.IsOnDomS1()==Standard_False)) {
435 if(VTXi.ParameterOnLine() == VTXj.ParameterOnLine()) {
436 if(VTXi.ArcOnS2() == VTXj.ArcOnS2()) {
437 svtx.Remove(j);
438 nbvtx--;
439 if(lapt) { if(indl>=j) indl--; }
440 if(fipt) { if(indf>=j) indf--; }
441 APointDeleted = Standard_True;
442 }
443 }
444 }
445 }
446 }
447 }
448 }
449 }
450 while(APointDeleted == Standard_True);
451
452 nbvtx = NbVertex();
453 nbponline = NbPnts();
454
455 //----------------------------------------------------
456 //-- On trie les Vertex
457 Standard_Boolean SortIsOK;
458 do {
459 SortIsOK = Standard_True;
460 for(i=2; i<=nbvtx; i++) {
461 if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) {
462 SortIsOK = Standard_False;
463 svtx.Exchange(i-1,i);
464 }
465 }
466 }
467 while(!SortIsOK);
468
469 //----------------------------------------------------
470 //-- On detecte les points confondus dans la LineOn2S
471 Standard_Real dmini = Precision::Confusion();
472 dmini*=dmini;
473 for(i=2; i<=nbponline; i++) {
474 //const IntSurf_PntOn2S& aPntOn2S1=curv->Value(i-1);
475 //const IntSurf_PntOn2S& aPntOn2S2=curv->Value(i);
476 Standard_Real d = (curv->Value(i-1).Value()).SquareDistance((curv->Value(i).Value()));
477 if(d < dmini) {
478 curv->RemovePoint(i);
479 nbponline--;
480 //----------------------------------------------
481 //-- On recadre les Vertex si besoin
482 //--
483 for(j=1; j<=nbvtx; j++) {
484 indicevertex = svtx.Value(j).ParameterOnLine();
485 if(indicevertex >= i) {
486 svtx.ChangeValue(j).SetParameter(indicevertex-1.0);
487 }
488 }
489 //modified by NIZNHY-PKV Mon Feb 11 09:28:02 2002 f
490 i--;
491 //modified by NIZNHY-PKV Mon Feb 11 09:28:04 2002 t
492 }
493 }
494 //----------------------------------------------------
495 for(i=1; i<=nbvtx; i++) {
496 const gp_Pnt& P = svtx.Value(i).Value();
497 Standard_Real vTol = svtx.Value(i).Tolerance();
498 indicevertex = svtx.Value(i).ParameterOnLine();
499 indicevertexonline = (Standard_Integer)indicevertex;
500 //--------------------------------------------------
501 //-- On Compare le vertex avec les points de la ligne
502 //-- d indice indicevertexOnLine-1
503 //-- indicevertexOnLine
504 //-- indicevertexOnLine+1
505 //--------------------------------------------------
506 if(indicevertexonline<1) {
507 if(CompareVertexAndPoint(P,curv->Value(1).Value(),vTol)) {
508 //-------------------------------------------------------
509 //-- On remplace le point cheminement(1) par vertex(i)
510 //-- et vertex(i) prend pour parametre 1
511 //-------------------------------------------------------
512
513 IntSurf_PntOn2S POn2S = svtx.Value(i).PntOn2S();
514 RecadreMemePeriode(POn2S,curv->Value(1),U1Period(),V1Period(),U2Period(),V2Period());
515 curv->Value(1,POn2S);
516
517 //--curv->Value(1,svtx.Value(i).PntOn2S());
518 svtx.ChangeValue(i).SetParameter(1.0);
519 }
520 else {
521 //-------------------------------------------------------
522 //-- On insere le point de cheminement Vertex(i)
523 //-- On recadre les parametres des autres vertex
524 //-------------------------------------------------------
525 IntSurf_PntOn2S POn2S = svtx.Value(i).PntOn2S();
526 RecadreMemePeriode(POn2S,curv->Value(1),U1Period(),V1Period(),U2Period(),V2Period());
527 curv->InsertBefore(1,POn2S);
528
529 //-- curv->InsertBefore(1,svtx.Value(i).PntOn2S());
530 svtx.ChangeValue(i).SetParameter(1.0);
531 nbponline++;
532 for(j=1;j<=nbvtx;j++) {
533 if(j!=1) {
534 Standard_Real t = svtx.Value(j).ParameterOnLine();
535 if(t>1.0) {
536 svtx.ChangeValue(j).SetParameter(t+1.0);
537 }
538 }
539 }
540 }
541 } //--- fin : if(indicevertexonline<1)
542 else {
543 //---------------------------------------------------------
544 //-- vertex(i) == cheminement (indicevertexonline-1)
545 //-- vertex(i) == cheminement (indicevertexonline)
546 //-- vertex(i) == cheminement (indicevertexonline+1)
547 //---------------------------------------------------------
548 Standard_Boolean Substitution = Standard_False;
549 //-- for(k=indicevertexonline+1; !Substitution && k>=indicevertexonline-1;k--) { avant le 9 oct 97
550 for(k=indicevertexonline+1; k>=indicevertexonline-1;k--) {
551 if(k>0 && k<=nbponline) {
552 if(CompareVertexAndPoint(P,curv->Value(k).Value(),vTol)) {
553 //-------------------------------------------------------
554 //-- On remplace le point cheminement(k)
555 //-- par vertex(i) et vertex(i) prend pour parametre k
556 //-------------------------------------------------------
557 IntSurf_PntOn2S POn2S = svtx.Value(i).PntOn2S();
558 RecadreMemePeriode(POn2S,curv->Value(k),U1Period(),V1Period(),U2Period(),V2Period());
559 curv->Value(k,POn2S);
560 Standard_Real mu1,mv1,mu2,mv2;
561 POn2S.Parameters(mu1,mv1,mu2,mv2);
562 svtx.ChangeValue(i).SetParameter(k);
563 svtx.ChangeValue(i).SetParameters(mu1,mv1,mu2,mv2);
564 Substitution = Standard_True;
565 }
566 }
567 }
e9a6ce82 568
569 //Remove duplicating points
570 if (Substitution)
571 {
572 Standard_Integer ind_point;
573 for(ind_point = 2; (ind_point <= nbponline && nbponline > 2); ind_point++) {
574 Standard_Real d = (curv->Value(ind_point-1).Value()).SquareDistance((curv->Value(ind_point).Value()));
575 if(d < dmini) {
576 curv->RemovePoint(ind_point);
577 nbponline--;
578 //----------------------------------------------
579 //-- On recadre les Vertex si besoin
580 //--
581 for(j=1; j<=nbvtx; j++) {
582 indicevertex = svtx.Value(j).ParameterOnLine();
583 if(indicevertex >= ind_point) {
584 svtx.ChangeValue(j).SetParameter(indicevertex-1.0);
585 }
586 }
587 //modified by NIZNHY-PKV Mon Feb 11 09:28:02 2002 f
588 ind_point--;
589 //modified by NIZNHY-PKV Mon Feb 11 09:28:04 2002 t
590 }
591 }
592 }
7fd59977 593
594 //--static int deb6nov98=1; Ne resout rien (a part partiellement BUC60409)
595 //--if(deb6nov98) {
596 //--Substitution=Standard_True;
597 //-- }
598
599 if(Substitution==Standard_False) {
600 //-------------------------------------------------------
601 //-- On insere le point de cheminement Vertex(i)
602 //-- On recadre les parametres des autres vertex
603 //-------------------------------------------------------
604 IntSurf_PntOn2S POn2S = svtx.Value(i).PntOn2S();
605 if(indicevertexonline >= nbponline) {
606 RecadreMemePeriode(POn2S,curv->Value(nbponline),U1Period(),V1Period(),U2Period(),V2Period());
607 curv->Add(POn2S);
608 }
609 else {
610 RecadreMemePeriode(POn2S,curv->Value(indicevertexonline+1),U1Period(),V1Period(),U2Period(),V2Period());
611 curv->InsertBefore(indicevertexonline+1,POn2S);
612 }
613 //-- curv->InsertBefore(indicevertexonline+1,svtx.Value(i).PntOn2S());
614 svtx.ChangeValue(i).SetParameter(indicevertexonline+1);
615 nbponline++;
616 for(j=1;j<=nbvtx;j++) {
617 if(j!=i) {
618 Standard_Real t = svtx.Value(j).ParameterOnLine();
619 if(t>(Standard_Real)indicevertexonline) {
620 svtx.ChangeValue(j).SetParameter(t+1.0);
621 }
622 }
623 }
624 } //-- Substitution
625 } //-- indicevertexonline>=1
626
627 } //-- boucle i sur vertex
628
629
630
631
632 do {
633 APointDeleted = Standard_False;
634 for(i=1; i<=nbvtx && (APointDeleted == Standard_False); i++) {
635 const IntPatch_Point& VTX = svtx.Value(i);
636 for(j=1; j<=nbvtx && (APointDeleted == Standard_False) ; j++) {
637 if(i!=j) {
638 const IntPatch_Point& VTXM1 = svtx.Value(j);
639
640 Standard_Boolean kill = Standard_False;
641 Standard_Boolean killm1 = Standard_False;
642 if(VTXM1.ParameterOnLine() == VTX.ParameterOnLine()) {
643 if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) { //-- OnS1 OnS1
644 if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS1 == OnS1
645 if(VTXM1.IsOnDomS2()) { //-- OnS1 == OnS1 OnS2
646 if(VTX.IsOnDomS2()==Standard_False) { //-- OnS1 == OnS1 OnS2 PasOnS2
647 kill=Standard_True;
648 }
649 else {
650 if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS1 == OnS1 OnS2 == OnS2
651 kill=Standard_True;
652 }
653 }
654 }
655 else { //-- OnS1 == OnS1 PasOnS2
656 if(VTX.IsOnDomS2()) { //-- OnS1 == OnS1 PasOnS2 OnS2
657 killm1=Standard_True;
658 }
659 }
660 }
661 }
662
663 if(!(kill || killm1)) {
664 if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()) { //-- OnS2 OnS2
665 if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS2 == OnS2
666 if(VTXM1.IsOnDomS1()) { //-- OnS2 == OnS2 OnS1
667 if(VTX.IsOnDomS1()==Standard_False) { //-- OnS2 == OnS2 OnS1 PasOnS1
668 kill=Standard_True;
669 }
670 else {
671 if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS2 == OnS2 OnS1 == OnS1
672 kill=Standard_True;
673 }
674 }
675 }
676 else { //-- OnS2 == OnS2 PasOnS1
677 if(VTX.IsOnDomS1()) { //-- OnS2 == OnS2 PasOnS1 OnS1
678 killm1=Standard_True;
679 }
680 }
681 }
682 }
683 }
684 if(kill) {
685 APointDeleted = Standard_True;
686 svtx.Remove(i);
687 nbvtx--;
688 }
689 else if(killm1) {
690 APointDeleted = Standard_True;
691 svtx.Remove(j);
692 nbvtx--;
693 }
694 }
695 }
696 }
697 }
698 }
699 while(APointDeleted == Standard_True);
700
701 do {
702 SortIsOK = Standard_True;
703 for(i=2; i<=nbvtx && SortIsOK; i++) {
704 const IntPatch_Point& Pim1=svtx.Value(i-1);
705 const IntPatch_Point& Pii =svtx.Value(i);
706 if(Pim1.ParameterOnLine()==Pii.ParameterOnLine()) {
707 if( (Pii.IsOnDomS1() == Standard_False)
708 && (Pii.IsOnDomS2() == Standard_False)) {
709 SortIsOK = Standard_False;
710 svtx.Remove(i);
711 nbvtx--;
712 }
713 else {
714 if( (Pim1.IsOnDomS1() == Standard_False)
715 && (Pim1.IsOnDomS2() == Standard_False)) {
716 SortIsOK = Standard_False;
717 svtx.Remove(i-1);
718 nbvtx--;
719 }
720 }
721 }
722 }
723 }
724 while(!SortIsOK);
725 //-- ----------------------------------------------------------------------------
726 //-- On ajoute les vertex de debut et de fin de ligne s il ne sont pas presents.
727 //--
728 //-- Existe t il un vertex de debut de ligne, de fin .
729 //--
730 //-- Si Besoin : il faudra dedoubler les points de debut et de fin sur les periodiques ??????
731
732
733
734
735 Standard_Boolean bFirst = Standard_False;
736 Standard_Boolean bLast = Standard_False;
737 nbponline = NbPnts();
738 for(i=1;i<=nbvtx;i++) {
739 Standard_Real pol = svtx.Value(i).ParameterOnLine();
740 if(pol==1.0) {
741 bFirst = fipt = Standard_True;
742 indf = i;
743 }
744 if(pol==nbponline) {
745 bLast = lapt = Standard_True;
746 indl = i;
747 }
748 }
749 if(bFirst == Standard_False) {
750 Standard_Real pu1,pv1,pu2,pv2;
751 Standard_Boolean vtxfound = Standard_False;
752 IntPatch_Point vtx;
753 curv->Value(1).Parameters(pu1,pv1,pu2,pv2);
754 for(i=1;
755 (vtxfound==Standard_False) && (i<=nbvtx);i++) {
756 const IntPatch_Point& V = svtx.Value(i);
757 Standard_Real vTol = V.Tolerance();
758 if(CompareVertexAndPoint(V.Value(),curv->Value(1).Value(),vTol)) {
759 vtx = V;
760 vtx.SetParameters(pu1,pv1,pu2,pv2);
761 vtxfound = Standard_True;
762 }
763 }
764 if(vtxfound == Standard_False) {
765 vtx.SetValue(curv->Value(1).Value(),Tol,Standard_False);
766 vtx.SetParameters(pu1,pv1,pu2,pv2);
767 }
768 vtx.SetParameter(1);
769 svtx.Prepend(vtx); nbvtx++;
770 fipt = Standard_True;
771 indf = 1;
772 }
773 if(bLast == Standard_False) {
774 Standard_Real pu1,pv1,pu2,pv2;
775 Standard_Boolean vtxfound = Standard_False;
776 IntPatch_Point vtx;
777 curv->Value(nbponline).Parameters(pu1,pv1,pu2,pv2);
778 for(i=1;
779 (vtxfound==Standard_False) && (i<=nbvtx);i++) {
780 const IntPatch_Point& V = svtx.Value(i);
781 Standard_Real vTol = V.Tolerance();
782 if(CompareVertexAndPoint(V.Value(),curv->Value(nbponline).Value(),vTol)) {
783 vtx = V;
784 vtx.SetParameters(pu1,pv1,pu2,pv2);
785 vtxfound = Standard_True;
786 }
787 }
788 if(vtxfound == Standard_False) {
789 vtx.SetValue(curv->Value(nbponline).Value(),Tol,Standard_False);
790 vtx.SetParameters(pu1,pv1,pu2,pv2);
791 }
792 vtx.SetParameter(nbponline);
793 svtx.Append(vtx); nbvtx++;
794 lapt = Standard_True;
795 indl = nbvtx;
796 }
797
798
799
800
801 //--------------------------------------------------------------
802 //-- ** Detection de points trouves sur une meme restriction
803 //-- avec la meme transition et avec des params on line
804 //-- voisins.
805 //-- ** Dans ce cas (-> donnerait un baillemenmt) on supprime
806 //-- le point 'intermediaire'.
807 //-- ** (exemple Vtx(1) ..... Vtx(204) Vtx(205))
808 //-- on supprime le Vtx(204)
809 //-- ** (exemple Vtx(1) Vtx(2) ..... Vtx(205))
810 //-- on supprime le Vtx(2)
811 //-- ** (exemple Vtx(1) ... Vtx(100) Vtx(101) ... Vtx(205))
812 //-- on supprime le Vtx(100) (Vtx(100)et101 sur m restr)
813
814 //--------------------------------------------------------------
815 nbvtx = NbVertex();
816 do {
817 APointDeleted = Standard_False;
818 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
819 const IntPatch_Point& VTXi = svtx.Value(i);
820 if((VTXi.IsOnDomS1()==Standard_True) && (VTXi.IsOnDomS2()==Standard_False)) {
821 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
822 if(i!=j) {
823 const IntPatch_Point& VTXj = svtx.Value(j);
824 if((VTXj.IsOnDomS1()==Standard_True) && (VTXj.IsOnDomS2()==Standard_False)) {
825 if( (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()+1)
826 || (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()-1)) {
827 if(VTXi.ArcOnS1() == VTXj.ArcOnS1()) {
828 IntSurf_Transition t1 = VTXi.TransitionLineArc1();
829 IntSurf_Transition t2 = VTXj.TransitionLineArc1();
830 if(t1.TransitionType()==t2.TransitionType()) {
831 if((VTXj.ParameterOnLine()!=1) && (VTXj.ParameterOnLine()!=NbPnts())) {
832 svtx.Remove(j);
833 nbvtx--;
834 if(lapt) { if(indl>=j) indl--; }
835 if(fipt) { if(indf>=j) indf--; }
836 APointDeleted = Standard_True;
837 }
838 }
839 }
840 }
841 }
842 }
843 }
844 }
845 }
846 }
847
848 //-- meme traitement sur les restrictions du second shape
849
850 while(APointDeleted == Standard_True);
851 nbvtx = NbVertex();
852 do {
853 APointDeleted = Standard_False;
854 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
855 const IntPatch_Point& VTXi = svtx.Value(i);
856 if((VTXi.IsOnDomS1()==Standard_False) && (VTXi.IsOnDomS2()==Standard_True)) {
857 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
858 if(i!=j) {
859 const IntPatch_Point& VTXj = svtx.Value(j);
860 if((VTXj.IsOnDomS1()==Standard_False) && (VTXj.IsOnDomS2()==Standard_True)) {
861 if( (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()+1)
862 || (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()-1)) {
863 if(VTXi.ArcOnS2() == VTXj.ArcOnS2()) {
864 IntSurf_Transition t1 = VTXi.TransitionLineArc2();
865 IntSurf_Transition t2 = VTXj.TransitionLineArc2();
866 if(t1.TransitionType()==t2.TransitionType()) {
867 if((VTXj.ParameterOnLine()!=1) && (VTXj.ParameterOnLine()!=NbPnts())) {
868 svtx.Remove(j);
869 nbvtx--;
870 if(lapt) { if(indl>=j) indl--; }
871 if(fipt) { if(indf>=j) indf--; }
872 APointDeleted = Standard_True;
873 }
874 }
875 }
876 }
877 }
878 }
879 }
880 }
881 }
882 }
883 while(APointDeleted == Standard_True);
884 //--------------------------------------------------------------
885
886 //--------------------------------------------------------------
887 //-- dans le cas de lignes periodiques du type :
888 //-- Un point sur restriction R1 de param p1 -> P3d1 Vtx1
889 //-- Un point sur restriction R2 de param p2 -> P3d1 Vtx2
890 //--
891 //-- Un point sur restriction R1 de param p1 -> P3d1 Vtx3
892 //-- pas de point sur R2
893 //--
894 //-- On doit dans ce cas creer un nouveau Vtx4 = Vtx3 sur la
895 //-- restriction R2
896 //--
897 //-- Ce cas se produit qd on a corrige un baillement avec le filtre
898 //-- precedent
899 //--
900
901
902
903
904
905
906 nbvtx = NbVertex();
907 do {
908 SortIsOK = Standard_True;
909 for(i=2; i<=nbvtx; i++) {
910 if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) {
911 SortIsOK = Standard_False;
912 svtx.Exchange(i-1,i);
913 }
914 }
915 }
916 while(!SortIsOK);
917
918 //-- Dump();
919
920#if DEBUGV
921 cout<<"\n----------- apres ComputeVertexParameters -------------"<<endl;
922 for(i=1;i<=nbvtx;i++) {
923 Vertex(i).Dump();
924 Standard_Real polr = Vertex(i).ParameterOnLine();
925 Standard_Real pol = (Standard_Integer)polr;
926 if(pol>=1 && pol<=nbvtx) {
927 cout<<"----> IntSurf_PntOn2S : "<<polr<<" Pnt ("<<Vertex(pol).Value().X()
928 <<","<<Vertex(pol).Value().Y()
929 <<","<<Vertex(pol).Value().Z()<<")"<<endl;
930 }
931 }
932 cout<<"\n----------------------------------------------------------"<<endl;
933#endif
934
935
936}
937
938
939
940Standard_Boolean IntPatch_WLine::IsOutSurf1Box(const gp_Pnt2d& P1uv) {
941 if(Buv1.IsWhole()) {
942 Standard_Integer n=NbPnts();
943 Standard_Real pu1,pu2,pv1,pv2;
944 Buv1.SetVoid();
945 for(Standard_Integer i=1;i<=n;i++) {
946 curv->Value(i).Parameters(pu1,pv1,pu2,pv2);
947 Buv1.Add(gp_Pnt2d(pu1,pv1));
948 }
949 Buv1.Get(pu1,pv1,pu2,pv2);
950 pu2-=pu1;
951 pv2-=pv1;
952 if(pu2>pv2) {
953 Buv1.Enlarge(pu2*0.01);
954 }
955 else {
956 Buv1.Enlarge(pv2*0.01);
957 }
958 }
959 Standard_Boolean out=Buv1.IsOut(P1uv);
960 return(out);
961}
962
963Standard_Boolean IntPatch_WLine::IsOutSurf2Box(const gp_Pnt2d& P2uv) {
964 if(Buv2.IsWhole()) {
965 Standard_Integer n=NbPnts();
966 Standard_Real pu1,pu2,pv1,pv2;
967 Buv2.SetVoid();
968 for(Standard_Integer i=1;i<=n;i++) {
969 curv->Value(i).Parameters(pu1,pv1,pu2,pv2);
970 Buv2.Add(gp_Pnt2d(pu2,pv2));
971 }
972 Buv2.Get(pu1,pv1,pu2,pv2);
973 pu2-=pu1;
974 pv2-=pv1;
975 if(pu2>pv2) {
976 Buv2.Enlarge(pu2*0.01);
977 }
978 else {
979 Buv2.Enlarge(pv2*0.01);
980 }
981 }
982 Standard_Boolean out=Buv2.IsOut(P2uv);
983 return(out);
984}
985
986Standard_Boolean IntPatch_WLine::IsOutBox(const gp_Pnt& Pxyz) {
987 if(Bxyz.IsWhole()) {
988 Standard_Integer n=NbPnts();
989 Bxyz.SetVoid();
990 for(Standard_Integer i=1;i<=n;i++) {
991 gp_Pnt P=curv->Value(i).Value();
992 Bxyz.Add(P);
993 }
994 Standard_Real x0,y0,z0,x1,y1,z1;
995 Bxyz.Get(x0,y0,z0,x1,y1,z1);
996 x1-=x0; y1-=y0; z1-=z0;
997 if(x1>y1) {
998 if(x1>z1) {
999 Bxyz.Enlarge(x1*0.01);
1000 }
1001 else {
1002 Bxyz.Enlarge(z1*0.01);
1003 }
1004 }
1005 else {
1006 if(y1>z1) {
1007 Bxyz.Enlarge(y1*0.01);
1008 }
1009 else {
1010 Bxyz.Enlarge(z1*0.01);
1011 }
1012 }
1013 }
1014 Standard_Boolean out=Bxyz.IsOut(Pxyz);
1015 return(out);
1016}
1017
1018
1019Standard_Boolean IntPatch_WLine::HasArcOnS1() const {
1020 return(hasArcOnS1);
1021}
1022
1023void IntPatch_WLine::SetArcOnS1(const Handle(Adaptor2d_HCurve2d)& A) {
1024 hasArcOnS1=Standard_True;
1025 theArcOnS1=A;
1026}
1027
1028const Handle(Adaptor2d_HCurve2d)& IntPatch_WLine::GetArcOnS1() const {
1029 return(theArcOnS1);
1030}
1031
1032Standard_Boolean IntPatch_WLine::HasArcOnS2() const {
1033 return(hasArcOnS2);
1034}
1035
1036void IntPatch_WLine::SetArcOnS2(const Handle(Adaptor2d_HCurve2d)& A) {
1037 hasArcOnS2=Standard_True;
1038 theArcOnS2=A;
1039}
1040
1041const Handle(Adaptor2d_HCurve2d)& IntPatch_WLine::GetArcOnS2() const {
1042 return(theArcOnS2);
1043}
1044
1045
1046void IntPatch_WLine::Dump() const {
1047
1048 cout<<" ----------- D u m p I n t P a t c h _ W L i n e --------------"<<endl;
1049 Standard_Integer i;
1050 Standard_Integer nbp = NbPnts();
1051 printf("Num [X Y Z] [U1 V1] [U2 V2]\n");
1052// for(Standard_Integer i=1;i<=nbp;i++) {
1053 for(i=1;i<=nbp;i++) {
1054 Standard_Real u1,v1,u2,v2;
1055 Point(i).Parameters(u1,v1,u2,v2);
1056 printf("%4d [%+5.8e %+5.8e %+5.8e] [%+5.8e %+5.8e] [%+5.8e %+5.8e]\n",
1057 i,
1058 Point(i).Value().X(),
1059 Point(i).Value().Y(),
1060 Point(i).Value().Z(),
1061 u1,v1,u2,v2);
1062
1063
1064 //cout<<"IntSurf_PntOn2S : "<<i<<" Pnt ("<<curv->Value(i).Value().X()
1065 // <<","<<curv->Value(i).Value().Y()
1066 // <<","<<curv->Value(i).Value().Z()<<")"<<endl;
1067 //cout<<" : u1("<<u1<<") v1("<<v1<<") u2("<<u2<<") v2("<<v2<<")"<<endl;
1068 }
1069 nbp = NbVertex();
1070 for(i=1;i<=nbp;i++) {
1071 Vertex(i).Dump();
1072 Standard_Real polr = Vertex(i).ParameterOnLine();
1073 Standard_Integer pol = (Standard_Integer)polr;
1074 if(pol>=1 && pol<=nbp) {
1075 cout<<"----> IntSurf_PntOn2S : "<<polr<<" Pnt ("<<Vertex(pol).Value().X()
1076 <<","<<Vertex(pol).Value().Y()
1077 <<","<<Vertex(pol).Value().Z()<<")"<<endl;
1078 }
1079 }
1080 cout<<"\n----------------------------------------------------------"<<endl;
1081}
1082