File: gmap_linear_cell_complex_3.cpp

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

typedef CGAL::Linear_cell_complex_for_generalized_map<3> LCC_3;
typedef LCC_3::Dart_descriptor Dart_descriptor;
typedef LCC_3::Point           Point;
typedef LCC_3::FT              FT;

// Functor used to display all the vertices of a given volume.
template<class LCC>
struct Display_vol_vertices : public CGAL::cpp98::unary_function<LCC, void>
{
  Display_vol_vertices(const LCC& alcc) :
    lcc(alcc),
    nb_volume(0)
  {}

  void operator() (typename LCC::Dart& d)
  {
    std::cout<<"Volume "<<++nb_volume<<" : ";
    for (typename LCC::template One_dart_per_incident_cell_range<0,3>::
           const_iterator it=lcc.template one_dart_per_incident_cell<0,3>
           (lcc.dart_descriptor(d)).begin(),
           itend=lcc.template one_dart_per_incident_cell<0,3>
           (lcc.dart_descriptor(d)).end();
         it!=itend; ++it)
    {
      std::cout << lcc.point(it) << "; ";
    }
    std::cout<<std::endl;
  }
private:
  const LCC& lcc;
  unsigned int nb_volume;
};

int main()
{
  LCC_3 lcc;

  // Create two tetrahedra.
  Dart_descriptor d1 = lcc.make_tetrahedron(Point(-1, 0, 0), Point(0, 2, 0),
                                        Point(1, 0, 0), Point(1, 1, 2));
  Dart_descriptor d2 = lcc.make_tetrahedron(Point(0, 2, -1),
                                        Point(-1, 0, -1),
                                        Point(1, 0, -1),
                                        Point(1, 1, -3));

  // Display all the vertices of the lcc by iterating on the
  // Vertex_attribute container.
  CGAL::IO::set_ascii_mode(std::cout);
  std::cout<<"Vertices: ";
  for (LCC_3::Vertex_attribute_const_range::iterator
         v=lcc.vertex_attributes().begin(),
         vend=lcc.vertex_attributes().end();
       v!=vend; ++v)
    std::cout << lcc.point_of_vertex_attribute(v) << "; ";
  std::cout<<std::endl;

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));

  // 3-Sew the 2 tetrahedra along one facet
  lcc.sew<3>(d1, d2);

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));

  // Translate the second tetrahedra by a given vector
  LCC_3::Vector v(3,1,1);
  for (LCC_3::One_dart_per_incident_cell_range<0,3>::iterator
         it=lcc.one_dart_per_incident_cell<0,3>(d2).begin(),
         itend=lcc.one_dart_per_incident_cell<0,3>(d2).end();
       it!=itend; ++it)
  {
    lcc.point(it)=LCC_3::Traits::Construct_translated_point_3()
      (lcc.point(it),v);
  }

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));

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

  return EXIT_SUCCESS;
}