Salome HOME
Merge branch 'BR_MULTI_BATHS' into HEAD
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_DTM.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_DTM.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_Profile.h>
22 #include <HYDROData_DTM.h>
23 #include <Geom2d_Curve.hxx>
24 #include <Geom2d_BSplineCurve.hxx>
25 #include <gp_XY.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
28 #include <TestViewer.h>
29 #include <AIS_InteractiveContext.hxx>
30 #include <AIS_PointCloud.hxx>
31 #include <HYDROGUI_ShapeBathymetry.h>
32 #include <Aspect_ColorScale.hxx>
33 #include <QGraphicsItem>
34 #include <QGraphicsScene>
35 #include <QGraphicsView>
36 #include <QPixmap>
37 #include <QApplication>
38
39 const double EPS = 1E-3;
40
41 NCollection_Sequence<HYDROData_IPolyline::Point> points;
42
43 class DTM_item : public QGraphicsItem
44 {
45 public:
46   DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
47   {
48     Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() );
49     Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
50     myBB = QRectF();
51     double xmin, xmax, ymin, ymax;
52     myD = d;
53
54     int n = pp->VertexNumber();
55     
56     for( int i=1; i<=n; i++ )
57     {
58       gp_Pnt pnt = pp->Vertice( i );
59       Quantity_Color col = pp->VertexColor( i );
60
61       int r = col.Red()*255;
62       int g = col.Green()*255;
63       int b = col.Blue()*255;
64       int val = ( r << 16 ) + ( g << 8 ) + b;
65       double x = pnt.X();
66       double y = -pnt.Y();
67       QPointF aPnt( x, y );
68       myPoints[val].append( aPnt );
69       if( i==1 )
70       {
71         xmin = x;
72         xmax = x;
73         ymin = y;
74         ymax = y;
75       }
76       else
77       {
78         if( x>xmax )
79           xmax = x;
80         if( x<xmin )
81           xmin = x;
82         if( y>ymax )
83           ymax = y;
84         if( y<ymin )
85           ymin = y;
86       }
87     }
88
89     xmin -= 10;
90     xmax += 10;
91     ymin -= 10;
92     ymax += 10;
93     myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
94   }
95
96   virtual QRectF boundingRect() const
97   {
98     return myBB;
99   }
100
101   virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
102   {
103     QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
104     for( ; it!=last; it++ )
105     {
106       int r = ( it.key() >> 16 ) % 256;
107       int g = ( it.key() >> 8  ) % 256;
108       int b = ( it.key() >> 0  ) % 256;
109       QColor aColor( r, g, b );
110       QBrush aBrush( aColor );
111       foreach( QPointF pnt, it.value() )
112       {
113         QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
114         p->fillRect( r, aBrush );
115       }
116     }
117   }
118
119 private:
120   QRectF myBB;
121   double myD;
122   QMap<int, QList<QPointF> > myPoints;
123 };
124
125 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
126 {
127   QGraphicsScene aScene;
128   QGraphicsView aView;
129   DTM_item anItem( theDTM, theD );
130
131   aView.setScene( &aScene );
132   aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
133   aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
134   aScene.addItem( &anItem );
135
136   aView.resize( theWidth, theHeight );
137   QRectF bb = anItem.boundingRect();
138   aView.fitInView( bb, Qt::KeepAspectRatio );
139   QApplication::processEvents();
140
141   QPixmap aPixmap = QPixmap::grabWidget( &aView );
142   return aPixmap.toImage();
143 }
144
145
146 void test_HYDROData_DTM::setUp()
147 {
148   points.Clear();
149   points.Append( gp_XY( 0.0, 5.0 ) );
150   points.Append( gp_XY( 1.0, 1.0 ) );
151   points.Append( gp_XY( 1.5, 0.0 ) );
152   points.Append( gp_XY( 4.0, 4.0 ) );
153 }
154
155 void test_HYDROData_DTM::test_creation()
156 {
157   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
158
159   Handle(HYDROData_DTM) DTM = 
160     Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
161
162   CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
163    
164   aDoc->Close();
165 }
166
167 void test_HYDROData_DTM::test_hydraulic_axis()
168 {
169   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
170
171   Handle(HYDROData_Profile) aProfile1 = 
172     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
173
174   Handle(HYDROData_Profile) aProfile2 = 
175     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
176
177   Handle(HYDROData_Profile) aProfile3 = 
178     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
179
180   aProfile1->SetParametricPoints( points );
181   aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
182   aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
183   aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
184
185   aProfile2->SetParametricPoints( points );
186   aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
187   aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
188   aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
189
190   aProfile3->SetParametricPoints( points );
191   aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
192   aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
193   aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
194
195   std::vector<double> distances;
196   std::vector<Handle(HYDROData_Profile)> profiles;
197   profiles.push_back( aProfile1 );
198   profiles.push_back( aProfile2 );
199   profiles.push_back( aProfile3 );
200
201   Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
202   CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
203   CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
204
205   CPPUNIT_ASSERT_DOUBLES_EQUAL(   0.0,   distances[0], EPS );
206   CPPUNIT_ASSERT_DOUBLES_EQUAL(  43.499, distances[1], EPS );
207   CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS );
208
209   gp_Pnt2d p;
210   gp_Vec2d q;
211   HA->D1( 0, p, q );
212   CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS );
213   CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS );
214   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS );
215   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS );
216
217   aDoc->Close();
218 }
219
220 void test_HYDROData_DTM::test_profile_conversion_to_2d()
221 {
222   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
223
224   Handle(HYDROData_Profile) aProfile1 = 
225     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
226
227   Handle(HYDROData_Profile) aProfile2 = 
228     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
229
230   aProfile1->SetParametricPoints( points );
231   aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
232   aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
233   aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
234
235   aProfile2->SetParametricPoints( points );
236   aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
237   aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
238   aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
239
240   double aUMin1 = std::numeric_limits<double>::max(),
241          aUMax1 = -aUMin1,
242          aUMin2 = aUMin1,
243          aUMax2 = aUMax1;
244   std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1 );
245   std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2 );
246
247   gp_Pnt2d aFirst, aLast;
248   CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
249   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
250   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aUMax1, EPS );
251   curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
252   curves1[0]->D0( curves1[0]->LastParameter(), aLast );
253   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
254   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aFirst.Y(), EPS );
255   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(),  EPS );
256   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.0,   aLast.Y(),  EPS );
257   curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
258   curves1[1]->D0( curves1[1]->LastParameter(), aLast );
259   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
260   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.0,   aFirst.Y(), EPS );
261   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aLast.X(),  EPS );
262   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aLast.Y(),  EPS );
263   curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
264   curves1[2]->D0( curves1[2]->LastParameter(), aLast );
265   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aFirst.X(), EPS );
266   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aFirst.Y(), EPS );
267   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aLast.X(),  EPS );
268   CPPUNIT_ASSERT_DOUBLES_EQUAL(  4.0,   aLast.Y(),  EPS );
269
270   CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
271   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
272   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.839, aUMax2, EPS );
273   Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
274   CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
275   const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
276   CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
277   CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
278   CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
279   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   poles.Value( 1 ).Y(), EPS );
280   CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
281   CPPUNIT_ASSERT_DOUBLES_EQUAL(  3.667, poles.Value( 2 ).Y(), EPS );
282   CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
283   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.120, poles.Value( 3 ).Y(), EPS );
284   CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
285   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.574, poles.Value( 4 ).Y(), EPS );
286
287   aDoc->Close();
288 }
289
290 void test_HYDROData_DTM::test_profile_properties()
291 {
292   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
293
294   Handle(HYDROData_Profile) aProfile = 
295     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
296
297   aProfile->SetParametricPoints( points );
298   aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
299   aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
300   aProfile->SetRightPoint( gp_XY( 20, 25 ) );
301
302   gp_Pnt lp;
303   gp_Vec2d dd;
304   double zmin, zmax;
305   HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax );
306   CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
307   CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
308   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
309   CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
310   CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
311   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
312   CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
313
314   HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
315   CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
316   CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
317   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
318   CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
319   CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
320   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
321   CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
322
323   aDoc->Close();
324 }
325
326 void test_HYDROData_DTM::test_profile_discretization_polyline()
327 {
328   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
329
330   Handle(HYDROData_Profile) aProfile = 
331     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
332
333   aProfile->SetParametricPoints( points );
334   aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
335   aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
336   aProfile->SetRightPoint( gp_XY( 20, 20 ) );
337
338   HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 );
339   HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid );
340   CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
341   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aMid[0].U, EPS );
342   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aMid[0].Z, EPS );
343   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.11,  aMid[1].U, EPS );
344   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aMid[1].Z, EPS );
345   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.215, aMid[5].U, EPS );
346   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aMid[5].Z, EPS );
347   CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS );
348   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aMid[10].Z, EPS );
349
350   CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
351   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].U, EPS );
352   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].Z, EPS );
353   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.989, aWid[1].U, EPS );
354   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aWid[1].Z, EPS );
355   CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.618, aWid[5].U, EPS );
356   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aWid[5].Z, EPS );
357   CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
358   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aWid[10].Z, EPS );
359
360   aDoc->Close();
361 }
362
363 void test_HYDROData_DTM::test_profile_discretization_spline()
364 {
365 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
366
367   Handle(HYDROData_Profile) aProfile = 
368     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
369
370   aProfile->SetParametricPoints( points );
371   aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
372   aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
373   aProfile->SetRightPoint( gp_XY( 20, 20 ) );
374
375   HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 );
376   HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid );
377   CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
378   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.242, aMid[0].U, EPS );
379   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aMid[0].Z, EPS );
380   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.755, aMid[1].U, EPS );
381   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aMid[1].Z, EPS );
382   CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.473, aMid[5].U, EPS );
383   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aMid[5].Z, EPS );
384   CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS );
385   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aMid[10].Z, EPS );
386
387   CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
388   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.484, aWid[0].U, EPS );
389   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].Z, EPS );
390   CPPUNIT_ASSERT_DOUBLES_EQUAL(  3.809, aWid[1].U, EPS );
391   CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aWid[1].Z, EPS );
392   CPPUNIT_ASSERT_DOUBLES_EQUAL(  9.472, aWid[5].U, EPS );
393   CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aWid[5].Z, EPS );
394   CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
395   CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aWid[10].Z, EPS );
396
397   aDoc->Close();
398 }
399
400 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
401 {
402   s << "(" << p.U << "; " << p.Z << ") ";
403 }
404
405 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
406 {
407   s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
408 }
409
410 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
411 {
412   return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
413 }
414
415 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
416 {
417   return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
418 }
419
420 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
421 {
422   size_t n = c.size();
423   for( size_t i=0; i<n; i++ )
424     s << c[i];
425 }
426
427 void test_HYDROData_DTM::test_curves_interpolation()
428 {
429   HYDROData_DTM::CurveUZ A(1.0), B(2.0);
430   A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
431   A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
432   A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
433   B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
434   B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
435   B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
436
437   std::vector<HYDROData_DTM::CurveUZ> i1;
438   HYDROData_DTM::Interpolate( A, B, 1, i1, false );
439
440   CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
441   CPPUNIT_ASSERT_EQUAL( A, i1[0] );
442   CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
443   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
444   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
445   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
446
447   std::vector<HYDROData_DTM::CurveUZ> i2;
448   HYDROData_DTM::Interpolate( A, B, 1, i2, true );
449
450   CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
451   CPPUNIT_ASSERT_EQUAL( A, i2[0] );
452   CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
453   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
454   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
455   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
456   CPPUNIT_ASSERT_EQUAL( B, i2[2] );
457
458   std::vector<HYDROData_DTM::CurveUZ> i3;
459   HYDROData_DTM::Interpolate( A, B, 3, i3, false );
460
461   CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
462   CPPUNIT_ASSERT_EQUAL( A, i3[0] );
463   CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
464   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
465   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
466   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
467 }
468
469 void test_HYDROData_DTM::test_curve_to_3d()
470 {
471   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
472
473   Handle(HYDROData_Profile) aProfile1 = 
474     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
475
476   Handle(HYDROData_Profile) aProfile2 = 
477     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
478
479   aProfile1->SetParametricPoints( points );
480   aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
481   aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
482   aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
483
484   aProfile2->SetParametricPoints( points );
485   aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
486   aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
487   aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
488
489   std::vector<double> distances;
490   std::vector<Handle(HYDROData_Profile)> profiles;
491   profiles.push_back( aProfile1 );
492   profiles.push_back( aProfile2 );
493
494   Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
495   HYDROData_DTM::AltitudePoints points;
496   HYDROData_DTM::CurveUZ mid( 5.0 );
497   mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
498   mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
499   HYDROData_DTM::CurveUZ wid( 5.0 );
500   wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
501   wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
502   HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
503
504   CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
505   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.434, -0.598, 5.0 ), points[0] );
506   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.497, -0.947, 5.0 ), points[1] );
507   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.903, -0.423, 6.0 ), points[2] );
508   CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 13.092, -1.471, 6.0 ), points[3] );
509
510   aDoc->Close();
511 }
512
513 void test_HYDROData_DTM::test_presentation()
514 {
515   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
516
517   Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
518
519   Handle(HYDROData_Profile) aProfile1 = 
520     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
521
522   Handle(HYDROData_Profile) aProfile2 = 
523     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
524
525   aProfile1->SetParametricPoints( points );
526   aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
527   aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
528   aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
529
530   aProfile2->SetParametricPoints( points );
531   aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
532   aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
533   aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
534
535   HYDROData_SequenceOfObjects seq;
536   seq.Append( aProfile1 );
537   seq.Append( aProfile2 );
538   DTM->SetProfiles( seq );
539   DTM->SetDDZ( 0.1 );
540   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
541   DTM->SetSpatialStep( 1.0 );
542   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
543   DTM->Update();
544   
545   CPPUNIT_ASSERT_EQUAL( 10200, (int)DTM->GetAltitudePoints().size() ); 
546
547   Handle_AIS_InteractiveContext aContext = TestViewer::context();
548   HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
549   aBathPrs->update( true, false );
550
551   TestViewer::showColorScale( true );
552   Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
553   aCS->SetMin( 0.0 );
554   aCS->SetMax( 5.0 );
555   aCS->SetNumberOfIntervals( 10 );
556   aBathPrs->UpdateWithColorScale( aCS );
557   
558   QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
559   CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" );
560   delete aBathPrs;
561
562   aDoc->Close();
563 }
564
565 void test_HYDROData_DTM::test_garonne()
566 {
567   //TODO
568 }