X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_NumberOfSegments.cxx;h=139ea22e6c57ec9632ce393da9338c2826057cac;hp=0b9d333556f0052ec19e485c38d81457adbcbfe6;hb=d0f366c4a3a66a71b0be94f7a6e2d146f80a94c4;hpb=6b471bcc54cbeb90f0d977323db8c76d3d2cce09 diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index 0b9d33355..139ea22e6 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -27,20 +27,27 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_NumberOfSegments.hxx" + #include "StdMeshers_Distribution.hxx" -#include -#include -#include -#include +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + #include -#include #include -#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include + +using namespace std; const double PRECISION = 1e-7; @@ -640,3 +647,40 @@ istream & operator >>(istream & load, StdMeshers_NumberOfSegments & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize number of segments 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_NumberOfSegments::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _numberOfSegments = 0; + _distrType = DT_Regular; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + // get current segment length + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edgeMap( i )); + if ( eSubMesh && eSubMesh->NbElements()) + _numberOfSegments += eSubMesh->NbElements(); + + ++nbEdges; + } + if ( nbEdges ) + _numberOfSegments /= nbEdges; + + return nbEdges; +}