Salome HOME
Fix regression of SMESH_TEST/Grids/smesh/3D_mesh_Extrusion/A3
authoreap <eap@opencascade.com>
Tue, 13 Aug 2013 16:35:31 +0000 (16:35 +0000)
committereap <eap@opencascade.com>
Tue, 13 Aug 2013 16:35:31 +0000 (16:35 +0000)
+  static bool isStraight( const TopoDS_Edge & E, const bool degenResult=false );

src/SMESH/SMESH_Algo.cxx
src/SMESH/SMESH_Algo.hxx

index 60921d4a45ae9d8205e9dbb2c09f163c8164fef8..f08542dc0f73c1ce3e9c48387d055c853a36fdbf 100644 (file)
@@ -529,6 +529,57 @@ GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
   return GeomAbs_C0;
 }
 
   return GeomAbs_C0;
 }
 
+//================================================================================
+/*!
+ * \brief Return true if an edge can be considered straight
+ */
+//================================================================================
+
+bool SMESH_Algo::isStraight( const TopoDS_Edge & E,
+                             const bool          degenResult)
+{
+  {
+    double f,l;
+    if ( BRep_Tool::Curve( E, f, l ).IsNull())
+      return degenResult;
+  }
+  BRepAdaptor_Curve curve( E );
+  switch( curve.GetType() )
+  {
+  case GeomAbs_Line:
+    return true;
+  case GeomAbs_Circle:
+  case GeomAbs_Ellipse:
+  case GeomAbs_Hyperbola:
+  case GeomAbs_Parabola:
+    return false;
+  // case GeomAbs_BezierCurve:
+  // case GeomAbs_BSplineCurve:
+  // case GeomAbs_OtherCurve:
+  default:;
+  }
+  const double   f = curve.FirstParameter();
+  const double   l = curve.LastParameter();
+  const gp_Pnt  pf = curve.Value( f );
+  const gp_Pnt  pl = curve.Value( l );
+  const gp_Vec v1( pf, pl );
+  const double v1Len = v1.Magnitude();
+  if ( v1Len < std::numeric_limits< double >::min() )
+    return false; // E seems closed
+  const double tol = Min( 10 * curve.Tolerance(), v1Len * 1e-2 );
+  const int nbSamples = 7;
+  for ( int i = 0; i < nbSamples; ++i )
+  {
+    const double  r = ( i + 1 ) / nbSamples;
+    const gp_Pnt pi = curve.Value( f * r + l * ( 1 - r ));
+    const gp_Vec vi( pf, pi );
+    const double  h = 0.5 * v1.Crossed( vi ).Magnitude() / v1Len;
+    if ( h > tol )
+      return false;
+  }
+  return true;
+}
+
 //================================================================================
 /*!
  * \brief Return the node built on a vertex
 //================================================================================
 /*!
  * \brief Return the node built on a vertex
index a7cfd5fd0a1438f1c48df7b2d9323f7518cb1360..4d22e655dc432cfa12bc636e1f309734cd2ccd7b 100644 (file)
@@ -357,6 +357,10 @@ public:
   static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
     return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
   }
   static bool IsContinuous(const TopoDS_Edge & E1, const TopoDS_Edge & E2) {
     return ( Continuity( E1, E2 ) >= GeomAbs_G1 );
   }
+  /*!
+   * \brief Return true if an edge can be considered straight
+   */
+  static bool isStraight( const TopoDS_Edge & E, const bool degenResult=false );
 
   /*!
    * \brief Return the node built on a vertex
 
   /*!
    * \brief Return the node built on a vertex