Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_LandCoverMap.cxx
index 76f6a7f5ee8e60337ff6469778db006fe9124d84..8b0fed78a6f510b004093cce123c32c603c17658 100644 (file)
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 #include <BRepCheck_Analyzer.hxx>
+#include <OSD_Timer.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
 
-const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test/HYDRO";
+const QString REF_DATA_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/bin/salome/test";
 const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
 
 void test_HYDROData_LandCoverMap::test_add_2_objects()
@@ -904,14 +906,13 @@ void test_HYDROData_LandCoverMap::test_shp_loop_back()
 
   //This test verify only some geom data (shp+shx) without any dbf reading/writing 
   {
-    DEBTRACE("aFFileName: " << aFFileName.toStdString());
-    DEBTRACE("aSFileName: " << aSFileName.toStdString());
+    //DEBTRACE("aFFileName: " << aFFileName.toStdString());
+    //DEBTRACE("aSFileName: " << aSFileName.toStdString());
     Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
     HYDROData_ShapeFile anImporter;
     QStringList PolygonList;
     TopTools_SequenceOfShape PolygonFaces;
     int Type = -1;
-    DEBTRACE("---");
 
     //import LCM from file (#2-4; #12-14 polygons)
     CPPUNIT_ASSERT( anImporter.ImportPolygons(aDoc, aFFileName, PolygonList, PolygonFaces, Type));
@@ -924,7 +925,6 @@ void test_HYDROData_LandCoverMap::test_shp_loop_back()
     aMapFace2ST.Add( TopoDS::Face( PolygonFaces(12) ), "" );
     aMapFace2ST.Add( TopoDS::Face( PolygonFaces(13) ), "" );
     aMapFace2ST.Add( TopoDS::Face( PolygonFaces(14) ), "" );
-    DEBTRACE("---");
 
     LCM->StoreLandCovers(aMapFace2ST);
     LCM->SetName("lcm_1");
@@ -936,9 +936,8 @@ void test_HYDROData_LandCoverMap::test_shp_loop_back()
     //export lcm
     HYDROData_ShapeFile anExporter;
     QStringList aNonExpList;
-    anExporter.Export(aSFileName, LCM, aNonExpList);
+    anExporter.Export(aDoc, aSFileName, LCM, aNonExpList);
     CPPUNIT_ASSERT (aNonExpList.empty());
-    DEBTRACE("---");
 
     aDoc->Close();
   }
@@ -1148,3 +1147,134 @@ void test_HYDROData_LandCoverMap::test_copy()
 
   aDoc->Close();
 }
+
+void test_HYDROData_LandCoverMap::test_shp_clc_classification_perf()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  QString aFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
+  HYDROData_ShapeFile anImporter;
+  QStringList PolygonList;
+  TopTools_SequenceOfShape PolygonFaces;
+  int Type = -1;
+  int aStat = anImporter.ImportPolygons(aDoc, aFileName, PolygonList, PolygonFaces, Type);
+  CPPUNIT_ASSERT(aStat == 1);
+  CPPUNIT_ASSERT_EQUAL(5, Type);
+  CPPUNIT_ASSERT_EQUAL(625, PolygonFaces.Length());
+  
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+#ifdef NDEBUG
+  int SI = 100;
+  int EI = 300;
+#else
+  int SI = 150;
+  int EI = 200;
+#endif
+
+  for ( int i = SI; i <= EI; i++ )
+  {
+    TopoDS_Shape aShape = PolygonFaces(i);
+    if ( aShape.IsNull() ) 
+      continue;
+    aMapFace2ST.Add( TopoDS::Face( aShape ), "ST_" + QString::number(i) );
+  }
+
+  LCM->StoreLandCovers(aMapFace2ST);
+
+  std::vector<gp_XY> pnts;
+#ifdef NDEBUG
+  int N = 1000; //1000*1000 points; uniform distribution for release mode
+#else
+  int N = 100;
+#endif
+
+  pnts.reserve(N);
+  double x0 = 448646.91897505691;
+  double x1 = 487420.3990381231;
+  double y0 = 6373566.5122489957;
+  double y1 = 6392203.4117361344;
+  for (size_t i=0; i < N; i++)
+  {
+    for (size_t j=0; j < N; j++)
+    {
+      double px = x0 + (x1-x0)*((double)i/(double)N);
+      double py = y0 + (y1-y0)*((double)j/(double)N);
+      pnts.push_back(gp_XY(px,py));
+    }
+  }
+  OSD_Timer aTimer;
+  std::vector<std::set <QString> > TRes;  
+  aTimer.Start();
+  LCM->ClassifyPoints(pnts, TRes);
+  aTimer.Stop();
+#ifdef NDEBUG
+  CPPUNIT_ASSERT( aTimer.ElapsedTime() < 1.4);
+  aTimer.Show();
+#endif
+}
+
+void test_HYDROData_LandCoverMap::test_shp_clc_classification_check()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  QString aFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
+  HYDROData_ShapeFile anImporter;
+  QStringList PolygonList;
+  TopTools_SequenceOfShape PolygonFaces;
+  int Type = -1;
+  int aStat = anImporter.ImportPolygons(aDoc, aFileName, PolygonList, PolygonFaces, Type);
+  CPPUNIT_ASSERT(aStat == 1);
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(172) ), "Tissu urbain continu" );
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(179) ), "Aéroports" );
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(185) ), "Rizières" );
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(187) ), "Vignobles" );
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(190) ), "Oliveraies" );
+  aMapFace2ST.Add( TopoDS::Face( PolygonFaces(196) ), "Estuaires" );
+  
+  LCM->StoreLandCovers(aMapFace2ST);
+
+  TopoDS_Shape Sh = LCM->GetShape();
+
+  std::vector<gp_XY> pnts;
+  pnts.push_back(gp_XY(0,0));
+
+  pnts.push_back(gp_XY(468380, 6382300));
+  pnts.push_back(gp_XY(468380, 6382900));
+  pnts.push_back(gp_XY(468380, 6383200));
+  pnts.push_back(gp_XY(468250, 6384700));
+  pnts.push_back(gp_XY(470350, 6384700));
+  pnts.push_back(gp_XY(469279.642874048, 6385132.45048612 ));
+
+  std::vector<std::set <QString> > TRes;  
+  LCM->ClassifyPoints(pnts, TRes);
+
+  CPPUNIT_ASSERT (TRes[0].empty());
+  CPPUNIT_ASSERT (TRes[1].empty());
+  CPPUNIT_ASSERT (TRes[2].empty());
+  CPPUNIT_ASSERT_EQUAL (*TRes[3].begin(), QString("Estuaires"));
+  CPPUNIT_ASSERT_EQUAL (*TRes[4].begin(), QString("Oliveraies"));
+  CPPUNIT_ASSERT_EQUAL (*TRes[5].begin(), QString("Vignobles"));
+
+  //std::less comparator; so compare first and second elem safely
+  CPPUNIT_ASSERT_EQUAL (*TRes[6].begin(), QString("Estuaires"));
+  CPPUNIT_ASSERT_EQUAL (*(++TRes[6].begin()), QString("Tissu urbain continu"));
+
+  ///
+  Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+  CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
+  std::vector<double> coeffs;
+  LCM->ClassifyPoints(pnts, aTable, coeffs, 0.0, true);
+
+  CPPUNIT_ASSERT_EQUAL (coeffs[0], 0.0);
+  CPPUNIT_ASSERT_EQUAL (coeffs[1], 0.0);
+  CPPUNIT_ASSERT_EQUAL (coeffs[2], 0.0);
+  CPPUNIT_ASSERT_EQUAL (coeffs[3], 1.0522);
+  CPPUNIT_ASSERT_EQUAL (coeffs[4], 1.0223);
+  CPPUNIT_ASSERT_EQUAL (coeffs[5], 1.0221);
+  CPPUNIT_ASSERT_EQUAL (coeffs[6], 1.0522);
+
+}
+