1 // Copyright (C) 2007-2014 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
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)
52 //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
54 myNodes = new const SMDS_MeshNode* [myNbNodes];
65 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
66 const SMDS_MeshNode * node1,
67 const SMDS_MeshNode * node2,
68 const SMDS_MeshNode * node3,
69 const SMDS_MeshNode * node4)
71 //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
73 myNodes = new const SMDS_MeshNode* [myNbNodes];
80 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
81 const SMDS_MeshNode * node1,
82 const SMDS_MeshNode * node2,
83 const SMDS_MeshNode * node3,
84 const SMDS_MeshNode * node4,
85 const SMDS_MeshNode * node5)
87 //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
89 myNodes = new const SMDS_MeshNode* [myNbNodes];
97 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
98 const SMDS_MeshNode * node1,
99 const SMDS_MeshNode * node2,
100 const SMDS_MeshNode * node3,
101 const SMDS_MeshNode * node4,
102 const SMDS_MeshNode * node5,
103 const SMDS_MeshNode * node6)
105 //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
107 myNodes = new const SMDS_MeshNode* [myNbNodes];
116 bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
119 if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
124 myNodes = new const SMDS_MeshNode* [myNbNodes];
125 for ( int i = 0; i < nbNodes; i++ )
126 myNodes[ i ] = nodes [ i ];
131 SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
133 if (myNodes != NULL) {
139 void SMDS_VolumeOfNodes::Print(ostream & OS) const
141 OS << "volume <" << GetID() << "> : ";
143 for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ",";
144 OS << myNodes[NbNodes()-1]<< ") " << endl;
147 int SMDS_VolumeOfNodes::NbFaces() const
155 default: MESSAGE("invalid number of nodes");
160 int SMDS_VolumeOfNodes::NbNodes() const
165 int SMDS_VolumeOfNodes::NbEdges() const
173 default: MESSAGE("invalid number of nodes");
179 * \brief Iterator on node of volume
181 class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
184 SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
185 SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
189 * \brief Iterator on faces or edges of volume
191 class _MySubIterator : public SMDS_ElemIterator
193 vector< const SMDS_MeshElement* > myElems;
196 _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) {
197 SMDS_VolumeTool vTool(vol);
198 if (type == SMDSAbs_Face)
199 vTool.GetAllExistingFaces( myElems );
201 vTool.GetAllExistingFaces( myElems );
203 /// Return true if and only if there are other object in this iterator
204 virtual bool more() { return myIndex < myElems.size(); }
206 /// Return the current object and step to the next one
207 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
210 SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
215 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
217 return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
219 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
221 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
223 MESSAGE("ERROR : Iterator not implemented");
224 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
228 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
230 return SMDSAbs_Volume;
234 * \brief Return node by its index
235 * \param ind - node index
236 * \retval const SMDS_MeshNode* - the node
238 const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
240 return myNodes[ ind ];
243 SMDSAbs_EntityType SMDS_VolumeOfNodes::GetEntityType() const
245 SMDSAbs_EntityType aType = SMDSEntity_Tetra;
248 case 4: aType = SMDSEntity_Tetra; break;
249 case 5: aType = SMDSEntity_Pyramid; break;
250 case 6: aType = SMDSEntity_Penta; break;
252 default: aType = SMDSEntity_Hexa; break;
257 SMDSAbs_GeometryType SMDS_VolumeOfNodes::GetGeomType() const
259 SMDSAbs_GeometryType aType = SMDSGeom_NONE;
262 case 4: aType = SMDSGeom_TETRA; break;
263 case 5: aType = SMDSGeom_PYRAMID; break;
264 case 6: aType = SMDSGeom_PENTA; break;
265 case 12: aType = SMDSGeom_HEXAGONAL_PRISM; break;
267 default: aType = SMDSGeom_HEXA; break;