X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2Ftest_HYDROData_DTM.cxx;h=453a315f6430750f93eea1a8a6aca68aca6b4b3d;hb=3bece499e83cc9ca95536228c7f6740030e9d5d8;hp=9c06cc7e1fa22078972f99e30f6d2337a0d91427;hpb=54c517abf4fb5f89df90c75a71d8292eec4148d6;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/test_HYDROData_DTM.cxx b/src/HYDRO_tests/test_HYDROData_DTM.cxx index 9c06cc7e..453a315f 100644 --- a/src/HYDRO_tests/test_HYDROData_DTM.cxx +++ b/src/HYDRO_tests/test_HYDROData_DTM.cxx @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include const double EPS = 1E-3; @@ -55,7 +58,7 @@ public: myD = d; int n = pp->VertexNumber(); - + for( int i=1; i<=n; i++ ) { gp_Pnt pnt = pp->Vertice( i ); @@ -157,27 +160,27 @@ void test_HYDROData_DTM::setUp() void test_HYDROData_DTM::test_creation() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_DTM) DTM = + Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() ); - + aDoc->Close(); } void test_HYDROData_DTM::test_hydraulic_axis() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile) aProfile1 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile) aProfile2 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - Handle(HYDROData_Profile) aProfile3 = + Handle(HYDROData_Profile) aProfile3 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile1->SetParametricPoints( points ); @@ -206,28 +209,28 @@ void test_HYDROData_DTM::test_hydraulic_axis() CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, distances[0], EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 43.499, distances[1], EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 211.474, distances[2], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 44.859, distances[1], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 207.661, 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 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.X(), EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.532, q.Y(), EPS ); aDoc->Close(); } void test_HYDROData_DTM::test_profile_conversion_to_2d() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile) aProfile1 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile) aProfile2 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile1->SetParametricPoints( points ); @@ -240,7 +243,7 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d() aProfile2->SetLeftPoint( gp_XY( 10, 10 ) ); aProfile2->SetRightPoint( gp_XY( 20, 20 ) ); - double aUMin1 = std::numeric_limits::max(), + double aUMin1 = DBL_MAX, aUMax1 = -aUMin1, aUMin2 = aUMin1, aUMax2 = aUMax1; @@ -293,9 +296,9 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d() void test_HYDROData_DTM::test_profile_properties() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile->SetParametricPoints( points ); @@ -329,9 +332,9 @@ void test_HYDROData_DTM::test_profile_properties() void test_HYDROData_DTM::test_profile_discretization_polyline() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile->SetParametricPoints( points ); @@ -341,7 +344,8 @@ void test_HYDROData_DTM::test_profile_discretization_polyline() HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 ); int dummy = 0; - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy ); + QSet warnings; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings ); 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 ); @@ -367,9 +371,9 @@ void test_HYDROData_DTM::test_profile_discretization_polyline() void test_HYDROData_DTM::test_profile_discretization_spline() { -Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); +Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile->SetParametricPoints( points ); @@ -379,7 +383,8 @@ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 ); int dummy = 0 ; - HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy ); + QSet warnings; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings ); 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 ); @@ -474,12 +479,12 @@ void test_HYDROData_DTM::test_curves_interpolation() void test_HYDROData_DTM::test_curve_to_3d() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); - Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile) aProfile1 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile) aProfile2 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile1->SetParametricPoints( points ); @@ -499,33 +504,33 @@ 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, gp_Vec2d(-10,10), 0, 0 ); + HYDROData_DTM::CurveUZ mid( 5.0, gp_Vec2d(-10,10), 0, 10 ); mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) ); mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) ); - HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0, 0 ); + HYDROData_DTM::CurveUZ wid( 5.0, gp_Vec2d(-10,10), 0, 10 ); 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( 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] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 21.588, 5.419, 6.0 ), points[0] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 20.881, 6.126, 5.0 ), points[1] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 19.466, 7.541, 5.0 ), points[2] ); + CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::AltitudePoint( 17.345, 9.662, 6.0 ), points[3] ); aDoc->Close(); } void test_HYDROData_DTM::test_presentation() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) ); - Handle(HYDROData_Profile) aProfile1 = + Handle(HYDROData_Profile) aProfile1 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); - Handle(HYDROData_Profile) aProfile2 = + Handle(HYDROData_Profile) aProfile2 = Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); aProfile1->SetParametricPoints( points ); @@ -547,12 +552,13 @@ void test_HYDROData_DTM::test_presentation() DTM->SetSpatialStep( 1.0 ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS ); DTM->Update(); - - CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() ); + + CPPUNIT_ASSERT_EQUAL( 9108, (int)DTM->GetAltitudePoints().size() ); Handle(AIS_InteractiveContext) aContext = TestViewer::context(); HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); aBathPrs->update( true, false ); + aBathPrs->RescaleDefault(); bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); TestViewer::showColorScale( true ); @@ -561,9 +567,9 @@ void test_HYDROData_DTM::test_presentation() aCS->SetMax( 5.0 ); aCS->SetNumberOfIntervals( 10 ); aBathPrs->UpdateWithColorScale( aCS ); - + //QTest::qWait(50000); QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 ); - CPPUNIT_ASSERT_IMAGES2( &aDTMPrs, "DTM_1" ); + CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_1", false ); delete aBathPrs; TestViewer::showColorScale( ColorScaleIsDisp ); @@ -572,14 +578,14 @@ void test_HYDROData_DTM::test_presentation() void test_HYDROData_DTM::test_garonne() { - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); + 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 ); @@ -600,13 +606,14 @@ void test_HYDROData_DTM::test_garonne() 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() ); - + + CPPUNIT_ASSERT_EQUAL( 281898, (int)DTM->GetAltitudePoints().size() ); + Handle(AIS_InteractiveContext) aContext = TestViewer::context(); HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM ); aBathPrs->update( true, false ); - + aBathPrs->RescaleDefault(); + bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed(); TestViewer::showColorScale( true ); @@ -615,9 +622,9 @@ void test_HYDROData_DTM::test_garonne() 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" ); + CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_2", false ); TestViewer::showColorScale( ColorScaleIsDisp ); delete aBathPrs; aDoc->Close(); @@ -627,13 +634,13 @@ void test_HYDROData_DTM::test_classifier_1() { TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data(); fname += "/pb_1066.cbf"; - CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString(), 1 ) ); + CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString() ) ); - Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); - - Handle(HYDROData_CalculationCase) aCase = + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); + + Handle(HYDROData_CalculationCase) aCase = Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) ); - CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); + CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); std::vector points; points.push_back( gp_XY( 43.4842, 3.33176 ) ); points.push_back( gp_XY( -125.777, 2.24728 ) ); @@ -647,19 +654,98 @@ void test_HYDROData_DTM::test_classifier_1() CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[0], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[1], EPS ); CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[2], EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[3], EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[4], EPS ); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0123, values[5], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[3], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[4], EPS ); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0221, values[5], EPS ); std::vector types = aCase->GetStricklerTypeForPoints( points ); CPPUNIT_ASSERT_EQUAL( 6, (int)types.size() ); CPPUNIT_ASSERT_EQUAL( 123, types[0] ); CPPUNIT_ASSERT_EQUAL( 123, types[1] ); CPPUNIT_ASSERT_EQUAL( 221, types[2] ); - CPPUNIT_ASSERT_EQUAL( 123, types[3] ); - CPPUNIT_ASSERT_EQUAL( 123, types[4] ); - CPPUNIT_ASSERT_EQUAL( 123, types[5] ); + CPPUNIT_ASSERT_EQUAL( 221, types[3] ); + CPPUNIT_ASSERT_EQUAL( 221, types[4] ); + CPPUNIT_ASSERT_EQUAL( 221, types[5] ); aDoc->Close(); } +void test_HYDROData_DTM::test_profile_discretization_warnings() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(); + + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + NCollection_Sequence pnts; + pnts.Append( gp_XY( 0.0, 1.0 ) ); + pnts.Append( gp_XY( 1.0, 0.0 ) ); + pnts.Append( gp_XY( 2.0, 4.0 ) ); + pnts.Append( gp_XY( 3.0, 5.0 ) ); + + aProfile->SetParametricPoints( pnts ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 10, 20 ) ); + + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 ); + int dummy = 0; + QSet warnings; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings ); + + //CPPUNIT_ASSERT_EQUAL(1, warnings.size()); + CPPUNIT_ASSERT( warnings.contains("One of the extreme points is higher than another")); + } + { + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + NCollection_Sequence pnts; + pnts.Append( gp_XY( 0.0, 1.0 ) ); + pnts.Append( gp_XY( 1.0, 0.0 ) ); + pnts.Append( gp_XY( 2.0, 5.0 ) ); + pnts.Append( gp_XY( 3.0, 0.0 ) ); + pnts.Append( gp_XY( 4.0, 1.0 ) ); + + aProfile->SetParametricPoints( pnts ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 10, 20 ) ); + + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 ); + int dummy = 0; + QSet warnings; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings ); + + CPPUNIT_ASSERT_EQUAL(1, warnings.size()); + CPPUNIT_ASSERT( warnings.contains("More than 2 intersections between profile & altitude Z-lines found")); + } + { + //plato case + Handle(HYDROData_Profile) aProfile = + Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) ); + + NCollection_Sequence pnts; + pnts.Append( gp_XY( 0.0, 5.0 ) ); + pnts.Append( gp_XY( 1.0, 5.0 ) ); + pnts.Append( gp_XY( 2.0, 0.5 ) ); + pnts.Append( gp_XY( 3.0, 5.0 ) ); + pnts.Append( gp_XY( 4.0, 5.0 ) ); + + aProfile->SetParametricPoints( pnts ); + aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE ); + aProfile->SetLeftPoint( gp_XY( 10, 10 ) ); + aProfile->SetRightPoint( gp_XY( 10, 20 ) ); + + HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 ); + int dummy = 0; + QSet warnings; + HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings ); + + CPPUNIT_ASSERT_EQUAL(2, warnings.size()); + CPPUNIT_ASSERT( warnings.contains("Plato case on extremes")); + } + + aDoc->Close(); +}