Salome HOME
refs #562: basic logic for Strickler table operation and dialog.
[modules/hydro.git] / src / HYDROData / HYDROData_StreamAltitude.cxx
index bb8aa4e7610b4a9e2a474e770273ede71569edad..50443a315d707f139085652189815ade803b395f 100644 (file)
@@ -1,3 +1,20 @@
+// Copyright (C) 2014-2015  EDF-R&D
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "HYDROData_StreamAltitude.h"
 
@@ -28,6 +45,8 @@
 
 #include <TopTools_SequenceOfShape.hxx>
 
+#include <Geom_Line.hxx>
+
 #include <QStringList>
 
 #ifdef DEB_CLASS2D
@@ -54,8 +73,8 @@ Standard_Real getAltitudeFromProfile( const Handle(HYDROData_Profile)& theProfil
   Standard_Real aResAlt = 0.0;
 
   gp_XY aFirstPoint, aLastPoint;
-  if ( !theProfile->GetLeftPoint( aFirstPoint ) ||
-       !theProfile->GetRightPoint( aLastPoint ) )
+  if ( !theProfile->GetLeftPoint( aFirstPoint, false ) ||
+       !theProfile->GetRightPoint( aLastPoint, false ) )
     return aResAlt;
 
   gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
@@ -71,7 +90,7 @@ Standard_Real getAltitudeFromProfile( const Handle(HYDROData_Profile)& theProfil
 
   gp_Pnt aPrevPoint;
   gp_Lin aPrevNormal;
-  HYDROData_Profile::ProfilePoints aProfilePoints = theProfile->GetProfilePoints();
+  HYDROData_Profile::ProfilePoints aProfilePoints = theProfile->GetProfilePoints( false );
   for ( int i = 1, n = aProfilePoints.Length(); i <= n; ++i )
   {
     gp_Pnt aProfPoint( aProfilePoints.Value( i ) );
@@ -141,7 +160,8 @@ bool HYDROData_StreamAltitude::getBoundaryProfilesForPoint(
       continue;
 
     gp_XY aFirstPoint, aLastPoint;
-    if ( !aProfile->GetLeftPoint( aFirstPoint ) || !aProfile->GetRightPoint( aLastPoint ) )
+    if ( !aProfile->GetLeftPoint( aFirstPoint, false ) ||
+         !aProfile->GetRightPoint( aLastPoint, false ) )
       continue;
 
     gp_Pnt aPnt1( aFirstPoint.X(), aFirstPoint.Y(), 0 );
@@ -255,10 +275,33 @@ double HYDROData_StreamAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) co
   Standard_Real aRightAlt = getAltitudeFromProfile( aRightProfile, aLeftDist, aRightDist );
 
   // Interpolate altitudes
-  Standard_Real aFirstCoeff = aLeftDist / ( aLeftDist + aRightDist );
-  Standard_Real aSecCoeff = aRightDist / ( aLeftDist + aRightDist );
-
-  aResAltitude = aLeftAlt * aFirstCoeff + aRightAlt * aSecCoeff;
+  // Left profile line ( the segment between the firts and the last profile point )
+  HYDROData_Profile::ProfilePoints aLeftProfilePoints = aLeftProfile->GetProfilePoints( false );
+  gp_Pnt aLeftProfileP1( aLeftProfilePoints.First() );
+  aLeftProfileP1.SetZ( 0 );
+  gp_Pnt aLeftProfileP2( aLeftProfilePoints.Last() );
+  aLeftProfileP2.SetZ( 0 );
+  gp_Vec aLeftProfileVec( aLeftProfileP1, aLeftProfileP2 );
+  Handle(Geom_Line) aLeftProfileLine = new Geom_Line( gp_Ax1( aLeftProfileP1, aLeftProfileVec ) );
+  // Right profile line
+  HYDROData_Profile::ProfilePoints aRightProfilePoints = aRightProfile->GetProfilePoints( false );
+  gp_Pnt aRightProfileP1( aRightProfilePoints.First() );
+  aRightProfileP1.SetZ( 0 );
+  gp_Pnt aRightProfileP2( aRightProfilePoints.Last() );
+  aRightProfileP2.SetZ( 0 );
+  gp_Vec aRightProfileVec( aRightProfileP1, aRightProfileP2 );
+  Handle(Geom_Line) aRightProfileLine = new Geom_Line( gp_Ax1( aRightProfileP1, aRightProfileVec ) );
+  // The point projections on the left and right profiles
+  GeomAPI_ProjectPointOnCurve aLeftProfileProject( aPointToTest, aLeftProfileLine );
+  GeomAPI_ProjectPointOnCurve aRightProfileProject( aPointToTest, aRightProfileLine );
+  // The point distance to the left and right profiles
+  Standard_Real aLeftProfileDist = aLeftProfileProject.LowerDistance();
+  Standard_Real aRightProfileDist = aRightProfileProject.LowerDistance();
+  // The coefficients
+  Standard_Real aFirstCoeff = aLeftProfileDist / ( aLeftProfileDist + aRightProfileDist );
+  Standard_Real aSecCoeff = aRightProfileDist / ( aLeftProfileDist + aRightProfileDist );
+
+  aResAltitude = aLeftAlt * ( 1 - aFirstCoeff ) + aRightAlt * ( 1 - aSecCoeff );
 
   return aResAltitude;
 }