1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 #include "SMDS_MeshElement.hxx"
23 #include "SMDS_MeshNode.hxx"
24 #include "SMDS_MeshEdge.hxx"
25 #include "SMDS_MeshFace.hxx"
26 #include "SMDS_MeshVolume.hxx"
27 #include "utilities.h"
29 SMDS_MeshElement::SMDS_MeshElement(int ID):myID(ID)
33 void SMDS_MeshElement::Print(ostream & OS) const
35 OS << "dump of mesh element" << endl;
38 ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME)
44 ///////////////////////////////////////////////////////////////////////////////
45 /// Create an iterator which iterate on nodes owned by the element.
46 /// This method call elementsIterator().
47 ///////////////////////////////////////////////////////////////////////////////
48 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::nodesIterator() const
50 return elementsIterator(SMDSAbs_Node);
53 ///////////////////////////////////////////////////////////////////////////////
54 /// Create an iterator which iterate on edges linked with or owned by the element.
55 /// This method call elementsIterator().
56 ///////////////////////////////////////////////////////////////////////////////
57 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::edgesIterator() const
59 return elementsIterator(SMDSAbs_Edge);
62 ///////////////////////////////////////////////////////////////////////////////
63 /// Create an iterator which iterate on faces linked with or owned by the element.
64 /// This method call elementsIterator().
65 ///////////////////////////////////////////////////////////////////////////////
66 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::facesIterator() const
68 return elementsIterator(SMDSAbs_Face);
71 ///////////////////////////////////////////////////////////////////////////////
72 ///Return The number of nodes owned by the current element
73 ///////////////////////////////////////////////////////////////////////////////
74 int SMDS_MeshElement::NbNodes() const
77 SMDS_Iterator<const SMDS_MeshElement *> * it=nodesIterator();
87 ///////////////////////////////////////////////////////////////////////////////
88 ///Return the number of edges owned by or linked with the current element
89 ///////////////////////////////////////////////////////////////////////////////
90 int SMDS_MeshElement::NbEdges() const
93 SMDS_Iterator<const SMDS_MeshElement *> * it=edgesIterator();
103 ///////////////////////////////////////////////////////////////////////////////
104 ///Return the number of faces owned by or linked with the current element
105 ///////////////////////////////////////////////////////////////////////////////
106 int SMDS_MeshElement::NbFaces() const
109 SMDS_Iterator<const SMDS_MeshElement *> * it=facesIterator();
119 ///////////////////////////////////////////////////////////////////////////////
120 ///Create and iterator which iterate on elements linked with the current element.
121 ///The iterator must be free by the caller (call delete myIterator).
122 ///@param type The of elements on which you want to iterate
123 ///@return An iterator, that you must free when you no longer need it
124 ///////////////////////////////////////////////////////////////////////////////
125 SMDS_Iterator<const SMDS_MeshElement *> * SMDS_MeshElement::
126 elementsIterator(SMDSAbs_ElementType type) const
128 class MyIterator:public SMDS_Iterator<const SMDS_MeshElement*>
130 const SMDS_MeshElement * myElement;
133 MyIterator(const SMDS_MeshElement * element):
134 myElement(element),myMore(true)
143 const SMDS_MeshElement* next()
150 if(type==GetType()) return new MyIterator(this);
153 MESSAGE("Iterator not implemented");
158 ///////////////////////////////////////////////////////////////////////////////
159 ///Return the ID of the element
160 ///////////////////////////////////////////////////////////////////////////////
161 int SMDS_MeshElement::GetID() const
166 bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2)
168 if(e1.GetType()!=e2.GetType()) return false;
172 return static_cast<const SMDS_MeshNode &>(e1) <
173 static_cast<const SMDS_MeshNode &>(e2);
176 return static_cast<const SMDS_MeshEdge &>(e1) <
177 static_cast<const SMDS_MeshEdge &>(e2);
180 return static_cast<const SMDS_MeshFace &>(e1) <
181 static_cast<const SMDS_MeshFace &>(e2);
184 return static_cast<const SMDS_MeshVolume &>(e1) <
185 static_cast<const SMDS_MeshVolume &>(e2);
187 default : MESSAGE("Internal Error");