1 // Copyright (C) 2007-2012 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 //MESSAGE("****************************************** SMDS_PolyhedralVolumeOfNodes");
49 ChangeNodes(nodes, quantities);
52 //=======================================================================
55 //=======================================================================
56 SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const
58 // return SMDSAbs_PolyhedralVolume;
59 return SMDSAbs_Volume;
62 //=======================================================================
63 //function : ChangeNodes
65 //=======================================================================
66 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const vector<const SMDS_MeshNode *>& nodes,
67 const vector<int>& quantities)
69 myNodesByFaces = nodes;
70 myQuantities = quantities;
72 // Init fields of parent class, it allows to get only unique nodes(?)
74 set<const SMDS_MeshNode *> aSet;
75 aSet.insert( nodes.begin(), nodes.end());
76 //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
78 myNbNodes = aSet.size();
79 myNodes = new const SMDS_MeshNode* [myNbNodes];
80 set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
81 for (int k=0; anIter != aSet.end(); anIter++, k++)
87 //=======================================================================
90 //=======================================================================
91 int SMDS_PolyhedralVolumeOfNodes::NbNodes() const
93 return myNodesByFaces.size();
96 //=======================================================================
99 //=======================================================================
100 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
104 for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
105 nbEdges += myQuantities[ifa];
112 //=======================================================================
115 //=======================================================================
116 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
118 return myQuantities.size();
121 //=======================================================================
122 //function : NbFaceNodes
124 //=======================================================================
125 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
127 if (face_ind < 1 || myQuantities.size() < face_ind)
129 return myQuantities[face_ind - 1];
132 //=======================================================================
133 //function : GetFaceNode
135 //=======================================================================
136 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
137 const int node_ind) const
139 if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
142 int i, first_node = 0;
143 for (i = 0; i < face_ind - 1; i++) {
144 first_node += myQuantities[i];
147 return myNodesByFaces[first_node + node_ind - 1];
150 //=======================================================================
153 //=======================================================================
154 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
156 OS << "polyhedral volume <" << GetID() << "> : ";
158 int faces_len = myQuantities.size();
159 //int nodes_len = myNodesByFaces.size();
160 int cur_first_node = 0;
163 for (i = 0; i < faces_len; i++) {
164 OS << "face_" << i << " (";
165 for (j = 0; j < myQuantities[i] - 1; j++) {
166 OS << myNodesByFaces[cur_first_node + j] << ",";
168 OS << myNodesByFaces[cur_first_node + j] << ") ";
169 cur_first_node += myQuantities[i];
173 //=======================================================================
174 //function : ChangeNodes
175 //purpose : usage disabled
176 //=======================================================================
177 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
183 /// ===================================================================
185 * \brief Iterator on node of volume
187 /// ===================================================================
189 struct _MyIterator:public SMDS_NodeVectorElemIterator
191 _MyIterator(const vector<const SMDS_MeshNode *>& nodes):
192 SMDS_NodeVectorElemIterator( nodes.begin(), nodes.end()) {}
195 /// ===================================================================
197 * \brief Iterator on faces or edges of volume
199 /// ===================================================================
201 class _MySubIterator : public SMDS_ElemIterator
203 vector< const SMDS_MeshElement* > myElems;
206 _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
207 SMDS_VolumeTool vTool(vol);
208 if (type == SMDSAbs_Face)
209 vTool.GetAllExistingFaces( myElems );
211 vTool.GetAllExistingEdges( myElems );
213 /// Return true if and only if there are other object in this iterator
214 virtual bool more() { return myIndex < myElems.size(); }
216 /// Return the current object and step to the next one
217 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
220 //================================================================================
222 * \brief Return Iterator of sub elements
224 //================================================================================
226 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
231 return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
233 return SMDS_ElemIteratorPtr(new _MyIterator(myNodesByFaces));
235 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
237 return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
239 MESSAGE("ERROR : Iterator not implemented");
240 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
244 //================================================================================
246 * \brief Return iterator on unique nodes
248 //================================================================================
250 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::uniqueNodesIterator() const
252 return SMDS_ElemIteratorPtr
253 (new SMDS_NodeArrayElemIterator( myNodes, & myNodes[ myNbNodes ]));
256 //================================================================================
258 * \brief Return node by its index
260 //================================================================================
262 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetNode(const int ind) const
264 return myNodesByFaces[ ind ];