1 // Copyright (C) 2007-2008 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
22 // SMESH SMDS : implementaion of Salome mesh data structure
25 #pragma warning(disable:4786)
28 #include "SMDS_PolygonalFaceOfNodes.hxx"
30 #include "SMDS_IteratorOfElements.hxx"
31 #include "SMDS_SetIterator.hxx"
32 #include "SMDS_Mesh.hxx"
34 #include "utilities.h"
38 //=======================================================================
39 //function : Constructor
41 //=======================================================================
42 SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes
43 (std::vector<const SMDS_MeshNode *> nodes)
48 //=======================================================================
51 //=======================================================================
52 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const
55 //return SMDSAbs_PolygonalFace;
58 //=======================================================================
59 //function : ChangeNodes
61 //=======================================================================
62 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes)
72 //=======================================================================
73 //function : ChangeNodes
74 //purpose : to support the same interface, as SMDS_FaceOfNodes
75 //=======================================================================
76 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
82 myNodes.resize(nbNodes);
84 for (; i < nbNodes; i++) {
85 myNodes[i] = nodes[i];
91 //=======================================================================
94 //=======================================================================
95 int SMDS_PolygonalFaceOfNodes::NbNodes() const
97 return myNodes.size();
100 //=======================================================================
103 //=======================================================================
104 int SMDS_PolygonalFaceOfNodes::NbEdges() const
109 //=======================================================================
112 //=======================================================================
113 int SMDS_PolygonalFaceOfNodes::NbFaces() const
118 //=======================================================================
121 //=======================================================================
122 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
124 OS << "polygonal face <" << GetID() << " > : ";
125 int i, nbNodes = myNodes.size();
126 for (i = 0; i < nbNodes - 1; i++)
127 OS << myNodes[i] << ",";
128 OS << myNodes[i] << ") " << endl;
131 //=======================================================================
132 //function : elementsIterator
134 //=======================================================================
135 class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator
138 SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
139 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
142 /// ===================================================================
144 * \brief Iterator on edges of face
146 /// ===================================================================
148 class _MyEdgeIterator : public SMDS_ElemIterator
150 vector< const SMDS_MeshElement* > myElems;
153 _MyEdgeIterator(const SMDS_MeshFace* face):myIndex(0) {
154 myElems.reserve( face->NbNodes() );
155 for ( int i = 0; i < face->NbNodes(); ++i ) {
156 const SMDS_MeshElement* edge =
157 SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNode( i + 1 ));
159 myElems.push_back( edge );
162 /// Return true if and only if there are other object in this iterator
163 virtual bool more() { return myIndex < myElems.size(); }
165 /// Return the current object and step to the next one
166 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
169 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
170 (SMDSAbs_ElementType type) const
175 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
177 return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes));
179 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
182 return SMDS_ElemIteratorPtr
183 (new SMDS_IteratorOfElements
184 (this,type,SMDS_ElemIteratorPtr
185 (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes))));
187 return SMDS_ElemIteratorPtr();
191 * \brief Return node by its index
192 * \param ind - node index
193 * \retval const SMDS_MeshNode* - the node
195 * Index is wrapped if it is out of a valid range
197 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
199 return myNodes[ WrappedIndex( ind )];