File: sm_memory.cpp

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (67 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download | duplicates (3)
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
#include <iostream>

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>

typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
typedef Mesh::Vertex_index vertex_descriptor;

int main()
{
  Mesh m;
  Mesh::Vertex_index u;
  for(unsigned int i=0; i < 5; ++i){
    Mesh::Vertex_index v = m.add_vertex(K::Point_3(0,0,i+1));
    if(i==2) u=v;
  }

  m.remove_vertex(u);

  std::cout << "After insertion of 5 vertices and removal of the 3. vertex\n"
            << "# vertices  / # vertices + # removed vertices = "
            << m.number_of_vertices()
            << " / " << m.number_of_vertices() + m.number_of_removed_vertices() << std::endl;

  std::cout << "Iterate over vertices\n";
  {
    for(vertex_descriptor vd : m.vertices()){
      std::cout << m.point(vd) << std::endl;
    }
  }

  // The status of being used or removed is stored in a property map
  Mesh::Property_map<Mesh::Vertex_index,bool> removed
    = m.property_map<Mesh::Vertex_index,bool>("v:removed").value();


  std::cout << "\nIterate over vertices and deleted vertices\n"
            << "# vertices / # vertices + # removed vertices = "
            << m.number_of_vertices()
            << " / " << m.number_of_vertices() + m.number_of_removed_vertices() << std::endl;
    {
    unsigned int i = 0, end = m.number_of_vertices() + m.number_of_removed_vertices();
    for( ; i < end; ++i) {
      vertex_descriptor vh(i);
      assert(m.is_removed(vh) == removed[vh]);
      std::cout << m.point(vh) << ((m.is_removed(vh)) ? "  R\n" : "\n");
    }
  }

  m.collect_garbage();

  std::cout << "\nAfter garbage collection\n"
            << "# vertices / # vertices + # removed vertices = "
            << m.number_of_vertices()
            << " / " << m.number_of_vertices() + m.number_of_removed_vertices() << std::endl;

 {
   unsigned int i = 0, end = m.number_of_vertices() + m.number_of_removed_vertices();
    for( ; i < end; ++i) {
      vertex_descriptor vh(i);
      std::cout << m.point(vh) << ((m.is_removed(vh)) ? "  R\n" : "\n");
    }
  }

  return 0;
}