From: mzn Date: Fri, 27 Mar 2015 15:11:46 +0000 (+0300) Subject: refs #492: add HYDROData_Profile::GetBottomPoint() method X-Git-Tag: BR_hydro_v_1_0_5~22 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4e8df20c41b5a3ff5ae4473026bebb4574c4b69b;p=modules%2Fhydro.git refs #492: add HYDROData_Profile::GetBottomPoint() method --- diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index b970af45..3a628a74 100755 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -663,4 +663,58 @@ void HYDROData_Profile::UpdateLocalCS( double theDx, double theDy ) SetRightPoint( aPnt, false ); } +HYDROData_Profile::ProfilePoint HYDROData_Profile::GetBottomPoint() const +{ + ProfilePoint aBottom; + + // Get parametric points + HYDROData_ProfileUZ::PointsList aParametricPoints = GetParametricPoints(); + if ( aParametricPoints.Length() < 1 ) { + return aBottom; + } + + // Calculate midvalue for U parameter + Standard_Real anUMidValue = aParametricPoints.First().X(); + Standard_Real anUMinValue = anUMidValue; + Standard_Real anUMaxValue = anUMidValue; + + for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) { + const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i ); + Standard_Real anU = aParPoint.X(); + + if ( anU < anUMinValue ) { + anUMinValue = anU; + } else if ( anU > anUMaxValue ) { + anUMaxValue = anU; + } + } + + anUMidValue = ( anUMinValue + anUMaxValue ) / 2; + + // Find index of the parametric point with minimal Z value + int aBottomIndex = 1; + HYDROData_IPolyline::Point aParBottom = aParametricPoints.First(); + + for ( int i = 2, aNbPoints = aParametricPoints.Size(); i <= aNbPoints; i++ ) { + const HYDROData_IPolyline::Point& aParPoint = aParametricPoints.Value( i ); + if ( aParPoint.Y() < aParBottom.Y() ) { + aBottomIndex = i; + aParBottom = aParPoint; + } else if ( aParPoint.Y() == aParBottom.Y() ) { + // Check which point is neares to the U = 0.5 + if ( fabs( aParPoint.X() - anUMidValue ) < fabs( aParBottom.X() - anUMidValue ) ) { + aBottomIndex = i; + aParBottom = aParPoint; + } + } + } + + // Find the corresponding profile point + ProfilePoints aProfilePoints = GetProfilePoints( false ); + if ( aBottomIndex >= 1 && aBottomIndex <= aProfilePoints.Length() ) { + aBottom = aProfilePoints.Value( aBottomIndex ); + } + + return aBottom; +} diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index 14701053..03339e1f 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -191,6 +191,13 @@ public: */ HYDRODATA_EXPORT ProfilePoints GetProfilePoints( bool IsConvertToGlobal = false ) const; + + /** + * Return profile point with minimal Z value. + * \return non-parametric profile point + */ + HYDRODATA_EXPORT ProfilePoint GetBottomPoint() const; + public: // Public methods to work with files.