]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
#669: draft implementation of the merge algorithm
authorasl <asl@opencascade.com>
Thu, 15 Oct 2015 12:06:03 +0000 (15:06 +0300)
committerasl <asl@opencascade.com>
Thu, 15 Oct 2015 12:06:03 +0000 (15:06 +0300)
src/HYDROData/HYDROData_LandCoverMap.cxx
src/HYDROData/HYDROData_LandCoverMap.h
src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx
src/HYDRO_tests/test_HYDROData_LandCoverMap.h

index 76ec9364b020136edc0306701c2a7eed91a610f5..8efeb107b6e206b2b22889ad61a25ed75ccb97b3 100644 (file)
@@ -21,6 +21,7 @@
 #include <HYDROData_PolylineXY.h>
 #include <HYDROData_Tool.h>
 
+#include <BOPAlgo_BOP.hxx>
 #include <BOPAlgo_Builder.hxx>
 #include <BOPAlgo_PaveFiller.hxx>
 #include <BOPCol_ListOfShape.hxx>
@@ -293,13 +294,25 @@ bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const
   Remove( theFaces );
 
   // 2. to fuse the faces into the new face
-  BRepAlgoAPI_Fuse aFuse;
-  aFuse.SetArguments( theFaces );
-  aFuse.Build();
-  if( !aFuse.IsDone() )
+  BOPAlgo_PaveFiller aPF;
+  aPF.SetArguments( theFaces );
+  aPF.SetFuzzyValue( 1E-2 ); 
+  aPF.SetRunParallel( Standard_False );
+  aPF.Perform();
+  int iErr = aPF.ErrorStatus();
+  if( iErr )
     return false;
 
-  TopoDS_Shape aMergedShape = aFuse.Shape();
+  BOPAlgo_BOP aBOP;
+  aBOP.SetArguments( theFaces );
+  aBOP.SetOperation( BOPAlgo_FUSE );
+  aBOP.SetRunParallel( Standard_False );
+  aBOP.PerformWithFiller(aPF);
+  iErr = aBOP.ErrorStatus();
+  if( iErr )
+    return false;
+
+  TopoDS_Shape aMergedShape = aBOP.Shape();
   if( aMergedShape.ShapeType()!=TopAbs_FACE )
     return false;
 
@@ -436,3 +449,24 @@ void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfFaceToStrickl
 
   SetShape( aCompound );
 }
+
+/**
+  Find the land cover for the given point
+  @param thePoint the point laying in some land cover
+  @param theType the returned type
+  @return the found land cover's face
+*/
+TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QString& theType ) const
+{
+  //TODO: some more optimal algorithm
+  Iterator anIt( *this );
+  for( ; anIt.More(); anIt.Next() )
+    if( HYDROData_Tool::ComputePointState( thePoint.XY(), anIt.Face() ) == TopAbs_IN )
+    {
+      theType = anIt.StricklerType();
+      return anIt.Face();
+    }
+
+  theType = "";
+  return TopoDS_Face();
+}
index ba5c5f685303fdcd5ba1921a634c2aa6bf1080ce..3c0c834d57f9bf857e99a1390546298b2630c40a 100644 (file)
@@ -31,6 +31,7 @@ class TopTools_ListOfShape;
 class Handle( HYDROData_PolylineXY );
 class Handle( HYDROData_Object );
 class HYDROData_MapOfFaceToStricklerType;
+class gp_Pnt2d;
 
 class HYDROData_LandCoverMap : public HYDROData_Entity
 {
@@ -83,6 +84,8 @@ public:
   bool Split( const Handle( HYDROData_PolylineXY )& );
   bool Merge( const TopTools_ListOfShape&, const QString& theType );
 
+  TopoDS_Face FindByPoint( const gp_Pnt2d&, QString& theType ) const;
+
 protected:
   TopoDS_Shape GetShape() const;
   void SetShape( const TopoDS_Shape& );
index b2c3ac69534cdae00d138ae0a9ba00461bce8cf9..7eb33b15eb3639b2703da1864b31243452c71268 100644 (file)
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
 #include <TestViewer.h>
+#include <TopTools_ListOfShape.hxx>
 #include <AIS_DisplayMode.hxx>
 #include <QString>
 #include <QColor>
 
+#include <BRepTools.hxx>
+
 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
 {
   int n = theXYList.size()/2;
@@ -118,7 +121,7 @@ void test_HYDROData_LandCoverMap::test_split_by_polyline()
   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
 
   TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
-  //TestViewer::show( aWire, QColor(), 0 );
+  TestViewer::show( aWire, QColor(), 0 );
   TestViewer::AssertEqual( "LandCoverMap_Split_1" );
 
   HYDROData_LandCoverMap::Iterator anIt( aMap );
@@ -132,3 +135,46 @@ void test_HYDROData_LandCoverMap::test_split_by_polyline()
 
   aDoc->Close();
 }
+
+void test_HYDROData_LandCoverMap::test_merge()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_LandCoverMap) aMap =
+    Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+
+  CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
+
+  TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
+
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+  TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
+                                                   44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
+                                                  128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
+                                                  31 << 114 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
+
+  TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
+                                                 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
+
+  //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+  //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
+
+  //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
+
+  QString aType1, aType2;
+  gp_Pnt2d aPnt1( 25, 35 );
+  gp_Pnt2d aPnt2( 45, 55 );
+  TopTools_ListOfShape aList;
+  aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
+  aList.Append( aMap->FindByPoint( aPnt2, 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::AssertEqual( "LandCoverMap_Merge_1" );
+
+  aDoc->Close();
+}
index 95684210bedd4a17102bb765d6d80f0fedc1d120..726e4ffb8c2beccac922c8f4e2f050527a928fd5 100644 (file)
@@ -27,11 +27,13 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST_SUITE( test_HYDROData_LandCoverMap );
   CPPUNIT_TEST( test_add_2_objects );
   CPPUNIT_TEST( test_split_by_polyline );
+  CPPUNIT_TEST( test_merge );
   CPPUNIT_TEST_SUITE_END();
 
 public:
   void test_add_2_objects();
   void test_split_by_polyline();
+  void test_merge();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );