X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH%2FSMESH_Algo.cxx;h=5ec1240b00bdcb9c8fd007e413b47c2d9b18a589;hp=60921d4a45ae9d8205e9dbb2c09f163c8164fef8;hb=f488c3c07d53aacb42ff2a143fb4a0cbfe8d5fc0;hpb=04fe81eb47258802362d02095b6fe7d73d3869ec diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 60921d4a4..5ec1240b0 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -178,8 +178,7 @@ const SMESH_Algo::Features& SMESH_Algo::GetFeatures( const std::string& algoType SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen) : SMESH_Hypothesis(hypId, studyId, gen) { - //gen->_mapAlgo[hypId] = this; - + _compatibleAllHypFilter = _compatibleNoAuxHypFilter = NULL; _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true; _quadraticMesh = _supportSubmeshes = false; _error = COMPERR_OK; @@ -195,6 +194,8 @@ SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen) SMESH_Algo::~SMESH_Algo() { + delete _compatibleNoAuxHypFilter; + // delete _compatibleAllHypFilter; -- _compatibleNoAuxHypFilter does it!!! } //============================================================================= @@ -208,28 +209,24 @@ SMESH_0D_Algo::SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen) { _shapeType = (1 << TopAbs_VERTEX); _type = ALGO_0D; - //gen->_map0D_Algo[hypId] = this; } SMESH_1D_Algo::SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Algo(hypId, studyId, gen) { _shapeType = (1 << TopAbs_EDGE); _type = ALGO_1D; - //gen->_map1D_Algo[hypId] = this; } SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Algo(hypId, studyId, gen) { _shapeType = (1 << TopAbs_FACE); _type = ALGO_2D; - //gen->_map2D_Algo[hypId] = this; } SMESH_3D_Algo::SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Algo(hypId, studyId, gen) { _shapeType = (1 << TopAbs_SOLID); _type = ALGO_3D; - //gen->_map3D_Algo[hypId] = this; } //============================================================================= @@ -269,10 +266,9 @@ SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh, { SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); me->_usedHypList.clear(); - SMESH_HypoFilter filter; - if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) + if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary )) { - aMesh.GetHypotheses( aShape, filter, me->_usedHypList, true ); + aMesh.GetHypotheses( aShape, *filter, me->_usedHypList, true ); if ( ignoreAuxiliary && _usedHypList.size() > 1 ) me->_usedHypList.clear(); //only one compatible hypothesis allowed } @@ -294,9 +290,8 @@ SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh, { SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); me->_appliedHypList.clear(); - SMESH_HypoFilter filter; - if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary )) - aMesh.GetHypotheses( aShape, filter, me->_appliedHypList, false ); + if ( const SMESH_HypoFilter* filter = GetCompatibleHypoFilter( ignoreAuxiliary )) + aMesh.GetHypotheses( aShape, *filter, me->_appliedHypList, false ); return _appliedHypList; } @@ -310,10 +305,10 @@ SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh, double SMESH_Algo::EdgeLength(const TopoDS_Edge & E) { double UMin = 0, UMax = 0; - if (BRep_Tool::Degenerated(E)) - return 0; TopLoc_Location L; Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); + if ( C.IsNull() ) + return 0.; GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax); return length; @@ -416,7 +411,7 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theM return false; SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge ); - if ( !eSubMesh || !eSubMesh->GetElements()->more() ) + if ( !eSubMesh || ( eSubMesh->NbElements()==0 && eSubMesh->NbNodes() == 0)) return false; // edge is not meshed int nbNodes = 0; @@ -463,27 +458,35 @@ bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theM //================================================================================ /*! - * \brief Make filter recognize only compatible hypotheses - * \param theFilter - the filter to initialize - * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses + * \brief Returns the filter recognizing only compatible hypotheses + * \param ignoreAuxiliary - make filter ignore auxiliary hypotheses + * \retval SMESH_HypoFilter* - the filter that can be NULL */ //================================================================================ -bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter, - const bool ignoreAuxiliary) const +const SMESH_HypoFilter* +SMESH_Algo::GetCompatibleHypoFilter(const bool ignoreAuxiliary) const { if ( !_compatibleHypothesis.empty() ) { - theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] )); - for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) - theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] )); - - if ( ignoreAuxiliary ) - theFilter.AndNot( theFilter.IsAuxiliary() ); - - return true; + if ( !_compatibleAllHypFilter ) + { + SMESH_HypoFilter* filter = new SMESH_HypoFilter(); + filter->Init( filter->HasName( _compatibleHypothesis[0] )); + for ( int i = 1; i < _compatibleHypothesis.size(); ++i ) + filter->Or( filter->HasName( _compatibleHypothesis[ i ] )); + + SMESH_HypoFilter* filterNoAux = new SMESH_HypoFilter( filter ); + filterNoAux->AndNot( filterNoAux->IsAuxiliary() ); + + // _compatibleNoAuxHypFilter will detele _compatibleAllHypFilter!!! + SMESH_Algo* me = const_cast< SMESH_Algo* >( this ); + me->_compatibleAllHypFilter = filter; + me->_compatibleNoAuxHypFilter = filterNoAux; + } + return ignoreAuxiliary ? _compatibleNoAuxHypFilter : _compatibleAllHypFilter; } - return false; + return 0; } //================================================================================ @@ -519,9 +522,7 @@ GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1, Standard_Real tol = BRep_Tool::Tolerance( V ); Standard_Real angTol = 2e-3; try { -#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; -#endif return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol); } catch (Standard_Failure) { @@ -529,12 +530,78 @@ 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 true if an edge has no 3D curve + */ +//================================================================================ + +bool SMESH_Algo::isDegenerated( const TopoDS_Edge & E ) +{ + double f,l; + TopLoc_Location loc; + Handle(Geom_Curve) C = BRep_Tool::Curve( E, loc, f,l ); + return C.IsNull(); +} + //================================================================================ /*! * \brief Return the node built on a vertex * \param V - the vertex * \param meshDS - mesh * \retval const SMDS_MeshNode* - found node or NULL + * \sa SMESH_MesherHelper::GetSubShapeByNode( const SMDS_MeshNode*, SMESHDS_Mesh* ) */ //================================================================================