File: gmap_3_marks.cpp

package info (click to toggle)
cgal 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 141,840 kB
  • sloc: cpp: 797,081; ansic: 203,398; sh: 490; python: 411; makefile: 286; javascript: 174
file content (62 lines) | stat: -rw-r--r-- 1,610 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
#include <CGAL/Generalized_map.h>
#include <iostream>
#include <cstdlib>
#include <cassert>

typedef CGAL::Generalized_map<3> GMap_3;
typedef GMap_3::Dart_descriptor Dart_descriptor;
typedef GMap_3::size_type size_type;

int main()
{
  GMap_3 gm;

  // 1) Reserve a mark.
  size_type amark;
  try
  {
    amark = gm.get_new_mark();
  }
  catch (GMap_3::Exception_no_more_available_mark)
  {
    std::cerr<<"No more free mark, exit."<<std::endl;
    exit(-1);
  }

  // 2) Create two tetrahedra.
  Dart_descriptor d1 = gm.make_combinatorial_tetrahedron();
  Dart_descriptor d2 = gm.make_combinatorial_tetrahedron();

  assert( gm.is_valid() );
  assert( gm.is_volume_combinatorial_tetrahedron(d1) );
  assert( gm.is_volume_combinatorial_tetrahedron(d2) );

  // 3) 3-sew them.
  gm.sew<3>(d1, d2);

  // 4) Mark the darts belonging to the first tetrahedron.

  // Mark the darts belonging to the first tetrahedron.
  for (GMap_3::Dart_of_cell_range<3>::iterator
       it(gm.darts_of_cell<3>(d1).begin()),
       itend(gm.darts_of_cell<3>(d1).end()); it!=itend; ++it)
    gm.mark(it, amark);

  // 4) Remove the common 2-cell between the two cubes:
  //    the two tetrahedra are merged.
  gm.remove_cell<2>(d1);

  // 5) Thanks to the mark, we know which darts come from the first tetrahedron.
  unsigned int res=0;
  for (GMap_3::Dart_range::iterator it(gm.darts().begin()),
         itend(gm.darts().end()); it!=itend; ++it)
  {
    if ( gm.is_marked(it, amark) )
      ++res;
  }

  std::cout<<"Number of darts from the first tetrahedron: "<<res<<std::endl;
  gm.free_mark(amark);

  return EXIT_SUCCESS;
}