Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-polyline.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  for (CDynamicCoverage01 it(this,ADart); it.cont(); ++it)
33  if (!isFree2(*it) || !isFree3(*it))
34  return false;
35 
36  return true;
37 }
38 //******************************************************************************
40 {
41  assert(ADart!=NULL);
42 
43  for (CDynamicCoverage01 it(this,ADart); it.cont(); ++it)
44  if (isFree0(*it) || isFree1(*it))
45  return false;
46 
47  return true;
48 }
49 //******************************************************************************
51 {
52  assert(ADart!=NULL);
53 
54  // Méthode utilisée: le nombre de sommets d'une face est égal à son nombre de
55  // brins divisé par 2.
56  // Lorsqu'un brin n'est pas 1-cousu, il compte double.
57 
58  int n=0;
59 
60  for (CDynamicCoverage01 it(this, ADart); it.cont(); ++it)
61  {
62  ++n;
63 
64  if (isFree1(*it))
65  ++n;
66  }
67 
68  assert(n%2 == 0);
69 
70  return n/2;
71 }
72 //******************************************************************************
74  bool AConsider0FreeDartsAsEdges)
75 {
76  assert(ADart!=NULL);
77 
78  // Méthode utilisée: le nombre d'arêtes d'une face est égal à son nombre de
79  // brins divisé par 2.
80  // Lorsqu'un brin n'est pas 0-cousu, soit il compte double
81  // (si AConsider0FreeDartsAsEdges vaut 'vrai') soit il ne compte pas
82  // (si AConsider0FreeDartsAsEdges vaut 'faux').
83 
84  int n=0;
85 
86  for (CDynamicCoverage01 it(this, ADart); it.cont(); ++it)
87  {
88  ++n;
89 
90  if (isFree0(*it))
91  n += AConsider0FreeDartsAsEdges ? +1 : -1;
92  }
93 
94  assert(n%2 == 0);
95 
96  return n/2;
97 }
98 //******************************************************************************
100 {
101  assert(ADart==NULL || isIsolatedPolyline(ADart));
102 
103  // Cas particulier 1: ADart==NULL
104  if (ADart==NULL)
105  return addMapDart();
106 
107  // Cas particulier 2: La polyligne n'alpha qu'un seul brin.
108  // On la prolonge pour créer une arête.
109  if (isFree0(ADart))
110  {
111  CDart * dart2= addMapDart();
112  linkAlpha0(ADart,dart2);
113  return dart2;
114  }
115 
116  // Cas général:
117  CDart * dart2= addMapDart();
118  CDart * dart3= addMapDart();
119 
120  linkAlpha1(ADart,dart2);
121  linkAlpha0(dart2,dart3);
122 
123  return dart3;
124 }
125 //******************************************************************************
127 {
128  assert(ADart!=NULL);
129  assert(isFree1(ADart));
130  assert(isIsolatedPolyline(ADart));
131 
132  // Cas particulier 1: La polyligne est réduite à un brin. On la détruit.
133  if (isFree0(ADart))
134  {
135  delMapDart(ADart);
136  return NULL;
137  }
138 
139  CDart * dart0= alpha0(ADart);
140 
141  // Cas particulier 2: La polyligne est une arête (2 brins)
142  if (isFree1(dart0))
143  {
144  unsew0(ADart);
145  delMapDart(ADart);
146  return dart0;
147  }
148 
149  // Cas général:
150  CDart * dart01= alpha1(dart0);
151 
152  // Inutile de 0-découdre dart0 et ADart car ils vont être détruits.
153  unsew1(dart01);
154 
155  delMapDart(ADart);
156  delMapDart(dart0);
157 
158  return dart01;
159 }
160 //******************************************************************************
162 {
163  assert(ADart!=NULL);
164  assert(isIsolatedPolyline(ADart));
165 
166  // D'abord, on cherche les deux bouts de la polyligne:
167  CDart * end1= NULL, * end2= NULL;
168 
169  CDynamicCoverage01 it(this, ADart);
170 
171  for (; it.cont(); ++it)
172  if (isFree1(*it))
173  {
174  if (end1==NULL)
175  end1=*it;
176  else
177  end2=*it;
178  }
179 
180  if (end2==NULL || // la polyligne n'alpha qu'un seul brin ou est déjà fermée
181  end2==alpha0(end1)) // la polyligne est une arête
182  return NULL;
183 
184  // Fermeture:
185  CDart * dart1= addMapDart();
186  CDart * dart2= addMapDart();
187 
188  linkAlpha1(dart1,end1);
189  linkAlpha1(dart2,end2);
190 
191  linkAlpha0(dart1,dart2);
192 
193  return dart1;
194 }
195 //******************************************************************************