X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMDS%2FSMDS_MeshElement.cxx;h=701e6fe97ce20051f79820ed74110609341e86a1;hp=df8be2d75dabe209ef8647dd40ad445d167d2451;hb=00c069f8d414099a12268c42d58c6cfae9d1bff9;hpb=bef9beee88cac57394b8dc3bc914381c1a2fff83 diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index df8be2d75..701e6fe97 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -1,177 +1,192 @@ -using namespace std; -// File: SMDS_MeshElement.cxx -// Created: Wed Jan 23 16:49:11 2002 -// Author: Jean-Michel BOULCOURT -// - - -#include "SMDS_MeshElement.ixx" - -//======================================================================= -//function : SMDS_MeshElement -//purpose : -//======================================================================= - -SMDS_MeshElement::SMDS_MeshElement(const Standard_Integer ID, const Standard_Integer nb,const SMDSAbs_ElementType Type) - :myID(ID),myNbNodes(nb),myType(Type) +// SMESH SMDS : implementaion of Salome mesh data structure +// +// 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 + +#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(int ID):myID(ID) { } -//======================================================================= -//function : GetConnections -//purpose : -//======================================================================= - -Standard_Address SMDS_MeshElement::GetConnections() const +void SMDS_MeshElement::Print(ostream & OS) const { - return (Standard_Address)&myID; + OS << "dump of mesh element" << endl; } - -//======================================================================= -//function : GetConnection -//purpose : -//======================================================================= - -Standard_Integer SMDS_MeshElement::GetConnection(const Standard_Integer rank) const +ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) { - return myID; + ME->Print(OS); + return OS; } - -//======================================================================= -//function : InverseElements -//purpose : -//======================================================================= - -const SMDS_ListOfMeshElement& SMDS_MeshElement::InverseElements() const +/////////////////////////////////////////////////////////////////////////////// +/// Create an iterator which iterate on nodes owned by the element. +/// This method call elementsIterator(). +/////////////////////////////////////////////////////////////////////////////// +SMDS_Iterator * SMDS_MeshElement::nodesIterator() const { - static SMDS_ListOfMeshElement empty; - return empty; + return elementsIterator(SMDSAbs_Node); } -//======================================================================= -//function : ClearInverseElements -//purpose : -//======================================================================= - -void SMDS_MeshElement::ClearInverseElements() +/////////////////////////////////////////////////////////////////////////////// +/// 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); } -//======================================================================= -//function : AddInverseElement -//purpose : -//======================================================================= - -void SMDS_MeshElement::AddInverseElement(const Handle(SMDS_MeshElement)& elem) +/////////////////////////////////////////////////////////////////////////////// +/// 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); } -//======================================================================= -//function : NbEdges -//purpose : -//======================================================================= - -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_Iterator * it=nodesIterator(); + while(it->more()) + { + it->next(); + nbnodes++; + } + delete it; + return nbnodes; } -//======================================================================= -//function : NbFaces -//purpose : -//======================================================================= - -Standard_Integer SMDS_MeshElement::NbFaces() const +/////////////////////////////////////////////////////////////////////////////// +///Return the number of edges owned by or linked with the current element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshElement::NbEdges() const { - return 0; + int nbedges=0; + SMDS_Iterator * it=edgesIterator(); + while(it->more()) + { + it->next(); + nbedges++; + } + delete it; + return nbedges; } - -//======================================================================= -//function : GetEdgeDefinedByNodes -//purpose : -//======================================================================= - -void SMDS_MeshElement::GetEdgeDefinedByNodes(const Standard_Integer rank, - Standard_Integer& idnode1, - Standard_Integer& idnode2) const +/////////////////////////////////////////////////////////////////////////////// +///Return the number of faces owned by or linked with the current element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshElement::NbFaces() const { - idnode1 = 0; - idnode2 = 0; + int nbfaces=0; + SMDS_Iterator * it=facesIterator(); + while(it->more()) + { + it->next(); + nbfaces++; + } + delete it; + return nbfaces; } -//======================================================================= -//function : GetFaceDefinedByNodes -//purpose : -//======================================================================= - -void SMDS_MeshElement::GetFaceDefinedByNodes(const Standard_Integer rank, - const Standard_Address idnode, - Standard_Integer& nb) const +/////////////////////////////////////////////////////////////////////////////// +///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 { - nb = 0; + /** @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; + } } -//======================================================================= -//function : SetNormal -//purpose : -//======================================================================= - -void SMDS_MeshElement::SetNormal(const Standard_Integer rank, - const Standard_Real vx, - const Standard_Real vy, - const Standard_Real vz) - -{ - if (myNormals.IsNull()) { - myNormals = new TColgp_HArray1OfDir(1,NbNodes()); - } - myNormals->SetValue(rank, gp_Dir(vx,vy,vz)); -} - -//======================================================================= -//function : SetNormal -//purpose : -//======================================================================= - -void SMDS_MeshElement::SetNormal(const Standard_Integer rank, - const gp_Vec& V) +/////////////////////////////////////////////////////////////////////////////// +///Return the ID of the element +/////////////////////////////////////////////////////////////////////////////// +int SMDS_MeshElement::GetID() const { - if (myNormals.IsNull()) { - myNormals = new TColgp_HArray1OfDir(1,NbNodes()); - } - myNormals->SetValue(rank, gp_Dir(V)); + return myID; } -//======================================================================= -//function : GetNormal -//purpose : -//======================================================================= - -gp_Dir SMDS_MeshElement::GetNormal(const Standard_Integer rank) -{ - if (myNormals.IsNull()) { - myNormals = new TColgp_HArray1OfDir(1,NbNodes()); - } - return myNormals->Value(rank); -} - -//======================================================================= -//function : Print -//purpose : -//======================================================================= - -void SMDS_MeshElement::Print(Standard_OStream& OS) const -{ - OS << "dump of mesh element" << endl; -} - - -Standard_OStream& operator << (Standard_OStream& OS - ,const Handle(SMDS_MeshElement)& ME) +bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) { - ME->Print(OS); - return OS; + 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"); + } }