1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMDS : implementaion of Salome mesh data structure
26 #pragma warning(disable:4786)
29 #include "SMDS_MeshElement.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34 #include "utilities.h"
38 SMDS_MeshElement::SMDS_MeshElement(int ID)
43 SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId)
45 init(id, meshId, shapeId);
48 void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId )
56 void SMDS_MeshElement::Print(ostream & OS) const
58 OS << "dump of mesh element" << endl;
61 ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME)
67 ///////////////////////////////////////////////////////////////////////////////
68 /// Create an iterator which iterate on nodes owned by the element.
69 /// This method call elementsIterator().
70 ///////////////////////////////////////////////////////////////////////////////
71 SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const
73 return elementsIterator(SMDSAbs_Node);
76 ///////////////////////////////////////////////////////////////////////////////
77 /// Create an iterator which iterate on edges linked with or owned by the element.
78 /// This method call elementsIterator().
79 ///////////////////////////////////////////////////////////////////////////////
80 SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const
82 return elementsIterator(SMDSAbs_Edge);
85 ///////////////////////////////////////////////////////////////////////////////
86 /// Create an iterator which iterate on faces linked with or owned by the element.
87 /// This method call elementsIterator().
88 ///////////////////////////////////////////////////////////////////////////////
89 SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const
91 return elementsIterator(SMDSAbs_Face);
94 ///////////////////////////////////////////////////////////////////////////////
95 ///Return The number of nodes owned by the current element
96 ///////////////////////////////////////////////////////////////////////////////
97 int SMDS_MeshElement::NbNodes() const
100 SMDS_ElemIteratorPtr it=nodesIterator();
109 ///////////////////////////////////////////////////////////////////////////////
110 ///Return the number of edges owned by or linked with the current element
111 ///////////////////////////////////////////////////////////////////////////////
112 int SMDS_MeshElement::NbEdges() const
115 SMDS_ElemIteratorPtr it=edgesIterator();
124 ///////////////////////////////////////////////////////////////////////////////
125 ///Return the number of faces owned by or linked with the current element
126 ///////////////////////////////////////////////////////////////////////////////
127 int SMDS_MeshElement::NbFaces() const
130 SMDS_ElemIteratorPtr it=facesIterator();
139 ///////////////////////////////////////////////////////////////////////////////
140 ///Create an iterator which iterate on elements linked with the current element.
141 ///@param type The of elements on which you want to iterate
142 ///@return A smart pointer to iterator, you are not to take care of freeing memory
143 ///////////////////////////////////////////////////////////////////////////////
144 class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator
146 const SMDS_MeshElement * myElement;
149 SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element):
150 myElement(element),myMore(true) {}
157 const SMDS_MeshElement* next()
164 SMDS_ElemIteratorPtr SMDS_MeshElement::
165 elementsIterator(SMDSAbs_ElementType type) const
167 /** @todo Check that iterator in the child classes return elements
168 in the same order for each different implementation (i.e: SMDS_VolumeOfNodes
169 and SMDS_VolumeOfFaces */
172 return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this));
175 MESSAGE("Iterator not implemented");
176 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
180 //! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes
181 SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const
183 MESSAGE("Iterator not implemented");
184 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
187 //! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes
188 SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const
190 MESSAGE("Iterator not implemented");
191 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL);
194 bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2)
196 if(e1.GetType()!=e2.GetType()) return false;
200 return static_cast<const SMDS_MeshNode &>(e1) <
201 static_cast<const SMDS_MeshNode &>(e2);
204 return static_cast<const SMDS_MeshEdge &>(e1) <
205 static_cast<const SMDS_MeshEdge &>(e2);
208 return static_cast<const SMDS_MeshFace &>(e1) <
209 static_cast<const SMDS_MeshFace &>(e2);
212 return static_cast<const SMDS_MeshVolume &>(e1) <
213 static_cast<const SMDS_MeshVolume &>(e2);
215 default : MESSAGE("Internal Error");
220 bool SMDS_MeshElement::IsValidIndex(const int ind) const
222 return ( ind>-1 && ind<NbNodes() );
225 const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const
228 SMDS_ElemIteratorPtr it = nodesIterator();
229 for ( int i = 0; i < ind; ++i )
232 return static_cast<const SMDS_MeshNode*> (it->next());
237 bool SMDS_MeshElement::IsQuadratic() const
242 bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const
247 //================================================================================
249 * \brief Return number of nodes excluding medium ones
251 //================================================================================
253 int SMDS_MeshElement::NbCornerNodes() const
255 return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes();
258 //================================================================================
260 * \brief Check if a node belongs to the element
261 * \param node - the node to check
262 * \retval int - node index within the element, -1 if not found
264 //================================================================================
266 int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const
268 SMDS_ElemIteratorPtr nIt = nodesIterator();
269 for ( int i = 0; nIt->more(); ++i )
270 if ( nIt->next() == node )