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>
45 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
46 const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt";
48 void test_HYDROData_LandCoverMap::test_add_2_objects()
50 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
52 Handle(HYDROData_LandCoverMap) aMap =
53 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
55 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
57 TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
58 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
60 TopoDS_Face aLC2 = Face( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
61 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
63 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
66 HYDROData_LandCoverMap::Iterator anIt( aMap );
67 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
68 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
70 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
71 CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
73 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
78 void test_HYDROData_LandCoverMap::test_split()
80 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
82 Handle(HYDROData_LandCoverMap) aMap =
83 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
85 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
87 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
88 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
90 Handle(HYDROData_PolylineXY) aPolyline =
91 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
92 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10, false );
93 aPolyline->SetShape( aWire );
95 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
97 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
98 TestViewer::show( aWire, 0, true, Qt::blue );
101 HYDROData_LandCoverMap::Iterator anIt( aMap );
102 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
103 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
105 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
106 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
108 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
113 void test_HYDROData_LandCoverMap::test_incomplete_split()
115 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
117 Handle(HYDROData_LandCoverMap) aMap =
118 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
120 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
122 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
123 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
125 Handle(HYDROData_PolylineXY) aPolyline =
126 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
127 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10, false );
128 aPolyline->SetShape( aWire );
130 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
132 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
133 TestViewer::show( aWire, 0, true, Qt::green );
134 CPPUNIT_ASSERT_IMAGES
136 HYDROData_LandCoverMap::Iterator anIt( aMap );
137 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
138 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
140 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
145 void test_HYDROData_LandCoverMap::test_merge()
147 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
149 Handle(HYDROData_LandCoverMap) aMap =
150 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
152 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
154 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
156 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
158 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
159 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
160 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
162 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
164 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
165 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
166 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
168 //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
169 //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
171 //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
173 QString aType1, aType2;
174 gp_Pnt2d aPnt1( 25, 35 );
175 gp_Pnt2d aPnt2( 45, 55 );
176 //gp_Pnt2d aPnt3( 45, 10 );
177 //gp_Pnt2d aPnt4( 45, 80 );
178 TopTools_ListOfShape aList;
179 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
180 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
181 CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
183 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
184 //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
185 CPPUNIT_ASSERT_IMAGES
190 void test_HYDROData_LandCoverMap::test_remove()
192 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
194 Handle(HYDROData_LandCoverMap) aMap =
195 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
197 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
199 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
201 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
203 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
204 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
205 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
207 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
209 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
210 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
211 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
213 QString aType1, aType2;
214 gp_Pnt2d aPnt1( 25, 35 );
215 gp_Pnt2d aPnt2( 45, 55 );
216 TopTools_ListOfShape aList;
217 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
218 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
219 CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
221 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
222 CPPUNIT_ASSERT_IMAGES
227 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
229 TopoDS_Shape pp1, pp2, pp3, pp4;
231 BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
232 BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
233 BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
234 BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
236 CPPUNIT_ASSERT(!pp1.IsNull());
237 CPPUNIT_ASSERT(!pp2.IsNull());
238 CPPUNIT_ASSERT(!pp3.IsNull());
239 CPPUNIT_ASSERT(!pp4.IsNull());
241 //Test mergeFaces() func // boxes // USD == true
243 TopTools_ListOfShape Faces;
246 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
247 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_11" );
248 CPPUNIT_ASSERT_IMAGES
249 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
252 TopTools_ListOfShape Faces;
255 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
256 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_12" );
257 CPPUNIT_ASSERT_IMAGES
258 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
261 TopTools_ListOfShape Faces;
265 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
266 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_13" );
267 CPPUNIT_ASSERT_IMAGES
268 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
271 TopTools_ListOfShape Faces;
276 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
277 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_14" );
278 CPPUNIT_ASSERT_IMAGES
279 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
283 //Test mergeFaces() func // boxes // USD == false
285 TopTools_ListOfShape Faces;
288 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
289 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_21" );
290 CPPUNIT_ASSERT_IMAGES
291 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
294 TopTools_ListOfShape Faces;
297 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
298 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_22" );
299 CPPUNIT_ASSERT_IMAGES
300 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
303 TopTools_ListOfShape Faces;
307 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
308 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_23" );
309 CPPUNIT_ASSERT_IMAGES
310 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
313 TopTools_ListOfShape Faces;
318 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
319 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_24" );
320 CPPUNIT_ASSERT_IMAGES
321 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
326 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
328 TopoDS_Shape ff1, ff2, ff3;
330 BRepTools::Read(ff1, (REF_DATA_PATH + "/ff1.brep").toStdString().c_str(), BB);
331 BRepTools::Read(ff2, (REF_DATA_PATH + "/ff2.brep").toStdString().c_str(), BB);
332 BRepTools::Read(ff3, (REF_DATA_PATH + "/ff3.brep").toStdString().c_str(), BB);
334 CPPUNIT_ASSERT(!ff1.IsNull());
335 CPPUNIT_ASSERT(!ff2.IsNull());
336 CPPUNIT_ASSERT(!ff3.IsNull());
338 //Test mergeFaces() func // circles // USD == true
340 TopTools_ListOfShape Faces;
343 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
344 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_11" );
345 CPPUNIT_ASSERT_IMAGES
346 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
349 TopTools_ListOfShape Faces;
352 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
353 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_12" );
354 CPPUNIT_ASSERT_IMAGES
355 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
358 TopTools_ListOfShape Faces;
362 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
363 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_13" );
364 CPPUNIT_ASSERT_IMAGES
365 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
368 TopTools_ListOfShape Faces;
372 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
373 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_14" );
374 CPPUNIT_ASSERT_IMAGES
375 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
379 //Test mergeFaces() func // circles // USD == false
381 TopTools_ListOfShape Faces;
384 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
385 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_21" );
386 CPPUNIT_ASSERT_IMAGES
387 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
390 TopTools_ListOfShape Faces;
393 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
394 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_22" );
395 CPPUNIT_ASSERT_IMAGES
396 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
399 TopTools_ListOfShape Faces;
403 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
404 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_23" );
405 CPPUNIT_ASSERT_IMAGES
406 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
409 TopTools_ListOfShape Faces;
413 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
414 TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_24" );
415 CPPUNIT_ASSERT_IMAGES
416 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
420 void test_HYDROData_LandCoverMap::test_import_dbf()
422 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
424 Handle(HYDROData_LandCoverMap) aMap =
425 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
427 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
428 QString aFileName = REF_DATA_PATH + "/t1.dbf";
435 aST.append("forest");
437 // aST.size() == aDBFV.size()!!
438 Handle(HYDROData_PolylineXY) aPolyline =
439 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
440 TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 );
441 aPolyline->SetShape( aWire );
442 for (int i = 0; i < 3; i++)
443 aMap->Add(aPolyline, "");
444 TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
445 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
447 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
448 QList<int> Inds = QList<int>() << 1 << 2 << 3;
449 aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
450 HYDROData_LandCoverMap::Iterator anIt( aMap );
452 CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
454 CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() );
459 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
461 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
463 Handle(HYDROData_StricklerTable) aTable =
464 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
465 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
467 Handle(HYDROData_LandCoverMap) aMap =
468 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
470 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
471 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
473 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
474 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
475 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
477 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
479 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
480 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
481 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
483 // build presentation object
484 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
485 aPrs->SetTable( aTable );
486 // show presentation in viewer
487 TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByTypes" );
488 // select one of faces (first)
489 TestViewer::select( 200, 300 );
490 CPPUNIT_ASSERT_IMAGES
495 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff()
497 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
499 Handle(HYDROData_StricklerTable) aTable =
500 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
501 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
503 Handle(HYDROData_LandCoverMap) aMap =
504 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
506 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
507 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
509 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
510 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
511 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
513 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
515 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
516 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
517 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
519 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
520 aPrs->SetTable( aTable );
521 aPrs->SetColorScale( TestViewer::showColorScale( true ) );
522 TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByCoeff" );
523 CPPUNIT_ASSERT_IMAGES
525 TestViewer::showColorScale( false );
529 void test_HYDROData_LandCoverMap::test_dump_python()
531 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
533 Handle(HYDROData_LandCoverMap) aMap =
534 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
535 aMap->SetName( "test_LCM" );
537 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
539 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
541 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
543 TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
544 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
545 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
547 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
549 TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
550 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
551 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
553 QString aTmpPath = QDir::tempPath() + "/lc_dump.py";
554 CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) );
556 //TODO: compare files
561 void test_HYDROData_LandCoverMap::test_transparent_prs()
563 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
565 Handle(HYDROData_StricklerTable) aTable =
566 Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
567 CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
569 Handle(HYDROData_PolylineXY) aPoly =
570 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
571 aPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, true );
572 aPoly->AddPoint( 0, gp_XY( 0, 0 ) );
573 aPoly->AddPoint( 0, gp_XY( 20, 0 ) );
574 aPoly->AddPoint( 0, gp_XY( 10, 10 ) );
577 Handle(HYDROData_ImmersibleZone) aZone =
578 Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
579 aZone->SetPolyline( aPoly );
582 Handle(HYDROData_LandCoverMap) aMap =
583 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
584 aMap->LocalPartition( Face( QList<double>() << 1 << 1 << 10 << 10 << 10 << 20 ), "Zones de champs cultivé à végétation haute" );
585 aMap->LocalPartition( Face( QList<double>() << 5 << 5 << 10 << 5 << 10 << 8 << 5 << 12 << 5 << 8 ), "Zones de champs cultivé à végétation haute" );
586 aMap->SetName( "test_LCM" );
588 TestViewer::show( aZone->GetTopShape(), AIS_Shaded, true, "LandCoverMap_TransparentPrs" );
590 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
591 aPrs->SetTable( aTable );
592 aPrs->SetTransparency( 0.5 );
593 TestViewer::show( aPrs, AIS_Shaded, 0, true, "" );
595 CPPUNIT_ASSERT_IMAGES
599 void test_HYDROData_LandCoverMap::test_add_triangles()
601 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
603 Handle(HYDROData_PolylineXY) Polyline_1 =
604 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
606 Polyline_1->SetName( "Polyline_1" );
607 Polyline_1->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
608 Polyline_1->AddPoint( 0, gp_XY( -264.84, 323.44 ) );
609 Polyline_1->AddPoint( 0, gp_XY( 254.45, 301.19 ) );
610 Polyline_1->AddPoint( 0, gp_XY( -291.54, -47.48 ) );
611 Polyline_1->Update();
613 Handle(HYDROData_PolylineXY) Polyline_2 =
614 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
615 Polyline_2->SetName( "Polyline_2" );
616 Polyline_2->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
617 Polyline_2->AddPoint( 0, gp_XY( -42.28, -351.63 ) );
618 Polyline_2->AddPoint( 0, gp_XY( 218.84, -146.88 ) );
619 Polyline_2->AddPoint( 0, gp_XY( 413.20, -235.91 ) );
620 Polyline_2->AddPoint( 0, gp_XY( 466.62, -388.72 ) );
621 Polyline_2->Update();
623 Handle(HYDROData_PolylineXY) Polyline_3 =
624 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
625 Polyline_3->SetName( "Polyline_3" );
626 Polyline_3->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
627 Polyline_3->AddPoint( 0, gp_XY( -108.31, 213.65 ) );
628 Polyline_3->AddPoint( 0, gp_XY( 127.60, 382.79 ) );
629 Polyline_3->AddPoint( 0, gp_XY( 192.88, -91.99 ) );
630 Polyline_3->Update();
632 Handle(HYDROData_PolylineXY) Polyline_4 =
633 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
634 Polyline_4->SetName( "Polyline_4" );
635 Polyline_4->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
636 Polyline_4->AddPoint( 0, gp_XY( 215.52, 344.61 ) );
637 Polyline_4->AddPoint( 0, gp_XY( 68.25, 258.52 ) );
638 Polyline_4->AddPoint( 0, gp_XY( 200.58, 154.65 ) );
639 Polyline_4->Update();
641 Handle(HYDROData_PolylineXY) Polyline_5 =
642 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
643 Polyline_5->SetName( "Polyline_5" );
644 Polyline_5->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
645 Polyline_5->AddPoint( 0, gp_XY( 16.15, -58.08 ) );
646 Polyline_5->AddPoint( 0, gp_XY( 116.47, 84.21 ) );
647 Polyline_5->AddPoint( 0, gp_XY( 266.59, 29.43 ) );
648 Polyline_5->Update();
650 Handle(HYDROData_LandCoverMap) aMap =
651 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
653 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_1, "" ) );
654 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_3, "" ) );
655 CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_4, "" ) );
657 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
658 TestViewer::show( aPrs, AIS_Shaded, 0, true, "LandCover_Triangles" );
659 CPPUNIT_ASSERT_IMAGES
661 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( Polyline_5 ) );
662 Handle(HYDROGUI_LandCoverMapPrs) aPrs2 = new HYDROGUI_LandCoverMapPrs( aMap );
663 TestViewer::show( aPrs2, AIS_Shaded, 0, true, "LandCover_Triangles_Split" );
664 CPPUNIT_ASSERT_IMAGES
669 void test_HYDROData_LandCoverMap::test_assign_to_calc_case()
671 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
673 Handle(HYDROData_LandCoverMap) aMap =
674 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
675 Handle(HYDROData_CalculationCase) aCalcCase =
676 Handle(HYDROData_CalculationCase)::DownCast( aDoc->CreateObject( KIND_CALCULATION ) );
678 aCalcCase->SetLandCoverMap( aMap );
679 CPPUNIT_ASSERT_EQUAL( aMap->myLab, aCalcCase->GetLandCoverMap()->myLab );
684 void test_HYDROData_LandCoverMap::test_shp_import_cyp()
686 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
687 QString myFileName = REF_DATA_PATH + "/cyprus_natural.shp";
688 HYDROData_ShapeFile anImporter;
689 QStringList PolygonList;
690 TopTools_SequenceOfShape PolygonFaces;
692 int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
693 CPPUNIT_ASSERT(aStat == 1);
694 CPPUNIT_ASSERT_EQUAL(5, Type);
695 CPPUNIT_ASSERT_EQUAL(268, PolygonFaces.Length());
697 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
698 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
700 for ( int i = 1; i <= PolygonFaces.Length(); i++ )
702 TopoDS_Shape aShape = PolygonFaces(i);
703 if ( aShape.IsNull() )
705 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
708 LCM->StoreLandCovers(aMapFace2ST);
709 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "cyprus_natural_all" );
710 CPPUNIT_ASSERT_IMAGES
714 void test_HYDROData_LandCoverMap::test_shp_import_clc_dec()
716 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
717 QString myFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
718 HYDROData_ShapeFile anImporter;
719 QStringList PolygonList;
720 TopTools_SequenceOfShape PolygonFaces;
722 int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
723 CPPUNIT_ASSERT(aStat == 1);
724 CPPUNIT_ASSERT_EQUAL(5, Type);
725 CPPUNIT_ASSERT_EQUAL(625, PolygonFaces.Length());
727 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
728 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
730 for ( int i = 150; i <= 350; i++ )
732 TopoDS_Shape aShape = PolygonFaces(i);
733 if ( aShape.IsNull() )
735 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
738 LCM->StoreLandCovers(aMapFace2ST);
739 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "clc_dec_150_350" );
740 CPPUNIT_ASSERT_IMAGES
744 void test_HYDROData_LandCoverMap::test_shp_import_nld_areas()
746 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
747 QString myFileName = REF_DATA_PATH + "/NLD_water_areas_dcw.shp";
748 HYDROData_ShapeFile anImporter;
749 QStringList PolygonList;
750 TopTools_SequenceOfShape PolygonFaces;
752 int aStat = anImporter.ImportPolygons(myFileName, PolygonList, PolygonFaces, Type);
753 CPPUNIT_ASSERT(aStat == 1);
754 CPPUNIT_ASSERT_EQUAL(5, Type);
755 CPPUNIT_ASSERT_EQUAL(127, PolygonFaces.Length());
757 Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
758 HYDROData_MapOfFaceToStricklerType aMapFace2ST;
760 for ( int i = 1; i <= PolygonFaces.Length(); i++ )
762 TopoDS_Shape aShape = PolygonFaces(i);
763 if ( aShape.IsNull() )
765 aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
768 LCM->StoreLandCovers(aMapFace2ST);
769 TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "NLD_water_areas_dcw" );
770 CPPUNIT_ASSERT_IMAGES