X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElement.cxx;h=13ee2d9b3ebc47af37e6e8332e0cb4eb071af7f5;hp=e6f84076bf2f71cf7f24deac1b7a53649e589d57;hb=38a77c4a9810f4715212368ac53315689ba9150f;hpb=c63ee099ad2b149bd70136839c973e8910137bc5 diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index e6f84076b..13ee2d9b3 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -1,24 +1,27 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2015 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 : implementaion of Salome mesh data structure +// #ifdef _MSC_VER #pragma warning(disable:4786) #endif @@ -32,19 +35,33 @@ using namespace std; -SMDS_MeshElement::SMDS_MeshElement(int ID):myID(ID) +SMDS_MeshElement::SMDS_MeshElement(int ID) +{ + init(ID); +} + +SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId) { + init(id, meshId, shapeId); +} + +void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId ) +{ + myID = id; + myMeshId = meshId; + myShapeId = shapeId; + myIdInShape = -1; } void SMDS_MeshElement::Print(ostream & OS) const { - OS << "dump of mesh element" << endl; + OS << "dump of mesh element" << endl; } ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) { - ME->Print(OS); - return OS; + ME->Print(OS); + return OS; } /////////////////////////////////////////////////////////////////////////////// @@ -53,7 +70,7 @@ ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) /////////////////////////////////////////////////////////////////////////////// SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const { - return elementsIterator(SMDSAbs_Node); + return elementsIterator(SMDSAbs_Node); } /////////////////////////////////////////////////////////////////////////////// @@ -62,7 +79,7 @@ SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const /////////////////////////////////////////////////////////////////////////////// SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const { - return elementsIterator(SMDSAbs_Edge); + return elementsIterator(SMDSAbs_Edge); } /////////////////////////////////////////////////////////////////////////////// @@ -71,7 +88,7 @@ SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const /////////////////////////////////////////////////////////////////////////////// SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const { - return elementsIterator(SMDSAbs_Face); + return elementsIterator(SMDSAbs_Face); } /////////////////////////////////////////////////////////////////////////////// @@ -79,14 +96,14 @@ SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const /////////////////////////////////////////////////////////////////////////////// int SMDS_MeshElement::NbNodes() const { - int nbnodes=0; - SMDS_ElemIteratorPtr it=nodesIterator(); - while(it->more()) - { - it->next(); - nbnodes++; - } - return nbnodes; + int nbnodes=0; + SMDS_ElemIteratorPtr it=nodesIterator(); + while(it->more()) + { + it->next(); + nbnodes++; + } + return nbnodes; } /////////////////////////////////////////////////////////////////////////////// @@ -94,14 +111,14 @@ int SMDS_MeshElement::NbNodes() const /////////////////////////////////////////////////////////////////////////////// int SMDS_MeshElement::NbEdges() const { - int nbedges=0; - SMDS_ElemIteratorPtr it=edgesIterator(); - while(it->more()) - { - it->next(); - nbedges++; - } - return nbedges; + int nbedges=0; + SMDS_ElemIteratorPtr it=edgesIterator(); + while(it->more()) + { + it->next(); + nbedges++; + } + return nbedges; } /////////////////////////////////////////////////////////////////////////////// @@ -109,14 +126,14 @@ int SMDS_MeshElement::NbEdges() const /////////////////////////////////////////////////////////////////////////////// int SMDS_MeshElement::NbFaces() const { - int nbfaces=0; - SMDS_ElemIteratorPtr it=facesIterator(); - while(it->more()) - { - it->next(); - nbfaces++; - } - return nbfaces; + int nbfaces=0; + SMDS_ElemIteratorPtr it=facesIterator(); + while(it->more()) + { + it->next(); + nbfaces++; + } + return nbfaces; } /////////////////////////////////////////////////////////////////////////////// @@ -140,56 +157,98 @@ class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator const SMDS_MeshElement* next() { myMore=false; - return myElement; - } + 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); - } + +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 +//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const { - return myID; + return nodeIterator(); +} + +//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const +{ + return nodeIterator(); +} + +namespace +{ + //======================================================================= + //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(); } + }; +} + +SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const +{ + return SMDS_ElemIteratorPtr + ( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() )); +} + +SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const +{ + return SMDS_NodeIteratorPtr + ( new _MyNodeIteratorFromElemIterator( nodesIterator() )); } 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); + 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_Edge: + return static_cast(e1) < + static_cast(e2); - case SMDSAbs_Face: - 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); + case SMDSAbs_Volume: + return static_cast(e1) < + static_cast(e2); - default : MESSAGE("Internal Error"); - } + default : MESSAGE("Internal Error"); + } return false; } @@ -200,12 +259,13 @@ bool SMDS_MeshElement::IsValidIndex(const int ind) const const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const { - SMDS_ElemIteratorPtr it = nodesIterator(); - int i = 0, index = WrappedIndex( ind ); - while ( index != i++ ) - it->next(); - if ( it->more() ) - return static_cast (it->next()); + 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; } @@ -219,6 +279,17 @@ bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const return false; } +//================================================================================ +/*! + * \brief Return number of nodes excluding medium ones + */ +//================================================================================ + +int SMDS_MeshElement::NbCornerNodes() const +{ + return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes(); +} + //================================================================================ /*! * \brief Check if a node belongs to the element