Moka kernel
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gmg-exploration.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 <cstring>
27 using namespace GMap3d;
28 //******************************************************************************
29 CDart * CGMapGeneric::go(TMovement ADirection, CDart * ALastDart, TOrbit AOrbit,
30  int AMarkNumber, bool ASelect)
31 {
32  assert(ALastDart!=NULL);
33  assert(AOrbit==ORBIT_03 || AOrbit==ORBIT_02 || AOrbit==ORBIT_023 ||
34  AOrbit==ORBIT_01 || AOrbit==ORBIT_013 || AOrbit==ORBIT_012);
35 
36  static const char * forward[16] =
37  {
38  /* ---- */ "",
39  /* 0--- */ "",
40  /* -1-- */ "",
41  /* 01-- face /volume */ "2101",
42  /* --2- */ "",
43  /* 0-2- arête /volume */ "1[21]0",
44  /* -12- */ "",
45  /* 012- volume/cc */ "321012",
46  /* ---3 */ "",
47  /* 0--3 arête /face */ "10",
48  /* -1-3 */ "",
49  /* 01-3 face /cc */ "2[32]101",
50  /* --23 */ "",
51  /* 0-23 arête /cc */ "1[2[32]1]0",
52  /* -123 */ "",
53  /* 0123 */ ""
54  };
55 
56  static const char * right[16] =
57  {
58  /* ---- */ "",
59  /* 0--- */ "",
60  /* -1-- */ "",
61  /* 01-- face /volume */ "10" /* 21*/,
62  /* --2- */ "",
63  /* 0-2- arête /volume */ "010[2]" /* 21*/,
64  /* -12- */ "",
65  /* 012- volume/cc */ "210" /*321*/,
66  /* ---3 */ "",
67  /* 0--3 arête /face */ "010" /* 1*/,
68  /* -1-3 */ "",
69  /* 01-3 face /cc */ "10" /*321*/,
70  /* --23 */ "",
71  /* 0-23 arête /cc */ "010[2]" /*321*/,
72  /* -123 */ "",
73  /* 0123 */ ""
74  };
75 
76  bool reverse = ADirection==Backward || ADirection==Left;
77 
78  const char * series =
79  (ADirection==Left || ADirection==Right) ? right[AOrbit] : forward[AOrbit];
80 
81  int length = strlen(series);
82 
83  // Marquage:
84  if (ASelect && !isWholeCellMarked(ALastDart, AOrbit, AMarkNumber))
85  {
86  markOrbit(ALastDart, AOrbit, AMarkNumber);
87  return ALastDart;
88  }
89 
90  if (!ASelect)
91  unmarkOrbit(ALastDart, AOrbit, AMarkNumber);
92 
93  // Déplacement:
94  CDart * current = ALastDart;
95  bool firstSubMove = false;
96 
97 #define INFINITE (9)
98 
99  for (int i=0, depth=0, freezeLevel=INFINITE; i<length; ++i)
100  {
101  char c = series[reverse ? length-i-1 : i];
102 
103  if (c=='[' || c==']')
104  {
105  if (reverse ^ (c=='['))
106  {
107  ++depth;
108  firstSubMove = true;
109  }
110  else
111  {
112  --depth;
113 
114  if (depth<freezeLevel)
115  freezeLevel = INFINITE;
116 
117  assert(!firstSubMove);
118  }
119  }
120  else
121  {
122  if (depth < freezeLevel)
123  {
124  assert(c=='0' || c=='1' || c=='2' || c=='3');
125  int dim = c-'0';
126 
127  if (isFree(current, dim))
128  {
129  if (firstSubMove)
130  freezeLevel = depth;
131  else
132  return ALastDart;
133  }
134  else
135  current = alpha(current, dim);
136  }
137 
138  firstSubMove = false;
139  }
140  }
141 
142 #undef INFINITE
143 
144  // Marquage:
145  if (ASelect)
146  markOrbit(current, AOrbit, AMarkNumber);
147  else
148  setMark(current, AMarkNumber);
149 
150  return current;
151 }
152 //******************************************************************************
154  TOrbit AOrbit, int AMarkNumber,
155  bool ASelect)
156 {
157  assert(ALastDart!=NULL);
158  assert(AOrbit==ORBIT_03 || AOrbit==ORBIT_02 || AOrbit==ORBIT_023 ||
159  AOrbit==ORBIT_01 || AOrbit==ORBIT_013 || AOrbit==ORBIT_012);
160 
161  int treated = getNewMark();
162 
163  CDart * current = ALastDart;
164 
165  go(ADirection, current, AOrbit, AMarkNumber, ASelect);
166 
167  while (!isMarked(current, treated))
168  {
169  setMark(current, treated);
170  current = go(ADirection, current, AOrbit, AMarkNumber, ASelect);
171  assert(current!=NULL);
172  }
173 
174  unmarkAll(treated);
175  freeMark(treated);
176 
177  return current;
178 }
179 //******************************************************************************