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
26 #pragma warning(disable:4786)
29 #include "SMDS_VolumeOfNodes.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_SetIterator.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "SMDS_Mesh.hxx"
34 #include "utilities.h"
38 ///////////////////////////////////////////////////////////////////////////////
39 /// Create an hexahedron. node 1,2,3,4 and 5,6,7,8 are quadrangle and
40 /// 5,1 and 7,3 are an edges.
41 ///////////////////////////////////////////////////////////////////////////////
42 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
43 const SMDS_MeshNode * node1,
44 const SMDS_MeshNode * node2,
45 const SMDS_MeshNode * node3,
46 const SMDS_MeshNode * node4,
47 const SMDS_MeshNode * node5,
48 const SMDS_MeshNode * node6,
49 const SMDS_MeshNode * node7,
50 const SMDS_MeshNode * node8)
53 myNodes = new const SMDS_MeshNode* [myNbNodes];
64 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
65 const SMDS_MeshNode * node1,
66 const SMDS_MeshNode * node2,
67 const SMDS_MeshNode * node3,
68 const SMDS_MeshNode * node4)
71 myNodes = new const SMDS_MeshNode* [myNbNodes];
78 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
79 const SMDS_MeshNode * node1,
80 const SMDS_MeshNode * node2,
81 const SMDS_MeshNode * node3,
82 const SMDS_MeshNode * node4,
83 const SMDS_MeshNode * node5)
86 myNodes = new const SMDS_MeshNode* [myNbNodes];
94 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
95 const SMDS_MeshNode * node1,
96 const SMDS_MeshNode * node2,
97 const SMDS_MeshNode * node3,
98 const SMDS_MeshNode * node4,
99 const SMDS_MeshNode * node5,
100 const SMDS_MeshNode * node6)
103 myNodes = new const SMDS_MeshNode* [myNbNodes];
112 bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
115 if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
120 myNodes = new const SMDS_MeshNode* [myNbNodes];
121 for ( int i = 0; i < nbNodes; i++ )
122 myNodes[ i ] = nodes [ i ];
127 SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
129 if (myNodes != NULL) {
135 void SMDS_VolumeOfNodes::Print(ostream & OS) const
137 OS << "volume <" << GetID() << "> : ";
139 for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ",";
140 OS << myNodes[NbNodes()-1]<< ") " << endl;
143 int SMDS_VolumeOfNodes::NbFaces() const
151 default: MESSAGE("invalid number of nodes");
156 int SMDS_VolumeOfNodes::NbNodes() const
161 int SMDS_VolumeOfNodes::NbEdges() const
169 default: MESSAGE("invalid number of nodes");
175 * \brief Iterator on node of volume
177 class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
180 SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
181 SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
185 * \brief Iterator on faces or edges of volume
187 class _MySubIterator : public SMDS_ElemIterator
189 vector< const SMDS_MeshElement* > myElems;
192 _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) {
193 SMDS_VolumeTool vTool(vol);
194 if (type == SMDSAbs_Face)
195 vTool.GetAllExistingFaces( myElems );
197 vTool.GetAllExistingFaces( myElems );
199 /// Return true if and only if there are other object in this iterator
200 virtual bool more() { return myIndex < myElems.size(); }
202 /// Return the current object and step to the next one
203 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
206 SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
211 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
213 return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
215 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
217 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
219 MESSAGE("ERROR : Iterator not implemented");
220 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
224 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
226 return SMDSAbs_Volume;
230 * \brief Return node by its index
231 * \param ind - node index
232 * \retval const SMDS_MeshNode* - the node
234 const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
236 return myNodes[ ind ];
239 SMDSAbs_EntityType SMDS_VolumeOfNodes::GetEntityType() const
241 SMDSAbs_EntityType aType = SMDSEntity_Tetra;
244 case 4: aType = SMDSEntity_Tetra; break;
245 case 5: aType = SMDSEntity_Pyramid; break;
246 case 6: aType = SMDSEntity_Penta; break;
248 default: aType = SMDSEntity_Hexa; break;