Salome HOME
Bug #202 - Fatal error during polyline creation
authornds <nds@opencascade.com>
Fri, 6 Dec 2013 11:25:33 +0000 (11:25 +0000)
committernds <nds@opencascade.com>
Fri, 6 Dec 2013 11:25:33 +0000 (11:25 +0000)
src/HYDROData/HYDROData_BSplineOperation.cxx
src/HYDROData/HYDROData_BSplineOperation.h
src/HYDROData/HYDROData_PolylineXY.cxx
src/HYDROData/test_HYDROData_BSplineOperation.cxx

index 293dbd442b6c6032e802982bbf1b17e46f87ffca..97fd9a57ffc5e6cb860b4b2435d2a4ef9cf5cee1 100644 (file)
 
 HYDROData_BSplineOperation::HYDROData_BSplineOperation(
   const NCollection_Sequence<gp_XYZ>& 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<gp_XYZ> 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 );
   }
 
index 640f85bce001fe1809884191a7aadece7b7c8849..093711a3dfe777716d03c19abb3b621b68de2c07 100644 (file)
@@ -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<gp_XYZ>& 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
index 94e3b1dc48c16be6ebbf856a547a946116d8e6a4..18dc1e4c663e2bed89a8a823d1af7ee06fb35f1e 100755 (executable)
@@ -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();
index 10dbb4360a160fea17f45cd0363d728edc268d8f..51bf3693276fc6fe6cc4eef0aecfa571558018cf 100644 (file)
@@ -4,6 +4,8 @@
 #include <gp_Pnt.hxx>
 #include <QTransform>
 
+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() );