From 23a6f7b3e29e74735d71d7e1448465a9920f91dd Mon Sep 17 00:00:00 2001 From: isn Date: Tue, 30 Jun 2015 14:55:53 +0300 Subject: [PATCH] Deny to create landcovers on the self-intersection wires/polyline --- src/HYDROData/HYDROData_LandCover.cxx | 48 +++++++++++++++++++++------ 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/HYDROData/HYDROData_LandCover.cxx b/src/HYDROData/HYDROData_LandCover.cxx index 815bc3b5..278f42c5 100644 --- a/src/HYDROData/HYDROData_LandCover.cxx +++ b/src/HYDROData/HYDROData_LandCover.cxx @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include #include @@ -197,7 +200,7 @@ void HYDROData_LandCover::removeShape() aLabel.ForgetAllAttributes(); } } - + TopoDS_Shape HYDROData_LandCover::buildShape( const HYDROData_SequenceOfObjects& thePolylines, TCollection_AsciiString& theErrorMsg ) { @@ -261,27 +264,50 @@ TopoDS_Shape HYDROData_LandCover::buildShape( const HYDROData_SequenceOfObjects& if ( aClosedWires.Extent() == 1 ) { // make face - BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aClosedWires.First() ) ); + TopoDS_Wire aW = TopoDS::Wire( aClosedWires.First()); + BRepBuilderAPI_MakeFace aMakeFace( aW ); aMakeFace.Build(); - if( aMakeFace.IsDone() ) { - aResShape = aMakeFace.Face(); + if( aMakeFace.IsDone() ) + { + Handle(ShapeAnalysis_Wire) aSAW = new ShapeAnalysis_Wire(aW, aMakeFace.Face(), Precision::Confusion()); + if (!aSAW->CheckSelfIntersection()) + aResShape = aMakeFace.Face(); + else + theErrorMsg = "Can't create landcover on the given polyline\nSelf-intersection of wire have been detected"; } } else if ( aClosedWires.Extent() > 1 ) { // make compound BRep_Builder aBuilder; TopoDS_Compound aCompound; aBuilder.MakeCompound( aCompound ); - + TopTools_SequenceOfShape aSeq; TopTools_ListIteratorOfListOfShape aWiresIter( aClosedWires ); - for ( ; aWiresIter.More(); aWiresIter.Next() ) { - BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( aWiresIter.Value() ) ); + bool anErrStat = false; + for ( ; aWiresIter.More() && !anErrStat; aWiresIter.Next() ) + { + TopoDS_Wire aW = TopoDS::Wire( aWiresIter.Value() ); + BRepBuilderAPI_MakeFace aMakeFace( aW ); aMakeFace.Build(); - if( aMakeFace.IsDone() ) { - aBuilder.Add( aCompound, aMakeFace.Face() ); + if( aMakeFace.IsDone() ) + { + Handle(ShapeAnalysis_Wire) aSAW = new ShapeAnalysis_Wire(aW, aMakeFace.Face(), Precision::Confusion()); + if (!aSAW->CheckSelfIntersection()) + aSeq.Append( aMakeFace.Face() ); + else + { + anErrStat = true; + theErrorMsg = "Can't create landcover on the given polyline\nSelf-intersection of wire(s) have been detected"; + } } } - - aResShape = aCompound; + if (!anErrStat) + { + for (int i = 1; i <= aSeq.Length(); i++) + aBuilder.Add( aCompound, aSeq(i) ); + aResShape = aCompound; + } + else + aResShape = TopoDS_Shape(); } else if ( aNbPolylines > 0 ) { TCollection_AsciiString aSourceName = aNbPolylines > 1 ? "polylines" : "polyline"; theErrorMsg = "Can't build closed contour on the given "; -- 2.39.2