Allink  v0.1
skin_surface_writer.h
1 #ifndef CGAL_SKIN_SURFACE_WRITER_H
2 #define CGAL_SKIN_SURFACE_WRITER_H
3 
4 #include <fstream>
5 #include <CGAL/IO/Polyhedron_iostream.h>
6 #include <CGAL/subdivide_skin_surface_mesh_3.h>
7 #include <CGAL/Skin_surface_refinement_policy_3.h>
8 
9 template <class SkinSurface, class Polyhedron>
11 void write_polyhedron_with_normals(SkinSurface &skin,
12  Polyhedron &p,
13  std::ostream &out)
14 {
15  typedef typename Polyhedron::Vertex_iterator Vertex_iterator;
16  typedef typename Polyhedron::Facet_iterator Facet_iterator;
17  typedef typename Polyhedron::Halfedge_around_facet_circulator HFC;
18  typedef typename Polyhedron::Vertex_handle Vertex_handle;
19  typedef typename Polyhedron::Traits::Vector_3 Vector;
20 
21  CGAL::Skin_surface_refinement_policy_3<SkinSurface, Polyhedron> policy(skin);
22 
23  // Write header
24  out << "NOFF " << p.size_of_vertices ()
25  << " " << p.size_of_facets()
26  << " " << p.size_of_halfedges()
27  << std::endl;
28 
29 
30 
31  // Write vertices
32  for (Vertex_iterator vit = p.vertices_begin();
33  vit != p.vertices_end(); vit ++) {
34  Vector n = policy.normal(vit);
35  n = n/sqrt(n*n);
36  out << vit->point() << " " << n << std::endl;
37  }
38 
39  // Write faces
40  CGAL::Inverse_index<Vertex_handle> index(p.vertices_begin(),
41  p.vertices_end());
42  for(Facet_iterator fi = p.facets_begin();
43  fi != p.facets_end(); ++fi) {
44  HFC hc = fi->facet_begin();
45  HFC hc_end = hc;
46  std::size_t n = circulator_size(hc);
47  out << n;
48  do {
49  Vertex_handle vh = (*hc).vertex();
50  out << " " << index[vh];
51  } while (++hc != hc_end);
52  out << "\n";
53  }
54 }
55 
56 #endif // CGAL_SKIN_SURFACE_WRITER_H