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>
44 const double EPS = 1E-3;
46 extern QString REF_DATA_PATH;
47 NCollection_Sequence<HYDROData_IPolyline::Point> points;
49 class DTM_item : public QGraphicsItem
52 DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
54 Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObjects()[0] );
55 Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
57 double xmin, xmax, ymin, ymax;
60 int n = pp->VertexNumber();
62 for( int i=1; i<=n; i++ )
64 gp_Pnt pnt = pp->Vertice( i );
65 Quantity_Color col = pp->VertexColor( i );
67 int r = col.Red()*255;
68 int g = col.Green()*255;
69 int b = col.Blue()*255;
70 int val = ( r << 16 ) + ( g << 8 ) + b;
74 myPoints[val].append( aPnt );
99 myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
102 virtual QRectF boundingRect() const
107 virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
109 QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
110 for( ; it!=last; it++ )
112 int r = ( it.key() >> 16 ) % 256;
113 int g = ( it.key() >> 8 ) % 256;
114 int b = ( it.key() >> 0 ) % 256;
115 QColor aColor( r, g, b );
116 QBrush aBrush( aColor );
117 foreach( QPointF pnt, it.value() )
119 QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
120 p->fillRect( r, aBrush );
128 QMap<int, QList<QPointF> > myPoints;
131 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
133 QGraphicsScene aScene;
135 DTM_item anItem( theDTM, theD );
137 aView.setScene( &aScene );
138 aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
139 aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
140 aScene.addItem( &anItem );
142 aView.resize( theWidth, theHeight );
143 QRectF bb = anItem.boundingRect();
144 aView.fitInView( bb, Qt::KeepAspectRatio );
145 QApplication::processEvents();
147 QPixmap aPixmap = QPixmap::grabWidget( &aView );
148 return aPixmap.toImage();
152 void test_HYDROData_DTM::setUp()
155 points.Append( gp_XY( 0.0, 5.0 ) );
156 points.Append( gp_XY( 1.0, 1.0 ) );
157 points.Append( gp_XY( 1.5, 0.0 ) );
158 points.Append( gp_XY( 4.0, 4.0 ) );
161 void test_HYDROData_DTM::test_creation()
163 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
165 Handle(HYDROData_DTM) DTM =
166 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
168 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
173 void test_HYDROData_DTM::test_hydraulic_axis()
175 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
177 Handle(HYDROData_Profile) aProfile1 =
178 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
180 Handle(HYDROData_Profile) aProfile2 =
181 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
183 Handle(HYDROData_Profile) aProfile3 =
184 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
186 aProfile1->SetParametricPoints( points );
187 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
188 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
189 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
191 aProfile2->SetParametricPoints( points );
192 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
193 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
194 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
196 aProfile3->SetParametricPoints( points );
197 aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
198 aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
199 aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
201 std::vector<double> distances;
202 std::vector<Handle(HYDROData_Profile)> profiles;
203 profiles.push_back( aProfile1 );
204 profiles.push_back( aProfile2 );
205 profiles.push_back( aProfile3 );
207 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
208 CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
209 CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
211 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS );
212 CPPUNIT_ASSERT_DOUBLES_EQUAL( 44.859, distances[1], EPS );
213 CPPUNIT_ASSERT_DOUBLES_EQUAL( 207.661, distances[2], EPS );
218 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS );
219 CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS );
220 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.X(), EPS );
221 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.Y(), EPS );
226 void test_HYDROData_DTM::test_profile_conversion_to_2d()
228 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
230 Handle(HYDROData_Profile) aProfile1 =
231 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
233 Handle(HYDROData_Profile) aProfile2 =
234 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
236 aProfile1->SetParametricPoints( points );
237 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
238 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
239 aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
241 aProfile2->SetParametricPoints( points );
242 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
243 aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
244 aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
246 double aUMin1 = DBL_MAX,
250 gp_Vec2d aProfileDir;
251 std::vector<Handle(Geom2d_Curve)> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir );
252 std::vector<Handle(Geom2d_Curve)> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir );
254 gp_Pnt2d aFirst, aLast;
255 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
256 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
257 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS );
258 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
259 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
260 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
261 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
262 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
263 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
264 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
265 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
266 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
267 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
268 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
269 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
270 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
271 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
272 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
273 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
274 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
275 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
277 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
278 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
279 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS );
280 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
281 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
282 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
283 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
284 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
285 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
286 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
287 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
288 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
289 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
290 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
291 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
292 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );
297 void test_HYDROData_DTM::test_profile_properties()
299 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
301 Handle(HYDROData_Profile) aProfile =
302 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
304 aProfile->SetParametricPoints( points );
305 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
306 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
307 aProfile->SetRightPoint( gp_XY( 20, 25 ) );
312 HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax );
313 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
314 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
315 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
316 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
317 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
318 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
319 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
321 /* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
322 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
323 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
324 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
326 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
327 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
328 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/
333 void test_HYDROData_DTM::test_profile_discretization_polyline()
335 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
337 Handle(HYDROData_Profile) aProfile =
338 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
340 aProfile->SetParametricPoints( points );
341 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
342 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
343 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
345 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
347 QSet<QString> warnings;
348 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
349 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
350 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS );
351 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
352 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS );
353 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
354 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS );
355 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
356 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
357 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
359 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
360 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS );
361 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
362 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS );
363 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
364 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS );
365 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
366 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
367 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
372 void test_HYDROData_DTM::test_profile_discretization_spline()
374 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
376 Handle(HYDROData_Profile) aProfile =
377 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
379 aProfile->SetParametricPoints( points );
380 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
381 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
382 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
384 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
386 QSet<QString> warnings;
387 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
388 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
389 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS );
390 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
391 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS );
392 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
393 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS );
394 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
395 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
396 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
398 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
399 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS );
400 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
401 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS );
402 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
403 CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS );
404 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
405 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
406 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
411 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
413 s << "(" << p.U << "; " << p.Z << ") ";
416 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
418 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
421 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
423 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
426 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
428 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
431 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
434 for( size_t i=0; i<n; i++ )
438 void test_HYDROData_DTM::test_curves_interpolation()
440 HYDROData_DTM::CurveUZ A(1.0, gp_Vec2d(), 0, 0), B(2.0, gp_Vec2d(), 0, 0);
441 A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
442 A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
443 A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
444 B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
445 B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
446 B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
448 std::vector<HYDROData_DTM::CurveUZ> i1;
449 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
451 CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
452 CPPUNIT_ASSERT_EQUAL( A, i1[0] );
453 CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
454 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
455 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
456 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
458 std::vector<HYDROData_DTM::CurveUZ> i2;
459 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
461 CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
462 CPPUNIT_ASSERT_EQUAL( A, i2[0] );
463 CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
464 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
465 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
466 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
467 CPPUNIT_ASSERT_EQUAL( B, i2[2] );
469 std::vector<HYDROData_DTM::CurveUZ> i3;
470 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
472 CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
473 CPPUNIT_ASSERT_EQUAL( A, i3[0] );
474 CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
475 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
476 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
477 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
480 void test_HYDROData_DTM::test_curve_to_3d()
482 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
484 Handle(HYDROData_Profile) aProfile1 =
485 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
487 Handle(HYDROData_Profile) aProfile2 =
488 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
490 aProfile1->SetParametricPoints( points );
491 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
492 aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
493 aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
495 aProfile2->SetParametricPoints( points );
496 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
497 aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
498 aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
500 std::vector<double> distances;
501 std::vector<Handle(HYDROData_Profile)> profiles;
502 profiles.push_back( aProfile1 );
503 profiles.push_back( aProfile2 );
505 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
506 HYDROData_DTM::AltitudePoints points;
507 HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0, 10 );
508 mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
509 mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
510 HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0, 10 );
511 wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
512 wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
513 HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
515 CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
516 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 21.588, 5.419, 6.0 ), points[0] );
517 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 20.881, 6.126, 5.0 ), points[1] );
518 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 19.466, 7.541, 5.0 ), points[2] );
519 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 17.345, 9.662, 6.0 ), points[3] );
524 void test_HYDROData_DTM::test_presentation()
526 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
528 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
530 Handle(HYDROData_Profile) aProfile1 =
531 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
533 Handle(HYDROData_Profile) aProfile2 =
534 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
536 aProfile1->SetParametricPoints( points );
537 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
538 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
539 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
541 aProfile2->SetParametricPoints( points );
542 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
543 aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
544 aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
546 HYDROData_SequenceOfObjects seq;
547 seq.Append( aProfile1 );
548 seq.Append( aProfile2 );
549 DTM->SetProfiles( seq );
551 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
552 DTM->SetSpatialStep( 1.0 );
553 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
556 CPPUNIT_ASSERT_EQUAL( 9108, (int)DTM->GetAltitudePoints().size() );
558 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
559 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
560 aBathPrs->update( true, false );
561 aBathPrs->RescaleDefault();
563 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
564 TestViewer::showColorScale( true );
565 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
568 aCS->SetNumberOfIntervals( 10 );
569 aBathPrs->UpdateWithColorScale( aCS );
570 //QTest::qWait(50000);
571 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
572 CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_1", false );
574 TestViewer::showColorScale( ColorScaleIsDisp );
579 void test_HYDROData_DTM::test_garonne()
581 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
583 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
584 fname += "/Profiles.xyz";
585 NCollection_Sequence<int> bad_ids;
587 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
589 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
590 CPPUNIT_ASSERT_EQUAL( 46, aSize );
592 HYDROData_SequenceOfObjects profiles;
593 HYDROData_Iterator it( aDoc, KIND_PROFILE );
594 for( int i=0; it.More(); it.Next(), i++ )
597 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
600 CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() );
602 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
603 DTM->SetProfiles( profiles );
605 DTM->SetSpatialStep( 1.0 );
606 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
607 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
610 CPPUNIT_ASSERT_EQUAL( 281898, (int)DTM->GetAltitudePoints().size() );
612 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
613 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
614 aBathPrs->update( true, false );
615 aBathPrs->RescaleDefault();
617 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
619 TestViewer::showColorScale( true );
620 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
623 aCS->SetNumberOfIntervals( 30 );
624 aBathPrs->UpdateWithColorScale( aCS );
626 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
627 CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_2", false );
628 TestViewer::showColorScale( ColorScaleIsDisp );
633 void test_HYDROData_DTM::test_classifier_1()
635 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
636 fname += "/pb_1066.cbf";
637 CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) );
639 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
641 Handle(HYDROData_CalculationCase) aCase =
642 Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) );
643 CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() );
644 std::vector<gp_XY> points;
645 points.push_back( gp_XY( 43.4842, 3.33176 ) );
646 points.push_back( gp_XY( -125.777, 2.24728 ) );
647 points.push_back( gp_XY( -60.1628, 168.262 ) );
648 points.push_back( gp_XY( 21.8055587645, 154.699344457 ) );
649 points.push_back( gp_XY( -84.4764138524, 79.2606012276 ) );
650 points.push_back( gp_XY( -73.4132070504, 69.7096313266 ) );
652 std::vector<double> values = aCase->GetStricklerCoefficientForPoints( points, 0.0, true );
653 CPPUNIT_ASSERT_EQUAL( 6, (int)values.size() );
654 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[0], EPS );
655 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[1], EPS );
656 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[2], EPS );
657 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[3], EPS );
658 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[4], EPS );
659 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[5], EPS );
661 std::vector<int> types = aCase->GetStricklerTypeForPoints( points );
662 CPPUNIT_ASSERT_EQUAL( 6, (int)types.size() );
663 CPPUNIT_ASSERT_EQUAL( 123, types[0] );
664 CPPUNIT_ASSERT_EQUAL( 123, types[1] );
665 CPPUNIT_ASSERT_EQUAL( 221, types[2] );
666 CPPUNIT_ASSERT_EQUAL( 221, types[3] );
667 CPPUNIT_ASSERT_EQUAL( 221, types[4] );
668 CPPUNIT_ASSERT_EQUAL( 221, types[5] );
673 void test_HYDROData_DTM::test_profile_discretization_warnings()
675 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
678 Handle(HYDROData_Profile) aProfile =
679 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
681 NCollection_Sequence<gp_XY> pnts;
682 pnts.Append( gp_XY( 0.0, 1.0 ) );
683 pnts.Append( gp_XY( 1.0, 0.0 ) );
684 pnts.Append( gp_XY( 2.0, 4.0 ) );
685 pnts.Append( gp_XY( 3.0, 5.0 ) );
687 aProfile->SetParametricPoints( pnts );
688 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
689 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
690 aProfile->SetRightPoint( gp_XY( 10, 20 ) );
692 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
694 QSet<QString> warnings;
695 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
697 //CPPUNIT_ASSERT_EQUAL(1, warnings.size());
698 CPPUNIT_ASSERT( warnings.contains("One of the extreme points is higher than another"));
701 Handle(HYDROData_Profile) aProfile =
702 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
704 NCollection_Sequence<gp_XY> pnts;
705 pnts.Append( gp_XY( 0.0, 1.0 ) );
706 pnts.Append( gp_XY( 1.0, 0.0 ) );
707 pnts.Append( gp_XY( 2.0, 5.0 ) );
708 pnts.Append( gp_XY( 3.0, 0.0 ) );
709 pnts.Append( gp_XY( 4.0, 1.0 ) );
711 aProfile->SetParametricPoints( pnts );
712 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
713 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
714 aProfile->SetRightPoint( gp_XY( 10, 20 ) );
716 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
718 QSet<QString> warnings;
719 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
721 CPPUNIT_ASSERT_EQUAL(1, warnings.size());
722 CPPUNIT_ASSERT( warnings.contains("More than 2 intersections between profile & altitude Z-lines found"));
726 Handle(HYDROData_Profile) aProfile =
727 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
729 NCollection_Sequence<gp_XY> pnts;
730 pnts.Append( gp_XY( 0.0, 5.0 ) );
731 pnts.Append( gp_XY( 1.0, 5.0 ) );
732 pnts.Append( gp_XY( 2.0, 0.5 ) );
733 pnts.Append( gp_XY( 3.0, 5.0 ) );
734 pnts.Append( gp_XY( 4.0, 5.0 ) );
736 aProfile->SetParametricPoints( pnts );
737 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
738 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
739 aProfile->SetRightPoint( gp_XY( 10, 20 ) );
741 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
743 QSet<QString> warnings;
744 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
746 CPPUNIT_ASSERT_EQUAL(2, warnings.size());
747 CPPUNIT_ASSERT( warnings.contains("Plato case on extremes"));