Salome HOME
Merge branch 'BR_HYDRO_IMPS_2016' into pre/IMPS_2016
[modules/hydro.git] / src / HYDROData / HYDROData_ChannelAltitude.cxx
index fd3917cc21566fda8e23c1f8d04bf44a255f53e6..92d4d2fe7c9597ef543d069124532067126d0e66 100644 (file)
@@ -23,6 +23,8 @@
 #include "HYDROData_Channel.h"
 #include "HYDROData_Projection.h"
 #include "HYDROData_Polyline3D.h"
+#include "HYDROData_PolylineXY.h"
+#include "HYDROData_ProfileUZ.h"
 #include "HYDROData_Profile.h"
 
 #define _DEVDEBUG_
@@ -63,9 +65,10 @@ HYDROData_ChannelAltitude::~HYDROData_ChannelAltitude()
 {
 }
 
-double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const
+double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint,
+                                                       int theMethod) const
 {
-  DEBTRACE("HYDROData_ChannelAltitude::GetAltitudeForPoint");
+  DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
   double aResAltitude = GetInvalidAltitude();
 
   Handle(HYDROData_Channel) aChannel =
@@ -76,24 +79,46 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
       return aResAltitude;
     }
   DEBTRACE("aChannel: " << aChannel->GetName().toStdString());
+
   Handle(HYDROData_Polyline3D) aGuideLine = aChannel->GetGuideLine();
   if (aGuideLine.IsNull())
     {
       DEBTRACE("aGuideLine.IsNull()");
       return aResAltitude;
     }
-  DEBTRACE("aGuideLine: " << aGuideLine->GetName().toStdString());
+  //DEBTRACE("aGuideLine: " << aGuideLine->GetName().toStdString());
+
+  Handle(HYDROData_PolylineXY) aGuideXY = aGuideLine->GetPolylineXY();
+  if (aGuideXY.IsNull())
+    {
+      DEBTRACE("aGuideXY.IsNull()");
+      return aResAltitude;
+    }
+  //DEBTRACE("aGuideXY: " << aGuideXY->GetName().toStdString());
+
+  Handle(HYDROData_ProfileUZ) aGuideUZ = aGuideLine->GetProfileUZ();
+  if (aGuideUZ.IsNull())
+    {
+      aGuideUZ = aGuideLine->GetChildProfileUZ(); // profile obtained from bathymetry
+    }
+  if (aGuideUZ.IsNull())
+    {
+      DEBTRACE("aGuideUZ.IsNull()");
+      return aResAltitude;
+    }
+  //DEBTRACE("aGuideUZ: " << aGuideUZ->GetName().toStdString());
+
   Handle (HYDROData_Profile) aProfile = aChannel->GetProfile();
   if (aProfile.IsNull())
     {
       return aResAltitude;
     }
-  DEBTRACE("aProfile: " << aProfile->GetName().toStdString());
+  //DEBTRACE("aProfile: " << aProfile->GetName().toStdString());
 
   // --- See GEOMImpl_ProjectionDriver.cxx
 
-  TopoDS_Shape aShape = aGuideLine->GetShape3D();
-  gp_Pnt P1(thePoint.X(), thePoint.Y(), 0); // plutot altitude moyenne
+  TopoDS_Shape aShape =  aGuideXY->GetShape();
+  gp_Pnt P1(thePoint.X(), thePoint.Y(), 0);
   TopoDS_Shape aPoint = BRepBuilderAPI_MakeVertex(P1).Shape();
 
   if (aPoint.IsNull() || aShape.IsNull())
@@ -223,46 +248,72 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
           // Store the valid solution.
           hasValidSolution = Standard_True;
 
-          // Normalize parameter.
-          TopoDS_Edge aSupportEdge = TopoDS::Edge(aSupportShape);
-          Standard_Real aF, aL;
-
-          BRep_Tool::Range(aSupportEdge, aF, aL);
-
-          if (Abs(aL - aF) <= aTolConf)
+          // profile altitude at projection point
+          HYDROData_IPolyline::PointsList aProfilePoints = aGuideUZ->GetPoints();
+          if ( aProfilePoints.IsEmpty() )
             {
-              DEBTRACE("Projection aborted : degenerated projection edge");
+              DEBTRACE("empty profile UZ");
               return aResAltitude;
             }
+          double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParam );
+          //DEBTRACE("profile altitude: " << aDepth);
 
-//          aParam = (aParam - aF) / (aL - aF);
-//          aProj.SetU(aParam);
-//
-//          // Compute edge index.
-//          TopExp_Explorer anExp(aShape, TopAbs_EDGE);
-//          int anIndex = 0;
-//
-//          for (; anExp.More(); anExp.Next(), anIndex++)
-//            {
-//              if (aSupportShape.IsSame(anExp.Current()))
-//                {
-//                  aProj.SetIndex(anIndex);
-//                  break;
-//                }
-//            }
-//
-//          if (!anExp.More())
-//            {
-//              DEBTRACE("Projection aborted : Can't define edge index");
-//              return aResAltitude;
-//            }
+          // Compute edge index.
+          TopExp_Explorer anExp(aShape, TopAbs_EDGE);
+          int anIndex = 0;
+          for (; anExp.More(); anExp.Next(), anIndex++)
+            {
+              if (aSupportShape.IsSame(anExp.Current()))
+                {
+                  break;
+                }
+            }
 
-          // Construct a projection vertex.
+          // get the XY distance from point to guideline
           const gp_Pnt &aPntProj = aDistShSh.PointOnShape2(i);
-          TopoDS_Shape aProj = BRepBuilderAPI_MakeVertex(aPntProj).Shape();
-          DEBTRACE("projection: (" << aPntProj.X() << ", " << aPntProj.Y() << ", " << aPntProj.Z() << ")");
-          return aPntProj.Z();
-          //aFunction->SetValue(aProj);
+          //DEBTRACE("projection: (" << aPntProj.X() << ", " << aPntProj.Y() << ", " << aPntProj.Z() << ")");
+          gp_XY aProjXY = gp_XY(aPntProj.X(), aPntProj.Y());
+          aProjXY.Subtract(thePoint);
+          double distance = aProjXY.Modulus();
+          //DEBTRACE("distance to guideline " << distance);
+
+          // get delta altitude on section (supposed symmetric) from guideline distance (aParam)
+          double delta = 0;
+          int i1 = 0;
+          gp_XY pt1 = gp_XY();
+          gp_XY pt2 = gp_XY();
+          HYDROData_ProfileUZ::PointsList aSectionPoints = aProfile->GetParametricPoints();
+          for ( int i = 1, aNbPoints = aSectionPoints.Size(); i <= aNbPoints; ++i )
+            {
+              const HYDROData_IPolyline::Point& aPolylinePoint = aSectionPoints.Value( i );
+              //DEBTRACE("  profile point: " << aPolylinePoint.X() << " " << aPolylinePoint.Y());
+              if (aPolylinePoint.X() < distance)
+                {
+                  i1 = i;
+                  pt1 = aPolylinePoint;
+                }
+              if (aPolylinePoint.X() >= distance)
+                {
+                  pt2 = aPolylinePoint;
+                  break;
+                }
+            }
+          if ((i1 == 0) && (distance > 0))
+            {
+              DEBTRACE("Projection aborted : non centered profile");
+              return aResAltitude;
+            }
+          if (i1 == aProfilePoints.Size()) // distance >= profile width
+            {
+              delta = pt1.Y();
+            }
+          else
+            {
+              delta = pt1.Y() + (pt2.Y() - pt1.Y())*(distance -pt1.X())/(pt2.X()-pt1.X());
+            }
+          aResAltitude = delta + aDepth;
+          DEBTRACE("distance XY: "<< aParam << " distance to guideline: " << distance << " final altitude: " << aResAltitude << " delta: " << delta);
+          return aResAltitude;
         }
     }