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