1 #include <CGAL/Simple_cartesian.h> 2 #include <CGAL/Polyhedron_3.h> 3 #include <CGAL/Iterator_range.h> 4 5 6 #include <iostream> 7 #include <fstream> 8 #include <list> 9 #include <algorithm> 10 11 12 typedef CGAL::Simple_cartesian<double> Kernel; 13 typedef CGAL::Polyhedron_3<Kernel> Polyhedron; 14 15 typedef boost::graph_traits<Polyhedron>::vertex_descriptor vertex_descriptor; 16 typedef boost::graph_traits<Polyhedron>::vertex_iterator vertex_iterator; 17 18 typedef CGAL::Iterator_range<vertex_iterator> vertex_range; 19 20 vertices_range(const Polyhedron & p)21vertex_range vertices_range(const Polyhedron& p) 22 { 23 return vertex_range(vertices(p)); 24 } 25 26 struct Fct 27 { operator ()Fct28 void operator()(const vertex_descriptor& vd) const 29 { 30 std::cout << vd->point() << std::endl; 31 } 32 }; 33 fct(const Polyhedron & p)34void fct(const Polyhedron& p) 35 { 36 vertex_range vr(vertices(p)); 37 38 std::cout << "new for loop" << std::endl; 39 for(vertex_descriptor vd : vr){ 40 std::cout << vd->point() << std::endl; 41 } 42 43 std::cout << "boost::tie + std::for_each" << std::endl; 44 vertex_iterator vb, ve; 45 46 boost::tie(vb,ve) = vertices_range(p); 47 std::for_each(vb,ve, Fct()); 48 } 49 main(int argc,char ** argv)50int main(int argc, char** argv) 51 { 52 Polyhedron P; 53 std::ifstream in((argc>1)?argv[1]:"cube.off"); 54 in >> P ; 55 56 fct(P); 57 return 0; 58 } 59