1 // Copyright (C) 2007-2015 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
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 : _MyNodeIterator
198 //=======================================================================
200 class _MyNodeIterator : public SMDS_NodeVectorElemIterator
203 _MyNodeIterator(const vector<const SMDS_MeshNode *>& s):
204 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
209 //=======================================================================
210 //function : interlacedNodesIterator
212 //=======================================================================
214 SMDS_NodeIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesIterator() const
216 static int triaInterlace [] = { 0, 3, 1, 4, 2, 5 };
217 static int quadInterlace [] = { 0, 4, 1, 5, 2, 6, 3, 7 };
218 return SMDS_NodeIteratorPtr
219 (new _MyInterlacedNodeIterator (myNodes, myNodes.size()==6 ? triaInterlace : quadInterlace));
222 /// ===================================================================
224 * \brief Iterator on edges of face
226 /// ===================================================================
228 class _MyEdgeIterator : public SMDS_ElemIterator
230 vector< const SMDS_MeshElement* > myElems;
233 _MyEdgeIterator(const SMDS_QuadraticFaceOfNodes* face):myIndex(0) {
234 myElems.reserve( face->NbNodes() );
235 SMDS_NodeIteratorPtr nIt = face->interlacedNodesIterator();
236 const SMDS_MeshNode* n0 = face->GetNodeWrap( -1 );
237 while ( nIt->more() ) {
238 const SMDS_MeshNode* n1 = nIt->next();
239 const SMDS_MeshElement* edge = SMDS_Mesh::FindEdge( n0, n1 );
241 myElems.push_back( edge );
245 /// Return true if and only if there are other object in this iterator
246 virtual bool more() { return myIndex < myElems.size(); }
248 /// Return the current object and step to the next one
249 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
252 //=======================================================================
253 //function : elementsIterator
255 //=======================================================================
257 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator
258 (SMDSAbs_ElementType type) const
263 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
265 return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
267 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
270 return SMDS_ElemIteratorPtr
271 (new SMDS_IteratorOfElements
272 (this,type,SMDS_ElemIteratorPtr (new _MyNodeIterator(myNodes))));
274 return SMDS_ElemIteratorPtr();
278 * \brief Return node by its index
279 * \param ind - node index
280 * \retval const SMDS_MeshNode* - the node
282 const SMDS_MeshNode* SMDS_QuadraticFaceOfNodes::GetNode(const int ind) const
284 return myNodes[ ind ];
287 SMDSAbs_EntityType SMDS_QuadraticFaceOfNodes::GetEntityType() const
289 return NbNodes() == 6 ? SMDSEntity_Quad_Triangle : SMDSEntity_Quad_Quadrangle;