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_Document.h>
21 #include <HYDROData_LandCoverMap.h>
22 #include <HYDROData_PolylineXY.h>
23 #include <HYDROData_Tool.h>
24 #include <TopoDS_Edge.hxx>
25 #include <TopoDS_Wire.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TColgp_HArray1OfPnt.hxx>
28 #include <GeomAPI_Interpolate.hxx>
29 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <BRepBuilderAPI_MakeFace.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
32 #include <TestViewer.h>
33 #include <TopTools_ListOfShape.hxx>
34 #include <AIS_DisplayMode.hxx>
38 #include <BRepTools.hxx>
39 #include <BRep_Builder.hxx>
41 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
43 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
45 int n = theXYList.size()/2;
46 Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
47 for( int i=1; i<=n; i++ )
49 double x = theXYList[2*i-2];
50 double y = theXYList[2*i-1];
51 gp_Pnt aPnt( x, y, 0 );
52 aPointsArray->SetValue( i, aPnt );
54 GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
55 anInterpolator.Perform();
56 bool aResult = anInterpolator.IsDone() == Standard_True;
59 Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
60 return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
66 TopoDS_Face LandCover( const QList<double>& theXYList )
68 TopoDS_Edge anEdge = Spline( theXYList, true );
72 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
73 TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
77 void test_HYDROData_LandCoverMap::test_add_2_objects()
79 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
81 Handle(HYDROData_LandCoverMap) aMap =
82 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
84 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
86 TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
87 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
89 TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
90 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
92 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
95 HYDROData_LandCoverMap::Iterator anIt( aMap );
96 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
97 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
99 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
100 CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
102 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
107 void test_HYDROData_LandCoverMap::test_split()
109 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
111 Handle(HYDROData_LandCoverMap) aMap =
112 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
114 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
116 TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
117 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
119 Handle(HYDROData_PolylineXY) aPolyline =
120 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
121 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
122 aPolyline->SetShape( aWire );
124 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
126 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
127 TestViewer::show( aWire, 0, true, Qt::blue );
128 CPPUNIT_ASSERT_IMAGES
130 HYDROData_LandCoverMap::Iterator anIt( aMap );
131 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
132 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
134 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
135 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
137 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
142 void test_HYDROData_LandCoverMap::test_incomplete_split()
144 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
146 Handle(HYDROData_LandCoverMap) aMap =
147 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
149 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
151 TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
152 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
154 Handle(HYDROData_PolylineXY) aPolyline =
155 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
156 TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 ) ).Wire();
157 aPolyline->SetShape( aWire );
159 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
161 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
162 TestViewer::show( aWire, 0, true, Qt::blue );
163 CPPUNIT_ASSERT_IMAGES
165 HYDROData_LandCoverMap::Iterator anIt( aMap );
166 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
167 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
169 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
174 void test_HYDROData_LandCoverMap::test_merge()
176 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
178 Handle(HYDROData_LandCoverMap) aMap =
179 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
181 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
183 TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
185 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
187 TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
188 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
189 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
191 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
193 TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
194 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
195 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
197 //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
198 //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
200 //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
202 QString aType1, aType2;
203 gp_Pnt2d aPnt1( 25, 35 );
204 gp_Pnt2d aPnt2( 45, 55 );
205 //gp_Pnt2d aPnt3( 45, 10 );
206 //gp_Pnt2d aPnt4( 45, 80 );
207 TopTools_ListOfShape aList;
208 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
209 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
210 CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
212 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
213 //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
214 CPPUNIT_ASSERT_IMAGES
219 void test_HYDROData_LandCoverMap::test_remove()
221 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
223 Handle(HYDROData_LandCoverMap) aMap =
224 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
226 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
228 TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
230 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
232 TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37 << 37 << 40 << 61 <<
233 44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
234 128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
236 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
238 TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1 << 47 << 51 << 45 <<
239 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
240 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
242 QString aType1, aType2;
243 gp_Pnt2d aPnt1( 25, 35 );
244 gp_Pnt2d aPnt2( 45, 55 );
245 TopTools_ListOfShape aList;
246 aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
247 aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
248 CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
250 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
251 CPPUNIT_ASSERT_IMAGES
256 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
258 TopoDS_Shape pp1, pp2, pp3, pp4;
260 BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
261 BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
262 BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
263 BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
265 CPPUNIT_ASSERT(!pp1.IsNull());
266 CPPUNIT_ASSERT(!pp2.IsNull());
267 CPPUNIT_ASSERT(!pp3.IsNull());
268 CPPUNIT_ASSERT(!pp4.IsNull());
270 //Test mergeFaces() func // boxes // USD == true
272 TopTools_ListOfShape Faces;
275 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
276 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs11" );
277 CPPUNIT_ASSERT_IMAGES
278 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
281 TopTools_ListOfShape Faces;
284 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
285 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs12" );
286 CPPUNIT_ASSERT_IMAGES
287 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
290 TopTools_ListOfShape Faces;
294 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
295 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs13" );
296 CPPUNIT_ASSERT_IMAGES
297 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
300 TopTools_ListOfShape Faces;
305 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
306 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs14" );
307 CPPUNIT_ASSERT_IMAGES
308 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
312 //Test mergeFaces() func // boxes // USD == false
314 TopTools_ListOfShape Faces;
317 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
318 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs21" );
319 CPPUNIT_ASSERT_IMAGES
320 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
323 TopTools_ListOfShape Faces;
326 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
327 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs22" );
328 CPPUNIT_ASSERT_IMAGES
329 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
332 TopTools_ListOfShape Faces;
336 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
337 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs23" );
338 CPPUNIT_ASSERT_IMAGES
339 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
342 TopTools_ListOfShape Faces;
347 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
348 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs24" );
349 CPPUNIT_ASSERT_IMAGES
350 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
355 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
357 TopoDS_Shape ff1, ff2, ff3;
359 BRepTools::Read(ff1, (REF_DATA_PATH + "/ff1.brep").toStdString().c_str(), BB);
360 BRepTools::Read(ff2, (REF_DATA_PATH + "/ff2.brep").toStdString().c_str(), BB);
361 BRepTools::Read(ff3, (REF_DATA_PATH + "/ff3.brep").toStdString().c_str(), BB);
363 CPPUNIT_ASSERT(!ff1.IsNull());
364 CPPUNIT_ASSERT(!ff2.IsNull());
365 CPPUNIT_ASSERT(!ff3.IsNull());
367 //Test mergeFaces() func // circles // USD == true
369 TopTools_ListOfShape Faces;
372 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
373 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs11_c" );
374 CPPUNIT_ASSERT_IMAGES
375 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
378 TopTools_ListOfShape Faces;
381 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
382 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs12_c" );
383 CPPUNIT_ASSERT_IMAGES
384 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
387 TopTools_ListOfShape Faces;
391 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
392 TestViewer::show( aMergedFace, AIS_Shaded, true, "_cs13" );
393 CPPUNIT_ASSERT_IMAGES
394 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
397 TopTools_ListOfShape Faces;
401 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
402 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs14_c" );
403 CPPUNIT_ASSERT_IMAGES
404 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
408 //Test mergeFaces() func // circles // USD == false
410 TopTools_ListOfShape Faces;
413 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
414 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs21_c" );
415 CPPUNIT_ASSERT_IMAGES
416 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
419 TopTools_ListOfShape Faces;
422 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
423 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs22_c" );
424 CPPUNIT_ASSERT_IMAGES
425 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
428 TopTools_ListOfShape Faces;
432 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
433 TestViewer::show( aMergedFace, AIS_Shaded, true, "_cs23" );
434 CPPUNIT_ASSERT_IMAGES
435 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
438 TopTools_ListOfShape Faces;
442 TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
443 TestViewer::show( aMergedFace, AIS_Shaded, true, "cs24_c" );
444 CPPUNIT_ASSERT_IMAGES
445 CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);