Salome HOME
activateModule/deactivateModule functions are made "bool".
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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   const SMDS_MeshNode* aNodes [aNbNodes];
79   std::set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
80   for (; anIter != aSet.end(); anIter++, k++) {
81     aNodes[k] = *anIter;
82   }
83
84   //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
85   delete [] myNodes;
86   //myNbNodes = nodes.size();
87   myNbNodes = aNbNodes;
88   myNodes = new const SMDS_MeshNode* [myNbNodes];
89   for (int i = 0; i < myNbNodes; i++) {
90     //myNodes[i] = nodes[i];
91     myNodes[i] = aNodes[i];
92   }
93
94   return true;
95 }
96
97 //=======================================================================
98 //function : NbEdges
99 //purpose  : 
100 //=======================================================================
101 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
102 {
103   int nbEdges = 0;
104
105   for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
106     nbEdges += myQuantities[ifa];
107   }
108   nbEdges /= 2;
109
110   return nbEdges;
111 }
112
113 //=======================================================================
114 //function : NbFaces
115 //purpose  : 
116 //=======================================================================
117 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
118 {
119   return myQuantities.size();
120 }
121
122 //=======================================================================
123 //function : NbFaceNodes
124 //purpose  : 
125 //=======================================================================
126 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
127 {
128   if (face_ind < 1 || myQuantities.size() < face_ind)
129     return 0;
130   return myQuantities[face_ind - 1];
131 }
132
133 //=======================================================================
134 //function : GetFaceNode
135 //purpose  : 
136 //=======================================================================
137 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
138                                                                 const int node_ind) const
139 {
140   if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
141     return NULL;
142
143   int i, first_node = 0;
144   for (i = 0; i < face_ind - 1; i++) {
145     first_node += myQuantities[i];
146   }
147
148   return myNodesByFaces[first_node + node_ind - 1];
149 }
150
151 //=======================================================================
152 //function : Print
153 //purpose  : 
154 //=======================================================================
155 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
156 {
157   OS << "polyhedral volume <" << GetID() << "> : ";
158
159   int faces_len = myQuantities.size();
160   //int nodes_len = myNodesByFaces.size();
161   int cur_first_node = 0;
162
163   int i, j;
164   for (i = 0; i < faces_len; i++) {
165     OS << "face_" << i << " (";
166     for (j = 0; j < myQuantities[i] - 1; j++) {
167       OS << myNodesByFaces[cur_first_node + j] << ",";
168     }
169     OS << myNodesByFaces[cur_first_node + j] << ") ";
170     cur_first_node += myQuantities[i];
171   }
172 }
173
174 //=======================================================================
175 //function : ChangeNodes
176 //purpose  : usage disabled
177 //=======================================================================
178 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
179                                                 const int            nbNodes)
180 {
181   return false;
182 }