// file: examples/Planar_map/example10.C #include #include #include #include #include #include #include #include #include template class Pm_my_vertex : public CGAL::Pm_vertex_base { public: Pm_my_vertex() : CGAL::Pm_vertex_base() { } void set_color(const std::string & c) { color = c; } std::string get_color() const { return color;} private: std::string color; }; // building new dcel with my vertex base. template class Pm_my_dcel : public CGAL::Pm_dcel, CGAL::Pm_halfedge_base, CGAL::Pm_face_base> { public: // Creation Pm_my_dcel() { } }; // extend the drawer to print the color as well. template class Pm_my_file_writer : public CGAL::Pm_file_writer { public: typedef typename PM::Vertex_handle Vertex_handle; typedef typename PM::Vertex_const_handle Vertex_const_handle; typedef typename PM::Vertex_iterator Vertex_iterator; typedef typename PM::Vertex_const_iterator Vertex_const_iterator; Pm_my_file_writer(std::ostream & o, const PM & pm, bool verbose = false) : CGAL::Pm_file_writer(o, pm, verbose) { } void write_vertex(Vertex_const_handle v) const { this->out() << v->point() <<" "; this->out() << v->get_color()<< std::endl; } }; typedef CGAL::Quotient NT; typedef CGAL::Cartesian Kernel; typedef CGAL::Pm_segment_traits_2 Traits; typedef Pm_my_dcel Dcel; typedef CGAL::Planar_map_2 Planar_map; typedef Planar_map::Vertex_iterator Vertex_iterator; int main() { Planar_map pm; std::cin >> pm; std::cout << "* * * Demonstrating definition of user attributes for " << "Planar map components" << std::endl << std::endl << std::endl; // Update the colors for halfedge and vertex: for (Vertex_iterator v_iter = pm.vertices_begin(); v_iter != pm.vertices_end(); ++v_iter) v_iter->set_color("BLUE"); // Print the map to output stream with the user attributes: std::cout << "* * * Printing the Planar map" << std::endl; std::cout << std::endl; Pm_my_file_writer writer(std::cout, pm); CGAL::write_pm(pm, writer, std::cout); return 0; }