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>
41 const double EPS = 1E-3;
43 extern QString REF_DATA_PATH;
44 NCollection_Sequence<HYDROData_IPolyline::Point> points;
46 class DTM_item : public QGraphicsItem
49 DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
51 Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() );
52 Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
54 double xmin, xmax, ymin, ymax;
57 int n = pp->VertexNumber();
59 for( int i=1; i<=n; i++ )
61 gp_Pnt pnt = pp->Vertice( i );
62 Quantity_Color col = pp->VertexColor( i );
64 int r = col.Red()*255;
65 int g = col.Green()*255;
66 int b = col.Blue()*255;
67 int val = ( r << 16 ) + ( g << 8 ) + b;
71 myPoints[val].append( aPnt );
96 myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
99 virtual QRectF boundingRect() const
104 virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
106 QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
107 for( ; it!=last; it++ )
109 int r = ( it.key() >> 16 ) % 256;
110 int g = ( it.key() >> 8 ) % 256;
111 int b = ( it.key() >> 0 ) % 256;
112 QColor aColor( r, g, b );
113 QBrush aBrush( aColor );
114 foreach( QPointF pnt, it.value() )
116 QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
117 p->fillRect( r, aBrush );
125 QMap<int, QList<QPointF> > myPoints;
128 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
130 QGraphicsScene aScene;
132 DTM_item anItem( theDTM, theD );
134 aView.setScene( &aScene );
135 aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
136 aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
137 aScene.addItem( &anItem );
139 aView.resize( theWidth, theHeight );
140 QRectF bb = anItem.boundingRect();
141 aView.fitInView( bb, Qt::KeepAspectRatio );
142 QApplication::processEvents();
144 QPixmap aPixmap = QPixmap::grabWidget( &aView );
145 return aPixmap.toImage();
149 void test_HYDROData_DTM::setUp()
152 points.Append( gp_XY( 0.0, 5.0 ) );
153 points.Append( gp_XY( 1.0, 1.0 ) );
154 points.Append( gp_XY( 1.5, 0.0 ) );
155 points.Append( gp_XY( 4.0, 4.0 ) );
158 void test_HYDROData_DTM::test_creation()
160 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
162 Handle(HYDROData_DTM) DTM =
163 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
165 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
170 void test_HYDROData_DTM::test_hydraulic_axis()
172 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
174 Handle(HYDROData_Profile) aProfile1 =
175 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
177 Handle(HYDROData_Profile) aProfile2 =
178 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
180 Handle(HYDROData_Profile) aProfile3 =
181 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
183 aProfile1->SetParametricPoints( points );
184 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
185 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
186 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
188 aProfile2->SetParametricPoints( points );
189 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
190 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
191 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
193 aProfile3->SetParametricPoints( points );
194 aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
195 aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
196 aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
198 std::vector<double> distances;
199 std::vector<Handle(HYDROData_Profile)> profiles;
200 profiles.push_back( aProfile1 );
201 profiles.push_back( aProfile2 );
202 profiles.push_back( aProfile3 );
204 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
205 CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
206 CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
208 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS );
209 CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS );
210 CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS );
215 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS );
216 CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS );
217 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS );
218 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS );
223 void test_HYDROData_DTM::test_profile_conversion_to_2d()
225 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
227 Handle(HYDROData_Profile) aProfile1 =
228 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
230 Handle(HYDROData_Profile) aProfile2 =
231 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
233 aProfile1->SetParametricPoints( points );
234 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
235 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
236 aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
238 aProfile2->SetParametricPoints( points );
239 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
240 aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
241 aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
243 double aUMin1 = std::numeric_limits<double>::max(),
247 gp_Vec2d aProfileDir;
248 std::vector<Handle(Geom2d_Curve)> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir );
249 std::vector<Handle(Geom2d_Curve)> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir );
251 gp_Pnt2d aFirst, aLast;
252 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
253 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
254 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS );
255 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
256 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
257 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
258 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
259 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
260 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
261 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
262 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
263 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
264 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
265 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
266 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
267 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
268 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
269 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
270 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
271 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
272 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
274 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
275 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
276 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS );
277 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
278 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
279 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
280 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
281 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
284 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
285 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
286 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
287 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
288 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
289 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );
294 void test_HYDROData_DTM::test_profile_properties()
296 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
298 Handle(HYDROData_Profile) aProfile =
299 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
301 aProfile->SetParametricPoints( points );
302 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
303 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
304 aProfile->SetRightPoint( gp_XY( 20, 25 ) );
309 HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax );
310 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
311 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
313 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
314 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
315 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
316 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
318 /* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
319 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
320 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
321 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
322 CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
323 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
324 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
325 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/
330 void test_HYDROData_DTM::test_profile_discretization_polyline()
332 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
334 Handle(HYDROData_Profile) aProfile =
335 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
337 aProfile->SetParametricPoints( points );
338 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
339 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
340 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
342 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
344 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy );
345 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
346 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS );
347 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
348 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS );
349 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
350 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS );
351 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
352 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
353 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
355 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
356 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS );
357 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
358 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS );
359 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
360 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS );
361 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
362 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
363 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
368 void test_HYDROData_DTM::test_profile_discretization_spline()
370 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
372 Handle(HYDROData_Profile) aProfile =
373 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
375 aProfile->SetParametricPoints( points );
376 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
377 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
378 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
380 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
382 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy );
383 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
384 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS );
385 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
386 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS );
387 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
388 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS );
389 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
390 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
391 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
393 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
394 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS );
395 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
396 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS );
397 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
398 CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS );
399 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
400 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
401 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
406 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
408 s << "(" << p.U << "; " << p.Z << ") ";
411 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
413 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
416 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
418 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
421 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
423 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
426 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
429 for( size_t i=0; i<n; i++ )
433 void test_HYDROData_DTM::test_curves_interpolation()
435 HYDROData_DTM::CurveUZ A(1.0, gp_Vec2d(), 0, 0), B(2.0, gp_Vec2d(), 0, 0);
436 A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
437 A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
438 A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
439 B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
440 B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
441 B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
443 std::vector<HYDROData_DTM::CurveUZ> i1;
444 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
446 CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
447 CPPUNIT_ASSERT_EQUAL( A, i1[0] );
448 CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
449 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
450 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
451 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
453 std::vector<HYDROData_DTM::CurveUZ> i2;
454 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
456 CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
457 CPPUNIT_ASSERT_EQUAL( A, i2[0] );
458 CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
459 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
460 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
461 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
462 CPPUNIT_ASSERT_EQUAL( B, i2[2] );
464 std::vector<HYDROData_DTM::CurveUZ> i3;
465 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
467 CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
468 CPPUNIT_ASSERT_EQUAL( A, i3[0] );
469 CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
470 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
471 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
472 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
475 void test_HYDROData_DTM::test_curve_to_3d()
477 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
479 Handle(HYDROData_Profile) aProfile1 =
480 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
482 Handle(HYDROData_Profile) aProfile2 =
483 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
485 aProfile1->SetParametricPoints( points );
486 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
487 aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
488 aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
490 aProfile2->SetParametricPoints( points );
491 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
492 aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
493 aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
495 std::vector<double> distances;
496 std::vector<Handle(HYDROData_Profile)> profiles;
497 profiles.push_back( aProfile1 );
498 profiles.push_back( aProfile2 );
500 Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
501 HYDROData_DTM::AltitudePoints points;
502 HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0, 0 );
503 mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
504 mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
505 HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0, 0 );
506 wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
507 wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
508 HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
510 CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
511 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 16.380, -2.186, 6.0 ), points[0] );
512 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.673, -1.479, 5.0 ), points[1] );
513 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.259, -0.065, 5.0 ), points[2] );
514 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 12.137, 2.056, 6.0 ), points[3] );
519 void test_HYDROData_DTM::test_presentation()
521 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
523 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
525 Handle(HYDROData_Profile) aProfile1 =
526 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
528 Handle(HYDROData_Profile) aProfile2 =
529 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
531 aProfile1->SetParametricPoints( points );
532 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
533 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
534 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
536 aProfile2->SetParametricPoints( points );
537 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
538 aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
539 aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
541 HYDROData_SequenceOfObjects seq;
542 seq.Append( aProfile1 );
543 seq.Append( aProfile2 );
544 DTM->SetProfiles( seq );
546 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
547 DTM->SetSpatialStep( 1.0 );
548 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
551 CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() );
553 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
554 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
555 aBathPrs->update( true, false );
557 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
558 TestViewer::showColorScale( true );
559 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
562 aCS->SetNumberOfIntervals( 10 );
563 aBathPrs->UpdateWithColorScale( aCS );
565 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
566 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" );
568 TestViewer::showColorScale( ColorScaleIsDisp );
573 void test_HYDROData_DTM::test_garonne()
575 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
577 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
578 fname += "/Profiles.xyz";
579 NCollection_Sequence<int> bad_ids;
581 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
583 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
584 CPPUNIT_ASSERT_EQUAL( 46, aSize );
586 HYDROData_SequenceOfObjects profiles;
587 HYDROData_Iterator it( aDoc, KIND_PROFILE );
588 for( int i=0; it.More(); it.Next(), i++ )
591 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
594 CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() );
596 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
597 DTM->SetProfiles( profiles );
599 DTM->SetSpatialStep( 1.0 );
600 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
601 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
604 CPPUNIT_ASSERT_EQUAL( 282338, (int)DTM->GetAltitudePoints().size() );
606 Handle(AIS_InteractiveContext) aContext = TestViewer::context();
607 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
608 aBathPrs->update( true, false );
610 bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
612 TestViewer::showColorScale( true );
613 Handle(AIS_ColorScale) aCS = TestViewer::colorScale();
616 aCS->SetNumberOfIntervals( 30 );
617 aBathPrs->UpdateWithColorScale( aCS );
619 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
620 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_2" );
621 TestViewer::showColorScale( ColorScaleIsDisp );
626 void test_HYDROData_DTM::test_classifier_1()
628 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
629 fname += "/pb_1066.cbf";
630 CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) );
632 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
634 Handle(HYDROData_CalculationCase) aCase =
635 Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) );
636 CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() );
637 std::vector<gp_XY> points;
638 points.push_back( gp_XY( 43.4842, 3.33176 ) );
639 points.push_back( gp_XY( -125.777, 2.24728 ) );
640 points.push_back( gp_XY( -60.1628, 168.262 ) );
641 points.push_back( gp_XY( 21.8055587645, 154.699344457 ) );
642 points.push_back( gp_XY( -84.4764138524, 79.2606012276 ) );
643 points.push_back( gp_XY( -73.4132070504, 69.7096313266 ) );
645 std::vector<double> values = aCase->GetStricklerCoefficientForPoints( points, 0.0, true );
646 CPPUNIT_ASSERT_EQUAL( 6, (int)values.size() );
647 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[0], EPS );
648 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[1], EPS );
649 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[2], EPS );
650 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[3], EPS );
651 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[4], EPS );
652 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[5], EPS );
654 std::vector<int> types = aCase->GetStricklerTypeForPoints( points );
655 CPPUNIT_ASSERT_EQUAL( 6, (int)types.size() );
656 CPPUNIT_ASSERT_EQUAL( 123, types[0] );
657 CPPUNIT_ASSERT_EQUAL( 123, types[1] );
658 CPPUNIT_ASSERT_EQUAL( 221, types[2] );
659 CPPUNIT_ASSERT_EQUAL( 123, types[3] );
660 CPPUNIT_ASSERT_EQUAL( 123, types[4] );
661 CPPUNIT_ASSERT_EQUAL( 123, types[5] );