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=701e6fe97ce20051f79820ed74110609341e86a1;hb=ad3cb4c93852dbc834d7075c087bbc749197454b;hpb=00c069f8d414099a12268c42d58c6cfae9d1bff9 diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index 701e6fe97..48221c7c6 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -1,192 +1,216 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 +// +// 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" -SMDS_MeshElement::SMDS_MeshElement(int ID):myID(ID) +//================================================================================ +/*! + * \brief Constructor of a non-used element + */ +//================================================================================ + +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 +{ + return !( GetNodeIndex( node ) < NbCornerNodes() ); +} + +//================================================================================ +/*! + * \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 +{ + return ( ind>-1 && ind= NbCornerNodes() ) return ind % NbCornerNodes(); + return ind; } - -ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) -{ - ME->Print(OS); - return OS; -} - -/////////////////////////////////////////////////////////////////////////////// -/// Create an iterator which iterate on nodes owned by the element. -/// This method call elementsIterator(). -/////////////////////////////////////////////////////////////////////////////// -SMDS_Iterator * SMDS_MeshElement::nodesIterator() const -{ - return elementsIterator(SMDSAbs_Node); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Create an iterator which iterate on edges linked with or owned by the element. -/// This method call elementsIterator(). -/////////////////////////////////////////////////////////////////////////////// -SMDS_Iterator * SMDS_MeshElement::edgesIterator() const -{ - return elementsIterator(SMDSAbs_Edge); -} - -/////////////////////////////////////////////////////////////////////////////// -/// Create an iterator which iterate on faces linked with or owned by the element. -/// This method call elementsIterator(). -/////////////////////////////////////////////////////////////////////////////// -SMDS_Iterator * SMDS_MeshElement::facesIterator() const -{ - return elementsIterator(SMDSAbs_Face); -} - -/////////////////////////////////////////////////////////////////////////////// -///Return The number of nodes owned by the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbNodes() const -{ - int nbnodes=0; - SMDS_Iterator * it=nodesIterator(); - while(it->more()) - { - it->next(); - nbnodes++; - } - delete it; - return nbnodes; -} - -/////////////////////////////////////////////////////////////////////////////// -///Return the number of edges owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbEdges() const -{ - int nbedges=0; - SMDS_Iterator * it=edgesIterator(); - while(it->more()) - { - it->next(); - nbedges++; - } - delete it; - return nbedges; -} - -/////////////////////////////////////////////////////////////////////////////// -///Return the number of faces owned by or linked with the current element -/////////////////////////////////////////////////////////////////////////////// -int SMDS_MeshElement::NbFaces() const -{ - int nbfaces=0; - SMDS_Iterator * it=facesIterator(); - while(it->more()) - { - it->next(); - nbfaces++; - } - delete it; - return nbfaces; -} - -/////////////////////////////////////////////////////////////////////////////// -///Create and iterator which iterate on elements linked with the current element. -///The iterator must be free by the caller (call delete myIterator). -///@param type The of elements on which you want to iterate -///@return An iterator, that you must free when you no longer need it -/////////////////////////////////////////////////////////////////////////////// -SMDS_Iterator * 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 */ - class MyIterator:public SMDS_Iterator - { - const SMDS_MeshElement * myElement; - bool myMore; - public: - MyIterator(const SMDS_MeshElement * element): - myElement(element),myMore(true) - { - } - - bool more() - { - return myMore; - } - - const SMDS_MeshElement* next() - { - myMore=false; - return myElement; - } - }; - - if(type==GetType()) return new MyIterator(this); - else - { - MESSAGE("Iterator not implemented"); - return NULL; - } -} - -/////////////////////////////////////////////////////////////////////////////// -///Return the ID of the element -/////////////////////////////////////////////////////////////////////////////// + +//================================================================================ +/*! + * \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 +{ + SMDS_ElemIteratorPtr nIt = nodesIterator(); + for ( int i = 0; nIt->more(); ++i ) + if ( nIt->next() == node ) + return i; + return -1; +} + +//================================================================================ +/*! + * \brief Return ID of an element + */ +//================================================================================ + int SMDS_MeshElement::GetID() const { - return myID; + return myHolder ? myHolder->GetID( this ) : -1; } -bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) +//================================================================================ +/*! + * \brief Set ID of a shape this element was generated on + */ +//================================================================================ + +void SMDS_MeshElement::setShapeID( const int shapeID ) const { - if(e1.GetType()!=e2.GetType()) return false; - switch(e1.GetType()) - { - case SMDSAbs_Node: - return static_cast(e1) < - static_cast(e2); + const_cast( myHolder )->SetShapeID( this, shapeID ); +} - case SMDSAbs_Edge: - return static_cast(e1) < - static_cast(e2); +//================================================================================ +/*! + * \brief Return ID of a shape this element was generated on + */ +//================================================================================ - case SMDSAbs_Face: - return static_cast(e1) < - static_cast(e2); +int SMDS_MeshElement::GetShapeID() const +{ + return myHolder->GetShapeID( this ); +} - case SMDSAbs_Volume: - return static_cast(e1) < - static_cast(e2); +//================================================================================ +/*! + * \brief Return VTK ID of this element + */ +//================================================================================ - default : MESSAGE("Internal Error"); - } +int SMDS_MeshElement::GetVtkID() const +{ + return myHolder->GetVtkID( this ); +} + +//================================================================================ +/*! + * \brief Mark this element + */ +//================================================================================ + +void SMDS_MeshElement::setIsMarked( bool is ) const +{ + const_cast( myHolder )->SetIsMarked( this, is ); +} + +//================================================================================ +/*! + * \brief Check if this element is marked + */ +//================================================================================ + +bool SMDS_MeshElement::isMarked() const +{ + return myHolder->IsMarked( this ); +} + +//================================================================================ +/*! + * \brief Store VTK ID + */ +//================================================================================ + +void SMDS_MeshElement::setVtkID( const int vtkID ) +{ + myHolder->SetVTKID( this, vtkID ); +} + +//================================================================================ +/*! + * \brief Return the mesh this element belongs to + */ +//================================================================================ + +SMDS_Mesh* SMDS_MeshElement::GetMesh() const +{ + return const_cast( myHolder )->GetMesh(); +} + +//================================================================================ +/*! + * \brief Return a SMDS_UnstructuredGrid + */ +//================================================================================ + +SMDS_UnstructuredGrid* SMDS_MeshElement::getGrid() const +{ + return const_cast( myHolder )->GetMesh()->GetGrid(); +} + +//================================================================================ +/*! + * \brief Print self + */ +//================================================================================ + +void SMDS_MeshElement::Print(ostream & OS) const +{ + OS << "dump of mesh element" << endl; +} + +ostream & operator <<(ostream & OS, const SMDS_MeshElement * e) +{ + e->Print(OS); + return OS; }