From 601f95d45f11a4498f8b5a3a133a9bdb84937059 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Dec 2013 11:25:33 +0000 Subject: [PATCH] Bug #202 - Fatal error during polyline creation --- src/HYDROData/HYDROData_BSplineOperation.cxx | 21 ++++++++++++++++--- src/HYDROData/HYDROData_BSplineOperation.h | 4 +++- src/HYDROData/HYDROData_PolylineXY.cxx | 6 +++--- .../test_HYDROData_BSplineOperation.cxx | 6 ++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/HYDROData/HYDROData_BSplineOperation.cxx b/src/HYDROData/HYDROData_BSplineOperation.cxx index 293dbd44..97fd9a57 100644 --- a/src/HYDROData/HYDROData_BSplineOperation.cxx +++ b/src/HYDROData/HYDROData_BSplineOperation.cxx @@ -11,15 +11,30 @@ HYDROData_BSplineOperation::HYDROData_BSplineOperation( const NCollection_Sequence& thePoints, - const bool theIsClosed ) + const bool theIsClosed, + const double theTolerance ) { - // fill array for algorithm by the received coordinates + // skip equal points int aNbPoints = thePoints.Size(); + NCollection_Sequence aPoints; + if ( aNbPoints > 0 ) { + gp_XYZ aPrevPoint = thePoints.Value( 1 ); + aPoints.Append( aPrevPoint ); + for( int i = 2 ; i <= aNbPoints; ++i ) + { + gp_XYZ aPoint( thePoints.Value( i ) ); + if ( !aPoint.IsEqual( aPrevPoint, theTolerance ) ) + aPoints.Append( aPoint ); + aPrevPoint = aPoint; + } + } + // fill array for algorithm by the received coordinates + aNbPoints = aPoints.Size(); Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt( 1, aNbPoints ); for ( int i = 1; i <= aNbPoints; i++ ) { - gp_Pnt aPnt( thePoints.Value( i ) ); + gp_Pnt aPnt( aPoints.Value( i ) ); aHCurvePoints->SetValue( i, aPnt ); } diff --git a/src/HYDROData/HYDROData_BSplineOperation.h b/src/HYDROData/HYDROData_BSplineOperation.h index 640f85bc..093711a3 100644 --- a/src/HYDROData/HYDROData_BSplineOperation.h +++ b/src/HYDROData/HYDROData_BSplineOperation.h @@ -26,8 +26,10 @@ public: //! Creates a spline by list of coordinates: pairs X and Y //! \param thePoints coordinates of curve //! \param theIsClosed flag indicating that the result spline should be closed + //! \param theTolerance flag indicating the tolerance to skip equal points HYDROData_BSplineOperation( const NCollection_Sequence& thePoints, - const bool theIsClosed ); + const bool theIsClosed, + const double theTolerance ); //! Returns the BSpline curve passing through the points //! \returns Null if Computation of BSpline was failed diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 94e3b1dc..18dc1e4c 100755 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -149,7 +149,7 @@ TopoDS_Wire HYDROData_PolylineXY::BuildWire( const SectionType& } else //if( theType == PolylineSection::SECTION_SPLINE ) { - HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed ); + HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE ); TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSpline.Curve() ).Edge(); aMakeWire.Add( anEdge ); @@ -188,7 +188,7 @@ void HYDROData_PolylineXY::BuildPainterPath( QPainterPath& } else { - HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed ); + HYDROData_BSplineOperation aBSpline( thePoints, theIsClosed, LOCAL_SELECTION_TOLERANCE ); aBSpline.ComputePath( thePath ); } } @@ -323,7 +323,7 @@ double HYDROData_PolylineXY::GetDistance( const int theSectionIndex, aPointToTest = aPoint; } - HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed ); + HYDROData_BSplineOperation aBSpline( aPoints, anIsSectionClosed, LOCAL_SELECTION_TOLERANCE ); Quantity_Parameter aFirstParam = aBSpline.Curve()->FirstParameter(); Quantity_Parameter aSecondParam = aBSpline.Curve()->LastParameter(); diff --git a/src/HYDROData/test_HYDROData_BSplineOperation.cxx b/src/HYDROData/test_HYDROData_BSplineOperation.cxx index 10dbb436..51bf3693 100644 --- a/src/HYDROData/test_HYDROData_BSplineOperation.cxx +++ b/src/HYDROData/test_HYDROData_BSplineOperation.cxx @@ -4,6 +4,8 @@ #include #include +const double LOCAL_SELECTION_TOLERANCE = 0.0001; + void test_HYDROData_BSplineOperation::testCurve() { // prepare points: function of sin(x) @@ -14,7 +16,7 @@ void test_HYDROData_BSplineOperation::testCurve() aPoints.Append( aPoint ); } // compute BSpline - HYDROData_BSplineOperation aBSpline( aPoints, false ); + HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE ); Handle(Geom_BSplineCurve) aBS = aBSpline.Curve(); CPPUNIT_ASSERT( !aBS.IsNull() ); @@ -44,7 +46,7 @@ void test_HYDROData_BSplineOperation::testPath() } // convert to QPainterPath - HYDROData_BSplineOperation aBSpline( aPoints, false ); + HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE ); CPPUNIT_ASSERT( !aBSpline.Curve().IsNull() ); -- 2.39.2