0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_ShapeClassifier.cxx
CommitLineData
7fd59977 1// File: TopOpeBRepTool_ShapeClassifier.cxx
2// Created: Tue Feb 1 18:18:54 1994
3// Author: Jean Yves LEBEY
4// <jyl@phobox>
5
6#include <TopOpeBRepTool_ShapeClassifier.ixx>
7#include <BRepClass_FaceClassifier.hxx>
8#include <BRepTopAdaptor_FClass2d.hxx>
9#include <BRep_Tool.hxx>
10#include <TopoDS.hxx>
11#include <TopExp.hxx>
12#include <TopExp_Explorer.hxx>
13#include <Geom_Curve.hxx>
14#include <Geom2d_Curve.hxx>
15#include <gp_Vec2d.hxx>
16#include <Precision.hxx>
17#include <Standard_ProgramError.hxx>
18#include <BRepClass_FacePassiveClassifier.hxx>
19#include <BRepClass3d_SolidExplorer.hxx>
20#include <BRepClass_Edge.hxx>
21#include <BRepAdaptor_Curve2d.hxx>
22#include <BRepAdaptor_Surface.hxx>
23#include <TopOpeBRepTool_CurveTool.hxx>
24#include <TopOpeBRepTool_define.hxx>
25#include <TopOpeBRepTool_2d.hxx>
26
27//=======================================================================
28//function : TopOpeBRepTool_ShapeClassifier
29//purpose :
30//=======================================================================
31
32TopOpeBRepTool_ShapeClassifier::TopOpeBRepTool_ShapeClassifier() :
33myP3Ddef(Standard_False),myP2Ddef(Standard_False)
34{
35}
36
37//=======================================================================
38//function : TopOpeBRepTool_ShapeClassifier
39//purpose :
40//=======================================================================
41
42TopOpeBRepTool_ShapeClassifier::TopOpeBRepTool_ShapeClassifier
43(const TopoDS_Shape& SRef) :myP3Ddef(Standard_False),myP2Ddef(Standard_False)
44{
45 myRef = SRef;
46}
47
48//=======================================================================
49//function : ClearAll
50//purpose :
51//=======================================================================
52
53void TopOpeBRepTool_ShapeClassifier::ClearAll()
54{
55 ClearCurrent();
56 mySolidClassifier.Clear();
57}
58
59//=======================================================================
60//function : ClearCurrent
61//purpose :
62//=======================================================================
63
64void TopOpeBRepTool_ShapeClassifier::ClearCurrent()
65{
66 mySameDomain = -1;
67 myS.Nullify();
68 myRef.Nullify();
69 myAvS.Nullify();
70 myMapAvS.Clear();
71 mymre.Clear();
72 mymren = 0;
73 mymredone = Standard_False;
74 myState = TopAbs_UNKNOWN;
75 myEdge.Nullify();
76 myFace.Nullify();
77 myP3Ddef = myP2Ddef = Standard_False;
78}
79
80//=======================================================================
81//function : SameDomain
82//purpose :
83//=======================================================================
84
85Standard_Integer TopOpeBRepTool_ShapeClassifier::SameDomain() const
86{
87 return mySameDomain;
88}
89
90//=======================================================================
91//function : SameDomain
92//purpose :
93//=======================================================================
94
95void TopOpeBRepTool_ShapeClassifier::SameDomain(const Standard_Integer sam)
96{
97 mySameDomain = sam;
98}
99
100//=======================================================================
101//function : SetReference
102//purpose :
103//=======================================================================
104
105void TopOpeBRepTool_ShapeClassifier::SetReference(const TopoDS_Shape& SRef)
106{
107 myRef = SRef;
108 MapRef();
109}
110
111//=======================================================================
112//function : MapRef
113//purpose :
114//=======================================================================
115
116void TopOpeBRepTool_ShapeClassifier::MapRef()
117{
118 mymre.Clear();
119 mymren = 0;
120 if (myRef.ShapeType() == TopAbs_FACE && mySameDomain == 1) {
121 TopExp::MapShapes(myRef,TopAbs_EDGE,mymre);
122 mymren = mymre.Extent();
123 if (mymren == 1) {
124 TopExp_Explorer x(myRef,TopAbs_EDGE);
125 const TopoDS_Edge& E = TopoDS::Edge(x.Current());
126 TopoDS_Vertex v1,v2;TopExp::Vertices(E,v1,v2);
127 if (v1.IsSame(v2)) mymren = 0;
128 }
129 }
130 mymredone = Standard_True;
131}
132
133//=======================================================================
134//function : StateShapeShape
135//purpose :
136//=======================================================================
137
138TopAbs_State TopOpeBRepTool_ShapeClassifier::StateShapeShape
139(const TopoDS_Shape& S,const TopoDS_Shape& SRef,const Standard_Integer samedomain)
140{
141 ClearCurrent();
142 mySameDomain = samedomain;
143 myS = S;
144 myAvS.Nullify();
145 myPAvLS = NULL;
146 myRef = SRef;
147 Perform();
148 return myState;
149}
150
151//=======================================================================
152//function : StateShapeShape
153//purpose :
154//=======================================================================
155
156TopAbs_State TopOpeBRepTool_ShapeClassifier::StateShapeShape
157(const TopoDS_Shape& S,const TopoDS_Shape& AvS,const TopoDS_Shape& SRef)
158{
159 ClearCurrent();
160 myS = S;
161 myAvS = AvS;
162 myPAvLS = NULL;
163 myRef = SRef;
164 Perform();
165 return myState;
166}
167
168//=======================================================================
169//function : StateShapeShape
170//purpose :
171//=======================================================================
172
173TopAbs_State TopOpeBRepTool_ShapeClassifier::StateShapeShape
174(const TopoDS_Shape& S, const TopTools_ListOfShape& AvLS,const TopoDS_Shape& SRef)
175{
176 ClearCurrent();
177 myS = S;
178 myAvS.Nullify();
179 myPAvLS = (TopTools_ListOfShape*)&AvLS;
180 myRef = SRef;
181 Perform();
182 return myState;
183}
184
185//=======================================================================
186//function : StateShapeReference
187//purpose :
188//=======================================================================
189
190TopAbs_State TopOpeBRepTool_ShapeClassifier::StateShapeReference
191(const TopoDS_Shape& S,const TopoDS_Shape& AvS)
192{
193 myS = S;
194 myAvS = AvS;
195 myPAvLS = NULL;
196 Perform();
197 return myState;
198}
199
200//=======================================================================
201//function : StateShapeReference
202//purpose :
203//=======================================================================
204
205TopAbs_State TopOpeBRepTool_ShapeClassifier::StateShapeReference
206(const TopoDS_Shape& S,const TopTools_ListOfShape& AvLS)
207{
208 myS = S;
209 myAvS.Nullify();
210 myPAvLS = (TopTools_ListOfShape*)&AvLS;
211 Perform();
212 return myState;
213}
214
215//=======================================================================
216//function : ChangeSolidClassifier
217//purpose :
218//=======================================================================
219
220TopOpeBRepTool_SolidClassifier& TopOpeBRepTool_ShapeClassifier::ChangeSolidClassifier()
221{
222 return mySolidClassifier;
223}
224
225//=======================================================================
226//function : FindEdge
227//purpose :
228//=======================================================================
229
230void TopOpeBRepTool_ShapeClassifier::FindEdge()
231{
232 myEdge.Nullify();
233 myFace.Nullify();
234
235 TopAbs_ShapeEnum t = myS.ShapeType();
236 if ( t < TopAbs_FACE ) { // compsolid .. shell
237 FindFace(myS);
238 FindEdge(myFace);
239 }
240 else {
241 FindEdge(myS);
242 }
243}
244
245//=======================================================================
246//function : FindEdge
247//purpose :
248//=======================================================================
249
250void TopOpeBRepTool_ShapeClassifier::FindEdge(const TopoDS_Shape& S)
251{
252 myEdge.Nullify();
253 Standard_Boolean isavls = HasAvLS();
254 Standard_Boolean isavs = (! myAvS.IsNull());
255 if (S.IsNull()) return;
256
257 TopAbs_ShapeEnum tS = S.ShapeType();
258 TopExp_Explorer eex;
259 if ( ! myFace.IsNull() ) eex.Init(myFace,TopAbs_EDGE);
260 else eex.Init(S,TopAbs_EDGE);
261
262 for(; eex.More(); eex.Next()) {
263 const TopoDS_Edge& E = TopoDS::Edge(eex.Current());
264 Standard_Boolean toavoid = Standard_False;
265 if ( isavls || isavs ) {
266 toavoid = toavoid || myMapAvS.Contains(E);
267 if (!myAvS.IsNull()) toavoid = toavoid || E.IsSame(myAvS);
268 }
269 else if ( BRep_Tool::Degenerated(E) ) toavoid = ( tS != TopAbs_EDGE );
270 if ( toavoid ) continue;
271 myEdge = E;
272 break;
273 }
274}
275
276//=======================================================================
277//function : FindFace
278//purpose :
279//=======================================================================
280
281void TopOpeBRepTool_ShapeClassifier::FindFace(const TopoDS_Shape& S)
282{
283 myFace.Nullify();
284 Standard_Boolean isavls = HasAvLS();
285 Standard_Boolean isavs = (! myAvS.IsNull());
286 TopExp_Explorer fex(S,TopAbs_FACE);
287 for (; fex.More(); fex.Next()) {
288 const TopoDS_Face& F = TopoDS::Face(fex.Current());
289 Standard_Boolean toavoid = Standard_False;
290 if ( isavls || isavs ) {
291 toavoid = toavoid || myMapAvS.Contains(F);
292 if (!myAvS.IsNull()) toavoid = toavoid || F.IsSame(myAvS);
293 }
294 if ( toavoid ) continue;
295 myFace = F;
296 break;
297 }
298}
299
300//=======================================================================
301//function : Perform
302//purpose :
303//=======================================================================
304
305void TopOpeBRepTool_ShapeClassifier::Perform()
306{
307 myState = TopAbs_UNKNOWN;
308 if (myS.IsNull()) return;
309 if (myRef.IsNull()) return;
310
311 if (!mymredone) {
312 MapRef();
313 }
314
315 if ( !myAvS.IsNull() ) {
316 // tAvS = FACE,EDGE --> map(AvS,EDGE)
317 // rejet des aretes de myAvS comme arete de classification
318 // (le rejet simple de myAvS est insuffisant (connexite))
319 myMapAvS.Clear();
320 TopAbs_ShapeEnum tAvS = myAvS.ShapeType();
321 if ( tAvS == TopAbs_FACE ) {
322 myMapAvS.Add(myAvS);
323 TopExp::MapShapes(myAvS,TopAbs_EDGE,myMapAvS);
324 }
325 else if ( tAvS == TopAbs_EDGE ) {
326 TopExp::MapShapes(myAvS,TopAbs_EDGE,myMapAvS);
327 }
328 }
329 else if ( HasAvLS() ) {
330 // tAvS = FACE,EDGE --> map(AvS,EDGE)
331 // rejet des aretes de myPAvLS comme arete de classification
332 // (le rejet simple de myPAvLS est insuffisant (connexite))
333 myMapAvS.Clear();
334 TopAbs_ShapeEnum tAvS = myPAvLS->First().ShapeType();
335 if ( tAvS == TopAbs_FACE ) {
336 TopTools_ListIteratorOfListOfShape it((*myPAvLS));
337 for (; it.More(); it.Next() ) {
338 const TopoDS_Shape& S = it.Value();
339 myMapAvS.Add(S);
340 TopExp::MapShapes(S,TopAbs_EDGE,myMapAvS);
341 }
342 }
343 else if ( tAvS == TopAbs_EDGE ) {
344 TopTools_ListIteratorOfListOfShape it((*myPAvLS));
345 for (; it.More(); it.Next() ) {
346 const TopoDS_Shape& S = it.Value();
347 TopExp::MapShapes(S,TopAbs_EDGE,myMapAvS);
348 }
349 }
350 }
351 else {
352 if ( myS.ShapeType() == TopAbs_FACE ) {
353 myP3Ddef = BRepClass3d_SolidExplorer::FindAPointInTheFace
354 (TopoDS::Face(myS),myP3D);
355 }
356 }
357
358 TopAbs_ShapeEnum tS = myS.ShapeType();
359 TopAbs_ShapeEnum tR = myRef.ShapeType();
360
361 if ( tS == TopAbs_VERTEX ) {
362 if ( tR <= TopAbs_SOLID ) {
363 gp_Pnt P3D = BRep_Tool::Pnt(TopoDS::Vertex(myS));
364 StateP3DReference(P3D);
365 }
366 }
367 else if ( tS == TopAbs_EDGE ) {
368 if ( tR == TopAbs_FACE || tR <= TopAbs_SOLID ) {
369 FindEdge();
370 StateEdgeReference();
371 }
372 }
373 else if ( tS == TopAbs_WIRE ) {
374 if ( tR == TopAbs_FACE || tR <= TopAbs_SOLID ) {
375 FindEdge();
376 StateEdgeReference();
377 }
378 }
379 else if ( tS == TopAbs_FACE ) {
380 if ( tR == TopAbs_FACE ) {
381 FindEdge();
382 if ( mySameDomain == 1 ) {
383 StateEdgeReference();
384 }
385 else {
386 if (!myP3Ddef) {
387 myP3Ddef = BRepClass3d_SolidExplorer::FindAPointInTheFace
388 (TopoDS::Face(myS),myP3D);
389 }
390 if (myP3Ddef) {
391 StateP3DReference(myP3D);
392 }
393 else {
394 myState = TopAbs_UNKNOWN;
395 Standard_ProgramError::Raise("TopOpeBRepTool_ShapeClassifier !P3Ddef");
396 }
397 }
398 }
399 else if ( tR <= TopAbs_SOLID ) {
400 FindEdge();
401 if (myP3Ddef) {
402 StateP3DReference(myP3D);
403 }
404 else {
405 StateEdgeReference();
406 }
407 }
408 }
409 else if ( tS == TopAbs_SHELL ) {
410 if ( tR <= TopAbs_SOLID ) {
411 FindEdge();
412 StateEdgeReference();
413 }
414 }
415 else if ( tS == TopAbs_SOLID ) {
416 if ( tR <= TopAbs_SOLID ) {
417 FindEdge();
418 StateEdgeReference();
419 }
420 }
421 else {
422 Standard_ProgramError::Raise("StateShapeShape : bad operands");
423 }
424
425 // take orientation of reference shape in account
426 TopAbs_Orientation oriRef = myRef.Orientation();
427 if (oriRef == TopAbs_EXTERNAL || oriRef == TopAbs_INTERNAL ) {
428 if (myState == TopAbs_IN) myState = TopAbs_OUT;
429 }
430
431}
432
433
434//=======================================================================
435//function : StateEdgeReference
436//purpose :
437//=======================================================================
438
439void TopOpeBRepTool_ShapeClassifier::StateEdgeReference()
440{
441 myState = TopAbs_UNKNOWN;
442
443 if(myEdge.IsNull())
444 return;
445 if(myRef.IsNull())
446 return;
447
448 Handle(Geom_Curve) C3D;
449 gp_Pnt P3D;
450 Standard_Real f3d,l3d;
451
452 Handle(Geom2d_Curve) C2D;
453 gp_Pnt2d P2D;
454 Standard_Real f2d,l2d,tol2d;
455
456 TopAbs_ShapeEnum tR = myRef.ShapeType();
457 // myEdge est une arete de myS, pas de myRef
458 if( tR == TopAbs_FACE )
459 {
460 const TopoDS_Face& F = TopoDS::Face(myRef);
461 if(mySameDomain)
462 {
463 Standard_Boolean trimCurve = Standard_True;
464 C2D = FC2D_CurveOnSurface(myEdge,F,f2d,l2d,tol2d,trimCurve);
465
466 if(C2D.IsNull())
467 Standard_ProgramError::Raise("StateShapeShape : no 2d curve");
468
469 Standard_Real t = 0.127956477;
470 Standard_Real p = (1-t)*f2d + t*l2d;
471 P2D = C2D->Value(p);
472
473#ifdef DEB
474 C3D = BRep_Tool::Curve(myEdge,f3d,l3d);
475 if(!C3D.IsNull())
476 P3D = C3D->Value(p);
477#endif
478 StateP2DReference(P2D);
479 return;
480 }
481 else
482 { // myEdge/myRef=face en 3d
483 C3D = BRep_Tool::Curve(myEdge,f3d,l3d);
484
485 if(C3D.IsNull())
486 Standard_ProgramError::Raise("StateShapeShape : no 3d curve");
487
488 Standard_Real t = 0.127956477;
489 Standard_Real p = (1-t)*f3d + t*l3d;
490 P3D = C3D->Value(p);
491 StateP3DReference(P3D);
492 return;
493 }
494 }
495 else if( tR <= TopAbs_SOLID )
496 {
497 Standard_Boolean degen = BRep_Tool::Degenerated(myEdge);
498 if( degen )
499 {
500 const TopoDS_Vertex& v = TopExp::FirstVertex(myEdge);
501 P3D = BRep_Tool::Pnt(v);
502 StateP3DReference(P3D);
503 return;
504 }
505 else
506 {
507 C3D = BRep_Tool::Curve(myEdge,f3d,l3d);
508
509 if (C3D.IsNull())
510 Standard_ProgramError::Raise("StateShapeShape : no 3d curve");
511
512 Standard_Real t = 0.127956477;
513 Standard_Real p = (1-t)*f3d + t*l3d;
514 P3D = C3D->Value(p);
515 StateP3DReference(P3D);
516 return;
517 }
518 }
519 else
520 Standard_ProgramError::Raise("StateShapeShape : bad operands");
521}
522
523
524//=======================================================================
525//function : StateP2DReference
526//purpose :
527//=======================================================================
528
529void TopOpeBRepTool_ShapeClassifier::StateP2DReference
530(const gp_Pnt2d& P2D)
531{
532 myState = TopAbs_UNKNOWN;
533 if (myRef.IsNull()) return;
534 TopAbs_ShapeEnum tR = myRef.ShapeType();
535
536 if ( tR == TopAbs_FACE ) {
537 if (mymren == 1) {
538 TopExp_Explorer x;
539 for(x.Init(myRef,TopAbs_EDGE);x.More();x.Next()) {
540// for(TopExp_Explorer x(myRef,TopAbs_EDGE);x.More();x.Next()) {
541 TopAbs_Orientation o = x.Current().Orientation();
542// if (o == TopAbs_EXTERNAL) myState == TopAbs_OUT;
543 if (o == TopAbs_EXTERNAL) myState = TopAbs_OUT;
544// else if (o == TopAbs_INTERNAL) myState == TopAbs_IN;
545 else if (o == TopAbs_INTERNAL) myState = TopAbs_IN;
546 else {
547#ifdef DEB
548 cout<<"StateP2DReference o<>E,I"<<endl;
549#endif
550 break;
551 }
552 }
553 }
554 else {
555 myP2D = P2D;
556 myP2Ddef = Standard_True;
557 TopoDS_Face F = TopoDS::Face(myRef);
558 F.Orientation(TopAbs_FORWARD);
7fd59977 559 Standard_Real TolClass = 1e-8;
560 BRepTopAdaptor_FClass2d FClass2d(F,TolClass);
561 myState = FClass2d.Perform(P2D);
562 }
563 }
564 else {
565 Standard_ProgramError::Raise("StateShapeShape : bad operands");
566 }
567}
568
569//=======================================================================
570//function : StateP3DReference
571//purpose :
572//=======================================================================
573
574void TopOpeBRepTool_ShapeClassifier::StateP3DReference(const gp_Pnt& P3D)
575{
576 myState = TopAbs_UNKNOWN;
577 if (myRef.IsNull()) return;
578 TopAbs_ShapeEnum tR = myRef.ShapeType();
579
580 if ( tR == TopAbs_SOLID ) {
581 myP3D = P3D;
582 myP3Ddef = Standard_True;
583 const TopoDS_Solid& SO = TopoDS::Solid(myRef);
584 Standard_Real tol3d = Precision::Confusion();
585 mySolidClassifier.Classify(SO,P3D,tol3d);
586 myState = mySolidClassifier.State();
587 }
588 else if ( tR < TopAbs_SOLID ) {
589 myP3D = P3D;
590 myP3Ddef = Standard_True;
591 TopExp_Explorer ex;
592 for (ex.Init(myRef,TopAbs_SOLID);ex.More();ex.Next()) {
593// for (TopExp_Explorer ex(myRef,TopAbs_SOLID);ex.More();ex.Next()) {
594 const TopoDS_Solid& SO = TopoDS::Solid(ex.Current());
595 Standard_Real tol3d = Precision::Confusion();
596 mySolidClassifier.Classify(SO,P3D,tol3d);
597 myState = mySolidClassifier.State();
598 if (myState == TopAbs_IN || myState == TopAbs_ON) {
599 break;
600 }
601 }
602 }
603 else {
604 Standard_ProgramError::Raise("StateShapeShape : bad operands");
605 }
606}
607
608//=======================================================================
609//function : State
610//purpose :
611//=======================================================================
612
613TopAbs_State TopOpeBRepTool_ShapeClassifier::State() const
614{
615 return myState;
616}
617
618//=======================================================================
619//function : P3D
620//purpose :
621//=======================================================================
622
623const gp_Pnt& TopOpeBRepTool_ShapeClassifier::P3D() const
624{
625 if (myP3Ddef) {
626 return myP3D;
627 }
628 Standard_ProgramError::Raise("ShapeClassifier::P3D undefined");
629 return myP3D;
630}
631
632//=======================================================================
633//function : P2D
634//purpose :
635//=======================================================================
636
637const gp_Pnt2d& TopOpeBRepTool_ShapeClassifier::P2D() const
638{
639 if (myP2Ddef) {
640 return myP2D;
641 }
642 Standard_ProgramError::Raise("ShapeClassifier::P2D undefined");
643 return myP2D;
644}
645
646//=======================================================================
647//function : HasAvLS
648//purpose :
649//=======================================================================
650
651Standard_Boolean TopOpeBRepTool_ShapeClassifier::HasAvLS() const
652{
653 Standard_Boolean hasavls = (myPAvLS) ? (!myPAvLS->IsEmpty()) : Standard_False;
654 return hasavls;
655}
656
657#if 0
658//=======================================================================
659//function : FindEdge
660//purpose :
661//=======================================================================
662
663void TopOpeBRepTool_ShapeClassifier::FindEdge(const TopoDS_Shape& S)
664{
665 myEdge.Nullify();
666 Standard_Boolean isavs = (! myAvS.IsNull());
667 Standard_Boolean isavls = HasAvLS();
668 Standard_Boolean isav = (isavs || isavls);
669
670 if (S.IsNull()) return;
671 TopAbs_ShapeEnum tS = S.ShapeType();
672
673 TopExp_Explorer eex;
674 if ( ! myFace.IsNull() ) eex.Init(myFace,TopAbs_EDGE);
675 else eex.Init(S,TopAbs_EDGE);
676
677 for(; eex.More(); eex.Next()) {
678 const TopoDS_Edge& E = TopoDS::Edge(eex.Current());
679 if ( isav ) {
680 Standard_Boolean toavoid = Standard_False;
681 if ( isavls ) toavoid = myMapAvS.Contains(E);
682 else if ( isavs ) toavoid = E.IsSame(myAvS);
683 if ( toavoid ) continue;
684 }
685 else if ( BRep_Tool::Degenerated(E) ) {
686 if ( tS != TopAbs_EDGE ) continue;
687 }
688 myEdge = E;
689 break;
690 }
691}
692
693static Standard_Boolean FindAPointInTheFace
694(const TopoDS_Face& _face,gp_Pnt& APoint,Standard_Real& u,Standard_Real& v)
695{
696 TopoDS_Face face=_face;
697 face.Orientation(TopAbs_FORWARD);
698
699 TopExp_Explorer faceexplorer;
700 BRepAdaptor_Curve2d c;
701 gp_Vec2d T;
702 gp_Pnt2d P;
703 Standard_Boolean Ok = Standard_False;
704 Standard_Integer nbiter=0;
705 Standard_Real myParamOnEdge = 0.5;
706 do {
707 nbiter++;
708 if(myParamOnEdge==0.5) myParamOnEdge = 0.4;
709 else if(myParamOnEdge==0.4) myParamOnEdge = 0.6;
710 else if(myParamOnEdge==0.6) myParamOnEdge = 0.3;
711 else if(myParamOnEdge==0.3) myParamOnEdge = 0.7;
712 else if(myParamOnEdge==0.7) myParamOnEdge = 0.2;
713 else if(myParamOnEdge==0.2) myParamOnEdge = 0.8;
714 else if(myParamOnEdge==0.8) myParamOnEdge = 0.1;
715 else if(myParamOnEdge==0.1) myParamOnEdge = 0.9;
716 else { myParamOnEdge*=0.5; }
717
718 for (faceexplorer.Init(face,TopAbs_EDGE);
719 faceexplorer.More();
720 faceexplorer.Next()) {
721 TopoDS_Edge Edge = TopoDS::Edge(faceexplorer.Current());
722 c.Initialize(Edge,face);
723 Standard_Integer nbinterval = c.NbIntervals(GeomAbs_C1);
724 c.D1((c.LastParameter() - c.FirstParameter()) * myParamOnEdge + c.FirstParameter(),P,T);
725
726 Standard_Real x=T.X();
727 Standard_Real y=T.Y();
728 //-- cout<<"Param:"<<(c.IntervalFirst() + c.IntervalLast()) * param<<" U:"<<P.X()<<" V:"<<P.Y();
729 //-- cout<<" tguv x:"<<x<<" , y:"<<y<<endl;
730
731
732 if(Edge.Orientation() == TopAbs_FORWARD) {
733 T.SetCoord(-y,x);
734 }
735 else {
736 T.SetCoord(y,-x);
737 }
738
739 Standard_Real ParamInit = RealLast();
740 Standard_Real TolInit = 0.00001;
741 Standard_Boolean APointExist = Standard_False;
742
743 BRepClass_FacePassiveClassifier FClassifier;
744
745 T.Normalize();
746 P.SetCoord(P.X()+TolInit*T.X(),P.Y()+TolInit*T.Y());
747 FClassifier.Reset(gp_Lin2d(P,T),ParamInit,RealEpsilon()); //-- Longueur et Tolerance #######
748
749 TopExp_Explorer otherfaceexplorer;
750 for (otherfaceexplorer.Init(face,TopAbs_EDGE);
751 otherfaceexplorer.More();
752 otherfaceexplorer.Next()) {
753 TopoDS_Edge OtherEdge = TopoDS::Edge(otherfaceexplorer.Current());
754 if((OtherEdge.Orientation() == TopAbs_EXTERNAL)) {
755 }
756 else {
757 BRepClass_Edge AEdge(OtherEdge,face);
758 FClassifier.Compare(AEdge,OtherEdge.Orientation());
759 if(FClassifier.ClosestIntersection()) {
760 //-- cout<<" ---> Edge : "<<FClassifier.Parameter()<<endl;
761 if(ParamInit > FClassifier.Parameter()) {
762 ParamInit = FClassifier.Parameter();
763 APointExist = Standard_True;
764 }
765 }
766 }
767 }
768 if(APointExist) {
769 ParamInit*=0.5;
770 u = P.X() + ParamInit* T.X();
771 v = P.Y() + ParamInit* T.Y();
772 BRepAdaptor_Surface s;
773 Standard_Boolean computerestriction = Standard_False;
774 s.Initialize(face,computerestriction);
775 s.D0(u,v,APoint);
776 //-- cout<<" u="<<u<<" v="<<v<<" -> ("<<APoint.X()<<","<<APoint.Y()<<","<<APoint.Z()<<endl;
777 return(Standard_True);
778 }
779 }
780 }
781 while(nbiter<100);
782 return(Standard_False);
783}
784
785#endif