1 // Copyright (C) 2007-2008 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
22 // SMESH SMDS : implementaion of Salome mesh data structure
23 // File: SMDS_QuadraticVolumeOfNodes.cxx
24 // Created: 17.01.06 09:46:11
25 // Author: Sergey KUUL
27 #include "SMDS_QuadraticVolumeOfNodes.hxx"
29 #include "SMDS_IteratorOfElements.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_SetIterator.hxx"
32 #include "SMDS_VolumeTool.hxx"
34 #include "utilities.h"
39 //=======================================================================
40 //function : SMDS_QuadraticVolumeOfNodes()
41 //purpose : Constructor tetrahedron of 10 nodes
42 //=======================================================================
44 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
45 (const SMDS_MeshNode * n1,
46 const SMDS_MeshNode * n2,
47 const SMDS_MeshNode * n3,
48 const SMDS_MeshNode * n4,
49 const SMDS_MeshNode * n12,
50 const SMDS_MeshNode * n23,
51 const SMDS_MeshNode * n31,
52 const SMDS_MeshNode * n14,
53 const SMDS_MeshNode * n24,
54 const SMDS_MeshNode * n34)
70 //=======================================================================
71 //function : SMDS_QuadraticVolumeOfNodes()
72 //purpose : Constructor pyramid of 13 nodes
73 //=======================================================================
75 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
76 (const SMDS_MeshNode * n1,
77 const SMDS_MeshNode * n2,
78 const SMDS_MeshNode * n3,
79 const SMDS_MeshNode * n4,
80 const SMDS_MeshNode * n5,
81 const SMDS_MeshNode * n12,
82 const SMDS_MeshNode * n23,
83 const SMDS_MeshNode * n34,
84 const SMDS_MeshNode * n41,
85 const SMDS_MeshNode * n15,
86 const SMDS_MeshNode * n25,
87 const SMDS_MeshNode * n35,
88 const SMDS_MeshNode * n45)
107 //=======================================================================
108 //function : SMDS_QuadraticVolumeOfNodes()
109 //purpose : Constructor Pentahedron with 15 nodes
110 //=======================================================================
112 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
113 (const SMDS_MeshNode * n1,
114 const SMDS_MeshNode * n2,
115 const SMDS_MeshNode * n3,
116 const SMDS_MeshNode * n4,
117 const SMDS_MeshNode * n5,
118 const SMDS_MeshNode * n6,
119 const SMDS_MeshNode * n12,
120 const SMDS_MeshNode * n23,
121 const SMDS_MeshNode * n31,
122 const SMDS_MeshNode * n45,
123 const SMDS_MeshNode * n56,
124 const SMDS_MeshNode * n64,
125 const SMDS_MeshNode * n14,
126 const SMDS_MeshNode * n25,
127 const SMDS_MeshNode * n36)
129 myNodes.resize( 15 );
148 //=======================================================================
149 //function : SMDS_QuadraticVolumeOfNodes()
150 //purpose : Constructor Hexahedrons with 20 nodes
151 //=======================================================================
153 SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
154 (const SMDS_MeshNode * n1,
155 const SMDS_MeshNode * n2,
156 const SMDS_MeshNode * n3,
157 const SMDS_MeshNode * n4,
158 const SMDS_MeshNode * n5,
159 const SMDS_MeshNode * n6,
160 const SMDS_MeshNode * n7,
161 const SMDS_MeshNode * n8,
162 const SMDS_MeshNode * n12,
163 const SMDS_MeshNode * n23,
164 const SMDS_MeshNode * n34,
165 const SMDS_MeshNode * n41,
166 const SMDS_MeshNode * n56,
167 const SMDS_MeshNode * n67,
168 const SMDS_MeshNode * n78,
169 const SMDS_MeshNode * n85,
170 const SMDS_MeshNode * n15,
171 const SMDS_MeshNode * n26,
172 const SMDS_MeshNode * n37,
173 const SMDS_MeshNode * n48)
175 myNodes.resize( 20 );
199 //=======================================================================
200 //function : IsMediumNode
202 //=======================================================================
204 bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const
207 switch (myNodes.size()) {
208 case 10: nbCorners = 4; break;
209 case 13: nbCorners = 5; break;
210 case 15: nbCorners = 6; break;
211 default: nbCorners = 8;
213 for ( int i = nbCorners; i<myNodes.size(); i++) {
214 if(myNodes[i]==node) return true;
220 //=======================================================================
221 //function : ChangeNodes
223 //=======================================================================
225 bool SMDS_QuadraticVolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
228 if( nbNodes==10 || nbNodes==13 || nbNodes==15 || nbNodes==20 ) {
229 myNodes.resize(nbNodes);
231 for(; i<nbNodes; i++) {
232 myNodes[i] = nodes[i];
240 //=======================================================================
243 //=======================================================================
244 int SMDS_QuadraticVolumeOfNodes::NbNodes() const
246 return myNodes.size();
250 //=======================================================================
253 //=======================================================================
254 int SMDS_QuadraticVolumeOfNodes::NbEdges() const
256 if(myNodes.size()==10)
258 else if(myNodes.size()==13)
260 else if(myNodes.size()==15)
267 //=======================================================================
270 //=======================================================================
271 int SMDS_QuadraticVolumeOfNodes::NbFaces() const
273 if(myNodes.size()==10)
275 else if(myNodes.size()==20)
281 //=======================================================================
284 //=======================================================================
285 void SMDS_QuadraticVolumeOfNodes::Print(ostream & OS) const
287 OS << "quadratic volume <" << GetID() << " > : ";
288 int i, nbNodes = myNodes.size();
289 for (i = 0; i < nbNodes - 1; i++)
290 OS << myNodes[i] << ",";
291 OS << myNodes[i] << ") " << endl;
295 //=======================================================================
296 //private class : SMDS_QuadraticVolumeOfNodes_MyIterator
298 //=======================================================================
300 class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator
303 SMDS_QuadraticVolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
304 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
307 /// ===================================================================
309 * \brief Iterator on faces or edges of volume
311 /// ===================================================================
313 class _MySubIterator : public SMDS_ElemIterator
315 vector< const SMDS_MeshElement* > myElems;
318 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
319 SMDS_VolumeTool vTool(vol);
320 if (type == SMDSAbs_Face)
321 vTool.GetAllExistingFaces( myElems );
323 vTool.GetAllExistingFaces( myElems );
325 /// Return true if and only if there are other object in this iterator
326 virtual bool more() { return myIndex < myElems.size(); }
328 /// Return the current object and step to the next one
329 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
332 //=======================================================================
333 //function : elementsIterator
335 //=======================================================================
337 SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
338 (SMDSAbs_ElementType type) const
343 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
345 return SMDS_ElemIteratorPtr(new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes));
347 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
350 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
353 return SMDS_ElemIteratorPtr
354 (new SMDS_IteratorOfElements
355 (this,type,SMDS_ElemIteratorPtr
356 (new SMDS_QuadraticVolumeOfNodes_MyIterator(myNodes))));
358 return SMDS_ElemIteratorPtr();
362 * \brief Return node by its index
363 * \param ind - node index
364 * \retval const SMDS_MeshNode* - the node
366 const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const
368 return myNodes[ ind ];
371 SMDSAbs_EntityType SMDS_QuadraticVolumeOfNodes::GetEntityType() const
373 SMDSAbs_EntityType aType = SMDSEntity_Quad_Tetra;
376 case 10: aType = SMDSEntity_Quad_Tetra; break;
377 case 13: aType = SMDSEntity_Quad_Pyramid; break;
378 case 15: aType = SMDSEntity_Quad_Penta; break;
380 default: aType = SMDSEntity_Quad_Hexa; break;