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_PolyhedralVolumeOfNodes.hxx"
30 #include "SMDS_MeshNode.hxx"
31 #include "SMDS_SetIterator.hxx"
32 #include "SMDS_VolumeTool.hxx"
33 #include "utilities.h"
39 //=======================================================================
40 //function : Constructor
41 //purpose : Create a volume of many faces
42 //=======================================================================
43 SMDS_PolyhedralVolumeOfNodes::SMDS_PolyhedralVolumeOfNodes
44 (vector<const SMDS_MeshNode *> nodes,
45 vector<int> quantities)
46 : SMDS_VolumeOfNodes(NULL, NULL, NULL, NULL)
48 ChangeNodes(nodes, quantities);
51 //=======================================================================
54 //=======================================================================
55 SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const
57 // return SMDSAbs_PolyhedralVolume;
58 return SMDSAbs_Volume;
61 //=======================================================================
62 //function : ChangeNodes
64 //=======================================================================
65 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const vector<const SMDS_MeshNode *>& nodes,
66 const vector<int>& quantities)
68 myNodesByFaces = nodes;
69 myQuantities = quantities;
71 // Init fields of parent class, it allows to get only unique nodes(?)
73 set<const SMDS_MeshNode *> aSet;
74 aSet.insert( nodes.begin(), nodes.end());
75 //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
77 myNbNodes = aSet.size();
78 myNodes = new const SMDS_MeshNode* [myNbNodes];
79 set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
80 for (int k=0; anIter != aSet.end(); anIter++, k++)
86 //=======================================================================
89 //=======================================================================
90 int SMDS_PolyhedralVolumeOfNodes::NbNodes() const
92 return myNodesByFaces.size();
95 //=======================================================================
98 //=======================================================================
99 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
103 for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
104 nbEdges += myQuantities[ifa];
111 //=======================================================================
114 //=======================================================================
115 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
117 return myQuantities.size();
120 //=======================================================================
121 //function : NbFaceNodes
123 //=======================================================================
124 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
126 if (face_ind < 1 || myQuantities.size() < face_ind)
128 return myQuantities[face_ind - 1];
131 //=======================================================================
132 //function : GetFaceNode
134 //=======================================================================
135 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
136 const int node_ind) const
138 if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
141 int i, first_node = 0;
142 for (i = 0; i < face_ind - 1; i++) {
143 first_node += myQuantities[i];
146 return myNodesByFaces[first_node + node_ind - 1];
149 //=======================================================================
152 //=======================================================================
153 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
155 OS << "polyhedral volume <" << GetID() << "> : ";
157 int faces_len = myQuantities.size();
158 //int nodes_len = myNodesByFaces.size();
159 int cur_first_node = 0;
162 for (i = 0; i < faces_len; i++) {
163 OS << "face_" << i << " (";
164 for (j = 0; j < myQuantities[i] - 1; j++) {
165 OS << myNodesByFaces[cur_first_node + j] << ",";
167 OS << myNodesByFaces[cur_first_node + j] << ") ";
168 cur_first_node += myQuantities[i];
172 //=======================================================================
173 //function : ChangeNodes
174 //purpose : usage disabled
175 //=======================================================================
176 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
182 /// ===================================================================
184 * \brief Iterator on node of volume
186 /// ===================================================================
188 struct _MyIterator:public SMDS_NodeVectorElemIterator
190 _MyIterator(const vector<const SMDS_MeshNode *>& nodes):
191 SMDS_NodeVectorElemIterator( nodes.begin(), nodes.end()) {}
194 /// ===================================================================
196 * \brief Iterator on faces or edges of volume
198 /// ===================================================================
200 class _MySubIterator : public SMDS_ElemIterator
202 vector< const SMDS_MeshElement* > myElems;
205 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
206 SMDS_VolumeTool vTool(vol);
207 if (type == SMDSAbs_Face)
208 vTool.GetAllExistingFaces( myElems );
210 vTool.GetAllExistingEdges( myElems );
212 /// Return true if and only if there are other object in this iterator
213 virtual bool more() { return myIndex < myElems.size(); }
215 /// Return the current object and step to the next one
216 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
219 //================================================================================
221 * \brief Return Iterator of sub elements
223 //================================================================================
225 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
230 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
232 return SMDS_ElemIteratorPtr(new _MyIterator(myNodesByFaces));
234 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
236 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
238 MESSAGE("ERROR : Iterator not implemented");
239 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
243 //================================================================================
245 * \brief Return iterator on unique nodes
247 //================================================================================
249 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::uniqueNodesIterator() const
251 return SMDS_ElemIteratorPtr
252 (new SMDS_NodeArrayElemIterator( myNodes, & myNodes[ myNbNodes ]));
255 //================================================================================
257 * \brief Return node by its index
259 //================================================================================
261 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetNode(const int ind) const
263 return myNodesByFaces[ ind ];