X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_LocalLength.cxx;h=6fd6bbcf73b87721f572854cab62c3508ec2b9a5;hp=457d8d80c912e9296659d46065f10bd7d0180177;hb=c63ee099ad2b149bd70136839c973e8910137bc5;hpb=c3bf92bd87b770fd81631a3853f7f5bb1ac6a4e8 diff --git a/src/StdMeshers/StdMeshers_LocalLength.cxx b/src/StdMeshers/StdMeshers_LocalLength.cxx index 457d8d80c..6fd6bbcf7 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.cxx +++ b/src/StdMeshers/StdMeshers_LocalLength.cxx @@ -17,7 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // @@ -27,24 +27,37 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LocalLength.hxx" + +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + #include "utilities.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { - _length = 1.; - _name = "LocalLength"; -// SCRUTE(_name); -// SCRUTE(&_name); - _param_algo_dim = 1; // is used by SMESH_Regular_1D + _length = 1.; + _name = "LocalLength"; + _param_algo_dim = 1; // is used by SMESH_Regular_1D } //============================================================================= @@ -135,3 +148,47 @@ istream & operator >>(istream & load, StdMeshers_LocalLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_LocalLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _length = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + for ( int i = 1; i < params.size(); ++i ) + _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]); + nbEdges += params.size() - 1; + } + } + if ( nbEdges ) + _length /= nbEdges; + + return nbEdges; +}