From 942fa072e28ea2f0c44d09d535a8f05cae75f5d8 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Wed, 7 Jun 2000 06:57:32 +0000 Subject: [PATCH] r80: removed support for sdf files --- src/phm2sdf.cpp | 496 -------------------------------- src/rs2sdf.cpp | 157 ----------- src/sdf-1.cpp | 194 ------------- src/sdf-2.cpp | 225 --------------- src/sdf2img.cpp | 736 ------------------------------------------------ src/sdfinfo.cpp | 241 ---------------- 6 files changed, 2049 deletions(-) delete mode 100644 src/phm2sdf.cpp delete mode 100644 src/rs2sdf.cpp delete mode 100644 src/sdf-1.cpp delete mode 100644 src/sdf-2.cpp delete mode 100644 src/sdf2img.cpp delete mode 100644 src/sdfinfo.cpp diff --git a/src/phm2sdf.cpp b/src/phm2sdf.cpp deleted file mode 100644 index 4211ae7..0000000 --- a/src/phm2sdf.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: phm2sdf.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: phm2sdf.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.10 2000/05/24 22:50:04 kevin -** Added support for new SGP library -** -** Revision 1.9 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.8 2000/05/11 01:06:30 kevin -** Changed sprintf to snprintf -** -** Revision 1.7 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.6 2000/05/03 08:49:50 kevin -** Code cleanup -** -** Revision 1.5 2000/04/30 19:17:54 kevin -** *** empty log message *** -** -** Revision 1.4 2000/04/30 04:06:13 kevin -** Update Raysum i/o routines -** Fix MPI bug in ctrec (scatter_raysum) that referenced rs_global -** -** Revision 1.3 2000/04/28 18:19:01 kevin -** removed unused files -** -** Revision 1.2 2000/04/28 13:50:45 kevin -** Removed Makefile Makefile.in that are automatically generated by autoconf -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * phm2sdf.c Generate a SDF image from a phantom - * - * HISTORY - * 1984 - Final DOS verion - * 1999 - First UNIX version - */ - -#include "ct.h" - -enum { O_PHANTOM, O_DESC, O_NSAMPLE, O_FILTER, O_TRACE, O_VERBOSE, O_HELP, - O_PHMFILE, O_FILTER_DOMAIN, O_FILTER_BW, O_FILTER_PARAM, O_DEBUG, O_VERSION }; - -static struct option my_options[] = -{ - {"phantom", 1, 0, O_PHANTOM}, - {"phmfile", 1, 0, O_PHMFILE}, - {"desc", 1, 0, O_DESC}, - {"nsample", 1, 0, O_NSAMPLE}, - {"filter", 1, 0, O_FILTER}, - {"filter-domain", 1, 0, O_FILTER_DOMAIN}, - {"filter-bw", 1, 0, O_FILTER_BW}, - {"filter-param", 1, 0, O_FILTER_PARAM}, - {"trace", 1, 0, O_TRACE}, - {"verbose", 0, 0, O_VERBOSE}, - {"debug", 0, 0, O_DEBUG}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - -void -phm2sdf_usage (const char *program) -{ - fprintf(stdout,"phm2sdf_usage: %s outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n",kbasename(program)); - fprintf(stdout,"Generate phantom image from a predefined --phantom or a --phmfile\n"); - fprintf(stdout,"\n"); - fprintf(stdout," outfile Name of output file for image\n"); - fprintf(stdout," nx Number of pixels X-axis\n"); - fprintf(stdout," ny Number of pixels Y-axis\n"); - fprintf(stdout," --phantom Phantom to use for projection\n"); - fprintf(stdout," herman Herman head phantom\n"); - fprintf(stdout," rowland Rowland head phantom\n"); - fprintf(stdout," browland Bordered Rowland head phantom\n"); - fprintf(stdout," unitpulse Unit pulse phantom\n"); - fprintf(stdout," --phmfile Generate Phantom from phantom file\n"); - fprintf(stdout," --filter Generate Phantom from a filter function\n"); - fprintf(stdout," abs_bandlimit Abs * Bandlimiting\n"); - fprintf(stdout," abs_sinc Abs * Sinc\n"); - fprintf(stdout," abs_cos Abs * Cosine\n"); - fprintf(stdout," abs_hamming Abs * Hamming\n"); - fprintf(stdout," shepp Shepp-Logan\n"); - fprintf(stdout," bandlimit Bandlimiting\n"); - fprintf(stdout," sinc Sinc\n"); - fprintf(stdout," cos Cosine\n"); - fprintf(stdout," triangle Triangle\n"); - fprintf(stdout," hamming Hamming\n"); - fprintf(stdout," --filter-param Alpha level for Hamming filter\n"); - fprintf(stdout," --filter-domain Set domain of filter\n"); - fprintf(stdout," spatial Spatial domain (default)\n"); - fprintf(stdout," freq Frequency domain\n"); - fprintf(stdout," --filter-bw Filter bandwidth (default = 1)\n"); - fprintf(stdout," --desc Description of raysum\n"); - fprintf(stdout," --nsample Number of samples per axis per pixel (default = 1)\n"); - fprintf(stdout," --trace Trace level to use\n"); - fprintf(stdout," none No tracing (default)\n"); - fprintf(stdout," text Trace text level\n"); - fprintf(stdout," phm Trace phantom\n"); - fprintf(stdout," rays Trace rays\n"); - fprintf(stdout," plot Trace plot\n"); - fprintf(stdout," clipping Trace clipping\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"); -} - -#ifdef MPI_CT -void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug); -#endif - -int -phm2sdf_main (const int argc, char *const argv[]) -{ - IMAGE *im_global = NULL; - PHANTOM *phm = NULL; - int opt_nx = 0, opt_ny = 0; - int opt_nsample = 1; - int opt_phmnum = -1; - FilterType opt_filter = static_cast(-1); - DomainType opt_filter_domain = D_SPATIAL; - char *opt_outfile = NULL; - int opt_debug = 0; - char str[256]; - char opt_desc[256], opt_phmfilename[256]; - char *endstr, *endptr; - double opt_filter_param = 1; - double opt_filter_bw = 1.; - int opt_trace = TRACE_NONE; - int opt_verbose = 0; - double time_start=0, time_end=0; -#ifdef MPI_CT - IMAGE *im_local = NULL; - int mpi_argc = argc; - char **mpi_argv = (char **) argv; - double mpi_t1, mpi_t2, mpi_t, mpi_t_g; - - MPI_Init(&mpi_argc, &mpi_argv); - MPI_Comm_dup (MPI_COMM_WORLD, &mpi_ct.comm); - MPI_Comm_size(mpi_ct.comm, &mpi_ct.nproc); - MPI_Comm_rank(mpi_ct.comm, &mpi_ct.my_rank); - - if (mpi_ct.nproc > MPI_MAX_PROCESS) { - sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", - mpi_ct.nproc, MPI_MAX_PROCESS); - } -#endif - -#ifdef MPI_CT - time_start = MPI_Wtime(); -#else - time_start = td_current_sec(); -#endif - -#ifdef MPI_CT - if (mpi_ct.my_rank == 0) { -#endif - - strcpy(opt_desc, ""); - strcpy(opt_phmfilename, ""); - while (1) { - int c = getopt_long(argc, argv, "", my_options, NULL); - char *endptr = NULL; - char *endstr; - - if (c == -1) - break; - - switch (c) { - case O_PHANTOM: - if ((opt_phmnum = opt_set_phantom(optarg)) < 0) { - phm2sdf_usage(argv[0]); - return (1); - } - break; - case O_PHMFILE: - strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); - phm = phm_create_from_file(opt_phmfilename); -#ifdef MPI_CT - if (mpi_ct.my_rank == 0) - fprintf(stderr, "Can't use phantom from file in MPI mode\n"); - return (1); -#endif - break; - case O_VERBOSE: - opt_verbose = 1; - break; - case O_DEBUG: - opt_debug = 1; - break; - case O_TRACE: - if ((opt_trace = opt_set_trace(optarg)) < 0) { - phm2sdf_usage(argv[0]); - return (1); - } - break; - case O_FILTER: - if ((opt_filter = opt_set_filter(optarg)) < 0) { - phm2sdf_usage (argv[0]); - return (1); - } - break; - case O_FILTER_DOMAIN: - if ((opt_filter_domain = opt_set_filter_domain(optarg)) < 0) { - phm2sdf_usage (argv[0]); - return (1); - } - break; - case O_DESC: - strncpy(opt_desc, optarg, sizeof(opt_desc)); - 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); - phm2sdf_usage(argv[0]); - return (1); - } - break; - case O_FILTER_PARAM: - opt_filter_param = strtod(optarg, &endptr); - endstr = optarg + strlen(optarg); - if (endptr != endstr) { - fprintf(stderr,"Error setting --filter-param to %s\n", optarg); - phm2sdf_usage(argv[0]); - return (1); - } - break; - case O_NSAMPLE: - opt_nsample = strtol(optarg, &endptr, 10); - endstr = optarg + strlen(optarg); - if (endptr != endstr) { - fprintf(stderr,"Error setting --nsample to %s\n", optarg); - phm2sdf_usage(argv[0]); - return (1); - } - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - case O_HELP: - case '?': - phm2sdf_usage(argv[0]); - return (0); - default: - phm2sdf_usage(argv[0]); - return (1); - } - } - - if (phm == NULL && opt_phmnum == -1 && opt_filter == -1) { - fprintf(stderr, "No phantom defined\n"); - phm2sdf_usage(argv[0]); - return (1); - } - - if (optind + 3 != argc) { - phm2sdf_usage(argv[0]); - return (1); - } - opt_outfile = argv[optind]; - 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]); - phm2sdf_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]); - phm2sdf_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)); - } - 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)); - } - strncpy(opt_desc, str, sizeof(opt_desc)); - - if (opt_verbose) - printf("Compile Phantom to Image\n\n"); -#ifdef MPI_CT - } -#endif - -#ifdef MPI_CT - mpi_t1 = MPI_Wtime(); - MPI_Bcast(&opt_verbose, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_debug, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_trace, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_nx, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_ny, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_nsample, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_phmnum, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_domain, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_param, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&opt_filter_bw, 1, MPI_DOUBLE, 0, mpi_ct.comm); - - if (opt_verbose) { - mpi_t2 = MPI_Wtime(); - mpi_t = mpi_t2 - mpi_t1; - MPI_Reduce(&mpi_t, &mpi_t_g, 1, MPI_DOUBLE, MPI_MAX, 0, mpi_ct.comm); - if (mpi_ct.my_rank == 0) - printf("Time to Bcast vars = %f secs, Max time = %f\n", mpi_t, mpi_t_g); - } - - mpi_ct_calc_work_units(opt_nx); - - if (mpi_ct.my_rank == 0) - im_global = image_create (opt_outfile, opt_nx, opt_ny); - - im_local = image_create(NULL, opt_nx, opt_ny); -#else - im_global = image_create (opt_outfile, opt_nx, opt_ny); -#endif - - if (opt_phmnum >= 0) - phm = phm_create (opt_phmnum); - -#ifdef MPI_CT - else { - if (mpi_ct.my_rank == 0) - fprintf(stderr, "phmnum < 0\n"); - exit(1); - } -#endif - -#ifdef MPI_CT - if (phm->type == P_UNIT_PULSE) { - if (mpi_ct.my_rank == 0) { - im_global->v[opt_nx/2][opt_ny/2] = 1.; - im_global->calctime = 0; - } - } else if (opt_filter != -1) { - if (mpi_ct.my_rank == 0) { - image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); - im_global->calctime = 0; - } - } else { - if (opt_verbose) - mpi_t1 = MPI_Wtime(); - phm_to_image (phm, im_local, mpi_ct.start_work_unit[mpi_ct.my_rank], - mpi_ct.local_work_units[mpi_ct.my_rank], opt_nsample, opt_trace); - if (opt_verbose) { - mpi_t2 = MPI_Wtime(); - mpi_t = mpi_t2 - mpi_t1; - MPI_Reduce(&mpi_t, &mpi_t_g, 1, MPI_DOUBLE, MPI_MAX, 0, mpi_ct.comm); - if (mpi_ct.my_rank == 0) - printf("Time to compile phm = %f secs, Max time = %f\n", mpi_t, mpi_t_g); - } - mpi_gather_image(im_global, im_local, opt_debug); - } -#else - if (phm->type == P_UNIT_PULSE) { - im_global->v[opt_nx/2][opt_ny/2] = 1.; - im_global->calctime = 0; - } else if (opt_filter != -1) { - image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); - im_global->calctime = 0; - } else { -#if HAVE_SGP - if (opt_trace >= TRACE_PHM) - phm_show(phm); -#endif - phm_to_image (phm, im_global, 0, opt_nx, opt_nsample, opt_trace); - } -#endif - -#ifdef MPI_CT - time_end = MPI_Wtime(); -#else - time_end = td_current_sec(); -#endif - -#ifdef MPI_CT - if (mpi_ct.my_rank == 0) -#endif - { - im_global->calctime = time_end - time_start; - strncpy (im_global->remark, opt_desc, sizeof(im_global->remark)); - image_save (im_global); - if (opt_verbose) - fprintf (stdout, "Time to compile image = %.2f sec\n\n", im_global->calctime); - } - - if (opt_trace >= TRACE_PHM) - { - double dmin, dmax; - int nscale; - - printf ("Enter display size scale (nominal = 1): "); - scanf ("%d", &nscale); - printf ("Enter minimum and maximum densities (min, max): "); - scanf ("%lf %lf", &dmin, &dmax); - image_display_scale (im_global, nscale, dmin, dmax); - } - - phm_free (phm); - - return (0); -} - - - -#ifdef MPI_CT -void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug) -{ - int iproc; - int end_work_unit; - int iw; - - end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1; - for (iw = 0; iw <= end_work_unit; iw++) { - MPI_Send(im_local->v[iw], im_local->ny, MPI_FLOAT, 0, 0, mpi_ct.comm); - } - - if (mpi_ct.my_rank == 0) { - for (iproc = 0; iproc < mpi_ct.nproc; iproc++) { - end_work_unit = mpi_ct.start_work_unit[iproc] - + mpi_ct.local_work_units[iproc] - - 1; - - if (opt_debug) { - fprintf(stdout, "Recv rs data from process %d (%d-%d)\n", iproc, - mpi_ct.start_work_unit[iproc], end_work_unit); - fflush(stdout); - } - - - for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) { - MPI_Status status; - - MPI_Recv(im_global->v[iw], im_global->ny, MPI_FLOAT, iproc, 0, mpi_ct.comm, &status); - } - } - } - -} -#endif - -#ifndef NO_MAIN -int -main (const int argc, char *const argv[]) -{ - return (phm2sdf_main(argc, argv)); -} -#endif diff --git a/src/rs2sdf.cpp b/src/rs2sdf.cpp deleted file mode 100644 index 4ce0622..0000000 --- a/src/rs2sdf.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: rs2sdf.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: rs2sdf.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.3 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.2 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * rs2sdf.c Convert Raysum to image - * - * DATE - * Apr 1999 - */ - -#include "ct.h" - -enum { O_VERBOSE, O_HELP, O_VERSION }; - -static struct option my_options[] = -{ - {"verbose", 0, 0, O_VERBOSE}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - - -void -rs2sdf_usage (const char *program) -{ - fprintf(stdout, "rs2sdf_usage: %s in-rs-file out-sdf-file [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "This program converts a raysum file to a SDF2D 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"); -} - - - -int -rs2sdf_main (const int argc, char *const argv[]) -{ - IMAGE *im; - RAYSUM *rs; - DETARRAY *detarray; - char *rs_name, *im_name; - int ix, iy; - int opt_v = 0; - extern int optind; - - while (1) - { - int c = getopt_long (argc, argv, "", my_options, NULL); - if (c == -1) - break; - - switch (c) - { - case O_VERBOSE: - opt_v = 1; - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - exit(0); - case O_HELP: - case '?': - rs2sdf_usage(argv[0]); - return (0); - default: - rs2sdf_usage(argv[0]); - return (1); - } - } - - if (argc - optind != 2) { - rs2sdf_usage(argv[0]); - return (1); - } - - rs_name = argv[optind]; - im_name = argv[optind + 1]; - - if (file_exists(rs_name) == FALSE) { - fprintf (stderr, "Raysum file %s does not exist\n", rs_name); - return (1); - } - - rs = raysum_open (rs_name); - - if (opt_v) - { - printf ("Number of detectors: %d\n", rs->ndet); - printf (" Number of views: %d\n", rs->nview); - printf (" Remark: %s\n", rs->remark); - } - - im = image_create (im_name, rs->ndet, rs->nview); - - sdf_add_label (LT_HISTORY, rs->remark, rs->calctime, im->dfp_2d->dfp); - sdf_add_empty_label (im->dfp_2d->dfp); - - detarray = detarray_alloc (rs->ndet); - for (iy = 0; iy < rs->nview; iy++) - { - detarray_read (rs, detarray, iy); - for (ix = 0; ix < rs->ndet; ix++) - { - im->v[ix][iy] = detarray->detval[ix]; - } - } - detarray_free (detarray); - - raysum_close (rs); - image_save (im); - - return(0); -} - -#ifndef NO_MAIN -int -main (const int argc, char *const argv[]) -{ - return (rs2sdf_main(argc, argv)); -} -#endif diff --git a/src/sdf-1.cpp b/src/sdf-1.cpp deleted file mode 100644 index 545bb72..0000000 --- a/src/sdf-1.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sdf-1.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: sdf-1.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.6 2000/05/24 22:50:04 kevin -** Added support for new SGP library -** -** Revision 1.5 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.4 2000/05/09 14:52:27 kevin -** added sqr and sqrt functions -** -** Revision 1.3 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.2 2000/05/03 08:49:50 kevin -** Code cleanup -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * sdf-1.c Filter a single SDF file - */ - -#include "ct.h" - -enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION}; - -static struct option my_options[] = -{ - {"invert", 0, 0, O_INVERT}, - {"verbose", 0, 0, O_VERBOSE}, - {"log", 0, 0, O_LOG}, - {"exp", 0, 0, O_EXP}, - {"sqr", 0, 0, O_SQR}, - {"sqrt", 0, 0, O_SQRT}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - -void -sdf1_usage (const char *program) -{ - fprintf(stdout, "sdf1_usage: %s infile outfile [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "Generate a SDF2D file from a SDF2D 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"); -} - -int -sdf1_main (int argc, char *const argv[]) -{ - IMAGE *im_in; - IMAGE *im_out; - char *in_file; - char *out_file; - int opt_verbose = 0; - int opt_invert = 0; - int opt_log = 0; - int opt_exp = 0; - int opt_sqr = 0; - int opt_sqrt = 0; - - while (1) - { - int c = getopt_long (argc, argv, "", my_options, NULL); - - if (c == -1) - break; - - switch (c) - { - case O_INVERT: - opt_invert = 1; - break; - case O_LOG: - opt_log = 1; - break; - case O_SQR: - opt_sqr = 1; - break; - case O_SQRT: - opt_sqrt = 1; - break; - case O_EXP: - opt_exp = 1; - break; - case O_VERBOSE: - opt_verbose = 1; - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - exit(0); - case O_HELP: - case '?': - sdf1_usage(argv[0]); - return (0); - default: - sdf1_usage(argv[0]); - return (1); - } - } - - if (optind + 2 != argc) - { - sdf1_usage(argv[0]); - return (1); - } - - in_file = argv[optind]; - out_file = argv[optind + 1]; - - - if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) { - int ix, iy; - - im_in = image_load (in_file); - im_out = image_create (out_file, im_in->nx, im_in->ny); - - if (opt_invert) { - for (ix = 0; ix < im_in->nx; ix++) - for (iy = 0; iy < im_in->ny; iy++) - im_out->v[ix][iy] = - im_in->v[ix][iy]; - } - if (opt_log) { - for (ix = 0; ix < im_in->nx; ix++) - for (iy = 0; iy < im_in->ny; iy++) - im_out->v[ix][iy] = log (im_in->v[ix][iy]); - } - if (opt_exp) { - for (ix = 0; ix < im_in->nx; ix++) - for (iy = 0; iy < im_in->ny; iy++) - im_out->v[ix][iy] = exp (im_in->v[ix][iy]); - } - if (opt_sqr) { - for (ix = 0; ix < im_in->nx; ix++) - for (iy = 0; iy < im_in->ny; iy++) - im_out->v[ix][iy] = im_in->v[ix][iy] * im_in->v[ix][iy]; - } - if (opt_sqrt) { - for (ix = 0; ix < im_in->nx; ix++) - for (iy = 0; iy < im_in->ny; iy++) - im_out->v[ix][iy] = sqrt (im_in->v[ix][iy]); - } - - image_save(im_out); - } - - return (0); -} - -#ifndef NO_MAIN -int -main (int argc, char *const argv[]) -{ - return (sdf1_main(argc, argv)); -} -#endif - diff --git a/src/sdf-2.cpp b/src/sdf-2.cpp deleted file mode 100644 index cf1dd74..0000000 --- a/src/sdf-2.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sdf-2.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: sdf-2.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.5 2000/05/24 22:50:04 kevin -** Added support for new SGP library -** -** Revision 1.4 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.3 2000/05/11 01:06:30 kevin -** Changed sprintf to snprintf -** -** Revision 1.2 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * sdf-2.c Generate a SDF file from two input SDF files - */ - -#include "ct.h" - -enum {O_ADD, O_SUB, O_MUL, O_COMP, O_VERBOSE, O_HELP, O_VERSION}; - -static struct option my_options[] = -{ - {"add", 0, 0, O_ADD}, - {"sub", 0, 0, O_SUB}, - {"mul", 0, 0, O_MUL}, - {"comp", 0, 0, O_COMP}, - {"verbose", 0, 0, O_VERBOSE}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - -void -sdf2_usage (const char *program) -{ - fprintf(stdout, "sdf2_usage: %s infile1 infile2 outfile [OPTIONS]\n", kbasename(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"); -} - -int -sdf2_main (int argc, char *const argv[]) -{ - IMAGE *im_in1; - IMAGE *im_in2; - IMAGE *im_out; - char *in_file1; - char *in_file2; - char *out_file; - int opt_verbose = 0; - int opt_add = 0; - int opt_sub = 0; - int opt_mul = 0; - int opt_comp = 0; - - while (1) - { - int c = getopt_long (argc, argv, "", my_options, NULL); - - if (c == -1) - break; - - switch (c) - { - case O_ADD: - opt_add = 1; - break; - case O_SUB : - opt_sub = 1; - break; - case O_MUL: - opt_mul = 1; - break; - case O_COMP: - opt_comp = 1; - break; - case O_VERBOSE: - opt_verbose = 1; - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - exit(0); - case O_HELP: - case '?': - sdf2_usage(argv[0]); - return (0); - default: - sdf2_usage(argv[0]); - return (1); - } - } - - if (optind + 3 != argc) - { - sdf2_usage(argv[0]); - return (1); - } - - in_file1 = argv[optind]; - in_file2 = argv[optind + 1]; - out_file = argv[optind + 2]; - - im_in1 = image_load (in_file1); - im_in2 = image_load (in_file2); - if (im_in1 == NULL || im_in2 == NULL) { - fprintf(stderr, "Error reading an image"); - return (1); - } - - 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", - 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"); - return(1); - } - - im_out = image_create (out_file, im_in1->nx, im_in1->ny); - - if (opt_add) { - int ix, iy; - for (ix = 0; ix < im_in1->nx; ix++) - { - IMAGE_ELEM_VAL *in1 = &im_in1->v[ix][0]; - IMAGE_ELEM_VAL *in2 = &im_in2->v[ix][0]; - IMAGE_ELEM_VAL *out = &im_out->v[ix][0]; - for (iy = 0; iy < im_in1->ny; iy++) - *out++ = *in1++ + *in2++; - } - } else if (opt_sub) { - int ix, iy; - for (ix = 0; ix < im_in1->nx; ix++) - { - IMAGE_ELEM_VAL *in1 = &im_in1->v[ix][0]; - IMAGE_ELEM_VAL *in2 = &im_in2->v[ix][0]; - IMAGE_ELEM_VAL *out = &im_out->v[ix][0]; - for (iy = 0; iy < im_in1->ny; iy++) - *out++ = *in1++ - *in2++; - } - } else if (opt_mul) { - int ix, iy; - for (ix = 0; ix < im_in1->nx; ix++) - { - IMAGE_ELEM_VAL *in1 = &im_in1->v[ix][0]; - IMAGE_ELEM_VAL *in2 = &im_in2->v[ix][0]; - IMAGE_ELEM_VAL *out = &im_out->v[ix][0]; - for (iy = 0; iy < im_in1->ny; iy++) - *out++ = *in1++ * *in2++; - } - } else if (opt_comp) { - int ix, iy; - double abs_error = 0.; - for (ix = 0; ix < im_in1->nx; ix++) - { - IMAGE_ELEM_VAL *in1 = &im_in1->v[ix][0]; - IMAGE_ELEM_VAL *in2 = &im_in2->v[ix][0]; - IMAGE_ELEM_VAL *out = &im_out->v[ix][0]; - for (iy = 0; iy < im_in1->ny; iy++) - { - double diff = *in1++ - *in2++; - *out++ = diff; - abs_error += fabs(diff); - } - } - abs_error /= (im_in1->nx * im_in1->ny); - fprintf(stdout, "Average Error = %f\n", abs_error); - } - - image_save(im_out); - - return (0); -} - -#ifndef NO_MAIN -int -main (int argc, char *const argv[]) -{ - return (sdf2_main(argc, argv)); -} -#endif - diff --git a/src/sdf2img.cpp b/src/sdf2img.cpp deleted file mode 100644 index c646e54..0000000 --- a/src/sdf2img.cpp +++ /dev/null @@ -1,736 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sdf2img.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: sdf2img.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.6 2000/06/03 07:57:51 kevin -** Fixed PNG 16-bit format -** -** Revision 1.5 2000/06/03 06:29:57 kevin -** *** empty log message *** -** -** Revision 1.4 2000/05/24 22:50:04 kevin -** Added support for new SGP library -** -** Revision 1.3 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.2 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * sdf2img.c Convert an SDF file to a viewable format image - */ - -#include "ct.h" - -#if HAVE_PNG -void sdf2d_to_png (IMAGE *im, char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax); -#endif -#if HAVE_GIF -void sdf2d_to_gif (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax); -#endif -void sdf2d_to_pgm (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax); -void sdf2d_to_pgmasc (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax); - -enum { O_SCALE, O_MIN, O_MAX, O_AUTO, O_CENTER, O_STATS, O_FORMAT, O_LABELS, - O_HELP, O_VERBOSE, O_VERSION, O_DEBUG }; - -static struct option my_options[] = -{ - {"scale", 1, 0, O_SCALE}, - {"min", 1, 0, O_MIN}, - {"max", 1, 0, O_MAX}, - {"auto", 1, 0, O_AUTO}, - {"center", 1, 0, O_CENTER}, - {"format", 1, 0, O_FORMAT}, - {"labels", 0, 0, O_LABELS}, - {"stats", 0, 0, O_STATS}, - {"verbose", 0, 0, O_VERBOSE}, - {"debug", 0, 0, O_DEBUG}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - -enum { O_AUTO_FULL, O_AUTO_STD0_1, O_AUTO_STD0_5, O_AUTO_STD1, O_AUTO_STD2, O_AUTO_STD3 }; -#define O_AUTO_FULL_STR "full" -#define O_AUTO_STD0_1_STR "std0.1" -#define O_AUTO_STD0_5_STR "std0.5" -#define O_AUTO_STD1_STR "std1" -#define O_AUTO_STD2_STR "std2" -#define O_AUTO_STD3_STR "std3" - -enum { O_CENTER_MEAN, O_CENTER_MODE }; -#define O_CENTER_MEAN_STR "mean" -#define O_CENTER_MODE_STR "mode" - -enum { O_FORMAT_GIF, O_FORMAT_PNG, O_FORMAT_PNG16, O_FORMAT_PGM, O_FORMAT_PGMASC, O_FORMAT_DISP }; -#define O_FORMAT_GIF_STR "gif" -#define O_FORMAT_PNG_STR "png" -#define O_FORMAT_PNG16_STR "png16" -#define O_FORMAT_PGM_STR "pgm" -#define O_FORMAT_PGMASC_STR "pgmasc" -#define O_FORMAT_DISP_STR "disp" - -void -sdf2img_usage (const char *program) -{ - fprintf(stdout, "sdf2img_usage: %s sdfname outfile [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "Convert SDF2D 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"); -#ifdef HAVE_PNG - fprintf(stdout, " png PNG (8-bit) format\n"); - fprintf(stdout, " png16 PNG (16-bit) format\n"); -#endif -#ifdef HAVE_GIF - fprintf(stdout, " gif GIF format\n"); -#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"); -} - - -int -sdf2img_main (int argc, char *const argv[]) -{ - IMAGE *im; - double densmin = HUGE_VAL, densmax = -HUGE_VAL; - char *in_file, *out_file; - int opt_verbose = 0; - int opt_scale = 1; - int opt_auto = O_AUTO_FULL; - int opt_set_max = 0; - int opt_set_min = 0; - int opt_stats = 0; - int opt_debug = 0; - int opt_center = O_CENTER_MODE; - int opt_format = O_FORMAT_PGM; - int opt_labels = 0; - - while (1) - { - int c = getopt_long (argc, argv, "", my_options, NULL); - char *endptr = NULL; - char *endstr; - - if (c == -1) - break; - - switch (c) - { - case O_MIN: - opt_set_min = 1; - densmin = strtod(optarg, &endptr); - endstr = optarg + strlen(optarg); - if (endptr != endstr) - { - fprintf(stderr, "Error setting --min to %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_MAX: - opt_set_max = 1; - densmax = strtod(optarg, &endptr); - endstr = optarg + strlen(optarg); - if (endptr != endstr) - { - fprintf(stderr, "Error setting --max to %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_SCALE: - opt_scale = strtol(optarg, &endptr, 10); - endstr = optarg + strlen(optarg); - if (endptr != endstr) - { - fprintf(stderr,"Error setting --scale to %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_AUTO: - if (strcmp(optarg, O_AUTO_FULL_STR) == 0) - opt_auto = O_AUTO_FULL; - else if (strcmp(optarg, O_AUTO_STD1_STR) == 0) - opt_auto = O_AUTO_STD1; - else if (strcmp(optarg, O_AUTO_STD0_5_STR) == 0) - opt_auto = O_AUTO_STD0_5; - else if (strcmp(optarg, O_AUTO_STD0_1_STR) == 0) - opt_auto = O_AUTO_STD0_1; - else if (strcmp(optarg, O_AUTO_STD2_STR) == 0) - opt_auto = O_AUTO_STD2; - else if (strcmp(optarg, O_AUTO_STD3_STR) == 0) - opt_auto = O_AUTO_STD3; - else - { - fprintf(stderr, "Invalid auto mode %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_CENTER: - if (strcmp(optarg, O_CENTER_MEAN_STR) == 0) - opt_center = O_CENTER_MEAN; - else if (strcmp(optarg, O_CENTER_MODE_STR) == 0) - opt_center = O_CENTER_MODE; - else - { - fprintf(stderr, "Invalid center mode %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_FORMAT: - if (strcmp(optarg, O_FORMAT_PGM_STR) == 0) - opt_format = O_FORMAT_PGM; - else if (strcmp(optarg, O_FORMAT_PGMASC_STR) == 0) - opt_format = O_FORMAT_PGMASC; -#if HAVE_PNG - else if (strcmp(optarg, O_FORMAT_PNG_STR) == 0) - opt_format = O_FORMAT_PNG; - else if (strcmp(optarg, O_FORMAT_PNG16_STR) == 0) - opt_format = O_FORMAT_PNG16; -#endif -#if HAVE_GIF - else if (strcmp(optarg, O_FORMAT_GIF_STR) == 0) - opt_format = O_FORMAT_GIF; -#endif - else if (strcmp(optarg, O_FORMAT_DISP_STR) == 0) - opt_format = O_FORMAT_DISP; - else { - fprintf(stderr, "Invalid format mode %s\n", optarg); - sdf2img_usage(argv[0]); - return (1); - } - break; - case O_LABELS: - opt_labels = 1; - break; - case O_VERBOSE: - opt_verbose = 1; - break; - case O_DEBUG: - opt_debug = 1; - break; - case O_STATS: - opt_stats = 1; - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - exit(0); - case O_HELP: - case '?': - sdf2img_usage(argv[0]); - return (0); - default: - sdf2img_usage(argv[0]); - return (1); - } - } - - if ((opt_format == O_FORMAT_DISP && optind + 1 != argc) - || (opt_format != O_FORMAT_DISP && optind + 2 != argc)) - { - sdf2img_usage(argv[0]); - return (1); - } - - in_file = argv[optind]; - - if (opt_format != O_FORMAT_DISP) - out_file = argv[optind+1]; - else out_file = NULL; - - if ((im = image_load (in_file)) == NULL) - { - fprintf(stderr, "File %s does not exist\n", in_file); - return (1); - } - - if (opt_labels) - { - int nlabels = im->dfp_2d->dfp->num_label; - int i; - - for (i = 0; i < nlabels; i++) - { - SDF_BLK blk; - if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK) - break; - if (blk.lab.label_type == LT_HISTORY) { - fprintf(stdout, "History: %s\n", blk.lab.label_str); - fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } else if (blk.lab.label_type == LT_TITLE) { - fprintf(stdout, "Title: %s\n", blk.lab.label_str); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } else if (blk.lab.label_type == LT_NOTE) { - fprintf(stdout, "Note: %s\n", blk.lab.label_str); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } - } - } - - if (opt_stats || (! (opt_set_max && opt_set_min))) - { - double minfound = HUGE_VAL, maxfound = -HUGE_VAL; - double mode = 0, mean = 0, stddev = 0, window = 0; - double spread; - int hist[256]; - int ibin, nbin = 256; - int max_bin, max_binindex; - double maxbin; - int ix, iy; - - maxbin = nbin - 1; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - if (im->v[ix][iy] > maxfound) - maxfound = im->v[ix][iy]; - if (im->v[ix][iy] < minfound) - minfound = im->v[ix][iy]; - mean += im->v[ix][iy]; - } - } - spread = maxfound - minfound; - if (spread == 0) - mode = minfound; - else - { - for (ibin = 0; ibin < nbin; ibin++) - hist[ibin] = 0; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5); - hist[b]++; - } - } - max_binindex = 0; - max_bin = -1; - for (ibin = 0; ibin < nbin; ibin++) - { - if (hist[ibin] > max_bin) - { - max_bin = hist[ibin]; - max_binindex = ibin; - } - } - mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound; - } - - if (opt_auto == O_AUTO_FULL) - { - if (! opt_set_max) - densmax = maxfound; - if (! opt_set_min) - densmin = minfound; - } - if (opt_stats || opt_auto != O_AUTO_FULL) - { - mean /= im->nx * im->ny; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - double diff = (im->v[ix][iy] - mean); - stddev += diff * diff; - } - } - stddev = sqrt(stddev / (im->nx * im->ny)); - if (opt_auto == O_AUTO_FULL) - ; - else if (opt_auto == O_AUTO_STD1) - window = stddev; - else if (opt_auto == O_AUTO_STD0_1) - window = stddev * 0.1; - else if (opt_auto == O_AUTO_STD0_5) - window = stddev * 0.5; - else if (opt_auto == O_AUTO_STD2) - window = stddev * 2; - else if (opt_auto == O_AUTO_STD3) - window = stddev * 3; - else - { - fprintf(stderr, "Internal Error: Invalid auto mode %d\n", opt_auto); - return (1); - } - } - if (opt_stats) - { - fprintf(stdout,"nx=%d\n", im->nx); - fprintf(stdout,"ny=%d\n", im->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); - } - if (opt_auto != O_AUTO_FULL) - { - double center; - - if (opt_center == O_CENTER_MODE) - center = mode; - else if (opt_center == O_CENTER_MEAN) - center = mean; - else - { - fprintf(stderr, "Internal Error: Invalid center mode %d\n", opt_center); - return (1); - } - if (! opt_set_max) - densmax = center + window; - if (! opt_set_min) - densmin = center - window; - } - } - - if (opt_stats) - { - fprintf(stdout,"min_disp=%f\n", densmin); - fprintf(stdout,"max_disp=%f\n", densmax); - } - - if (opt_format == O_FORMAT_PGM) - sdf2d_to_pgm (im, out_file, opt_scale, opt_scale, densmin, densmax); - else if (opt_format == O_FORMAT_PGMASC) - sdf2d_to_pgmasc (im, out_file, opt_scale, opt_scale, densmin, densmax); -#if HAVE_PNG - else if (opt_format == O_FORMAT_PNG) - sdf2d_to_png (im, out_file, 8, opt_scale, opt_scale, densmin, densmax); - else if (opt_format == O_FORMAT_PNG16) - sdf2d_to_png (im, out_file, 16, opt_scale, opt_scale, densmin, densmax); -#endif -#if HAVE_GIF - else if (opt_format == O_FORMAT_GIF) - sdf2d_to_gif (im, out_file, opt_scale, opt_scale, densmin, densmax); -#endif - else if (opt_format == O_FORMAT_DISP) { -#if HAVE_SGP - image_display_scale (im, opt_scale, densmin, densmax); - cio_kb_getc(); - sgp2_close(sgp2_get_active_win()); -#endif - } - else - { - fprintf(stderr, "Internal Error: Invalid format mode %d\n", opt_format); - return (1); - } - return (0); -} - - -void -sdf2d_to_pgm (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax) -{ - FILE *fp; - int irow; - unsigned char *rowp; - - rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img"); - if (rowp == NULL) - return; - - if ((fp = fopen (outfile, "wb")) == NULL) - return; - - fprintf(fp, "P5\n"); - fprintf(fp, "%d %d\n", im->nx, im->ny); - fprintf(fp, "255\n"); - - for (irow = im->ny - 1; irow >= 0; irow--) - { - int icol, ir; - - for (icol = 0; icol < im->nx; icol++) - { - double dens; - int p; - int pos = icol * nxcell; - dens = (im->v[icol][irow] - densmin) / (densmax - densmin); - if (dens < 0) - dens = 0; - else if (dens > 1) - dens = 1; - for (p = pos; p < pos + nxcell; p++) - { - rowp[p] = (unsigned int) (dens * 255.); - } - } - for (ir = 0; ir < nycell; ir++) - { - int ic; - for (ic = 0; ic < im->nx * nxcell; ic++) - fprintf(fp, "%c ", rowp[ic]); - } - } - sys_free(rowp, "sdf2img"); - - fclose(fp); -} - -void -sdf2d_to_pgmasc (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax) -{ - FILE *fp; - int irow; - unsigned char *rowp; - - rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img"); - if (rowp == NULL) - return; - - if ((fp = fopen (outfile, "wb")) == NULL) - return; - - fprintf(fp, "P2\n"); - fprintf(fp, "%d %d\n", im->nx, im->ny); - fprintf(fp, "255\n"); - - for (irow = im->ny - 1; irow >= 0; irow--) - { - int icol, ir; - - for (icol = 0; icol < im->nx; icol++) - { - double dens; - int p; - int pos = icol * nxcell; - dens = (im->v[icol][irow] - densmin) / (densmax - densmin); - if (dens < 0) - dens = 0; - else if (dens > 1) - dens = 1; - for (p = pos; p < pos + nxcell; p++) - { - rowp[p] = (unsigned int) (dens * 255.); - } - } - for (ir = 0; ir < nycell; ir++) - { - int ic; - for (ic = 0; ic < im->nx * nxcell; ic++) - fprintf(fp, "%d ", rowp[ic]); - fprintf(fp, "\n"); - } - } - sys_free(rowp, "sdf2img"); - - fclose(fp); -} - - -#ifdef HAVE_PNG -void -sdf2d_to_png (IMAGE *im, char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax) -{ - FILE *fp; - png_structp png_ptr; - png_infop info_ptr; - int irow; - unsigned char *rowp; - double max_out_level = (1 << bitdepth) - 1; - - rowp = (unsigned char *) sys_alloc(im->nx * nxcell * (bitdepth / 8),"sdf2d_to_img"); - if (rowp == NULL) - return; - - if ((fp = fopen (outfile, "wb")) == NULL) - return; - - png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (! png_ptr) - return; - - info_ptr = png_create_info_struct(png_ptr); - if (! info_ptr) - { - png_destroy_write_struct(&png_ptr, (png_infopp) NULL); - fclose(fp); - return; - } - - if (setjmp(png_ptr->jmpbuf)) - { - png_destroy_write_struct(&png_ptr, &info_ptr); - fclose(fp); - return; - } - - png_init_io(png_ptr, fp); - - png_set_IHDR(png_ptr, info_ptr, im->nx * nxcell, im->ny * nycell, bitdepth, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_DEFAULT); - - png_write_info(png_ptr, info_ptr); - for (irow = im->ny - 1; irow >= 0; irow--) - { - png_bytep row_pointer = rowp; - int icol, ir; - - for (icol = 0; icol < im->nx; icol++) - { - double dens; - int p; - unsigned int outval; - int pos = icol * nxcell; - dens = (im->v[icol][irow] - densmin) / (densmax - densmin); - if (dens < 0) - dens = 0; - else if (dens > 1) - dens = 1; - outval = (unsigned int) (dens * max_out_level); - for (p = pos; p < pos + nxcell; p++) - { - if (bitdepth == 8) - rowp[p] = outval; - else { - int rowpos = p * 2; - rowp[rowpos] = (outval >> 8) & 0xFF; - rowp[rowpos+1] = (outval & 0xFF); - } - } - } - for (ir = 0; ir < nycell; ir++) - { - png_write_rows (png_ptr, &row_pointer, 1); - } - } - sys_free(rowp, "sdf2img"); - - png_write_end(png_ptr, info_ptr); - png_destroy_write_struct(&png_ptr, &info_ptr); - - fclose(fp); -} -#endif - -#ifdef HAVE_GD -#include "gd.h" -#define N_GRAYSCALE 256 -#endif - -void -sdf2d_to_gif (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax) -{ -#ifdef HAVE_GD - gdImagePtr gif; - FILE *out; - int gs_indices[N_GRAYSCALE]; - int i; - int irow; - int lastrow; - unsigned char *rowp; - - rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img"); - if (rowp == NULL) - return; - - gif = gdImageCreate(im->nx * nxcell, im->ny * nycell); - for (i = 0; i < N_GRAYSCALE; i++) - gs_indices[i] = gdImageColorAllocate(gif, i, i, i); - - lastrow = im->ny * nycell - 1; - for (irow = 0; irow < im->ny; irow++) - { - int icol, ir; - int rpos = irow * nycell; - for (ir = rpos; ir < rpos + nycell; ir++) - { - for (icol = 0; icol < im->nx; icol++) - { - double dens; - int ic; - int cpos = icol * nxcell; - dens = (im->v[icol][irow] - densmin) / (densmax - densmin); - if (dens < 0) - dens = 0; - else if (dens > 1) - dens = 1; - for (ic = cpos; ic < cpos + nxcell; ic++) - { - rowp[ic] = (unsigned int) (dens * (double) (N_GRAYSCALE - 1)); - gdImageSetPixel(gif, ic, lastrow - ir, gs_indices[rowp[ic]]); - } - } - } - } - sys_free(rowp, "sdf2img"); - - if ((out = fopen(outfile,"w")) == NULL) - { - fprintf(stderr,"Error opening output file %s for writing\n", outfile); - exit(1); - } - gdImageGif(gif,out); - fclose(out); - gdImageDestroy(gif); -#else - fprintf(stderr, "This version does not support GIF"); -#endif -} - -#ifndef NO_MAIN -int -main (int argc, char *const argv[]) -{ - return (sdf2img_main(argc, argv)); -} -#endif diff --git a/src/sdfinfo.cpp b/src/sdfinfo.cpp deleted file mode 100644 index b6d71f8..0000000 --- a/src/sdfinfo.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sdfinfo.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: sdfinfo.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** Revision 1.3 2000/05/16 04:33:59 kevin -** Improved option processing -** -** Revision 1.2 2000/05/08 20:02:32 kevin -** ANSI C changes -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** 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 -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FILE - * sdfinfo.c Display info on sdf files - */ - -#include "ct.h" - -enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG }; - -static struct option my_options[] = -{ - {"labels", 0, 0, O_LABELS}, - {"no-labels", 0, 0, O_NO_LABELS}, - {"stats", 0, 0, O_STATS}, - {"no-stats", 0, 0, O_NO_STATS}, - {"debug", 0, 0, O_DEBUG}, - {"verbose", 0, 0, O_VERBOSE}, - {"help", 0, 0, O_HELP}, - {"version", 0, 0, O_VERSION}, - {0, 0, 0, 0} -}; - -void -sdfinfo_usage (const char *program) -{ - fprintf(stdout, "sdfinfo_usage: %s infile [OPTIONS]\n", kbasename(program)); - fprintf(stdout, "Analyze an SDF2D file\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"); -} - -int -sdfinfo_main (int argc, char *const argv[]) -{ - IMAGE *im; - char *in_file; - int opt_verbose = 0; - int opt_stats = 1; - int opt_labels = 1; - int opt_debug = 0; - - while (1) - { - int c = getopt_long (argc, argv, "", my_options, NULL); - - if (c == -1) - break; - - switch (c) - { - case O_LABELS: - opt_labels = 1; - break; - case O_STATS: - opt_stats = 1; - break; - case O_NO_LABELS: - opt_labels = 0; - break; - case O_NO_STATS: - opt_stats = 0; - break; - case O_VERBOSE: - opt_verbose = 1; - break; - case O_DEBUG: - opt_debug = 0; - break; - case O_VERSION: -#ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); -#else - fprintf(stderr, "Unknown version number"); -#endif - exit(0); - case O_HELP: - case '?': - sdfinfo_usage(argv[0]); - return (0); - default: - sdfinfo_usage(argv[0]); - return (1); - } - } - - if (optind + 1 != argc) - { - sdfinfo_usage(argv[0]); - return (1); - } - - in_file = argv[optind]; - - im = image_load (in_file); - - if (opt_labels) - { - int nlabels = im->dfp_2d->dfp->num_label; - int i; - - for (i = 0; i < nlabels; i++) - { - SDF_BLK blk; - if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK) - break; - if (blk.lab.label_type == LT_HISTORY) { - fprintf(stdout, "History: %s\n", blk.lab.label_str); - fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } else if (blk.lab.label_type == LT_TITLE) { - fprintf(stdout, "Title: %s\n", blk.lab.label_str); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } else if (blk.lab.label_type == LT_NOTE) { - fprintf(stdout, "Note: %s\n", blk.lab.label_str); - fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate)); - } - } - } - - if (opt_stats) - { - double minfound = HUGE_VAL, maxfound = -HUGE_VAL; - double mode = 0, mean = 0, stddev = 0; - double spread; - int hist[256]; - int ibin, nbin = 256; - int max_bin, max_binindex; - double maxbin; - int ix, iy; - - maxbin = nbin - 1; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - if (im->v[ix][iy] > maxfound) - maxfound = im->v[ix][iy]; - if (im->v[ix][iy] < minfound) - minfound = im->v[ix][iy]; - mean += im->v[ix][iy]; - } - } - spread = maxfound - minfound; - if (spread == 0) - mode = minfound; - else - { - for (ibin = 0; ibin < nbin; ibin++) - hist[ibin] = 0; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5); - hist[b]++; - } - } - max_binindex = 0; - max_bin = -1; - for (ibin = 0; ibin < nbin; ibin++) - { - if (hist[ibin] > max_bin) - { - max_bin = hist[ibin]; - max_binindex = ibin; - } - } - mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound; - } - - mean /= im->nx * im->ny; - for (ix = 0; ix < im->nx; ix++) - { - for (iy = 0; iy < im->ny; iy++) - { - double diff = (im->v[ix][iy] - mean); - stddev += diff * diff; - } - } - stddev = sqrt(stddev / (im->nx * im->ny)); - fprintf(stdout,"nx=%d\n", im->nx); - fprintf(stdout,"ny=%d\n", im->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); - } - - return (0); -} - -#ifndef NO_MAIN -int -main (int argc, char *const argv[]) -{ - return (sdfinfo_main(argc, argv)); -} -#endif -- 2.34.1