Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-direct-info.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 #include "alt-stdint.hh"
27 using namespace GMap3d;
28 //******************************************************************************
30  int ADirectInfoIndex,
31  int ABytes, TOrbit AOrbitUsed)
32 {
33  assert(ABytes>0);
34 
35  if (AOrbitUsed==ORBIT_NONE)
36  {
37  for (CDynamicCoverageAll it(this); it.cont(); ++it)
38  if (isMarked(*it, AMarkNumber))
39  setDirectInfo(*it, ADirectInfoIndex, new uint8_t[ABytes]);
40  }
41  else
42  {
43  assert(isOrbitUsed(AOrbitUsed));
44  int treated = getNewMark();
45 
46  for (CDynamicCoverageAll it(this); it.cont(); ++it)
47  if (!isMarked(*it, treated))
48  {
49  if (isMarked(*it, AMarkNumber))
50  {
51  CDart * owner = getEmbeddingOwner(*it, AOrbitUsed);
52  assert(owner!=NULL);
53 
54  setDirectInfo(owner, ADirectInfoIndex, new uint8_t[ABytes]);
55 
56  markOrbit(owner, AOrbitUsed, treated);
57  }
58  else
59  setMark(*it, treated);
60  }
61 
62  negateMaskMark(treated);
63  freeMark(treated);
64  }
65 }
66 //******************************************************************************
68  int ADirectInfoIndex,
69  int ABytes, TOrbit AOrbitUsed)
70 {
71  assert(ADart!=NULL);
72 
73  int mark = getNewMark();
74 
75  markOrbit(ADart, AOrbit, mark);
76  allocMemoryToDirectInfo(mark, ADirectInfoIndex, ABytes, AOrbitUsed);
77  unmarkOrbit(ADart, AOrbit, mark);
78 
79  freeMark(mark);
80 }
81 //******************************************************************************
83  int ADirectInfoIndex,
84  TOrbit AOrbitUsed)
85 {
86  if (AOrbitUsed==ORBIT_NONE)
87  {
88  for (CDynamicCoverageAll it(this); it.cont(); ++it)
89  if (isMarked(*it, AMarkNumber))
90  delete (uint8_t *) getDirectInfo(*it, ADirectInfoIndex);
91  }
92  else
93  {
94  assert(isOrbitUsed(AOrbitUsed));
95  int treated = getNewMark();
96 
97  for (CDynamicCoverageAll it(this); it.cont(); ++it)
98  if (!isMarked(*it, treated))
99  {
100  if (isMarked(*it, AMarkNumber))
101  {
102  CDart * owner = getEmbeddingOwner(*it, AOrbitUsed);
103  assert(owner!=NULL);
104 
105  delete (uint8_t *) getDirectInfo(owner, ADirectInfoIndex);
106 
107  markOrbit(owner, AOrbitUsed, treated);
108  }
109  else
110  setMark(*it, treated);
111  }
112 
113  negateMaskMark(treated);
114  freeMark(treated);
115  }
116 }
117 //******************************************************************************
119  int ADirectInfoIndex,
120  TOrbit AOrbitUsed /*ORBIT_NONE*/)
121 {
122  assert(ADart!=NULL);
123 
124  int mark = getNewMark();
125 
126  markOrbit(ADart, AOrbit, mark);
127  freeMemoryFromDirectInfo(mark, ADirectInfoIndex, AOrbitUsed);
128  unmarkOrbit(ADart, AOrbit, mark);
129 
130  freeMark(mark);
131 }
132 //******************************************************************************
133 void CGMapGeneric::saveAlphaInDirectInfo(int AAlphaIndex, int ADirectInfoIndex)
134 {
135  assert(0 <= AAlphaIndex && AAlphaIndex <= 3);
136 
137  for (CDynamicCoverageAll it(this); it.cont(); ++it)
138  setDirectInfo(*it, ADirectInfoIndex, alpha(*it, AAlphaIndex));
139 }
140 //******************************************************************************
141 void CGMapGeneric::initUnionFindTrees(int AIndex, TOrbit AOrbit)
142 {
143  int treated = getNewMark();
144  for (CDynamicCoverageAll it(this); it.cont(); ++it)
145  {
146  if ( !isMarked(*it,treated) )
147  {
148  CCoverage* it2 = getDynamicCoverage(*it,AOrbit);
149  for ( ; it2->cont(); ++(*it2) )
150  {
151  setDirectInfo(**it2, AIndex, *it);
152  setMark(**it2,treated);
153  }
154  delete it2;
155  }
156  }
157  negateMaskMark(treated);
158  freeMark(treated);
159 }
160 //******************************************************************************
161 void CGMapGeneric::initTwoUnionFindTrees(int AIndex1, TOrbit AOrbit1,
162  int AIndex2, TOrbit AOrbit2)
163 {
164  assert(AIndex1!=AIndex2);
165 
166  int treated1 = getNewMark();
167  int treated2 = getNewMark();
168  for (CDynamicCoverageAll it(this); it.cont(); ++it)
169  {
170  if ( !isMarked(*it,treated1) )
171  {
172  CCoverage* it2 = getDynamicCoverage(*it,AOrbit1);
173  for ( ; it2->cont(); ++(*it2) )
174  {
175  setDirectInfo(**it2, AIndex1, *it);
176  setMark(**it2,treated1);
177  }
178  delete it2;
179  }
180  if ( !isMarked(*it,treated2) )
181  {
182  CCoverage* it2 = getDynamicCoverage(*it,AOrbit2);
183  for ( ; it2->cont(); ++(*it2) )
184  {
185  setDirectInfo(**it2, AIndex2, *it);
186  setMark(**it2,treated2);
187  }
188  delete it2;
189  }
190  }
191  negateMaskMark(treated1);
192  negateMaskMark(treated2);
193  freeMark(treated1);
194  freeMark(treated2);
195 }
196 //******************************************************************************
197 void CGMapGeneric::initUnionFindTreesFaceVolume(int AIndexFace, int AIndexVol)
198 {
199  assert(AIndexFace!=AIndexVol);
200 
201  int treatedFace = getNewMark();
202  int treatedVol = getNewMark();
203  for (CDynamicCoverageAll it(this); it.cont(); ++it)
204  {
205  if ( !isMarked(*it,treatedFace) )
206  {
207  for (CDynamicCoverageFace it2(this,*it); it2.cont(); ++it2)
208  {
209  setDirectInfo(*it2, AIndexFace, *it);
210  setMark(*it2,treatedFace);
211  }
212  }
213  if ( !isMarked(*it,treatedVol) )
214  {
215  for (CBasicDynamicCoverageVolume it2(this, *it, treatedVol);
216  it2.cont(); ++it2)
217  {
218  setDirectInfo(*it2, AIndexVol, *it);
219  assert( isMarked(*it2, treatedVol) );
220  }
221  }
222  }
223 
224  negateMaskMark(treatedFace);
225  negateMaskMark(treatedVol);
226  freeMark(treatedFace);
227  freeMark(treatedVol);
228 }
229 //******************************************************************************
231  int AIndexEdge)
232 {
233  assert(AIndexVertex!=AIndexEdge);
234 
235  int treatedVertex = getNewMark();
236  int treatedEdge = getNewMark();
237  for (CDynamicCoverageAll it(this); it.cont(); ++it)
238  {
239  if ( !isMarked(*it,treatedVertex) )
240  {
241  for (CBasicDynamicCoverageVertex it2(this,*it,treatedVertex);
242  it2.cont(); ++it2)
243  {
244  setDirectInfo(*it2, AIndexVertex, *it);
245  assert( isMarked(*it2, treatedVertex) );
246  }
247  }
248  if ( !isMarked(*it,treatedEdge) )
249  {
250  for (CDynamicCoverageEdge it2(this, *it); it2.cont(); ++it2)
251  {
252  setDirectInfo(*it2, AIndexEdge, *it);
253  setMark(*it2,treatedEdge);
254  }
255  }
256  }
257 
258  negateMaskMark(treatedVertex);
259  negateMaskMark(treatedEdge);
260  freeMark(treatedVertex);
261  freeMark(treatedEdge);
262 
263 }
264 //******************************************************************************
266 {
267  CDart *res = ADart, *cur = ADart;
268 
269  while (getDirectInfo(res, AIndex)!=res)
270  res = static_cast<CDart*>(getDirectInfo(res,AIndex));
271 
272  while (getDirectInfo(cur, AIndex)!=res)
273  {
274  ADart=static_cast<CDart*>(getDirectInfo(cur,AIndex));
275  setDirectInfo(cur, AIndex, res);
276  cur=ADart;
277  }
278 
279  return res;
280 }
281 //******************************************************************************
282 void CGMapGeneric::mergeUnionFindTrees(CDart* ADart1,CDart* ADart2,int AIndex)
283 {
284  CDart *root1 = findUnionFindTrees(ADart1,AIndex);
285  CDart *root2 = findUnionFindTrees(ADart2,AIndex);
286 
287  if ( root1==root2 ) return;
288 
289  setDirectInfo(root1, AIndex, root2);
290 }
291 //******************************************************************************