X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElement.cxx;h=48221c7c6861dda72d67072bf44434508399b404;hp=31119a8eda8abc03dfd6cb094b9c797cf14bb73c;hb=4c16067d4281f56bd07d3f92fb63fff9c0c1d169;hpb=88141f757b048eaa5aae0be49faaf274448bbcaf diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index 31119a8ed..48221c7c6 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -27,282 +27,190 @@ #endif #include "SMDS_MeshElement.hxx" -#include "SMDS_MeshNode.hxx" -#include "SMDS_MeshEdge.hxx" -#include "SMDS_MeshFace.hxx" -#include "SMDS_MeshVolume.hxx" + +#include "SMDS_Mesh.hxx" +#include "SMDS_ElementFactory.hxx" + #include "utilities.h" -using namespace std; +//================================================================================ +/*! + * \brief Constructor of a non-used element + */ +//================================================================================ -SMDS_MeshElement::SMDS_MeshElement(int ID) +SMDS_MeshElement::SMDS_MeshElement(): myHolder(0) { - init(ID); } -SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId) -{ - init(id, meshId, shapeId); -} +//================================================================================ +/*! + * \brief Check if a node is a medium node of a quadratic cell + */ +//================================================================================ -void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId ) +bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const { - myID = id; - myMeshId = meshId; - myShapeId = shapeId; - myIdInShape = -1; + return !( GetNodeIndex( node ) < NbCornerNodes() ); } -void SMDS_MeshElement::Print(ostream & OS) const -{ - OS << "dump of mesh element" << endl; -} +//================================================================================ +/*! + * \brief Return true if index of node is valid (0 <= ind < NbNodes()) + * \param ind - node index + * \retval bool - index check result + */ +//================================================================================ -ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) +bool SMDS_MeshElement::IsValidIndex(const int ind) const { - ME->Print(OS); - return OS; + return ( ind>-1 && ind= NbCornerNodes() ) return ind % NbCornerNodes(); + return ind; } -/////////////////////////////////////////////////////////////////////////////// -/// Create an iterator which iterate on faces linked with or owned by the element. -/// This method call elementsIterator(). -/////////////////////////////////////////////////////////////////////////////// -SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const -{ - return elementsIterator(SMDSAbs_Face); -} +//================================================================================ +/*! + * \brief Check if a node belongs to the element + * \param node - the node to check + * \retval int - node index within the element, -1 if not found + */ +//================================================================================ -/////////////////////////////////////////////////////////////////////////////// -///Return The number of nodes owned by the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbNodes() const +int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const { - int nbnodes=0; - SMDS_ElemIteratorPtr it=nodesIterator(); - while(it->more()) - { - it->next(); - nbnodes++; - } - return nbnodes; + SMDS_ElemIteratorPtr nIt = nodesIterator(); + for ( int i = 0; nIt->more(); ++i ) + if ( nIt->next() == node ) + return i; + return -1; } -/////////////////////////////////////////////////////////////////////////////// -///Return the number of edges owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbEdges() const -{ - int nbedges=0; - SMDS_ElemIteratorPtr it=edgesIterator(); - while(it->more()) - { - it->next(); - nbedges++; - } - return nbedges; -} +//================================================================================ +/*! + * \brief Return ID of an element + */ +//================================================================================ -/////////////////////////////////////////////////////////////////////////////// -///Return the number of faces owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbFaces() const +int SMDS_MeshElement::GetID() const { - int nbfaces=0; - SMDS_ElemIteratorPtr it=facesIterator(); - while(it->more()) - { - it->next(); - nbfaces++; - } - return nbfaces; + return myHolder ? myHolder->GetID( this ) : -1; } -/////////////////////////////////////////////////////////////////////////////// -///Create an iterator which iterate on elements linked with the current element. -///@param type The of elements on which you want to iterate -///@return A smart pointer to iterator, you are not to take care of freeing memory -/////////////////////////////////////////////////////////////////////////////// -class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator -{ - const SMDS_MeshElement * myElement; - bool myMore; -public: - SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element): - myElement(element),myMore(true) {} - - bool more() - { - return myMore; - } - - const SMDS_MeshElement* next() - { - myMore=false; - return myElement; - } -}; - -SMDS_ElemIteratorPtr -SMDS_MeshElement::elementsIterator(SMDSAbs_ElementType type) const -{ - /** @todo Check that iterator in the child classes return elements - in the same order for each different implementation (i.e: SMDS_VolumeOfNodes - and SMDS_VolumeOfFaces */ - if(type==GetType()) - return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this)); - else - { - MESSAGE("Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); - } -} +//================================================================================ +/*! + * \brief Set ID of a shape this element was generated on + */ +//================================================================================ -//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes -SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const +void SMDS_MeshElement::setShapeID( const int shapeID ) const { - return nodeIterator(); + const_cast( myHolder )->SetShapeID( this, shapeID ); } -//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes -SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const -{ - return nodeIterator(); -} +//================================================================================ +/*! + * \brief Return ID of a shape this element was generated on + */ +//================================================================================ -namespace +int SMDS_MeshElement::GetShapeID() const { - //======================================================================= - //class : _MyNodeIteratorFromElemIterator - //======================================================================= - class _MyNodeIteratorFromElemIterator : public SMDS_NodeIterator - { - SMDS_ElemIteratorPtr myItr; - public: - _MyNodeIteratorFromElemIterator(SMDS_ElemIteratorPtr elemItr):myItr( elemItr ) {} - bool more() { return myItr->more(); } - const SMDS_MeshNode* next() { return static_cast< const SMDS_MeshNode*>( myItr->next() ); } - }; - //======================================================================= - //class : _MyElemIteratorFromNodeIterator - //======================================================================= - class _MyElemIteratorFromNodeIterator : public SMDS_ElemIterator - { - SMDS_NodeIteratorPtr myItr; - public: - _MyElemIteratorFromNodeIterator(SMDS_NodeIteratorPtr nodeItr): myItr( nodeItr ) {} - bool more() { return myItr->more(); } - const SMDS_MeshElement* next() { return myItr->next(); } - }; + return myHolder->GetShapeID( this ); } -SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const -{ - return SMDS_ElemIteratorPtr - ( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() )); -} +//================================================================================ +/*! + * \brief Return VTK ID of this element + */ +//================================================================================ -SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const +int SMDS_MeshElement::GetVtkID() const { - return SMDS_NodeIteratorPtr - ( new _MyNodeIteratorFromElemIterator( nodesIterator() )); + return myHolder->GetVtkID( this ); } -bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) -{ - if(e1.GetType()!=e2.GetType()) return false; - switch(e1.GetType()) - { - case SMDSAbs_Node: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Edge: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Face: - return static_cast(e1) < - static_cast(e2); - - case SMDSAbs_Volume: - return static_cast(e1) < - static_cast(e2); - - default : MESSAGE("Internal Error"); - } - return false; -} +//================================================================================ +/*! + * \brief Mark this element + */ +//================================================================================ -bool SMDS_MeshElement::IsValidIndex(const int ind) const +void SMDS_MeshElement::setIsMarked( bool is ) const { - return ( ind>-1 && ind( myHolder )->SetIsMarked( this, is ); } -const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const +//================================================================================ +/*! + * \brief Check if this element is marked + */ +//================================================================================ + +bool SMDS_MeshElement::isMarked() const { - if ( ind >= 0 ) { - SMDS_ElemIteratorPtr it = nodesIterator(); - for ( int i = 0; i < ind; ++i ) - it->next(); - if ( it->more() ) - return static_cast (it->next()); - } - return 0; + return myHolder->IsMarked( this ); } -bool SMDS_MeshElement::IsQuadratic() const +//================================================================================ +/*! + * \brief Store VTK ID + */ +//================================================================================ + +void SMDS_MeshElement::setVtkID( const int vtkID ) { - return false; + myHolder->SetVTKID( this, vtkID ); } -bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const +//================================================================================ +/*! + * \brief Return the mesh this element belongs to + */ +//================================================================================ + +SMDS_Mesh* SMDS_MeshElement::GetMesh() const { - return false; + return const_cast( myHolder )->GetMesh(); } //================================================================================ /*! - * \brief Return number of nodes excluding medium ones + * \brief Return a SMDS_UnstructuredGrid */ //================================================================================ -int SMDS_MeshElement::NbCornerNodes() const +SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const { - return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes(); + return const_cast( myHolder )->GetMesh()->GetGrid(); } //================================================================================ /*! - * \brief Check if a node belongs to the element - * \param node - the node to check - * \retval int - node index within the element, -1 if not found + * \brief Print self */ //================================================================================ -int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const +void SMDS_MeshElement::Print(ostream & OS) const { - SMDS_ElemIteratorPtr nIt = nodesIterator(); - for ( int i = 0; nIt->more(); ++i ) - if ( nIt->next() == node ) - return i; - return -1; + OS << "dump of mesh element" << endl; +} + +ostream & operator <<(ostream & OS, const SMDS_MeshElement * e) +{ + e->Print(OS); + return OS; }