0023425: diffimage generate OSD_Exception during execution
[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 }
568
569 //--static int deb6nov98=1; Ne resout rien (a part partiellement BUC60409)
570 //--if(deb6nov98) {
571 //--Substitution=Standard_True;
572 //-- }
573
574 if(Substitution==Standard_False) {
575 //-------------------------------------------------------
576 //-- On insere le point de cheminement Vertex(i)
577 //-- On recadre les parametres des autres vertex
578 //-------------------------------------------------------
579 IntSurf_PntOn2S POn2S = svtx.Value(i).PntOn2S();
580 if(indicevertexonline >= nbponline) {
581 RecadreMemePeriode(POn2S,curv->Value(nbponline),U1Period(),V1Period(),U2Period(),V2Period());
582 curv->Add(POn2S);
583 }
584 else {
585 RecadreMemePeriode(POn2S,curv->Value(indicevertexonline+1),U1Period(),V1Period(),U2Period(),V2Period());
586 curv->InsertBefore(indicevertexonline+1,POn2S);
587 }
588 //-- curv->InsertBefore(indicevertexonline+1,svtx.Value(i).PntOn2S());
589 svtx.ChangeValue(i).SetParameter(indicevertexonline+1);
590 nbponline++;
591 for(j=1;j<=nbvtx;j++) {
592 if(j!=i) {
593 Standard_Real t = svtx.Value(j).ParameterOnLine();
594 if(t>(Standard_Real)indicevertexonline) {
595 svtx.ChangeValue(j).SetParameter(t+1.0);
596 }
597 }
598 }
599 } //-- Substitution
600 } //-- indicevertexonline>=1
601
602 } //-- boucle i sur vertex
603
604
605
606
607 do {
608 APointDeleted = Standard_False;
609 for(i=1; i<=nbvtx && (APointDeleted == Standard_False); i++) {
610 const IntPatch_Point& VTX = svtx.Value(i);
611 for(j=1; j<=nbvtx && (APointDeleted == Standard_False) ; j++) {
612 if(i!=j) {
613 const IntPatch_Point& VTXM1 = svtx.Value(j);
614
615 Standard_Boolean kill = Standard_False;
616 Standard_Boolean killm1 = Standard_False;
617 if(VTXM1.ParameterOnLine() == VTX.ParameterOnLine()) {
618 if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) { //-- OnS1 OnS1
619 if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS1 == OnS1
620 if(VTXM1.IsOnDomS2()) { //-- OnS1 == OnS1 OnS2
621 if(VTX.IsOnDomS2()==Standard_False) { //-- OnS1 == OnS1 OnS2 PasOnS2
622 kill=Standard_True;
623 }
624 else {
625 if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS1 == OnS1 OnS2 == OnS2
626 kill=Standard_True;
627 }
628 }
629 }
630 else { //-- OnS1 == OnS1 PasOnS2
631 if(VTX.IsOnDomS2()) { //-- OnS1 == OnS1 PasOnS2 OnS2
632 killm1=Standard_True;
633 }
634 }
635 }
636 }
637
638 if(!(kill || killm1)) {
639 if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()) { //-- OnS2 OnS2
640 if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS2 == OnS2
641 if(VTXM1.IsOnDomS1()) { //-- OnS2 == OnS2 OnS1
642 if(VTX.IsOnDomS1()==Standard_False) { //-- OnS2 == OnS2 OnS1 PasOnS1
643 kill=Standard_True;
644 }
645 else {
646 if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS2 == OnS2 OnS1 == OnS1
647 kill=Standard_True;
648 }
649 }
650 }
651 else { //-- OnS2 == OnS2 PasOnS1
652 if(VTX.IsOnDomS1()) { //-- OnS2 == OnS2 PasOnS1 OnS1
653 killm1=Standard_True;
654 }
655 }
656 }
657 }
658 }
659 if(kill) {
660 APointDeleted = Standard_True;
661 svtx.Remove(i);
662 nbvtx--;
663 }
664 else if(killm1) {
665 APointDeleted = Standard_True;
666 svtx.Remove(j);
667 nbvtx--;
668 }
669 }
670 }
671 }
672 }
673 }
674 while(APointDeleted == Standard_True);
675
676 do {
677 SortIsOK = Standard_True;
678 for(i=2; i<=nbvtx && SortIsOK; i++) {
679 const IntPatch_Point& Pim1=svtx.Value(i-1);
680 const IntPatch_Point& Pii =svtx.Value(i);
681 if(Pim1.ParameterOnLine()==Pii.ParameterOnLine()) {
682 if( (Pii.IsOnDomS1() == Standard_False)
683 && (Pii.IsOnDomS2() == Standard_False)) {
684 SortIsOK = Standard_False;
685 svtx.Remove(i);
686 nbvtx--;
687 }
688 else {
689 if( (Pim1.IsOnDomS1() == Standard_False)
690 && (Pim1.IsOnDomS2() == Standard_False)) {
691 SortIsOK = Standard_False;
692 svtx.Remove(i-1);
693 nbvtx--;
694 }
695 }
696 }
697 }
698 }
699 while(!SortIsOK);
700 //-- ----------------------------------------------------------------------------
701 //-- On ajoute les vertex de debut et de fin de ligne s il ne sont pas presents.
702 //--
703 //-- Existe t il un vertex de debut de ligne, de fin .
704 //--
705 //-- Si Besoin : il faudra dedoubler les points de debut et de fin sur les periodiques ??????
706
707
708
709
710 Standard_Boolean bFirst = Standard_False;
711 Standard_Boolean bLast = Standard_False;
712 nbponline = NbPnts();
713 for(i=1;i<=nbvtx;i++) {
714 Standard_Real pol = svtx.Value(i).ParameterOnLine();
715 if(pol==1.0) {
716 bFirst = fipt = Standard_True;
717 indf = i;
718 }
719 if(pol==nbponline) {
720 bLast = lapt = Standard_True;
721 indl = i;
722 }
723 }
724 if(bFirst == Standard_False) {
725 Standard_Real pu1,pv1,pu2,pv2;
726 Standard_Boolean vtxfound = Standard_False;
727 IntPatch_Point vtx;
728 curv->Value(1).Parameters(pu1,pv1,pu2,pv2);
729 for(i=1;
730 (vtxfound==Standard_False) && (i<=nbvtx);i++) {
731 const IntPatch_Point& V = svtx.Value(i);
732 Standard_Real vTol = V.Tolerance();
733 if(CompareVertexAndPoint(V.Value(),curv->Value(1).Value(),vTol)) {
734 vtx = V;
735 vtx.SetParameters(pu1,pv1,pu2,pv2);
736 vtxfound = Standard_True;
737 }
738 }
739 if(vtxfound == Standard_False) {
740 vtx.SetValue(curv->Value(1).Value(),Tol,Standard_False);
741 vtx.SetParameters(pu1,pv1,pu2,pv2);
742 }
743 vtx.SetParameter(1);
744 svtx.Prepend(vtx); nbvtx++;
745 fipt = Standard_True;
746 indf = 1;
747 }
748 if(bLast == Standard_False) {
749 Standard_Real pu1,pv1,pu2,pv2;
750 Standard_Boolean vtxfound = Standard_False;
751 IntPatch_Point vtx;
752 curv->Value(nbponline).Parameters(pu1,pv1,pu2,pv2);
753 for(i=1;
754 (vtxfound==Standard_False) && (i<=nbvtx);i++) {
755 const IntPatch_Point& V = svtx.Value(i);
756 Standard_Real vTol = V.Tolerance();
757 if(CompareVertexAndPoint(V.Value(),curv->Value(nbponline).Value(),vTol)) {
758 vtx = V;
759 vtx.SetParameters(pu1,pv1,pu2,pv2);
760 vtxfound = Standard_True;
761 }
762 }
763 if(vtxfound == Standard_False) {
764 vtx.SetValue(curv->Value(nbponline).Value(),Tol,Standard_False);
765 vtx.SetParameters(pu1,pv1,pu2,pv2);
766 }
767 vtx.SetParameter(nbponline);
768 svtx.Append(vtx); nbvtx++;
769 lapt = Standard_True;
770 indl = nbvtx;
771 }
772
773
774
775
776 //--------------------------------------------------------------
777 //-- ** Detection de points trouves sur une meme restriction
778 //-- avec la meme transition et avec des params on line
779 //-- voisins.
780 //-- ** Dans ce cas (-> donnerait un baillemenmt) on supprime
781 //-- le point 'intermediaire'.
782 //-- ** (exemple Vtx(1) ..... Vtx(204) Vtx(205))
783 //-- on supprime le Vtx(204)
784 //-- ** (exemple Vtx(1) Vtx(2) ..... Vtx(205))
785 //-- on supprime le Vtx(2)
786 //-- ** (exemple Vtx(1) ... Vtx(100) Vtx(101) ... Vtx(205))
787 //-- on supprime le Vtx(100) (Vtx(100)et101 sur m restr)
788
789 //--------------------------------------------------------------
790 nbvtx = NbVertex();
791 do {
792 APointDeleted = Standard_False;
793 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
794 const IntPatch_Point& VTXi = svtx.Value(i);
795 if((VTXi.IsOnDomS1()==Standard_True) && (VTXi.IsOnDomS2()==Standard_False)) {
796 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
797 if(i!=j) {
798 const IntPatch_Point& VTXj = svtx.Value(j);
799 if((VTXj.IsOnDomS1()==Standard_True) && (VTXj.IsOnDomS2()==Standard_False)) {
800 if( (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()+1)
801 || (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()-1)) {
802 if(VTXi.ArcOnS1() == VTXj.ArcOnS1()) {
803 IntSurf_Transition t1 = VTXi.TransitionLineArc1();
804 IntSurf_Transition t2 = VTXj.TransitionLineArc1();
805 if(t1.TransitionType()==t2.TransitionType()) {
806 if((VTXj.ParameterOnLine()!=1) && (VTXj.ParameterOnLine()!=NbPnts())) {
807 svtx.Remove(j);
808 nbvtx--;
809 if(lapt) { if(indl>=j) indl--; }
810 if(fipt) { if(indf>=j) indf--; }
811 APointDeleted = Standard_True;
812 }
813 }
814 }
815 }
816 }
817 }
818 }
819 }
820 }
821 }
822
823 //-- meme traitement sur les restrictions du second shape
824
825 while(APointDeleted == Standard_True);
826 nbvtx = NbVertex();
827 do {
828 APointDeleted = Standard_False;
829 for(i=1; (i<=nbvtx) && (APointDeleted==Standard_False) ;i++) {
830 const IntPatch_Point& VTXi = svtx.Value(i);
831 if((VTXi.IsOnDomS1()==Standard_False) && (VTXi.IsOnDomS2()==Standard_True)) {
832 for(j=1; (j<=nbvtx) && (APointDeleted==Standard_False) ;j++) {
833 if(i!=j) {
834 const IntPatch_Point& VTXj = svtx.Value(j);
835 if((VTXj.IsOnDomS1()==Standard_False) && (VTXj.IsOnDomS2()==Standard_True)) {
836 if( (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()+1)
837 || (VTXi.ParameterOnLine() == VTXj.ParameterOnLine()-1)) {
838 if(VTXi.ArcOnS2() == VTXj.ArcOnS2()) {
839 IntSurf_Transition t1 = VTXi.TransitionLineArc2();
840 IntSurf_Transition t2 = VTXj.TransitionLineArc2();
841 if(t1.TransitionType()==t2.TransitionType()) {
842 if((VTXj.ParameterOnLine()!=1) && (VTXj.ParameterOnLine()!=NbPnts())) {
843 svtx.Remove(j);
844 nbvtx--;
845 if(lapt) { if(indl>=j) indl--; }
846 if(fipt) { if(indf>=j) indf--; }
847 APointDeleted = Standard_True;
848 }
849 }
850 }
851 }
852 }
853 }
854 }
855 }
856 }
857 }
858 while(APointDeleted == Standard_True);
859 //--------------------------------------------------------------
860
861 //--------------------------------------------------------------
862 //-- dans le cas de lignes periodiques du type :
863 //-- Un point sur restriction R1 de param p1 -> P3d1 Vtx1
864 //-- Un point sur restriction R2 de param p2 -> P3d1 Vtx2
865 //--
866 //-- Un point sur restriction R1 de param p1 -> P3d1 Vtx3
867 //-- pas de point sur R2
868 //--
869 //-- On doit dans ce cas creer un nouveau Vtx4 = Vtx3 sur la
870 //-- restriction R2
871 //--
872 //-- Ce cas se produit qd on a corrige un baillement avec le filtre
873 //-- precedent
874 //--
875
876
877
878
879
880
881 nbvtx = NbVertex();
882 do {
883 SortIsOK = Standard_True;
884 for(i=2; i<=nbvtx; i++) {
885 if(svtx.Value(i-1).ParameterOnLine() > svtx.Value(i).ParameterOnLine()) {
886 SortIsOK = Standard_False;
887 svtx.Exchange(i-1,i);
888 }
889 }
890 }
891 while(!SortIsOK);
892
893 //-- Dump();
894
895#if DEBUGV
896 cout<<"\n----------- apres ComputeVertexParameters -------------"<<endl;
897 for(i=1;i<=nbvtx;i++) {
898 Vertex(i).Dump();
899 Standard_Real polr = Vertex(i).ParameterOnLine();
900 Standard_Real pol = (Standard_Integer)polr;
901 if(pol>=1 && pol<=nbvtx) {
902 cout<<"----> IntSurf_PntOn2S : "<<polr<<" Pnt ("<<Vertex(pol).Value().X()
903 <<","<<Vertex(pol).Value().Y()
904 <<","<<Vertex(pol).Value().Z()<<")"<<endl;
905 }
906 }
907 cout<<"\n----------------------------------------------------------"<<endl;
908#endif
909
910
911}
912
913
914
915Standard_Boolean IntPatch_WLine::IsOutSurf1Box(const gp_Pnt2d& P1uv) {
916 if(Buv1.IsWhole()) {
917 Standard_Integer n=NbPnts();
918 Standard_Real pu1,pu2,pv1,pv2;
919 Buv1.SetVoid();
920 for(Standard_Integer i=1;i<=n;i++) {
921 curv->Value(i).Parameters(pu1,pv1,pu2,pv2);
922 Buv1.Add(gp_Pnt2d(pu1,pv1));
923 }
924 Buv1.Get(pu1,pv1,pu2,pv2);
925 pu2-=pu1;
926 pv2-=pv1;
927 if(pu2>pv2) {
928 Buv1.Enlarge(pu2*0.01);
929 }
930 else {
931 Buv1.Enlarge(pv2*0.01);
932 }
933 }
934 Standard_Boolean out=Buv1.IsOut(P1uv);
935 return(out);
936}
937
938Standard_Boolean IntPatch_WLine::IsOutSurf2Box(const gp_Pnt2d& P2uv) {
939 if(Buv2.IsWhole()) {
940 Standard_Integer n=NbPnts();
941 Standard_Real pu1,pu2,pv1,pv2;
942 Buv2.SetVoid();
943 for(Standard_Integer i=1;i<=n;i++) {
944 curv->Value(i).Parameters(pu1,pv1,pu2,pv2);
945 Buv2.Add(gp_Pnt2d(pu2,pv2));
946 }
947 Buv2.Get(pu1,pv1,pu2,pv2);
948 pu2-=pu1;
949 pv2-=pv1;
950 if(pu2>pv2) {
951 Buv2.Enlarge(pu2*0.01);
952 }
953 else {
954 Buv2.Enlarge(pv2*0.01);
955 }
956 }
957 Standard_Boolean out=Buv2.IsOut(P2uv);
958 return(out);
959}
960
961Standard_Boolean IntPatch_WLine::IsOutBox(const gp_Pnt& Pxyz) {
962 if(Bxyz.IsWhole()) {
963 Standard_Integer n=NbPnts();
964 Bxyz.SetVoid();
965 for(Standard_Integer i=1;i<=n;i++) {
966 gp_Pnt P=curv->Value(i).Value();
967 Bxyz.Add(P);
968 }
969 Standard_Real x0,y0,z0,x1,y1,z1;
970 Bxyz.Get(x0,y0,z0,x1,y1,z1);
971 x1-=x0; y1-=y0; z1-=z0;
972 if(x1>y1) {
973 if(x1>z1) {
974 Bxyz.Enlarge(x1*0.01);
975 }
976 else {
977 Bxyz.Enlarge(z1*0.01);
978 }
979 }
980 else {
981 if(y1>z1) {
982 Bxyz.Enlarge(y1*0.01);
983 }
984 else {
985 Bxyz.Enlarge(z1*0.01);
986 }
987 }
988 }
989 Standard_Boolean out=Bxyz.IsOut(Pxyz);
990 return(out);
991}
992
993
994Standard_Boolean IntPatch_WLine::HasArcOnS1() const {
995 return(hasArcOnS1);
996}
997
998void IntPatch_WLine::SetArcOnS1(const Handle(Adaptor2d_HCurve2d)& A) {
999 hasArcOnS1=Standard_True;
1000 theArcOnS1=A;
1001}
1002
1003const Handle(Adaptor2d_HCurve2d)& IntPatch_WLine::GetArcOnS1() const {
1004 return(theArcOnS1);
1005}
1006
1007Standard_Boolean IntPatch_WLine::HasArcOnS2() const {
1008 return(hasArcOnS2);
1009}
1010
1011void IntPatch_WLine::SetArcOnS2(const Handle(Adaptor2d_HCurve2d)& A) {
1012 hasArcOnS2=Standard_True;
1013 theArcOnS2=A;
1014}
1015
1016const Handle(Adaptor2d_HCurve2d)& IntPatch_WLine::GetArcOnS2() const {
1017 return(theArcOnS2);
1018}
1019
1020
1021void IntPatch_WLine::Dump() const {
1022
1023 cout<<" ----------- D u m p I n t P a t c h _ W L i n e --------------"<<endl;
1024 Standard_Integer i;
1025 Standard_Integer nbp = NbPnts();
1026 printf("Num [X Y Z] [U1 V1] [U2 V2]\n");
1027// for(Standard_Integer i=1;i<=nbp;i++) {
1028 for(i=1;i<=nbp;i++) {
1029 Standard_Real u1,v1,u2,v2;
1030 Point(i).Parameters(u1,v1,u2,v2);
1031 printf("%4d [%+5.8e %+5.8e %+5.8e] [%+5.8e %+5.8e] [%+5.8e %+5.8e]\n",
1032 i,
1033 Point(i).Value().X(),
1034 Point(i).Value().Y(),
1035 Point(i).Value().Z(),
1036 u1,v1,u2,v2);
1037
1038
1039 //cout<<"IntSurf_PntOn2S : "<<i<<" Pnt ("<<curv->Value(i).Value().X()
1040 // <<","<<curv->Value(i).Value().Y()
1041 // <<","<<curv->Value(i).Value().Z()<<")"<<endl;
1042 //cout<<" : u1("<<u1<<") v1("<<v1<<") u2("<<u2<<") v2("<<v2<<")"<<endl;
1043 }
1044 nbp = NbVertex();
1045 for(i=1;i<=nbp;i++) {
1046 Vertex(i).Dump();
1047 Standard_Real polr = Vertex(i).ParameterOnLine();
1048 Standard_Integer pol = (Standard_Integer)polr;
1049 if(pol>=1 && pol<=nbp) {
1050 cout<<"----> IntSurf_PntOn2S : "<<polr<<" Pnt ("<<Vertex(pol).Value().X()
1051 <<","<<Vertex(pol).Value().Y()
1052 <<","<<Vertex(pol).Value().Z()<<")"<<endl;
1053 }
1054 }
1055 cout<<"\n----------------------------------------------------------"<<endl;
1056}
1057