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 <Geom2d_Curve.hxx>
25 #include <Geom2d_BSplineCurve.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>
38 #include <QApplication>
40 const double EPS = 1E-3;
42 extern QString REF_DATA_PATH;
43 NCollection_Sequence<HYDROData_IPolyline::Point> points;
45 class DTM_item : public QGraphicsItem
48 DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
50 Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() );
51 Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
53 double xmin, xmax, ymin, ymax;
56 int n = pp->VertexNumber();
58 for( int i=1; i<=n; i++ )
60 gp_Pnt pnt = pp->Vertice( i );
61 Quantity_Color col = pp->VertexColor( i );
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;
70 myPoints[val].append( aPnt );
95 myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
98 virtual QRectF boundingRect() const
103 virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
105 QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
106 for( ; it!=last; it++ )
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() )
115 QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
116 p->fillRect( r, aBrush );
124 QMap<int, QList<QPointF> > myPoints;
127 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
129 QGraphicsScene aScene;
131 DTM_item anItem( theDTM, theD );
133 aView.setScene( &aScene );
134 aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
135 aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
136 aScene.addItem( &anItem );
138 aView.resize( theWidth, theHeight );
139 QRectF bb = anItem.boundingRect();
140 aView.fitInView( bb, Qt::KeepAspectRatio );
141 QApplication::processEvents();
143 QPixmap aPixmap = QPixmap::grabWidget( &aView );
144 return aPixmap.toImage();
148 void test_HYDROData_DTM::setUp()
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 ) );
157 void test_HYDROData_DTM::test_creation()
159 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
161 Handle(HYDROData_DTM) DTM =
162 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
164 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
169 void test_HYDROData_DTM::test_hydraulic_axis()
171 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
173 Handle(HYDROData_Profile) aProfile1 =
174 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
176 Handle(HYDROData_Profile) aProfile2 =
177 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
179 Handle(HYDROData_Profile) aProfile3 =
180 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 ) );
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 ) );
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 );
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() );
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 );
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 );
222 void test_HYDROData_DTM::test_profile_conversion_to_2d()
224 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
226 Handle(HYDROData_Profile) aProfile1 =
227 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
229 Handle(HYDROData_Profile) aProfile2 =
230 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 ) );
242 double aUMin1 = std::numeric_limits<double>::max(),
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 );
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 );
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 );
292 void test_HYDROData_DTM::test_profile_properties()
294 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
296 Handle(HYDROData_Profile) aProfile =
297 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 );
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 );
328 void test_HYDROData_DTM::test_profile_discretization_polyline()
330 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
332 Handle(HYDROData_Profile) aProfile =
333 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 );
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 );
365 void test_HYDROData_DTM::test_profile_discretization_spline()
367 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
369 Handle(HYDROData_Profile) aProfile =
370 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 );
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 );
402 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
404 s << "(" << p.U << "; " << p.Z << ") ";
407 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
409 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
412 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
414 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
417 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
419 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
422 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
425 for( size_t i=0; i<n; i++ )
429 void test_HYDROData_DTM::test_curves_interpolation()
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 ) );
439 std::vector<HYDROData_DTM::CurveUZ> i1;
440 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
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] );
449 std::vector<HYDROData_DTM::CurveUZ> i2;
450 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
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] );
460 std::vector<HYDROData_DTM::CurveUZ> i3;
461 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
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] );
471 void test_HYDROData_DTM::test_curve_to_3d()
473 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
475 Handle(HYDROData_Profile) aProfile1 =
476 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
478 Handle(HYDROData_Profile) aProfile2 =
479 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 ) );
491 std::vector<double> distances;
492 std::vector<Handle(HYDROData_Profile)> profiles;
493 profiles.push_back( aProfile1 );
494 profiles.push_back( aProfile2 );
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 );
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] );
515 void test_HYDROData_DTM::test_presentation()
517 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
519 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
521 Handle(HYDROData_Profile) aProfile1 =
522 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
524 Handle(HYDROData_Profile) aProfile2 =
525 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
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 ) );
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 ) );
537 HYDROData_SequenceOfObjects seq;
538 seq.Append( aProfile1 );
539 seq.Append( aProfile2 );
540 DTM->SetProfiles( seq );
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 );
547 CPPUNIT_ASSERT_EQUAL( 10200, (int)DTM->GetAltitudePoints().size() );
549 Handle_AIS_InteractiveContext aContext = TestViewer::context();
550 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
551 aBathPrs->update( true, false );
553 TestViewer::showColorScale( true );
554 Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
557 aCS->SetNumberOfIntervals( 10 );
558 aBathPrs->UpdateWithColorScale( aCS );
560 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
561 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" );
567 void test_HYDROData_DTM::test_garonne()
569 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
571 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
572 fname += "/Profiles.xyz";
573 NCollection_Sequence<int> bad_ids;
575 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
577 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
578 CPPUNIT_ASSERT_EQUAL( 46, aSize );
580 HYDROData_SequenceOfObjects profiles;
581 HYDROData_Iterator it( aDoc, KIND_PROFILE );
582 for( int i=0; it.More(); it.Next(), i++ )
585 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
588 //CPPUNIT_ASSERT_EQUAL( 46, (int)profiles.Size() );
592 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
593 DTM->SetProfiles( profiles );
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 );
600 CPPUNIT_ASSERT_EQUAL( 282336, (int)DTM->GetAltitudePoints().size() );
602 Handle_AIS_InteractiveContext aContext = TestViewer::context();
603 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
604 aBathPrs->update( true, false );
606 TestViewer::showColorScale( true );
607 Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
610 aCS->SetNumberOfIntervals( 30 );
611 aBathPrs->UpdateWithColorScale( aCS );
613 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
614 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_2" );