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_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)
57 //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
72 //=======================================================================
73 //function : SMDS_QuadraticVolumeOfNodes()
74 //purpose : Constructor pyramid of 13 nodes
75 //=======================================================================
77 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
78 (const SMDS_MeshNode * n1,
79 const SMDS_MeshNode * n2,
80 const SMDS_MeshNode * n3,
81 const SMDS_MeshNode * n4,
82 const SMDS_MeshNode * n5,
83 const SMDS_MeshNode * n12,
84 const SMDS_MeshNode * n23,
85 const SMDS_MeshNode * n34,
86 const SMDS_MeshNode * n41,
87 const SMDS_MeshNode * n15,
88 const SMDS_MeshNode * n25,
89 const SMDS_MeshNode * n35,
90 const SMDS_MeshNode * n45)
92 //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
110 //=======================================================================
111 //function : SMDS_QuadraticVolumeOfNodes()
112 //purpose : Constructor Pentahedron with 15 nodes
113 //=======================================================================
115 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
116 (const SMDS_MeshNode * n1,
117 const SMDS_MeshNode * n2,
118 const SMDS_MeshNode * n3,
119 const SMDS_MeshNode * n4,
120 const SMDS_MeshNode * n5,
121 const SMDS_MeshNode * n6,
122 const SMDS_MeshNode * n12,
123 const SMDS_MeshNode * n23,
124 const SMDS_MeshNode * n31,
125 const SMDS_MeshNode * n45,
126 const SMDS_MeshNode * n56,
127 const SMDS_MeshNode * n64,
128 const SMDS_MeshNode * n14,
129 const SMDS_MeshNode * n25,
130 const SMDS_MeshNode * n36)
132 //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
133 myNodes.resize( 15 );
152 //=======================================================================
153 //function : SMDS_QuadraticVolumeOfNodes()
154 //purpose : Constructor Hexahedrons with 20 nodes
155 //=======================================================================
157 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
158 (const SMDS_MeshNode * n1,
159 const SMDS_MeshNode * n2,
160 const SMDS_MeshNode * n3,
161 const SMDS_MeshNode * n4,
162 const SMDS_MeshNode * n5,
163 const SMDS_MeshNode * n6,
164 const SMDS_MeshNode * n7,
165 const SMDS_MeshNode * n8,
166 const SMDS_MeshNode * n12,
167 const SMDS_MeshNode * n23,
168 const SMDS_MeshNode * n34,
169 const SMDS_MeshNode * n41,
170 const SMDS_MeshNode * n56,
171 const SMDS_MeshNode * n67,
172 const SMDS_MeshNode * n78,
173 const SMDS_MeshNode * n85,
174 const SMDS_MeshNode * n15,
175 const SMDS_MeshNode * n26,
176 const SMDS_MeshNode * n37,
177 const SMDS_MeshNode * n48)
179 //MESSAGE("*********************************************** SMDS_QuadraticVolumeOfNodes");
180 myNodes.resize( 20 );
204 //=======================================================================
205 //function : IsMediumNode
207 //=======================================================================
209 bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const
212 switch (myNodes.size()) {
213 case 10: nbCorners = 4; break;
214 case 13: nbCorners = 5; break;
215 case 15: nbCorners = 6; break;
216 default: nbCorners = 8;
218 for ( int i = nbCorners; i<myNodes.size(); i++) {
219 if(myNodes[i]==node) return true;
225 //=======================================================================
226 //function : ChangeNodes
228 //=======================================================================
230 bool SMDS_QuadraticVolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
233 if( nbNodes==10 || nbNodes==13 || nbNodes==15 || nbNodes==20 ) {
234 myNodes.resize(nbNodes);
236 for(; i<nbNodes; i++) {
237 myNodes[i] = nodes[i];
245 //=======================================================================
248 //=======================================================================
249 int SMDS_QuadraticVolumeOfNodes::NbNodes() const
251 return myNodes.size();
255 //=======================================================================
258 //=======================================================================
259 int SMDS_QuadraticVolumeOfNodes::NbEdges() const
261 if(myNodes.size()==10)
263 else if(myNodes.size()==13)
265 else if(myNodes.size()==15)
272 //=======================================================================
275 //=======================================================================
276 int SMDS_QuadraticVolumeOfNodes::NbFaces() const
278 if(myNodes.size()==10)
280 else if(myNodes.size()==20)
286 //=======================================================================
289 //=======================================================================
290 void SMDS_QuadraticVolumeOfNodes::Print(ostream & OS) const
292 OS << "quadratic volume <" << GetID() << " > : ";
293 int i, nbNodes = myNodes.size();
294 for (i = 0; i < nbNodes - 1; i++)
295 OS << myNodes[i] << ",";
296 OS << myNodes[i] << ") " << endl;
300 //=======================================================================
301 //private class : SMDS_QuadraticVolumeOfNodes_MyIterator
303 //=======================================================================
305 class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator
308 SMDS_QuadraticVolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
309 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
312 /// ===================================================================
314 * \brief Iterator on faces or edges of volume
316 /// ===================================================================
318 class _MySubIterator : public SMDS_ElemIterator
320 vector< const SMDS_MeshElement* > myElems;
323 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
324 SMDS_VolumeTool vTool(vol);
325 if (type == SMDSAbs_Face)
326 vTool.GetAllExistingFaces( myElems );
328 vTool.GetAllExistingFaces( myElems );
330 /// Return true if and only if there are other object in this iterator
331 virtual bool more() { return myIndex < myElems.size(); }
333 /// Return the current object and step to the next one
334 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
337 //=======================================================================
338 //function : elementsIterator
340 //=======================================================================
342 SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
343 (SMDSAbs_ElementType type) const
348 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
350 return SMDS_ElemIteratorPtr(new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes));
352 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
355 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
358 return SMDS_ElemIteratorPtr
359 (new SMDS_IteratorOfElements
360 (this,type,SMDS_ElemIteratorPtr
361 (new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes))));
363 return SMDS_ElemIteratorPtr();
367 * \brief Return node by its index
368 * \param ind - node index
369 * \retval const SMDS_MeshNode* - the node
371 const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const
373 return myNodes[ ind ];
376 SMDSAbs_EntityType SMDS_QuadraticVolumeOfNodes::GetEntityType() const
378 SMDSAbs_EntityType aType = SMDSEntity_Quad_Tetra;
381 case 10: aType = SMDSEntity_Quad_Tetra; break;
382 case 13: aType = SMDSEntity_Quad_Pyramid; break;
383 case 15: aType = SMDSEntity_Quad_Penta; break;
385 default: aType = SMDSEntity_Quad_Hexa; break;