/************************************************************************** *** *** Copyright (c) 2004 Regents of the University of Michigan, *** Hayward H. Chan and Igor L. Markov *** *** Contact author(s): hhchan@umich.edu, imarkov@umich.edu *** Original Affiliation: EECS Department, *** The University of Michigan, *** Ann Arbor, MI 48109-2122 *** *** Permission is hereby granted, free of charge, to any person obtaining *** a copy of this software and associated documentation files (the *** "Software"), to deal in the Software without restriction, including *** without limitation *** the rights to use, copy, modify, merge, publish, distribute, sublicense, *** and/or sell copies of the Software, and to permit persons to whom the *** Software is furnished to do so, subject to the following conditions: *** *** The above copyright notice and this permission notice shall be included *** in all copies or substantial portions of the Software. *** *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *** THE USE OR OTHER DEALINGS IN THE SOFTWARE. *** *** ***************************************************************************/ #include #include #include using namespace std; const double ASPECT_RATIO = 1.5; int main(int argc, char* argv[]) { ifstream infile; ofstream outfile; bool label = false; int startNode = 0; double linewidth = 1.5; bool verbose = false; infile.open(argv[1]); if (!infile.good()) { cout << "Cannot open file: " << argv[1] << endl; exit(1); } outfile.open(argv[2]); if (!outfile.good()) { cout << "Cannot open file: " << argv[2] << endl; exit(1); } for (int i = 3; i < argc; i++) if (!strcmp(argv[i], "-s")) { i++; if (i >= argc) { cout << "\"-s\" must be followed by an integer." << endl; exit(1); } else startNode = atoi(argv[i]); } else if (!strcmp(argv[i], "-l")) label = true; else if (!strcmp(argv[i], "-n")) label = false; else if (!strcmp(argv[i], "-w")) { i++; if (i >= argc) cout << "ERROR: must specify a linewidth after \"-w\"" << endl; else linewidth = atof(argv[i]); } else if (!strcmp(argv[i], "-v")) verbose = true; else if (!strcmp(argv[i], "-t")) verbose = false; else { cout << "ERROR: invalid option \"" << argv[i] << "\"." << endl; exit(1); } double width, height; infile >> width >> height; int blocknum; infile >> blocknum; vector widths; vector heights; for (int i = 0; i < blocknum; i++) { double w, h; infile >> w >> h; widths.push_back(w); heights.push_back(h); } vector xloc; vector yloc; for (int i = 0; i < blocknum; i++) { double x, y; infile >> x >> y; xloc.push_back(x); yloc.push_back(y); } outfile << "function plotrect()" << endl; outfile << "axes('DataAspectRatio', [1 1 1]);" << endl; outfile << "axis off;" << endl; if (!verbose) outfile << "axis([0 " << width << " 0 " << height << "]); " << endl; else if (width < ASPECT_RATIO * height) outfile << "axis([0 " << width * 2 << " 0 " << height << "]); " << endl; else outfile << "axis([0 " << width << " 0 " << height * 2 << "]); " << endl; outfile << "hold on;" << endl; outfile << "total_x = ["; outfile << "0 0 " << width << " " << width << "];" << endl; outfile << "total_y = ["; outfile << "0 " << height << " " << height << " 0];" << endl; outfile << "set(fill(total_x, total_y, 'k'), 'LineWidth', " << linewidth << "); " << endl; double totalArea = 0; for (int i = 0; i < blocknum; i++) { outfile << endl; outfile << "x" << i << " = ["; outfile << xloc[i] << " " << xloc[i] << " "; outfile << xloc[i]+widths[i] << " " << xloc[i]+widths[i] << "];" << endl; outfile << "y" << i << " = ["; outfile << yloc[i] << " " << yloc[i]+heights[i] << " "; outfile << yloc[i]+heights[i] << " " << yloc[i] << "];" << endl; outfile << "set(fill(x" << i << ", y" << i << ", 'w'), 'LineWidth', " << linewidth << "); " << endl; if (label) { double xMid = xloc[i] + (widths[i] / 2); double yMid = yloc[i] + (heights[i] / 2); outfile << "text(" << xMid << ", " << yMid << ", '" << (startNode+i) << "', " << "'HorizontalAlignment', 'center', 'VerticalAlignment', 'middle', " << "'FontName', 'Times', 'FontSize', 24, 'FontWeight', 'normal')" << endl; } totalArea += widths[i] * heights[i]; } if (verbose) { outfile.setf(ios::fixed); outfile.precision(3); if (width < height * ASPECT_RATIO) { outfile << "set(text("; outfile << (width * 1.1) << ", " << (height / 2) << ", "; } else { outfile << "set(text("; outfile << (width / 2) << ", " << (height * 1.1) << ", "; } outfile << "sprintf("; outfile << "'-----" << argv[2] << "-----\\n"; outfile << "# blocks = " << blocknum << "\\n"; outfile << "width = " << width << "\\n"; outfile << "height = " << height << "\\n"; outfile << "area = " << width * height << "\\n"; outfile << "total block area = " << totalArea << "\\n"; outfile.precision(6); outfile << "dead space = " << ((width * height / totalArea) - 1) * 100 << "%c"; outfile.precision(3); outfile << "', '%')), "; if (width < height * ASPECT_RATIO) { outfile << "'HorizontalAlignment', 'left', "; outfile << "'VerticalAlignment', 'middle'"; } else { outfile << "'HorizontalAlignment', 'center', "; outfile << "'VerticalAlignment', 'bottom'"; } outfile << ");" << endl; // percentage sign for deadspace } return 0; }