X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=tools%2Fif2.cpp;fp=tools%2Fif2.cpp;h=db92c228aee511cbc53b788b4f0e65539f5a4db7;hp=ce6d3da9505236577646a560e5fcdb8b7a97a46e;hb=89997e727ff5d4d8828f6fdaee435d809b623ffe;hpb=75a3edd6e6a5c16aea583771dfd1924c7aee9103 diff --git a/tools/if2.cpp b/tools/if2.cpp index ce6d3da..db92c22 100644 --- a/tools/if2.cpp +++ b/tools/if2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if2.cpp,v 1.2 2000/12/18 13:39:15 kevin Exp $ +** $Id: if2.cpp,v 1.3 2000/12/19 21:37:51 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -45,7 +45,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if2.cpp,v 1.2 2000/12/18 13:39:15 kevin Exp $"; +static const char* g_szIdStr = "$Id: if2.cpp,v 1.3 2000/12/19 21:37:51 kevin Exp $"; void if2_usage (const char *program) @@ -55,7 +55,7 @@ if2_usage (const char *program) std::cout << std::endl; std::cout << " infile1 Name of first input IF file\n"; std::cout << " infile2 Name of second input IF file\n"; - std::cout << " outfile Name of output IF file\n"; + std::cout << " outfile Name of output Image or Plot file\n"; std::cout << " --add Add images\n"; std::cout << " --sub Subtract image 2 from image 1\n"; std::cout << " --mul Multiply images\n"; @@ -75,13 +75,14 @@ if2_main (int argc, char *const argv[]) ImageFile* pim_out = NULL; std::string in_file1; std::string in_file2; - std::string out_file; + std::string strOutFile; int opt_verbose = 0; int opt_add = 0; int opt_sub = 0; int opt_mul = 0; int opt_comp = 0; - bool opt_outputFile = false; + bool opt_bImageOutputFile = false; + bool opt_bPlotOutputFile = false; int opt_rowPlot = -1; int opt_columnPlot = -1; Timer timerProgram; @@ -96,27 +97,29 @@ if2_main (int argc, char *const argv[]) switch (c) { case O_ADD: opt_add = 1; - opt_outputFile = true; + opt_bImageOutputFile = true; break; case O_SUB : opt_sub = 1; - opt_outputFile = true; + opt_bImageOutputFile = true; break; case O_MUL: opt_mul = 1; - opt_outputFile = true; + opt_bImageOutputFile = true; break; case O_ROW_PLOT: opt_rowPlot = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) { if2_usage(argv[0]); } + opt_bPlotOutputFile = true; break; case O_COLUMN_PLOT: opt_columnPlot = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) { if2_usage(argv[0]); } + opt_bPlotOutputFile = true; break; case O_COMP: opt_comp = 1; @@ -141,19 +144,19 @@ if2_main (int argc, char *const argv[]) } } - if (opt_outputFile && (optind + 3 != argc)) { + if ((opt_bImageOutputFile || opt_bPlotOutputFile) && (optind + 3 != argc)) { if2_usage(argv[0]); return (1); } - else if (! opt_outputFile && optind + 2 != argc) { + else if (! (opt_bImageOutputFile || opt_bPlotOutputFile) && optind + 2 != argc) { if2_usage(argv[0]); return (1); } in_file1 = argv[optind]; in_file2 = argv[optind + 1]; - if (opt_outputFile) - out_file = argv[optind + 2]; + if (opt_bImageOutputFile || opt_bPlotOutputFile) + strOutFile = argv[optind + 2]; pim_in1 = new ImageFile (); pim_in2 = new ImageFile (); @@ -179,7 +182,11 @@ if2_main (int argc, char *const argv[]) ImageFileArray v2 = im_in2.getArray(); ImageFileArray vout = NULL; - if (opt_outputFile) { + if (opt_bImageOutputFile && opt_bPlotOutputFile) { + sys_error (ERR_SEVERE, "Both Image and Plot output files can not be selected simultaneously"); + return (1); + } + if (opt_bImageOutputFile) { pim_out = new ImageFile (im_in1.nx(), im_in1.ny()); vout = pim_out->getArray(); } @@ -222,7 +229,8 @@ if2_main (int argc, char *const argv[]) double d, r, e; im_in1.comparativeStatistics (im_in2, d, r, e); std::cout << "d=" << d << ", r=" << r << ", e=" << e << std::endl; - } + } + int i; if (opt_columnPlot > 0) { if (opt_columnPlot >= nx || opt_columnPlot >= nx2) { @@ -232,6 +240,18 @@ if2_main (int argc, char *const argv[]) double* plot_xaxis = new double [nx]; for (i = 0; i < nx; i++) plot_xaxis[i] = i; + + PlotFile plotFile (3, nx); + + plotFile.addColumn (0, plot_xaxis); + plotFile.addColumn (1, v1[opt_columnPlot]); + plotFile.addColumn (2, v2[opt_columnPlot]); + plotFile.setTitle ("Column Plot"); + plotFile.setXLabel ("Column"); + plotFile.setYLabel ("Pixel Value"); + + plotFile.fileWrite (strOutFile.c_str()); + #if HAVE_SGP SGPDriver driver ("Column Plot"); SGP sgp (driver); @@ -247,9 +267,9 @@ if2_main (int argc, char *const argv[]) ezplot.addCurve (plot_xaxis, v2[opt_columnPlot], im_in2.ny()); ezplot.plot(); std::cout << "Press enter to continue" << flush; - cio_kb_getc(); -#endif - delete plot_xaxis; + cio_kb_getc(); +#endif + delete plot_xaxis; } if (opt_rowPlot > 0) { @@ -258,16 +278,27 @@ if2_main (int argc, char *const argv[]) return (1); } double* plot_xaxis = new double [ny]; - double* v1Row = new double [nx]; - double* v2Row = new double [nx2]; + double* v1Row = new double [ny]; + double* v2Row = new double [ny2]; for (i = 0; i < ny; i++) plot_xaxis[i] = i; - for (i = 0; i < nx; i++) + for (i = 0; i < ny; i++) v1Row[i] = v1[i][opt_rowPlot]; - for (i = 0; i < nx2; i++) + for (i = 0; i < ny2; i++) v2Row[i] = v2[i][opt_rowPlot]; + PlotFile plotFile (3, ny); + + plotFile.addColumn (0, plot_xaxis); + plotFile.addColumn (1, v1Row); + plotFile.addColumn (2, v2Row); + plotFile.setTitle ("Row Plot"); + plotFile.setXLabel ("Row"); + plotFile.setYLabel ("Pixel Value"); + + plotFile.fileWrite (strOutFile.c_str()); + #if HAVE_SGP SGPDriver driver ("Row Plot"); SGP sgp (driver); @@ -290,13 +321,13 @@ if2_main (int argc, char *const argv[]) delete v2Row; } - if (opt_outputFile) { + if (opt_bImageOutputFile) { pim_out->labelsCopy (im_in1, "if2 file 1: "); pim_out->labelsCopy (im_in2, "if2 file 2: "); pim_out->labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str(), timerProgram.timerEnd()); - pim_out->fileWrite(out_file); + pim_out->fileWrite (strOutFile); } - + return (0); }