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 <Geom2d_Curve.hxx>
24 #include <Geom2d_BSplineCurve.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <TColgp_Array1OfPnt2d.hxx>
28 #include <TestViewer.h>
29 #include <AIS_InteractiveContext.hxx>
30 #include <AIS_PointCloud.hxx>
31 #include <HYDROGUI_ShapeBathymetry.h>
32 #include <Aspect_ColorScale.hxx>
33 #include <QGraphicsItem>
34 #include <QGraphicsScene>
35 #include <QGraphicsView>
37 #include <QApplication>
39 const double EPS = 1E-3;
41 NCollection_Sequence<HYDROData_IPolyline::Point> points;
43 class DTM_item : public QGraphicsItem
46 DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
48 Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() );
49 Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
51 double xmin, xmax, ymin, ymax;
54 int n = pp->VertexNumber();
56 for( int i=1; i<=n; i++ )
58 gp_Pnt pnt = pp->Vertice( i );
59 Quantity_Color col = pp->VertexColor( i );
61 int r = col.Red()*255;
62 int g = col.Green()*255;
63 int b = col.Blue()*255;
64 int val = ( r << 16 ) + ( g << 8 ) + b;
68 myPoints[val].append( aPnt );
93 myBB.setRect( xmin, ymin, xmax-xmin, ymax-ymin );
96 virtual QRectF boundingRect() const
101 virtual void paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
103 QMap<int, QList<QPointF> >::const_iterator it = myPoints.begin(), last = myPoints.end();
104 for( ; it!=last; it++ )
106 int r = ( it.key() >> 16 ) % 256;
107 int g = ( it.key() >> 8 ) % 256;
108 int b = ( it.key() >> 0 ) % 256;
109 QColor aColor( r, g, b );
110 QBrush aBrush( aColor );
111 foreach( QPointF pnt, it.value() )
113 QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD );
114 p->fillRect( r, aBrush );
122 QMap<int, QList<QPointF> > myPoints;
125 QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight )
127 QGraphicsScene aScene;
129 DTM_item anItem( theDTM, theD );
131 aView.setScene( &aScene );
132 aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
133 aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
134 aScene.addItem( &anItem );
136 aView.resize( theWidth, theHeight );
137 QRectF bb = anItem.boundingRect();
138 aView.fitInView( bb, Qt::KeepAspectRatio );
139 QApplication::processEvents();
141 QPixmap aPixmap = QPixmap::grabWidget( &aView );
142 return aPixmap.toImage();
146 void test_HYDROData_DTM::setUp()
149 points.Append( gp_XY( 0.0, 5.0 ) );
150 points.Append( gp_XY( 1.0, 1.0 ) );
151 points.Append( gp_XY( 1.5, 0.0 ) );
152 points.Append( gp_XY( 4.0, 4.0 ) );
155 void test_HYDROData_DTM::test_creation()
157 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
159 Handle(HYDROData_DTM) DTM =
160 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
162 CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
167 void test_HYDROData_DTM::test_hydraulic_axis()
169 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
171 Handle(HYDROData_Profile) aProfile1 =
172 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
174 Handle(HYDROData_Profile) aProfile2 =
175 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
177 Handle(HYDROData_Profile) aProfile3 =
178 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
180 aProfile1->SetParametricPoints( points );
181 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
182 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
183 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
185 aProfile2->SetParametricPoints( points );
186 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
187 aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
188 aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
190 aProfile3->SetParametricPoints( points );
191 aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
192 aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
193 aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
195 std::vector<double> distances;
196 std::vector<Handle(HYDROData_Profile)> profiles;
197 profiles.push_back( aProfile1 );
198 profiles.push_back( aProfile2 );
199 profiles.push_back( aProfile3 );
201 Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
202 CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
203 CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
205 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS );
206 CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS );
207 CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS );
212 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS );
213 CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS );
214 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS );
215 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS );
220 void test_HYDROData_DTM::test_profile_conversion_to_2d()
222 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
224 Handle(HYDROData_Profile) aProfile1 =
225 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
227 Handle(HYDROData_Profile) aProfile2 =
228 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
230 aProfile1->SetParametricPoints( points );
231 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
232 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
233 aProfile1->SetRightPoint( gp_XY( 20, 20 ) );
235 aProfile2->SetParametricPoints( points );
236 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
237 aProfile2->SetLeftPoint( gp_XY( 10, 10 ) );
238 aProfile2->SetRightPoint( gp_XY( 20, 20 ) );
240 double aUMin1 = std::numeric_limits<double>::max(),
244 std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1 );
245 std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2 );
247 gp_Pnt2d aFirst, aLast;
248 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
249 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
250 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS );
251 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
252 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
253 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
254 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
255 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
256 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
257 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
258 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
259 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
260 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
261 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
262 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
263 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
264 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
265 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
266 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
267 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
268 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
270 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
271 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
272 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS );
273 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
274 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
275 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
276 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
277 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
278 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
279 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
280 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
281 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
284 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
285 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );
290 void test_HYDROData_DTM::test_profile_properties()
292 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
294 Handle(HYDROData_Profile) aProfile =
295 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
297 aProfile->SetParametricPoints( points );
298 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
299 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
300 aProfile->SetRightPoint( gp_XY( 20, 25 ) );
305 HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax );
306 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
307 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
308 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
309 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
310 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
311 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
314 HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
315 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
316 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
317 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
318 CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
319 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
320 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
321 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
326 void test_HYDROData_DTM::test_profile_discretization_polyline()
328 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
330 Handle(HYDROData_Profile) aProfile =
331 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
333 aProfile->SetParametricPoints( points );
334 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
335 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
336 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
338 HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 );
339 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid );
340 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
341 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS );
342 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
343 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS );
344 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
345 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS );
346 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
347 CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS );
348 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
350 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
351 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS );
352 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
353 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS );
354 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
355 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS );
356 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
357 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
358 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
363 void test_HYDROData_DTM::test_profile_discretization_spline()
365 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
367 Handle(HYDROData_Profile) aProfile =
368 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
370 aProfile->SetParametricPoints( points );
371 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
372 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
373 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
375 HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 );
376 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid );
377 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
378 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS );
379 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
380 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS );
381 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
382 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS );
383 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
384 CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS );
385 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
387 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
388 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS );
389 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
390 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS );
391 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
392 CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS );
393 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
394 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
395 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
400 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
402 s << "(" << p.U << "; " << p.Z << ") ";
405 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
407 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
410 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
412 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
415 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
417 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
420 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
423 for( size_t i=0; i<n; i++ )
427 void test_HYDROData_DTM::test_curves_interpolation()
429 HYDROData_DTM::CurveUZ A(1.0), B(2.0);
430 A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
431 A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
432 A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
433 B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
434 B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
435 B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
437 std::vector<HYDROData_DTM::CurveUZ> i1;
438 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
440 CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
441 CPPUNIT_ASSERT_EQUAL( A, i1[0] );
442 CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
443 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
444 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
445 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
447 std::vector<HYDROData_DTM::CurveUZ> i2;
448 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
450 CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
451 CPPUNIT_ASSERT_EQUAL( A, i2[0] );
452 CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
453 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
454 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
455 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
456 CPPUNIT_ASSERT_EQUAL( B, i2[2] );
458 std::vector<HYDROData_DTM::CurveUZ> i3;
459 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
461 CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
462 CPPUNIT_ASSERT_EQUAL( A, i3[0] );
463 CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
464 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
465 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
466 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
469 void test_HYDROData_DTM::test_curve_to_3d()
471 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
473 Handle(HYDROData_Profile) aProfile1 =
474 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
476 Handle(HYDROData_Profile) aProfile2 =
477 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
479 aProfile1->SetParametricPoints( points );
480 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
481 aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
482 aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
484 aProfile2->SetParametricPoints( points );
485 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
486 aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
487 aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
489 std::vector<double> distances;
490 std::vector<Handle(HYDROData_Profile)> profiles;
491 profiles.push_back( aProfile1 );
492 profiles.push_back( aProfile2 );
494 Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
495 HYDROData_DTM::AltitudePoints points;
496 HYDROData_DTM::CurveUZ mid( 5.0 );
497 mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
498 mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
499 HYDROData_DTM::CurveUZ wid( 5.0 );
500 wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
501 wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
502 HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
504 CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
505 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.434, -0.598, 5.0 ), points[0] );
506 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.497, -0.947, 5.0 ), points[1] );
507 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.903, -0.423, 6.0 ), points[2] );
508 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 13.092, -1.471, 6.0 ), points[3] );
513 void test_HYDROData_DTM::test_presentation()
515 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
517 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
519 Handle(HYDROData_Profile) aProfile1 =
520 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
522 Handle(HYDROData_Profile) aProfile2 =
523 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
525 aProfile1->SetParametricPoints( points );
526 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
527 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
528 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
530 aProfile2->SetParametricPoints( points );
531 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
532 aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
533 aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
535 HYDROData_SequenceOfObjects seq;
536 seq.Append( aProfile1 );
537 seq.Append( aProfile2 );
538 DTM->SetProfiles( seq );
540 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
541 DTM->SetSpatialStep( 1.0 );
542 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
545 CPPUNIT_ASSERT_EQUAL( 10200, (int)DTM->GetAltitudePoints().size() );
547 Handle_AIS_InteractiveContext aContext = TestViewer::context();
548 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
549 aBathPrs->update( true, false );
551 TestViewer::showColorScale( true );
552 Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
555 aCS->SetNumberOfIntervals( 10 );
556 aBathPrs->UpdateWithColorScale( aCS );
558 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
559 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" );
565 void test_HYDROData_DTM::test_garonne()