From: isn Date: Thu, 1 Sep 2016 11:12:08 +0000 (+0300) Subject: new tests for LCM classification X-Git-Tag: v1.6~75^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_HYDRO_IMPS_TEST;p=modules%2Fhydro.git new tests for LCM classification --- diff --git a/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx b/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx index b801df77..faf7678f 100644 --- a/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx +++ b/src/HYDROData/HYDROData_LCM_FaceClassifier.cxx @@ -75,11 +75,11 @@ void HYDROData_LCM_FaceClassifier::Classify( const std::vector& thePoi NCollection_UBTreeFiller aTreeFiller (aTree); NCollection_IndexedDataMap aMapF2Class2d; - int NbF= aFaces.Extent(); + int NbF = aFaces.Extent(); std::vector 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)); diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 7afb3132..f709b378 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -1264,3 +1264,32 @@ void HYDROData_LandCoverMap::ClassifyPoints( const std::vector& thePoi HYDROData_LCM_FaceClassifier FC(this); FC.Classify(thePoints, theTypes, NULL); } + +void HYDROData_LandCoverMap::ClassifyPoints( const std::vector& thePoints, + Handle(HYDROData_StricklerTable) theTable, + std::vector& theCoeffs, double DefValue, bool UseMax ) const +{ + std::vector > 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& SStr = Types[i]; + if (SStr.empty()) + theCoeffs[i] = DefValue; + else + { + std::set::const_iterator it; + std::vector 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; + } + } +} diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index 43c074ba..f0d17d17 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -152,6 +152,10 @@ public: HYDRODATA_EXPORT void ClassifyPoints( const std::vector& thePoints, std::vector >& theTypes ) const; + HYDRODATA_EXPORT void ClassifyPoints( const std::vector& thePoints, + Handle(HYDROData_StricklerTable) theTable, + std::vector& theCoeffs, double DefValue, bool UseMax ) const; + protected: void SetShape( const TopoDS_Shape& ); diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 1b71f652..df9deb4c 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -43,6 +43,7 @@ #include #include #include +#include #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 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 > TRes; + OSD_Timer aTimer; + std::vector > 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 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 > 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 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); + +} + diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h index d03ead1b..c473c4a1 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.h +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.h @@ -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 );