X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2Ftest_HYDROData_DTM.cxx;h=0436c8fb693e0e48607636206ef0a19932b8fbb3;hb=58bb6b7459bebeeb089c9ed486c4683a8bae7288;hp=96e779c7046d65a64c2bf3fe8328cc96f942f822;hpb=ccf0c94c7ad984eddae21372ca02edbaf1d6bb1e;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index 96e779c7..0436c8fb 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -29,13 +30,121 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include +#include const double EPS = 1E-3; +extern QString REF_DATA_PATH; NCollection_Sequence points; +class DTM_item : public QGraphicsItem +{ +public: + DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d ) + { + Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() ); + Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints(); + myBB = QRectF(); + double xmin, xmax, ymin, ymax; + myD = d; + + int n = pp->VertexNumber(); + + for( int i=1; i<=n; i++ ) + { + gp_Pnt pnt = pp->Vertice( i ); + Quantity_Color col = pp->VertexColor( i ); + + int r = col.Red()*255; + int g = col.Green()*255; + int b = col.Blue()*255; + int val = ( r << 16 ) + ( g << 8 ) + b; + double x = pnt.X(); + double y = -pnt.Y(); + QPointF aPnt( x, y ); + myPoints[val].append( aPnt ); + if( i==1 ) + { + xmin = x; + xmax = x; + ymin = y; + ymax = y; + } + else + { + if( x>xmax ) + xmax = x; + if( xymax ) + ymax = y; + if( y >::const_iterator it = myPoints.begin(), last = myPoints.end(); + for( ; it!=last; it++ ) + { + int r = ( it.key() >> 16 ) % 256; + int g = ( it.key() >> 8 ) % 256; + int b = ( it.key() >> 0 ) % 256; + QColor aColor( r, g, b ); + QBrush aBrush( aColor ); + foreach( QPointF pnt, it.value() ) + { + QRectF r( pnt.x()-myD/2, pnt.y()-myD/2, myD, myD ); + p->fillRect( r, aBrush ); + } + } + } + +private: + QRectF myBB; + double myD; + QMap > myPoints; +}; + +QImage draw_DTM( HYDROGUI_ShapeBathymetry* theDTM, double theD, int theWidth, int theHeight ) +{ + QGraphicsScene aScene; + QGraphicsView aView; + DTM_item anItem( theDTM, theD ); + + aView.setScene( &aScene ); + aView.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aView.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); + aScene.addItem( &anItem ); + + aView.resize( theWidth, theHeight ); + QRectF bb = anItem.boundingRect(); + aView.fitInView( bb, Qt::KeepAspectRatio ); + QApplication::processEvents(); + + QPixmap aPixmap = QPixmap::grabWidget( &aView ); + return aPixmap.toImage(); +} + + void test_HYDROData_DTM::setUp() { points.Clear(); @@ -99,6 +208,14 @@ void test_HYDROData_DTM::test_hydraulic_axis() CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS ); + gp_Pnt2d p; + gp_Vec2d q; + HA->D1( 0, p, q ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, p.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 6.25, p.Y(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.568, q.Y(), EPS ); + aDoc->Close(); } @@ -126,8 +243,9 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d() aUMax1 = -aUMin1, aUMin2 = aUMin1, aUMax2 = aUMax1; - std::vector curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1 ); - std::vector curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2 ); + gp_Vec2d aProfileDir; + std::vector curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir ); + std::vector curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir ); gp_Pnt2d aFirst, aLast; CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() ); @@ -220,8 +338,9 @@ void test_HYDROData_DTM::test_profile_discretization_polyline() aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); aProfile->SetRightPoint( gp_XY( 20, 20 ) ); - HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 ); - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid ); + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 ); + int dummy = 0; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy ); CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS ); @@ -229,7 +348,7 @@ void test_HYDROData_DTM::test_profile_discretization_polyline() CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.215, aMid[5].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS ); CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() ); @@ -257,8 +376,9 @@ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); aProfile->SetRightPoint( gp_XY( 20, 20 ) ); - HYDROData_DTM::CurveUZ aMid( 0.0 ), aWid( 0.0 ); - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid ); + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0 ), aWid( 0.0, gp_Vec2d(), 0 ); + int dummy = 0 ; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 0.5, aMid, aWid, dummy ); CPPUNIT_ASSERT_EQUAL( 11, (int)aMid.size() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.242, aMid[0].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, aMid[0].Z, EPS ); @@ -266,7 +386,7 @@ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, aMid[1].Z, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.473, aMid[5].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.5, aMid[5].Z, EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.589, aMid[10].U, EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.768, aMid[10].U, EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, aMid[10].Z, EPS ); CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() ); @@ -311,7 +431,7 @@ void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c ) void test_HYDROData_DTM::test_curves_interpolation() { - HYDROData_DTM::CurveUZ A(1.0), B(2.0); + HYDROData_DTM::CurveUZ A(1.0, gp_Vec2d(), 0), B(2.0, gp_Vec2d(), 0); A.push_back( HYDROData_DTM::PointUZ( 0, 0 ) ); A.push_back( HYDROData_DTM::PointUZ( 1, 1 ) ); A.push_back( HYDROData_DTM::PointUZ( 2, 2 ) ); @@ -378,19 +498,19 @@ void test_HYDROData_DTM::test_curve_to_3d() Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances ); HYDROData_DTM::AltitudePoints points; - HYDROData_DTM::CurveUZ mid( 5.0 ); + HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0 ); mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) ); mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) ); - HYDROData_DTM::CurveUZ wid( 5.0 ); + HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0 ); wid.push_back( HYDROData_DTM::PointUZ( 2, 5 ) ); wid.push_back( HYDROData_DTM::PointUZ( 6, 6 ) ); HYDROData_DTM::CurveTo3D( HA, mid, wid, points ); CPPUNIT_ASSERT_EQUAL( 4, (int)points.size() ); - CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.434, -0.598, 5.0 ), points[0] ); - CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.497, -0.947, 5.0 ), points[1] ); - CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.903, -0.423, 6.0 ), points[2] ); - CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 13.092, -1.471, 6.0 ), points[3] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 16.380, -2.186, 6.0 ), points[0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 15.673, -1.479, 5.0 ), points[1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 14.259, -0.065, 5.0 ), points[2] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 12.137, 2.056, 6.0 ), points[3] ); aDoc->Close(); } @@ -409,13 +529,13 @@ void test_HYDROData_DTM::test_presentation() aProfile1->SetParametricPoints( points ); aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); - aProfile1->SetLeftPoint( gp_XY( 20, 0 ) ); - aProfile1->SetRightPoint( gp_XY( 10, 10 ) ); + aProfile1->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile1->SetRightPoint( gp_XY( 20, 0 ) ); aProfile2->SetParametricPoints( points ); aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE ); - aProfile2->SetLeftPoint( gp_XY( 100, 0 ) ); - aProfile2->SetRightPoint( gp_XY( 110, 0 ) ); + aProfile2->SetLeftPoint( gp_XY( 110, 10 ) ); + aProfile2->SetRightPoint( gp_XY( 100, 0 ) ); HYDROData_SequenceOfObjects seq; seq.Append( aProfile1 ); @@ -427,27 +547,78 @@ void test_HYDROData_DTM::test_presentation() CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); DTM->Update(); - CPPUNIT_ASSERT_EQUAL( 10404, (int)DTM->GetAltitudePoints().size() ); + CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() ); Handle_AIS_InteractiveContext aContext = TestViewer::context(); HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); aBathPrs->update( true, false ); + bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); TestViewer::showColorScale( true ); - Handle_Aspect_ColorScale aCS = TestViewer::colorScale(); + Handle(AIS_ColorScale) aCS = TestViewer::colorScale(); aCS->SetMin( 0.0 ); aCS->SetMax( 5.0 ); aCS->SetNumberOfIntervals( 10 ); aBathPrs->UpdateWithColorScale( aCS ); - TestViewer::show( aBathPrs->getAISObject(), AIS_PointCloud::DM_Points, 0, true, "DTM_1" ); - CPPUNIT_ASSERT_IMAGES + QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); + CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" ); delete aBathPrs; + TestViewer::showColorScale( ColorScaleIsDisp ); aDoc->Close(); } void test_HYDROData_DTM::test_garonne() { - //TODO + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); + fname += "/Profiles.xyz"; + NCollection_Sequence bad_ids; + + int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true ); + + CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() ); + CPPUNIT_ASSERT_EQUAL( 46, aSize ); + + HYDROData_SequenceOfObjects profiles; + HYDROData_Iterator it( aDoc, KIND_PROFILE ); + for( int i=0; it.More(); it.Next(), i++ ) + { + if( i>=25 && i<=35 ) + profiles.Append( Handle(HYDROData_Profile)::DownCast( it.Current() ) ); + } + + CPPUNIT_ASSERT_EQUAL( 11, (int)profiles.Size() ); + + Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); + DTM->SetProfiles( profiles ); + DTM->SetDDZ( 0.1 ); + DTM->SetSpatialStep( 1.0 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); + DTM->Update(); + + CPPUNIT_ASSERT_EQUAL( 282338, (int)DTM->GetAltitudePoints().size() ); + + Handle_AIS_InteractiveContext aContext = TestViewer::context(); + HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); + aBathPrs->update( true, false ); + + bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); + + TestViewer::showColorScale( true ); + Handle(AIS_ColorScale) aCS = TestViewer::colorScale(); + aCS->SetMin( 0.0 ); + aCS->SetMax( 25.0 ); + aCS->SetNumberOfIntervals( 30 ); + aBathPrs->UpdateWithColorScale( aCS ); + + QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); + CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_2" ); + TestViewer::showColorScale( ColorScaleIsDisp ); + delete aBathPrs; + aDoc->Close(); + }