From 435a10574b561be07841fa3e9e5ce0eb45c7f248 Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 14 Dec 2007 09:46:51 +0000 Subject: [PATCH] NPAL18111: Bad shape build by partition. --- src/GEOMAlgo/GEOMAlgo_FinderShapeOn.cxx | 57 +++++++++++++++++++++++- src/GEOMAlgo/GEOMAlgo_FinderShapeOn.hxx | 4 +- src/GEOMAlgo/GEOMAlgo_FinderShapeOn1.cxx | 15 +++++-- src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx | 15 +++++-- 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.cxx b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.cxx index c3a5b7cfc..237e81ef4 100644 --- a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.cxx +++ b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.cxx @@ -44,6 +44,10 @@ #include #include +#include +#include +#include + #include #include @@ -527,6 +531,58 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE, // aEx.Free(bFree); } +// +//======================================================================= +//function : BuildTriangulation +//purpose : +//======================================================================= +bool GEOMAlgo_FinderShapeOn::BuildTriangulation (const TopoDS_Shape& theShape) +{ + // calculate deflection + Standard_Real aDeviationCoefficient = 0.001; + + Bnd_Box B; + BRepBndLib::Add(theShape, B); + Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + + Standard_Real dx = aXmax - aXmin, dy = aYmax - aYmin, dz = aZmax - aZmin; + Standard_Real aDeflection = Max(Max(dx, dy), dz) * aDeviationCoefficient * 4; + Standard_Real aHLRAngle = 0.349066; + + // build triangulation + BRepMesh_IncrementalMesh Inc (theShape, aDeflection, Standard_False, aHLRAngle); + + // check triangulation + bool isTriangulation = true; + + TopExp_Explorer exp (theShape, TopAbs_FACE); + if (exp.More()) + { + TopLoc_Location aTopLoc; + Handle(Poly_Triangulation) aTRF; + aTRF = BRep_Tool::Triangulation(TopoDS::Face(exp.Current()), aTopLoc); + if (aTRF.IsNull()) { + isTriangulation = false; + } + } + else // no faces, try edges + { + TopExp_Explorer expe (theShape, TopAbs_EDGE); + if (!expe.More()) { + isTriangulation = false; + } + else { + TopLoc_Location aLoc; + Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(TopoDS::Edge(expe.Current()), aLoc); + if (aPE.IsNull()) { + isTriangulation = false; + } + } + } + + return isTriangulation; +} // // myErrorStatus : @@ -544,4 +600,3 @@ void GEOMAlgo_FinderShapeOn::CopySource(const TopoDS_Shape& aE, // myWarningStatus // // 10 -subshapes of type myShapeType can not be fond in myShape - diff --git a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.hxx b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.hxx index fbc85f0d9..6053ad654 100644 --- a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.hxx +++ b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn.hxx @@ -111,9 +111,7 @@ Standard_EXPORT const TopTools_ListOfShape& Shapes() const; Standard_EXPORT static void CopySource(const TopoDS_Shape& aS,TopTools_DataMapOfShapeShape& aImages,TopTools_DataMapOfShapeShape& aOriginals,TopoDS_Shape& aSC) ; - - - +Standard_EXPORT static bool BuildTriangulation (const TopoDS_Shape& theShape); protected: diff --git a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn1.cxx b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn1.cxx index 78c540b08..6f9f6a0b4 100644 --- a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn1.cxx +++ b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn1.cxx @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -543,8 +544,11 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF, // aTRF=BRep_Tool::Triangulation(aF, aLoc); if (aTRF.IsNull()) { - myErrorStatus=20; // no triangulation found - return; + if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aF)) { + myErrorStatus=20; // no triangulation found + return; + } + aTRF=BRep_Tool::Triangulation(aF, aLoc); } // const gp_Trsf& aTrsf=aLoc.Transformation(); @@ -691,8 +695,11 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE, if (aTRE.IsNull() || aPTE.IsNull()) { Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(aE, aLoc); if (aPE.IsNull()) { - myErrorStatus=20; // no triangulation found - return; + if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aE)) { + myErrorStatus=20; // no triangulation found + return; + } + aPE = BRep_Tool::Polygon3D(aE, aLoc); } const gp_Trsf& aTrsf=aLoc.Transformation(); const TColgp_Array1OfPnt& aNodes=aPE->Nodes(); diff --git a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx index 9d8ff5a23..ebc34e718 100644 --- a/src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx +++ b/src/GEOMAlgo/GEOMAlgo_FinderShapeOn2.cxx @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -603,8 +604,11 @@ // aTRF=BRep_Tool::Triangulation(aF, aLoc); if (aTRF.IsNull()) { - myErrorStatus=20; // no triangulation found - return; + if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aF)) { + myErrorStatus=20; // no triangulation found + return; + } + aTRF=BRep_Tool::Triangulation(aF, aLoc); } // const gp_Trsf& aTrsf=aLoc.Transformation(); @@ -751,8 +755,11 @@ if (aTRE.IsNull() || aPTE.IsNull()) { Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(aE, aLoc); if (aPE.IsNull()) { - myErrorStatus=20; // no triangulation found - return; + if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aE)) { + myErrorStatus=20; // no triangulation found + return; + } + aPE = BRep_Tool::Polygon3D(aE, aLoc); } const gp_Trsf& aTrsf=aLoc.Transformation(); const TColgp_Array1OfPnt& aNodes=aPE->Nodes(); -- 2.30.2