X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElement.cxx;h=708f5c1a8845e2ac32ea5e750182da6c0a9c282c;hp=10432de1d96eb973e7a042d287be346f50e3b338;hb=24d5088297c103c52c52e47df887532bc650038b;hpb=4791f5b30ea7a9c1247aa551750dc71cb83b99aa diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index 10432de1d..708f5c1a8 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -1,198 +1,308 @@ -// SMESH SMDS : implementaion of Salome mesh data structure +// Copyright (C) 2007-2013 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. // -// 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 +// 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 // -// File : SMDS_MeshElement.cxx -// Author : Jean-Michel BOULCOURT -// Module : SMESH -using namespace std; -#include "SMDS_MeshElement.ixx" +// SMESH SMDS : implementaion of Salome mesh data structure +// +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif -//======================================================================= -//function : SMDS_MeshElement -//purpose : -//======================================================================= +#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMDS_MeshEdge.hxx" +#include "SMDS_MeshFace.hxx" +#include "SMDS_MeshVolume.hxx" +#include "utilities.h" -SMDS_MeshElement::SMDS_MeshElement(const Standard_Integer ID, const Standard_Integer nb,const SMDSAbs_ElementType Type) - :myID(ID),myNbNodes(nb),myType(Type) +using namespace std; + +SMDS_MeshElement::SMDS_MeshElement(int ID) { + init(ID); } -//======================================================================= -//function : GetConnections -//purpose : -//======================================================================= - -Standard_Address SMDS_MeshElement::GetConnections() const +SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId) { - return (Standard_Address)&myID; + init(id, meshId, shapeId); } - -//======================================================================= -//function : GetConnection -//purpose : -//======================================================================= - -Standard_Integer SMDS_MeshElement::GetConnection(const Standard_Integer rank) const +void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId ) { - return myID; + myID = id; + myMeshId = meshId; + myShapeId = shapeId; + myIdInShape = -1; } - -//======================================================================= -//function : InverseElements -//purpose : -//======================================================================= - -const SMDS_ListOfMeshElement& SMDS_MeshElement::InverseElements() const +void SMDS_MeshElement::Print(ostream & OS) const { - static SMDS_ListOfMeshElement empty; - return empty; + OS << "dump of mesh element" << endl; } -//======================================================================= -//function : ClearInverseElements -//purpose : -//======================================================================= - -void SMDS_MeshElement::ClearInverseElements() +ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) { + ME->Print(OS); + return OS; } -//======================================================================= -//function : AddInverseElement -//purpose : -//======================================================================= +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/// This method call elementsIterator(). +/////////////////////////////////////////////////////////////////////////////// +SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const +{ + return elementsIterator(SMDSAbs_Node); +} -void SMDS_MeshElement::AddInverseElement(const Handle(SMDS_MeshElement)& elem) +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on edges linked with or owned by the element. +/// This method call elementsIterator(). +/////////////////////////////////////////////////////////////////////////////// +SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const { + return elementsIterator(SMDSAbs_Edge); } -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= +/////////////////////////////////////////////////////////////////////////////// +/// 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); +} -Standard_Integer SMDS_MeshElement::NbEdges() const +/////////////////////////////////////////////////////////////////////////////// +///Return The number of nodes owned by the current element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshElement::NbNodes() const { - return 0; + int nbnodes=0; + SMDS_ElemIteratorPtr it=nodesIterator(); + while(it->more()) + { + it->next(); + nbnodes++; + } + return nbnodes; } -//======================================================================= -//function : NbFaces -//purpose : -//======================================================================= +/////////////////////////////////////////////////////////////////////////////// +///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; +} -Standard_Integer SMDS_MeshElement::NbFaces() const +/////////////////////////////////////////////////////////////////////////////// +///Return the number of faces owned by or linked with the current element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshElement::NbFaces() const { - return 0; + int nbfaces=0; + SMDS_ElemIteratorPtr it=facesIterator(); + while(it->more()) + { + it->next(); + nbfaces++; + } + return nbfaces; } +/////////////////////////////////////////////////////////////////////////////// +///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; + } -//======================================================================= -//function : GetEdgeDefinedByNodes -//purpose : -//======================================================================= + 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); + } +} -void SMDS_MeshElement::GetEdgeDefinedByNodes(const Standard_Integer rank, - Standard_Integer& idnode1, - Standard_Integer& idnode2) const +//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const { - idnode1 = 0; - idnode2 = 0; + return nodeIterator(); } -//======================================================================= -//function : GetFaceDefinedByNodes -//purpose : -//======================================================================= +//! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const +{ + return nodeIterator(); +} -void SMDS_MeshElement::GetFaceDefinedByNodes(const Standard_Integer rank, - const Standard_Address idnode, - Standard_Integer& nb) const +namespace { - nb = 0; + //======================================================================= + //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(); } + }; } -//======================================================================= -//function : SetNormal -//purpose : -//======================================================================= +SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const +{ + return SMDS_ElemIteratorPtr + ( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() )); +} -void SMDS_MeshElement::SetNormal(const Standard_Integer rank, - const Standard_Real vx, - const Standard_Real vy, - const Standard_Real vz) +SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const +{ + return SMDS_NodeIteratorPtr + ( new _MyNodeIteratorFromElemIterator( nodesIterator() )); +} +bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) { - if (myNormals.IsNull()) { - myNormals = new TColgp_HArray1OfDir(1,NbNodes()); - } - myNormals->SetValue(rank, gp_Dir(vx,vy,vz)); + 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; } -//======================================================================= -//function : SetNormal -//purpose : -//======================================================================= +bool SMDS_MeshElement::IsValidIndex(const int ind) const +{ + return ( ind>-1 && ind= 0 ) { + SMDS_ElemIteratorPtr it = nodesIterator(); + for ( int i = 0; i < ind; ++i ) + it->next(); + if ( it->more() ) + return static_cast (it->next()); } - myNormals->SetValue(rank, gp_Dir(V)); + return 0; } -//======================================================================= -//function : GetNormal -//purpose : -//======================================================================= +bool SMDS_MeshElement::IsQuadratic() const +{ + return false; +} -gp_Dir SMDS_MeshElement::GetNormal(const Standard_Integer rank) +bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const { - if (myNormals.IsNull()) { - myNormals = new TColgp_HArray1OfDir(1,NbNodes()); - } - return myNormals->Value(rank); + return false; } -//======================================================================= -//function : Print -//purpose : -//======================================================================= +//================================================================================ +/*! + * \brief Return number of nodes excluding medium ones + */ +//================================================================================ -void SMDS_MeshElement::Print(Standard_OStream& OS) const +int SMDS_MeshElement::NbCornerNodes() const { - OS << "dump of mesh element" << endl; + return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes(); } +//================================================================================ + /*! + * \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 + */ +//================================================================================ -Standard_OStream& operator << (Standard_OStream& OS - ,const Handle(SMDS_MeshElement)& ME) +int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const { - ME->Print(OS); - return OS; + SMDS_ElemIteratorPtr nIt = nodesIterator(); + for ( int i = 0; nIt->more(); ++i ) + if ( nIt->next() == node ) + return i; + return -1; }