Salome HOME
merge master
[modules/hydro.git] / src / HYDROData / HYDROData_ChannelAltitude.cxx
index 1b1111c45350801030b209a93c823d6a9410f187..413685f83f3ddbc4a8874ec8de21e856ee2d10c5 100644 (file)
@@ -67,7 +67,7 @@ HYDROData_ChannelAltitude::~HYDROData_ChannelAltitude()
 
 double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const
 {
-  DEBTRACE("HYDROData_ChannelAltitude::GetAltitudeForPoint");
+  DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")");
   double aResAltitude = GetInvalidAltitude();
 
   Handle(HYDROData_Channel) aChannel =
@@ -85,7 +85,7 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
       DEBTRACE("aGuideLine.IsNull()");
       return aResAltitude;
     }
-  DEBTRACE("aGuideLine: " << aGuideLine->GetName().toStdString());
+  //DEBTRACE("aGuideLine: " << aGuideLine->GetName().toStdString());
 
   Handle(HYDROData_PolylineXY) aGuideXY = aGuideLine->GetPolylineXY();
   if (aGuideXY.IsNull())
@@ -93,7 +93,7 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
       DEBTRACE("aGuideXY.IsNull()");
       return aResAltitude;
     }
-  DEBTRACE("aGuideXY: " << aGuideXY->GetName().toStdString());
+  //DEBTRACE("aGuideXY: " << aGuideXY->GetName().toStdString());
 
   Handle(HYDROData_ProfileUZ) aGuideUZ = aGuideLine->GetProfileUZ();
   if (aGuideUZ.IsNull())
@@ -105,26 +105,17 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
       DEBTRACE("aGuideUZ.IsNull()");
       return aResAltitude;
     }
-  DEBTRACE("aGuideUZ: " << aGuideUZ->GetName().toStdString());
+  //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();
-//  double middleZ = -9999;
-//  aGuideLine->GetMiddleZ(middleZ); // use the middle Z value of the 3d line to help the projection.
-//  if (middleZ < -9000)
-//    {
-//      DEBTRACE("the middle Z value of the 3d line is incorrect");
-//    }
-//  gp_Pnt P1(thePoint.X(), thePoint.Y(), middleZ);
-
   TopoDS_Shape aShape =  aGuideXY->GetShape();
   gp_Pnt P1(thePoint.X(), thePoint.Y(), 0);
   TopoDS_Shape aPoint = BRepBuilderAPI_MakeVertex(P1).Shape();
@@ -256,16 +247,15 @@ 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;
             }
-          aParam = (aParam - aF)/(aL - aF);
+          double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParam );
+          //DEBTRACE("profile altitude: " << aDepth);
 
           // Compute edge index.
           TopExp_Explorer anExp(aShape, TopAbs_EDGE);
@@ -278,22 +268,24 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
                 }
             }
 
-          // 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() << ")");
+          //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 " << distance);
+          //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 aProfilePoints = aProfile->GetParametricPoints();
-          for ( int i = 1, aNbPoints = aProfilePoints.Size(); i <= aNbPoints; ++i )
+          HYDROData_ProfileUZ::PointsList aSectionPoints = aProfile->GetParametricPoints();
+          for ( int i = 1, aNbPoints = aSectionPoints.Size(); i <= aNbPoints; ++i )
             {
-              const HYDROData_IPolyline::Point& aPolylinePoint = aProfilePoints.Value( i );
-              DEBTRACE("  profile point: " << aPolylinePoint.X() << " " << aPolylinePoint.Y());
+              const HYDROData_IPolyline::Point& aPolylinePoint = aSectionPoints.Value( i );
+              //DEBTRACE("  profile point: " << aPolylinePoint.X() << " " << aPolylinePoint.Y());
               if (aPolylinePoint.X() < distance)
                 {
                   i1 = i;
@@ -310,47 +302,16 @@ double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) c
               DEBTRACE("Projection aborted : non centered profile");
               return aResAltitude;
             }
-
-          // get the point with the same param on altitude profile
-          double zRef = 0; //aPntProj.Z();
-          TopoDS_Shape aShapeUZ =  aGuideUZ->GetShape();
-          if (!aShapeUZ.IsNull())
-            {
-              TopExp_Explorer anExpUZ(aShapeUZ, TopAbs_EDGE);
-              TopoDS_Edge anEdgeUZ;
-              int anI = 0;
-              for (; anExpUZ.More(); anExpUZ.Next(), anI++)
-                {
-                  if (anI == anIndex)
-                    {
-                      anEdgeUZ = TopoDS::Edge(anExpUZ.Current());
-                      break;
-                    }
-                }
-              if (!anEdgeUZ.IsNull())
-                {
-                  double anEdgePars[2];
-                  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdgeUZ, anEdgePars[0], anEdgePars[1]);
-                  gp_Pnt aVal;
-                  aCurve->D0(aParam, aVal);
-                  DEBTRACE("altitude point: " << aVal.X() << " "<< aVal.Y() << " "<< aVal.Z());
-                  zRef = aVal.Y();
-                }
-              else zRef = 20;
-            }
-          else zRef = 20;
-
-          // distance on section to get altitude
           if (i1 == aProfilePoints.Size()) // distance >= profile width
             {
-              aResAltitude = zRef + pt1.Y();
+              delta = pt1.Y();
             }
           else
             {
-              double z = pt1.Y() + (pt2.Y() - pt1.Y())*(distance -pt1.X())/(pt2.X()-pt1.X());
-              aResAltitude = zRef + z;
+              delta = pt1.Y() + (pt2.Y() - pt1.Y())*(distance -pt1.X())/(pt2.X()-pt1.X());
             }
-          DEBTRACE("altitude: " << aResAltitude << " delta: " << aResAltitude - zRef);
+          aResAltitude = delta + aDepth;
+          DEBTRACE("distance XY: "<< aParam << " distance to guideline: " << distance << " final altitude: " << aResAltitude << " delta: " << delta);
           return aResAltitude;
         }
     }