Salome HOME
tests configuration for Linux and YAMM
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_DTM.cxx
index 97d122abf52250be0405377abbb079be7d87ce98..9c06cc7e1fa22078972f99e30f6d2337a0d91427 100644 (file)
@@ -20,6 +20,8 @@
 #include <HYDROData_Document.h>
 #include <HYDROData_Profile.h>
 #include <HYDROData_DTM.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_CalculationCase.h>
 #include <Geom2d_Curve.hxx>
 #include <Geom2d_BSplineCurve.hxx>
 #include <gp_XY.hxx>
@@ -29,7 +31,7 @@
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_PointCloud.hxx>
 #include <HYDROGUI_ShapeBathymetry.h>
-#include <Aspect_ColorScale.hxx>
+#include <AIS_ColorScale.hxx>
 #include <QGraphicsItem>
 #include <QGraphicsScene>
 #include <QGraphicsView>
@@ -38,6 +40,7 @@
 
 const double EPS = 1E-3;
 
+extern QString REF_DATA_PATH;
 NCollection_Sequence<HYDROData_IPolyline::Point> points;
 
 class DTM_item : public QGraphicsItem
@@ -45,7 +48,7 @@ class DTM_item : public QGraphicsItem
 public:
   DTM_item( HYDROGUI_ShapeBathymetry* theDTM, double d )
   {
-    Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObject() );
+    Handle(AIS_PointCloud) pc = Handle(AIS_PointCloud)::DownCast( theDTM->getAISObjects()[0] );
     Handle(Graphic3d_ArrayOfPoints) pp = pc->GetPoints();
     myBB = QRectF();
     double xmin, xmax, ymin, ymax;
@@ -198,7 +201,7 @@ void test_HYDROData_DTM::test_hydraulic_axis()
   profiles.push_back( aProfile2 );
   profiles.push_back( aProfile3 );
 
-  Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
+  Handle(Geom2d_BSplineCurve) HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
   CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
   CPPUNIT_ASSERT_EQUAL( 3, (int)distances.size() );
 
@@ -241,8 +244,9 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d()
          aUMax1 = -aUMin1,
          aUMin2 = aUMin1,
          aUMax2 = aUMax1;
-  std::vector<Handle_Geom2d_Curve> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1 );
-  std::vector<Handle_Geom2d_Curve> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2 );
+  gp_Vec2d aProfileDir;
+  std::vector<Handle(Geom2d_Curve)> curves1 = HYDROData_DTM::ProfileToParametric( aProfile1, aUMin1, aUMax1, aProfileDir );
+  std::vector<Handle(Geom2d_Curve)> curves2 = HYDROData_DTM::ProfileToParametric( aProfile2, aUMin2, aUMax2, aProfileDir );
 
   gp_Pnt2d aFirst, aLast;
   CPPUNIT_ASSERT_EQUAL( 3, (int)curves1.size() );
@@ -302,7 +306,7 @@ void test_HYDROData_DTM::test_profile_properties()
   gp_Pnt lp;
   gp_Vec2d dd;
   double zmin, zmax;
-  HYDROData_DTM::GetProperties( aProfile, lp, dd, false, zmin, zmax );
+  HYDROData_DTM::GetProperties( aProfile, lp, dd, zmin, zmax );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
@@ -311,14 +315,14 @@ void test_HYDROData_DTM::test_profile_properties()
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
 
-  HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
/* HYDROData_DTM::GetProperties( aProfile, lp, dd, true, zmin, zmax );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.75, lp.X(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 15.625, lp.Y(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, lp.Z(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( -15, dd.X(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 10, dd.Y(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, zmin, EPS );
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 5.0, zmax, EPS );*/
 
   aDoc->Close();
 }
@@ -335,8 +339,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, 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 );
   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 );
@@ -344,7 +349,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() );
@@ -372,8 +377,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, 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 );
   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 );
@@ -381,7 +387,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() );
@@ -426,7 +432,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, 0), B(2.0, gp_Vec2d(), 0, 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 ) );
@@ -491,21 +497,21 @@ void test_HYDROData_DTM::test_curve_to_3d()
   profiles.push_back( aProfile1 );
   profiles.push_back( aProfile2 );
 
-  Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
+  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, 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, 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();
 }
@@ -542,14 +548,15 @@ void test_HYDROData_DTM::test_presentation()
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
   DTM->Update();
   
-  CPPUNIT_ASSERT_EQUAL( 10200, (int)DTM->GetAltitudePoints().size() ); 
+  CPPUNIT_ASSERT_EQUAL( 9177, (int)DTM->GetAltitudePoints().size() ); 
 
-  Handle_AIS_InteractiveContext aContext = TestViewer::context();
+  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 );
@@ -558,11 +565,101 @@ void test_HYDROData_DTM::test_presentation()
   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<int> 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();
+}
+
+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 ) );
+
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  
+  Handle(HYDROData_CalculationCase) aCase = 
+    Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) );
+  CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); 
+  std::vector<gp_XY> points;
+  points.push_back( gp_XY( 43.4842, 3.33176  ) );
+  points.push_back( gp_XY( -125.777, 2.24728 ) );
+  points.push_back( gp_XY( -60.1628, 168.262 ) );
+  points.push_back( gp_XY( 21.8055587645, 154.699344457 ) );
+  points.push_back( gp_XY( -84.4764138524, 79.2606012276 ) );
+  points.push_back( gp_XY( -73.4132070504, 69.7096313266 ) );
+
+  std::vector<double> values = aCase->GetStricklerCoefficientForPoints( points, 0.0, true );
+  CPPUNIT_ASSERT_EQUAL( 6, (int)values.size() );
+  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 );
+
+  std::vector<int> 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] );
+
+  aDoc->Close();
 }
+