1 // Copyright (C) 2007-2010 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_QuadraticVolumeOfNodes.cxx
25 // Created: 17.01.06 09:46:11
26 // Author: Sergey KUUL
28 #include "SMDS_QuadraticVolumeOfNodes.hxx"
30 #include "SMDS_IteratorOfElements.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMDS_SetIterator.hxx"
33 #include "SMDS_VolumeTool.hxx"
35 #include "utilities.h"
40 //=======================================================================
41 //function : SMDS_QuadraticVolumeOfNodes()
42 //purpose : Constructor tetrahedron of 10 nodes
43 //=======================================================================
45 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
46 (const SMDS_MeshNode * n1,
47 const SMDS_MeshNode * n2,
48 const SMDS_MeshNode * n3,
49 const SMDS_MeshNode * n4,
50 const SMDS_MeshNode * n12,
51 const SMDS_MeshNode * n23,
52 const SMDS_MeshNode * n31,
53 const SMDS_MeshNode * n14,
54 const SMDS_MeshNode * n24,
55 const SMDS_MeshNode * n34)
71 //=======================================================================
72 //function : SMDS_QuadraticVolumeOfNodes()
73 //purpose : Constructor pyramid of 13 nodes
74 //=======================================================================
76 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
77 (const SMDS_MeshNode * n1,
78 const SMDS_MeshNode * n2,
79 const SMDS_MeshNode * n3,
80 const SMDS_MeshNode * n4,
81 const SMDS_MeshNode * n5,
82 const SMDS_MeshNode * n12,
83 const SMDS_MeshNode * n23,
84 const SMDS_MeshNode * n34,
85 const SMDS_MeshNode * n41,
86 const SMDS_MeshNode * n15,
87 const SMDS_MeshNode * n25,
88 const SMDS_MeshNode * n35,
89 const SMDS_MeshNode * n45)
108 //=======================================================================
109 //function : SMDS_QuadraticVolumeOfNodes()
110 //purpose : Constructor Pentahedron with 15 nodes
111 //=======================================================================
113 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
114 (const SMDS_MeshNode * n1,
115 const SMDS_MeshNode * n2,
116 const SMDS_MeshNode * n3,
117 const SMDS_MeshNode * n4,
118 const SMDS_MeshNode * n5,
119 const SMDS_MeshNode * n6,
120 const SMDS_MeshNode * n12,
121 const SMDS_MeshNode * n23,
122 const SMDS_MeshNode * n31,
123 const SMDS_MeshNode * n45,
124 const SMDS_MeshNode * n56,
125 const SMDS_MeshNode * n64,
126 const SMDS_MeshNode * n14,
127 const SMDS_MeshNode * n25,
128 const SMDS_MeshNode * n36)
130 myNodes.resize( 15 );
149 //=======================================================================
150 //function : SMDS_QuadraticVolumeOfNodes()
151 //purpose : Constructor Hexahedrons with 20 nodes
152 //=======================================================================
154 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
155 (const SMDS_MeshNode * n1,
156 const SMDS_MeshNode * n2,
157 const SMDS_MeshNode * n3,
158 const SMDS_MeshNode * n4,
159 const SMDS_MeshNode * n5,
160 const SMDS_MeshNode * n6,
161 const SMDS_MeshNode * n7,
162 const SMDS_MeshNode * n8,
163 const SMDS_MeshNode * n12,
164 const SMDS_MeshNode * n23,
165 const SMDS_MeshNode * n34,
166 const SMDS_MeshNode * n41,
167 const SMDS_MeshNode * n56,
168 const SMDS_MeshNode * n67,
169 const SMDS_MeshNode * n78,
170 const SMDS_MeshNode * n85,
171 const SMDS_MeshNode * n15,
172 const SMDS_MeshNode * n26,
173 const SMDS_MeshNode * n37,
174 const SMDS_MeshNode * n48)
176 myNodes.resize( 20 );
200 //=======================================================================
201 //function : IsMediumNode
203 //=======================================================================
205 bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const
208 switch (myNodes.size()) {
209 case 10: nbCorners = 4; break;
210 case 13: nbCorners = 5; break;
211 case 15: nbCorners = 6; break;
212 default: nbCorners = 8;
214 for ( int i = nbCorners; i<myNodes.size(); i++) {
215 if(myNodes[i]==node) return true;
221 //=======================================================================
222 //function : ChangeNodes
224 //=======================================================================
226 bool SMDS_QuadraticVolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
229 if( nbNodes==10 || nbNodes==13 || nbNodes==15 || nbNodes==20 ) {
230 myNodes.resize(nbNodes);
232 for(; i<nbNodes; i++) {
233 myNodes[i] = nodes[i];
241 //=======================================================================
244 //=======================================================================
245 int SMDS_QuadraticVolumeOfNodes::NbNodes() const
247 return myNodes.size();
251 //=======================================================================
254 //=======================================================================
255 int SMDS_QuadraticVolumeOfNodes::NbEdges() const
257 if(myNodes.size()==10)
259 else if(myNodes.size()==13)
261 else if(myNodes.size()==15)
268 //=======================================================================
271 //=======================================================================
272 int SMDS_QuadraticVolumeOfNodes::NbFaces() const
274 if(myNodes.size()==10)
276 else if(myNodes.size()==20)
282 //=======================================================================
285 //=======================================================================
286 void SMDS_QuadraticVolumeOfNodes::Print(ostream & OS) const
288 OS << "quadratic volume <" << GetID() << " > : ";
289 int i, nbNodes = myNodes.size();
290 for (i = 0; i < nbNodes - 1; i++)
291 OS << myNodes[i] << ",";
292 OS << myNodes[i] << ") " << endl;
296 //=======================================================================
297 //private class : SMDS_QuadraticVolumeOfNodes_MyIterator
299 //=======================================================================
301 class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator
304 SMDS_QuadraticVolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
305 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
308 /// ===================================================================
310 * \brief Iterator on faces or edges of volume
312 /// ===================================================================
314 class _MySubIterator : public SMDS_ElemIterator
316 vector< const SMDS_MeshElement* > myElems;
319 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
320 SMDS_VolumeTool vTool(vol);
321 if (type == SMDSAbs_Face)
322 vTool.GetAllExistingFaces( myElems );
324 vTool.GetAllExistingFaces( myElems );
326 /// Return true if and only if there are other object in this iterator
327 virtual bool more() { return myIndex < myElems.size(); }
329 /// Return the current object and step to the next one
330 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
333 //=======================================================================
334 //function : elementsIterator
336 //=======================================================================
338 SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
339 (SMDSAbs_ElementType type) const
344 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
346 return SMDS_ElemIteratorPtr(new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes));
348 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
351 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
354 return SMDS_ElemIteratorPtr
355 (new SMDS_IteratorOfElements
356 (this,type,SMDS_ElemIteratorPtr
357 (new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes))));
359 return SMDS_ElemIteratorPtr();
363 * \brief Return node by its index
364 * \param ind - node index
365 * \retval const SMDS_MeshNode* - the node
367 const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const
369 return myNodes[ ind ];
372 SMDSAbs_EntityType SMDS_QuadraticVolumeOfNodes::GetEntityType() const
374 SMDSAbs_EntityType aType = SMDSEntity_Quad_Tetra;
377 case 10: aType = SMDSEntity_Quad_Tetra; break;
378 case 13: aType = SMDSEntity_Quad_Pyramid; break;
379 case 15: aType = SMDSEntity_Quad_Penta; break;
381 default: aType = SMDSEntity_Quad_Hexa; break;