1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <test_HYDROData_LandCoverMap.h>
20 #include <HYDROData_CalculationCase.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_LandCoverMap.h>
23 #include <HYDROData_ImmersibleZone.h>
24 #include <HYDROData_PolylineXY.h>
25 #include <HYDROData_StricklerTable.h>
26 #include <HYDROData_Tool.h>
27 #include <HYDROData_ShapeFile.h>
28 #include <HYDROGUI_LandCoverMapPrs.h>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Wire.hxx>
31 #include <TopoDS_Face.hxx>
33 #include <TestViewer.h>
34 #include <TestShape.h>
35 #include <TopTools_ListOfShape.hxx>
36 #include <AIS_DisplayMode.hxx>
37 #include <Aspect_ColorScale.hxx>
42 #include <BRepTools.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepCheck_Analyzer.hxx>
46 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
47 const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt";
49 void test_HYDROData_LandCoverMap::test_add_2_objects()
51 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
53 Handle(HYDROData_LandCoverMap) aMap =
54 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
56 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
58 TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
59 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
61 TopoDS_Face aLC2 = Face( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
62 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
64 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
67 HYDROData_LandCoverMap::Iterator anIt( aMap );
68 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
69 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
71 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
72 CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
74 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
79 void test_HYDROData_LandCoverMap::test_split()
81 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
83 Handle(HYDROData_LandCoverMap) aMap =
84 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
86 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
88 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
89 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
91 Handle(HYDROData_PolylineXY) aPolyline =
92 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
93 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10, false );
94 aPolyline->SetShape( aWire );
96 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
98 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
99 TestViewer::show( aWire, 0, true, Qt::blue );
100 CPPUNIT_ASSERT_IMAGES
102 HYDROData_LandCoverMap::Iterator anIt( aMap );
103 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
104 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
106 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
107 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
109 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
114 void test_HYDROData_LandCoverMap::test_incomplete_split()
116 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
118 Handle(HYDROData_LandCoverMap) aMap =
119 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
121 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
123 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
124 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
126 Handle(HYDROData_PolylineXY) aPolyline =
127 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
128 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10, false );
129 aPolyline->SetShape( aWire );
131 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
133 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
134 TestViewer::show( aWire, 0, true, Qt::green );
135 CPPUNIT_ASSERT_IMAGES
137 HYDROData_LandCoverMap::Iterator anIt( aMap );
138 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
139 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
141 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
146 void test_HYDROData_LandCoverMap::test_merge()
148 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
150 Handle(HYDROData_LandCoverMap) aMap =
151 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
153 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
155 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
157 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
159 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
160 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
161 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
163 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
165 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
166 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
167 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
169 //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
170 //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
172 //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
174 QString aType1, aType2;
175 gp_Pnt2d aPnt1( 25, 35 );
176 gp_Pnt2d aPnt2( 45, 55 );
177 //gp_Pnt2d aPnt3( 45, 10 );
178 //gp_Pnt2d aPnt4( 45, 80 );
179 TopTools_ListOfShape aList;
180 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
181 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
182 CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
184 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
185 //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
186 CPPUNIT_ASSERT_IMAGES
191 void test_HYDROData_LandCoverMap::test_remove()
193 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
195 Handle(HYDROData_LandCoverMap) aMap =
196 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
198 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
200 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
202 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
204 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
205 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
206 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
208 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
210 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
211 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
212 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
214 QString aType1, aType2;
215 gp_Pnt2d aPnt1( 25, 35 );
216 gp_Pnt2d aPnt2( 45, 55 );
217 TopTools_ListOfShape aList;
218 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
219 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
220 CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
222 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
223 CPPUNIT_ASSERT_IMAGES
228 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
230 TopoDS_Shape pp1, pp2, pp3, pp4;
232 BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
233 BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
234 BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
235 BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
237 CPPUNIT_ASSERT(!pp1.IsNull());
238 CPPUNIT_ASSERT(!pp2.IsNull());
239 CPPUNIT_ASSERT(!pp3.IsNull());
240 CPPUNIT_ASSERT(!pp4.IsNull());
242 //Test mergeFaces() func // boxes // USD == true
244 TopTools_ListOfShape Faces;
247 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
248 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_11" );
249 CPPUNIT_ASSERT_IMAGES
250 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
253 TopTools_ListOfShape Faces;
256 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
257 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_12" );
258 CPPUNIT_ASSERT_IMAGES
259 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
262 TopTools_ListOfShape Faces;
266 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
267 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_13" );
268 CPPUNIT_ASSERT_IMAGES
269 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
272 TopTools_ListOfShape Faces;
277 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
278 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_14" );
279 CPPUNIT_ASSERT_IMAGES
280 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
284 //Test mergeFaces() func // boxes // USD == false
286 TopTools_ListOfShape Faces;
289 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
290 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_21" );
291 CPPUNIT_ASSERT_IMAGES
292 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
295 TopTools_ListOfShape Faces;
298 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
299 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_22" );
300 CPPUNIT_ASSERT_IMAGES
301 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
304 TopTools_ListOfShape Faces;
308 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
309 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_23" );
310 CPPUNIT_ASSERT_IMAGES
311 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
314 TopTools_ListOfShape Faces;
319 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
320 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_24" );
321 CPPUNIT_ASSERT_IMAGES
322 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
327 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
329 TopoDS_Shape ff1, ff2, ff3;
331 BRepTools::Read(ff1, (REF_DATA_PATH + "/ff1.brep").toStdString().c_str(), BB);
332 BRepTools::Read(ff2, (REF_DATA_PATH + "/ff2.brep").toStdString().c_str(), BB);
333 BRepTools::Read(ff3, (REF_DATA_PATH + "/ff3.brep").toStdString().c_str(), BB);
335 CPPUNIT_ASSERT(!ff1.IsNull());
336 CPPUNIT_ASSERT(!ff2.IsNull());
337 CPPUNIT_ASSERT(!ff3.IsNull());
339 //Test mergeFaces() func // circles // USD == true
341 TopTools_ListOfShape Faces;
344 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
345 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_11" );
346 CPPUNIT_ASSERT_IMAGES
347 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
350 TopTools_ListOfShape Faces;
353 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
354 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_12" );
355 CPPUNIT_ASSERT_IMAGES
356 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
359 TopTools_ListOfShape Faces;
363 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
364 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_13" );
365 CPPUNIT_ASSERT_IMAGES
366 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
369 TopTools_ListOfShape Faces;
373 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
374 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_14" );
375 CPPUNIT_ASSERT_IMAGES
376 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
380 //Test mergeFaces() func // circles // USD == false
382 TopTools_ListOfShape Faces;
385 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
386 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_21" );
387 CPPUNIT_ASSERT_IMAGES
388 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
391 TopTools_ListOfShape Faces;
394 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
395 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_22" );
396 CPPUNIT_ASSERT_IMAGES
397 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
400 TopTools_ListOfShape Faces;
404 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
405 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_23" );
406 CPPUNIT_ASSERT_IMAGES
407 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
410 TopTools_ListOfShape Faces;
414 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
415 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_24" );
416 CPPUNIT_ASSERT_IMAGES
417 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
421 void test_HYDROData_LandCoverMap::test_import_dbf()
423 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
425 Handle(HYDROData_LandCoverMap) aMap =
426 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
428 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
429 QString aFileName = REF_DATA_PATH + "/t1.dbf";
436 aST.append("forest");
438 // aST.size() == aDBFV.size()!!
439 Handle(HYDROData_PolylineXY) aPolyline =
440 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
441 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 );
442 aPolyline->SetShape( aWire );
443 for (int i = 0; i < 3; i++)
444 aMap->Add(aPolyline, "");
445 TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
446 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
448 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
449 QList<int> Inds = QList<int>() << 1 << 2 << 3;
450 aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
451 HYDROData_LandCoverMap::Iterator anIt( aMap );
453 CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
455 CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() );
460 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
462 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
464 Handle(HYDROData_StricklerTable) aTable =
465 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
466 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
468 Handle(HYDROData_LandCoverMap) aMap =
469 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
471 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
472 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
474 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
475 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
476 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
478 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
480 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
481 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
482 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
484 // build presentation object
485 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
486 aPrs->SetTable( aTable );
487 // show presentation in viewer
488 TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByTypes" );
489 // select one of faces (first)
490 TestViewer::select( 200, 300 );
491 CPPUNIT_ASSERT_IMAGES
496 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff()
498 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
500 Handle(HYDROData_StricklerTable) aTable =
501 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
502 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
504 Handle(HYDROData_LandCoverMap) aMap =
505 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
507 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
508 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
510 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
511 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
512 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
514 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
516 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
517 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
518 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
520 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
521 aPrs->SetTable( aTable );
522 aPrs->SetColorScale( TestViewer::showColorScale( true ) );
523 TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByCoeff" );
524 CPPUNIT_ASSERT_IMAGES
526 TestViewer::showColorScale( false );
530 void test_HYDROData_LandCoverMap::test_dump_python()
532 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
534 Handle(HYDROData_LandCoverMap) aMap =
535 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
536 aMap->SetName( "test_LCM" );
538 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
540 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
542 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
544 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
545 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
546 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
548 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
550 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
551 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
552 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
554 QString aTmpPath = QDir::tempPath() + "/lc_dump.py";
555 CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) );
557 //TODO: compare files
562 void test_HYDROData_LandCoverMap::test_transparent_prs()
564 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
566 Handle(HYDROData_StricklerTable) aTable =
567 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
568 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
570 Handle(HYDROData_PolylineXY) aPoly =
571 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
572 aPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, true );
573 aPoly->AddPoint( 0, gp_XY( 0, 0 ) );
574 aPoly->AddPoint( 0, gp_XY( 20, 0 ) );
575 aPoly->AddPoint( 0, gp_XY( 10, 10 ) );
578 Handle(HYDROData_ImmersibleZone) aZone =
579 Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
580 aZone->SetPolyline( aPoly );
583 Handle(HYDROData_LandCoverMap) aMap =
584 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
585 aMap->LocalPartition( Face( QList<double>() << 1 << 1 << 10 << 10 << 10 << 20 ), "Zones de champs cultivé à végétation haute" );
586 aMap->LocalPartition( Face( QList<double>() << 5 << 5 << 10 << 5 << 10 << 8 << 5 << 12 << 5 << 8 ), "Zones de champs cultivé à végétation haute" );
587 aMap->SetName( "test_LCM" );
589 TestViewer::show( aZone->GetTopShape(), AIS_Shaded, true, "LandCoverMap_TransparentPrs" );
591 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
592 aPrs->SetTable( aTable );
593 aPrs->SetTransparency( 0.5 );
594 TestViewer::show( aPrs, AIS_Shaded, 0, true, "" );
596 CPPUNIT_ASSERT_IMAGES
600 void test_HYDROData_LandCoverMap::test_add_triangles()
602 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
604 Handle(HYDROData_PolylineXY) Polyline_1 =
605 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
607 Polyline_1->SetName( "Polyline_1" );
608 Polyline_1->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
609 Polyline_1->AddPoint( 0, gp_XY( -264.84, 323.44 ) );
610 Polyline_1->AddPoint( 0, gp_XY( 254.45, 301.19 ) );
611 Polyline_1->AddPoint( 0, gp_XY( -291.54, -47.48 ) );
612 Polyline_1->Update();
614 Handle(HYDROData_PolylineXY) Polyline_2 =
615 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
616 Polyline_2->SetName( "Polyline_2" );
617 Polyline_2->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
618 Polyline_2->AddPoint( 0, gp_XY( -42.28, -351.63 ) );
619 Polyline_2->AddPoint( 0, gp_XY( 218.84, -146.88 ) );
620 Polyline_2->AddPoint( 0, gp_XY( 413.20, -235.91 ) );
621 Polyline_2->AddPoint( 0, gp_XY( 466.62, -388.72 ) );
622 Polyline_2->Update();
624 Handle(HYDROData_PolylineXY) Polyline_3 =
625 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
626 Polyline_3->SetName( "Polyline_3" );
627 Polyline_3->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
628 Polyline_3->AddPoint( 0, gp_XY( -108.31, 213.65 ) );
629 Polyline_3->AddPoint( 0, gp_XY( 127.60, 382.79 ) );
630 Polyline_3->AddPoint( 0, gp_XY( 192.88, -91.99 ) );
631 Polyline_3->Update();
633 Handle(HYDROData_PolylineXY) Polyline_4 =
634 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
635 Polyline_4->SetName( "Polyline_4" );
636 Polyline_4->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
637 Polyline_4->AddPoint( 0, gp_XY( 215.52, 344.61 ) );
638 Polyline_4->AddPoint( 0, gp_XY( 68.25, 258.52 ) );
639 Polyline_4->AddPoint( 0, gp_XY( 200.58, 154.65 ) );
640 Polyline_4->Update();
642 Handle(HYDROData_PolylineXY) Polyline_5 =
643 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
644 Polyline_5->SetName( "Polyline_5" );
645 Polyline_5->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
646 Polyline_5->AddPoint( 0, gp_XY( 16.15, -58.08 ) );
647 Polyline_5->AddPoint( 0, gp_XY( 116.47, 84.21 ) );
648 Polyline_5->AddPoint( 0, gp_XY( 266.59, 29.43 ) );
649 Polyline_5->Update();
651 Handle(HYDROData_LandCoverMap) aMap =
652 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
654 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_1, "" ) );
655 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_3, "" ) );
656 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_4, "" ) );
658 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
659 TestViewer::show( aPrs, AIS_Shaded, 0, true, "LandCover_Triangles" );
660 CPPUNIT_ASSERT_IMAGES
662 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( Polyline_5 ) );
663 Handle(HYDROGUI_LandCoverMapPrs) aPrs2 = new HYDROGUI_LandCoverMapPrs( aMap );
664 TestViewer::show( aPrs2, AIS_Shaded, 0, true, "LandCover_Triangles_Split" );
665 CPPUNIT_ASSERT_IMAGES
670 void test_HYDROData_LandCoverMap::test_assign_to_calc_case()
672 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
674 Handle(HYDROData_LandCoverMap) aMap =
675 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
676 Handle(HYDROData_CalculationCase) aCalcCase =
677 Handle(HYDROData_CalculationCase)::DownCast( aDoc->CreateObject( KIND_CALCULATION ) );
679 aCalcCase->SetLandCoverMap( aMap );
680 CPPUNIT_ASSERT_EQUAL( aMap->myLab, aCalcCase->GetLandCoverMap()->myLab );
685 void test_HYDROData_LandCoverMap::test_shp_import_cyp()
687 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
688 QString aFileName = REF_DATA_PATH + "/cyprus_natural.shp";
689 HYDROData_ShapeFile anImporter;
690 QStringList PolygonList;
691 TopTools_SequenceOfShape PolygonFaces;
693 int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
694 CPPUNIT_ASSERT(aStat == 1);
695 CPPUNIT_ASSERT_EQUAL(5, Type);
696 CPPUNIT_ASSERT_EQUAL(268, PolygonFaces.Length());
698 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
699 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
701 for ( int i = 1; i <= PolygonFaces.Length(); i++ )
703 TopoDS_Shape aShape = PolygonFaces(i);
704 if ( aShape.IsNull() )
706 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
709 LCM->StoreLandCovers(aMapFace2ST);
710 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "cyprus_natural_all" );
711 CPPUNIT_ASSERT_IMAGES
715 void test_HYDROData_LandCoverMap::test_shp_import_clc_dec()
717 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
718 QString aFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
719 HYDROData_ShapeFile anImporter;
720 QStringList PolygonList;
721 TopTools_SequenceOfShape PolygonFaces;
723 int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
724 CPPUNIT_ASSERT(aStat == 1);
725 CPPUNIT_ASSERT_EQUAL(5, Type);
726 CPPUNIT_ASSERT_EQUAL(625, PolygonFaces.Length());
728 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
729 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
731 for ( int i = 150; i <= 350; i++ )
733 TopoDS_Shape aShape = PolygonFaces(i);
734 if ( aShape.IsNull() )
736 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
739 LCM->StoreLandCovers(aMapFace2ST);
740 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "clc_dec_150_350" );
741 CPPUNIT_ASSERT_IMAGES
745 void test_HYDROData_LandCoverMap::test_shp_import_nld_areas()
747 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
748 QString aFileName = REF_DATA_PATH + "/NLD_water_areas_dcw.shp";
749 HYDROData_ShapeFile anImporter;
750 QStringList PolygonList;
751 TopTools_SequenceOfShape PolygonFaces;
753 int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
754 CPPUNIT_ASSERT(aStat == 1);
755 CPPUNIT_ASSERT_EQUAL(5, Type);
756 CPPUNIT_ASSERT_EQUAL(127, PolygonFaces.Length());
758 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
759 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
761 for ( int i = 1; i <= PolygonFaces.Length(); i++ )
763 TopoDS_Shape aShape = PolygonFaces(i);
764 if ( aShape.IsNull() )
766 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
769 LCM->StoreLandCovers(aMapFace2ST);
770 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "NLD_water_areas_dcw" );
771 CPPUNIT_ASSERT_IMAGES
775 void test_HYDROData_LandCoverMap::test_shp_loop_back()
777 QString aFFileName = REF_DATA_PATH + "/CLC06-cut_1.shp";
778 QString aSFileName = REF_DATA_PATH + "/CLC06-cut_1_res.shp";
779 //This test verify only some geom data (shp+shx) without any dbf reading/writing
781 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
782 HYDROData_ShapeFile anImporter;
783 QStringList PolygonList;
784 TopTools_SequenceOfShape PolygonFaces;
787 //import LCM from file (#2-4; #12-14 polygons)
788 CPPUNIT_ASSERT( anImporter.ImportPolygons(aFFileName, PolygonList, PolygonFaces, Type));
789 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
790 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
792 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(2) ), "" );
793 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(3) ), "" );
794 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(4) ), "" );
795 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(12) ), "" );
796 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(13) ), "" );
797 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(14) ), "" );
799 LCM->StoreLandCovers(aMapFace2ST);
800 LCM->SetName("lcm_1");
802 TopoDS_Shape aSh = LCM->GetShape();
803 BRepCheck_Analyzer aBCA(aSh);
804 CPPUNIT_ASSERT(aBCA.IsValid());
807 HYDROData_ShapeFile anExporter;
808 QStringList aNonExpList;
809 anExporter.Export(aSFileName, LCM, aNonExpList);
810 CPPUNIT_ASSERT (aNonExpList.empty());
815 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
816 HYDROData_ShapeFile anImporter;
817 QStringList PolygonList;
818 TopTools_SequenceOfShape PolygonFaces;
822 CPPUNIT_ASSERT( anImporter.ImportPolygons(aSFileName, PolygonList, PolygonFaces, Type));
823 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
824 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
825 CPPUNIT_ASSERT_EQUAL(PolygonFaces.Length(), 6);
826 for ( int i = 1; i <= PolygonFaces.Length(); i++ )
827 aMapFace2ST.Add( TopoDS::Face( PolygonFaces(i) ), "" );
829 LCM->StoreLandCovers(aMapFace2ST);
830 LCM->SetName("lcm_2");
832 TopoDS_Shape OutSh = LCM->GetShape();
833 BRepCheck_Analyzer aBCA(OutSh);
834 CPPUNIT_ASSERT(aBCA.IsValid());
836 TestViewer::show( OutSh, AIS_Shaded, true, "CLC06-cut_1_res" );
837 CPPUNIT_ASSERT_IMAGES
841 CPPUNIT_ASSERT_EQUAL(0, remove(aSFileName.toStdString().c_str()));