]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bug #388: fix coefficients for calculation of the average altitude value.
authormzn <mzn@opencascade.com>
Wed, 9 Apr 2014 10:58:43 +0000 (10:58 +0000)
committermzn <mzn@opencascade.com>
Wed, 9 Apr 2014 10:58:43 +0000 (10:58 +0000)
src/HYDROData/HYDROData_StreamAltitude.cxx

index bb8aa4e7610b4a9e2a474e770273ede71569edad..11cd35e4d5e73359105f52d91e55c4d613bd7f98 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <TopTools_SequenceOfShape.hxx>
 
+#include <Geom_Line.hxx>
+
 #include <QStringList>
 
 #ifdef DEB_CLASS2D
@@ -255,10 +257,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();
+  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();
+  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;
 }