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_PolyhedralVolumeOfNodes.hxx"
27 #include "SMDS_MeshNode.hxx"
28 #include "SMDS_SetIterator.hxx"
29 #include "SMDS_VolumeTool.hxx"
30 #include "utilities.h"
36 //=======================================================================
37 //function : Constructor
38 //purpose : Create a volume of many faces
39 //=======================================================================
40 SMDS_PolyhedralVolumeOfNodes::SMDS_PolyhedralVolumeOfNodes
41 (vector<const SMDS_MeshNode *> nodes,
42 vector<int> quantities)
43 : SMDS_VolumeOfNodes(NULL, NULL, NULL, NULL)
45 ChangeNodes(nodes, quantities);
48 //=======================================================================
51 //=======================================================================
52 SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const
54 // return SMDSAbs_PolyhedralVolume;
55 return SMDSAbs_Volume;
58 //=======================================================================
59 //function : ChangeNodes
61 //=======================================================================
62 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const vector<const SMDS_MeshNode *>& nodes,
63 const vector<int>& quantities)
65 myNodesByFaces = nodes;
66 myQuantities = quantities;
68 // Init fields of parent class, it allows to get only unique nodes(?)
70 set<const SMDS_MeshNode *> aSet;
71 aSet.insert( nodes.begin(), nodes.end());
72 //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
74 myNbNodes = aSet.size();
75 myNodes = new const SMDS_MeshNode* [myNbNodes];
76 set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
77 for (int k=0; anIter != aSet.end(); anIter++, k++)
83 //=======================================================================
86 //=======================================================================
87 int SMDS_PolyhedralVolumeOfNodes::NbNodes() const
89 return myNodesByFaces.size();
92 //=======================================================================
95 //=======================================================================
96 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
100 for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
101 nbEdges += myQuantities[ifa];
108 //=======================================================================
111 //=======================================================================
112 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
114 return myQuantities.size();
117 //=======================================================================
118 //function : NbFaceNodes
120 //=======================================================================
121 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
123 if (face_ind < 1 || myQuantities.size() < face_ind)
125 return myQuantities[face_ind - 1];
128 //=======================================================================
129 //function : GetFaceNode
131 //=======================================================================
132 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
133 const int node_ind) const
135 if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
138 int i, first_node = 0;
139 for (i = 0; i < face_ind - 1; i++) {
140 first_node += myQuantities[i];
143 return myNodesByFaces[first_node + node_ind - 1];
146 //=======================================================================
149 //=======================================================================
150 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
152 OS << "polyhedral volume <" << GetID() << "> : ";
154 int faces_len = myQuantities.size();
155 //int nodes_len = myNodesByFaces.size();
156 int cur_first_node = 0;
159 for (i = 0; i < faces_len; i++) {
160 OS << "face_" << i << " (";
161 for (j = 0; j < myQuantities[i] - 1; j++) {
162 OS << myNodesByFaces[cur_first_node + j] << ",";
164 OS << myNodesByFaces[cur_first_node + j] << ") ";
165 cur_first_node += myQuantities[i];
169 //=======================================================================
170 //function : ChangeNodes
171 //purpose : usage disabled
172 //=======================================================================
173 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
179 /// ===================================================================
181 * \brief Iterator on node of volume
183 /// ===================================================================
185 struct _MyIterator:public SMDS_NodeVectorElemIterator
187 _MyIterator(const vector<const SMDS_MeshNode *>& nodes):
188 SMDS_NodeVectorElemIterator( nodes.begin(), nodes.end()) {}
191 /// ===================================================================
193 * \brief Iterator on faces or edges of volume
195 /// ===================================================================
197 class _MySubIterator : public SMDS_ElemIterator
199 vector< const SMDS_MeshElement* > myElems;
202 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
203 SMDS_VolumeTool vTool(vol);
204 if (type == SMDSAbs_Face)
205 vTool.GetAllExistingFaces( myElems );
207 vTool.GetAllExistingFaces( myElems );
209 /// Return true if and only if there are other object in this iterator
210 virtual bool more() { return myIndex < myElems.size(); }
212 /// Return the current object and step to the next one
213 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
216 //================================================================================
218 * \brief Return Iterator of sub elements
220 //================================================================================
222 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
227 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
229 return SMDS_ElemIteratorPtr(new _MyIterator(myNodesByFaces));
231 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
233 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
235 MESSAGE("ERROR : Iterator not implemented");
236 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
240 //================================================================================
242 * \brief Return iterator on unique nodes
244 //================================================================================
246 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::uniqueNodesIterator() const
248 return SMDS_ElemIteratorPtr
249 (new SMDS_NodeArrayElemIterator( myNodes, & myNodes[ myNbNodes ]));
252 //================================================================================
254 * \brief Return node by its index
256 //================================================================================
258 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetNode(const int ind) const
260 return myNodesByFaces[ WrappedIndex( ind )];