From: eap Date: Tue, 13 Aug 2013 16:35:31 +0000 (+0000) Subject: Fix regression of SMESH_TEST/Grids/smesh/3D_mesh_Extrusion/A3 X-Git-Tag: V7_3_0a1~205 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d070665a5b42b6395723eca612bed8a78c77b6d;p=modules%2Fsmesh.git Fix regression of SMESH_TEST/Grids/smesh/3D_mesh_Extrusion/A3 + static bool isStraight( const TopoDS_Edge & E, const bool degenResult=false ); --- diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 60921d4a4..f08542dc0 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -529,6 +529,57 @@ GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1, 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 diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index a7cfd5fd0..4d22e655d 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -357,6 +357,10 @@ public: 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