From: isn Date: Fri, 16 Oct 2015 09:04:26 +0000 (+0300) Subject: MergeFaces() X-Git-Tag: v1.5~110 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3f9ac22f1a9e9a5eb1e1005fa5c94566909430fe;p=modules%2Fhydro.git MergeFaces() --- diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 8efeb107..1af26fdb 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -35,6 +35,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -294,7 +298,7 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const Remove( theFaces ); // 2. to fuse the faces into the new face - BOPAlgo_PaveFiller aPF; + /*BOPAlgo_PaveFiller aPF; aPF.SetArguments( theFaces ); aPF.SetFuzzyValue( 1E-2 ); aPF.SetRunParallel( Standard_False ); @@ -314,10 +318,90 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const TopoDS_Shape aMergedShape = aBOP.Shape(); if( aMergedShape.ShapeType()!=TopAbs_FACE ) - return false; + return false;*/ + + + //// + TopoDS_Shape MergedFace; + MergeFaces(theFaces, true, MergedFace); + //BRepTools::Write(aMergedShape, "c:/sh_.brep"); // 3. to add the face into the map - return LocalPartition( TopoDS::Face( aMergedShape ), theType ); + return LocalPartition( TopoDS_Face( /*aMergedShape*/ ), theType ); +} + +bool HYDROData_LandCoverMap::MergeFaces(const TopTools_ListOfShape& theFaces, bool IsToUnify, TopoDS_Shape& outSh) +{ + int iErr; + TopTools_ListIteratorOfListOfShape aIt; + BOPCol_ListOfShape aLC; + aIt.Initialize(theFaces); + for (; aIt.More(); aIt.Next()) { + const TopoDS_Shape& aS=aIt.Value(); + aLC.Append(aS); + } + BOPAlgo_PaveFiller aPF; + aPF.SetArguments(aLC); + aPF.SetRunParallel(Standard_False); + aPF.SetFuzzyValue(1e-02); + + aPF.Perform(); + iErr=aPF.ErrorStatus(); + if (iErr) + return false; + + BOPAlgo_Builder aBuilder; + aIt.Initialize(theFaces); + for (; aIt.More(); aIt.Next()) { + const TopoDS_Shape& aS=aIt.Value(); + aBuilder.AddArgument(aS); + } + + aBuilder.PerformWithFiller(aPF); + iErr = aBuilder.ErrorStatus(); + if (iErr) + return false; + const TopoDS_Shape& aMergedShape=aBuilder.Shape(); + + // + BRep_Builder BB; + TopoDS_Shell she; + BB.MakeShell(she); + she.Closed(Standard_False); + TopExp_Explorer ff(aMergedShape, TopAbs_FACE); + for(; ff.More(); ff.Next()) + { + const TopoDS_Face& F = TopoDS::Face(ff.Current()); + if (F.IsNull()) + continue; + if (F.ShapeType() == TopAbs_FACE) { + BB.Add(she, F); + she.Closed (Standard_False); + } + } + + if (IsToUnify) + { + ShapeUpgrade_UnifySameDomain USD; + USD.Initialize(she); + USD.Build(); + outSh = USD.Shape(); + } + else + { + outSh = she; + } + + ff.Init(outSh, TopAbs_FACE); + int i = 0; + TopoDS_Face OneF; + for(; ff.More(); ff.Next(), i++) + OneF = TopoDS::Face(ff.Current()); + if (i == 1) + outSh = OneF; + + return true; + } /** diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 3c0c834d..09ae68eb 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -91,6 +91,7 @@ protected: void SetShape( const TopoDS_Shape& ); bool LocalPartition( const TopoDS_Shape&, const QString& theNewType ); + bool MergeFaces(const TopTools_ListOfShape& theFaces, bool IsToUnify, TopoDS_Shape& outSh); void StoreLandCovers( const HYDROData_MapOfFaceToStricklerType& ); public: diff --git a/src/HYDRO_tests/CMakeLists.txt b/src/HYDRO_tests/CMakeLists.txt index 08731d0f..0fdeb4e4 100644 --- a/src/HYDRO_tests/CMakeLists.txt +++ b/src/HYDRO_tests/CMakeLists.txt @@ -48,7 +48,7 @@ ENDIF() SET( BOOST_INCLUDES $ENV{BOOST_ROOT_DIR}/include/boost-1_52 ) SET( CPPUNIT_INCLUDES $ENV{CPPUNIT_ROOT_DIR}/include ) -SET( CAS_INCLUDES $ENV{CASROOT_DIR}/inc ) +SET( CAS_INCLUDES $ENV{CAS_ROOT_DIR}/inc ) SET( QT_INCLUDES $ENV{QT4_ROOT_DIR}/include $ENV{QT4_ROOT_DIR}/include/QtCore $ENV{QT4_ROOT_DIR}/include/QtGui ) SET( GUI_INCLUDES $ENV{GUI_ROOT_DIR}/include/salome ) diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 7eb33b15..b29a3bbe 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -167,13 +167,17 @@ void test_HYDROData_LandCoverMap::test_merge() QString aType1, aType2; gp_Pnt2d aPnt1( 25, 35 ); gp_Pnt2d aPnt2( 45, 55 ); + //gp_Pnt2d aPnt3( 45, 10 ); + //gp_Pnt2d aPnt4( 45, 80 ); TopTools_ListOfShape aList; aList.Append( aMap->FindByPoint( aPnt1, aType1 ) ); aList.Append( aMap->FindByPoint( aPnt2, aType2 ) ); + //aList.Append( aMap->FindByPoint( aPnt3, aType1 ) ); + //aList.Append( aMap->FindByPoint( aPnt4, aType2 ) ); CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) ); TestViewer::show( aMap->GetShape(), AIS_Shaded, true ); - //TestViewer::show( BRepBuilderAPI_MakeEdge( aPnt1, aPnt2 ).Edge(), QColor( Qt::black ), AIS_Shaded ); + //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded ); TestViewer::AssertEqual( "LandCoverMap_Merge_1" ); aDoc->Close();