1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 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 #pragma warning(disable:4786)
26 #include "SMDS_VolumeOfNodes.hxx"
27 #include "SMDS_MeshNode.hxx"
28 #include "SMDS_SetIterator.hxx"
29 #include "SMDS_VolumeTool.hxx"
30 #include "utilities.h"
36 ///////////////////////////////////////////////////////////////////////////////
37 /// Create an hexahedron. node 1,2,3,4 and 5,6,7,8 are quadrangle and
38 /// 5,1 and 7,3 are an edges.
39 ///////////////////////////////////////////////////////////////////////////////
40 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
41 const SMDS_MeshNode * node1,
42 const SMDS_MeshNode * node2,
43 const SMDS_MeshNode * node3,
44 const SMDS_MeshNode * node4,
45 const SMDS_MeshNode * node5,
46 const SMDS_MeshNode * node6,
47 const SMDS_MeshNode * node7,
48 const SMDS_MeshNode * node8)
51 myNodes = new const SMDS_MeshNode* [myNbNodes];
62 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
63 const SMDS_MeshNode * node1,
64 const SMDS_MeshNode * node2,
65 const SMDS_MeshNode * node3,
66 const SMDS_MeshNode * node4)
69 myNodes = new const SMDS_MeshNode* [myNbNodes];
76 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
77 const SMDS_MeshNode * node1,
78 const SMDS_MeshNode * node2,
79 const SMDS_MeshNode * node3,
80 const SMDS_MeshNode * node4,
81 const SMDS_MeshNode * node5)
84 myNodes = new const SMDS_MeshNode* [myNbNodes];
92 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
93 const SMDS_MeshNode * node1,
94 const SMDS_MeshNode * node2,
95 const SMDS_MeshNode * node3,
96 const SMDS_MeshNode * node4,
97 const SMDS_MeshNode * node5,
98 const SMDS_MeshNode * node6)
101 myNodes = new const SMDS_MeshNode* [myNbNodes];
110 bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
113 if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
118 myNodes = new const SMDS_MeshNode* [myNbNodes];
119 for ( int i = 0; i < nbNodes; i++ )
120 myNodes[ i ] = nodes [ i ];
125 SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
127 if (myNodes != NULL) {
133 //=======================================================================
136 //=======================================================================
138 void SMDS_VolumeOfNodes::Print(ostream & OS) const
140 OS << "volume <" << GetID() << "> : ";
142 for (i = 0; i < NbNodes(); ++i) OS << myNodes[i] << ",";
143 OS << myNodes[NbNodes()-1]<< ") " << endl;
146 int SMDS_VolumeOfNodes::NbFaces() const
154 default: MESSAGE("invalid number of nodes");
159 int SMDS_VolumeOfNodes::NbNodes() const
164 int SMDS_VolumeOfNodes::NbEdges() const
172 default: MESSAGE("invalid number of nodes");
177 /// ===================================================================
179 * \brief Iterator on node of volume
181 /// ===================================================================
183 class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
186 SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
187 SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
190 /// ===================================================================
192 * \brief Iterator on faces or edges of volume
194 /// ===================================================================
196 class _MySubIterator : public SMDS_ElemIterator
198 vector< const SMDS_MeshElement* > myElems;
201 _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) {
202 SMDS_VolumeTool vTool(vol);
203 if (type == SMDSAbs_Face)
204 vTool.GetAllExistingFaces( myElems );
206 vTool.GetAllExistingFaces( myElems );
208 /// Return true if and only if there are other object in this iterator
209 virtual bool more() { return myIndex < myElems.size(); }
211 /// Return the current object and step to the next one
212 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
215 SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
220 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
222 return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
224 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
226 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
228 MESSAGE("ERROR : Iterator not implemented");
229 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
233 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
235 return SMDSAbs_Volume;
239 * \brief Return node by its index
240 * \param ind - node index
241 * \retval const SMDS_MeshNode* - the node
243 * Index is wrapped if it is out of a valid range
245 const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
247 return myNodes[ WrappedIndex( ind )];