Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-duplication.cc
Go to the documentation of this file.
1 /*
2  * lib-gmapkernel : Un noyau de 3-G-cartes et des opérations.
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-gmapkernel
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 "g-map-generic.hh"
26 using namespace GMap3d;
27 //******************************************************************************
29  int ADirectInfoIndex,
30  bool ADuplicateEmbeddings,
31  bool A0Sew, bool A1Sew,
32  bool A2Sew, bool A3Sew)
33 {
34  if (AMap==NULL) AMap=this;
35 
36  int nbDuplicated = 0;
37 
38  int duplicated = AMap->getNewMark();
39 
40  int directInfoIndex =
41  ADirectInfoIndex<0 ? getNewDirectInfo() : ADirectInfoIndex;
42 
43  CDynamicCoverageAll it(this);
44 
45  // Duplication des brins:
46  for (; it.cont(); ++it)
47  if (isMarked(*it, AMarkNumber))
48  {
49  CDart * newDart = AMap->addMapDart();
50 
51  if (ADuplicateEmbeddings)
52  AMap->setMark(newDart, duplicated);
53 
54  (*it)->setDirectInfo(directInfoIndex, newDart);
55 
56  ++nbDuplicated;
57  }
58 
59  // Coutures:
60  sewDuplicatedDarts(&it, AMarkNumber, directInfoIndex,
61  AMap, A0Sew, A1Sew, A2Sew, A3Sew);
62 
63  // Duplication des plongements:
64  if (ADuplicateEmbeddings)
66  AMarkNumber, duplicated,
67  directInfoIndex, AMap);
68 
69  // Libérations:
70  if (ADirectInfoIndex<0)
71  freeDirectInfo(directInfoIndex);
72 
73  assert(AMap->isWholeMapUnmarked(duplicated));
74  AMap->freeMark(duplicated);
75 
76  return nbDuplicated;
77 }
78 //******************************************************************************
80  CGMapGeneric* AMap,
81  int ADirectInfoIndex,
82  bool ADuplicateEmbeddings)
83 {
84  assert(ADart!=NULL);
85  if (AMap==NULL) AMap=this;
86 
87  int selected = getNewMark();
88  int duplicated = AMap->getNewMark();
89 
90  int directInfoIndex =
91  ADirectInfoIndex<0 ? getNewDirectInfo() : ADirectInfoIndex;
92 
93  CCoverage * cov = getDynamicCoverage(ADart, AOrbit);
94 
95  // Duplication des brins:
96  for (; cov->cont(); ++(*cov))
97  {
98  CDart * newDart = AMap->addMapDart();
99  AMap->setMark(newDart, duplicated);
100  setMark(**cov, selected);
101  (**cov)->setDirectInfo(directInfoIndex, newDart);
102  }
103 
104  // Coutures:
105  sewDuplicatedDarts(cov, selected, directInfoIndex, AMap,
106  AND_ORBIT(AOrbit, ORBIT_0) != ORBIT_SELF,
107  AND_ORBIT(AOrbit, ORBIT_1) != ORBIT_SELF,
108  AND_ORBIT(AOrbit, ORBIT_2) != ORBIT_SELF,
109  AND_ORBIT(AOrbit, ORBIT_3) != ORBIT_SELF);
110 
111  // Duplication des plongements:
112  if (ADuplicateEmbeddings)
114  selected, duplicated,
115  directInfoIndex, AMap);
116 
117  // Libérations:
118  CDart * result = getDirectInfoAsDart(ADart, directInfoIndex);
119 
120  for (cov->reinit(); cov->cont(); ++(*cov))
121  unsetMark(**cov, selected);
122 
123  delete cov;
124 
125  if (ADirectInfoIndex<0)
126  freeDirectInfo(directInfoIndex);
127 
128  freeMark(selected);
129  AMap->freeMark(duplicated);
130 
131  return result;
132 }
133 //******************************************************************************
134 #define DUP(D) (getDirectInfoAsDart(D, ADirectInfoIndex))
135 //******************************************************************************
137  int AMarkNumber, int ADirectInfoIndex,
138  CGMapGeneric* AMap,
139  bool A0Sew, bool A1Sew,
140  bool A2Sew, bool A3Sew)
141 {
142  assert(ACoverage!=NULL);
143  assert(AMarkNumber>=0);
144  assert(ADirectInfoIndex>=0);
145 
146  // 0 et 1 coutures:
147  for (ACoverage->reinit(); ACoverage->cont(); ++(*ACoverage))
148  {
149  CDart * d = **ACoverage;
150 
151  if (AMarkNumber<0 || isMarked(d, AMarkNumber))
152  {
153  if (A0Sew)
154  if (!isFree0(d) && isMarked(alpha0(d), AMarkNumber) &&
155  AMap->isFree0(DUP(d)))
156  AMap->linkAlpha0(DUP(d), DUP(alpha0(d)));
157 
158  if (A1Sew)
159  if (!isFree1(d) && isMarked(alpha1(d), AMarkNumber) &&
160  AMap->isFree1(DUP(d)))
161  AMap->linkAlpha1(DUP(d), DUP(alpha1(d)));
162  }
163  }
164 
165  // 2 and 3 coutures:
166  for (ACoverage->reinit(); ACoverage->cont(); ++(*ACoverage))
167  {
168  CDart * d = **ACoverage;
169 
170  if (isMarked(d, AMarkNumber))
171  {
172  if (A2Sew)
173  if (!isFree2(d) && isMarked(alpha2(d), AMarkNumber) &&
174  AMap->canSew2(DUP(d), DUP(alpha2(d))))
175  AMap->topoSew2(DUP(d), DUP(alpha2(d)));
176 
177  if (A3Sew)
178  if (!isFree3(d) && isMarked(alpha3(d), AMarkNumber) &&
179  AMap->canSew3(DUP(d), DUP(alpha3(d))))
180  AMap->topoSew3(DUP(d), DUP(alpha3(d)));
181  }
182  }
183 }
184 //******************************************************************************
186  int AMarkInitial,
187  int AMarkDuplicated,
188  int ADirectInfoIndex,
189  CGMapGeneric* AMap)
190 {
191  assert(ACoverage!=NULL);
192  assert(AMarkInitial>=0);
193  assert(AMarkDuplicated>=0);
194  assert(ADirectInfoIndex>=0);
195  assert(this!=AMap || AMarkInitial!=AMarkDuplicated);
196 
197  int treated = getNewMark();
198  int treated2 = (AMap==this?treated:AMap->getNewMark());
199 
200  for (int i=ORBIT_0; i<=ORBIT_0123; ++i)
201  if (isOrbitUsed(TOrbit(i)))
202  {
203  // Duplication pour l'orbite i:
204  for (ACoverage->reinit(); ACoverage->cont(); ++(*ACoverage))
205  {
206  CDart * d = **ACoverage;
207 
208  if (!isMarked(d, treated))
209  {
210  if (isMarked(d, AMarkInitial))
211  {
212  CDart * owner = getEmbeddingOwner(d, TOrbit(i));
213 
214  if (owner!=NULL)
215  {
216  CEmbedding * E = owner->getEmbedding(TOrbit(i));
217  assert(E!=NULL);
218 
219  CCoverage * cov = getDynamicCoverage(d, TOrbit(i));
220  assert(cov!=NULL);
221 
222  for (; cov->cont(); setMark(**cov, treated), ++(*cov))
223  if (isMarked(**cov, AMarkInitial) &&
224  !AMap->isMarked(DUP(**cov), treated2))
225  {
226  CEmbedding * dupE = E->copy();
227  DUP(**cov)->addEmbedding(dupE);
228 
229  AMap->markOrbit(DUP(**cov), TOrbit(i), treated2);
230  AMap->unmarkOrbit(DUP(**cov), TOrbit(i), AMarkDuplicated);
231  }
232 
233  delete cov;
234  }
235  }
236  else
237  {
238  // Le 2ème test est la que pour le cas this==AMap (car on
239  // insère les brins dans la liste parcouru)
240  if ( this!=AMap || !isMarked(d, AMarkDuplicated) )
241  setMark(d, treated);
242  }
243  }
244  }
245 
246  // Démarquage:
247  if (ACoverage->type() == COVERAGE_ALL && AMap==this)
248  negateMaskMark(treated);
249  else
250  for (ACoverage->reinit(); ACoverage->cont(); ++(*ACoverage))
251  {
252  if (isMarked(**ACoverage, treated))
253  unmarkOrbit(**ACoverage, TOrbit(i), treated);
254 
255  if (AMap->isMarked(DUP(**ACoverage), treated2))
256  AMap->unmarkOrbit(DUP(**ACoverage), TOrbit(i), treated2);
257  }
258  }
259 
260  freeMark(treated);
261  if ( AMap!=this ) AMap->freeMark(treated2);
262 }
263 //******************************************************************************
264 #undef DUP
265 //******************************************************************************