Пример #1
0
Circle_2 DT::global_largest_circumcircle_bruteforce(FH &face) const
{
    Circle_2 largest(Point_2(0, 0), 0);
    CDT::Face_iterator fi;
    for (fi = dt.faces_begin(); fi != dt.faces_end(); ++fi) {
        if (dt.is_infinite(fi)) continue;
        if (!fi->info().main_face) continue;
        
        Circle_2 c = fi->info().circle;
        if (c.squared_radius() > largest.squared_radius()) {
            largest = c;
            face = fi;
        }
    }
    return largest;
}
Пример #2
0
void DT::save_triangulation_eps(const char *fname, bool debug) const
{
    std::ofstream os;
    os.open(fname, std::ofstream::out | std::ofstream::trunc);
    
    double scale = 512.0;
    double radius = 3.0 / scale;
    Point_2 BB[2];
    if (debug) {
        BB[0] = Point_2( -scale,  -scale);
        BB[1] = Point_2(2*scale, 2*scale);
    } else {
        BB[0] = Point_2(0, 0);
        BB[1] = Point_2(scale, scale);
    }
    
    os << "%!PS-Adobe-3.1 EPSF-3.0\n";
    os << "%%HiResBoundingBox: " << BB[0] << " " << BB[1] << "\n";
    os << "%%BoundingBox: " << BB[0] << " " << BB[1] << "\n";
    os << "%%CropBox: " << BB[0] << " " << BB[1] << "\n";
    os << "/radius { " << radius << " } def\n";
    os << "/p { radius 0 360 arc closepath fill stroke } def\n";
    
    os << "gsave " << scale << " " << scale << " scale\n";
    os << (1.0 / scale) << " setlinewidth\n";
    
    // Faces
    os << "0.75 0.75 0.75 setrgbcolor\n";
    CDT::Face_iterator fi;
    for (fi = dt.faces_begin(); fi != dt.faces_end(); ++fi) {
        if (!fi->info().main_face) continue;
        
        Point_2 p0 = fi->vertex(0)->point(),
                p1 = fi->vertex(1)->point(),
                p2 = fi->vertex(2)->point();
        os << p0 << " moveto "
           << p1 << " lineto " << p2 << " lineto closepath "
           << (debug ? "fill" : "stroke") << "\n";
    }
    
    // Edges
    os << "0.25 0.25 0.25 setrgbcolor\n";
    CDT::Edge_iterator ei;
    for (ei = dt.edges_begin(); ei != dt.edges_end(); ++ei) {
        const FH fh = ei->first;
        const int i = ei->second;
        Point_2 p0 = fh->vertex(CDT::cw(i))->point(),
                p1 = fh->vertex(CDT::ccw(i))->point();
        os << p0 << " moveto " << p1 << " lineto stroke\n";
    }
    
    // Vertices
    os << "0 0 0 setrgbcolor\n";
    for (unsigned i = 0; i < sites.size(); ++i)
        os << sites[i].vertex->point() << " p\n";
    
    os << "grestore\n";

    // Bounding Box
    if (debug) {
        os << "0 0 0 setrgbcolor\n";
        os << "1.0 setlinewidth\n";
        os << "0 0 moveto 0 " << scale << " rlineto " << scale
           << " 0 rlineto 0 " << -scale << " rlineto closepath stroke\n";
    }
    
    os.close();
}