Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-border.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 {
30  assert(ADart!=NULL);
31 
32  if (isFree0(ADart)) return 0;
33  if (isFree1(ADart)) return 1;
34  if (isFree2(ADart)) return 2;
35  if (isFree3(ADart)) return 3;
36  return 4;
37 }
38 //******************************************************************************
39 bool CGMapGeneric::markBorders(int AMarkNumber, int ADim)
40 {
41  bool marked = false;
42 
43  int selected= getNewMark();
44  int treated = getNewMark();
45 
46  // 1: Copie des marques
47  markCopy(AMarkNumber, selected);
48 
49  // 2: Sélection des bords:
50  for (CDynamicCoverageAll it(this); it.cont(); ++it)
51  if (!isMarked(*it, treated))
52  {
53  if (isMarked(*it, selected) && isFree(*it, ADim))
54  {
55  for (CDynamicBorderCoverage cov(this, *it, ADim);
56  cov.cont(); ++cov)
57  {
58  setMark(*cov, AMarkNumber);
59  setMark(*cov, treated);
60  }
61 
62  marked = true;
63  }
64  else
65  setMark(*it, treated);
66  }
67 
68  // 3: Libération des marques:
69  negateMaskMark(treated);
70  freeMark(treated);
71 
72  unmarkAll(selected);
73  freeMark(selected);
74 
75  return marked;
76 }
77 //******************************************************************************
78 bool CGMapGeneric::markBorders(int AMarkNumber)
79 {
80  bool marked = false;
81 
82  int selected= getNewMark();
83  int treated = getNewMark();
84 
85  // 1: Copie des marques
86  markCopy(AMarkNumber, selected);
87 
88  // 2: Sélection des bords:
89  for (CDynamicCoverageAll it(this); it.cont(); ++it)
90  if (!isMarked(*it, treated))
91  {
92  if (isMarked(*it, selected))
93  {
94  int dim = getBorderDimension(*it);
95 
96  if (dim<4)
97  {
98  for (CDynamicBorderCoverage cov(this, *it, dim);
99  cov.cont(); ++cov)
100  {
101  setMark(*cov, AMarkNumber);
102  setMark(*cov, treated);
103  }
104 
105  marked = true;
106  }
107  }
108  else
109  setMark(*it, treated);
110  }
111 
112  // 3: Libération des marques:
113  negateMaskMark(treated);
114  freeMark(treated);
115 
116  unmarkAll(selected);
117  freeMark(selected);
118 
119  return marked;
120 }
121 //******************************************************************************
122 bool CGMapGeneric::canSewBorders(CDart * ADart1, CDart * ADart2,
123  int ADim, int An)
124 {
125  assert(ADart1!=NULL);
126  assert(ADart2!=NULL);
127 
128  if (!isFree(ADart1, ADim) || !isFree(ADart2, ADim))
129  return false;
130 
131  CDynamicBorderCoverage it1(this, ADart1, ADim);
132  CDynamicBorderCoverage it2(this, ADart2, ADim);
133 
134  if (An==0)
135  An=-1;
136 
137  for (; it1.cont() && it2.cont() && An!=0; ++it1, ++it2, --An)
138  if (it1.prevOperationType()!=it2.prevOperationType())
139  return false;
140 
141  return An==0 || (!it1.cont() && !it2.cont());
142 }
143 //******************************************************************************
144 void CGMapGeneric::borderTopoSew(CDart * ADart1, CDart * ADart2,
145  int ADim, int An)
146 {
147  assert(canSewBorders(ADart1, ADart2, ADim, An));
148 
149  if (An==0)
150  An=-1;
151 
152  CStaticBorderCoverage it1(this, ADart1, ADim);
153  CStaticBorderCoverage it2(this, ADart2, ADim);
154 
155  for (; it1.cont() && An!=0; ++it1, ++it2, --An)
156  if (isFree(*it1, ADim) && isFree(*it2, ADim))
157  topoSew(*it1, *it2, ADim);
158 }
159 //******************************************************************************
160 void CGMapGeneric::borderSew(CDart * ADart1, CDart * ADart2, int ADim, int An)
161 {
162  assert(canSewBorders(ADart1, ADart2, ADim, An));
163 
164  if (An==0)
165  An=-1;
166 
167  CStaticBorderCoverage it1(this, ADart1, ADim);
168  CStaticBorderCoverage it2(this, ADart2, ADim);
169 
170  for (; it1.cont() && An!=0; ++it1, ++it2, --An)
171  if (isFree(*it1, ADim) && isFree(*it2, ADim))
172  sew(*it1, *it2, ADim);
173 }
174 //******************************************************************************
175 bool CGMapGeneric::intuitiveBorderSew(CDart * ADart1, CDart * ADart2, int An)
176 {
177  assert(ADart1!=NULL && ADart2!=NULL);
178 
179  int dim = getBorderDimension(ADart1);
180 
181  if (dim==4 || !canSewBorders(ADart1, ADart2, dim))
182  return false;
183 
184  borderSew(ADart1, ADart2, dim, An);
185  return true;
186 }
187 //******************************************************************************
188 void CGMapGeneric::border2TopoSew(CDart * ADart1, CDart * ADart2, int An)
189 {
190  borderTopoSew(ADart1, ADart2, 2, 2*An);
191 }
192 //******************************************************************************
193 void CGMapGeneric::border2Sew(CDart * ADart1, CDart * ADart2, int An)
194 {
195  borderSew(ADart1, ADart2, 2, 2*An);
196 }
197 //******************************************************************************