Salome HOME
Some forgotten return statments
[modules/smesh.git] / src / SMDS / SMDSControl.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.opencascade.org or email : webmaster@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMDSControl.cxx
24 //  Author : Jean-Michel BOULCOURT
25 //  Module : SMESH
26
27 using namespace std;
28 #include "SMDSControl.ixx"
29 #include "SMDS_Mesh.hxx"
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_ListOfMeshElement.hxx"
32 #include "SMDS_ListIteratorOfListOfMeshElement.hxx"
33
34 //=======================================================================
35 //function : ComputeNeighborFaces
36 //purpose  : 
37 //=======================================================================
38
39 Standard_Integer SMDSControl::ComputeNeighborFaces(const Handle(SMDS_Mesh)& M,
40                                                    const Handle(SMDS_MeshElement)& ME,
41                                                    const Standard_Integer idnode1,
42                                                    const Standard_Integer idnode2)
43 {
44   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
45   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
46   const SMDS_ListOfMeshElement& lstInvFaces1 = node1->InverseElements();
47   const SMDS_ListOfMeshElement& lstInvFaces2 = node2->InverseElements();
48   Standard_Integer neighbor=0;
49
50   SMDS_ListIteratorOfListOfMeshElement it1(lstInvFaces1);
51   for (;it1.More();it1.Next()) {
52     const Handle(SMDS_MeshElement)& face = it1.Value();
53     if (M->Contains(face) && !face->IsSame(ME)) {
54       if (face->IsNodeInElement(idnode1) && face->IsNodeInElement(idnode2)) {
55         neighbor++;
56       }
57     }
58   }
59
60   if (neighbor > 0) {
61     return neighbor;
62   }
63
64   SMDS_ListIteratorOfListOfMeshElement it2(lstInvFaces2);
65   for (;it2.More();it2.Next()) {
66     const Handle(SMDS_MeshElement)& face = it2.Value();
67     if (M->Contains(face) && !face->IsSame(ME)) {
68       if (face->IsNodeInElement(idnode1) && face->IsNodeInElement(idnode2)) {
69         neighbor++;
70       }
71     }
72   }
73
74   return neighbor;
75 }
76
77 //=======================================================================
78 //function : ComputeNeighborVolumes
79 //purpose  : 
80 //=======================================================================
81
82 Standard_Integer SMDSControl::ComputeNeighborVolumes(const Handle(SMDS_Mesh)& M,
83                                                      const Handle(SMDS_MeshElement)& ME,
84                                                      const Standard_Integer idnode1,
85                                                      const Standard_Integer idnode2,
86                                                      const Standard_Integer idnode3)
87 {
88
89   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
90   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
91   const Handle(SMDS_MeshElement)& node3 = M->FindNode(idnode3);
92   const SMDS_ListOfMeshElement& lstInvVol1 = node1->InverseElements();
93   const SMDS_ListOfMeshElement& lstInvVol2 = node2->InverseElements();
94   const SMDS_ListOfMeshElement& lstInvVol3 = node3->InverseElements();
95   
96   Standard_Integer neighbor=0;
97
98   SMDS_ListIteratorOfListOfMeshElement it1(lstInvVol1);
99   for (;it1.More() && neighbor == 0;it1.Next()) {
100     const Handle(SMDS_MeshElement)& vol = it1.Value();
101     if (M->Contains(vol) && !vol->IsSame(ME)) {
102       if (vol->IsNodeInElement(idnode1)
103           && vol->IsNodeInElement(idnode2)
104           && vol->IsNodeInElement(idnode3)) {
105         neighbor++;
106       }
107     }
108   }
109   
110   if (neighbor > 0) {
111     return neighbor;
112   }
113   
114   SMDS_ListIteratorOfListOfMeshElement it2(lstInvVol2);
115   for (;it2.More() && neighbor == 0;it2.Next()) {
116     const Handle(SMDS_MeshElement)& vol = it2.Value();
117     if (M->Contains(vol) && !vol->IsSame(ME)) {
118       if (vol->IsNodeInElement(idnode1) 
119           && vol->IsNodeInElement(idnode2)
120           && vol->IsNodeInElement(idnode3)) {
121         neighbor++;
122       }
123     }
124   }
125   
126   if (neighbor > 0) {
127     return neighbor;
128   }
129   
130   SMDS_ListIteratorOfListOfMeshElement it3(lstInvVol3);
131   for (;it3.More() && neighbor == 0;it3.Next()) {
132     const Handle(SMDS_MeshElement)& vol = it3.Value();
133     if (M->Contains(vol) && !vol->IsSame(ME)) {
134       if (vol->IsNodeInElement(idnode1)
135           && vol->IsNodeInElement(idnode2)
136           && vol->IsNodeInElement(idnode3)) {
137         neighbor++;
138       }
139     }
140   }
141   
142   return neighbor;
143
144 }
145
146 //=======================================================================
147 //function : ComputeNeighborVolumes
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Integer SMDSControl::ComputeNeighborVolumes(const Handle(SMDS_Mesh)& M,
152                                                      const Handle(SMDS_MeshElement)& ME,
153                                                      const Standard_Integer idnode1,
154                                                      const Standard_Integer idnode2,
155                                                      const Standard_Integer idnode3,
156                                                      const Standard_Integer idnode4)
157 {
158
159   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
160   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
161   const Handle(SMDS_MeshElement)& node3 = M->FindNode(idnode3);
162   const Handle(SMDS_MeshElement)& node4 = M->FindNode(idnode4);
163   const SMDS_ListOfMeshElement& lstInvVol1 = node1->InverseElements();
164   const SMDS_ListOfMeshElement& lstInvVol2 = node2->InverseElements();
165   const SMDS_ListOfMeshElement& lstInvVol3 = node3->InverseElements();
166   const SMDS_ListOfMeshElement& lstInvVol4 = node4->InverseElements();
167   Standard_Integer neighbor=0;
168
169   SMDS_ListIteratorOfListOfMeshElement it1(lstInvVol1);
170   for (;it1.More();it1.Next()) {
171     const Handle(SMDS_MeshElement)& vol = it1.Value();
172     if (M->Contains(vol) && !vol->IsSame(ME)) {
173       if (   vol->IsNodeInElement(idnode1) 
174           && vol->IsNodeInElement(idnode2)
175           && vol->IsNodeInElement(idnode3)
176           && vol->IsNodeInElement(idnode4)) {
177         neighbor++;
178       }
179     }
180   }
181
182   if (neighbor >= 2) {
183     return neighbor;
184   }
185
186   SMDS_ListIteratorOfListOfMeshElement it2(lstInvVol2);
187   for (;it2.More();it2.Next()) {
188     const Handle(SMDS_MeshElement)& vol = it2.Value();
189     if (M->Contains(vol) && !vol->IsSame(ME)) {
190       if (   vol->IsNodeInElement(idnode1) 
191           && vol->IsNodeInElement(idnode2)
192           && vol->IsNodeInElement(idnode3)
193           && vol->IsNodeInElement(idnode4)) {
194         neighbor++;
195       }
196     }
197   }
198
199   if (neighbor >= 2) {
200     return neighbor;
201   }
202
203   SMDS_ListIteratorOfListOfMeshElement it3(lstInvVol3);
204   for (;it3.More();it3.Next()) {
205     const Handle(SMDS_MeshElement)& vol = it3.Value();
206     if (M->Contains(vol) && !vol->IsSame(ME)) {
207       if (   vol->IsNodeInElement(idnode1) 
208           && vol->IsNodeInElement(idnode2)
209           && vol->IsNodeInElement(idnode3)
210           && vol->IsNodeInElement(idnode4)) {
211         neighbor++;
212       }
213     }
214   }
215
216   if (neighbor >= 2) {
217     return neighbor;
218   }
219
220   SMDS_ListIteratorOfListOfMeshElement it4(lstInvVol4);
221   for (;it4.More();it4.Next()) {
222     const Handle(SMDS_MeshElement)& vol = it4.Value();
223     if (M->Contains(vol) && !vol->IsSame(ME)) {
224       if (   vol->IsNodeInElement(idnode1) 
225           && vol->IsNodeInElement(idnode2)
226           && vol->IsNodeInElement(idnode3)
227           && vol->IsNodeInElement(idnode4)) {
228         neighbor++;
229       }
230     }
231   }
232
233   return neighbor;
234 }