X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH%2FSMESH_ProxyMesh.cxx;h=c8dcec11c7f3cd0bddb77175f8bf3b4fdc6fddd2;hb=8dc55ee0b75c97cc1a3d537cff6e992c6122b6d1;hp=a4e4f5998b9c114fbddd472efb2cc778772b2290;hpb=bd4e115a78b52e3fbc016e5e30bb0e19b2a9e7d6;p=modules%2Fsmesh.git diff --git a/src/SMESH/SMESH_ProxyMesh.cxx b/src/SMESH/SMESH_ProxyMesh.cxx index a4e4f5998..c8dcec11c 100644 --- a/src/SMESH/SMESH_ProxyMesh.cxx +++ b/src/SMESH/SMESH_ProxyMesh.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // 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 @@ -24,6 +24,8 @@ #include "SMDS_IteratorOnIterators.hxx" #include "SMDS_SetIterator.hxx" +#include "SMESHDS_Mesh.hxx" +#include "SMESH_Mesh.hxx" #include "SMESH_MesherHelper.hxx" #include @@ -36,16 +38,28 @@ */ //================================================================================ -SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0) +SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0), _subContainer(0) { } +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ + +SMESH_ProxyMesh::SMESH_ProxyMesh(const SMESH_Mesh& mesh) + : _mesh( &mesh ), + _subContainer( new SubMesh( GetMeshDS() ) ) +{ +} + //================================================================================ /*! * \brief Make a proxy mesh from components. Components become empty */ //================================================================================ -SMESH_ProxyMesh::SMESH_ProxyMesh(vector& components): +SMESH_ProxyMesh::SMESH_ProxyMesh(std::vector& components): _mesh(0) { if ( components.empty() ) return; @@ -57,7 +71,7 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector& components): takeTmpElemsInMesh( m ); - if ( !_mesh ) _mesh = m->_mesh; + if ( !_mesh && m->_mesh ) setMesh( *( m->_mesh )); if ( _allowedTypes.empty() ) _allowedTypes = m->_allowedTypes; if ( _subMeshes.size() < m->_subMeshes.size() ) @@ -68,8 +82,8 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector& components): if ( _subMeshes[j] ) { // unite 2 sub-meshes - set< const SMDS_MeshElement * > elems( _subMeshes[j]->_elements.begin(), - _subMeshes[j]->_elements.end()); + std::set< const SMDS_MeshElement * > elems( _subMeshes[j]->_elements.begin(), + _subMeshes[j]->_elements.end()); elems.insert( m->_subMeshes[j]->_elements.begin(), m->_subMeshes[j]->_elements.end()); _subMeshes[j]->_elements.assign( elems.begin(), elems.end() ); @@ -93,22 +107,37 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector& components): //================================================================================ /*! - * \brief Destructor deletes proxy submeshes and tmp elemens + * \brief Destructor deletes proxy submeshes and tmp elements */ //================================================================================ SMESH_ProxyMesh::~SMESH_ProxyMesh() { - for ( unsigned i = 0; i < _subMeshes.size(); ++i ) + delete _subContainer; + + for ( size_t i = 0; i < _subMeshes.size(); ++i ) delete _subMeshes[i]; _subMeshes.clear(); - set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.begin(); + std::set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.begin(); for ( ; i != _elemsInMesh.end(); ++i ) GetMeshDS()->RemoveFreeElement( *i, 0 ); _elemsInMesh.clear(); } +//================================================================================ +/*! + * \brief Set mesh + */ +//================================================================================ + +void SMESH_ProxyMesh::setMesh(const SMESH_Mesh& mesh) +{ + _mesh = &mesh; + if ( _mesh ) + _subContainer = new SubMesh( GetMeshDS() ); +} + //================================================================================ /*! * \brief Returns index of a shape @@ -120,6 +149,19 @@ int SMESH_ProxyMesh::shapeIndex(const TopoDS_Shape& shape) const return ( shape.IsNull() || !_mesh->HasShapeToMesh() ? 0 : GetMeshDS()->ShapeToIndex(shape)); } +//================================================================================ +/*! + * \brief Create a SubMesh + * \param [ino] index - shape index + * \return SubMesh* - new SubMesh + */ +//================================================================================ + +SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::newSubmesh(int index) const +{ + return new SubMesh( GetMeshDS(),index ); +} + //================================================================================ /*! * \brief Returns the submesh of a shape; it can be a proxy sub-mesh @@ -130,7 +172,7 @@ const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const TopoDS_Shape& shape) co { const SMESHDS_SubMesh* sm = 0; - int i = shapeIndex(shape); + size_t i = shapeIndex(shape); if ( i < _subMeshes.size() ) sm = _subMeshes[i]; if ( !sm ) @@ -148,7 +190,7 @@ const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const TopoDS_Shape& shape) co const SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::GetProxySubMesh(const TopoDS_Shape& shape) const { - int i = shapeIndex(shape); + size_t i = shapeIndex(shape); return i < _subMeshes.size() ? _subMeshes[i] : 0; } @@ -178,6 +220,21 @@ const SMDS_MeshNode* SMESH_ProxyMesh::GetProxyNode( const SMDS_MeshNode* node ) return proxy; } +//================================================================================ +/*! + * \brief Returns number of proxy sub-meshes + */ +//================================================================================ + +int SMESH_ProxyMesh::NbProxySubMeshes() const +{ + int nb = 0; + for ( size_t i = 0; i < _subMeshes.size(); ++i ) + nb += bool( _subMeshes[i] ); + + return nb; +} + namespace { //================================================================================ @@ -188,12 +245,12 @@ namespace class TFilteringIterator : public SMDS_ElemIterator { - SMDS_ElemIteratorPtr _iter; - const SMDS_MeshElement * _curElem; - vector< SMDSAbs_EntityType> _okTypes; + SMDS_ElemIteratorPtr _iter; + const SMDS_MeshElement * _curElem; + std::vector< SMDSAbs_EntityType> _okTypes; public: - TFilteringIterator( const vector< SMDSAbs_EntityType>& okTypes, - const SMDS_ElemIteratorPtr& elemIterator) + TFilteringIterator( const std::vector< SMDSAbs_EntityType>& okTypes, + const SMDS_ElemIteratorPtr& elemIterator) :_iter(elemIterator), _curElem(0), _okTypes(okTypes) { next(); @@ -228,15 +285,15 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces(const TopoDS_Shape& shape) const if ( !_mesh->HasShapeToMesh() ) return SMDS_ElemIteratorPtr(); - _subContainer.RemoveAllSubmeshes(); + _subContainer->RemoveAllSubmeshes(); TopTools_IndexedMapOfShape FF; TopExp::MapShapes( shape, TopAbs_FACE, FF ); for ( int i = 1; i <= FF.Extent(); ++i ) if ( const SMESHDS_SubMesh* sm = GetSubMesh( FF(i))) - _subContainer.AddSubMesh( sm ); + _subContainer->AddSubMesh( sm ); - return _subContainer.SMESHDS_SubMesh::GetElements(); + return _subContainer->SMESHDS_SubMesh::GetElements(); } //================================================================================ @@ -251,27 +308,27 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces() const if ( _mesh->HasShapeToMesh() ) return SMDS_ElemIteratorPtr(); - _subContainer.RemoveAllSubmeshes(); + _subContainer->RemoveAllSubmeshes(); for ( unsigned i = 0; i < _subMeshes.size(); ++i ) if ( _subMeshes[i] ) - _subContainer.AddSubMesh( _subMeshes[i] ); + _subContainer->AddSubMesh( _subMeshes[i] ); - if ( _subContainer.NbSubMeshes() == 0 ) // no elements substituted + if ( _subContainer->NbSubMeshes() == 0 ) // no elements substituted return GetMeshDS()->elementsIterator(SMDSAbs_Face); // if _allowedTypes is empty, only elements from _subMeshes are returned,... - SMDS_ElemIteratorPtr proxyIter = _subContainer.SMESHDS_SubMesh::GetElements(); + SMDS_ElemIteratorPtr proxyIter = _subContainer->SMESHDS_SubMesh::GetElements(); if ( _allowedTypes.empty() || NbFaces() == _mesh->NbFaces() ) return proxyIter; // ... else elements filtered using allowedTypes are additionally returned SMDS_ElemIteratorPtr facesIter = GetMeshDS()->elementsIterator(SMDSAbs_Face); SMDS_ElemIteratorPtr filterIter( new TFilteringIterator( _allowedTypes, facesIter )); - vector< SMDS_ElemIteratorPtr > iters(2); + std::vector< SMDS_ElemIteratorPtr > iters(2); iters[0] = proxyIter; iters[1] = filterIter; - typedef vector< SMDS_ElemIteratorPtr > TElemIterVector; + typedef std::vector< SMDS_ElemIteratorPtr > TElemIterVector; typedef SMDS_IteratorOnIterators TItersIter; return SMDS_ElemIteratorPtr( new TItersIter( iters )); } @@ -329,7 +386,7 @@ SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::getProxySubMesh(int index) if ( int(_subMeshes.size()) <= index ) _subMeshes.resize( index+1, 0 ); if ( !_subMeshes[index] ) - _subMeshes[index] = new SubMesh( index ); + _subMeshes[index] = newSubmesh( index ); return _subMeshes[index]; } @@ -408,24 +465,24 @@ void SMESH_ProxyMesh::takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh ) //================================================================================ /*! - * \brief Removes tmp faces from the _mesh + * \brief Removes tmp elements from the _mesh */ //================================================================================ -void SMESH_ProxyMesh::removeTmpElement( const SMDS_MeshElement* face ) +void SMESH_ProxyMesh::removeTmpElement( const SMDS_MeshElement* elem ) { - if ( face && face->GetID() > 0 ) + if ( elem && elem->GetID() > 0 ) { - set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.find( face ); + std::set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.find( elem ); if ( i != _elemsInMesh.end() ) { - GetMeshDS()->RemoveFreeElement( face, 0 ); + GetMeshDS()->RemoveFreeElement( elem, 0 ); _elemsInMesh.erase( i ); } } else { - delete face; + delete elem; } } @@ -435,9 +492,9 @@ void SMESH_ProxyMesh::removeTmpElement( const SMDS_MeshElement* face ) */ //================================================================================ -void SMESH_ProxyMesh::storeTmpElement( const SMDS_MeshElement* face ) +void SMESH_ProxyMesh::storeTmpElement( const SMDS_MeshElement* elem ) { - _elemsInMesh.insert( face ); + _elemsInMesh.insert( elem ); } //================================================================================ @@ -453,7 +510,7 @@ void SMESH_ProxyMesh::setNode2Node(const SMDS_MeshNode* srcNode, SubMesh* sm = const_cast( subMesh ); if ( !subMesh->_n2n ) sm->_n2n = new TN2NMap; - sm->_n2n->insert( make_pair( srcNode, proxyNode )); + sm->_n2n->insert( std::make_pair( srcNode, proxyNode )); } //================================================================================ @@ -467,6 +524,18 @@ bool SMESH_ProxyMesh::IsTemporary(const SMDS_MeshElement* elem ) const return ( elem->GetID() < 1 ) || _elemsInMesh.count( elem ); } +//================================================================================ +/*! + * \brief SubMesh Constructor + */ +//================================================================================ + +SMESH_ProxyMesh::SubMesh::SubMesh( const SMDS_Mesh* mesh, int index ) + : SMESHDS_SubMesh( static_cast( mesh ), index ), + _n2n(0) +{ +} + //================================================================================ /*! * \brief Return a proxy node or an input node @@ -499,18 +568,20 @@ void SMESH_ProxyMesh::SubMesh::Clear() //================================================================================ /*! - * \brief Return number of elements in a proxy submesh + * \brief Return number of elements in a proxy sub-mesh. The method is meaningful + * for a sub-mesh containing tmp faces. */ //================================================================================ int SMESH_ProxyMesh::SubMesh::NbElements() const { - return _elements.size(); + return _uvPtStructVec.empty() ? _elements.size() : _uvPtStructVec.size() - 1; } //================================================================================ /*! - * \brief Return elements of a proxy submesh + * \brief Return elements of a proxy sub-mesh. The method is meaningful + * for a sub-mesh containing tmp faces. */ //================================================================================ @@ -520,6 +591,39 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::SubMesh::GetElements() const ( new SMDS_ElementVectorIterator( _elements.begin(), _elements.end() )); } +//================================================================================ +/*! + * \brief Return number of nodes in a proxy sub-mesh. The method is meaningful + * for a sub-mesh containing nodes of 2D viscous layer. + */ +//================================================================================ + +int SMESH_ProxyMesh::SubMesh::NbNodes() const +{ + return _uvPtStructVec.size(); +} + +//================================================================================ +/*! + * \brief Return nodes of a proxy sub-mesh. The method is meaningful + * for a sub-mesh containing nodes of 2D viscous layer. + */ +//================================================================================ + +SMDS_NodeIteratorPtr SMESH_ProxyMesh::SubMesh::GetNodes() const +{ + if ( !_uvPtStructVec.empty() ) + return SMDS_NodeIteratorPtr ( new SMDS_SetIterator + < SMDS_pNode, + UVPtStructVec::const_iterator, + UVPtStruct::NodeAccessor > + ( _uvPtStructVec.begin(), _uvPtStructVec.end() )); + + return SMDS_NodeIteratorPtr + ( new SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pElement >::const_iterator> + ( _elements.begin(), _elements.end() )); +} + //================================================================================ /*! * \brief Store an element