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
25 #pragma warning(disable:4786)
28 #include "SMDS_VolumeOfNodes.hxx"
29 #include "SMDS_MeshNode.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMDS_VolumeTool.hxx"
32 #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 //=======================================================================
138 //=======================================================================
140 void SMDS_VolumeOfNodes::Print(ostream & OS) const
142 OS << "volume <" << GetID() << "> : ";
144 for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ",";
145 OS << myNodes[NbNodes()-1]<< ") " << endl;
148 int SMDS_VolumeOfNodes::NbFaces() const
156 default: MESSAGE("invalid number of nodes");
161 int SMDS_VolumeOfNodes::NbNodes() const
166 int SMDS_VolumeOfNodes::NbEdges() const
174 default: MESSAGE("invalid number of nodes");
179 /// ===================================================================
181 * \brief Iterator on node of volume
183 /// ===================================================================
185 class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
188 SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
189 SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
192 /// ===================================================================
194 * \brief Iterator on faces or edges of volume
196 /// ===================================================================
198 class _MySubIterator : public SMDS_ElemIterator
200 vector< const SMDS_MeshElement* > myElems;
203 _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) {
204 SMDS_VolumeTool vTool(vol);
205 if (type == SMDSAbs_Face)
206 vTool.GetAllExistingFaces( myElems );
208 vTool.GetAllExistingFaces( myElems );
210 /// Return true if and only if there are other object in this iterator
211 virtual bool more() { return myIndex < myElems.size(); }
213 /// Return the current object and step to the next one
214 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
217 SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
222 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
224 return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
226 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
228 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
230 MESSAGE("ERROR : Iterator not implemented");
231 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
235 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
237 return SMDSAbs_Volume;
241 * \brief Return node by its index
242 * \param ind - node index
243 * \retval const SMDS_MeshNode* - the node
245 const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
247 return myNodes[ ind ];
250 SMDSAbs_EntityType SMDS_VolumeOfNodes::GetEntityType() const
252 SMDSAbs_EntityType aType = SMDSEntity_Tetra;
255 case 4: aType = SMDSEntity_Tetra; break;
256 case 5: aType = SMDSEntity_Pyramid; break;
257 case 6: aType = SMDSEntity_Penta; break;
259 default: aType = SMDSEntity_Hexa; break;