Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-contraction.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 <deque>
27 using namespace std;
28 using namespace GMap3d;
29 //******************************************************************************
30 // Contraction d'une i-cellules incidente à un brin donné.
31 //
32 // dim == 3: contraction de volume
33 // (précondition : volume de degré inférieur local égal à 2)
34 // dim == 2: contraction de face
35 // (précondition : face de degré inférieur local égal à 2)
36 // dim == 1: contraction d'arête
37 // (pas de précondition)
38 //
39 //******************************************************************************
40 bool CGMapGeneric::canContract(CDart * ADart, int ADim)
41 {
42  assert(ADart!=NULL);
43  assert(ADim>=1 && ADim<=3);
44 
45  return isLocalDegreeTwoInf(ADart, ADim);
46 }
47 //******************************************************************************
48 void CGMapGeneric::contract(CDart * ADart, int ADim, bool ADeleteDarts)
49 {
50  assert(ADart!=NULL);
51  assert(ADim>=1 && ADim<=3);
52  assert(canContract(ADart, ADim));
53 
54  int mark = getNewMark();
55  markOrbit(ADart, ORBIT_CELL[ADim], mark);
56 
57  CDart* current = NULL;
58  CDart* t2 = NULL;
59 
60  CCoverage * it = getStaticCoverage(ADart, ORBIT_CELL[ADim]);
61  while ( it->cont() )
62  {
63  current = alpha((*it)++, ADim);
64  if ( !isMarked(current, mark) )
65  {
66  t2 = alpha(current, ADim);
67  while ( isMarked(t2, mark) )
68  {
69  t2 = alpha(alpha(t2, ADim-1), ADim);
70  }
71 
72  if ( t2 != alpha(current, ADim) )
73  {
74  unsew(current, ADim);
75  if (!isFree(t2, ADim)) unsew(t2, ADim);
76  if (current!=t2) sew(current, t2, ADim);
77  }
78  }
79  }
80 
81  if (ADeleteDarts)
82  {
83  for (it->reinit(); it->cont(); )
84  delMapDart((*it)++);
85  }
86 
87  freeMark(mark);
88 
89  delete it;
90 }
91 //******************************************************************************
92 int CGMapGeneric::contractMarkedCells( int AMarkNumber, int ADim,
93  bool ADeleteDarts )
94 {
95  assert(ADim>=1 && ADim<=3);
96 
97  int nbContract = markIncidentCells(ORBIT_CELL[ADim], AMarkNumber);
98 
99  CDynamicCoverageAll cov(this);
100  for ( ; cov.cont(); ++cov )
101  {
102  if ( isMarked(*cov, AMarkNumber) )
103  {
104  if ( !canContract(*cov, ADim) )
105  {
106  unmarkOrbit( *cov, ORBIT_CELL[ADim], AMarkNumber );
107  --nbContract;
108  }
109  }
110  }
111 
112  CDart* current = NULL;
113  CDart* t2 = NULL;
114 
115  for ( cov.reinit(); cov.cont(); ++cov )
116  {
117  if ( !isMarked( *cov, AMarkNumber) &&
118  isMarked( alpha(*cov, ADim), AMarkNumber) )
119  {
120  current = *cov;
121  t2 = alpha(current, ADim);
122 
123  while (isMarked(t2, AMarkNumber))
124  {
125  t2 = alpha(alpha(t2, ADim-1), ADim);
126  }
127 
128  if ( t2 != alpha(current, ADim) )
129  {
130  unsew(current, ADim);
131  if ( !isFree(t2, ADim) ) unsew(t2, ADim);
132  if ( t2!=current ) sew(current, t2, ADim);
133  }
134  }
135  }
136 
137  if (ADeleteDarts)
138  {
139  for (cov.reinit(); cov.cont(); )
140  {
141  if ( isMarked(*cov, AMarkNumber) )
142  delMapDart(cov++);
143  else
144  ++cov;
145  }
146  }
147 
148  return nbContract;
149 }
150 //******************************************************************************