void TreeNode::draw() const { std::ofstream ofs(NODE_FILENAME); cairo_t *cr; cairo_surface_t *surface; CGAL::Bbox_2 bbox = region.bbox(); assert(bbox.xmin() >= 0.0); assert(bbox.ymin() >= 0.0); #ifdef PDF_OUTPUT surface = cairo_pdf_surface_create(IMG_FILENAME, bbox.xmax(), bbox.ymax()); #endif #ifdef PNG_OUTPUT surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bbox.xmax(), bbox.ymax()); #endif cr = cairo_create(surface); cairo_select_font_face(cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 10.0); draw_region(cr); draw_text(cr); write_centroid(ofs); cairo_show_page(cr); cairo_destroy(cr); #ifdef PNG_OUTPUT cairo_surface_write_to_png(surface, IMG_FILENAME); #endif cairo_surface_destroy(surface); }
void TreeNode::draw_region(cairo_t *cr) const { if (region.size() >= 3) { if (this->name) { Polygon_2::Vertex_circulator vcir, vend; vcir = vend = region.vertices_circulator(); Bbox_2 bbox = region.bbox(); cairo_pattern_t *fill = cairo_pattern_create_linear(bbox.xmin(), bbox.ymin(), bbox.xmax(), bbox.ymax()); cairo_pattern_add_color_stop_rgb(fill, 0.0, 1.0, 1.0, 1.0); /* L*a*b* 色空間 { double r, g, b; cl2pix(&r, &g, &b, dsfmt_genrand_open_open(&dsfmt), dsfmt_genrand_open_open(&dsfmt)); cairo_pattern_add_color_stop_rgb(fill, 1.0, r, g, b); } */ // 単なるRGB cairo_pattern_add_color_stop_rgb(fill, 1.0, dsfmt_genrand_open_open(&dsfmt), dsfmt_genrand_open_open(&dsfmt), dsfmt_genrand_open_open(&dsfmt)); cairo_move_to(cr, CGAL::to_double(vcir->x()), CGAL::to_double(vcir->y())); ++vcir; do { cairo_line_to(cr, CGAL::to_double(vcir->x()), CGAL::to_double(vcir->y())); ++vcir; } while (vcir != vend); cairo_line_to(cr, CGAL::to_double(vend->x()), CGAL::to_double(vend->y())); cairo_set_source(cr, fill); cairo_fill_preserve(cr); cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); cairo_stroke(cr); cairo_pattern_destroy(fill); } } std::list<TreeNode>::const_iterator tit; for (tit = children.begin(); tit != children.end(); ++tit) { tit->draw_region(cr); } }