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_DTM.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_Profile.h>
22 #include <HYDROData_DTM.h>
23 #include <HYDROData_Iterator.h>
24 #include <HYDROData_CalculationCase.h>
25 #include <Geom2d_Curve.hxx>
26 #include <Geom2d_BSplineCurve.hxx>
28 #include <gp_Pnt2d.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
30 #include <TestViewer.h>
31 #include <AIS_InteractiveContext.hxx>
32 #include <AIS_PointCloud.hxx>
33 #include <HYDROGUI_ShapeBathymetry.h>
34 #include <AIS_ColorScale.hxx>
35 #include <QGraphicsItem>
36 #include <QGraphicsScene>
37 #include <QGraphicsView>
39 #include <QApplication>
42 const double EPS = 1E-3;
44 extern QString REF_DATA_PATH;
45 NCollection_Sequence<HYDROData_IPolyline::Point> points;
47 class DTM_item : public QGraphicsItem
50 DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
52 Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObjects()[0] );
53 Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
55 double xmin, xmax, ymin, ymax;
58 int n = pp->VertexNumber();
60 for( int i=1; i<=n; i++ )
62 gp_Pnt pnt = pp->Vertice( i );
63 Quantity_Color col = pp->VertexColor( i );
65 int r = col.Red()*255;
66 int g = col.Green()*255;
67 int b = col.Blue()*255;
68 int val = ( r << 16 ) + ( g << 8 ) + b;
72 myPoints[val].append( aPnt );
97 myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
100 virtual QRectF boundingRect() const
105 virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
107 QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
108 for( ; it!=last; it++ )
110 int r = ( it.key() >> 16 ) % 256;
111 int g = ( it.key() >> 8 ) % 256;
112 int b = ( it.key() >> 0 ) % 256;
113 QColor aColor( r, g, b );
114 QBrush aBrush( aColor );
115 foreach( QPointF pnt, it.value() )
117 QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
118 p->fillRect( r, aBrush );
126 QMap<int, QList<QPointF> > myPoints;
129 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
131 QGraphicsScene aScene;
133 DTM_item anItem( theDTM, theD );
135 aView.setScene( &aScene );
136 aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
137 aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
138 aScene.addItem( &anItem );
140 aView.resize( theWidth, theHeight );
141 QRectF bb = anItem.boundingRect();
142 aView.fitInView( bb, Qt::KeepAspectRatio );
143 QApplication::processEvents();
145 QPixmap aPixmap = QPixmap::grabWidget( &aView );
146 return aPixmap.toImage();
150 void test_HYDROData_DTM::setUp()
153 points.Append( gp_XY( 0.0, 5.0 ) );
154 points.Append( gp_XY( 1.0, 1.0 ) );
155 points.Append( gp_XY( 1.5, 0.0 ) );
156 points.Append( gp_XY( 4.0, 4.0 ) );
159 void test_HYDROData_DTM::test_creation()
161 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
163 Handle(HYDROData_DTM) DTM =
164 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
166 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
171 void test_HYDROData_DTM::test_hydraulic_axis()
173 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
175 Handle(HYDROData_Profile) aProfile1 =
176 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
178 Handle(HYDROData_Profile) aProfile2 =
179 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
181 Handle(HYDROData_Profile) aProfile3 =
182 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
184 aProfile1->SetParametricPoints( points );
185 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
186 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
187 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
189 aProfile2->SetParametricPoints( points );
190 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
191 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
192 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
194 aProfile3->SetParametricPoints( points );
195 aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
196 aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
197 aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
199 std::vector<double> distances;
200 std::vector<Handle(HYDROData_Profile)> profiles;
201 profiles.push_back( aProfile1 );
202 profiles.push_back( aProfile2 );
203 profiles.push_back( aProfile3 );
205 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
206 CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
207 CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
209 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS );
210 CPPUNIT_ASSERT_DOUBLES_EQUAL( 44.859, distances[1], EPS );
211 CPPUNIT_ASSERT_DOUBLES_EQUAL( 207.661, distances[2], EPS );
216 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS );
217 CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS );
218 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.X(), EPS );
219 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.Y(), EPS );
224 void test_HYDROData_DTM::test_profile_conversion_to_2d()
226 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
228 Handle(HYDROData_Profile) aProfile1 =
229 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
231 Handle(HYDROData_Profile) aProfile2 =
232 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
234 aProfile1->SetParametricPoints( points );
235 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
236 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
237 aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
239 aProfile2->SetParametricPoints( points );
240 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
241 aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
242 aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
244 double aUMin1 = std::numeric_limits<double>::max(),
248 gp_Vec2d aProfileDir;
249 std::vector<Handle(Geom2d_Curve)> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir );
250 std::vector<Handle(Geom2d_Curve)> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir );
252 gp_Pnt2d aFirst, aLast;
253 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
254 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
255 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS );
256 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
257 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
258 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
259 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
260 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
261 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
262 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
263 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
264 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
265 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
266 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
267 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
268 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
269 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
270 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
271 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
272 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
273 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
275 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
276 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
277 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS );
278 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
279 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
280 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
281 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
282 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
284 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
285 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
286 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
287 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
288 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
289 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
290 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );
295 void test_HYDROData_DTM::test_profile_properties()
297 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
299 Handle(HYDROData_Profile) aProfile =
300 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
302 aProfile->SetParametricPoints( points );
303 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
304 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
305 aProfile->SetRightPoint( gp_XY( 20, 25 ) );
310 HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax );
311 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
313 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
314 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
315 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
316 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
317 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
319 /* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
320 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
321 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
322 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
323 CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
324 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
326 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/
331 void test_HYDROData_DTM::test_profile_discretization_polyline()
333 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
335 Handle(HYDROData_Profile) aProfile =
336 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
338 aProfile->SetParametricPoints( points );
339 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
340 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
341 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
343 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
345 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy );
346 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
347 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS );
348 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
349 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS );
350 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
351 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS );
352 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
353 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
354 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
356 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
357 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS );
358 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
359 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS );
360 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
361 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS );
362 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
363 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
364 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
369 void test_HYDROData_DTM::test_profile_discretization_spline()
371 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
373 Handle(HYDROData_Profile) aProfile =
374 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
376 aProfile->SetParametricPoints( points );
377 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
378 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
379 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
381 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
383 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy );
384 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
385 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS );
386 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
387 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS );
388 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
389 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS );
390 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
391 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
392 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
394 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
395 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS );
396 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
397 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS );
398 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
399 CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS );
400 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
401 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
402 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
407 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
409 s << "(" << p.U << "; " << p.Z << ") ";
412 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
414 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
417 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
419 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
422 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
424 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
427 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
430 for( size_t i=0; i<n; i++ )
434 void test_HYDROData_DTM::test_curves_interpolation()
436 HYDROData_DTM::CurveUZ A(1.0, gp_Vec2d(), 0, 0), B(2.0, gp_Vec2d(), 0, 0);
437 A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
438 A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
439 A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
440 B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
441 B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
442 B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
444 std::vector<HYDROData_DTM::CurveUZ> i1;
445 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
447 CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
448 CPPUNIT_ASSERT_EQUAL( A, i1[0] );
449 CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
450 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
451 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
452 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
454 std::vector<HYDROData_DTM::CurveUZ> i2;
455 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
457 CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
458 CPPUNIT_ASSERT_EQUAL( A, i2[0] );
459 CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
460 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
461 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
462 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
463 CPPUNIT_ASSERT_EQUAL( B, i2[2] );
465 std::vector<HYDROData_DTM::CurveUZ> i3;
466 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
468 CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
469 CPPUNIT_ASSERT_EQUAL( A, i3[0] );
470 CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
471 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
472 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
473 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
476 void test_HYDROData_DTM::test_curve_to_3d()
478 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
480 Handle(HYDROData_Profile) aProfile1 =
481 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
483 Handle(HYDROData_Profile) aProfile2 =
484 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
486 aProfile1->SetParametricPoints( points );
487 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
488 aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
489 aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
491 aProfile2->SetParametricPoints( points );
492 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
493 aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
494 aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
496 std::vector<double> distances;
497 std::vector<Handle(HYDROData_Profile)> profiles;
498 profiles.push_back( aProfile1 );
499 profiles.push_back( aProfile2 );
501 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
502 HYDROData_DTM::AltitudePoints points;
503 HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0, 10 );
504 mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
505 mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
506 HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0, 10 );
507 wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
508 wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
509 HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
511 CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
512 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 21.588, 5.419, 6.0 ), points[0] );
513 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 20.881, 6.126, 5.0 ), points[1] );
514 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 19.466, 7.541, 5.0 ), points[2] );
515 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 17.345, 9.662, 6.0 ), points[3] );
520 void test_HYDROData_DTM::test_presentation()
522 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
524 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
526 Handle(HYDROData_Profile) aProfile1 =
527 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
529 Handle(HYDROData_Profile) aProfile2 =
530 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
532 aProfile1->SetParametricPoints( points );
533 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
534 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
535 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
537 aProfile2->SetParametricPoints( points );
538 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
539 aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
540 aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
542 HYDROData_SequenceOfObjects seq;
543 seq.Append( aProfile1 );
544 seq.Append( aProfile2 );
545 DTM->SetProfiles( seq );
547 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
548 DTM->SetSpatialStep( 1.0 );
549 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
552 CPPUNIT_ASSERT_EQUAL( 9108, (int)DTM->GetAltitudePoints().size() );
554 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
555 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
556 aBathPrs->update( true, false );
557 aBathPrs->RescaleDefault();
559 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
560 TestViewer::showColorScale( true );
561 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
564 aCS->SetNumberOfIntervals( 10 );
565 aBathPrs->UpdateWithColorScale( aCS );
566 //QTest::qWait(50000);
567 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
568 CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_1", false );
570 TestViewer::showColorScale( ColorScaleIsDisp );
575 void test_HYDROData_DTM::test_garonne()
577 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
579 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
580 fname += "/Profiles.xyz";
581 NCollection_Sequence<int> bad_ids;
583 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
585 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
586 CPPUNIT_ASSERT_EQUAL( 46, aSize );
588 HYDROData_SequenceOfObjects profiles;
589 HYDROData_Iterator it( aDoc, KIND_PROFILE );
590 for( int i=0; it.More(); it.Next(), i++ )
593 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
596 CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() );
598 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
599 DTM->SetProfiles( profiles );
601 DTM->SetSpatialStep( 1.0 );
602 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
603 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
606 CPPUNIT_ASSERT_EQUAL( 281898, (int)DTM->GetAltitudePoints().size() );
608 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
609 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
610 aBathPrs->update( true, false );
611 aBathPrs->RescaleDefault();
613 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
615 TestViewer::showColorScale( true );
616 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
619 aCS->SetNumberOfIntervals( 30 );
620 aBathPrs->UpdateWithColorScale( aCS );
622 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
623 CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_2", false );
624 TestViewer::showColorScale( ColorScaleIsDisp );
629 void test_HYDROData_DTM::test_classifier_1()
631 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
632 fname += "/pb_1066.cbf";
633 CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) );
635 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
637 Handle(HYDROData_CalculationCase) aCase =
638 Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) );
639 CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() );
640 std::vector<gp_XY> points;
641 points.push_back( gp_XY( 43.4842, 3.33176 ) );
642 points.push_back( gp_XY( -125.777, 2.24728 ) );
643 points.push_back( gp_XY( -60.1628, 168.262 ) );
644 points.push_back( gp_XY( 21.8055587645, 154.699344457 ) );
645 points.push_back( gp_XY( -84.4764138524, 79.2606012276 ) );
646 points.push_back( gp_XY( -73.4132070504, 69.7096313266 ) );
648 std::vector<double> values = aCase->GetStricklerCoefficientForPoints( points, 0.0, true );
649 CPPUNIT_ASSERT_EQUAL( 6, (int)values.size() );
650 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[0], EPS );
651 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[1], EPS );
652 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[2], EPS );
653 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[3], EPS );
654 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[4], EPS );
655 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[5], EPS );
657 std::vector<int> types = aCase->GetStricklerTypeForPoints( points );
658 CPPUNIT_ASSERT_EQUAL( 6, (int)types.size() );
659 CPPUNIT_ASSERT_EQUAL( 123, types[0] );
660 CPPUNIT_ASSERT_EQUAL( 123, types[1] );
661 CPPUNIT_ASSERT_EQUAL( 221, types[2] );
662 CPPUNIT_ASSERT_EQUAL( 221, types[3] );
663 CPPUNIT_ASSERT_EQUAL( 221, types[4] );
664 CPPUNIT_ASSERT_EQUAL( 221, types[5] );