]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
new tests for LCM classification BR_HYDRO_IMPS_TEST
authorisn <isn@opencascade.com>
Thu, 1 Sep 2016 11:12:08 +0000 (14:12 +0300)
committerisn <isn@opencascade.com>
Thu, 1 Sep 2016 14:16:33 +0000 (17:16 +0300)
src/HYDROData/HYDROData_LCM_FaceClassifier.cxx
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 b801df77bb1ed85b8ad6e8e507f4db0e3c1afd38..faf7678ff23cec6c5e38216e84c1be623b092255 100644 (file)
@@ -75,11 +75,11 @@ void HYDROData_LCM_FaceClassifier::Classify( const std::vector<gp_Pnt2d>& thePoi
   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box2d> aTreeFiller (aTree);
   NCollection_IndexedDataMap<TopoDS_Face, BRepTopAdaptor_FClass2d*> aMapF2Class2d;
 
-  int NbF= aFaces.Extent();
+  int NbF = aFaces.Extent();
   std::vector<BRepTopAdaptor_FClass2d*> fclass2dpointers;
   fclass2dpointers.reserve(NbF);
 
-  for (int i = 1; i < NbF; i++)
+  for (int i = 1; i <= NbF; i++)
   {
     Bnd_Box2d B;
     const TopoDS_Face& F = TopoDS::Face(aFaces(i));
index 7afb3132cdb25b1224543faf1a4c08cd5adc8872..f709b378cf92bca158f93bea3d210d1001d1ad29 100644 (file)
@@ -1264,3 +1264,32 @@ void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_Pnt2d>& thePoi
   HYDROData_LCM_FaceClassifier FC(this);
   FC.Classify(thePoints, theTypes, NULL);
 }
+
+void HYDROData_LandCoverMap::ClassifyPoints( const std::vector<gp_Pnt2d>& thePoints,  
+  Handle(HYDROData_StricklerTable) theTable, 
+  std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const
+{
+  std::vector<std::set <QString> > Types;
+  HYDROData_LCM_FaceClassifier FC(this);
+  FC.Classify(thePoints, Types, NULL);
+  theCoeffs.resize(thePoints.size());
+  for (size_t i = 0; i < Types.size(); i++)
+  {
+    const std::set<QString>& SStr = Types[i];
+    if (SStr.empty())
+      theCoeffs[i] = DefValue;
+    else
+    {
+      std::set<QString>::const_iterator it;
+      std::vector<double> C1(SStr.size());
+      for (it = SStr.begin(); it != SStr.end(); ++it)
+        C1.push_back(theTable->Get( *it, DefValue ));
+      double Val;
+      if (UseMax)
+        Val = *(std::max_element(std::begin(C1), std::end(C1)));
+      else
+        Val = *(std::min_element(std::begin(C1), std::end(C1)));
+      theCoeffs[i] = Val;
+    }
+  }
+}
index 43c074ba183ce89522b36b0d440385079b1c01fd..f0d17d17482627b4e36ffac3de932a823257c9b4 100644 (file)
@@ -152,6 +152,10 @@ public:
 
   HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_Pnt2d>& thePoints, std::vector<std::set <QString> >& theTypes ) const;
 
+  HYDRODATA_EXPORT void ClassifyPoints( const std::vector<gp_Pnt2d>& thePoints,
+    Handle(HYDROData_StricklerTable) theTable, 
+    std::vector<double>& theCoeffs, double DefValue, bool UseMax ) const;
+
 protected:
   void SetShape( const TopoDS_Shape& );
 
index 1b71f65242b6651c056e844b0da681ae4e128d68..df9deb4c9b47e1eecf2ca2e51db9d7090bb4d447 100644 (file)
@@ -43,6 +43,7 @@
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
 #include <BRepCheck_Analyzer.hxx>
+#include <OSD_Timer.hxx>
 
 #define _DEVDEBUG_
 #include "HYDRO_trace.hxx"
@@ -1146,7 +1147,7 @@ void test_HYDROData_LandCoverMap::test_copy()
   aDoc->Close();
 }
 
-void test_HYDROData_LandCoverMap::test_shp_clc_classification()
+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";
@@ -1162,7 +1163,15 @@ void test_HYDROData_LandCoverMap::test_shp_clc_classification()
   Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
   HYDROData_MapOfFaceToStricklerType aMapFace2ST;
 
-  for ( int i = 100; i <= 300; i++ )
+#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() ) 
@@ -1171,10 +1180,14 @@ void test_HYDROData_LandCoverMap::test_shp_clc_classification()
   }
 
   LCM->StoreLandCovers(aMapFace2ST);
-  //TopoDS_Shape aSh = LCM->GetShape();
 
   std::vector<gp_Pnt2d> pnts;
-  int N = 100000;
+#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;
@@ -1182,10 +1195,85 @@ void test_HYDROData_LandCoverMap::test_shp_clc_classification()
   double y1 = 6392203.4117361344;
   for (size_t i=0; i < N; i++)
   {
-    double px = x0 + (x1-x0)/(double)N;
-    double py = y0 + (y1-y0)/(double)N;
-    pnts.push_back(gp_Pnt2d(px,py));
+    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_Pnt2d(px,py));
+    }
   }
-  std::vector<std::set <QString> > TRes;
+  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_Pnt2d> 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);
+
+}
+
index d03ead1bc504f314111a938da6401d690c7f3157..c473c4a1a3f858c0034e5c957eb50f3f389e6bd5 100644 (file)
@@ -50,7 +50,8 @@ class test_HYDROData_LandCoverMap : public CppUnit::TestFixture
   CPPUNIT_TEST( test_shp_import_clc_dec );
   CPPUNIT_TEST( test_shp_import_nld_areas );
   CPPUNIT_TEST( test_shp_loop_back );
-  CPPUNIT_TEST( test_shp_clc_classification );
+  CPPUNIT_TEST( test_shp_clc_classification_perf );
+  CPPUNIT_TEST( test_shp_clc_classification_check );
 #endif
   CPPUNIT_TEST_SUITE_END();
 
@@ -78,7 +79,8 @@ public:
   void test_shp_loop_back();
   void test_export_telemac();
   void test_copy();
-  void test_shp_clc_classification();
+  void test_shp_clc_classification_perf();
+  void test_shp_clc_classification_check();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_LandCoverMap );