0022627: Change OCCT memory management defaults
[occt.git] / src / BRepTools / BRepTools.cxx
CommitLineData
7fd59977 1// File: BRepTools.cxx
2// Created: Thu Jan 21 19:59:19 1993
3// Author: Remi LEQUETTE
4// <rle@phylox>
5
6#include <Standard_Stream.hxx>
7
8#include <BRepTools.ixx>
9#include <BRepTools_ShapeSet.hxx>
10#include <BRep_Tool.hxx>
11#include <TopExp.hxx>
12#include <TopExp_Explorer.hxx>
13#include <TopoDS.hxx>
14#include <TopoDS_Iterator.hxx>
15#include <BndLib_Add2dCurve.hxx>
16#include <Geom2dAdaptor_Curve.hxx>
17#include <Geom_Surface.hxx>
18#include <Geom_Curve.hxx>
19#include <Geom2d_Curve.hxx>
20#include <BRepTools_MapOfVertexPnt2d.hxx>
21#include <BRep_CurveRepresentation.hxx>
22#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23#include <BRep_TEdge.hxx>
24#include <TColgp_SequenceOfPnt2d.hxx>
25#include <TColStd_SequenceOfReal.hxx>
26#include <TColGeom2d_SequenceOfCurve.hxx>
27#include <TopTools_SequenceOfShape.hxx>
28#include <Precision.hxx>
29
30#include <Poly_Triangulation.hxx>
31#include <Poly_PolygonOnTriangulation.hxx>
32#include <TColStd_HArray1OfInteger.hxx>
01697018 33#include <TColStd_MapOfTransient.hxx>
7fd59977 34
35#include <gp_Lin2d.hxx>
36#include <ElCLib.hxx>
37#include <gp_Vec2d.hxx>
38#include <Standard_ErrorHandler.hxx>
39#include <Standard_Failure.hxx>
40
41#include <errno.h>
42
43//=======================================================================
44//function : UVBounds
45//purpose :
46//=======================================================================
47
48void BRepTools::UVBounds(const TopoDS_Face& F,
49 Standard_Real& UMin, Standard_Real& UMax,
50 Standard_Real& VMin, Standard_Real& VMax)
51{
52 Bnd_Box2d B;
53 AddUVBounds(F,B);
54 B.Get(UMin,VMin,UMax,VMax);
55}
56
57//=======================================================================
58//function : UVBounds
59//purpose :
60//=======================================================================
61
62void BRepTools::UVBounds(const TopoDS_Face& F,
63 const TopoDS_Wire& W,
64 Standard_Real& UMin, Standard_Real& UMax,
65 Standard_Real& VMin, Standard_Real& VMax)
66{
67 Bnd_Box2d B;
68 AddUVBounds(F,W,B);
69 B.Get(UMin,VMin,UMax,VMax);
70}
71
72
73//=======================================================================
74//function : UVBounds
75//purpose :
76//=======================================================================
77
78void BRepTools::UVBounds(const TopoDS_Face& F,
79 const TopoDS_Edge& E,
80 Standard_Real& UMin, Standard_Real& UMax,
81 Standard_Real& VMin, Standard_Real& VMax)
82{
83 Bnd_Box2d B;
84 AddUVBounds(F,E,B);
85 B.Get(UMin,VMin,UMax,VMax);
86}
87
88//=======================================================================
89//function : AddUVBounds
90//purpose :
91//=======================================================================
92
93void BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B)
94{
95 TopoDS_Face F = FF;
96 F.Orientation(TopAbs_FORWARD);
97 TopExp_Explorer ex(F,TopAbs_EDGE);
98
99 // fill box for the given face
100 Bnd_Box2d aBox;
101 for (;ex.More();ex.Next()) {
102 BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),aBox);
103 }
104
105 // if the box is empty (face without edges or without pcurves),
106 // get natural bounds
107 if (aBox.IsVoid()) {
108 Standard_Real UMin,UMax,VMin,VMax;
109 TopLoc_Location L;
110 BRep_Tool::Surface(F,L)->Bounds(UMin,UMax,VMin,VMax);
111 aBox.Update(UMin,VMin,UMax,VMax);
112 }
113
114 // add face box to result
115 B.Add ( aBox );
116}
117
118
119//=======================================================================
120//function : AddUVBounds
121//purpose :
122//=======================================================================
123
124void BRepTools::AddUVBounds(const TopoDS_Face& F,
125 const TopoDS_Wire& W,
126 Bnd_Box2d& B)
127{
128 TopExp_Explorer ex;
129 for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) {
130 BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),B);
131 }
132}
133
134
135//=======================================================================
136//function : AddUVBounds
137//purpose :
138//=======================================================================
139
140void BRepTools::AddUVBounds(const TopoDS_Face& F,
141 const TopoDS_Edge& E,
142 Bnd_Box2d& B)
143{
144 Standard_Real pf,pl;
145 Bnd_Box2d Baux;
146 const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl);
c55993db 147 if (C.IsNull()) return;
7fd59977 148 if (pl < pf) { // Petit Blindage
149 Standard_Real aux;
150 aux = pf; pf = pl; pl = aux;
151 }
7fd59977 152 Geom2dAdaptor_Curve PC(C,pf,pl);
153 if (Precision::IsNegativeInfinite(pf) ||
154 Precision::IsPositiveInfinite(pf)) {
155 Geom2dAdaptor_Curve GC(PC);
156 BndLib_Add2dCurve::Add(GC,0.,B);
157 }
158 else {
159
160 // just compute points to get a close box.
161 TopLoc_Location L;
162 Standard_Real Umin,Umax,Vmin,Vmax;
163 const Handle(Geom_Surface)& Surf=BRep_Tool::Surface(F,L);
164 Surf->Bounds(Umin,Umax,Vmin,Vmax);
165 gp_Pnt2d Pa,Pb,Pc;
166
167
168 Standard_Real i, nbp = 20;
169 if (PC.GetType() == GeomAbs_Line) nbp = 2;
170 Standard_Real step = (pl - pf) / nbp;
171 gp_Pnt2d P;
172 PC.D0(pf,P);
173 Baux.Add(P);
174
175 Standard_Real du=0.0;
176 Standard_Real dv=0.0;
177
178 Pc=P;
179 for (i = 1; i < nbp; i++) {
180 pf += step;
181 PC.D0(pf,P);
182 Baux.Add(P);
183 if(i==1) { Pb=Pc; Pc=P; }
184 else {
185 //-- Calcul de la fleche
186 Pa=Pb; Pb=Pc; Pc=P;
187 gp_Vec2d PaPc(Pa,Pc);
188// gp_Lin2d L2d(Pa,PaPc);
189// Standard_Real up = ElCLib::Parameter(L2d,Pb);
190// gp_Pnt2d PProj = ElCLib::Value(up,L2d);
191 gp_Pnt2d PProj(Pa.Coord()+(PaPc.XY()/2.));
192 Standard_Real ddu=Abs(Pb.X()-PProj.X());
193 Standard_Real ddv=Abs(Pb.Y()-PProj.Y());
194 if(ddv>dv) dv=ddv;
195 if(ddu>du) du=ddu;
196 }
197 }
198 PC.D0(pl,P);
199 Baux.Add(P);
200
201 //-- cout<<" du="<<du<<" dv="<<dv<<endl;
202 Standard_Real u0,u1,v0,v1;
203 Baux.Get(u0,v0,u1,v1);
204 du*=1.5;
205 dv*=1.5;
206 u0-=du; v0-=dv; u1+=du; v1+=dv;
207 if(Surf->IsUPeriodic()) { }
208 else {
209 if(u0<=Umin) { u0=Umin; }
210 if(u1>=Umax) { u1=Umax; }
211 }
212 if(Surf->IsVPeriodic()) { }
213 else {
214 if(v0<=Vmin) { v0=Vmin; }
215 if(v1>=Vmax) { v1=Vmax; }
216 }
217 P.SetCoord(u0,v0) ; Baux.Add(P);
218 P.SetCoord(u1,v1) ; Baux.Add(P);
cf836671 219
220 Bnd_Box2d FinalBox;
221 Standard_Real aXmin, aYmin, aXmax, aYmax;
222 Baux.Get(aXmin, aYmin, aXmax, aYmax);
223 Standard_Real Tol2d = Precision::PConfusion();
224 if (Abs(aXmin - Umin) <= Tol2d)
225 aXmin = Umin;
226 if (Abs(aYmin - Vmin) <= Tol2d)
227 aYmin = Vmin;
228 if (Abs(aXmax - Umax) <= Tol2d)
229 aXmax = Umax;
230 if (Abs(aYmax - Vmax) <= Tol2d)
231 aYmax = Vmax;
232 FinalBox.Update(aXmin, aYmin, aXmax, aYmax);
233
234 B.Add(FinalBox);
7fd59977 235 }
236}
237
238//=======================================================================
239//function : Update
240//purpose :
241//=======================================================================
242
243void BRepTools::Update(const TopoDS_Vertex&)
244{
245}
246
247//=======================================================================
248//function : Update
249//purpose :
250//=======================================================================
251
252void BRepTools::Update(const TopoDS_Edge&)
253{
254}
255
256//=======================================================================
257//function : Update
258//purpose :
259//=======================================================================
260
261void BRepTools::Update(const TopoDS_Wire&)
262{
263}
264
265//=======================================================================
266//function : Update
267//purpose :
268//=======================================================================
269
270void BRepTools::Update(const TopoDS_Face& F)
271{
272 if (!F.Checked()) {
273 UpdateFaceUVPoints(F);
274 F.TShape()->Checked(Standard_True);
275 }
276}
277
278//=======================================================================
279//function : Update
280//purpose :
281//=======================================================================
282
283void BRepTools::Update(const TopoDS_Shell& S)
284{
285 TopExp_Explorer ex(S,TopAbs_FACE);
286 while (ex.More()) {
287 Update(TopoDS::Face(ex.Current()));
288 ex.Next();
289 }
290}
291
292//=======================================================================
293//function : Update
294//purpose :
295//=======================================================================
296
297void BRepTools::Update(const TopoDS_Solid& S)
298{
299 TopExp_Explorer ex(S,TopAbs_FACE);
300 while (ex.More()) {
301 Update(TopoDS::Face(ex.Current()));
302 ex.Next();
303 }
304}
305
306//=======================================================================
307//function : Update
308//purpose :
309//=======================================================================
310
311void BRepTools::Update(const TopoDS_CompSolid& CS)
312{
313 TopExp_Explorer ex(CS,TopAbs_FACE);
314 while (ex.More()) {
315 Update(TopoDS::Face(ex.Current()));
316 ex.Next();
317 }
318}
319
320//=======================================================================
321//function : Update
322//purpose :
323//=======================================================================
324
325void BRepTools::Update(const TopoDS_Compound& C)
326{
327 TopExp_Explorer ex(C,TopAbs_FACE);
328 while (ex.More()) {
329 Update(TopoDS::Face(ex.Current()));
330 ex.Next();
331 }
332}
333
334//=======================================================================
335//function : Update
336//purpose :
337//=======================================================================
338
339void BRepTools::Update(const TopoDS_Shape& S)
340{
341 switch (S.ShapeType()) {
342
343 case TopAbs_VERTEX :
344 Update(TopoDS::Vertex(S));
345 break;
346
347 case TopAbs_EDGE :
348 Update(TopoDS::Edge(S));
349 break;
350
351 case TopAbs_WIRE :
352 Update(TopoDS::Wire(S));
353 break;
354
355 case TopAbs_FACE :
356 Update(TopoDS::Face(S));
357 break;
358
359 case TopAbs_SHELL :
360 Update(TopoDS::Shell(S));
361 break;
362
363 case TopAbs_SOLID :
364 Update(TopoDS::Solid(S));
365 break;
366
367 case TopAbs_COMPSOLID :
368 Update(TopoDS::CompSolid(S));
369 break;
370
371 case TopAbs_COMPOUND :
372 Update(TopoDS::Compound(S));
373 break;
374
375 default:
376 break;
377
378 }
379}
380
381
382//=======================================================================
383//function : UpdateFaceUVPoints
384//purpose : reset the UV points of a Face
385//=======================================================================
386
387void BRepTools::UpdateFaceUVPoints(const TopoDS_Face& F)
388{
389 // Recompute for each edge the two UV points in order to have the same
390 // UV point on connected edges.
391
392 // First edge loop, store the vertices in a Map with their 2d points
393
394 BRepTools_MapOfVertexPnt2d theVertices;
395 TopoDS_Iterator expE,expV;
396 TopoDS_Iterator EdgeIt,VertIt;
397 TColStd_SequenceOfReal aFSeq, aLSeq;
398 TColGeom2d_SequenceOfCurve aCSeq;
399 TopTools_SequenceOfShape aShSeq;
400 gp_Pnt2d P;
401 Standard_Integer i;
402 // a 3d tolerance for UV !!
403 Standard_Real tolerance = BRep_Tool::Tolerance(F);
404 TColgp_SequenceOfPnt2d emptySequence;
405
406 for (expE.Initialize(F); expE.More(); expE.Next()) {
407 if(expE.Value().ShapeType() != TopAbs_WIRE)
408 continue;
409
410 EdgeIt.Initialize(expE.Value());
411 for( ; EdgeIt.More(); EdgeIt.Next())
412 {
413 const TopoDS_Edge& E = TopoDS::Edge(EdgeIt.Value());
414 Standard_Real f,l;
415 Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,f,l);
416
417 aFSeq.Append(f);
418 aLSeq.Append(l);
419 aCSeq.Append(C);
420 aShSeq.Append(E);
421
422 if (C.IsNull()) continue;
423
424 for (expV.Initialize(E.Oriented(TopAbs_FORWARD));
425 expV.More(); expV.Next()) {
426
427 const TopoDS_Vertex& V = TopoDS::Vertex(expV.Value());
428
429 TopAbs_Orientation Vori = V.Orientation();
430 if ( Vori == TopAbs_INTERNAL ) {
431 continue;
432 }
433
434 Standard_Real p = BRep_Tool::Parameter(V,E,F);
435 C->D0(p,P);
436 if (!theVertices.IsBound(V))
437 theVertices.Bind(V,emptySequence);
438 TColgp_SequenceOfPnt2d& S = theVertices(V);
439 for (i = 1; i <= S.Length(); i++) {
440 if (P.Distance(S(i)) < tolerance) break;
441 }
442 if (i > S.Length())
443 S.Append(P);
444 }
445 }
446 }
447
448 // second edge loop, update the edges 2d points
449 TopoDS_Vertex Vf,Vl;
450 gp_Pnt2d Pf,Pl;
451
452 for(Standard_Integer j = 1; j <= aShSeq.Length(); j++)
453 {
454 const TopoDS_Edge& E = TopoDS::Edge(aShSeq.Value(j));
455 const Handle(Geom2d_Curve)& C = aCSeq.Value(j);
456 if (C.IsNull()) continue;
457
458 TopExp::Vertices(E,Vf,Vl);
459 if (Vf.IsNull()) {
460 Pf.SetCoord(RealLast(),RealLast());
461 }
462 else {
463 if ( Vf.Orientation() == TopAbs_INTERNAL ) {
464 continue;
465 }
466 const TColgp_SequenceOfPnt2d& seqf = theVertices(Vf);
467 if (seqf.Length() == 1)
468 Pf = seqf(1);
469 else {
470 C->D0(aFSeq.Value(j),Pf);
471 for (i = 1; i <= seqf.Length(); i++) {
472 if (Pf.Distance(seqf(i)) <= tolerance) {
473 Pf = seqf(i);
474 break;
475 }
476 }
477 }
478 }
479 if (Vl.IsNull()) {
480 Pl.SetCoord(RealLast(),RealLast());
481 }
482 else {
483 if ( Vl.Orientation() == TopAbs_INTERNAL ) {
484 continue;
485 }
486 const TColgp_SequenceOfPnt2d& seql = theVertices(Vl);
487 if (seql.Length() == 1)
488 Pl = seql(1);
489 else {
490 C->D0(aLSeq.Value(j),Pl);
491 for (i = 1; i <= seql.Length(); i++) {
492 if (Pl.Distance(seql(i)) <= tolerance) {
493 Pl = seql(i);
494 break;
495 }
496 }
497 }
498 }
499
500 // set the correct points
501 BRep_Tool::SetUVPoints(E,F,Pf,Pl);
502 }
503}
504
505
506
507//=======================================================================
508//function : Compare
509//purpose :
510//=======================================================================
511
512Standard_Boolean BRepTools::Compare(const TopoDS_Vertex& V1,
513 const TopoDS_Vertex& V2)
514{
515 if (V1.IsSame(V2)) return Standard_True;
516 gp_Pnt p1 = BRep_Tool::Pnt(V1);
517 gp_Pnt p2 = BRep_Tool::Pnt(V2);
518 Standard_Real l = p1.Distance(p2);
519 if (l <= BRep_Tool::Tolerance(V1)) return Standard_True;
520 if (l <= BRep_Tool::Tolerance(V2)) return Standard_True;
521 return Standard_False;
522}
523
524//=======================================================================
525//function : Compare
526//purpose :
527//=======================================================================
528
529Standard_Boolean BRepTools::Compare(const TopoDS_Edge& E1,
530 const TopoDS_Edge& E2)
531{
532 if (E1.IsSame(E2)) return Standard_True;
533 return Standard_False;
534}
535
536//=======================================================================
537//function : OuterWire
538//purpose :
539//=======================================================================
540
541TopoDS_Wire BRepTools::OuterWire(const TopoDS_Face& F)
542{
543 TopoDS_Wire Wres;
544 TopExp_Explorer expw (F,TopAbs_WIRE);
545
546 if (expw.More()) {
547 Wres = TopoDS::Wire(expw.Current());
548 expw.Next();
549 if (expw.More()) {
550 Standard_Real UMin, UMax, VMin, VMax;
551 Standard_Real umin, umax, vmin, vmax;
552 BRepTools::UVBounds(F,Wres,UMin,UMax,VMin,VMax);
553 while (expw.More()) {
554 const TopoDS_Wire& W = TopoDS::Wire(expw.Current());
555 BRepTools::UVBounds(F,W,umin, umax, vmin, vmax);
556 if ((umin <= UMin) &&
557 (umax >= UMax) &&
558 (vmin <= VMin) &&
559 (vmax >= VMax)) {
560 Wres = W;
561 UMin = umin;
562 UMax = umax;
563 VMin = vmin;
564 VMax = vmax;
565 }
566 expw.Next();
567 }
568 }
569 }
570 return Wres;
571}
572
573
574//=======================================================================
575//function : OuterShell
576//purpose :
577//=======================================================================
578
579TopoDS_Shell BRepTools::OuterShell(const TopoDS_Solid& S)
580{
581 TopExp_Explorer its(S,TopAbs_SHELL);
582 if (its.More())
583 return TopoDS::Shell(its.Current());
584 else
585 return TopoDS_Shell();
586}
587
588
589//=======================================================================
590//function : Map3DEdges
591//purpose :
592//=======================================================================
593
594void BRepTools::Map3DEdges(const TopoDS_Shape& S,
595 TopTools_IndexedMapOfShape& M)
596{
597 TopExp_Explorer Ex;
598 for (Ex.Init(S,TopAbs_EDGE); Ex.More(); Ex.Next()) {
599 if (!BRep_Tool::Degenerated(TopoDS::Edge(Ex.Current())))
600 M.Add(Ex.Current());
601 }
602}
603
604//=======================================================================
605//function : Dump
606//purpose :
607//=======================================================================
608
609void BRepTools::Dump(const TopoDS_Shape& Sh, Standard_OStream& S)
610{
611 BRepTools_ShapeSet SS;
612 SS.Add(Sh);
613 SS.Dump(Sh,S);
614 SS.Dump(S);
615}
616
617#ifdef DEB
618//=======================================================================
619//function : BRepTools_Write
620//purpose :
621//=======================================================================
622void BRepTools_Write (const TopoDS_Shape& S,
623 const Standard_CString File)
624{
625 BRepTools::Write (S,File);
626}
627#endif
628
629//=======================================================================
630//function : Write
631//purpose :
632//=======================================================================
633
634void BRepTools::Write(const TopoDS_Shape& Sh, Standard_OStream& S,
635 const Handle(Message_ProgressIndicator)& PR)
636{
637 BRepTools_ShapeSet SS;
638 SS.SetProgress(PR);
639 SS.Add(Sh);
640 SS.Write(S);
641 SS.Write(Sh,S);
642}
643
644
645//=======================================================================
646//function : Read
647//purpose :
648//=======================================================================
649
650void BRepTools::Read(TopoDS_Shape& Sh,
651 istream& S,
652 const BRep_Builder& B,
653 const Handle(Message_ProgressIndicator)& PR)
654{
655 BRepTools_ShapeSet SS(B);
656 SS.SetProgress(PR);
657 SS.Read(S);
658 SS.Read(Sh,S);
659}
660
661//=======================================================================
662//function : Write
663//purpose :
664//=======================================================================
665
666Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
667 const Standard_CString File,
668 const Handle(Message_ProgressIndicator)& PR)
669{
670 ofstream os;
671 // if (!fic.open(File,output)) return Standard_False;
672 os.open(File, ios::out);
673 if (!os.rdbuf()->is_open()) return Standard_False;
674
675 Standard_Boolean isGood = (os.good() && !os.eof());
676 if(!isGood)
677 return isGood;
678
679 BRepTools_ShapeSet SS;
680 SS.SetProgress(PR);
681 SS.Add(Sh);
682
683 os << "DBRep_DrawableShape\n"; // for easy Draw read
684 SS.Write(os);
685 isGood = os.good();
686 if(isGood )
687 SS.Write(Sh,os);
688 os.flush();
689 isGood = os.good();
690
691 errno = 0;
692 os.close();
7fd59977 693 isGood = os.good() && isGood && !errno;
694
695 return isGood;
696}
697
698//=======================================================================
699//function : Read
700//purpose :
701//=======================================================================
702
703Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
704 const Standard_CString File,
705 const BRep_Builder& B,
706 const Handle(Message_ProgressIndicator)& PR)
707{
708 filebuf fic;
709 istream in(&fic);
710 if (!fic.open(File, ios::in)) return Standard_False;
711
712 BRepTools_ShapeSet SS(B);
713 SS.SetProgress(PR);
714 SS.Read(in);
715 if(!SS.NbShapes()) return Standard_False;
716 SS.Read(Sh,in);
717 return Standard_True;
718}
719
720
721//=======================================================================
722//function : Clean
723//purpose :
724//=======================================================================
725
726void BRepTools::Clean(const TopoDS_Shape& S)
727{
728 BRep_Builder B;
729 TopExp_Explorer ex;
730 Handle(Poly_Triangulation) TNULL, T;
731 Handle(Poly_PolygonOnTriangulation) PolyNULL, Poly;
732
733 if (!S.IsNull()) {
734 TopLoc_Location L;
735 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
736 const TopoDS_Face& F = TopoDS::Face(ex.Current());
737 B.UpdateFace(F, TNULL);
738 }
739 for (ex.Init(S, TopAbs_EDGE); ex.More(); ex.Next()) {
740 const TopoDS_Edge& E = TopoDS::Edge(ex.Current());
741// agv 21.09.01 : Inefficient management of Locations -> improve performance
742// do {
743// BRep_Tool::PolygonOnTriangulation(E, Poly, T, L);
744// B.UpdateEdge(E, PolyNULL, T, L);
745// } while(!Poly.IsNull());
746//
747 Handle(BRep_CurveRepresentation) cr;
748 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape());
749 BRep_ListOfCurveRepresentation& lcr = TE -> ChangeCurves();
750 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
751
752 // find and remove all representations
753 while (itcr.More()) {
754 cr = itcr.Value();
755 if (cr->IsPolygonOnTriangulation())
756 lcr.Remove(itcr);
757 else
758 itcr.Next();
759 }
760 TE->Modified(Standard_True);
761// agv : fin
762 }
763 }
764}
765
01697018
J
766//=======================================================================
767//function : RemoveUnusedPCurves
768//purpose :
769//=======================================================================
770
771void BRepTools::RemoveUnusedPCurves(const TopoDS_Shape& S)
772{
773 TColStd_MapOfTransient UsedSurfaces;
774
775 TopExp_Explorer Explo(S, TopAbs_FACE);
776 for (; Explo.More(); Explo.Next())
777 {
778 TopoDS_Face aFace = TopoDS::Face(Explo.Current());
779 TopLoc_Location aLoc;
780 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
781 UsedSurfaces.Add(aSurf);
782 }
783
784 TopTools_IndexedMapOfShape Emap;
785 TopExp::MapShapes(S, TopAbs_EDGE, Emap);
7fd59977 786
01697018
J
787 Standard_Integer i;
788 for (i = 1; i <= Emap.Extent(); i++)
789 {
790 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Emap(i).TShape());
791 BRep_ListOfCurveRepresentation& lcr = TE -> ChangeCurves();
792 BRep_ListIteratorOfListOfCurveRepresentation itrep(lcr );
793 while (itrep.More())
794 {
795 Standard_Boolean ToRemove = Standard_False;
796
797 Handle(BRep_CurveRepresentation) CurveRep = itrep.Value();
798 if (CurveRep->IsCurveOnSurface())
799 {
800 Handle(Geom_Surface) aSurface = CurveRep->Surface();
801 if (!UsedSurfaces.Contains(aSurface))
802 ToRemove = Standard_True;
803 }
804 else if (CurveRep->IsRegularity())
805 {
806 Handle(Geom_Surface) Surf1 = CurveRep->Surface();
807 Handle(Geom_Surface) Surf2 = CurveRep->Surface2();
808 ToRemove = (!UsedSurfaces.Contains(Surf1) || !UsedSurfaces.Contains(Surf2));
809 }
810
811 if (ToRemove)
812 lcr.Remove(itrep);
813 else
814 itrep.Next();
815 }
816 }
817}
7fd59977 818
819//=======================================================================
820//function : Triangulation
821//purpose :
822//=======================================================================
823
824Standard_Boolean BRepTools::Triangulation(const TopoDS_Shape& S,
825 const Standard_Real deflec)
826{
827 TopExp_Explorer exf, exe;
828 TopLoc_Location l;
829 Handle(Poly_Triangulation) T;
830 Handle(Poly_PolygonOnTriangulation) Poly;
831
832 for (exf.Init(S, TopAbs_FACE); exf.More(); exf.Next()) {
833 const TopoDS_Face& F = TopoDS::Face(exf.Current());
834 T = BRep_Tool::Triangulation(F, l);
835 if (T.IsNull() || (T->Deflection() > deflec))
836 return Standard_False;
837 for (exe.Init(F, TopAbs_EDGE); exe.More(); exe.Next()) {
838 const TopoDS_Edge& E = TopoDS::Edge(exe.Current());
839 Poly = BRep_Tool::PolygonOnTriangulation(E, T, l);
840 if (Poly.IsNull()) return Standard_False;
841 }
842 }
843 return Standard_True;
844}
845
846
847//=======================================================================
848//function : IsReallyClosed
849//purpose :
850//=======================================================================
851
852Standard_Boolean BRepTools::IsReallyClosed(const TopoDS_Edge& E,
853 const TopoDS_Face& F)
854{
855 if (!BRep_Tool::IsClosed(E,F)) {
856 return Standard_False;
857 }
858 Standard_Integer nbocc = 0;
859 TopExp_Explorer exp;
860 for (exp.Init(F,TopAbs_EDGE);exp.More();exp.Next()) {
861 if (exp.Current().IsSame(E)) {
862 nbocc++;
863 }
864 }
865 return nbocc == 2;
866}
867
868
869