X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElement.cxx;h=42ce33bfaf08f91a5b48f6a7976a519c907d9d82;hp=e6f84076bf2f71cf7f24deac1b7a53649e589d57;hb=refs%2Ftags%2FV9_7_0b1;hpb=c63ee099ad2b149bd70136839c973e8910137bc5 diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index e6f84076b..42ce33bfa 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -1,237 +1,216 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2021 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 +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// SMESH SMDS : implementation of Salome mesh data structure +// #ifdef _MSC_VER #pragma warning(disable:4786) #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):myID(ID) +SMDS_MeshElement::SMDS_MeshElement(): myHolder(0) { } -void SMDS_MeshElement::Print(ostream & OS) const +//================================================================================ +/*! + * \brief Check if a node is a medium node of a quadratic cell + */ +//================================================================================ + +bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const { - OS << "dump of mesh element" << endl; + return !( GetNodeIndex( node ) < NbCornerNodes() ); } -ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) +//================================================================================ +/*! + * \brief Return true if index of node is valid (0 <= ind < NbNodes()) + * \param ind - node index + * \retval bool - index check result + */ +//================================================================================ + +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 + +//================================================================================ +/*! + * \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 + */ +//================================================================================ + +int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const { - return elementsIterator(SMDSAbs_Face); + SMDS_ElemIteratorPtr nIt = nodesIterator(); + for ( int i = 0; nIt->more(); ++i ) + if ( nIt->next() == node ) + return i; + return -1; } -/////////////////////////////////////////////////////////////////////////////// -///Return The number of nodes owned by the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbNodes() const +//================================================================================ +/*! + * \brief Return ID of an element + */ +//================================================================================ + +smIdType SMDS_MeshElement::GetID() const { - int nbnodes=0; - SMDS_ElemIteratorPtr it=nodesIterator(); - while(it->more()) - { - it->next(); - nbnodes++; - } - return nbnodes; + return myHolder ? myHolder->GetID( this ) : -1; } -/////////////////////////////////////////////////////////////////////////////// -///Return the number of edges owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbEdges() const +//================================================================================ +/*! + * \brief Set ID of a shape this element was generated on + */ +//================================================================================ + +void SMDS_MeshElement::setShapeID( const int shapeID ) const { - int nbedges=0; - SMDS_ElemIteratorPtr it=edgesIterator(); - while(it->more()) - { - it->next(); - nbedges++; - } - return nbedges; + const_cast( myHolder )->SetShapeID( this, shapeID ); } -/////////////////////////////////////////////////////////////////////////////// -///Return the number of faces owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbFaces() const +//================================================================================ +/*! + * \brief Return ID of a shape this element was generated on + */ +//================================================================================ + +int SMDS_MeshElement::GetShapeID() const { - int nbfaces=0; - SMDS_ElemIteratorPtr it=facesIterator(); - while(it->more()) - { - it->next(); - nbfaces++; - } - return nbfaces; + return myHolder->GetShapeID( this ); } -/////////////////////////////////////////////////////////////////////////////// -///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 +//================================================================================ +/*! + * \brief Return VTK ID of this element + */ +//================================================================================ + +vtkIdType SMDS_MeshElement::GetVtkID() const { - const SMDS_MeshElement * myElement; - bool myMore; - public: - SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element): - myElement(element),myMore(true) {} + return myHolder->GetVtkID( this ); +} - bool more() - { - return myMore; - } +//================================================================================ +/*! + * \brief Mark this element + */ +//================================================================================ - 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); - } -} - -/////////////////////////////////////////////////////////////////////////////// -///Return the ID of the element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::GetID() const -{ - return myID; -} - -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; +void SMDS_MeshElement::setIsMarked( bool is ) const +{ + const_cast( myHolder )->SetIsMarked( this, is ); } -bool SMDS_MeshElement::IsValidIndex(const int ind) const +//================================================================================ +/*! + * \brief Check if this element is marked + */ +//================================================================================ + +bool SMDS_MeshElement::isMarked() const { - return ( ind>-1 && indIsMarked( this ); } -const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const +//================================================================================ +/*! + * \brief Store VTK ID + */ +//================================================================================ + +void SMDS_MeshElement::setVtkID( const vtkIdType vtkID ) { - SMDS_ElemIteratorPtr it = nodesIterator(); - int i = 0, index = WrappedIndex( ind ); - while ( index != i++ ) - it->next(); - if ( it->more() ) - return static_cast (it->next()); - return 0; + myHolder->SetVTKID( this, vtkID ); } -bool SMDS_MeshElement::IsQuadratic() const +//================================================================================ +/*! + * \brief Return the mesh this element belongs to + */ +//================================================================================ + +SMDS_Mesh* SMDS_MeshElement::GetMesh() const { - return false; + return const_cast( myHolder )->GetMesh(); } -bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const +//================================================================================ +/*! + * \brief Return a SMDS_UnstructuredGrid + */ +//================================================================================ + +SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const { - return false; + 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; }