From: Kevin M. Rosenberg Date: Sun, 18 Jun 2000 10:27:11 +0000 (+0000) Subject: r98: finished object-orient convern of Scanner & Phantom X-Git-Tag: debian-4.5.3-3~919 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=2c61ff85796550481227f2fbec53506a6b5bd365 r98: finished object-orient convern of Scanner & Phantom --- diff --git a/include/byteorder.h b/include/byteorder.h index 187e4fb..94fe959 100644 --- a/include/byteorder.h +++ b/include/byteorder.h @@ -1,9 +1,10 @@ #ifndef NETORDER_H #define NETORDER_H +#include + /* netorder.cpp */ -void *strreverse (void *dest, const void *src, size_t n); bool read_nint16 (kuint16 *n, int fd); bool write_nint16 (kuint16 const *n, int fd); bool read_nint32 (kuint32 *n, int fd); @@ -12,7 +13,32 @@ bool read_nfloat32 (float *f, int fd); bool write_nfloat32 (float const *f, int fd); bool read_nfloat64 (double *d, int fd); bool write_nfloat64 (double const *d, int fd); -void ConvertNetworkOrder (void* buffer, size_t bytes); -void ConvertReverseNetworkOrder (void* buffer, size_t bytes); +void ConvertNetworkOrder (void* buffer, size_t bytes); +void ConvertReverseNetworkOrder (void* buffer, size_t bytes); + +class inetorderstream : public istream { + public: + inetorderstream& readInt16 (kuint16& n); + inetorderstream& readInt32 (kuint32& n); + inetorderstream& readFloat32 (kfloat32& n); + inetorderstream& readFloat64 (kfloat64& n); +}; + +class onetorderstream : public ostream { + public: + onetorderstream& writeInt16 (kuint16 n); + onetorderstream& writeInt32 (kuint32 n); + onetorderstream& writeFloat32 (kfloat32 n); + onetorderstream& writeFloat64 (kfloat64 n); +}; + +void read_rnint16 (kuint16& n, istream istr); +void write_rnint16 (kuint16 n, ostream ostr); +void read_rnint32 (kuint32& n, istream istr); +void write_rnint32 (kuint32 n, ostream ostr); +void read_rnfloat32 (kfloat32& n, istream istr); +void write_rnfloat32 (kfloat32 n, ostream ostr); +void read_rnfloat64 (kfloat64& n, istream istr); +void write_rnfloat64 (kfloat64 n, ostream ostr); #endif diff --git a/include/ct.h b/include/ct.h index 4817fb3..937a885 100644 --- a/include/ct.h +++ b/include/ct.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ct.h,v 1.15 2000/06/17 20:12:14 kevin Exp $ +** $Id: ct.h,v 1.16 2000/06/18 10:27:11 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 @@ -125,6 +125,7 @@ extern "C" { #include "sgp.h" #endif +#include #include #include #include diff --git a/include/ezplot.h b/include/ezplot.h index 744a33d..4beb8ff 100644 --- a/include/ezplot.h +++ b/include/ezplot.h @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.h,v 1.5 2000/06/13 16:20:31 kevin Exp $ +** $Id: ezplot.h,v 1.6 2000/06/18 10:27:11 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 @@ -54,7 +54,7 @@ struct ezp_curve_st { }; #define XBUF_DEF 600 -#define YBUF_DEF XBUF_DEF * (72. / 120.) * 0.75 +#define YBUF_DEF 600 #define PRTMODE_DEF 1 /*----------------------------------------------------------------------*/ diff --git a/include/kmath.h b/include/kmath.h index bb30f05..0ed4f2a 100644 --- a/include/kmath.h +++ b/include/kmath.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: kmath.h,v 1.14 2000/06/17 20:12:14 kevin Exp $ +** $Id: kmath.h,v 1.15 2000/06/18 10:27:11 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 @@ -68,6 +68,18 @@ template inline T lineLength (T x1, T y1, T x2, T y2) { return static_cast( sqrt ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) ); } +template +inline void minmax_array (const T* array, const int n, T& min, T& max) +{ + max = min = array[0]; + + for (int i = 1; i < n; i++) + if (array[i] < min) + min = array[i]; + else if (array[i] > max) + max = array[i]; +} + /* clip.cpp */ int clip_rect(double *x1, double *y1, double *x2, double *y2, const double rect[4]); int clip_segment(double *x1, double *y1, double *x2, double *y2, const double u, const double v); @@ -92,8 +104,4 @@ void scale2d(double x[], double y[], int pts, double xfact, double yfact); /* simpson.cpp */ double simpson(const double xmin, const double xmax, const double *y, const int np); -/* minmax.cpp */ -void minmax_dvector(const double array[], const int pts, double *xmin, double *xmax); - - #endif diff --git a/src/ctrec.cpp b/src/ctrec.cpp index 0ec8402..42dadc0 100644 --- a/src/ctrec.cpp +++ b/src/ctrec.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctrec.cpp,v 1.10 2000/06/17 20:12:15 kevin Exp $ +** $Id: ctrec.cpp,v 1.11 2000/06/18 10:27:11 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 @@ -107,7 +107,6 @@ ctrec_main (int argc, char * argv[]) Projections projGlobal; char *pj_name, *im_filename = NULL; string remark; - char filt_name[80]; char *endptr; int opt_verbose = 0; int opt_debug = 0; @@ -204,14 +203,14 @@ ctrec_main (int argc, char * argv[]) nx = strtol(argv[optind + 2], &endptr, 10); ny = strtol(argv[optind + 3], &endptr, 10); + ostringstream filt_name; if (opt_filter == FILTER_G_HAMMING || opt_filter == FILTER_ABS_G_HAMMING) - snprintf (filt_name, sizeof(filt_name), "%s: alpha = %.2f", - name_of_filter (opt_filter), opt_filter_param); + filt_name << name_of_filter (opt_filter) << ": alpha=" << opt_filter_param; else - snprintf (filt_name, sizeof(filt_name), "%s", name_of_filter (opt_filter)); + filt_name << name_of_filter (opt_filter); ostringstream label; - label << "Reconstruct: " << nx << "x" << ny << ", " << filt_name << ", " << name_of_interpolation (opt_interp) << ", " << name_of_backproj(opt_backproj); + label << "Reconstruct: " << nx << "x" << ny << ", " << filt_name.str() << ", " << name_of_interpolation (opt_interp) << ", " << name_of_backproj(opt_backproj); remark = label.str(); if (opt_verbose) diff --git a/src/if-1.cpp b/src/if-1.cpp index 3150cf9..f85a269 100644 --- a/src/if-1.cpp +++ b/src/if-1.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if-1.cpp,v 1.6 2000/06/13 16:20:31 kevin Exp $ +** $Id: if-1.cpp,v 1.7 2000/06/18 10:27:11 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 @@ -49,17 +49,17 @@ static struct option my_options[] = void if1_usage (const char *program) { - fprintf(stdout, "if1_usage: %s infile outfile [OPTIONS]\n", fileBasename(program)); - fprintf(stdout, "Generate a IF file from a IF file\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " --invert Invert image\n"); - fprintf(stdout, " --log Natural logrithm of image\n"); - fprintf(stdout, " --exp Natural exponential of image\n"); - fprintf(stdout, " --sqr Square of image\n"); - fprintf(stdout, " --sqrt Square root of image\n"); - fprintf(stdout, " --verbose Verbose modem\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << endl; + cout << "Generate a IF file from a IF file" << endl; + cout << endl; + cout << " --invert Invert image" << endl; + cout << " --log Natural logrithm of image" << endl; + cout << " --exp Natural exponential of image" << endl; + cout << " --sqr Square of image" << endl; + cout << " --sqrt Square root of image" << endl; + cout << " --verbose Verbose modem" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int @@ -105,11 +105,11 @@ if1_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': if1_usage(argv[0]); diff --git a/src/if-2.cpp b/src/if-2.cpp index 29aef01..89e6cc8 100644 --- a/src/if-2.cpp +++ b/src/if-2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if-2.cpp,v 1.4 2000/06/13 16:20:31 kevin Exp $ +** $Id: if-2.cpp,v 1.5 2000/06/18 10:27:11 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 @@ -26,7 +26,7 @@ ******************************************************************************/ /* FILE - * sdf-2.c Generate a SDF file from two input SDF files + * if-2.c Generate a IF file from two input IF files */ #include "ct.h" @@ -46,25 +46,25 @@ static struct option my_options[] = }; void -sdf2_usage (const char *program) +if2_usage (const char *program) { - fprintf(stdout, "sdf2_usage: %s infile1 infile2 outfile [OPTIONS]\n", fileBasename(program)); - fprintf(stdout, "Generate an SDF2D file from two input SDF2D files\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " infile1 Name of first input SDF file\n"); - fprintf(stdout, " infile2 Name of second input SDF file\n"); - fprintf(stdout, " outfile Name of output SDF file\n"); - fprintf(stdout, " --add Add images\n"); - fprintf(stdout, " --sub Subtract image 2 from image 1\n"); - fprintf(stdout, " --mul Multiply images\n"); - fprintf(stdout, " --comp Compare images\n"); - fprintf(stdout, " --verbose Verbose modem\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << "usage: " << fileBasename(program) << " infile1 infile2 outfile [OPTIONS]" << endl; + cout << "Generate an image file from two input image files files" << endl; + cout << endl; + cout << " infile1 Name of first input IF file" << endl; + cout << " infile2 Name of second input IF file" << endl; + cout << " outfile Name of output IF file" << endl; + cout << " --add Add images" << endl; + cout << " --sub Subtract image 2 from image 1" << endl; + cout << " --mul Multiply images" << endl; + cout << " --comp Compare images" << endl; + cout << " --verbose Verbose modem" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int -sdf2_main (int argc, char *const argv[]) +if2_main (int argc, char *const argv[]) { ImageFile* pim_in1; ImageFile* pim_in2; @@ -102,23 +102,23 @@ sdf2_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (0); default: - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (1); } } if (optind + 3 != argc) { - sdf2_usage(argv[0]); + if2_usage(argv[0]); return (1); } @@ -137,12 +137,12 @@ sdf2_main (int argc, char *const argv[]) } if (im_in1.nx() != im_in2.nx() || im_in1.ny() != im_in2.ny()) { - fprintf(stderr, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match\n", + sys_error (ERR_SEVERE, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match", im_in1.nx(), im_in1.ny(), im_in2.nx(), im_in2.ny()); return(1); } if (im_in1.nx() < 0 || im_in1.ny() < 0) { - fprintf(stderr, "Error: Size of image < 0"); + sys_error (ERR_SEVERE, "Error: Size of image < 0"); return(1); } @@ -199,7 +199,7 @@ sdf2_main (int argc, char *const argv[]) } } abs_error /= (im_in1.nx() * im_in1.ny()); - fprintf(stdout, "Average Error = %f\n", abs_error); + cout << "Average Error: " << abs_error << endl; } im_out.arrayDataWrite(); @@ -216,7 +216,7 @@ sdf2_main (int argc, char *const argv[]) int main (int argc, char *const argv[]) { - return (sdf2_main(argc, argv)); + return (if2_main(argc, argv)); } #endif diff --git a/src/if2img.cpp b/src/if2img.cpp index 85237a7..018e504 100644 --- a/src/if2img.cpp +++ b/src/if2img.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if2img.cpp,v 1.5 2000/06/17 20:12:15 kevin Exp $ +** $Id: if2img.cpp,v 1.6 2000/06/18 10:27:11 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 @@ -83,41 +83,41 @@ enum { O_FORMAT_GIF, O_FORMAT_PNG, O_FORMAT_PNG16, O_FORMAT_PGM, O_FORMAT_PGMASC void if2img_usage (const char *program) { - fprintf(stdout, "usage: %s sdfname outfile [OPTIONS]\n", fileBasename(program)); - fprintf(stdout, "Convert IF file to an image file\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " sdfname Name of input SDF file\n"); - fprintf(stdout, " outfile Name of output file\n"); - fprintf(stdout, " --format Output format\n"); - fprintf(stdout, " pgm PGM (portable graymap) format (default)\n"); - fprintf(stdout, " pgmasc PGM (portable graymap) ASCII format\n"); + cout << "usage: " << fileBasename(program) << " ifname outfile [OPTIONS]" << endl; + cout << "Convert IF file to an image file" << endl; + cout << endl; + cout << " sdfname Name of input SDF file" << endl; + cout << " outfile Name of output file" << endl; + cout << " --format Output format" << endl; + cout << " pgm PGM (portable graymap) format (default)" << endl; + cout << " pgmasc PGM (portable graymap) ASCII format" << endl; #ifdef HAVE_PNG - fprintf(stdout, " png PNG (8-bit) format\n"); - fprintf(stdout, " png16 PNG (16-bit) format\n"); + cout << " png PNG (8-bit) format" << endl; + cout << " png16 PNG (16-bit) format" << endl; #endif #ifdef HAVE_GIF - fprintf(stdout, " gif GIF format\n"); + cout << " gif GIF format" << endl; #endif - fprintf(stdout, " disp Display on screen\n"); - fprintf(stdout, " --center Center of window\n"); - fprintf(stdout, " mode Mode is center of window (default)\n"); - fprintf(stdout, " mean Mean is center of window\n"); - fprintf(stdout, " --auto Set auto window\n"); - fprintf(stdout, " full Use full window (default)\n"); - fprintf(stdout, " std0.1 Use 0.1 standard deviation about center\n"); - fprintf(stdout, " std0.5 Use 0.5 standard deviation about center\n"); - fprintf(stdout, " std1 Use one standard deviation about center\n"); - fprintf(stdout, " std2 Use two standard deviations about center\n"); - fprintf(stdout, " std3 Use three standard deviations about center\n"); - fprintf(stdout, " --scale Scaling factor for output size\n"); - fprintf(stdout, " --min Set minimum intensity\n"); - fprintf(stdout, " --max Set maximum intensity\n"); - fprintf(stdout, " --stats Print image statistics\n"); - fprintf(stdout, " --labels Print image labels\n"); - fprintf(stdout, " --debug Set debug mode\n"); - fprintf(stdout, " --verbose Set verbose mode\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << " disp Display on screen" << endl; + cout << " --center Center of window" << endl; + cout << " mode Mode is center of window (default)" << endl; + cout << " mean Mean is center of window" << endl; + cout << " --auto Set auto window" << endl; + cout << " full Use full window (default)" << endl; + cout << " std0.1 Use 0.1 standard deviation about center" << endl; + cout << " std0.5 Use 0.5 standard deviation about center" << endl; + cout << " std1 Use one standard deviation about center" << endl; + cout << " std2 Use two standard deviations about center" << endl; + cout << " std3 Use three standard deviations about center" << endl; + cout << " --scale Scaling factor for output size" << endl; + cout << " --min Set minimum intensity" << endl; + cout << " --max Set maximum intensity" << endl; + cout << " --stats Print image statistics" << endl; + cout << " --labels Print image labels" << endl; + cout << " --debug Set debug mode" << endl; + cout << " --verbose Set verbose mode" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } @@ -156,7 +156,7 @@ if2img_main (int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr, "Error setting --min to %s\n", optarg); + sys_error (ERR_SEVERE, "Error setting --min to %s", optarg); if2img_usage(argv[0]); return (1); } @@ -167,7 +167,7 @@ if2img_main (int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr, "Error setting --max to %s\n", optarg); + sys_error (ERR_SEVERE, "Error setting --max to %s", optarg); if2img_usage(argv[0]); return (1); } @@ -177,7 +177,7 @@ if2img_main (int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --scale to %s\n", optarg); + sys_error (ERR_SEVERE, "Error setting --scale to %s", optarg); if2img_usage(argv[0]); return (1); } @@ -197,7 +197,7 @@ if2img_main (int argc, char *const argv[]) opt_auto = O_AUTO_STD3; else { - fprintf(stderr, "Invalid auto mode %s\n", optarg); + sys_error (ERR_SEVERE, "Invalid auto mode %s", optarg); if2img_usage(argv[0]); return (1); } @@ -209,11 +209,11 @@ if2img_main (int argc, char *const argv[]) opt_center = O_CENTER_MODE; else { - fprintf(stderr, "Invalid center mode %s\n", optarg); + sys_error (ERR_SEVERE, "Invalid center mode %s", optarg); if2img_usage(argv[0]); return (1); } - break; + break; case O_FORMAT: if (strcmp(optarg, O_FORMAT_PGM_STR) == 0) opt_format = O_FORMAT_PGM; @@ -232,7 +232,7 @@ if2img_main (int argc, char *const argv[]) else if (strcmp(optarg, O_FORMAT_DISP_STR) == 0) opt_format = O_FORMAT_DISP; else { - fprintf(stderr, "Invalid format mode %s\n", optarg); + sys_error (ERR_SEVERE, "Invalid format mode %s", optarg); if2img_usage(argv[0]); return (1); } @@ -251,9 +251,9 @@ if2img_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif exit(0); case O_HELP: @@ -282,7 +282,7 @@ if2img_main (int argc, char *const argv[]) pim = new ImageFile (in_file); ImageFile& im = *pim; if (! im.fileRead()) { - fprintf(stderr, "File %s does not exist\n", in_file); + sys_error (ERR_SEVERE, "File %s does not exist", in_file); return (1); } @@ -377,18 +377,18 @@ if2img_main (int argc, char *const argv[]) else if (opt_auto == O_AUTO_STD3) window = stddev * 3; else { - fprintf(stderr, "Internal Error: Invalid auto mode %d\n", opt_auto); + sys_error (ERR_SEVERE, "Internal Error: Invalid auto mode %d", opt_auto); return (1); } } if (opt_stats) { - fprintf(stdout,"nx=%d\n", nx); - fprintf(stdout,"ny=%d\n", ny); - fprintf(stdout,"min=%f\n", minfound); - fprintf(stdout,"max=%f\n", maxfound); - fprintf(stdout,"mean=%f\n", mean); - fprintf(stdout,"mode=%f\n", mode); - fprintf(stdout,"stddev=%f\n", stddev); + cout <<"nx: " << nx << endl; + cout <<"ny: " << ny << endl; + cout <<"min: " << minfound << endl; + cout <<"max: " << maxfound << endl; + cout <<"mean: " << mean << endl; + cout <<"mode: " << mode << endl; + cout <<"stddev: " << stddev << endl; } if (opt_auto != O_AUTO_FULL) { double center; @@ -398,7 +398,7 @@ if2img_main (int argc, char *const argv[]) else if (opt_center == O_CENTER_MEAN) center = mean; else { - fprintf(stderr, "Internal Error: Invalid center mode %d\n", opt_center); + sys_error (ERR_SEVERE, "Internal Error: Invalid center mode %d", opt_center); return (1); } if (! opt_set_max) @@ -409,8 +409,8 @@ if2img_main (int argc, char *const argv[]) } if (opt_stats) { - fprintf(stdout,"min_disp=%f\n", densmin); - fprintf(stdout,"max_disp=%f\n", densmax); + cout << "min display: " << densmin << endl; + cout << "max display: " << densmax << endl; } if (opt_format == O_FORMAT_PGM) @@ -436,7 +436,7 @@ if2img_main (int argc, char *const argv[]) } else { - fprintf(stderr, "Internal Error: Invalid format mode %d\n", opt_format); + sys_error (ERR_SEVERE, "Internal Error: Invalid format mode %d", opt_format); return (1); } return (0); @@ -631,14 +631,14 @@ sdf2d_to_gif (ImageFile& im, char *outfile, int nxcell, int nycell, double densm delete rowp; if ((out = fopen(outfile,"w")) == NULL) { - fprintf(stderr,"Error opening output file %s for writing\n", outfile); + sys_error(ERR_SEVERE,"Error opening output file %s for writing", outfile); exit(1); } gdImageGif(gif,out); fclose(out); gdImageDestroy(gif); #else - fprintf(stderr, "This version does not support GIF"); + cout << "This version does not support GIF" << endl; #endif } diff --git a/src/ifinfo.cpp b/src/ifinfo.cpp index a054f2a..f0a475d 100644 --- a/src/ifinfo.cpp +++ b/src/ifinfo.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ifinfo.cpp,v 1.7 2000/06/17 20:12:15 kevin Exp $ +** $Id: ifinfo.cpp,v 1.8 2000/06/18 10:27:11 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 @@ -49,19 +49,19 @@ static struct option my_options[] = void ifinfo_usage (const char *program) { - fprintf(stdout, "usage: %s infile [OPTIONS]\n", fileBasename(program)); - fprintf(stdout, "Imagefile information\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " infile Name of input SDF file\n"); - fprintf(stdout, " --display Display image\n"); - fprintf(stdout, " --labels Print image labels (default)\n"); - fprintf(stdout, " --no-labels Do not print image labels\n"); - fprintf(stdout, " --stats Print image statistics (default)\n"); - fprintf(stdout, " --no-stats Do not print image statistics\n"); - fprintf(stdout, " --debug Debug mode\n"); - fprintf(stdout, " --verbose Verbose mode\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << "usage: " << fileBasename(program) << " infile [OPTIONS]" << endl; + cout << "Imagefile information" << endl; + cout << endl; + cout << " infile Name of input IF file" << endl; + cout << " --display Display image" << endl; + cout << " --labels Print image labels (default)" << endl; + cout << " --no-labels Do not print image labels" << endl; + cout << " --stats Print image statistics (default)" << endl; + cout << " --no-stats Do not print image statistics" << endl; + cout << " --debug Debug mode" << endl; + cout << " --verbose Verbose mode" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int @@ -103,11 +103,11 @@ ifinfo_main (int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': ifinfo_usage(argv[0]); diff --git a/src/phm2if.cpp b/src/phm2if.cpp index 3e82eef..573cb7c 100644 --- a/src/phm2if.cpp +++ b/src/phm2if.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2if.cpp,v 1.9 2000/06/15 19:07:10 kevin Exp $ +** $Id: phm2if.cpp,v 1.10 2000/06/18 10:27:11 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 @@ -112,13 +112,13 @@ phm2if_main (int argc, char* argv[]) DomainType opt_filter_domain = D_SPATIAL; char *opt_outfile = NULL; int opt_debug = 0; - char str[256]; - char opt_desc[256], opt_phmfilename[256]; + string opt_desc; + string opt_phmfilename; char *endstr, *endptr; double opt_filter_param = 1; double opt_filter_bw = 1.; int opt_trace = TRACE_NONE; - int opt_verbose = 0; + bool opt_verbose = false; #ifdef HAVE_MPI ImageFile* imLocal = NULL; MPIWorld mpiWorld (argc, argv); @@ -129,8 +129,6 @@ phm2if_main (int argc, char* argv[]) #ifdef HAVE_MPI if (mpiWorld.getRank() == 0) { #endif - strcpy(opt_desc, ""); - strcpy(opt_phmfilename, ""); while (1) { int c = getopt_long(argc, argv, "", my_options, NULL); char *endptr = NULL; @@ -147,8 +145,8 @@ phm2if_main (int argc, char* argv[]) } break; case O_PHMFILE: - strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); - phm.createFromFile(opt_phmfilename); + opt_phmfilename = optarg; + phm.createFromFile(opt_phmfilename.c_str()); #ifdef HAVE_MPI if (mpiWorld.getRank() == 0) cerr << "Can't use phantom from file in MPI mode" << endl; @@ -156,7 +154,7 @@ phm2if_main (int argc, char* argv[]) #endif break; case O_VERBOSE: - opt_verbose = 1; + opt_verbose = true; break; case O_DEBUG: opt_debug = 1; @@ -180,13 +178,13 @@ phm2if_main (int argc, char* argv[]) } break; case O_DESC: - strncpy(opt_desc, optarg, sizeof(opt_desc)); + opt_desc = optarg; break; case O_FILTER_BW: opt_filter_bw = strtod(optarg, &endptr); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --filter-bw to %s\n", optarg); + sys_error(ERR_SEVERE,"Error setting --filter-bw to %s\n", optarg); phm2if_usage(argv[0]); return (1); } @@ -195,7 +193,7 @@ phm2if_main (int argc, char* argv[]) opt_filter_param = strtod(optarg, &endptr); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --filter-param to %s\n", optarg); + sys_error(ERR_SEVERE,"Error setting --filter-param to %s\n", optarg); phm2if_usage(argv[0]); return (1); } @@ -204,7 +202,7 @@ phm2if_main (int argc, char* argv[]) opt_nsample = strtol(optarg, &endptr, 10); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --nsample to %s\n", optarg); + sys_error(ERR_SEVERE,"Error setting --nsample to %s\n", optarg); phm2if_usage(argv[0]); return (1); } @@ -239,38 +237,31 @@ phm2if_main (int argc, char* argv[]) opt_nx = strtol(argv[optind+1], &endptr, 10); endstr = argv[optind+1] + strlen(argv[optind+1]); if (endptr != endstr) { - fprintf(stderr,"Error setting nx to %s\n", argv[optind+1]); + sys_error(ERR_SEVERE,"Error setting nx to %s\n", argv[optind+1]); phm2if_usage(argv[0]); return (1); } opt_ny = strtol(argv[optind+2], &endptr, 10); endstr = argv[optind+2] + strlen(argv[optind+2]); if (endptr != endstr) { - fprintf(stderr,"Error setting ny to %s\n", argv[optind+2]); + sys_error(ERR_SEVERE,"Error setting ny to %s\n", argv[optind+2]); phm2if_usage(argv[0]); return (1); } - snprintf(str, sizeof(str), "nx=%d, ny=%d, nsample=%d, ", opt_nx, opt_ny, opt_nsample); - if (opt_phmfilename[0]) { - strncat(str, "phantom=", sizeof(str)); - strncat(str, opt_phmfilename, sizeof(str)); - } - else if (opt_phmnum != -1) { - strncat(str, "phantom=", sizeof(str)); - strncat(str, name_of_phantom(opt_phmnum), sizeof(str)); - } + ostringstream oss; + oss << "nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", "; + if (opt_phmfilename.length()) + oss << "phantom=" << opt_phmfilename; + else if (opt_phmnum != -1) + oss << "phantom=" << name_of_phantom(opt_phmnum); else if (opt_filter != -1) { - strncat(str, "filter=", sizeof(str)); - strncat(str, name_of_filter(opt_filter), sizeof(str)); - strncat(str, " - ", sizeof(str)); - strncat(str, name_of_filter_domain(opt_filter_domain), sizeof(str)); - } - if (opt_desc[0]) { - strncat(str, ": ", sizeof(str)); - strncat(str, opt_desc, sizeof(str)); + oss << "filter=" << name_of_filter(opt_filter); + oss << " - " << name_of_filter_domain(opt_filter_domain); } - strncpy(opt_desc, str, sizeof(opt_desc)); + if (opt_desc.length()) + oss << ": " << opt_desc; + opt_desc = oss.str(); if (opt_verbose) cout << "Rasterize Phantom to Image" << endl << endl; @@ -363,7 +354,7 @@ phm2if_main (int argc, char* argv[]) { imGlobal->arrayDataWrite (); double calctime = timerProgram.timerEnd (); - imGlobal->labelAdd (Array2dFileLabel::L_HISTORY, opt_desc, calctime); + imGlobal->labelAdd (Array2dFileLabel::L_HISTORY, opt_desc.c_str(), calctime); imGlobal->fileClose (); if (opt_verbose) cout << "Time to rasterized phantom: " << calctime << " seconds" << endl; diff --git a/src/pj2if.cpp b/src/pj2if.cpp index c77f901..530f23b 100644 --- a/src/pj2if.cpp +++ b/src/pj2if.cpp @@ -1,7 +1,7 @@ /***************************************************************************** ** FILE IDENTIFICATION ** -** Name: proj2if.cpp +** Name: pj2if.cpp ** Purpose: Convert an projection data file to an image file ** Programmer: Kevin Rosenberg ** Date Started: April 2000 @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pj2if.cpp,v 1.1 2000/06/17 20:12:15 kevin Exp $ +** $Id: pj2if.cpp,v 1.2 2000/06/18 10:27:11 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 @@ -26,7 +26,7 @@ ******************************************************************************/ /* FILE - * proj2if.c Convert Raysum to image + * pj2if.c Convert Raysum to image * * DATE * Apr 1999 @@ -47,22 +47,22 @@ static struct option my_options[] = void -proj2if_usage (const char *program) +pj2if_usage (const char *program) { - fprintf(stdout, "usage: %s in-proj-file out-if-file [OPTIONS]\n", fileBasename(program)); - fprintf(stdout, "This program converts a projection file to a IF file\n"); - fprintf(stdout, "\n"); - fprintf(stdout, " --verbose Verbose mode\n"); - fprintf(stdout, " --version Print version\n"); - fprintf(stdout, " --help Print this help message\n"); + cout << "usage: " << fileBasename(program) << " in-proj-file out-if-file [OPTIONS]" << endl; + cout << "Converts a projection file to a IF file" << endl; + cout << endl; + cout << " --verbose Verbose mode" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } int -proj2if_main (const int argc, char *const argv[]) +pj2if_main (const int argc, char *const argv[]) { - char *proj_name, *im_name; + char *pj_name, *im_name; int ix, iy; bool opt_verbose = false; extern int optind; @@ -80,47 +80,47 @@ proj2if_main (const int argc, char *const argv[]) break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cout << "Unknown version number" << endl; #endif - exit(0); + return (0); case O_HELP: case '?': - proj2if_usage(argv[0]); + pj2if_usage(argv[0]); return (0); default: - proj2if_usage(argv[0]); + pj2if_usage(argv[0]); return (1); } } if (argc - optind != 2) { - proj2if_usage(argv[0]); + pj2if_usage(argv[0]); return (1); } - proj_name = argv[optind]; + pj_name = argv[optind]; im_name = argv[optind + 1]; - Projections proj; - if (! proj.read (proj_name)) { - sys_error (ERR_SEVERE, "Can not open projection file %s", proj_name); + Projections pj; + if (! pj.read (pj_name)) { + sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name); return (1); } if (opt_verbose) - proj.printScanInfo(); + pj.printScanInfo(); - ImageFile im (im_name, proj.nDet(), proj.nView()); + ImageFile im (im_name, pj.nDet(), pj.nView()); ImageFileArray v = im.getArray(); - for (iy = 0; iy < proj.nView(); iy++) + for (iy = 0; iy < pj.nView(); iy++) { - DetectorArray& detarray = proj.getDetectorArray (iy); + DetectorArray& detarray = pj.getDetectorArray (iy); const DetectorValue* detval = detarray.detValues(); - for (ix = 0; ix < proj.nDet(); ix++) + for (ix = 0; ix < pj.nDet(); ix++) { v[ix][iy] = detval[ix]; } @@ -128,7 +128,7 @@ proj2if_main (const int argc, char *const argv[]) im.fileCreate (); im.arrayDataWrite (); - im.labelAdd (Array2dFileLabel::L_HISTORY, proj.remark(), proj.calcTime()); + im.labelAdd (Array2dFileLabel::L_HISTORY, pj.remark(), pj.calcTime()); im.labelAdd (Array2dFileLabel::L_HISTORY, "Conversion from .pj to .if"); im.fileClose (); @@ -140,6 +140,6 @@ proj2if_main (const int argc, char *const argv[]) int main (const int argc, char *const argv[]) { - return (proj2if_main(argc, argv)); + return (pj2if_main(argc, argv)); } #endif