summaryrefslogtreecommitdiff
path: root/src/IntTools/IntTools_FClass2d.cxx
blob: 8f4b02fa6c1311c8424bff4eda48d5186c0723e8 (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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
// File:	IntTools_FClass2d.cxx
// Created:	Wed Mar 22 09:44:18 1995
// Author:	Laurent BUCHARD
//		<lbr@mastox>

#include <IntTools_FClass2d.ixx>

#include <stdio.h>

#include <Precision.hxx>
#include <gp_Pnt.hxx>
#include <ElCLib.hxx>

#include <Geom2dInt_Geom2dCurveTool.hxx>
#include <GeomAbs_SurfaceType.hxx>

#include <BRep_Tool.hxx>
#include <BRepTools_WireExplorer.hxx>
#include <BRepClass_FaceClassifier.hxx>
#include <CSLib_Class2d.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Curve2d.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopExp.hxx>
#include <TopAbs_Orientation.hxx>
#include <TopExp_Explorer.hxx>
#include <TColgp_SequenceOfPnt2d.hxx>

#include <TColgp_Array1OfPnt2d.hxx>
#include <TopoDS_Wire.hxx>
#include <TColStd_DataMapOfIntegerInteger.hxx>
#include <TColgp_SequenceOfVec2d.hxx>

//=======================================================================
//function : IntTools_FClass2d:IntTools:_FClass2d
//purpose  : 
//=======================================================================
  IntTools_FClass2d::IntTools_FClass2d()
{
}
//=======================================================================
//function : IntTools_FClass2d::IntTools_FClass2d
//purpose  : 
//=======================================================================
  IntTools_FClass2d::IntTools_FClass2d(const TopoDS_Face& aFace,
				       const Standard_Real TolUV) 
: Toluv(TolUV), Face(aFace)  
{
  Init(Face, Toluv);
}
//=======================================================================
//function : IsHole
//purpose  : 
//=======================================================================
  Standard_Boolean IntTools_FClass2d::IsHole() const
{
  return myIsHole;
} 
//=======================================================================
//function : Init
//purpose  : 
//=======================================================================
  void IntTools_FClass2d::Init(const TopoDS_Face& aFace,
			       const Standard_Real TolUV) 
{
  Standard_Boolean WireIsNotEmpty, Ancienpnt3dinitialise, degenerated;
  Standard_Integer nbpnts, firstpoint, NbEdges;
  Standard_Integer iX, aNbs1, nbs, Avant, BadWire;
  Standard_Real u, du, Tole, Tol, pfbid, plbid;
  Standard_Real FlecheU, FlecheV, TolVertex1, TolVertex;
  Standard_Real uFirst, uLast;
  Standard_Real aPrCf, aPrCf2;
  //
  TopoDS_Edge  edge;
  TopoDS_Vertex Va,Vb;
  TopAbs_Orientation Or;
  BRepTools_WireExplorer aWExp;
  TopExp_Explorer aExpF, aExp;
  Handle(Geom2d_Curve) aC2D;
  gp_Pnt Ancienpnt3d;
  TColgp_SequenceOfPnt2d SeqPnt2d;
  TColStd_DataMapOfIntegerInteger anIndexMap;
  TColgp_SequenceOfVec2d          aD1Prev;
  TColgp_SequenceOfVec2d          aD1Next;
  //
  aPrCf=Precision::Confusion();
  aPrCf2=aPrCf*aPrCf;
  myIsHole=Standard_True;
  //
  Toluv=TolUV;
  Face=aFace;
  Face.Orientation(TopAbs_FORWARD);
  Handle(BRepAdaptor_HSurface) surf = new BRepAdaptor_HSurface();
  surf->ChangeSurface().Initialize(aFace, Standard_False);
  //
  Tole = 0.;
  Tol=0.;
  Umin = Vmin = RealLast();
  Umax = Vmax = -Umin;
  BadWire=0;
  //
  //if face has several wires and one of them is bad,
  //it is necessary to process all of them for correct
  //calculation of Umin, Umax, Vmin, Vmax - ifv, 23.08.06 
  //
  aExpF.Init(Face,TopAbs_WIRE); 
  for(; aExpF.More();  aExpF.Next()) {
    const TopoDS_Wire& aW=*((TopoDS_Wire*)&aExpF.Current());
    //
    nbpnts = 0;
    firstpoint =1;
    FlecheU = 0.;
    FlecheV = 0.;
    TolVertex1=0.;
    TolVertex=0.;
    WireIsNotEmpty = Standard_False;
    Ancienpnt3dinitialise=Standard_False;
    Ancienpnt3d.SetCoord(0.,0.,0.);
    //
    SeqPnt2d.Clear();
    anIndexMap.Clear();
    aD1Prev.Clear();
    aD1Next.Clear();
    //
    // NbEdges
    NbEdges=0;
    aExp.Init(aW, TopAbs_EDGE);
    for(; aExp.More(); aExp.Next()) { 
      NbEdges++;
    }
    //
    aWExp.Init(aW, Face);
    for(;aWExp.More(); aWExp.Next()) {
      NbEdges--;
      edge = aWExp.Current();
      Or = edge.Orientation();
      if(!(Or==TopAbs_FORWARD || Or==TopAbs_REVERSED)) {
	continue;
      }
      //
      aC2D=BRep_Tool::CurveOnSurface(edge, Face, pfbid, plbid);
      if (aC2D.IsNull()) {
	return;
      }
      //
      BRepAdaptor_Curve2d C(edge,Face);
      BRepAdaptor_Curve C3d;
      //------------------------------------------
      degenerated=Standard_False;
      if(BRep_Tool::Degenerated(edge) ||
	 BRep_Tool::IsClosed(edge, Face)) {
	degenerated=Standard_True;
      }
      //
      TopExp::Vertices(edge,Va,Vb);
      //
      TolVertex1=0.;
      TolVertex=0.;
      if (Va.IsNull()) {
	degenerated=Standard_True;
      }	
      else {
	TolVertex1=BRep_Tool::Tolerance(Va);
      }
      if (Vb.IsNull()){
	degenerated=Standard_True;
      }	
      else {
	TolVertex=BRep_Tool::Tolerance(Vb);
      }
	// 
      if(TolVertex<TolVertex1) {
	TolVertex=TolVertex1;
      }	
      //
      //-- Verification of cases when forgotten to code degenereted
      if(!degenerated) {
	Standard_Real aR2;
	gp_Pnt P3da, P3db;
	//
	C3d.Initialize(edge,Face);
	du=(plbid-pfbid)*0.1;
	u=pfbid+du;
	P3da=C3d.Value(u);
	degenerated=Standard_True;
	u+=du;
	do { 
	  P3db=C3d.Value(u);
	  aR2=P3da.SquareDistance(P3db);
	  if(aR2>0.) { 
	    degenerated=Standard_False;
	    break;
	  }
	  u+=du;
	}
	while(u<plbid);
      }//if(!degenerated)
      //-- ----------------------------------------
      Tole = BRep_Tool::Tolerance(edge);
      if(Tole>Tol) {
	Tol=Tole;
      }
      //
      // NbSamples +> nbs
      nbs = Geom2dInt_Geom2dCurveTool::NbSamples(C);
      if (nbs > 2) {
	nbs*=4;
      }
      du = (plbid-pfbid)/(Standard_Real)(nbs-1);
      //
      if(Or==TopAbs_FORWARD) { 
	u = pfbid;
	uFirst=pfbid;
	uLast=plbid;
      }
      else { 
	u = plbid;
	uFirst=plbid;
	uLast=pfbid;
	du=-du;
      }
      //
      // aPrms
      aNbs1=nbs+1;
      TColStd_Array1OfReal aPrms(1, aNbs1);
      //
      if (nbs==2) {
	Standard_Real aCoef=0.0025;
	aPrms(1)=uFirst;
	aPrms(2)=uFirst+aCoef*(uLast-uFirst);
	aPrms(3)=uLast;
      }
      else if (nbs>2) {
	aNbs1=nbs;
	aPrms(1)=uFirst;
	for (iX=2; iX<aNbs1; ++iX) {
	  aPrms(iX)=u+(iX-1)*du;
	}
	aPrms(aNbs1)=uLast;
      }
      //
      //-- ------------------------------------------------------------
      //-- Check distance uv between the start point of the edge
      //-- and the last point saved in SeqPnt2d
      //-- To to set the first point of the current 
      //-- afar from the last saved point
      Avant = nbpnts;
      for(iX=firstpoint; iX<=aNbs1; iX++) {
	Standard_Boolean IsRealCurve3d;
	Standard_Integer ii;
	Standard_Real aDstX;
	gp_Pnt2d P2d;
	gp_Pnt P3d;
	//
	u=aPrms(iX);
	P2d = C.Value(u);
	if(P2d.X()<Umin) Umin = P2d.X();
	if(P2d.X()>Umax) Umax = P2d.X();
	if(P2d.Y()<Vmin) Vmin = P2d.Y();
	if(P2d.Y()>Vmax) Vmax = P2d.Y();
	//
	aDstX=RealLast();	
	if(degenerated==Standard_False) { 
	  P3d=C3d.Value(u);
	  if(nbpnts>1) {
	    if(Ancienpnt3dinitialise) { 
	      aDstX=P3d.SquareDistance(Ancienpnt3d);
	    }
	  }
	}
	//
	IsRealCurve3d = Standard_True; 
	if (aDstX < aPrCf2)  {
	  if(iX>1) {
	    Standard_Real aDstX1;
	    gp_Pnt MidP3d;
	    //
	    MidP3d = C3d.Value(0.5*(u+aPrms(iX-1)));
	    aDstX1=P3d.SquareDistance( MidP3d );
	    if (aDstX1 < aPrCf2){
	      IsRealCurve3d = Standard_False;
	    }
	  }
	}
	//
	if (IsRealCurve3d) {
	  if(degenerated==Standard_False) { 
	    Ancienpnt3d=P3d;
	    Ancienpnt3dinitialise=Standard_True;
	  }
	  nbpnts++;
	  SeqPnt2d.Append(P2d);
	}
	//
	ii=nbpnts;
	if(ii>(Avant+4)) { 
	  Standard_Real ul, dU, dV;
	  gp_Pnt2d Pp;
	  //
	  gp_Lin2d Lin(SeqPnt2d(ii-2),gp_Dir2d(gp_Vec2d(SeqPnt2d(ii-2),SeqPnt2d(ii))));
	  ul = ElCLib::Parameter(Lin,SeqPnt2d(ii-1));
	  Pp = ElCLib::Value(ul,Lin);
	  dU = Abs(Pp.X()-SeqPnt2d(ii-1).X());
	  dV = Abs(Pp.Y()-SeqPnt2d(ii-1).Y());
	  if(dU>FlecheU) {
	    FlecheU = dU;
	  }
	  if(dV>FlecheV) {
	    FlecheV = dV;
	  }
	}
      }// for(iX=firstpoint; iX<=aNbs1; iX++) {
      //
      if(BadWire) {
	continue; //if face has several wires and one of them is bad,
	          //it is necessary to process all of them for correct
	          //calculation of Umin, Umax, Vmin, Vmax - ifv, 23.08.06 
      }
      //
      if(firstpoint==1) firstpoint=2;
      WireIsNotEmpty = Standard_True;
      // Append the derivative of the first parameter.
      Standard_Real aU = aPrms(1);
      gp_Pnt2d      aP;
      gp_Vec2d      aV;

      C.D1(aU, aP, aV);

      if(Or == TopAbs_REVERSED)
	aV.Reverse();

      aD1Next.Append(aV);

      // Append the derivative of the last parameter.
      aU = aPrms(aNbs1);
      C.D1(aU, aP, aV);

      if(Or == TopAbs_REVERSED)
	aV.Reverse();

      if (NbEdges > 0)
	aD1Prev.Append(aV);
      else
	aD1Prev.Prepend(aV);

      // Fill the map anIndexMap.
      if (Avant > 0)
	anIndexMap.Bind(Avant, aD1Next.Length());
      else
	anIndexMap.Bind(1, aD1Next.Length());
    } //for(;aWExp.More(); aWExp.Next()) {
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    //
    if(NbEdges) { 
      //-- count ++ with normal explorer and -- with Wire Explorer
      TColgp_Array1OfPnt2d PClass(1,2);
      gp_Pnt2d anInitPnt(0., 0.);
      //
      PClass.Init(anInitPnt);
      TabClass.Append((void *)new CSLib_Class2d(PClass,FlecheU,FlecheV,Umin,Vmin,Umax,Vmax));
      BadWire=1;
      TabOrien.Append(-1);
    }
    //
    else if(WireIsNotEmpty) { 
      TColgp_Array1OfPnt2d PClass(1,nbpnts);
      gp_Pnt2d anInitPnt(0., 0.);
      //
      PClass.Init(anInitPnt);
      if(nbpnts>3) { 
	Standard_Integer im2=nbpnts-2;
	Standard_Integer im1=nbpnts-1;
	Standard_Integer im0=1;
	Standard_Integer ii;
	Standard_Real    angle = 0.0;
	Standard_Real aX0, aY0, aX1, aY1, aS;
	//
	aS=0.;
	//

	Standard_Integer iFlag=1;
	PClass(im2)=SeqPnt2d.Value(im2);
	PClass(im1)=SeqPnt2d.Value(im1);
	PClass(nbpnts)=SeqPnt2d.Value(nbpnts);
	for(ii=1; ii<nbpnts; ii++,im0++,im1++,im2++) { 
	  if(im2>=nbpnts) im2=1;
	  if(im1>=nbpnts) im1=1;
	  PClass(ii)=SeqPnt2d.Value(ii);
	  //
	  const gp_Pnt2d& aP2D1=PClass(im1);
	  const gp_Pnt2d& aP2D0=PClass(im0);
	  //aP2D0 is next to aP2D1
	  aP2D0.Coord(aX0, aY0);
	  aP2D1.Coord(aX1, aY1);
	  aS=aS+(aY0+aY1)*(aX1-aX0); 

	  gp_Vec2d A(PClass(im2),PClass(im1));
	  gp_Vec2d B(PClass(im1),PClass(im0));

	  Standard_Real N = A.Magnitude() * B.Magnitude();
	  if(N>1e-16) { 
	    Standard_Real a=A.Angle(B);
	    //  
	    if (anIndexMap.IsBound(im1)) {
	      Standard_Integer  anInd  = anIndexMap.Find(im1);
	      const gp_Vec2d   &aVPrev = aD1Prev.Value(anInd);
	      const gp_Vec2d   &aVNext = aD1Next.Value(anInd);

	      Standard_Real aN = aVPrev.Magnitude() * aVNext.Magnitude();
	      if(aN > 1e-16) { 
		Standard_Real aDerivAngle = aVPrev.Angle(aVNext);
		//ifv 23.08.06
		if(Abs(aDerivAngle) <= Precision::Angular()) aDerivAngle = 0.; 
		//ifv 23.08.06 : if edges continuity > G1, |aDerivAngle| ~0,
		//but can has wrong sign and causes condition aDerivAngle * a < 0.
		//that is wrong in such situation
		if (iFlag && aDerivAngle * a < 0.) {
		  iFlag=0;
		  // Bad case.
		  angle = 0.;
		}
	      }
	    }
	    angle+=a;
	  }
	}//for(ii=1; ii<nbpnts; ii++,im0++,im1++,im2++) { 
	if (!iFlag) {
	  angle = 0.; 
	}
	if(aS>0.){
	  myIsHole=Standard_False;
	}
	//
	if(FlecheU<Toluv)
	  FlecheU = Toluv;

	if(FlecheV<Toluv)
	  FlecheV = Toluv;

	TabClass.Append((void *)new CSLib_Class2d(PClass,FlecheU,FlecheV,Umin,Vmin,Umax,Vmax));
	//
	if((angle<2 && angle>-2)||(angle>10)||(angle<-10)) { 
	  BadWire=1;
	  TabOrien.Append(-1);
	} 
	else { 	
	  TabOrien.Append((angle>0.0)? 1 : 0);
	}
      } 
      else { 
	BadWire=1;
	TabOrien.Append(-1);
	TColgp_Array1OfPnt2d PPClass(1,2);
	PPClass.Init(anInitPnt);
	TabClass.Append((void *)new CSLib_Class2d(PPClass,FlecheU,FlecheV,Umin,Vmin,Umax,Vmax));
      }
    }// else if(WireIsNotEmpty)
  } // for(; aExpF.More();  aExpF.Next()) {
  //
  Standard_Integer nbtabclass = TabClass.Length();
  //
  if(nbtabclass>0) { 
    //-- if an error on a wire was detected : all TabOrien set to -1
    if(BadWire) {
      TabOrien(1)=-1;
    }
    
    if(   surf->GetType()==GeomAbs_Cone
       || surf->GetType()==GeomAbs_Cylinder
       || surf->GetType()==GeomAbs_Torus
       || surf->GetType()==GeomAbs_Sphere
       || surf->GetType()==GeomAbs_SurfaceOfRevolution) { 
      Standard_Real uuu=PI+PI-(Umax-Umin);
      if(uuu<0) uuu=0;
      U1 = Umin-uuu*0.5;
      U2 = U1+PI+PI;
    }
    else { 
      U1=U2=0.0; 
    } 
    
    if(surf->GetType()==GeomAbs_Torus) { 
      Standard_Real uuu=PI+PI-(Vmax-Vmin);
      if(uuu<0) uuu=0;
      
      V1 = Vmin-uuu*0.5;
      V2 = V1+PI+PI;
    }
    else { 
      V1=V2=0.0; 
    }   
  }
}
//=======================================================================
//function : PerformInfinitePoint
//purpose  : 
//=======================================================================
  TopAbs_State IntTools_FClass2d::PerformInfinitePoint() const 
{ 
  if(Umax==-RealLast() || Vmax==-RealLast() || Umin==RealLast() || Vmin==RealLast()) { 
    return(TopAbs_IN);
  }
  gp_Pnt2d P(Umin-(Umax-Umin),Vmin-(Vmax-Vmin));
  return(Perform(P,Standard_False));
}
//=======================================================================
//function : Perform
//purpose  : 
//=======================================================================
  TopAbs_State IntTools_FClass2d::Perform(const gp_Pnt2d& _Puv,
					  const Standard_Boolean RecadreOnPeriodic) const
{ 
  Standard_Integer dedans, nbtabclass;
  
  nbtabclass = TabClass.Length();
  
  if(nbtabclass==0) { 
    return(TopAbs_IN);
  }
  
  //-- U1 is the First Param and U2 is in this case U1+Period
  Standard_Real u, v, uu, vv,  uperiod, vperiod;
  Standard_Boolean IsUPer, IsVPer, urecadre, vrecadre;
  TopAbs_State Status= TopAbs_UNKNOWN;

  u=_Puv.X();
  v=_Puv.Y();
  uu = u, vv = v;

  Handle(BRepAdaptor_HSurface) surf = new BRepAdaptor_HSurface();
  surf->ChangeSurface().Initialize( Face, Standard_False );
  
  uperiod=0., vperiod=0.;
  IsUPer = surf->IsUPeriodic();
  IsVPer = surf->IsVPeriodic();

  if (IsUPer){ 
    uperiod = surf->UPeriod();
  }

  if (IsVPer){
    vperiod = surf->VPeriod();
  }
  
  urecadre = Standard_False;
  vrecadre = Standard_False;

  if (RecadreOnPeriodic) {
    
    if (IsUPer) {
      if (uu < Umin)
	while (uu < Umin) {
	  uu += uperiod;
	}
      else {
	while (uu >= Umin){
	  uu -= uperiod;
	}
	uu += uperiod;
      }
    }// if (IsUPer) {
    
    if (IsVPer) {
      if (vv < Vmin)
	while (vv < Vmin){
	  vv += vperiod;
	}
      else {
	while (vv >= Vmin) {
	  vv -= vperiod;
	}
	vv += vperiod;
      }
    }//if (IsVPer) {
  }

  while (1) {
    dedans = 1;
    gp_Pnt2d Puv(u,v);
      
    if(TabOrien(1)!=-1) {
      Standard_Integer n, cur, TabOrien_n ;
      for(n=1; n<=nbtabclass; n++) { 
	cur = ((CSLib_Class2d *)TabClass(n))->SiDans(Puv);
	TabOrien_n=TabOrien(n);

	if(cur==1) { 
	  if(TabOrien_n==0) { 
	    dedans = -1; 
	    break;
	  }
	}
	else if(cur==-1) { 
	  if(TabOrien_n==1) {  
	    dedans = -1; 
	    break;
	  }
	}
	else { 
	  dedans = 0;
	  break;
	}
      } // for(n=1; n<=nbtabclass; n++)

      if(dedans==0) { 
	BRepClass_FaceClassifier aClassifier;
	aClassifier.Perform(Face,Puv,Toluv);
	Status = aClassifier.State();
      }
      if(dedans == 1) { 
	Status = TopAbs_IN;
      }
      if(dedans == -1) {
	Status = TopAbs_OUT;
      }
    } // if(TabOrien(1)!=-1) {
    
    else {  //-- TabOrien(1)=-1   Wrong Wire
      BRepClass_FaceClassifier aClassifier;
      aClassifier.Perform(Face,Puv,Toluv);
      Status = aClassifier.State();
    }
    
    if (!RecadreOnPeriodic || (!IsUPer && !IsVPer))
      return Status;
    
    if (Status == TopAbs_IN || Status == TopAbs_ON)
      return Status;
    
    if (!urecadre){
      u = uu;
      urecadre = Standard_True;
    }
    else {
      if (IsUPer){
	u += uperiod;
      }
    }

    if (u > Umax || !IsUPer) {
      if (!vrecadre){
	v = vv;
	vrecadre = Standard_True;
      }
      else {
	if (IsVPer){
	  v += vperiod;
	}
      }

      u = uu;
      
      if (v > Vmax || !IsVPer) {
	return Status;
      }
    }
  } //while (1)
}

//=======================================================================
//function : TestOnRestriction
//purpose  : 
//=======================================================================
  TopAbs_State IntTools_FClass2d::TestOnRestriction(const gp_Pnt2d& _Puv,
						    const Standard_Real Tol,
						    const Standard_Boolean RecadreOnPeriodic) const
{ 

  Standard_Integer dedans, nbtabclass;
  
  nbtabclass = TabClass.Length();
  
  if(nbtabclass==0) { 
    return(TopAbs_IN);
  }
  
  //-- U1 is the First Param and U2 in this case is U1+Period
  Standard_Real u=_Puv.X();
  Standard_Real v=_Puv.Y();
  Standard_Real uu = u, vv = v;
  
  Handle(BRepAdaptor_HSurface) surf = new BRepAdaptor_HSurface();
  surf->ChangeSurface().Initialize( Face, Standard_False );
  Standard_Boolean IsUPer, IsVPer;
  Standard_Real uperiod=0, vperiod=0;
  if ((IsUPer = surf->IsUPeriodic()) == Standard_True)
    uperiod = surf->UPeriod();
  if ((IsVPer = surf->IsVPeriodic()) == Standard_True)
    vperiod = surf->VPeriod();
  TopAbs_State Status = TopAbs_UNKNOWN;
  Standard_Boolean urecadre = Standard_False, vrecadre = Standard_False;
  
  if (RecadreOnPeriodic)
    {
      if (IsUPer)
	{
	  if (uu < Umin)
	    while (uu < Umin)
	      uu += uperiod;
	  else
	    {
	      while (uu >= Umin)
		uu -= uperiod;
	      uu += uperiod;
	    }
	}
      if (IsVPer)
	{
	  if (vv < Vmin)
	    while (vv < Vmin)
	      vv += vperiod;
	  else
	    {
	      while (vv >= Vmin)
		vv -= vperiod;
	      vv += vperiod;
	    }
	}
    }
  
  for (;;) {
    dedans = 1;
    gp_Pnt2d Puv(u,v);
    
    if(TabOrien(1)!=-1) { 
      for(Standard_Integer n=1; n<=nbtabclass; n++) { 
	Standard_Integer cur = ((CSLib_Class2d *)TabClass(n))->SiDans_OnMode(Puv,Tol);
	if(cur==1) { 
	  if(TabOrien(n)==0) { 
	    dedans = -1; 
	    break;
	  }
	}
	else if(cur==-1) { 
	  if(TabOrien(n)==1) {  
	    dedans = -1; 
	    break;
	  }
	}
	else { 
	  dedans = 0;
	  break;
	}
      }
      if(dedans==0) {
	Status = TopAbs_ON;
      }
      if(dedans == 1) {
	Status = TopAbs_IN;
      }
      if(dedans == -1) {
	Status = TopAbs_OUT;
      }
    }
    else {  //-- TabOrien(1)=-1  Wrong  Wire 
      BRepClass_FaceClassifier aClassifier;
      aClassifier.Perform(Face,Puv,Tol);
      Status = aClassifier.State();
    }
    
    if (!RecadreOnPeriodic || (!IsUPer && !IsVPer))
      return Status;
    if (Status == TopAbs_IN || Status == TopAbs_ON)
      return Status;
    
    if (!urecadre)
      {
	u = uu;
	urecadre = Standard_True;
      }
    else
      if (IsUPer)
	u += uperiod;
    if (u > Umax || !IsUPer)
      {
	if (!vrecadre)
	  {
	    v = vv;
	    vrecadre = Standard_True;
	  }
	else
	  if (IsVPer)
	    v += vperiod;
	
	u = uu;
	
	if (v > Vmax || !IsVPer)
	  return Status;
      }
  } //for (;;)
}

//=======================================================================
//function : Destroy
//purpose  : 
//=======================================================================
  void IntTools_FClass2d::Destroy() 
{ 
  Standard_Integer nbtabclass = TabClass.Length(); 
  for(Standard_Integer d=1; d<=nbtabclass;d++) {
    if(TabClass(d)) { 
      delete ((CSLib_Class2d *)TabClass(d));
      TabClass(d)=NULL;
    }
  }
}