summaryrefslogtreecommitdiff
path: root/src/BRepFill/BRepFill_Pipe.cxx
blob: 25b8debf0eb625b9065eed252d96b2ccbe048234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
// File:	BRepFill_Pipe.cxx
// Created:	Tue Jun  7 16:31:15 1994
// Author:	Bruno DUMORTIER
//		<dub@fuegox>

#include <BRepFill_Pipe.ixx>

#include <Standard_ErrorHandler.hxx>

#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <BRepLib_MakeVertex.hxx>

#include <GeomFill_CorrectedFrenet.hxx>
#include <GeomFill_CurveAndTrihedron.hxx>

#include <BRepFill_SectionPlacement.hxx>
#include <BRepFill_ShapeLaw.hxx>
#include <BRepFill_Edge3DLaw.hxx>
#include <BRepFill_Sweep.hxx>

#include <GeomAbs_Shape.hxx>
#include <TopExp.hxx>
#include <TopAbs_ShapeEnum.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shell.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Iterator.hxx>

#include <Precision.hxx>
#include <Standard_NotImplemented.hxx>

#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <Geom_BSplineCurve.hxx>

#ifdef DRAW
#include <DBRep.hxx>
static Standard_Boolean Affich = 0;
#endif

//=======================================================================
//function : BRepFill_Pipe
//purpose  : 
//=======================================================================

BRepFill_Pipe::BRepFill_Pipe()
{
  myDegmax = 10;
  mySegmax = 100;
}


//=======================================================================
//function : BRepFill_Pipe
//purpose  : 
//=======================================================================

BRepFill_Pipe::BRepFill_Pipe(const TopoDS_Wire&  Spine,
			     const TopoDS_Shape& Profile,
			     const Standard_Boolean KPart)
{
  myDegmax = 10;
  mySegmax = 100;
  Perform(Spine, Profile, KPart);
}



//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================

void BRepFill_Pipe::Perform(const TopoDS_Wire&  Spine,
			    const TopoDS_Shape& Profile,
			    const Standard_Boolean KPart)

{
  mySections.Nullify();
  myFaces.Nullify();
  myEdges.Nullify();

  mySpine   = Spine;
  myProfile = Profile;

  DefineRealSegmax();

  BRepTools_WireExplorer wexp;
  TopoDS_Shape TheProf; 


 Handle(GeomFill_CorrectedFrenet) TLaw = 
   new (GeomFill_CorrectedFrenet) ();
  Handle(GeomFill_CurveAndTrihedron) Loc = 
    new (GeomFill_CurveAndTrihedron) (TLaw);
  myLoc = new (BRepFill_Edge3DLaw) (mySpine, Loc);
  if (myLoc->NbLaw() == 0) {
    return; // Cas degenere
  }
  myLoc->TransformInG0Law(); // Mise en continuite
    
  BRepFill_SectionPlacement Place(myLoc, Profile);
  myTrsf = Place.Transformation();

  TopLoc_Location Loc2(myTrsf), Loc1;
  Loc1 = Profile.Location();
  TopoDS_Shape aux;
  TheProf =  myProfile;
  TheProf.Location(Loc2.Multiplied(Loc1));
 
  // Construit les Shape First && Last
  Handle(GeomFill_LocationLaw) law;

  gp_Mat M;
  gp_Vec V;
  gp_Trsf fila;
  Standard_Real first, last;
  myLoc->Law(1)->GetDomain(first, last);
  myLoc->Law(1)->D0(first, M, V);
    fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
		   M(2,1), M(2,2), M(2,3), V.Y(),
		   M(3,1), M(3,2), M(3,3), V.Z(),
		   1.e-12, 1.e-14);

  fila.Multiply(myTrsf);
  TopLoc_Location LocFirst(fila);
  myFirst = myProfile;
  if ( ! LocFirst.IsIdentity()) {
    myFirst.Location( LocFirst.Multiplied(myProfile.Location()) );
  }

  myLoc->Law(myLoc->NbLaw())->GetDomain(first, last);
  myLoc->Law(myLoc->NbLaw())->D0(last,M, V);
//    try { // Pas joli mais il n'y as pas d'autre moyens de tester SetValues
  fila.SetValues(M(1,1), M(1,2), M(1,3), V.X(),
		 M(2,1), M(2,2), M(2,3), V.Y(),
		 M(3,1), M(3,2), M(3,3), V.Z(),
		 1.e-12, 1.e-14);
  fila.Multiply(myTrsf);
  TopLoc_Location LocLast(fila);
  if (! myLoc->IsClosed() || LocFirst != LocLast) {
    myLast = myProfile;
    if ( ! LocLast.IsIdentity()) {
      myLast.Location(LocLast.Multiplied(myProfile.Location()) );
    }
  }
  else {
    myLast = myFirst;
  }
#if DRAW
  if (Affich) {
    DBRep::Set("theprof",  TheProf);
    DBRep::Set("thefirst", myFirst);
    DBRep::Set("thelast" , myLast);
 }
#endif
 
  myShape = MakeShape(TheProf, myFirst, myLast);
}


//=======================================================================
//function : Spine
//purpose  : 
//=======================================================================

const TopoDS_Shape& BRepFill_Pipe::Spine() const 
{
  return mySpine;
}

//=======================================================================
//function : Profile
//purpose  : 
//=======================================================================

const TopoDS_Shape& BRepFill_Pipe::Profile() const 
{
  return myProfile;
}

//=======================================================================
//function : Shape
//purpose  : 
//=======================================================================

const TopoDS_Shape& BRepFill_Pipe::Shape() const 
{
  return myShape;
}


//=======================================================================
//function : FirstShape
//purpose  : 
//=======================================================================

const TopoDS_Shape& BRepFill_Pipe::FirstShape() const 
{
  return myFirst;
}


//=======================================================================
//function : LastShape
//purpose  : 
//=======================================================================

const TopoDS_Shape& BRepFill_Pipe::LastShape() const 
{
  return myLast;
}


//=======================================================================
//function : Face
//purpose  : 
//=======================================================================

TopoDS_Face BRepFill_Pipe::Face(const TopoDS_Edge& ESpine,
				const TopoDS_Edge& EProfile)
{
  TopoDS_Face theFace;

  if ( BRep_Tool::Degenerated(EProfile))
    return theFace;

  Standard_Integer ii, ispin = 0, iprof = 0, count = 0;

  // *************************************************
  // Search if EProfile is an edge of myProfile
  // *************************************************
  iprof = FindEdge(myProfile, EProfile, count);

  if (!iprof) Standard_DomainError::Raise(
              "BRepFill_Pipe::Face : Edge not in the Profile");


  // *************************************************
  // Search if ESpine  is an edge of mySpine and find 
  // the index of the corresponding Filler
  // *************************************************
 for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++) 
    if  (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;

  if (!ispin) Standard_DomainError::Raise(
    "BRepFill_Pipe::Edge  : Edge not in the Spine");

  theFace = TopoDS::Face(myFaces->Value(iprof, ispin));
  return theFace;

}

//=======================================================================
//function : Edge
//purpose  : 
//=======================================================================
TopoDS_Edge BRepFill_Pipe::Edge(const TopoDS_Edge&   ESpine,
				const TopoDS_Vertex& VProfile)
{
  Standard_Integer ii, ispin = 0, iprof = 0, count = 0;;

  // *************************************************
  // Search if VProfile is a Vertex of myProfile
  // *************************************************
  iprof = FindVertex(myProfile, VProfile, count);
  if (!iprof) Standard_DomainError::Raise(
	"BRepFill_Pipe::Edge : Vertex not in the Profile");


  // *************************************************
  // Search if ESpine  is an edge of mySpine and find 
  // the index of the corresponding Filler
  // *************************************************
   
  for (ii=1; ii<=myLoc->NbLaw() && (!ispin); ii++) 
    if  (ESpine.IsSame(myLoc->Edge(ii))) ispin = ii;

  if (!ispin) Standard_DomainError::Raise(
    "BRepFill_Pipe::Edge  : Edge not in the Spine");


  // *************************************************
  // Generate the corresponding Shape
  // *************************************************  
  TopoDS_Edge theEdge;
  theEdge = TopoDS::Edge(myEdges->Value(iprof, ispin));

  return theEdge;

}


//=======================================================================
//function : Section
//purpose  : 
//=======================================================================

TopoDS_Shape BRepFill_Pipe::Section(const TopoDS_Vertex& VSpine) const 
{
  TopoDS_Iterator it, itv;

  Standard_Integer ii, ispin = 0;

  TopoDS_Shape curSect = myProfile;

  // *************************************************
  // Search if ESpine  is an edge of mySpine and find 
  // the index of the corresponding Filler
  // *************************************************

  // iterate on all the edges of mySpine
 for (ii=1; ii<=myLoc->NbLaw()+1 && (!ispin); ii++) 
    if  (VSpine.IsSame(myLoc->Vertex(ii))) ispin = ii;

  if (!ispin) Standard_DomainError::Raise(
    "BRepFill_Pipe::Section  : Vertex not in the Spine");

  BRep_Builder B;
  TopoDS_Compound Comp; 
  B.MakeCompound(Comp);
  for (ii=1; ii<=mySections->ColLength(); ii++)
    B.Add(Comp, mySections->Value(ii, ispin));
  
  return Comp;
}

//=======================================================================
//function : PipeLine
//purpose  : Construit un wire par balayage d'un point
//=======================================================================

TopoDS_Wire BRepFill_Pipe::PipeLine(const gp_Pnt& Point) const
{
 // Postionnement
 gp_Pnt P;
 P = Point;
 P.Transform(myTrsf);

 BRepLib_MakeVertex MkV(P); 
 Handle(BRepFill_ShapeLaw) Section = 
	new (BRepFill_ShapeLaw) (MkV.Vertex());

 // Balayage
 BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
 MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
 TopoDS_Shape aLocalShape = MkSw.Shape();
 return TopoDS::Wire(aLocalShape);
// return TopoDS::Wire(MkSw.Shape());
}

//=======================================================================
//function : MakeShape
//purpose  : 
//=======================================================================

TopoDS_Shape BRepFill_Pipe::MakeShape(const TopoDS_Shape& S,
				      const TopoDS_Shape& FirstShape,
				      const TopoDS_Shape& LastShape)
{
  TopoDS_Shape result;
  BRep_Builder B;
  Standard_Boolean explode = Standard_False; 
  TopoDS_Shape TheS, TheFirst, TheLast;
  Standard_Integer InitialLength = 0;
  TheS = S;
  TheFirst = FirstShape;
  TheLast = LastShape;
  if (! myFaces.IsNull()) InitialLength = myFaces->ColLength();

  // there are two kinds of generation
  //  1. generate with S from each Filler (Vertex, Edge)
  //  2. call MakeShape recursively on the subshapes of S
  //
  // explode is True in the second case

  // create the result empty

  switch (S.ShapeType()) {

  case TopAbs_VERTEX :
    {
      B.MakeWire(TopoDS::Wire(result));
      break;
    }
	  
  case TopAbs_EDGE :
    {
      TopoDS_Wire W;
      B.MakeShell(TopoDS::Shell(result));
      B.MakeWire(W);
      B.Add(W, S);
      W.Closed(S.Closed());
      TheS = W;
      if (!FirstShape.IsNull()) {
	B.MakeWire(W);
	B.Add(W, FirstShape);
	W.Closed(FirstShape.Closed());
	TheFirst = W;
      }
      if (!LastShape.IsNull()) {
	B.MakeWire(W);
	B.Add(W, LastShape);
	W.Closed(LastShape.Closed());
	TheLast = W;
      }
      break;
    }
	  
  case TopAbs_WIRE :
    B.MakeShell(TopoDS::Shell(result));
    break;

  case TopAbs_FACE :
    {
      B.MakeShell(TopoDS::Shell(result));
      explode = Standard_True;
      if ( !mySpine.Closed() && !TheFirst.IsNull()) {
	 B.Add(result, TheFirst.Reversed());
      }
      break;
    }

  case TopAbs_SHELL :
    {
      B.MakeCompSolid(TopoDS::CompSolid(result));
      explode = Standard_True;
      break;
    }

  case TopAbs_SOLID :
  case TopAbs_COMPSOLID :
    Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
    break;

  case TopAbs_COMPOUND :
    {
      B.MakeCompound(TopoDS::Compound(result));
      explode = Standard_True;
      break;
    }
#ifndef DEB
  default:
    break;
#endif    
  }

  if (explode) {
    // add the subshapes
    TopoDS_Iterator itFirst, itLast;
    TopoDS_Shape first, last;
    if (!TheFirst.IsNull()) itFirst.Initialize(TheFirst);
    if (!TheLast.IsNull()) itLast.Initialize(TheLast);

    for (TopoDS_Iterator it(S); it.More(); it.Next()) {
      if (!TheFirst.IsNull()) first = itFirst.Value();
      if (!TheLast.IsNull())  last = itLast.Value();
      if (TheS.ShapeType() == TopAbs_FACE ) 
	MakeShape(it.Value(), first, last);
      else
	B.Add(result,MakeShape(it.Value(), first, last));

      if (!TheFirst.IsNull()) itFirst.Next();
      if (!TheLast.IsNull())  itLast.Next();
    }
  }
  
  else {
    if (TheS.ShapeType() == TopAbs_VERTEX ) {
     Handle(BRepFill_ShapeLaw) Section = 
	new (BRepFill_ShapeLaw) (TopoDS::Vertex(TheS));
      BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
      MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
      result = MkSw.Shape();
    }

    if (TheS.ShapeType() == TopAbs_WIRE ) {
      Handle(BRepFill_ShapeLaw) Section = 
	new (BRepFill_ShapeLaw) (TopoDS::Wire(TheS));
      BRepFill_Sweep MkSw(Section, myLoc, Standard_True);
      MkSw.SetBounds(TopoDS::Wire(TheFirst), 
		     TopoDS::Wire(TheLast));
      MkSw.Build( BRepFill_Modified, GeomFill_Location, GeomAbs_C2, myDegmax, mySegmax );
      result = MkSw.Shape();

      // Reperage des elements
      if (mySections.IsNull()) {
	myFaces    = MkSw.SubShape();
	mySections = MkSw.Sections();
	myEdges    = MkSw.InterFaces();
      }
      else {
	Handle(TopTools_HArray2OfShape) Aux, Somme;
	Standard_Integer length;
        Standard_Integer ii, jj, kk;

	Aux = MkSw.SubShape();
	length = Aux->ColLength() + myFaces->ColLength(); 
	Somme = new (TopTools_HArray2OfShape) (1, length, 1, 
					       Aux->RowLength());
	for (jj=1; jj<=myFaces->RowLength(); jj++) {
	  for (ii=1; ii<=myFaces->ColLength(); ii++)
	    Somme->SetValue(ii, jj, myFaces->Value(ii, jj));
 
	  for (kk=1, ii=myFaces->ColLength()+1; 
	       kk <=Aux->ColLength(); kk++, ii++)
	    Somme->SetValue(ii, jj, Aux->Value(kk, jj));
	}
	myFaces = Somme;    
       

	Aux = MkSw.Sections();
	length = Aux->ColLength() + mySections->ColLength(); 
	Somme = new (TopTools_HArray2OfShape) (1, length, 1, 
					       Aux->RowLength());
	for (jj=1; jj<=mySections->RowLength(); jj++) {
	  for (ii=1; ii<=mySections->ColLength(); ii++)
	    Somme->SetValue(ii, jj, mySections->Value(ii, jj));
 
	  for (kk=1, ii=mySections->ColLength()+1; 
	       kk <=Aux->ColLength(); kk++, ii++)
	    Somme->SetValue(ii, jj, Aux->Value(kk, jj));   
	}
	mySections = Somme;

	Aux = MkSw.InterFaces();
	length = Aux->ColLength() + myEdges->ColLength(); 
	Somme = new (TopTools_HArray2OfShape) (1, length, 1, 
					       Aux->RowLength());
	for (jj=1; jj<=myEdges->RowLength(); jj++) {
	  for (ii=1; ii<=myEdges->ColLength(); ii++)
	    Somme->SetValue(ii, jj, myEdges->Value(ii, jj));
 
	  for (kk=1, ii=myEdges->ColLength()+1; 
	       kk <=Aux->ColLength(); kk++, ii++)
	    Somme->SetValue(ii, jj, Aux->Value(kk, jj));   
	}
	myEdges = Somme;	       
      }
    }
  }
      
  if ( TheS.ShapeType() == TopAbs_FACE ) {
    Standard_Integer ii, jj;
    TopoDS_Face F;
    for (ii=InitialLength+1; ii<=myFaces->ColLength(); ii++) {
      for (jj=1; jj<=myFaces->RowLength(); jj++) {
	F = TopoDS::Face(myFaces->Value(ii, jj));
	if (!F.IsNull()) B.Add(result, F);
      }
    }

    if ( !mySpine.Closed()) {
      // if Spine is not closed 
      // add the last face of the solid
      B.Add(result, TopoDS::Face(TheLast));
    }

    TopoDS_Solid solid;
    BRep_Builder BS;
    BS.MakeSolid(solid);

    result.Closed(Standard_True);
    BS.Add(solid,TopoDS::Shell(result));

    BRepClass3d_SolidClassifier SC(solid);
    SC.PerformInfinitePoint(Precision::Confusion());
    if ( SC.State() == TopAbs_IN) {
      BS.MakeSolid(solid);
      TopoDS_Shape aLocalShape = result.Reversed();
      BS.Add(solid,TopoDS::Shell(aLocalShape));
//      BS.Add(solid,TopoDS::Shell(result.Reversed()));
    }
    return solid;
  }
  else {
    
  }
  return result;
}

//=======================================================================
//function : FindEdge
//purpose  : Recherche le numero de bande correspondant a une edge du
//           profil.
//=======================================================================

Standard_Integer BRepFill_Pipe::FindEdge(const TopoDS_Shape& S,
					 const TopoDS_Edge& E,
					 Standard_Integer& InitialLength) const
{
  Standard_Integer result = 0;

  switch (S.ShapeType()) {
	  
  case TopAbs_EDGE :
    {
      InitialLength++;
      if (S.IsSame(E)) result = InitialLength;
      break;
    }
	  
  case TopAbs_WIRE :
    {
      Standard_Integer ii = InitialLength+1;
      Handle(BRepFill_ShapeLaw) Section = 
	new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
      InitialLength += Section->NbLaw();
     
      for (; (ii<=InitialLength) && (!result); ii++) {
	if (E.IsSame(Section->Edge(ii)) ) result = ii;
      }
      break;
    }

  case TopAbs_FACE :
  case TopAbs_SHELL :
  case TopAbs_COMPOUND :
    {
     for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
       result = FindEdge(it.Value(), E, InitialLength );
     break;
    }

  case TopAbs_SOLID :
  case TopAbs_COMPSOLID :
    Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
    break;
#ifndef DEB
  default:
    break;
#endif
  }

  return result; 
}

//=======================================================================
//function : FindVertex
//purpose  : Recherche le numero de bande correspondant a une edge du
//           profil.
//=======================================================================

Standard_Integer BRepFill_Pipe::FindVertex(const TopoDS_Shape& S,
					   const TopoDS_Vertex& V,
					   Standard_Integer& InitialLength) const
{
  Standard_Integer result = 0;

  switch (S.ShapeType()) {
  case TopAbs_VERTEX :
    {
      InitialLength++;
      if (S.IsSame(V)) result = InitialLength;
      break;
    }
	  
  case TopAbs_EDGE :
    {
      TopoDS_Vertex VF, VL;
      TopExp::Vertices(TopoDS::Edge(S), VF, VL);
      if (S.Orientation() == TopAbs_REVERSED) {
	TopoDS_Vertex aux;
	aux = VF; VF = VL; VL = aux;
      }
      if (VF.IsSame(V)) result = InitialLength+1;
      else if (VL.IsSame(V)) result = InitialLength+2;
      InitialLength += 2;
      break;
    }
	  
  case TopAbs_WIRE :
    {
      Standard_Integer ii = InitialLength+1;
      Handle(BRepFill_ShapeLaw) Section = 
	new (BRepFill_ShapeLaw) (TopoDS::Wire(S), Standard_False);
      InitialLength += Section->NbLaw()+1;
     
      for (; (ii<=InitialLength) && (!result); ii++) {
	if (V.IsSame(Section->Vertex(ii, 0.)) ) result = ii;
      }
      break;
    }

  case TopAbs_FACE :
  case TopAbs_SHELL :
  case TopAbs_COMPOUND :
    {
     for (TopoDS_Iterator it(S); it.More() && (!result); it.Next())
       result = FindVertex(it.Value(), V, InitialLength);
     break;
    }

  case TopAbs_SOLID :
  case TopAbs_COMPSOLID :
    Standard_DomainError::Raise("BRepFill_Pipe::SOLID or COMPSOLID");
    break;
#ifndef DEB
  default:
    break;
#endif
  }

  return result; 
}

//=======================================================================
//function : DefineRealSegmax
//purpose  : Defines the real number of segments
//           required in the case of bspline spine
//=======================================================================

void BRepFill_Pipe::DefineRealSegmax()
{
  Standard_Integer RealSegmax = 0;

  TopoDS_Iterator iter(mySpine);
  for (; iter.More(); iter.Next())
    {
      TopoDS_Edge E = TopoDS::Edge(iter.Value());
      Standard_Real first, last;
      Handle(Geom_Curve) C = BRep_Tool::Curve( E, first, last );
      if (C.IsNull())
	continue;
      while (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve) ||
	     C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
	{
	  if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
	    C = (*((Handle(Geom_TrimmedCurve)*)&C))->BasisCurve();
	  if (C->DynamicType() == STANDARD_TYPE(Geom_OffsetCurve))
	    C = (*((Handle(Geom_OffsetCurve)*)&C))->BasisCurve();
	}
      if (C->DynamicType() == STANDARD_TYPE(Geom_BSplineCurve))
	{
	  const Handle(Geom_BSplineCurve)& BC = *((Handle(Geom_BSplineCurve)*)&C);
	  Standard_Integer NbKnots = BC->NbKnots();
	  Standard_Integer RealNbKnots = NbKnots;
	  if (first > BC->FirstParameter())
	    {
	      Standard_Integer I1, I2;
	      BC->LocateU( first, Precision::PConfusion(), I1, I2 );
	      RealNbKnots -= I1-1;
	    }
	  if (last < BC->LastParameter())
	    {
	      Standard_Integer I1, I2;
	      BC->LocateU( last, Precision::PConfusion(), I1, I2 );
	      RealNbKnots -= NbKnots-I2;
	    }
	  RealSegmax += RealNbKnots-1;
	}
    }

  if (mySegmax < RealSegmax)
    mySegmax = RealSegmax;
}