Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMDS / SMDSControl.cxx
1 using namespace std;
2 // File:        SMDSControl.cxx
3 // Created:     Wed Feb 20 18:33:06 2002
4 // Author:      Jean-Michel BOULCOURT
5 //              <jmb@localhost.localdomain>
6
7
8 #include "SMDSControl.ixx"
9 #include "SMDS_Mesh.hxx"
10 #include "SMDS_MeshElement.hxx"
11 #include "SMDS_ListOfMeshElement.hxx"
12 #include "SMDS_ListIteratorOfListOfMeshElement.hxx"
13
14 //=======================================================================
15 //function : ComputeNeighborFaces
16 //purpose  : 
17 //=======================================================================
18
19 Standard_Integer SMDSControl::ComputeNeighborFaces(const Handle(SMDS_Mesh)& M,
20                                                    const Handle(SMDS_MeshElement)& ME,
21                                                    const Standard_Integer idnode1,
22                                                    const Standard_Integer idnode2)
23 {
24   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
25   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
26   const SMDS_ListOfMeshElement& lstInvFaces1 = node1->InverseElements();
27   const SMDS_ListOfMeshElement& lstInvFaces2 = node2->InverseElements();
28   Standard_Integer neighbor=0;
29
30   SMDS_ListIteratorOfListOfMeshElement it1(lstInvFaces1);
31   for (;it1.More();it1.Next()) {
32     const Handle(SMDS_MeshElement)& face = it1.Value();
33     if (M->Contains(face) && !face->IsSame(ME)) {
34       if (face->IsNodeInElement(idnode1) && face->IsNodeInElement(idnode2)) {
35         neighbor++;
36       }
37     }
38   }
39
40   if (neighbor > 0) {
41     return neighbor;
42   }
43
44   SMDS_ListIteratorOfListOfMeshElement it2(lstInvFaces2);
45   for (;it2.More();it2.Next()) {
46     const Handle(SMDS_MeshElement)& face = it2.Value();
47     if (M->Contains(face) && !face->IsSame(ME)) {
48       if (face->IsNodeInElement(idnode1) && face->IsNodeInElement(idnode2)) {
49         neighbor++;
50       }
51     }
52   }
53
54   return neighbor;
55 }
56
57 //=======================================================================
58 //function : ComputeNeighborVolumes
59 //purpose  : 
60 //=======================================================================
61
62 Standard_Integer SMDSControl::ComputeNeighborVolumes(const Handle(SMDS_Mesh)& M,
63                                                      const Handle(SMDS_MeshElement)& ME,
64                                                      const Standard_Integer idnode1,
65                                                      const Standard_Integer idnode2,
66                                                      const Standard_Integer idnode3)
67 {
68
69   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
70   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
71   const Handle(SMDS_MeshElement)& node3 = M->FindNode(idnode3);
72   const SMDS_ListOfMeshElement& lstInvVol1 = node1->InverseElements();
73   const SMDS_ListOfMeshElement& lstInvVol2 = node2->InverseElements();
74   const SMDS_ListOfMeshElement& lstInvVol3 = node3->InverseElements();
75   
76   Standard_Integer neighbor=0;
77
78   SMDS_ListIteratorOfListOfMeshElement it1(lstInvVol1);
79   for (;it1.More() && neighbor == 0;it1.Next()) {
80     const Handle(SMDS_MeshElement)& vol = it1.Value();
81     if (M->Contains(vol) && !vol->IsSame(ME)) {
82       if (vol->IsNodeInElement(idnode1)
83           && vol->IsNodeInElement(idnode2)
84           && vol->IsNodeInElement(idnode3)) {
85         neighbor++;
86       }
87     }
88   }
89   
90   if (neighbor > 0) {
91     return neighbor;
92   }
93   
94   SMDS_ListIteratorOfListOfMeshElement it2(lstInvVol2);
95   for (;it2.More() && neighbor == 0;it2.Next()) {
96     const Handle(SMDS_MeshElement)& vol = it2.Value();
97     if (M->Contains(vol) && !vol->IsSame(ME)) {
98       if (vol->IsNodeInElement(idnode1) 
99           && vol->IsNodeInElement(idnode2)
100           && vol->IsNodeInElement(idnode3)) {
101         neighbor++;
102       }
103     }
104   }
105   
106   if (neighbor > 0) {
107     return neighbor;
108   }
109   
110   SMDS_ListIteratorOfListOfMeshElement it3(lstInvVol3);
111   for (;it3.More() && neighbor == 0;it3.Next()) {
112     const Handle(SMDS_MeshElement)& vol = it3.Value();
113     if (M->Contains(vol) && !vol->IsSame(ME)) {
114       if (vol->IsNodeInElement(idnode1)
115           && vol->IsNodeInElement(idnode2)
116           && vol->IsNodeInElement(idnode3)) {
117         neighbor++;
118       }
119     }
120   }
121   
122   return neighbor;
123
124 }
125
126 //=======================================================================
127 //function : ComputeNeighborVolumes
128 //purpose  : 
129 //=======================================================================
130
131 Standard_Integer SMDSControl::ComputeNeighborVolumes(const Handle(SMDS_Mesh)& M,
132                                                      const Handle(SMDS_MeshElement)& ME,
133                                                      const Standard_Integer idnode1,
134                                                      const Standard_Integer idnode2,
135                                                      const Standard_Integer idnode3,
136                                                      const Standard_Integer idnode4)
137 {
138
139   const Handle(SMDS_MeshElement)& node1 = M->FindNode(idnode1);
140   const Handle(SMDS_MeshElement)& node2 = M->FindNode(idnode2);
141   const Handle(SMDS_MeshElement)& node3 = M->FindNode(idnode3);
142   const Handle(SMDS_MeshElement)& node4 = M->FindNode(idnode4);
143   const SMDS_ListOfMeshElement& lstInvVol1 = node1->InverseElements();
144   const SMDS_ListOfMeshElement& lstInvVol2 = node2->InverseElements();
145   const SMDS_ListOfMeshElement& lstInvVol3 = node3->InverseElements();
146   const SMDS_ListOfMeshElement& lstInvVol4 = node4->InverseElements();
147   Standard_Integer neighbor=0;
148
149   SMDS_ListIteratorOfListOfMeshElement it1(lstInvVol1);
150   for (;it1.More();it1.Next()) {
151     const Handle(SMDS_MeshElement)& vol = it1.Value();
152     if (M->Contains(vol) && !vol->IsSame(ME)) {
153       if (   vol->IsNodeInElement(idnode1) 
154           && vol->IsNodeInElement(idnode2)
155           && vol->IsNodeInElement(idnode3)
156           && vol->IsNodeInElement(idnode4)) {
157         neighbor++;
158       }
159     }
160   }
161
162   if (neighbor >= 2) {
163     return neighbor;
164   }
165
166   SMDS_ListIteratorOfListOfMeshElement it2(lstInvVol2);
167   for (;it2.More();it2.Next()) {
168     const Handle(SMDS_MeshElement)& vol = it2.Value();
169     if (M->Contains(vol) && !vol->IsSame(ME)) {
170       if (   vol->IsNodeInElement(idnode1) 
171           && vol->IsNodeInElement(idnode2)
172           && vol->IsNodeInElement(idnode3)
173           && vol->IsNodeInElement(idnode4)) {
174         neighbor++;
175       }
176     }
177   }
178
179   if (neighbor >= 2) {
180     return neighbor;
181   }
182
183   SMDS_ListIteratorOfListOfMeshElement it3(lstInvVol3);
184   for (;it3.More();it3.Next()) {
185     const Handle(SMDS_MeshElement)& vol = it3.Value();
186     if (M->Contains(vol) && !vol->IsSame(ME)) {
187       if (   vol->IsNodeInElement(idnode1) 
188           && vol->IsNodeInElement(idnode2)
189           && vol->IsNodeInElement(idnode3)
190           && vol->IsNodeInElement(idnode4)) {
191         neighbor++;
192       }
193     }
194   }
195
196   if (neighbor >= 2) {
197     return neighbor;
198   }
199
200   SMDS_ListIteratorOfListOfMeshElement it4(lstInvVol4);
201   for (;it4.More();it4.Next()) {
202     const Handle(SMDS_MeshElement)& vol = it4.Value();
203     if (M->Contains(vol) && !vol->IsSame(ME)) {
204       if (   vol->IsNodeInElement(idnode1) 
205           && vol->IsNodeInElement(idnode2)
206           && vol->IsNodeInElement(idnode3)
207           && vol->IsNodeInElement(idnode4)) {
208         neighbor++;
209       }
210     }
211   }
212
213   return neighbor;
214 }