]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
debug of DTM object
authorasl <asl@opencascade.com>
Fri, 9 Sep 2016 13:02:18 +0000 (16:02 +0300)
committerasl <asl@opencascade.com>
Fri, 9 Sep 2016 13:02:18 +0000 (16:02 +0300)
src/HYDROData/HYDROData_Bathymetry.h
src/HYDROData/HYDROData_DTM.cxx
src/HYDROData/HYDROData_DTM.h
src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx
src/HYDROGUI/HYDROGUI_ShapeBathymetry.h
src/HYDRO_tests/ExternalFiles.cmake
src/HYDRO_tests/test_HYDROData_DTM.cxx
src/HYDRO_tests/test_HYDROData_DTM.h

index 79d5581dc33605175ebb5487217239b4e9ac46a4..63a44f92f47f11e6db601d8101047f17dbab1831 100644 (file)
@@ -43,6 +43,7 @@ class HYDROData_Bathymetry : public HYDROData_IAltitudeObject
 public:
   struct AltitudePoint
   {
+    AltitudePoint( double x=0, double y=0, double z=0 ) { X=x; Y=y; Z=z; }
     double X;
     double Y;
     double Z;
index 384f672a1348247ef936ac23b5f9523756fb6397..9e4da2318c36f4b33c004c8674829d565566f154 100644 (file)
@@ -22,6 +22,9 @@
 #include <TColStd_Array1OfInteger.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <Geom2dAPI_InterCurveCurve.hxx>
+#include <Geom2dAPI_ProjectPointOnCurve.hxx>
+#include <Geom2dAdaptor_Curve.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
 #include <limits>
 
 IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
@@ -82,8 +85,70 @@ HYDROData_DTM::~HYDROData_DTM()
 {
 }
 
+HYDROData_SequenceOfObjects HYDROData_DTM::GetProfiles() const
+{
+  return GetReferenceObjects( DataTag_Profiles );
+}
+
+void HYDROData_DTM::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles )
+{
+  SetReferenceObjects( theProfiles, DataTag_Profiles );
+}
+
+double HYDROData_DTM::GetDDZ() const
+{
+  return GetDouble( DataTag_DDZ );
+}
+
+void HYDROData_DTM::SetDDZ( double theDDZ )
+{
+  SetDouble( DataTag_DDZ, theDDZ );
+}
+
+double HYDROData_DTM::GetSpatialStep() const
+{
+  return GetDouble( DataTag_SpatialStep );
+}
+
+void HYDROData_DTM::SetSpatialStep( double theSpatialStep )
+{
+  SetDouble( DataTag_SpatialStep, theSpatialStep );
+}
+
+void HYDROData_DTM::Update()
+{
+  HYDROData_SequenceOfObjects objs = GetProfiles();
+  int aLower = objs.Lower(), anUpper = objs.Upper();
+  size_t n = anUpper-aLower+1;
+
+  std::vector<Handle_HYDROData_Profile> profiles;
+  profiles.reserve( n );
+  for( int i=aLower; i<=anUpper; i++ )
+  {
+    Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( objs.Value( i ) );
+    if( !aProfile.IsNull() )
+      profiles.push_back( aProfile );
+  }
+
+  double ddz = GetDDZ();
+  double step = GetSpatialStep();
+  const double EPS = 1E-3;
+  AltitudePoints points;
+  if( ddz>EPS && step>EPS )
+    points = Interpolate( profiles, ddz, step );
+  SetAltitudePoints( points );
+}
+
 
-void GetProperties( const Handle_HYDROData_Profile& theProfile,
+
+
+
+
+
+
+
+
+void HYDROData_DTM::GetProperties( const Handle_HYDROData_Profile& theProfile,
                     gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
                     bool isNormalDir,
                     double& theZMin, double& theZMax )
@@ -99,6 +164,20 @@ void GetProperties( const Handle_HYDROData_Profile& theProfile,
     theDir = gp_Vec2d( -y, x );
   else
     theDir = gp_Vec2d( x, y );
+
+  HYDROData_Profile::ProfilePoints points = theProfile->GetProfilePoints();
+  int lo = points.Lower();
+  int up = points.Upper();
+  theZMin = std::numeric_limits<double>::max();
+  theZMax = -theZMin;
+  for( int i=lo; i<=up; i++ )
+  {
+    double z = points.Value( i ).Z();
+    if( z>theZMax )
+      theZMax = z;
+    if( z<theZMin )
+      theZMin = z;
+  }
 }
 
 inline gp_Pnt2d To2D( const gp_Pnt& thePnt, const gp_Trsf& theTr,
@@ -193,7 +272,21 @@ Handle_Geom2d_BSplineCurve HYDROData_DTM::CreateHydraulicAxis(
   if( anInterpolator.IsDone() )
   {
     aResult = anInterpolator.Curve();
-    //TODO: fill the distances vector
+
+    //fill the distances vector
+    Geom2dAdaptor_Curve anAdaptor( aResult );
+
+    theDistances.clear();
+    theDistances.reserve( n );
+    Standard_Real aParamFirst = anAdaptor.FirstParameter(), aParamLast = anAdaptor.LastParameter();
+    for( size_t i = 1; i <= n; i++ )
+    {
+      gp_Pnt2d aPnt = points->Value( i );
+      Geom2dAPI_ProjectPointOnCurve aProject( aPnt, aResult );
+      Standard_Real aParam = aProject.LowerDistanceParameter();
+      double aDistance = GCPnts_AbscissaPoint::Length( anAdaptor, aParamFirst, aParam );  
+      theDistances.push_back( aDistance );
+    }
   }
   return aResult;
 }
@@ -278,7 +371,8 @@ void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& thePr
 {
   double aDblMax = std::numeric_limits<double>::max(),
          aUMin = aDblMax,
-         aUMax = -aUMin;
+         aUMax = -aUMin,
+         aVMax = 1000000;
   
   std::vector<Handle_Geom2d_Curve> curves = ProfileToParametric( theProfile, aUMin, aUMax );
   size_t n = curves.size();
@@ -291,10 +385,10 @@ void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& thePr
   curves[0]->D0( curves[0]->FirstParameter(), aFirst );
   curves[n-1]->D0( curves[n-1]->LastParameter(), aLast );
   Handle(Geom2d_Line) aV1 = new Geom2d_Line( aFirst, gp_Dir2d( 0, 1 ) );
-  Handle(Geom2d_TrimmedCurve) aT1 = new Geom2d_TrimmedCurve( aV1, 0.0, aDblMax );
+  Handle(Geom2d_TrimmedCurve) aT1 = new Geom2d_TrimmedCurve( aV1, 0.0, aVMax );
   
   Handle(Geom2d_Line) aV2 = new Geom2d_Line( aLast, gp_Dir2d( 0, 1 ) );
-  Handle(Geom2d_TrimmedCurve) aT2 = new Geom2d_TrimmedCurve( aV2, 0.0, aDblMax );
+  Handle(Geom2d_TrimmedCurve) aT2 = new Geom2d_TrimmedCurve( aV2, 0.0, aVMax );
 
   curves.push_back( aT1 );
   curves.push_back( aT2 );
@@ -315,7 +409,7 @@ void HYDROData_DTM::ProfileDiscretization( const Handle_HYDROData_Profile& thePr
     {
       Handle_Geom2d_Curve aCurve = curves[i];
       Geom2dAPI_InterCurveCurve anIntersect( aCurve, aLine, theTolerance );
-      for( int k=0, m=anIntersect.NbPoints(); k<m; k++ )
+      for( int k=1, m=anIntersect.NbPoints(); k<=m; k++ )
         intersections.push_back( anIntersect.Point( k ) );
     }
 
@@ -355,10 +449,35 @@ void HYDROData_DTM::Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCur
     theInterpolation.push_back( theCurveB );
 }
 
-void HYDROData_DTM::CurveTo3d( const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
+void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
+                               const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
                                AltitudePoints& thePoints )
 {
-  //TODO
+  Geom2dAdaptor_Curve anAdaptor( theHydraulicAxis );
+  GCPnts_AbscissaPoint ap( anAdaptor, theMidCurve.Xcurv(), anAdaptor.FirstParameter() );  
+  double aParam = ap.Parameter();
+
+  gp_Pnt2d point;
+  gp_Vec2d tangent, profile_dir;
+  anAdaptor.D1( aParam, point, tangent );
+  profile_dir.SetCoord( tangent.Y(), -tangent.X() );
+  profile_dir.Normalize();
+
+  size_t n = theMidCurve.size();
+  for( size_t i=0; i<n; i++ )
+  {
+    double param1 = theMidCurve[i].U - theWidthCurve[i].U / 2;
+    double param2 = theMidCurve[i].U + theWidthCurve[i].U / 2;
+
+    gp_Pnt2d p1 = point.Translated( param1 * profile_dir / 2 );
+    gp_Pnt2d p2 = point.Translated( param2 * profile_dir / 2 );
+
+    double z = theMidCurve[i].Z;
+
+    AltitudePoint p3d_1( p1.X(), p1.Y(), z ), p3d_2( p2.X(), p2.Y(), z );
+    thePoints.push_back( p3d_1 );
+    thePoints.push_back( p3d_2 );
+  }
 }
 
 inline double max( double a, double b )
@@ -369,12 +488,13 @@ inline double max( double a, double b )
     return b;
 }
 
-void HYDROData_DTM::Interpolate( const Handle_HYDROData_Profile& theProfileA,
-                                 double theXCurvA,
-                                 const Handle_HYDROData_Profile& theProfileB,
-                                 double theXCurvB,
-                                 double theDDZ, int theNbSteps, bool isAddSecond,
-                                 AltitudePoints& thePoints )
+HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
+  ( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
+    const Handle_HYDROData_Profile& theProfileA,
+    double theXCurvA,
+    const Handle_HYDROData_Profile& theProfileB,
+    double theXCurvB,
+    double theDDZ, int theNbSteps, bool isAddSecond )
 {
   double zminA, zmaxA, zminB, zmaxB;
   gp_Pnt lowestA, lowestB;
@@ -396,29 +516,40 @@ void HYDROData_DTM::Interpolate( const Handle_HYDROData_Profile& theProfileA,
   Interpolate( midA, midB, theNbSteps, mid, isAddSecond );
   Interpolate( widA, widB, theNbSteps, wid, isAddSecond );
 
-  size_t q = mid.size();
+  size_t p = mid.size();
+  size_t q = p>0 ? 2*mid[0].size() : 1;
+  AltitudePoints points;
+  points.reserve( p*q );
   for( size_t i=0; i<q; i++ )
-    CurveTo3d( mid[i], wid[i], thePoints );
+    CurveTo3D( theHydraulicAxis, mid[i], wid[i], points );
+  return points;
 }
 
-void HYDROData_DTM::Interpolate( const std::vector<Handle_HYDROData_Profile>& theProfiles,
-                                 double theDDZ, double theSpatialStep, AltitudePoints& thePoints )
+HYDROData_Bathymetry::AltitudePoints HYDROData_DTM::Interpolate
+  ( const std::vector<Handle_HYDROData_Profile>& theProfiles,
+    double theDDZ, double theSpatialStep )
 {
+  AltitudePoints points;
   size_t n = theProfiles.size();
   if( n<=1 )
-    return;
+    return points;
 
   std::vector<double> distances;
   Handle_Geom2d_BSplineCurve aHydraulicAxis = CreateHydraulicAxis( theProfiles, distances );
   if( aHydraulicAxis.IsNull() )
-    return;
+    return points;
 
   for( size_t i=0, n1=n-1; i<n1; i++ )
   {
     double aDistance = distances[i+1]-distances[i];
     int aNbSteps = int(aDistance/theSpatialStep) + 1;
     bool isAddSecond = i==n1-1;
-    Interpolate( theProfiles[i], distances[i], 
-      theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond, thePoints );
+    AltitudePoints local_points = Interpolate( aHydraulicAxis, theProfiles[i], distances[i], 
+      theProfiles[i+1], distances[i+1], theDDZ, aNbSteps, isAddSecond );
+    if( i==0 )
+      points.reserve( local_points.size() * ( n-1 ) );
+    for( size_t j=0, m=local_points.size(); j<m; j++ )
+      points.push_back( local_points[j] );
   }
+  return points;
 }
index 2194c861b2658c39e40a54f758237e10a2b9b1ad..87bb10affd899d042820ad12d51cb983d316a0e8 100644 (file)
@@ -25,6 +25,8 @@
 class Handle_HYDROData_Profile;
 class Handle_Geom2d_BSplineCurve;
 class Handle_Geom2d_Curve;
+class gp_Pnt;
+class gp_Vec2d;
 
 DEFINE_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry )
 
@@ -40,20 +42,29 @@ protected:
   enum DataTag
   {
     DataTag_First = HYDROData_Bathymetry::DataTag_First + 100, ///< first tag, to reserve
+    DataTag_Profiles,
+    DataTag_DDZ,
+    DataTag_SpatialStep,
   };
 
 public:
   DEFINE_STANDARD_RTTI( HYDROData_DTM );
 
-protected:
-  friend class HYDROData_Iterator;
-  friend class test_HYDROData_DTM;
+  HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetProfiles() const;
+  HYDRODATA_EXPORT void SetProfiles( const HYDROData_SequenceOfObjects& );
 
-  HYDRODATA_EXPORT HYDROData_DTM();
-  virtual HYDRODATA_EXPORT ~HYDROData_DTM();
+  HYDRODATA_EXPORT double GetDDZ() const;
+  HYDRODATA_EXPORT void SetDDZ( double );
+
+  HYDRODATA_EXPORT double GetSpatialStep() const;
+  HYDRODATA_EXPORT void SetSpatialStep( double );
 
+  HYDRODATA_EXPORT virtual void Update();
+
+public:
   struct PointUZ
   {
+    PointUZ( double u=0, double z=0 ) { U=u; Z=z; }
     double U;
     double Z;
   };
@@ -72,6 +83,13 @@ protected:
     double myXcurv;
   };
 
+protected:
+  friend class HYDROData_Iterator;
+  friend class test_HYDROData_DTM;
+
+  HYDRODATA_EXPORT HYDROData_DTM();
+  virtual HYDRODATA_EXPORT ~HYDROData_DTM();
+
   static Handle_Geom2d_BSplineCurve CreateHydraulicAxis( 
     const std::vector<Handle_HYDROData_Profile>& theProfiles,
     std::vector<double>& theDistances );
@@ -79,28 +97,34 @@ protected:
   static std::vector<Handle_Geom2d_Curve> ProfileToParametric( const Handle_HYDROData_Profile& theProfile,
                                                                double& theUMin, double& theUMax );
 
+  static void GetProperties( const Handle_HYDROData_Profile& theProfile,
+                             gp_Pnt& theLowestPoint, gp_Vec2d& theDir,
+                             bool isNormalDir,
+                             double& theZMin, double& theZMax );
+
   static void ProfileDiscretization( const Handle_HYDROData_Profile& theProfile,
                                      double theXCurv, double theMinZ, double theMaxZ, double theDDZ,
                                      CurveUZ& theMidPointCurve,
                                      CurveUZ& theWidthCurve,
                                      double theTolerance = 1E-6 );
 
-  static void CurveTo3d( const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
+  static void CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
+                         const CurveUZ& theMidCurve, const CurveUZ& theWidthCurve,
                          AltitudePoints& thePoints );
   
   static void Interpolate( const CurveUZ& theCurveA, const CurveUZ& theCurveB, 
                            int theNbSteps, std::vector<CurveUZ>& theInterpolation,
                            bool isAddSecond );
 
-  static void Interpolate( const Handle_HYDROData_Profile& theProfileA,
-                           double theXCurvA,
-                           const Handle_HYDROData_Profile& theProfileB,
-                           double theXCurvB,
-                           double theDDZ, int theNbSteps, bool isAddSecond,
-                           AltitudePoints& thePoints );
+  static AltitudePoints Interpolate( const Handle_Geom2d_BSplineCurve& theHydraulicAxis,
+                                     const Handle_HYDROData_Profile& theProfileA,
+                                     double theXCurvA,
+                                     const Handle_HYDROData_Profile& theProfileB,
+                                     double theXCurvB,
+                                     double theDDZ, int theNbSteps, bool isAddSecond );
 
-  static void Interpolate( const std::vector<Handle_HYDROData_Profile>& theProfiles,
-                           double theDDZ, double theSpatialStep, AltitudePoints& thePoints );
+  static AltitudePoints Interpolate( const std::vector<Handle_HYDROData_Profile>& theProfiles,
+                                     double theDDZ, double theSpatialStep );
 };
 
 #endif
index 9835e1aa37db2db37ac5f565050cd25723a05bf6..0575b94616ac63c8dddbc34f0afc00aa8a3d9680 100644 (file)
@@ -37,7 +37,7 @@ HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer*
 
 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
 {
-  myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( true );
 }
 
 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
@@ -122,8 +122,7 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( isShown != theState );
   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
@@ -131,8 +130,7 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
@@ -140,8 +138,7 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::display( theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
@@ -149,6 +146,13 @@ void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( isShown  );
   HYDROGUI_Shape::erase( theIsUpdateViewer );
-  if( isChanged )
+  setToUpdateColorScale( isChanged );
+}
+
+void HYDROGUI_ShapeBathymetry::setToUpdateColorScale( bool isChanged )
+{
+#ifndef LIGHT_MODE
+  if( isChanged && myDisplayer )
     myDisplayer->SetToUpdateColorScale();
+#endif
 }
index 2521119560b8b6d27de2eb4677dfbbd5c1fa7d77..8a6447215ebe52080263d0b88a436febe75bbbee 100644 (file)
@@ -51,6 +51,8 @@ protected:
   virtual Handle_AIS_InteractiveObject createShape() const;
   virtual void displayShape( const bool theIsUpdateViewer );
 
+  void setToUpdateColorScale( bool isChanged );
+
 private:
   HYDROGUI_OCCDisplayer* myDisplayer;
   Handle_TColgp_HArray1OfPnt     myCoords;
index b137e502fbbcd2b4add149287a94d6e1fa418933..dfa0344b11a9603ed1445506ad21a5c67cd0791b 100644 (file)
@@ -67,6 +67,8 @@ set( EXTERNAL_FILES
   ../HYDROGUI/HYDROGUI_Polyline.cxx
   ../HYDROGUI/HYDROGUI_AISShape.cxx
   ../HYDROGUI/HYDROGUI_Shape.cxx
+  ../HYDROGUI/HYDROGUI_ShapeBathymetry.cxx
+  ../HYDROGUI/HYDROGUI_BathymetryPrs.cxx
   ../HYDROGUI/HYDROGUI_InputPanel.cxx
   ../HYDROGUI/HYDROGUI_StricklerTableDlg.cxx
   ../HYDROGUI/HYDROGUI_LineEditDoubleValidator.cxx
index 5786bef3d59e652882d332916d49297d412e2918..96e779c7046d65a64c2bf3fe8328cc96f942f822 100644 (file)
 
 #include <test_HYDROData_DTM.h>
 #include <HYDROData_Document.h>
-#include <HYDROData_DTM.h>
 #include <HYDROData_Profile.h>
+#include <HYDROData_DTM.h>
 #include <Geom2d_Curve.hxx>
 #include <Geom2d_BSplineCurve.hxx>
 #include <gp_XY.hxx>
 #include <gp_Pnt2d.hxx>
 #include <TColgp_Array1OfPnt2d.hxx>
+#include <TestViewer.h>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_PointCloud.hxx>
+#include <HYDROGUI_ShapeBathymetry.h>
+#include <Aspect_ColorScale.hxx>
+#include <QTest>
 
 const double EPS = 1E-3;
 
+NCollection_Sequence<HYDROData_IPolyline::Point> points;
+
+void test_HYDROData_DTM::setUp()
+{
+  points.Clear();
+  points.Append( gp_XY( 0.0, 5.0 ) );
+  points.Append( gp_XY( 1.0, 1.0 ) );
+  points.Append( gp_XY( 1.5, 0.0 ) );
+  points.Append( gp_XY( 4.0, 4.0 ) );
+}
+
 void test_HYDROData_DTM::test_creation()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
@@ -40,7 +57,7 @@ void test_HYDROData_DTM::test_creation()
   aDoc->Close();
 }
 
-void test_HYDROData_DTM::test_profile_conversion_to_2d()
+void test_HYDROData_DTM::test_hydraulic_axis()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
 
@@ -50,11 +67,50 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d()
   Handle(HYDROData_Profile) aProfile2 = 
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  NCollection_Sequence<HYDROData_IPolyline::Point> points;
-  points.Append( gp_XY( 0.0, 5.0 ) );
-  points.Append( gp_XY( 1.0, 1.0 ) );
-  points.Append( gp_XY( 1.5, 0.0 ) );
-  points.Append( gp_XY( 4.0, 4.0 ) );
+  Handle(HYDROData_Profile) aProfile3 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile1->SetParametricPoints( points );
+  aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile1->SetLeftPoint( gp_XY( 10, 10 ) );
+  aProfile1->SetRightPoint( gp_XY( 20, 0 ) );
+
+  aProfile2->SetParametricPoints( points );
+  aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile2->SetLeftPoint( gp_XY( 50, 0 ) );
+  aProfile2->SetRightPoint( gp_XY( 60, 10 ) );
+
+  aProfile3->SetParametricPoints( points );
+  aProfile3->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile3->SetLeftPoint( gp_XY( 200, 50 ) );
+  aProfile3->SetRightPoint( gp_XY( 210, 40 ) );
+
+  std::vector<double> distances;
+  std::vector<Handle(HYDROData_Profile)> profiles;
+  profiles.push_back( aProfile1 );
+  profiles.push_back( aProfile2 );
+  profiles.push_back( aProfile3 );
+
+  Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
+  CPPUNIT_ASSERT_EQUAL( false, (bool)HA.IsNull() );
+  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 );
+
+  aDoc->Close();
+}
+
+void test_HYDROData_DTM::test_profile_conversion_to_2d()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Profile) aProfile1 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  Handle(HYDROData_Profile) aProfile2 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile1->SetParametricPoints( points );
   aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
@@ -115,3 +171,283 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d()
 
   aDoc->Close();
 }
+
+void test_HYDROData_DTM::test_profile_properties()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Profile) aProfile = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile->SetParametricPoints( points );
+  aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
+  aProfile->SetRightPoint( gp_XY( 20, 25 ) );
+
+  gp_Pnt lp;
+  gp_Vec2d dd;
+  double zmin, zmax;
+  HYDROData_DTM::GetProperties( aProfile, lp, dd, false, 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( 10, dd.X(), EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 15, dd.Y(), EPS );
+  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 );
+  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 );
+
+  aDoc->Close();
+}
+
+void test_HYDROData_DTM::test_profile_discretization_polyline()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Profile) aProfile = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile->SetParametricPoints( points );
+  aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_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 );
+  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 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.11,  aMid[1].U, EPS );
+  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(  5.0,   aMid[10].Z, EPS );
+
+  CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  1.989, aWid[1].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aWid[1].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  8.618, aWid[5].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aWid[5].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aWid[10].Z, EPS );
+
+  aDoc->Close();
+}
+
+void test_HYDROData_DTM::test_profile_discretization_spline()
+{
+Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Profile) aProfile = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile->SetParametricPoints( points );
+  aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
+  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 );
+  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 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.755, aMid[1].U, EPS );
+  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(  5.0,   aMid[10].Z, EPS );
+
+  CPPUNIT_ASSERT_EQUAL( 11, (int)aWid.size() );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.484, aWid[0].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.0,   aWid[0].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  3.809, aWid[1].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  0.5,   aWid[1].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  9.472, aWid[5].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  2.5,   aWid[5].Z, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 14.142, aWid[10].U, EPS );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL(  5.0,   aWid[10].Z, EPS );
+
+  aDoc->Close();
+}
+
+void operator << ( std::ostream& s, const HYDROData_DTM::PointUZ& p )
+{
+  s << "(" << p.U << "; " << p.Z << ") ";
+}
+
+void operator << ( std::ostream& s, const HYDROData_DTM::AltitudePoint& p )
+{
+  s << "(" << p.X << "; " << p.Y << "; " << p.Z << ") ";
+}
+
+bool operator == ( const HYDROData_DTM::PointUZ& p1, const HYDROData_DTM::PointUZ& p2 )
+{
+  return fabs(p1.U-p2.U)<EPS && fabs(p1.Z-p2.Z)<EPS;
+}
+
+bool operator == ( const HYDROData_DTM::AltitudePoint& p1, const HYDROData_DTM::AltitudePoint& p2 )
+{
+  return fabs(p1.X-p2.X)<EPS && fabs(p1.Y-p2.Y)<EPS && fabs(p1.Z-p2.Z)<EPS;
+}
+
+void operator << ( std::ostream& s, const HYDROData_DTM::CurveUZ& c )
+{
+  size_t n = c.size();
+  for( size_t i=0; i<n; i++ )
+    s << c[i];
+}
+
+void test_HYDROData_DTM::test_curves_interpolation()
+{
+  HYDROData_DTM::CurveUZ A(1.0), B(2.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 ) );
+  B.push_back( HYDROData_DTM::PointUZ( 10, 0 ) );
+  B.push_back( HYDROData_DTM::PointUZ( 15, 1 ) );
+  B.push_back( HYDROData_DTM::PointUZ( 20, 2 ) );
+
+  std::vector<HYDROData_DTM::CurveUZ> i1;
+  HYDROData_DTM::Interpolate( A, B, 1, i1, false );
+
+  CPPUNIT_ASSERT_EQUAL( 2, (int)i1.size() );
+  CPPUNIT_ASSERT_EQUAL( A, i1[0] );
+  CPPUNIT_ASSERT_EQUAL( 3, (int)i1[1].size() );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i1[1][0] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i1[1][1] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i1[1][2] );
+
+  std::vector<HYDROData_DTM::CurveUZ> i2;
+  HYDROData_DTM::Interpolate( A, B, 1, i2, true );
+
+  CPPUNIT_ASSERT_EQUAL( 3, (int)i2.size() );
+  CPPUNIT_ASSERT_EQUAL( A, i2[0] );
+  CPPUNIT_ASSERT_EQUAL( 3, (int)i2[1].size() );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 5, 0 ), i2[1][0] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 8, 1 ), i2[1][1] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 11, 2 ), i2[1][2] );
+  CPPUNIT_ASSERT_EQUAL( B, i2[2] );
+
+  std::vector<HYDROData_DTM::CurveUZ> i3;
+  HYDROData_DTM::Interpolate( A, B, 3, i3, false );
+
+  CPPUNIT_ASSERT_EQUAL( 4, (int)i3.size() );
+  CPPUNIT_ASSERT_EQUAL( A, i3[0] );
+  CPPUNIT_ASSERT_EQUAL( 3, (int)i3[1].size() );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 2.5, 0 ), i3[1][0] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 4.5, 1 ), i3[1][1] );
+  CPPUNIT_ASSERT_EQUAL( HYDROData_DTM::PointUZ( 6.5, 2 ), i3[1][2] );
+}
+
+void test_HYDROData_DTM::test_curve_to_3d()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_Profile) aProfile1 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  Handle(HYDROData_Profile) aProfile2 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile1->SetParametricPoints( points );
+  aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
+  aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
+
+  aProfile2->SetParametricPoints( points );
+  aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+  aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
+  aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
+
+  std::vector<double> distances;
+  std::vector<Handle(HYDROData_Profile)> profiles;
+  profiles.push_back( aProfile1 );
+  profiles.push_back( aProfile2 );
+
+  Handle_Geom2d_BSplineCurve HA = HYDROData_DTM::CreateHydraulicAxis( profiles, distances );
+  HYDROData_DTM::AltitudePoints points;
+  HYDROData_DTM::CurveUZ mid( 5.0 );
+  mid.push_back( HYDROData_DTM::PointUZ( 0, 5 ) );
+  mid.push_back( HYDROData_DTM::PointUZ( 1, 6 ) );
+  HYDROData_DTM::CurveUZ wid( 5.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] );
+
+  aDoc->Close();
+}
+
+void test_HYDROData_DTM::test_presentation()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+  Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
+
+  Handle(HYDROData_Profile) aProfile1 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  Handle(HYDROData_Profile) aProfile2 = 
+    Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+  aProfile1->SetParametricPoints( points );
+  aProfile1->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
+  aProfile1->SetLeftPoint( gp_XY( 20, 0 ) );
+  aProfile1->SetRightPoint( gp_XY( 10, 10 ) );
+
+  aProfile2->SetParametricPoints( points );
+  aProfile2->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_SPLINE );
+  aProfile2->SetLeftPoint( gp_XY( 100, 0 ) );
+  aProfile2->SetRightPoint( gp_XY( 110, 0 ) );
+
+  HYDROData_SequenceOfObjects seq;
+  seq.Append( aProfile1 );
+  seq.Append( aProfile2 );
+  DTM->SetProfiles( seq );
+  DTM->SetDDZ( 0.1 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
+  DTM->SetSpatialStep( 1.0 );
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
+  DTM->Update();
+  
+  CPPUNIT_ASSERT_EQUAL( 10404, (int)DTM->GetAltitudePoints().size() ); 
+
+  Handle_AIS_InteractiveContext aContext = TestViewer::context();
+  HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
+  aBathPrs->update( true, false );
+
+  TestViewer::showColorScale( true );
+  Handle_Aspect_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
+  delete aBathPrs;
+
+  aDoc->Close();
+}
+
+void test_HYDROData_DTM::test_garonne()
+{
+  //TODO
+}
index 30eac980c61334b8a9c832d37b599cccf8225201..5eb53be1bca2b7ff9b73ee18dc5b851698cb95ba 100644 (file)
@@ -22,15 +22,31 @@ class test_HYDROData_DTM : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE( test_HYDROData_DTM );
   CPPUNIT_TEST( test_creation );
+  CPPUNIT_TEST( test_hydraulic_axis );
   CPPUNIT_TEST( test_profile_conversion_to_2d );
+  CPPUNIT_TEST( test_profile_properties );
+  CPPUNIT_TEST( test_profile_discretization_polyline );
+  CPPUNIT_TEST( test_profile_discretization_spline );
+  CPPUNIT_TEST( test_curves_interpolation );
+  CPPUNIT_TEST( test_curve_to_3d );
+  CPPUNIT_TEST( test_presentation );
+  CPPUNIT_TEST( test_garonne );
   CPPUNIT_TEST_SUITE_END();
 
 public:
-  void setUp() {}
+  void setUp();
   void tearDown() {}
 
   void test_creation();
+  void test_hydraulic_axis();
   void test_profile_conversion_to_2d();
+  void test_profile_properties();
+  void test_profile_discretization_polyline();
+  void test_profile_discretization_spline();
+  void test_curves_interpolation();
+  void test_curve_to_3d();
+  void test_presentation();
+  void test_garonne();
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION( test_HYDROData_DTM );