From 21ae03f28bf1213ca6670edad46f13e17f9737c8 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 22 Nov 2016 15:42:52 +0300 Subject: [PATCH] patch for the crash in DTM creation --- src/HYDROData/HYDROData_Bathymetry.cxx | 18 ++++++++++++++++++ src/HYDROData/HYDROData_Bathymetry.h | 6 ++++-- src/HYDROData/HYDROData_DTM.cxx | 5 +++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index 1bdb97f9..f0a871a3 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -71,6 +71,24 @@ std::map HYDROData_Bathymetry::myQuadtrees; std::map HYDROData_Bathymetry::myDelaunay2D; #endif +inline double sqr( double x ) +{ + return x*x; +} + +HYDROData_Bathymetry::AltitudePoint::AltitudePoint( double x, double y, double z ) +{ + X=x; Y=y; Z=z; +} + +double HYDROData_Bathymetry::AltitudePoint::SquareDistance( const HYDROData_Bathymetry::AltitudePoint& p ) const +{ + double d = 0; + d += sqr( X - p.X ); + d += sqr( Y - p.Y ); + d += sqr( Z - p.Z ); + return d; +} HYDROData_Bathymetry::HYDROData_Bathymetry() : HYDROData_IAltitudeObject() diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 3797f195..8a0d8504 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -41,12 +41,14 @@ DEFINE_STANDARD_HANDLE(HYDROData_Bathymetry, HYDROData_IAltitudeObject) class HYDROData_Bathymetry : public HYDROData_IAltitudeObject { public: - struct AltitudePoint + struct HYDRODATA_EXPORT AltitudePoint { - AltitudePoint( double x=0, double y=0, double z=0 ) { X=x; Y=y; Z=z; } + AltitudePoint( double x=0, double y=0, double z=0 ); double X; double Y; double Z; + + double SquareDistance( const AltitudePoint& ) const; }; typedef std::vector AltitudePoints; diff --git a/src/HYDROData/HYDROData_DTM.cxx b/src/HYDROData/HYDROData_DTM.cxx index 96475a1b..13861a4b 100644 --- a/src/HYDROData/HYDROData_DTM.cxx +++ b/src/HYDROData/HYDROData_DTM.cxx @@ -53,7 +53,6 @@ IMPLEMENT_STANDARD_HANDLE( HYDROData_DTM, HYDROData_Bathymetry ) IMPLEMENT_STANDARD_RTTIEXT( HYDROData_DTM, HYDROData_Bathymetry ) - HYDROData_DTM::CurveUZ::CurveUZ( double theXCurv, const gp_Vec2d& theProfileDir, double theDeltaZ ) : myXcurv( theXCurv ), myProfileDir( theProfileDir ), myDeltaZ( theDeltaZ ) { @@ -738,9 +737,11 @@ void HYDROData_DTM::CurveTo3D( const Handle_Geom2d_BSplineCurve& theHydraulicAxi } thePoints.reserve( sorted_points.size() ); + const double EPS = 1E-12; std::map::const_iterator it = sorted_points.begin(), last = sorted_points.end(); for( ; it!=last; it++ ) - thePoints.push_back( it->second ); + if( thePoints.empty() || thePoints.back().SquareDistance( it->second ) > EPS ) + thePoints.push_back( it->second ); } inline double max( double a, double b ) -- 2.39.2