Salome HOME
Update mail address
[modules/smesh.git] / src / SMDS / SMDS_PolyhedralVolumeOfNodes.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #ifdef _MSC_VER
23 #pragma warning(disable:4786)
24 #endif
25
26 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
27 #include "SMDS_MeshNode.hxx"
28 #include "utilities.h"
29
30 #include <set>
31
32 using namespace std;
33
34 //=======================================================================
35 //function : Constructor
36 //purpose  : Create a volume of many faces
37 //=======================================================================
38 SMDS_PolyhedralVolumeOfNodes::SMDS_PolyhedralVolumeOfNodes
39                                 (std::vector<const SMDS_MeshNode *> nodes,
40                                  std::vector<int>                   quantities)
41 : SMDS_VolumeOfNodes(NULL, NULL, NULL, NULL)
42 {
43   ChangeNodes(nodes, quantities);
44 }
45
46 //=======================================================================
47 //function : GetType
48 //purpose  : 
49 //=======================================================================
50 SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const
51 {
52 //  return SMDSAbs_PolyhedralVolume;
53   return SMDSAbs_Volume;
54 }
55
56 //=======================================================================
57 //function : ChangeNodes
58 //purpose  : 
59 //=======================================================================
60 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes,
61                                                 std::vector<int>                   quantities)
62 {
63   myNodesByFaces = nodes;
64   myQuantities = quantities;
65
66   // Init fields of parent class
67   int aNbNodes = 0;
68   std::set<const SMDS_MeshNode *> aSet;
69   int nodes_len = nodes.size();
70   for (int j = 0; j < nodes_len; j++) {
71     if (aSet.find(nodes[j]) == aSet.end()) {
72       aSet.insert(nodes[j]);
73       aNbNodes++;
74     }
75   }
76
77   int k = 0;
78 #ifndef WNT
79   const SMDS_MeshNode* aNodes [aNbNodes];
80 #else
81   const SMDS_MeshNode** aNodes = (const SMDS_MeshNode **)new SMDS_MeshNode*[aNbNodes];
82 #endif
83   std::set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
84   for (; anIter != aSet.end(); anIter++, k++) {
85     aNodes[k] = *anIter;
86   }
87
88   //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
89   delete [] myNodes;
90   //myNbNodes = nodes.size();
91   myNbNodes = aNbNodes;
92   myNodes = new const SMDS_MeshNode* [myNbNodes];
93   for (int i = 0; i < myNbNodes; i++) {
94     //myNodes[i] = nodes[i];
95     myNodes[i] = aNodes[i];
96   }
97
98 #ifdef WNT
99   delete [] aNodes;
100 #endif
101
102   return true;
103 }
104
105 //=======================================================================
106 //function : NbEdges
107 //purpose  : 
108 //=======================================================================
109 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
110 {
111   int nbEdges = 0;
112
113   for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
114     nbEdges += myQuantities[ifa];
115   }
116   nbEdges /= 2;
117
118   return nbEdges;
119 }
120
121 //=======================================================================
122 //function : NbFaces
123 //purpose  : 
124 //=======================================================================
125 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
126 {
127   return myQuantities.size();
128 }
129
130 //=======================================================================
131 //function : NbFaceNodes
132 //purpose  : 
133 //=======================================================================
134 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
135 {
136   if (face_ind < 1 || myQuantities.size() < face_ind)
137     return 0;
138   return myQuantities[face_ind - 1];
139 }
140
141 //=======================================================================
142 //function : GetFaceNode
143 //purpose  : 
144 //=======================================================================
145 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
146                                                                 const int node_ind) const
147 {
148   if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
149     return NULL;
150
151   int i, first_node = 0;
152   for (i = 0; i < face_ind - 1; i++) {
153     first_node += myQuantities[i];
154   }
155
156   return myNodesByFaces[first_node + node_ind - 1];
157 }
158
159 //=======================================================================
160 //function : Print
161 //purpose  : 
162 //=======================================================================
163 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
164 {
165   OS << "polyhedral volume <" << GetID() << "> : ";
166
167   int faces_len = myQuantities.size();
168   //int nodes_len = myNodesByFaces.size();
169   int cur_first_node = 0;
170
171   int i, j;
172   for (i = 0; i < faces_len; i++) {
173     OS << "face_" << i << " (";
174     for (j = 0; j < myQuantities[i] - 1; j++) {
175       OS << myNodesByFaces[cur_first_node + j] << ",";
176     }
177     OS << myNodesByFaces[cur_first_node + j] << ") ";
178     cur_first_node += myQuantities[i];
179   }
180 }
181
182 //=======================================================================
183 //function : ChangeNodes
184 //purpose  : usage disabled
185 //=======================================================================
186 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
187                                                 const int            nbNodes)
188 {
189   return false;
190 }