]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
MergeFaces()
authorisn <isn@opencascade.com>
Fri, 16 Oct 2015 09:04:26 +0000 (12:04 +0300)
committerisn <isn@opencascade.com>
Fri, 16 Oct 2015 09:04:26 +0000 (12:04 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDRO_tests/CMakeLists.txt
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx

index 8efeb107b6e206b2b22889ad61a25ed75ccb97b3..1af26fdb902f4fd4c63970e07c81268dd3400deb 100644 (file)
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Shell.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <BOPAlgo_PaveFiller.hxx>
+#include <BRepTools.hxx>
+#include <TopExp_Explorer.hxx>
+#include <ShapeUpgrade_UnifySameDomain.hxx>
 
 #include <QString>
 
@@ -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;
+
 }
 
 /**
index 3c0c834d57f9bf857e99a1390546298b2630c40a..09ae68eb4bd4276848a41e7b471b7ee097b55c03 100644 (file)
@@ -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:
index 08731d0fa169e5ce7e19f774e2a0597eb5858be9..0fdeb4e43ffef9919b9fe0d06efa86f8949d951f 100644 (file)
@@ -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 )
 
index 7eb33b15eb3639b2703da1864b31243452c71268..b29a3bbea12f95a332441b61d7cfb623071f8f14 100644 (file)
@@ -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();