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
24 // File: SMDS_QuadraticFaceOfNodes.cxx
25 // Created: 16.01.06 17:12:58
26 // Author: Sergey KUUL
28 #include "SMDS_QuadraticFaceOfNodes.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMDS_IteratorOfElements.hxx"
32 #include "SMDS_MeshNode.hxx"
33 #include "SMDS_Mesh.hxx"
35 #include "utilities.h"
40 //=======================================================================
41 //function : SMDS_QuadraticFaceOfNodes()
42 //purpose : Constructor
43 //=======================================================================
45 SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
46 const SMDS_MeshNode * n2,
47 const SMDS_MeshNode * n3,
48 const SMDS_MeshNode * n12,
49 const SMDS_MeshNode * n23,
50 const SMDS_MeshNode * n31)
52 //MESSAGE("********************************************** SMDS_QuadraticFaceOfNodes 1");
63 //=======================================================================
64 //function : SMDS_QuadraticFaceOfNodes()
65 //purpose : Constructor
66 //=======================================================================
68 SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
69 const SMDS_MeshNode * n2,
70 const SMDS_MeshNode * n3,
71 const SMDS_MeshNode * n4,
72 const SMDS_MeshNode * n12,
73 const SMDS_MeshNode * n23,
74 const SMDS_MeshNode * n34,
75 const SMDS_MeshNode * n41)
77 //MESSAGE("********************************************* SMDS_QuadraticFaceOfNodes 2");
90 //=======================================================================
91 //function : IsMediumNode
93 //=======================================================================
95 bool SMDS_QuadraticFaceOfNodes::IsMediumNode(const SMDS_MeshNode * node) const
98 for(; i<NbNodes(); i++) {
99 if(myNodes[i]==node) return true;
105 //=======================================================================
106 //function : ChangeNodes
108 //=======================================================================
110 bool SMDS_QuadraticFaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
113 if( nbNodes==6 || nbNodes==8 ) {
114 myNodes.resize(nbNodes);
116 for(; i<nbNodes; i++) {
117 myNodes[i] = nodes[i];
125 //=======================================================================
128 //=======================================================================
129 int SMDS_QuadraticFaceOfNodes::NbNodes() const
131 return myNodes.size();
135 //=======================================================================
138 //=======================================================================
139 int SMDS_QuadraticFaceOfNodes::NbEdges() const
145 //=======================================================================
148 //=======================================================================
149 int SMDS_QuadraticFaceOfNodes::NbFaces() const
154 //=======================================================================
157 //=======================================================================
158 void SMDS_QuadraticFaceOfNodes::Print(ostream & OS) const
160 OS << "quadratic face <" << GetID() << " > : ";
161 int i, nbNodes = myNodes.size();
162 for (i = 0; i < nbNodes - 1; i++)
163 OS << myNodes[i] << ",";
164 OS << myNodes[i] << ") " << endl;
169 //=======================================================================
170 //class : _MyInterlacedNodeIterator
172 //=======================================================================
174 class _MyInterlacedNodeIterator:public SMDS_NodeIterator
176 const vector<const SMDS_MeshNode *>& mySet;
178 const int * myInterlace;
180 _MyInterlacedNodeIterator(const vector<const SMDS_MeshNode *>& s,
181 const int * interlace):
182 mySet(s),myIndex(0),myInterlace(interlace) {}
186 return myIndex < mySet.size();
189 const SMDS_MeshNode* next()
191 return mySet[ myInterlace[ myIndex++ ]];
195 //=======================================================================
196 //class : _MyInterlacedNodeElemIterator
198 //=======================================================================
200 class _MyInterlacedNodeElemIterator : public SMDS_ElemIterator
202 SMDS_NodeIteratorPtr myItr;
204 _MyInterlacedNodeElemIterator(SMDS_NodeIteratorPtr interlacedNodeItr):
205 myItr( interlacedNodeItr ) {}
206 bool more() { return myItr->more(); }
207 const SMDS_MeshElement* next() { return myItr->next(); }
210 //=======================================================================
211 //class : _MyNodeIterator
213 //=======================================================================
215 class _MyNodeIterator : public SMDS_NodeVectorElemIterator
218 _MyNodeIterator(const vector<const SMDS_MeshNode *>& s):
219 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
224 //=======================================================================
225 //function : interlacedNodesIterator
227 //=======================================================================
229 SMDS_NodeIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesIterator() const
231 static int triaInterlace [] = { 0, 3, 1, 4, 2, 5 };
232 static int quadInterlace [] = { 0, 4, 1, 5, 2, 6, 3, 7 };
233 return SMDS_NodeIteratorPtr
234 (new _MyInterlacedNodeIterator (myNodes, myNodes.size()==6 ? triaInterlace : quadInterlace));
237 //=======================================================================
238 //function : interlacedNodesElemIterator
240 //=======================================================================
242 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesElemIterator() const
244 return SMDS_ElemIteratorPtr
245 (new _MyInterlacedNodeElemIterator ( interlacedNodesIterator() ));
247 /// ===================================================================
249 * \brief Iterator on edges of face
251 /// ===================================================================
253 class _MyEdgeIterator : public SMDS_ElemIterator
255 vector< const SMDS_MeshElement* > myElems;
258 _MyEdgeIterator(const SMDS_QuadraticFaceOfNodes* face):myIndex(0) {
259 myElems.reserve( face->NbNodes() );
260 SMDS_ElemIteratorPtr nIt = face->interlacedNodesElemIterator();
261 const SMDS_MeshNode* n0 = face->GetNodeWrap( -1 );
262 while ( nIt->more() ) {
263 const SMDS_MeshNode* n1 = static_cast<const SMDS_MeshNode*>( nIt->next() );
264 const SMDS_MeshElement* edge = SMDS_Mesh::FindEdge( n0, n1 );
266 myElems.push_back( edge );
270 /// Return true if and only if there are other object in this iterator
271 virtual bool more() { return myIndex < myElems.size(); }
273 /// Return the current object and step to the next one
274 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
277 //=======================================================================
278 //function : elementsIterator
280 //=======================================================================
282 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator
283 (SMDSAbs_ElementType type) const
288 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
290 return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
292 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
295 return SMDS_ElemIteratorPtr
296 (new SMDS_IteratorOfElements
297 (this,type,SMDS_ElemIteratorPtr (new _MyNodeIterator(myNodes))));
299 return SMDS_ElemIteratorPtr();
303 * \brief Return node by its index
304 * \param ind - node index
305 * \retval const SMDS_MeshNode* - the node
307 const SMDS_MeshNode* SMDS_QuadraticFaceOfNodes::GetNode(const int ind) const
309 return myNodes[ ind ];
312 SMDSAbs_EntityType SMDS_QuadraticFaceOfNodes::GetEntityType() const
314 return NbNodes() == 6 ? SMDSEntity_Quad_Triangle : SMDSEntity_Quad_Quadrangle;