1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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_PolygonalFaceOfNodes.hxx"
31 #include "SMDS_IteratorOfElements.hxx"
32 #include "SMDS_SetIterator.hxx"
33 #include "SMDS_Mesh.hxx"
35 #include "utilities.h"
39 //=======================================================================
40 //function : Constructor
42 //=======================================================================
43 SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes
44 (std::vector<const SMDS_MeshNode *> nodes)
46 //MESSAGE("******************************************** SMDS_PolygonalFaceOfNodes");
50 //=======================================================================
53 //=======================================================================
54 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const
57 //return SMDSAbs_PolygonalFace;
60 //=======================================================================
61 //function : ChangeNodes
63 //=======================================================================
64 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes)
74 //=======================================================================
75 //function : ChangeNodes
76 //purpose : to support the same interface, as SMDS_FaceOfNodes
77 //=======================================================================
78 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
84 myNodes.resize(nbNodes);
86 for (; i < nbNodes; i++) {
87 myNodes[i] = nodes[i];
93 //=======================================================================
96 //=======================================================================
97 int SMDS_PolygonalFaceOfNodes::NbNodes() const
99 return myNodes.size();
102 //=======================================================================
105 //=======================================================================
106 int SMDS_PolygonalFaceOfNodes::NbEdges() const
111 //=======================================================================
114 //=======================================================================
115 int SMDS_PolygonalFaceOfNodes::NbFaces() const
120 //=======================================================================
123 //=======================================================================
124 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
126 OS << "polygonal face <" << GetID() << " > : ";
127 int i, nbNodes = myNodes.size();
128 for (i = 0; i < nbNodes - 1; i++)
129 OS << myNodes[i] << ",";
130 OS << myNodes[i] << ") " << endl;
133 //=======================================================================
134 //function : elementsIterator
136 //=======================================================================
137 class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator
140 SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
141 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
144 /// ===================================================================
146 * \brief Iterator on edges of face
148 /// ===================================================================
150 class _MyEdgeIterator : public SMDS_ElemIterator
152 vector< const SMDS_MeshElement* > myElems;
155 _MyEdgeIterator(const SMDS_MeshFace* face):myIndex(0) {
156 myElems.reserve( face->NbNodes() );
157 for ( int i = 0; i < face->NbNodes(); ++i ) {
158 const SMDS_MeshElement* edge =
159 SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNodeWrap( i + 1 ));
161 myElems.push_back( edge );
164 /// Return true if and only if there are other object in this iterator
165 virtual bool more() { return myIndex < myElems.size(); }
167 /// Return the current object and step to the next one
168 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
171 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
172 (SMDSAbs_ElementType type) const
177 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
179 return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes));
181 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
184 return SMDS_ElemIteratorPtr
185 (new SMDS_IteratorOfElements
186 (this,type,SMDS_ElemIteratorPtr
187 (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes))));
189 return SMDS_ElemIteratorPtr();
193 * \brief Return node by its index
194 * \param ind - node index
195 * \retval const SMDS_MeshNode* - the node
197 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
199 return myNodes[ WrappedIndex( ind )];