1 // Created on: 1993-01-21
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Bnd_Box2d.hxx>
19 #include <BndLib_Add2dCurve.hxx>
20 #include <BRep_Builder.hxx>
21 #include <BRep_CurveRepresentation.hxx>
22 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
23 #include <BRep_TEdge.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRepTools.hxx>
26 #include <BRepTools_MapOfVertexPnt2d.hxx>
27 #include <BRepTools_ShapeSet.hxx>
29 #include <Geom2d_Curve.hxx>
30 #include <Geom2dAdaptor_Curve.hxx>
31 #include <Geom_BSplineSurface.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom_RectangularTrimmedSurface.hxx>
34 #include <Geom_Surface.hxx>
35 #include <gp_Lin2d.hxx>
36 #include <gp_Vec2d.hxx>
37 #include <Message_ProgressIndicator.hxx>
38 #include <OSD_OpenFile.hxx>
39 #include <Poly_PolygonOnTriangulation.hxx>
40 #include <Poly_Triangulation.hxx>
41 #include <Precision.hxx>
42 #include <Standard_ErrorHandler.hxx>
43 #include <Standard_Failure.hxx>
44 #include <Standard_Stream.hxx>
45 #include <TColGeom2d_SequenceOfCurve.hxx>
46 #include <TColgp_SequenceOfPnt2d.hxx>
47 #include <TColStd_Array1OfReal.hxx>
48 #include <TColStd_HArray1OfInteger.hxx>
49 #include <TColStd_MapOfTransient.hxx>
50 #include <TColStd_SequenceOfReal.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <TopoDS_Compound.hxx>
55 #include <TopoDS_CompSolid.hxx>
56 #include <TopoDS_Edge.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Iterator.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopoDS_Shell.hxx>
61 #include <TopoDS_Solid.hxx>
62 #include <TopoDS_Vertex.hxx>
63 #include <TopoDS_Wire.hxx>
64 #include <TopTools_SequenceOfShape.hxx>
65 #include <GeomLib_CheckCurveOnSurface.hxx>
67 //=======================================================================
70 //=======================================================================
71 void BRepTools::UVBounds(const TopoDS_Face& F,
72 Standard_Real& UMin, Standard_Real& UMax,
73 Standard_Real& VMin, Standard_Real& VMax)
79 B.Get(UMin,VMin,UMax,VMax);
83 UMin = UMax = VMin = VMax = 0.0;
87 //=======================================================================
90 //=======================================================================
92 void BRepTools::UVBounds(const TopoDS_Face& F,
94 Standard_Real& UMin, Standard_Real& UMax,
95 Standard_Real& VMin, Standard_Real& VMax)
101 B.Get(UMin,VMin,UMax,VMax);
105 UMin = UMax = VMin = VMax = 0.0;
110 //=======================================================================
111 //function : UVBounds
113 //=======================================================================
115 void BRepTools::UVBounds(const TopoDS_Face& F,
116 const TopoDS_Edge& E,
117 Standard_Real& UMin, Standard_Real& UMax,
118 Standard_Real& VMin, Standard_Real& VMax)
124 B.Get(UMin,VMin,UMax,VMax);
128 UMin = UMax = VMin = VMax = 0.0;
132 //=======================================================================
133 //function : AddUVBounds
135 //=======================================================================
137 void BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B)
140 F.Orientation(TopAbs_FORWARD);
141 TopExp_Explorer ex(F,TopAbs_EDGE);
143 // fill box for the given face
145 for (;ex.More();ex.Next()) {
146 BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),aBox);
149 // if the box is empty (face without edges or without pcurves),
150 // get natural bounds
152 Standard_Real UMin,UMax,VMin,VMax;
154 const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(F, L);
160 aSurf->Bounds(UMin,UMax,VMin,VMax);
161 aBox.Update(UMin,VMin,UMax,VMax);
164 // add face box to result
169 //=======================================================================
170 //function : AddUVBounds
172 //=======================================================================
173 void BRepTools::AddUVBounds(const TopoDS_Face& F,
174 const TopoDS_Wire& W,
178 for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) {
179 BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),B);
184 //=======================================================================
185 //function : AddUVBounds
187 //=======================================================================
188 void BRepTools::AddUVBounds(const TopoDS_Face& aF,
189 const TopoDS_Edge& aE,
192 Standard_Real aT1, aT2, aXmin = 0.0, aYmin = 0.0, aXmax = 0.0, aYmax = 0.0;
193 Standard_Real aUmin, aUmax, aVmin, aVmax;
194 Bnd_Box2d aBoxC, aBoxS;
195 TopLoc_Location aLoc;
197 const Handle(Geom2d_Curve) aC2D = BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
202 BndLib_Add2dCurve::Add(aC2D, aT1, aT2, 0., aBoxC);
205 aBoxC.Get(aXmin, aYmin, aXmax, aYmax);
208 Handle(Geom_Surface) aS = BRep_Tool::Surface(aF, aLoc);
209 aS->Bounds(aUmin, aUmax, aVmin, aVmax);
211 if(aS->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
213 const Handle(Geom_RectangularTrimmedSurface) aSt =
214 Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
215 aS = aSt->BasisSurface();
219 if(!aS->IsUPeriodic())
221 Standard_Boolean isUPeriodic = Standard_False;
223 // Additional verification for U-periodicity for B-spline surfaces
224 // 1. Verify that the surface is U-closed (if such flag is false). Verification uses 2 points
225 // 2. Verify periodicity of surface inside UV-bounds of the edge. Verification uses 3 or 6 points.
226 if (aS->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface) &&
227 (aXmin < aUmin || aXmax > aUmax))
229 Standard_Real aTol2 = 100 * Precision::Confusion() * Precision::Confusion();
230 isUPeriodic = Standard_True;
232 // 1. Verify that the surface is U-closed
233 if (!aS->IsUClosed())
235 Standard_Real aVStep = aVmax - aVmin;
236 for (Standard_Real aV = aVmin; aV <= aVmax; aV += aVStep)
238 P1 = aS->Value(aUmin, aV);
239 P2 = aS->Value(aUmax, aV);
240 if (P1.SquareDistance(P2) > aTol2)
242 isUPeriodic = Standard_False;
247 // 2. Verify periodicity of surface inside UV-bounds of the edge
248 if (isUPeriodic) // the flag still not changed
250 Standard_Real aV = (aVmin + aVmax) * 0.5;
251 Standard_Real aU[6]; // values of U lying out of surface boundaries
252 Standard_Real aUpp[6]; // corresponding U-values plus/minus period
253 Standard_Integer aNbPnt = 0;
257 aU[1] = (aXmin + aUmin) * 0.5;
259 aUpp[0] = aU[0] + aUmax - aUmin;
260 aUpp[1] = aU[1] + aUmax - aUmin;
261 aUpp[2] = aU[2] + aUmax - aUmin;
267 aU[aNbPnt + 1] = (aXmax + aUmax) * 0.5;
268 aU[aNbPnt + 2] = aXmax;
269 aUpp[aNbPnt] = aU[aNbPnt] - aUmax + aUmin;
270 aUpp[aNbPnt + 1] = aU[aNbPnt + 1] - aUmax + aUmin;
271 aUpp[aNbPnt + 2] = aU[aNbPnt + 2] - aUmax + aUmin;
274 for (Standard_Integer anInd = 0; anInd < aNbPnt; anInd++)
276 P1 = aS->Value(aU[anInd], aV);
277 P2 = aS->Value(aUpp[anInd], aV);
278 if (P1.SquareDistance(P2) > aTol2)
280 isUPeriodic = Standard_False;
289 if((aXmin<aUmin) && (aUmin < aXmax))
293 if((aXmin < aUmax) && (aUmax < aXmax))
300 if(!aS->IsVPeriodic())
302 Standard_Boolean isVPeriodic = Standard_False;
304 // Additional verification for V-periodicity for B-spline surfaces
305 // 1. Verify that the surface is V-closed (if such flag is false). Verification uses 2 points
306 // 2. Verify periodicity of surface inside UV-bounds of the edge. Verification uses 3 or 6 points.
307 if (aS->DynamicType() == STANDARD_TYPE(Geom_BSplineSurface) &&
308 (aYmin < aVmin || aYmax > aVmax))
310 Standard_Real aTol2 = 100 * Precision::Confusion() * Precision::Confusion();
311 isVPeriodic = Standard_True;
313 // 1. Verify that the surface is V-closed
314 if (!aS->IsVClosed())
316 Standard_Real aUStep = aUmax - aUmin;
317 for (Standard_Real aU = aUmin; aU <= aUmax; aU += aUStep)
319 P1 = aS->Value(aU, aVmin);
320 P2 = aS->Value(aU, aVmax);
321 if (P1.SquareDistance(P2) > aTol2)
323 isVPeriodic = Standard_False;
328 // 2. Verify periodicity of surface inside UV-bounds of the edge
329 if (isVPeriodic) // the flag still not changed
331 Standard_Real aU = (aUmin + aUmax) * 0.5;
332 Standard_Real aV[6]; // values of V lying out of surface boundaries
333 Standard_Real aVpp[6]; // corresponding V-values plus/minus period
334 Standard_Integer aNbPnt = 0;
338 aV[1] = (aYmin + aVmin) * 0.5;
340 aVpp[0] = aV[0] + aVmax - aVmin;
341 aVpp[1] = aV[1] + aVmax - aVmin;
342 aVpp[2] = aV[2] + aVmax - aVmin;
348 aV[aNbPnt + 1] = (aYmax + aVmax) * 0.5;
349 aV[aNbPnt + 2] = aYmax;
350 aVpp[aNbPnt] = aV[aNbPnt] - aVmax + aVmin;
351 aVpp[aNbPnt + 1] = aV[aNbPnt + 1] - aVmax + aVmin;
352 aVpp[aNbPnt + 2] = aV[aNbPnt + 2] - aVmax + aVmin;
355 for (Standard_Integer anInd = 0; anInd < aNbPnt; anInd++)
357 P1 = aS->Value(aU, aV[anInd]);
358 P2 = aS->Value(aU, aVpp[anInd]);
359 if (P1.SquareDistance(P2) > aTol2)
361 isVPeriodic = Standard_False;
370 if((aYmin<aVmin) && (aVmin < aYmax))
374 if((aYmin < aVmax) && (aVmax < aYmax))
381 aBoxS.Update(aXmin, aYmin, aXmax, aYmax);
386 //=======================================================================
389 //=======================================================================
391 void BRepTools::Update(const TopoDS_Vertex&)
395 //=======================================================================
398 //=======================================================================
400 void BRepTools::Update(const TopoDS_Edge&)
404 //=======================================================================
407 //=======================================================================
409 void BRepTools::Update(const TopoDS_Wire&)
413 //=======================================================================
416 //=======================================================================
418 void BRepTools::Update(const TopoDS_Face& F)
421 UpdateFaceUVPoints(F);
422 F.TShape()->Checked(Standard_True);
426 //=======================================================================
429 //=======================================================================
431 void BRepTools::Update(const TopoDS_Shell& S)
433 TopExp_Explorer ex(S,TopAbs_FACE);
435 Update(TopoDS::Face(ex.Current()));
440 //=======================================================================
443 //=======================================================================
445 void BRepTools::Update(const TopoDS_Solid& S)
447 TopExp_Explorer ex(S,TopAbs_FACE);
449 Update(TopoDS::Face(ex.Current()));
454 //=======================================================================
457 //=======================================================================
459 void BRepTools::Update(const TopoDS_CompSolid& CS)
461 TopExp_Explorer ex(CS,TopAbs_FACE);
463 Update(TopoDS::Face(ex.Current()));
468 //=======================================================================
471 //=======================================================================
473 void BRepTools::Update(const TopoDS_Compound& C)
475 TopExp_Explorer ex(C,TopAbs_FACE);
477 Update(TopoDS::Face(ex.Current()));
482 //=======================================================================
485 //=======================================================================
487 void BRepTools::Update(const TopoDS_Shape& S)
489 switch (S.ShapeType()) {
492 Update(TopoDS::Vertex(S));
496 Update(TopoDS::Edge(S));
500 Update(TopoDS::Wire(S));
504 Update(TopoDS::Face(S));
508 Update(TopoDS::Shell(S));
512 Update(TopoDS::Solid(S));
515 case TopAbs_COMPSOLID :
516 Update(TopoDS::CompSolid(S));
519 case TopAbs_COMPOUND :
520 Update(TopoDS::Compound(S));
530 //=======================================================================
531 //function : UpdateFaceUVPoints
532 //purpose : reset the UV points of a Face
533 //=======================================================================
535 void BRepTools::UpdateFaceUVPoints(const TopoDS_Face& F)
537 // Recompute for each edge the two UV points in order to have the same
538 // UV point on connected edges.
540 // First edge loop, store the vertices in a Map with their 2d points
542 BRepTools_MapOfVertexPnt2d theVertices;
543 TopoDS_Iterator expE,expV;
544 TopoDS_Iterator EdgeIt,VertIt;
545 TColStd_SequenceOfReal aFSeq, aLSeq;
546 TColGeom2d_SequenceOfCurve aCSeq;
547 TopTools_SequenceOfShape aShSeq;
550 // a 3d tolerance for UV !!
551 Standard_Real tolerance = BRep_Tool::Tolerance(F);
552 TColgp_SequenceOfPnt2d emptySequence;
554 for (expE.Initialize(F); expE.More(); expE.Next()) {
555 if(expE.Value().ShapeType() != TopAbs_WIRE)
558 EdgeIt.Initialize(expE.Value());
559 for( ; EdgeIt.More(); EdgeIt.Next())
561 const TopoDS_Edge& E = TopoDS::Edge(EdgeIt.Value());
563 Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,f,l);
570 if (C.IsNull()) continue;
572 for (expV.Initialize(E.Oriented(TopAbs_FORWARD));
573 expV.More(); expV.Next()) {
575 const TopoDS_Vertex& V = TopoDS::Vertex(expV.Value());
577 TopAbs_Orientation Vori = V.Orientation();
578 if ( Vori == TopAbs_INTERNAL ) {
582 Standard_Real p = BRep_Tool::Parameter(V,E,F);
584 if (!theVertices.IsBound(V))
585 theVertices.Bind(V,emptySequence);
586 TColgp_SequenceOfPnt2d& S = theVertices(V);
587 for (i = 1; i <= S.Length(); i++) {
588 if (P.Distance(S(i)) < tolerance) break;
596 // second edge loop, update the edges 2d points
600 for(Standard_Integer j = 1; j <= aShSeq.Length(); j++)
602 const TopoDS_Edge& E = TopoDS::Edge(aShSeq.Value(j));
603 const Handle(Geom2d_Curve)& C = aCSeq.Value(j);
604 if (C.IsNull()) continue;
606 TopExp::Vertices(E,Vf,Vl);
608 Pf.SetCoord(RealLast(),RealLast());
611 if ( Vf.Orientation() == TopAbs_INTERNAL ) {
614 const TColgp_SequenceOfPnt2d& seqf = theVertices(Vf);
615 if (seqf.Length() == 1)
618 C->D0(aFSeq.Value(j),Pf);
619 for (i = 1; i <= seqf.Length(); i++) {
620 if (Pf.Distance(seqf(i)) <= tolerance) {
628 Pl.SetCoord(RealLast(),RealLast());
631 if ( Vl.Orientation() == TopAbs_INTERNAL ) {
634 const TColgp_SequenceOfPnt2d& seql = theVertices(Vl);
635 if (seql.Length() == 1)
638 C->D0(aLSeq.Value(j),Pl);
639 for (i = 1; i <= seql.Length(); i++) {
640 if (Pl.Distance(seql(i)) <= tolerance) {
648 // set the correct points
649 BRep_Tool::SetUVPoints(E,F,Pf,Pl);
655 //=======================================================================
658 //=======================================================================
660 Standard_Boolean BRepTools::Compare(const TopoDS_Vertex& V1,
661 const TopoDS_Vertex& V2)
663 if (V1.IsSame(V2)) return Standard_True;
664 gp_Pnt p1 = BRep_Tool::Pnt(V1);
665 gp_Pnt p2 = BRep_Tool::Pnt(V2);
666 Standard_Real l = p1.Distance(p2);
667 if (l <= BRep_Tool::Tolerance(V1)) return Standard_True;
668 if (l <= BRep_Tool::Tolerance(V2)) return Standard_True;
669 return Standard_False;
672 //=======================================================================
675 //=======================================================================
677 Standard_Boolean BRepTools::Compare(const TopoDS_Edge& E1,
678 const TopoDS_Edge& E2)
680 if (E1.IsSame(E2)) return Standard_True;
681 return Standard_False;
684 //=======================================================================
685 //function : OuterWire
687 //=======================================================================
689 TopoDS_Wire BRepTools::OuterWire(const TopoDS_Face& F)
692 TopExp_Explorer expw (F,TopAbs_WIRE);
695 Wres = TopoDS::Wire(expw.Current());
698 Standard_Real UMin, UMax, VMin, VMax;
699 Standard_Real umin, umax, vmin, vmax;
700 BRepTools::UVBounds(F,Wres,UMin,UMax,VMin,VMax);
701 while (expw.More()) {
702 const TopoDS_Wire& W = TopoDS::Wire(expw.Current());
703 BRepTools::UVBounds(F,W,umin, umax, vmin, vmax);
704 if ((umin <= UMin) &&
721 //=======================================================================
722 //function : Map3DEdges
724 //=======================================================================
726 void BRepTools::Map3DEdges(const TopoDS_Shape& S,
727 TopTools_IndexedMapOfShape& M)
730 for (Ex.Init(S,TopAbs_EDGE); Ex.More(); Ex.Next()) {
731 if (!BRep_Tool::Degenerated(TopoDS::Edge(Ex.Current())))
736 //=======================================================================
739 //=======================================================================
741 void BRepTools::Dump(const TopoDS_Shape& Sh, Standard_OStream& S)
743 BRepTools_ShapeSet SS;
749 //=======================================================================
752 //=======================================================================
754 void BRepTools::Write(const TopoDS_Shape& Sh, Standard_OStream& S,
755 const Handle(Message_ProgressIndicator)& PR)
757 BRepTools_ShapeSet SS;
765 //=======================================================================
768 //=======================================================================
770 void BRepTools::Read(TopoDS_Shape& Sh,
772 const BRep_Builder& B,
773 const Handle(Message_ProgressIndicator)& PR)
775 BRepTools_ShapeSet SS(B);
781 //=======================================================================
784 //=======================================================================
786 Standard_Boolean BRepTools::Write(const TopoDS_Shape& Sh,
787 const Standard_CString File,
788 const Handle(Message_ProgressIndicator)& PR)
791 OSD_OpenStream(os, File, ios::out);
792 if (!os.rdbuf()->is_open()) return Standard_False;
794 Standard_Boolean isGood = (os.good() && !os.eof());
798 BRepTools_ShapeSet SS;
802 os << "DBRep_DrawableShape\n"; // for easy Draw read
812 isGood = os.good() && isGood && !errno;
817 //=======================================================================
820 //=======================================================================
822 Standard_Boolean BRepTools::Read(TopoDS_Shape& Sh,
823 const Standard_CString File,
824 const BRep_Builder& B,
825 const Handle(Message_ProgressIndicator)& PR)
829 OSD_OpenFileBuf(fic,File,ios::in);
830 if(!fic.is_open()) return Standard_False;
832 BRepTools_ShapeSet SS(B);
835 if(!SS.NbShapes()) return Standard_False;
837 return Standard_True;
841 //=======================================================================
844 //=======================================================================
846 void BRepTools::Clean(const TopoDS_Shape& theShape)
848 BRep_Builder aBuilder;
849 Handle(Poly_Triangulation) aNullTriangulation;
850 Handle(Poly_PolygonOnTriangulation) aNullPoly;
852 if (theShape.IsNull())
855 TopExp_Explorer aFaceIt(theShape, TopAbs_FACE);
856 for (; aFaceIt.More(); aFaceIt.Next())
858 const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
860 TopLoc_Location aLoc;
861 const Handle(Poly_Triangulation)& aTriangulation =
862 BRep_Tool::Triangulation(aFace, aLoc);
864 if (aTriangulation.IsNull())
868 TopExp_Explorer aEdgeIt(aFace, TopAbs_EDGE);
869 for (; aEdgeIt.More(); aEdgeIt.Next())
871 const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current());
872 aBuilder.UpdateEdge(aEdge, aNullPoly, aTriangulation, aLoc);
875 aBuilder.UpdateFace(aFace, aNullTriangulation);
879 //=======================================================================
880 //function : RemoveUnusedPCurves
882 //=======================================================================
884 void BRepTools::RemoveUnusedPCurves(const TopoDS_Shape& S)
886 TColStd_MapOfTransient UsedSurfaces;
888 TopExp_Explorer Explo(S, TopAbs_FACE);
889 for (; Explo.More(); Explo.Next())
891 TopoDS_Face aFace = TopoDS::Face(Explo.Current());
892 TopLoc_Location aLoc;
893 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
894 UsedSurfaces.Add(aSurf);
897 TopTools_IndexedMapOfShape Emap;
898 TopExp::MapShapes(S, TopAbs_EDGE, Emap);
901 for (i = 1; i <= Emap.Extent(); i++)
903 const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &Emap(i).TShape());
904 BRep_ListOfCurveRepresentation& lcr = TE -> ChangeCurves();
905 BRep_ListIteratorOfListOfCurveRepresentation itrep(lcr );
908 Standard_Boolean ToRemove = Standard_False;
910 Handle(BRep_CurveRepresentation) CurveRep = itrep.Value();
911 if (CurveRep->IsCurveOnSurface())
913 Handle(Geom_Surface) aSurface = CurveRep->Surface();
914 if (!UsedSurfaces.Contains(aSurface))
915 ToRemove = Standard_True;
917 else if (CurveRep->IsRegularity())
919 Handle(Geom_Surface) Surf1 = CurveRep->Surface();
920 Handle(Geom_Surface) Surf2 = CurveRep->Surface2();
921 ToRemove = (!UsedSurfaces.Contains(Surf1) || !UsedSurfaces.Contains(Surf2));
932 //=======================================================================
933 //function : Triangulation
935 //=======================================================================
937 Standard_Boolean BRepTools::Triangulation(const TopoDS_Shape& S,
938 const Standard_Real deflec)
940 TopExp_Explorer exf, exe;
942 Handle(Poly_Triangulation) T;
943 Handle(Poly_PolygonOnTriangulation) Poly;
945 for (exf.Init(S, TopAbs_FACE); exf.More(); exf.Next()) {
946 const TopoDS_Face& F = TopoDS::Face(exf.Current());
947 T = BRep_Tool::Triangulation(F, l);
948 if (T.IsNull() || (T->Deflection() > deflec))
949 return Standard_False;
950 for (exe.Init(F, TopAbs_EDGE); exe.More(); exe.Next()) {
951 const TopoDS_Edge& E = TopoDS::Edge(exe.Current());
952 Poly = BRep_Tool::PolygonOnTriangulation(E, T, l);
953 if (Poly.IsNull()) return Standard_False;
956 return Standard_True;
960 //=======================================================================
961 //function : IsReallyClosed
963 //=======================================================================
965 Standard_Boolean BRepTools::IsReallyClosed(const TopoDS_Edge& E,
966 const TopoDS_Face& F)
968 if (!BRep_Tool::IsClosed(E,F)) {
969 return Standard_False;
971 Standard_Integer nbocc = 0;
973 for (exp.Init(F,TopAbs_EDGE);exp.More();exp.Next()) {
974 if (exp.Current().IsSame(E)) {
981 //=======================================================================
982 //function : EvalAndUpdateTol
984 //=======================================================================
986 Standard_Real BRepTools::EvalAndUpdateTol(const TopoDS_Edge& theE,
987 const Handle(Geom_Curve)& C3d,
988 const Handle(Geom2d_Curve) C2d,
989 const Handle(Geom_Surface)& S,
990 const Standard_Real f,
991 const Standard_Real l)
993 Standard_Real newtol = 0.;
994 Standard_Real first = f, last = l;
995 //Set first, last to avoid ErrosStatus = 2 because of
996 //too strong checking of limits in class CheckCurveOnSurface
998 if(!C3d->IsPeriodic())
1000 first = Max(first, C3d->FirstParameter());
1001 last = Min(last, C3d->LastParameter());
1003 if(!C2d->IsPeriodic())
1005 first = Max(first, C2d->FirstParameter());
1006 last = Min(last, C2d->LastParameter());
1009 GeomLib_CheckCurveOnSurface CT(C3d, S, first, last);
1013 newtol = CT.MaxDistance();
1017 if(CT.ErrorStatus() == 3 || (CT.ErrorStatus() == 2 &&
1018 (C3d->IsPeriodic() || C2d->IsPeriodic())))
1020 //Try to estimate by sample points
1021 Standard_Integer nbint = 22;
1022 Standard_Real dt = (last - first) / nbint;
1023 dt = Max(dt, Precision::Confusion());
1024 Standard_Real d, dmax = 0.;
1027 Standard_Integer cnt = 0;
1028 Standard_Real t = first;
1029 for(; t <= last; t += dt)
1034 S->D0(aP2d.X(), aP2d.Y(), aPS);
1035 d = aPS.SquareDistance(aPC);
1046 S->D0(aP2d.X(), aP2d.Y(), aPS);
1047 d = aPS.SquareDistance(aPC);
1054 newtol = 1.2 * Sqrt(dmax);
1057 Standard_Real Tol = BRep_Tool::Tolerance(theE);
1062 B.UpdateEdge(theE, Tol);