Moka libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mg-merge.cc
Go to the documentation of this file.
1 /*
2  * lib-mesh : Opérations de maillage et lissage.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-mesh
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "mesh-generic.hh"
26 #include "g-map-generic.hh"
27 #include <cassert>
28 using namespace GMap3d;
29 //******************************************************************************
30 bool CMeshGeneric::canMergeEdgeAndMesh1(CDart* AEdgeDart,
31  CDart* AMesh1Corners[2])
32 {
33  assert(AEdgeDart!=NULL);
34  assert(AMesh1Corners!=NULL);
35 
36  return
37  ! FMap->isFree0(AMesh1Corners[0]) && ! FMap->isFree0(AMesh1Corners[1]) &&
38  ! FMap->isSameOrbit(AMesh1Corners[0], AMesh1Corners[1], ORBIT_23) &&
39  isTopoEdge(AEdgeDart, AMesh1Corners[0]) &
40  isTopoEdge(AEdgeDart, AMesh1Corners[1]);
41 }
42 //------------------------------------------------------------------------------
43 void CMeshGeneric::mergeEdgeAndMesh1(CDart* AEdgeDart,
44  CDart* AMesh1Extremities[2])
45 {
46  assert(canMergeEdgeAndMesh1(AEdgeDart, AMesh1Extremities));
47 
48  CDart* edges[2] = { AEdgeDart, FMap->alpha0(AEdgeDart) };
49 
50  // Ouverture:
51  FMap->unsew0(AEdgeDart);
52 
53  // Fusion:
54  for (int i=0; i<2; ++i)
55  {
56  CDart* mesh = FMap->alpha0(AMesh1Extremities[i]);
57 
58  FMap->unsew0(AMesh1Extremities[i]);
59 
60  for (CStaticCoverage23 cov(FMap, AMesh1Extremities[i]); cov.cont(); ++cov)
61  FMap->delMapDart(*cov);
62 
63  FMap->topoSew0(edges[i], mesh);
64  }
65 }
66 //******************************************************************************
68  CDart* AMesh2Dart,
69  int ASx, int ASy)
70 {
71  assert(ASquareDart!=NULL);
72  assert(AMesh2Dart!=NULL);
73  assert(ASx>0);
74  assert(ASy>0);
75 
76  bool is3Sewed = ! FMap->isFree3(ASquareDart);
77 
78  return
79  isTopoSquare1Meshed(ASquareDart, ASx,ASy, true, is3Sewed) &&
80  isTopoSquare2Meshed(AMesh2Dart , ASx,ASy, true, is3Sewed);
81 }
82 //------------------------------------------------------------------------------
84  CDart * AMesh2Dart,
85  int ASx, int ASy)
86 {
87  assert(canMergeSquare1MeshedAndMesh2(ASquareDart, AMesh2Dart, ASx,ASy));
88 
89  int nbRounds = FMap->isFree3(ASquareDart) ? 1 : 2;
90 
91  CDart * current1 = ASquareDart;
92  CDart * current2 = AMesh2Dart;
93 
94  while (nbRounds > 0)
95  {
96  CDart * tmp;
97 
98  FMap->unlinkAlpha1(current1);
99 
100  for (int i=2*(ASx+ASy); i>0; --i)
101  {
102  tmp = FMap->alpha1(current2);
103 
104  FMap->unlinkAlpha1(tmp); FMap->linkAlpha1(tmp, current1);
105 
106  tmp = current2;
107  current2 = FMap->alpha01(current2);
108 
109  FMap->unlinkAlpha1(current2);
110  FMap->delMapDart(FMap->alpha0(tmp));
111  FMap->delMapDart( tmp );
112 
113  tmp = FMap->alpha0(current1);
114  current1 = FMap->alpha1(tmp);
115 
116  FMap->unlinkAlpha1(tmp); FMap->linkAlpha1(tmp, current2);
117 
118  if (! FMap->isFree2(current2))
119  current2 = FMap->alpha21(current2);
120  }
121 
122  if (nbRounds-- == 2)
123  {
124  current1 = FMap->alpha3(ASquareDart);
125  current2 = FMap->alpha3(AMesh2Dart );
126  }
127  }
128 }
129 //******************************************************************************
131  CDart* AMesh3Dart,
132  int ASx, int ASy)
133 {
134  assert(ASquareDart!=NULL);
135  assert(AMesh3Dart!=NULL);
136  assert(ASx>0);
137  assert(ASy>0);
138 
139  return
140  isTopoSquare2Meshed(ASquareDart, ASx,ASy) &&
141  isTopoSquare3Meshed(AMesh3Dart , ASx,ASy);
142 }
143 //------------------------------------------------------------------------------
145  CDart* AMesh3Dart,
146  int ASx, int ASy,
147  CDart** ANextSquare,
148  CDart** ANextMesh3Side)
149 {
150  assert(canMergeSquare2MeshedAndMesh3Side(ASquareDart, AMesh3Dart, ASx,ASy));
151 
152  CDart * currentX1, * currentX2, * currentY1=NULL, * currentY2=NULL;
153  CDart * nextX1 , * nextX2 , * nextY1 , * nextY2 ;
154  CDart * tmp1 , * tmp2 ;
155 
156  // Brins permettant de se déplacer selon la première dimension:
157  currentX1 = ASquareDart;
158  currentX2 = AMesh3Dart;
159 
160  // Pour chaque colonne:
161  for (int i=0; i<ASx; ++i)
162  {
163  // Mémorisation du début de la colonne suivante:
164  nextX1 = FMap->alpha0121 (currentX1);
165  nextX2 = FMap->alpha012321(currentX2);
166 
167  // Brins permettant de se déplacer selon la deuxième dimension:
168  currentY1 = FMap->alpha1(currentX1);
169  currentY2 = FMap->alpha1(currentX2);
170 
171  // Pour chaque ligne:
172  for (int j=0; j<ASy; ++j)
173  {
174  // Mémorisation de la cellule suivante dans la colonne:
175  nextY1 = FMap->alpha0121(currentY1);
176  nextY2 = j<ASy-1 ? FMap->alpha012321(currentY2) : FMap->alpha0121(currentY2);
177 
178  // Fusion:
179  for (int n=0; n<4; ++n)
180  {
181  tmp1 = currentY1;
182  tmp2 = currentY2;
183 
184  currentY1 = FMap->alpha01(currentY1);
185  currentY2 = FMap->alpha01(currentY2);
186 
187  if ((n==0 && i==0) || n==1 || n==2 || (n==3 && j==0))
188  {
189  FMap->unlinkAlpha2(tmp1);
190  FMap->unlinkAlpha2(FMap->alpha0(tmp1));
191  }
192 
193  CDart* tmp2Bis = FMap->alpha2(tmp2);
194 
195  FMap->unlinkAlpha2(tmp2);
196  FMap->unlinkAlpha2(FMap->alpha0(tmp2));
197 
198  FMap->topoSew2(tmp1, tmp2Bis);
199 
200  FMap->delMapDart(FMap->alpha0(tmp2));
201  FMap->delMapDart( tmp2 );
202  }
203 
204  // Passage à la ligne suivante:
205  currentY1 = nextY1;
206  currentY2 = nextY2;
207  }
208 
209  // Passage à la colonne suivante:
210  currentX1 = nextX1;
211  currentX2 = nextX2;
212  }
213 
214  // Paramètres en sortie:
215  if (ANextSquare!=NULL)
216  * ANextSquare = FMap->alpha10(currentY1);
217 
218  if (ANextMesh3Side!=NULL)
219  * ANextMesh3Side = FMap->alpha10(currentY2);
220 }
221 //******************************************************************************
223  CDart* AMesh3Dart,
224  int ASx, int ASy, int ASz)
225 {
226  assert(ACubeDart!=NULL);
227  assert(AMesh3Dart!=NULL);
228  assert(ASx>0);
229  assert(ASy>0);
230  assert(ASz>0);
231 
232  return
233  isTopoCube2Meshed(ACubeDart , ASx,ASy,ASz) &&
234  isTopoCube3Meshed(AMesh3Dart, ASx,ASy,ASz);
235 }
236 //------------------------------------------------------------------------------
237 void CMeshGeneric::mergeCube2MeshedAndMesh3(CDart* ACubeDart, CDart* AMesh3Dart,
238  int ASx, int ASy, int ASz)
239 {
240  assert(canMergeCube2MeshedAndMesh3(ACubeDart, AMesh3Dart, ASx,ASy,ASz));
241 
242  int s[3] = { ASx, ASy, ASz };
243 
244  CDart * current1 = ACubeDart;
245  CDart * current2 = AMesh3Dart;
246 
247  CDart * next1;
248  CDart * next2;
249 
250  for (int i=0; i<3; ++i)
251  {
252  next1 = FMap->alpha12(current1);
253  next2 = FMap->alpha12(current2);
254 
255  CDart * current1Bis;
256  CDart * current2Bis;
257 
258  mergeSquare2MeshedAndMesh3Side(current1, current2,
259  s[i], s[(i+1)%3],
260  &current1Bis, &current2Bis);
261 
262  mergeSquare2MeshedAndMesh3Side(current1Bis, current2Bis,
263  s[i], s[(i+2)%3]);
264 
265  current1 = next1;
266  current2 = next2;
267  }
268 }
269 //******************************************************************************