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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #pragma warning(disable:4786)
26 #include "SMDS_SetIterator.hxx"
27 #include "SMDS_FaceOfNodes.hxx"
28 #include "SMDS_IteratorOfElements.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_Mesh.hxx"
32 #include "utilities.h"
36 //=======================================================================
39 //=======================================================================
41 int SMDS_FaceOfNodes::NbEdges() const
46 int SMDS_FaceOfNodes::NbFaces() const
51 int SMDS_FaceOfNodes::NbNodes() const
56 //=======================================================================
59 //=======================================================================
61 void SMDS_FaceOfNodes::Print(ostream & OS) const
63 OS << "face <" << GetID() << " > : ";
65 for (i = 0; i < NbNodes() - 1; i++) OS << myNodes[i] << ",";
66 OS << myNodes[i] << ") " << endl;
69 //=======================================================================
70 //function : elementsIterator
72 //=======================================================================
74 class SMDS_FaceOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
77 SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
78 SMDS_NodeArrayElemIterator( s, & s[ l ] ) {}
81 /// ===================================================================
83 * \brief Iterator on edges of face
85 /// ===================================================================
87 class _MyEdgeIterator : public SMDS_ElemIterator
89 vector< const SMDS_MeshElement* > myElems;
92 _MyEdgeIterator(const SMDS_FaceOfNodes* face):myIndex(0) {
93 myElems.reserve( face->NbNodes() );
94 for ( int i = 0; i < face->NbNodes(); ++i ) {
95 const SMDS_MeshElement* edge =
96 SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNode( i + 1 ));
98 myElems.push_back( edge );
101 /// Return true if and only if there are other object in this iterator
102 virtual bool more() { return myIndex < myElems.size(); }
104 /// Return the current object and step to the next one
105 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
108 SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator
109 (SMDSAbs_ElementType type) const
114 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
116 return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes));
118 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
121 return SMDS_ElemIteratorPtr
122 (new SMDS_IteratorOfElements
123 (this,type,SMDS_ElemIteratorPtr
124 (new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes))));
126 return SMDS_ElemIteratorPtr();
129 SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
130 const SMDS_MeshNode* node2,
131 const SMDS_MeshNode* node3)
140 SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
141 const SMDS_MeshNode* node2,
142 const SMDS_MeshNode* node3,
143 const SMDS_MeshNode* node4)
151 bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
160 else if (nbNodes != 3)
167 * \brief Return node by its index
168 * \param ind - node index
169 * \retval const SMDS_MeshNode* - the node
171 * Index is wrapped if it is out of a valid range
173 const SMDS_MeshNode* SMDS_FaceOfNodes::GetNode(const int ind) const
175 return myNodes[ WrappedIndex( ind )];
178 /*bool operator<(const SMDS_FaceOfNodes& f1, const SMDS_FaceOfNodes& f2)
180 set<SMDS_MeshNode> set1,set2;
181 SMDS_ElemIteratorPtr it;
182 const SMDS_MeshNode * n;
184 it=f1.nodesIterator();
188 n=static_cast<const SMDS_MeshNode *>(it->next());
193 it=f2.nodesIterator();
197 n=static_cast<const SMDS_MeshNode *>(it->next());