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_PolygonalFaceOfNodes.hxx"
28 #include "SMDS_IteratorOfElements.hxx"
29 #include "SMDS_SetIterator.hxx"
30 #include "SMDS_Mesh.hxx"
32 #include "utilities.h"
36 //=======================================================================
37 //function : Constructor
39 //=======================================================================
40 SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes
41 (std::vector<const SMDS_MeshNode *> nodes)
46 //=======================================================================
49 //=======================================================================
50 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const
53 //return SMDSAbs_PolygonalFace;
56 //=======================================================================
57 //function : ChangeNodes
59 //=======================================================================
60 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes)
70 //=======================================================================
71 //function : ChangeNodes
72 //purpose : to support the same interface, as SMDS_FaceOfNodes
73 //=======================================================================
74 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
80 myNodes.resize(nbNodes);
82 for (; i < nbNodes; i++) {
83 myNodes[i] = nodes[i];
89 //=======================================================================
92 //=======================================================================
93 int SMDS_PolygonalFaceOfNodes::NbNodes() const
95 return myNodes.size();
98 //=======================================================================
101 //=======================================================================
102 int SMDS_PolygonalFaceOfNodes::NbEdges() const
107 //=======================================================================
110 //=======================================================================
111 int SMDS_PolygonalFaceOfNodes::NbFaces() const
116 //=======================================================================
119 //=======================================================================
120 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
122 OS << "polygonal face <" << GetID() << " > : ";
123 int i, nbNodes = myNodes.size();
124 for (i = 0; i < nbNodes - 1; i++)
125 OS << myNodes[i] << ",";
126 OS << myNodes[i] << ") " << endl;
129 //=======================================================================
130 //function : elementsIterator
132 //=======================================================================
133 class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator
136 SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
137 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
140 /// ===================================================================
142 * \brief Iterator on edges of face
144 /// ===================================================================
146 class _MyEdgeIterator : public SMDS_ElemIterator
148 vector< const SMDS_MeshElement* > myElems;
151 _MyEdgeIterator(const SMDS_MeshFace* face):myIndex(0) {
152 myElems.reserve( face->NbNodes() );
153 for ( int i = 0; i < face->NbNodes(); ++i ) {
154 const SMDS_MeshElement* edge =
155 SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNode( i + 1 ));
157 myElems.push_back( edge );
160 /// Return true if and only if there are other object in this iterator
161 virtual bool more() { return myIndex < myElems.size(); }
163 /// Return the current object and step to the next one
164 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
167 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
168 (SMDSAbs_ElementType type) const
173 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
175 return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes));
177 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
180 return SMDS_ElemIteratorPtr
181 (new SMDS_IteratorOfElements
182 (this,type,SMDS_ElemIteratorPtr
183 (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes))));
185 return SMDS_ElemIteratorPtr();
189 * \brief Return node by its index
190 * \param ind - node index
191 * \retval const SMDS_MeshNode* - the node
193 * Index is wrapped if it is out of a valid range
195 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
197 return myNodes[ WrappedIndex( ind )];