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