Allink  v0.1
skin_surface_writer.h
00001 #ifndef CGAL_SKIN_SURFACE_WRITER_H
00002 #define CGAL_SKIN_SURFACE_WRITER_H
00003 
00004 #include <fstream>
00005 #include <CGAL/IO/Polyhedron_iostream.h>
00006 #include <CGAL/subdivide_skin_surface_mesh_3.h>
00007 #include <CGAL/Skin_surface_refinement_policy_3.h>
00008 
00009 template <class SkinSurface, class Polyhedron>
00011 void write_polyhedron_with_normals(SkinSurface &skin,
00012                Polyhedron &p,
00013                std::ostream &out)
00014 {
00015   typedef typename Polyhedron::Vertex_iterator                  Vertex_iterator;
00016   typedef typename Polyhedron::Facet_iterator                   Facet_iterator;
00017   typedef typename Polyhedron::Halfedge_around_facet_circulator HFC;
00018   typedef typename Polyhedron::Vertex_handle                    Vertex_handle;
00019   typedef typename Polyhedron::Traits::Vector_3                 Vector;
00020 
00021   CGAL::Skin_surface_refinement_policy_3<SkinSurface, Polyhedron> policy(skin);
00022 
00023   // Write header
00024   out << "NOFF " << p.size_of_vertices ()
00025       << " " << p.size_of_facets()
00026       << " " << p.size_of_halfedges()
00027       << std::endl;
00028 
00029 
00030 
00031   // Write vertices
00032   for (Vertex_iterator vit = p.vertices_begin();
00033        vit != p.vertices_end(); vit ++) {
00034     Vector n = policy.normal(vit);
00035     n = n/sqrt(n*n);
00036     out << vit->point() << " " << n << std::endl;
00037   }
00038 
00039   // Write faces
00040   CGAL::Inverse_index<Vertex_handle> index(p.vertices_begin(),
00041                   p.vertices_end());
00042   for(Facet_iterator fi = p.facets_begin();
00043       fi != p.facets_end(); ++fi) {
00044     HFC hc = fi->facet_begin();
00045     HFC hc_end = hc;
00046     std::size_t n = circulator_size(hc);
00047     out << n;
00048     do {
00049       Vertex_handle vh = (*hc).vertex();
00050       out << " " << index[vh];
00051     } while (++hc != hc_end);
00052     out << "\n";
00053   }
00054 }
00055 
00056 #endif // CGAL_SKIN_SURFACE_WRITER_H