File: map_3_foreach.cpp

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (115 lines) | stat: -rw-r--r-- 3,615 bytes parent folder | download | duplicates (2)
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
#include <CGAL/Combinatorial_map.h>
#include <CGAL/Combinatorial_map_operations.h>
#include <CGAL/Combinatorial_map_constructors.h>
#include <iostream>
#include <algorithm>

typedef CGAL::Combinatorial_map<3> CMap_3;
typedef CMap_3::Dart_handle        Dart_handle;

// Functor used to display all the vertices of a given volume
template<class CMap, unsigned int i>
struct Display_vertices_of_cell : public std::unary_function<CMap, void>
{
  Display_vertices_of_cell(const CMap& acmap) :
    cmap(acmap),
    nb_cell(0)
  {}

  void operator() (const typename CMap::Dart& d)
  {
    std::cout<<i<<"-cell "<<++nb_cell<<" : ";
    for (typename CMap::template One_dart_per_incident_cell_range<0,i>::
           const_iterator it=cmap.template one_dart_per_incident_cell<0,i>
           (cmap.dart_handle(d)).begin(),
           itend=cmap.template one_dart_per_incident_cell<0,i>
           (cmap.dart_handle(d)).end();
         it!=itend; ++it)
    {
      std::cout << &*it << "; ";
    }
    std::cout<<std::endl;
  }

  void operator() (const typename CMap::Dart* ptr)
  { operator() (*ptr); }
  
private:
  const CMap& cmap;
  unsigned int nb_cell;
};

// Functor used to remove a face
template<class CMap>
struct Remove_face : public std::unary_function<CMap, void>
{
  Remove_face(CMap& acmap) : cmap(acmap)
  {}

  void operator() (typename CMap::Dart* d)
  {
    CGAL::remove_cell<CMap,2>(cmap, cmap.dart_handle(*d));
    std::cout<<"CMap characteristics: ";
    cmap.display_characteristics(std::cout) << ", valid=" << cmap.is_valid() 
                                            << std::endl;
  }
  
private:
  CMap& cmap;
};


// Functor allowing to transform a variable into its address.
template<typename T>
struct Take_adress : public std::unary_function<T, T*>
{
  T* operator() (T& t) const
  { return &t; }
};

int main()
{
  CMap_3 cmap;

  // Create two tetrahedra.
  Dart_handle d1 = CGAL::make_combinatorial_tetrahedron(cmap);
  Dart_handle d2 = CGAL::make_combinatorial_tetrahedron(cmap);

  // Display the vertices of each volume by iterating on darts.
  std::cout<<"********Volumes********"<<std::endl;
  std::for_each(cmap.one_dart_per_cell<3>().begin(),
                cmap.one_dart_per_cell<3>().end(),
                Display_vertices_of_cell<CMap_3,3>(cmap));
  
  // 3-Sew the 2 tetrahedra along one facet
  cmap.sew<3>(d1, d2);

  // Display the vertices of each face by iterating on darts.
  std::cout<<"********Faces********"<<std::endl;
  std::for_each(cmap.one_dart_per_cell<2>().begin(),
                cmap.one_dart_per_cell<2>().end(),
                Display_vertices_of_cell<CMap_3,2>(cmap));

    // We display the map characteristics.
  std::cout<<"CMap characteristics: ";
  cmap.display_characteristics(std::cout) << ", valid=" << cmap.is_valid() 
                                          << std::endl << std::endl;

  std::vector<CMap_3::Dart*> toremove;

  // Copy in vector toremove one dart per face
  std::copy(boost::transform_iterator<Take_adress<CMap_3::Dart>,
                                      CMap_3::One_dart_per_cell_range<2>::iterator>
            (cmap.one_dart_per_cell<2>().begin(),
             Take_adress<CMap_3::Dart>()),
            boost::transform_iterator<Take_adress<CMap_3::Dart>,
                                      CMap_3::One_dart_per_cell_range<2>::iterator>
            (cmap.one_dart_per_cell<2>().end(),
             Take_adress<CMap_3::Dart>()),
            back_inserter(toremove));
  
  // Remove each face sequentially.
  std::for_each(toremove.begin(), toremove.end(), Remove_face<CMap_3>(cmap));
  
  return EXIT_SUCCESS;
}