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 gp_Vec2d aProfileDir;
247 std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir );
248 std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir );
250 gp_Pnt2d aFirst, aLast;
251 CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
252 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin1, EPS );
253 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax1, EPS );
254 curves1[0]->D0( curves1[0]->FirstParameter(), aFirst );
255 curves1[0]->D0( curves1[0]->LastParameter(), aLast );
256 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aFirst.X(), EPS );
257 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aFirst.Y(), EPS );
258 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aLast.X(), EPS );
259 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aLast.Y(), EPS );
260 curves1[1]->D0( curves1[1]->FirstParameter(), aFirst );
261 curves1[1]->D0( curves1[1]->LastParameter(), aLast );
262 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.768, aFirst.X(), EPS );
263 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, aFirst.Y(), EPS );
264 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.X(), EPS );
265 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aLast.Y(), EPS );
266 curves1[2]->D0( curves1[2]->FirstParameter(), aFirst );
267 curves1[2]->D0( curves1[2]->LastParameter(), aLast );
268 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.X(), EPS );
269 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aFirst.Y(), EPS );
270 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aLast.X(), EPS );
271 CPPUNIT_ASSERT_DOUBLES_EQUAL( 4.0, aLast.Y(), EPS );
273 CPPUNIT_ASSERT_EQUAL( 1, (int)curves2.size() );
274 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, aUMin2, EPS );
275 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.839, aUMax2, EPS );
276 Handle(Geom2d_BSplineCurve) aBSpline = Handle(Geom2d_BSplineCurve)::DownCast( curves2[0] );
277 CPPUNIT_ASSERT_EQUAL( false, (bool)aBSpline.IsNull() );
278 const TColgp_Array1OfPnt2d& poles = aBSpline->Poles();
279 CPPUNIT_ASSERT_EQUAL( 1, (int)poles.Lower() );
280 CPPUNIT_ASSERT_EQUAL( 8, (int)poles.Upper() );
281 CPPUNIT_ASSERT_DOUBLES_EQUAL( -5.303, poles.Value( 1 ).X(), EPS );
282 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, poles.Value( 1 ).Y(), EPS );
283 CPPUNIT_ASSERT_DOUBLES_EQUAL( -4.125, poles.Value( 2 ).X(), EPS );
284 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.667, poles.Value( 2 ).Y(), EPS );
285 CPPUNIT_ASSERT_DOUBLES_EQUAL( -3.150, poles.Value( 3 ).X(), EPS );
286 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.120, poles.Value( 3 ).Y(), EPS );
287 CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.242, poles.Value( 4 ).X(), EPS );
288 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.574, poles.Value( 4 ).Y(), EPS );
293 void test_HYDROData_DTM::test_profile_properties()
295 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
297 Handle(HYDROData_Profile) aProfile =
298 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
300 aProfile->SetParametricPoints( points );
301 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
302 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
303 aProfile->SetRightPoint( gp_XY( 20, 25 ) );
308 HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax );
309 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
310 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
311 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
312 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.X(), EPS );
313 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
314 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
315 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
317 HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
318 CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
319 CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
320 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
321 CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
322 CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
323 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
324 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
329 void test_HYDROData_DTM::test_profile_discretization_polyline()
331 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
333 Handle(HYDROData_Profile) aProfile =
334 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
336 aProfile->SetParametricPoints( points );
337 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
338 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
339 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
341 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 );
343 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy );
344 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
345 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS );
346 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
347 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.11, aMid[1].U, EPS );
348 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
349 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS );
350 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
351 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
352 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
354 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
355 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].U, EPS );
356 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
357 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.989, aWid[1].U, EPS );
358 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
359 CPPUNIT_ASSERT_DOUBLES_EQUAL( 8.618, aWid[5].U, EPS );
360 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
361 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
362 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
367 void test_HYDROData_DTM::test_profile_discretization_spline()
369 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
371 Handle(HYDROData_Profile) aProfile =
372 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
374 aProfile->SetParametricPoints( points );
375 aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
376 aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
377 aProfile->SetRightPoint( gp_XY( 20, 20 ) );
379 HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 );
381 HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy );
382 CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() );
383 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS );
384 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS );
385 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.755, aMid[1].U, EPS );
386 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS );
387 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS );
388 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS );
389 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS );
390 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS );
392 CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
393 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.484, aWid[0].U, EPS );
394 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aWid[0].Z, EPS );
395 CPPUNIT_ASSERT_DOUBLES_EQUAL( 3.809, aWid[1].U, EPS );
396 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aWid[1].Z, EPS );
397 CPPUNIT_ASSERT_DOUBLES_EQUAL( 9.472, aWid[5].U, EPS );
398 CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aWid[5].Z, EPS );
399 CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
400 CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aWid[10].Z, EPS );
405 void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
407 s << "(" << p.U << "; " << p.Z << ") ";
410 void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
412 s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
415 bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
417 return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
420 bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
422 return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
425 void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
428 for( size_t i=0; i<n; i++ )
432 void test_HYDROData_DTM::test_curves_interpolation()
434 HYDROData_DTM::CurveUZ A(1.0, gp_Vec2d(), 0), B(2.0, gp_Vec2d(), 0);
435 A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) );
436 A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) );
437 A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) );
438 B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
439 B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
440 B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
442 std::vector<HYDROData_DTM::CurveUZ> i1;
443 HYDROData_DTM::Interpolate( A, B, 1, i1, false );
445 CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
446 CPPUNIT_ASSERT_EQUAL( A, i1[0] );
447 CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
448 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
449 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
450 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
452 std::vector<HYDROData_DTM::CurveUZ> i2;
453 HYDROData_DTM::Interpolate( A, B, 1, i2, true );
455 CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
456 CPPUNIT_ASSERT_EQUAL( A, i2[0] );
457 CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
458 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
459 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
460 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
461 CPPUNIT_ASSERT_EQUAL( B, i2[2] );
463 std::vector<HYDROData_DTM::CurveUZ> i3;
464 HYDROData_DTM::Interpolate( A, B, 3, i3, false );
466 CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
467 CPPUNIT_ASSERT_EQUAL( A, i3[0] );
468 CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
469 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
470 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
471 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
474 void test_HYDROData_DTM::test_curve_to_3d()
476 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
478 Handle(HYDROData_Profile) aProfile1 =
479 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
481 Handle(HYDROData_Profile) aProfile2 =
482 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
484 aProfile1->SetParametricPoints( points );
485 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
486 aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
487 aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
489 aProfile2->SetParametricPoints( points );
490 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
491 aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
492 aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
494 std::vector<double> distances;
495 std::vector<Handle(HYDROData_Profile)> profiles;
496 profiles.push_back( aProfile1 );
497 profiles.push_back( aProfile2 );
499 Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
500 HYDROData_DTM::AltitudePoints points;
501 HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0 );
502 mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
503 mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
504 HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0 );
505 wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) );
506 wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) );
507 HYDROData_DTM::CurveTo3D( HA, mid, wid, points );
509 CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() );
510 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 16.380, -2.186, 6.0 ), points[0] );
511 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.673, -1.479, 5.0 ), points[1] );
512 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.259, -0.065, 5.0 ), points[2] );
513 CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 12.137, 2.056, 6.0 ), points[3] );
518 void test_HYDROData_DTM::test_presentation()
520 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
522 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
524 Handle(HYDROData_Profile) aProfile1 =
525 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
527 Handle(HYDROData_Profile) aProfile2 =
528 Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
530 aProfile1->SetParametricPoints( points );
531 aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
532 aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
533 aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
535 aProfile2->SetParametricPoints( points );
536 aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
537 aProfile2->SetLeftPoint( gp_XY( 110, 10 ) );
538 aProfile2->SetRightPoint( gp_XY( 100, 0 ) );
540 HYDROData_SequenceOfObjects seq;
541 seq.Append( aProfile1 );
542 seq.Append( aProfile2 );
543 DTM->SetProfiles( seq );
545 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
546 DTM->SetSpatialStep( 1.0 );
547 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
550 CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() );
552 Handle_AIS_InteractiveContext aContext = TestViewer::context();
553 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
554 aBathPrs->update( true, false );
556 TestViewer::showColorScale( true );
557 Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
560 aCS->SetNumberOfIntervals( 10 );
561 aBathPrs->UpdateWithColorScale( aCS );
563 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
564 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" );
570 void test_HYDROData_DTM::test_garonne()
572 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
574 TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
575 fname += "/Profiles.xyz";
576 NCollection_Sequence<int> bad_ids;
578 int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
580 CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
581 CPPUNIT_ASSERT_EQUAL( 46, aSize );
583 HYDROData_SequenceOfObjects profiles;
584 HYDROData_Iterator it( aDoc, KIND_PROFILE );
585 for( int i=0; it.More(); it.Next(), i++ )
588 profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) );
591 CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() );
595 Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
596 DTM->SetProfiles( profiles );
598 DTM->SetSpatialStep( 1.0 );
599 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
600 CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
603 CPPUNIT_ASSERT_EQUAL( 282338, (int)DTM->GetAltitudePoints().size() );
605 Handle_AIS_InteractiveContext aContext = TestViewer::context();
606 HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
607 aBathPrs->update( true, false );
609 TestViewer::showColorScale( true );
610 Handle_Aspect_ColorScale aCS = TestViewer::colorScale();
613 aCS->SetNumberOfIntervals( 30 );
614 aBathPrs->UpdateWithColorScale( aCS );
616 QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
617 CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_2" );