File: Generalized_map_sewable.h

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (121 lines) | stat: -rw-r--r-- 3,763 bytes parent folder | download
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
// Copyright (c) 2016 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Generalized_map/include/CGAL/Generalized_map/internal/Generalized_map_sewable.h $
// $Id: include/CGAL/Generalized_map/internal/Generalized_map_sewable.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#ifndef CGAL_GENERALIZED_MAP_SEWABLE_H
#define CGAL_GENERALIZED_MAP_SEWABLE_H

#include <CGAL/GMap_dart_const_iterators.h>
#include <CGAL/Unique_hash_map.h>

/* Definition of functor used to test if two darts are i-sewable
 * (we use functors as there are different specializations).
 * @todo Specializations ?
 */
namespace CGAL
{
namespace internal
{
// Generic case (and for the moment the only one).
template<typename GMap, unsigned int i, unsigned int dim=GMap::dimension>
struct GMap_is_sewable_functor
{
  static bool run( const GMap& amap,
                   typename GMap::Dart_const_descriptor adart1,
                   typename GMap::Dart_const_descriptor adart2 )
  {
    CGAL_assertion( i<=GMap::dimension );
    if ( !amap.template is_free<i>(adart1) ||
         !amap.template is_free<i>(adart2) )
      return false;

    if ( adart1==adart2 )
    {
      if ( i==1 ) return true;
      return false;
    }

    // hash map to build the isomorphism between the two i-cells.
    CGAL::Unique_hash_map<typename GMap::Dart_const_descriptor,
        typename GMap::Dart_const_descriptor,
        typename GMap::Hash_function> bijection;

    typename GMap::size_type m1 = amap.get_new_mark();
    typename GMap::size_type m2 = amap.get_new_mark();
    CGAL::GMap_dart_const_iterator_basic_of_involution<GMap,i>
        I1(amap, adart1, m1);
    CGAL::GMap_dart_const_iterator_basic_of_involution<GMap,i>
        I2(amap, adart2, m2);
    bool res = true;
    typename GMap::size_type mbijection = amap.get_new_mark();

    while ( res && I1.cont() && I2.cont() )
    {
      amap.mark(I1, mbijection);
      bijection[I1]=I2;

      CGAL_assertion( amap.template is_free<i>(I1) );
      CGAL_assertion( amap.template is_free<i>(I2) );

      // We can remove this constraint which is not required for
      // generalized map definition, but which is quite "normal"
      // Indeed in this case we try to i-sew an i-cell with itself (case
      // of folded cells).
      if ( I1==adart2 || I2==adart1 ) res=false;

      for ( unsigned int j=0; res && j<=GMap::dimension; ++j )
      {
        if ( j+1!=i && j!=i && j!=i+1 )
        {
          if ( amap.is_free(I1,j) )
          {
            if ( !amap.is_free(I2,j) ) res=false;
          }
          else
          {
            if ( amap.is_free(I2,j) ) res=false;
            else if ( amap.is_marked(amap.alpha(I1,j), mbijection) )
            {
              if ( bijection[amap.alpha(I1,j)]!=amap.alpha(I2,j) ) res=false;
            }
          }
        }
      }
      ++I1; ++I2;
    }
    if ( I1.cont()!=I2.cont() )
      res = false;

    amap.negate_mark(m1);
    amap.negate_mark(m2);
    I1.rewind(); I2.rewind();
    while ( amap.number_of_marked_darts(mbijection)>0 )
    {
      amap.unmark(I1, mbijection);
      ++I1; ++I2;
    }

    CGAL_assertion( amap.is_whole_map_marked(m1) );
    CGAL_assertion( amap.is_whole_map_marked(m2) );
    CGAL_assertion( amap.is_whole_map_unmarked(mbijection) );
    amap.free_mark(m1);
    amap.free_mark(m2);
    amap.free_mark(mbijection);

    return res;
  }
};

} //namespace internal

} //namespace CGAL

#endif // CGAL_COMBINATORIAL_MAP_SEWABLE_H
//******************************************************************************