Salome HOME
d2df73aa702fd9062c131f65d78368dd27ad9c3e
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_LandCoverMap.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <test_HYDROData_LandCoverMap.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_LandCoverMap.h>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Wire.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TColgp_HArray1OfPnt.hxx>
26 #include <GeomAPI_Interpolate.hxx>
27 #include <BRepBuilderAPI_MakeEdge.hxx>
28 #include <BRepBuilderAPI_MakeFace.hxx>
29 #include <BRepBuilderAPI_MakeWire.hxx>
30 #include <TestViewer.h>
31 #include <AIS_DisplayMode.hxx>
32 #include <QString>
33
34 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
35 {
36   int n = theXYList.size()/2;
37   Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
38   for( int i=1; i<=n; i++ )
39   {
40     double x = theXYList[2*i-2];
41     double y = theXYList[2*i-1];
42     gp_Pnt aPnt( x, y, 0 );
43     aPointsArray->SetValue( i, aPnt );
44   }
45   GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
46   anInterpolator.Perform();
47   bool aResult = anInterpolator.IsDone() == Standard_True;
48   if( aResult )
49   {
50     Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
51     return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
52   }
53   else
54     return TopoDS_Edge();
55 }
56
57 TopoDS_Face LandCover( const QList<double>& theXYList )
58 {
59   TopoDS_Edge anEdge = Spline( theXYList, true );
60   if( anEdge.IsNull() )
61     return TopoDS_Face();
62
63   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
64   TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
65   return aFace;
66 }
67
68 void test_HYDROData_LandCoverMap::test_local_partition()
69 {
70   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
71
72   Handle(HYDROData_LandCoverMap) aMap =
73     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
74
75   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
76
77   TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
78   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
79
80   TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
81   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
82
83   TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
84
85   aDoc->Close();
86 }
87