1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
|
// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#ifndef CGAL_COMBINATORIAL_MAP_BASIC_OPERATIONS_H
#define CGAL_COMBINATORIAL_MAP_BASIC_OPERATIONS_H 1
namespace CGAL {
/** @file Combinatorial_map_basic_operations.h
* Basic operations on a combinatorial map.
*/
/** Test if the two given darts belong to the same given orbit.
* @param amap a combinatorial map.
* @param adart1 the first dart.
* @param adart2 the second dart.
* @return true iff the two darts belong to the same orbit.
*/
template < class Map, class Iterator >
bool belong_to_same_orbit(const Map & amap,
typename Map::Dart_const_handle adart1,
typename Map::Dart_const_handle adart2)
{
CGAL_static_assertion( (boost::is_same<typename Iterator::Basic_iterator,
Tag_false>::value) );
bool found = false;
for (Iterator it(amap, adart1); !found && it.cont(); ++it)
{
if (it == adart2) found = true;
}
return found;
}
/** Test if all the darts of a given orbit are marked.
* @param amap a combinatorial map.
* @param adart a dart of the orbit.
* @param amark the mark.
* @return true iff all the darts are marked.
*/
template < class Map, class Iterator >
bool is_whole_orbit_marked(const Map & amap,
typename Map::Dart_const_handle adart,
int amark)
{
CGAL_static_assertion( (boost::is_same<typename Iterator::Basic_iterator,
Tag_false>::value) );
bool res = true;
for ( Iterator it(amap, adart); res && it.cont(); ++it )
{
if (!amap.is_marked(it, amark)) res = false;
}
return res;
}
/** Test if all the darts of a given orbit are unmarked.
* @param amap a combinatorial map.
* @param adart a dart of the orbit.
* @param amark the mark.
* @return true iff all the darts are unmarked.
*/
template < class Map, class Iterator >
bool is_whole_orbit_unmarked(const Map & amap,
typename Map::Dart_const_handle adart,
int amark)
{
amap.negate_mark(amark);
bool res = is_whole_orbit_marked<Map,Iterator>(amap, adart, amark);
amap.negate_mark(amark);
return res;
}
/** Mark a given orbit with a given mark.
* @param amap a combinatorial map.
* @param adart a dart of the orbit.
* @param amark the mark.
* @return the number of darts of the marked orbit.
* @pre The whole orbit must be unmarked.
*/
template < class Map, class Iterator >
typename Map::size_type mark_orbit(const Map & amap,
typename Map::Dart_const_handle adart,
unsigned int amark)
{
CGAL_static_assertion( (boost::is_same<typename Iterator::Basic_iterator,
Tag_true>::value) );
CGAL_assertion( (is_whole_orbit_unmarked<Map,
CMap_non_basic_iterator<Map,Iterator> >
(amap, adart, amark)) );
typename Map::size_type res = 0;
for (Iterator it(amap, adart, amark); it.cont(); ++it)
{
amap.mark(it, amark);
++res;
}
return res;
}
/** Unmark a given orbit with a given mark.
* @param amap a combinatorial map.
* @param adart a dart of the orbit.
* @param amark the mark.
* @return the number of darts of the unmarked orbit.
* @pre The whole orbit must be marked.
*/
template < class Map, class Iterator >
typename Map::size_type unmark_orbit(const Map & amap,
typename Map::Dart_const_handle adart,
int amark)
{
amap.negate_mark(amark);
typename Map::size_type res = mark_orbit<Map, Iterator>(amap, adart, amark);
amap.negate_mark(amark);
return res;
}
/** Test if the two given darts belong to the same cell.
* @param amap a combinatorial map.
* @param adart1 the first dart.
* @param adart2 the second dart.
* @return true iff the two darts belong to the same cell.
*/
template < class Map, unsigned int i, unsigned int d>
bool belong_to_same_cell(const Map & amap,
typename Map::Dart_const_handle adart1,
typename Map::Dart_const_handle adart2)
{
return belong_to_same_orbit<Map,
typename Map::template
Dart_of_cell_range<i,d>::const_iterator>
(amap, adart1, adart2);
}
template < class Map, unsigned int i>
bool belong_to_same_cell(const Map & amap,
typename Map::Dart_const_handle adart1,
typename Map::Dart_const_handle adart2)
{
return belong_to_same_cell<Map,i,Map::dimension>(amap,adart1,adart2);
}
/** Test if all the darts of a given cell are marked.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @param amark the mark.
* @return true iff all the darts are marked.
*/
template < class Map, unsigned int i, unsigned int d>
bool is_whole_cell_marked(const Map & amap,
typename Map::Dart_const_handle adart,
unsigned int amark)
{
return is_whole_orbit_marked<Map,
typename Map::template
Dart_of_cell_range<i,d>::const_iterator>
(amap, adart, amark);
}
template < class Map, unsigned int i>
bool is_whole_cell_marked(const Map & amap,
typename Map::Dart_const_handle adart,
unsigned int amark)
{
return is_whole_cell_marked<Map,i,Map::dimension>(amap,adart,amark);
}
/** Test if all the darts of a given cell are unmarked.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @param amark the mark.
* @return true iff all the darts are marked.
*/
template < class Map, unsigned int i, unsigned int d >
bool is_whole_cell_unmarked(const Map & amap,
typename Map::Dart_const_handle adart,
unsigned int amark)
{
return is_whole_orbit_unmarked<Map,
typename Map::template
Dart_of_cell_range<i,d>::iterator>
(amap, adart, amark);
}
template < class Map, unsigned int i>
bool is_whole_cell_unmarked(const Map & amap,
typename Map::Dart_const_handle adart,
unsigned int amark)
{
return is_whole_cell_unmarked<Map,i,Map::dimension>(amap,adart,amark);
}
/** Mark a given cell with a given mark.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @param amark the mark.
* @return the number of darts of the marked cell.
* @pre The whole cell must be unmarked.
*/
template < class Map, unsigned int i, unsigned int d >
typename Map::size_type mark_cell(const Map & amap,
typename Map::Dart_const_handle adart,
int amark)
{ return mark_orbit<Map,
typename Map::template
Dart_of_cell_basic_range<i,d>::const_iterator>
(amap, adart, amark); }
template < class Map, unsigned int i>
typename Map::size_type mark_cell(const Map & amap,
typename Map::Dart_const_handle adart,
int amark)
{ return mark_cell<Map,i,Map::dimension>(amap, adart, amark);}
/** Unmark a given orbit with a given mark.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @param amark the mark.
* @return the number of darts of the unmarked cell.
* @pre The whole cell must be marked.
*/
template < class Map, unsigned int i, unsigned int d >
typename Map::size_type unmark_cell(const Map & amap,
typename Map::Dart_handle adart,
int amark)
{ return unmark_orbit<Map,
typename Map::template
Dart_of_cell_basic_range<i,d>::const_iterator>
(amap, adart, amark);}
template < class Map, unsigned int i >
typename Map::size_type unmark_cell(const Map & amap,
typename Map::Dart_handle adart,
int amark)
{ return unmark_cell<Map,i,Map::dimension>(amap, adart, amark);}
/** Compute the degree of a given i-cell c.
* The degree is the number of distinct i+1 cells incident to c.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @return the degree of the cell.
*/
template < class Map, unsigned int i >
typename Map::size_type degree( const Map & amap,
typename Map::Dart_handle adart )
{
CGAL_assertion(adart != NULL);
typename Map::size_type nbIncident = 0;
int mark = amap.get_new_mark();
int treated = amap.get_new_mark();
typename Map::template
Dart_of_cell_basic_range<i>::const_iterator it(amap, adart, mark);
for ( ;it.cont(); ++it )
{
if (!amap.is_marked(*it, treated))
{
++nbIncident;
mark_cell<Map,i+1>(amap, *it, treated);
}
amap.mark(*it,mark);
}
amap.negate_mark(mark);
for (it.rewind(); it.cont(); ++it)
{
if (amap.is_marked(*it, treated))
unmark_cell<Map,i+1>(amap, *it, treated);
amap.mark(*it,mark);
}
amap.negate_mark(mark);
CGAL_assertion( amap.is_whole_map_unmarked(mark) );
CGAL_assertion( amap.is_whole_map_unmarked(treated) );
amap.free_mark(mark);
amap.free_mark(treated);
CGAL_assertion(nbIncident != 0);
return nbIncident;
}
/** Compute the co-degree of a given i-cell c.
* The co-degree is the number of distinct i-1 cells incident to c.
* @param amap a combinatorial map.
* @param adart a dart of the cell.
* @return the co-degree of the cell.
*/
template < class Map, unsigned int i >
typename Map::size_type codegree(const Map & amap,
typename Map::Dart_handle adart)
{
CGAL_assertion(adart != NULL);
typename Map::size_type nbIncident = 0;
int mark = amap.get_new_mark();
int treated = amap.get_new_mark();
typename Map::template
Dart_of_cell_basic_range<i>::const_iterator it(amap, adart, mark);
for ( ; it.cont(); ++it)
{
if (!amap.is_marked(*it, treated))
{
++nbIncident;
mark_cell<Map,i-1>(amap, *it, treated);
}
amap.mark(*it,mark);
}
amap.negate_mark(mark);
for (it.rewind(); it.cont(); ++it)
{
if (amap.is_marked(*it, treated))
unmark_cell<Map,i-1>(amap, *it, treated);
amap.mark(*it,mark);
}
amap.negate_mark(mark);
CGAL_assertion( amap.is_whole_map_unmarked(mark) );
CGAL_assertion( amap.is_whole_map_unmarked(treated) );
amap.free_mark(mark);
amap.free_mark(treated);
CGAL_assertion(nbIncident != 0);
return nbIncident;
}
} // namespace CGAL
#endif // CGAL_COMBINATORIAL_MAP_BASIC_OPERATIONS_H //
// EOF //
|