示例#1
0
vector<Point> Design::FindUnblockedPoints(Point point, int block_index) const{
    vector<Point> points;
    points.push_back(point);
    Poly block = blocks_.at(block_index);
    for (unsigned int i = 0; i < block.Size(); ++i){
        Edge edge = block.GetEdge(i);
        //only take one end for each edge to avoid duplicates
        if (point.IsProjectedOn(edge) && !point.PointsOnSameLine(block.At(i))){
            points.push_back(point.Projection(edge));
        }
    }
    return points;
}
示例#2
0
void Design::PlotAndSave(const vector<Node> & nodes)const{//generate line doc for gnu
    //return;
    if (nodes.size() == 0)
        return;//Nothing to do with an empty tree
    static int count = -1;
    count++;//Every time plotTree got called, count+1. Then we can save picture with different name

    FILE * fp = popen ("gnuplot -persist", "w");
    //Plot the current tree edge
    DTYPE plot_x_min = INT_MAX, plot_x_max = 0, plot_y_min = INT_MAX, plot_y_max = 0;
    for (int i = 1; i < nodes.size(); ++i) {
        Node node = nodes.at(i);
        Node parent_node = nodes.at(node.parent_);
        fprintf(fp, "set arrow from %f,%f to %f,%f nohead\n",(double)node.point_.x,(double)node.point_.y, 
                (double)parent_node.point_.x, (double)parent_node.point_.y);


        plot_x_min = min(plot_x_min, min(node.point_.x, parent_node.point_.x));
        plot_x_max = max(plot_x_max, max(node.point_.x, parent_node.point_.x));
        plot_y_min = min(plot_y_min, min(node.point_.y, parent_node.point_.y));
        plot_y_max = max(plot_y_max, max(node.point_.y, parent_node.point_.y));
    }
    //Only plot the range around this tree. It will include all blocks in this range
    fprintf (fp, "set xrange [ %f : %f ]\n", 
            (double)plot_x_min-0.2*(plot_x_max-plot_x_min)-30, (double)plot_x_max+0.2*(plot_x_max-plot_x_min)+30.0);//30 is for test04
    fprintf (fp, "set yrange [ %f : %f ]\n",
            (double)plot_y_min-0.2*(plot_y_max-plot_y_min)-30, (double)plot_y_max+0.2*(plot_y_max-plot_y_min)+30);
    for (vector<Poly>::const_iterator it2 = blocks_.begin(); it2 != blocks_.end(); ++it2){
        Poly block = *it2;
        fprintf (fp, "set object %d polygon from ", 1 + it2-blocks_.begin());//from 1
        for (unsigned int i=0; i<block.Size();++i){
            Point point = block.At(i);
            fprintf (fp, "%f,%f", (double)point.x, (double)point.y);
            fprintf (fp," to ");
        }
        assert (block.Size() > 0);//Block with size 0 shouldn't exist
        if (block.Size() > 0){
            Point start_point = block.At(0);
            fprintf (fp, " %f,%f fs pattern 1 bo 2 fc rgbcolor \"cyan\"\n",
                    (double)start_point.x, (double)start_point.y);//to close the Polygon
        }
    }
    //Plot node in blue and root in red
    //This one use plot function, so it has to be done at last
    for (int i = 0; i < nodes.size();) {
        if (i == 0)
            fprintf (fp, "plot ");
        Node node = nodes.at(i);
        Node parent_node = nodes.at(node.parent_);
        if (i == 0){//root
            fprintf(fp, "\"<echo '%f %f'\" notitle with points pointtype 7 pointsize 1 linecolor rgb \"red\"", 
                    (double)node.point_.x,(double)node.point_.y);
        }else if (node.type_ == Node::SINK){
            fprintf(fp, "\"<echo '%f %f'\" notitle with points pointtype 4 pointsize 1 linecolor rgb \"green\"",
                    (double)node.point_.x,(double)node.point_.y);
        }else{
            fprintf(fp, "\"<echo '%f %f'\" notitle with points pointtype 4 pointsize 1 linecolor rgb \"blue\"",
                    (double)node.point_.x,(double)node.point_.y);
        }
        i++;
        if (i != nodes.size()){
            fprintf (fp, ", ");
        }
    }
    //Plot buffers in purple
    list<pair<Point,Buffer> > buffer_locations = best_solution_.get_buffer_locations();
    printf ("The buffer number is %d\n", buffer_locations.size());
    if (buffer_locations.size() !=0 ){
        for (list<pair<Point,Buffer> >::const_iterator buffer_location = buffer_locations.begin(); buffer_location != buffer_locations.end(); ){
            Point buffer_location_point = buffer_location->first;
            printf ("The location is at %f %f\n", (double)buffer_location_point.x,(double)buffer_location_point.y);
            fprintf (fp, ", ");
            fprintf(fp, "\"<echo '%f %f'\" notitle with points pointtype 6 pointsize 1 linecolor rgb \"purple\"",
                    (double)buffer_location_point.x,(double)buffer_location_point.y);
            buffer_location++;
        }
    }
    fprintf (fp, "\n");
    //Save to file
    fprintf (fp, "set terminal png\n");  
    fprintf (fp, "set output \"%s/my_plot_%d.png\"\n", benchmark_path_, count);//gthumb Erint
    //Plot on screen
    fprintf (fp, "replot\n");
    fprintf (fp, "set terminal x11\n");
    fprintf (fp, "pause -1\n");
    pclose (fp);
    return;

}