// File: BRepTools.cxx // Created: Thu Jan 21 19:59:19 1993 // Author: Remi LEQUETTE // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //======================================================================= //function : UVBounds //purpose : //======================================================================= void BRepTools::UVBounds(const TopoDS_Face& F, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax) { Bnd_Box2d B; AddUVBounds(F,B); B.Get(UMin,VMin,UMax,VMax); } //======================================================================= //function : UVBounds //purpose : //======================================================================= void BRepTools::UVBounds(const TopoDS_Face& F, const TopoDS_Wire& W, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax) { Bnd_Box2d B; AddUVBounds(F,W,B); B.Get(UMin,VMin,UMax,VMax); } //======================================================================= //function : UVBounds //purpose : //======================================================================= void BRepTools::UVBounds(const TopoDS_Face& F, const TopoDS_Edge& E, Standard_Real& UMin, Standard_Real& UMax, Standard_Real& VMin, Standard_Real& VMax) { Bnd_Box2d B; AddUVBounds(F,E,B); B.Get(UMin,VMin,UMax,VMax); } //======================================================================= //function : AddUVBounds //purpose : //======================================================================= void BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B) { TopoDS_Face F = FF; F.Orientation(TopAbs_FORWARD); TopExp_Explorer ex(F,TopAbs_EDGE); // fill box for the given face Bnd_Box2d aBox; for (;ex.More();ex.Next()) { BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),aBox); } // if the box is empty (face without edges or without pcurves), // get natural bounds if (aBox.IsVoid()) { Standard_Real UMin,UMax,VMin,VMax; TopLoc_Location L; BRep_Tool::Surface(F,L)->Bounds(UMin,UMax,VMin,VMax); aBox.Update(UMin,VMin,UMax,VMax); } // add face box to result B.Add ( aBox ); } //======================================================================= //function : AddUVBounds //purpose : //======================================================================= void BRepTools::AddUVBounds(const TopoDS_Face& F, const TopoDS_Wire& W, Bnd_Box2d& B) { TopExp_Explorer ex; for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) { BRepTools::AddUVBounds(F,TopoDS::Edge(ex.Current()),B); } } //======================================================================= //function : AddUVBounds //purpose : //======================================================================= void BRepTools::AddUVBounds(const TopoDS_Face& F, const TopoDS_Edge& E, Bnd_Box2d& B) { Standard_Real pf,pl; Bnd_Box2d Baux; const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl); if (pl < pf) { // Petit Blindage Standard_Real aux; aux = pf; pf = pl; pl = aux; } if (C.IsNull()) return; Geom2dAdaptor_Curve PC(C,pf,pl); if (Precision::IsNegativeInfinite(pf) || Precision::IsPositiveInfinite(pf)) { Geom2dAdaptor_Curve GC(PC); BndLib_Add2dCurve::Add(GC,0.,B); } else { // just compute points to get a close box. TopLoc_Location L; Standard_Real Umin,Umax,Vmin,Vmax; const Handle(Geom_Surface)& Surf=BRep_Tool::Surface(F,L); Surf->Bounds(Umin,Umax,Vmin,Vmax); gp_Pnt2d Pa,Pb,Pc; Standard_Real i, nbp = 20; if (PC.GetType() == GeomAbs_Line) nbp = 2; Standard_Real step = (pl - pf) / nbp; gp_Pnt2d P; PC.D0(pf,P); Baux.Add(P); Standard_Real du=0.0; Standard_Real dv=0.0; Pc=P; for (i = 1; i < nbp; i++) { pf += step; PC.D0(pf,P); Baux.Add(P); if(i==1) { Pb=Pc; Pc=P; } else { //-- Calcul de la fleche Pa=Pb; Pb=Pc; Pc=P; gp_Vec2d PaPc(Pa,Pc); // gp_Lin2d L2d(Pa,PaPc); // Standard_Real up = ElCLib::Parameter(L2d,Pb); // gp_Pnt2d PProj = ElCLib::Value(up,L2d); gp_Pnt2d PProj(Pa.Coord()+(PaPc.XY()/2.)); Standard_Real ddu=Abs(Pb.X()-PProj.X()); Standard_Real ddv=Abs(Pb.Y()-PProj.Y()); if(ddv>dv) dv=ddv; if(ddu>du) du=ddu; } } PC.D0(pl,P); Baux.Add(P); //-- cout<<" du="< improve performance // do { // BRep_Tool::PolygonOnTriangulation(E, Poly, T, L); // B.UpdateEdge(E, PolyNULL, T, L); // } while(!Poly.IsNull()); // Handle(BRep_CurveRepresentation) cr; const Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &E.TShape()); BRep_ListOfCurveRepresentation& lcr = TE -> ChangeCurves(); BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr); // find and remove all representations while (itcr.More()) { cr = itcr.Value(); if (cr->IsPolygonOnTriangulation()) lcr.Remove(itcr); else itcr.Next(); } TE->Modified(Standard_True); // agv : fin } } } //======================================================================= //function : Triangulation //purpose : //======================================================================= Standard_Boolean BRepTools::Triangulation(const TopoDS_Shape& S, const Standard_Real deflec) { TopExp_Explorer exf, exe; TopLoc_Location l; Handle(Poly_Triangulation) T; Handle(Poly_PolygonOnTriangulation) Poly; for (exf.Init(S, TopAbs_FACE); exf.More(); exf.Next()) { const TopoDS_Face& F = TopoDS::Face(exf.Current()); T = BRep_Tool::Triangulation(F, l); if (T.IsNull() || (T->Deflection() > deflec)) return Standard_False; for (exe.Init(F, TopAbs_EDGE); exe.More(); exe.Next()) { const TopoDS_Edge& E = TopoDS::Edge(exe.Current()); Poly = BRep_Tool::PolygonOnTriangulation(E, T, l); if (Poly.IsNull()) return Standard_False; } } return Standard_True; } //======================================================================= //function : IsReallyClosed //purpose : //======================================================================= Standard_Boolean BRepTools::IsReallyClosed(const TopoDS_Edge& E, const TopoDS_Face& F) { if (!BRep_Tool::IsClosed(E,F)) { return Standard_False; } Standard_Integer nbocc = 0; TopExp_Explorer exp; for (exp.Init(F,TopAbs_EDGE);exp.More();exp.Next()) { if (exp.Current().IsSame(E)) { nbocc++; } } return nbocc == 2; }