+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: ctrec.c,v 1.13 2000/06/05 01:33:25 kevin Exp $
-** $Log: ctrec.c,v $
-** Revision 1.13 2000/06/05 01:33:25 kevin
-** BSpline changes
-**
-** Revision 1.12 2000/05/24 22:50:04 kevin
-** Added support for new SGP library
-**
-** Revision 1.11 2000/05/16 04:33:59 kevin
-** Improved option processing
-**
-** Revision 1.10 2000/05/11 01:06:30 kevin
-** Changed sprintf to snprintf
-**
-** Revision 1.9 2000/05/08 20:02:32 kevin
-** ANSI C changes
-**
-** Revision 1.8 2000/05/04 18:16:34 kevin
-** renamed filter definitions
-**
-** Revision 1.7 2000/05/03 08:49:50 kevin
-** Code cleanup
-**
-** Revision 1.6 2000/05/02 15:31:47 kevin
-** code cleaning
-**
-** Revision 1.5 2000/04/30 11:41:06 kevin
-** Cleaned up debugging code
-**
-** Revision 1.4 2000/04/30 10:13:27 kevin
-** Fixed MPI bugs
-**
-** Revision 1.3 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.2 2000/04/29 23:24:56 kevin
-** *** empty log message ***
-**
-** 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
- * ctrec.c Reconstruct an image from raysums
- *
- * DATE
- * Aug 84
- * Jul 99 -- Converted to ANSI C
- * Added MPI parallel processing
- */
-
-#include "ct.h"
-
-enum {O_INTERP, O_FILTER, O_FILTER_PARAM, O_BACKPROJ, O_VERBOSE, O_TRACE, O_HELP, O_DEBUG, O_VERSION};
-
-static struct option my_options[] =
-{
- {"interp", 1, 0, O_INTERP},
- {"filter", 1, 0, O_FILTER},
- {"filter-param", 1, 0, O_FILTER_PARAM},
- {"backproj", 1, 0, O_BACKPROJ},
- {"trace", 1, 0, O_TRACE},
- {"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
-ctrec_usage (const char *program)
-{
- fprintf(stdout,"usage: %s raysum-file image-file nx-image ny-image [OPTIONS]\n", kbasename(program));
- fprintf(stdout,"Image reconstruction from raysum projections\n");
- fprintf(stdout,"\n");
- fprintf(stdout," raysum-file Input raysum file\n");
- fprintf(stdout," image-file Output image file in SDF2D format\n");
- fprintf(stdout," nx-image Number of columns in output image\n");
- fprintf(stdout," ny-image Number of rows in output image\n");
- fprintf(stdout," --interp Interpolation method during backprojection\n");
- fprintf(stdout," nearest Nearest neighbor interpolation\n");
- fprintf(stdout," linear Linear interpolation\n");
-#if HAVE_BSPLINE_INTERP
- fprintf(stdout," bspline B-spline interpolation\n");
-#endif
- fprintf(stdout," --filter Filter name\n");
- fprintf(stdout," abs_bandlimit Abs * Bandlimiting (default)\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," --backproj Backprojection Method\n");
- fprintf(stdout," trig Trigometric functions at every point\n");
- fprintf(stdout," table Trigometric functions with precalculated table\n");
- fprintf(stdout," diff Difference method\n");
- fprintf(stdout," diff2 Optimized difference method (default)\n");
- fprintf(stdout," idiff2 Optimized difference method with integer math\n");
- fprintf(stdout," --filter-param Alpha level for Hamming filter\n");
- fprintf(stdout," --trace Set tracing to level\n");
- fprintf(stdout," none No tracing (default)\n");
- fprintf(stdout," text Text level tracing\n");
- fprintf(stdout," phm Trace phantom\n");
- fprintf(stdout," rays Trace allrays\n");
- fprintf(stdout," plot Trace plotting\n");
- fprintf(stdout," clipping Trace clipping\n");
- fprintf(stdout," --verbose Turn on verbose mode\n");
- fprintf(stdout," --debug Turn on debug mode\n");
- fprintf(stdout," --version Print version\n");
- fprintf(stdout," --help Print this help message\n");
-}
-
-
-#ifdef MPI_CT
-static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int debug);
-#endif
-
-static void print_raysum_info(const RAYSUM *rs);
-
-int
-ctrec_main (const int argc, char *const argv[])
-{
- IMAGE *im_global = NULL;
- RAYSUM *rs_global = NULL;
- char *rs_name, *im_filename = NULL;
- char remark[MAXREMARK];
- char filt_name[80];
- int nx, ny;
- double time_start = 0, time_end = 0;
- char *endptr;
- int opt_verbose = 0;
- int opt_debug = 0;
- int opt_trace = TRACE_NONE;
- double opt_filter_param = 1;
- int opt_filter = FILTER_ABS_BANDLIMIT;
- int opt_interp = I_LINEAR;
- int opt_interp_param = 1;
- BackprojType opt_backproj = O_BPROJ_DIFF2;
-#ifdef MPI_CT
- IMAGE *im_local;
- RAYSUM *rs_local;
- int mpi_argc = argc;
- char **mpi_argv = (char **) argv;
- int mpi_nview, mpi_ndet;
- double mpi_detinc, mpi_rotinc, mpi_phmlen;
- double mpi_t1, mpi_t2, mpi_t, mpi_t_g;
- int ix;
-
- 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);
- exit(1);
- }
-#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
- while (1) {
- int c = getopt_long(argc, argv, "", my_options, NULL);
- char *endptr = NULL;
-
- if (c == -1)
- break;
-
- switch (c)
- {
- case O_INTERP:
- if ((opt_interp = opt_set_interpolation(optarg)) < 0) {
- ctrec_usage(argv[0]);
- return (1);
- }
- break;
- case O_FILTER:
- if ((opt_filter = opt_set_filter(optarg)) < 0) {
- ctrec_usage(argv[0]);
- return (1);
- }
- break;
- case O_BACKPROJ:
- if ((opt_backproj = opt_set_backproj(optarg)) < 0) {
- ctrec_usage(argv[0]);
- return (1);
- }
- break;
- case O_FILTER_PARAM:
- opt_filter_param = strtod(optarg, &endptr);
- if (endptr != optarg + strlen(optarg)) {
- ctrec_usage(argv[0]);
- }
- 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) {
- ctrec_usage(argv[0]);
- return (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 '?':
- ctrec_usage(argv[0]);
- return (0);
- default:
- ctrec_usage(argv[0]);
- return (1);
- }
- }
-
- if (optind + 4 != argc) {
- ctrec_usage(argv[0]);
- return (1);
- }
-
- rs_name = argv[optind];
-
- im_filename = argv[optind + 1];
-
- nx = strtol(argv[optind + 2], &endptr, 10);
- ny = strtol(argv[optind + 3], &endptr, 10);
-
- 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);
- else
- snprintf (filt_name, sizeof(filt_name), "%s", name_of_filter (opt_filter));
-
- snprintf (remark, sizeof(remark), "Reconstruct: %dx%d, %s, %s, %s",
- nx, ny, filt_name, name_of_interpolation (opt_interp), name_of_backproj(opt_backproj));
-
- if (opt_verbose)
- fprintf (stdout, "%s\n", remark);
-#ifdef MPI_CT
- }
-#endif
-
-#ifdef MPI_CT
- if (mpi_ct.my_rank == 0) {
- rs_global = raysum_open (rs_name);
- raysum_read (rs_global);
- if (opt_verbose)
- print_raysum_info(rs_global);
-
- mpi_ndet = rs_global->ndet;
- mpi_nview = rs_global->nview;
- mpi_detinc = rs_global->det_inc;
- mpi_phmlen = rs_global->phmlen;
- mpi_rotinc = rs_global->rot_inc;
- }
-
- 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_filter, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_interp, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_filter_param, 1, MPI_DOUBLE, 0, mpi_ct.comm);
- MPI_Bcast(&opt_interp_param, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_backproj, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&mpi_ndet, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&mpi_nview, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&mpi_detinc, 1, MPI_DOUBLE, 0, mpi_ct.comm);
- MPI_Bcast(&mpi_phmlen, 1, MPI_DOUBLE, 0, mpi_ct.comm);
- MPI_Bcast(&mpi_rotinc, 1, MPI_DOUBLE, 0, mpi_ct.comm);
- MPI_Bcast(&nx, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&ny, 1, MPI_INT, 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(mpi_nview);
-
- rs_local = raysum_create (NULL, mpi_ct.local_work_units[mpi_ct.my_rank], mpi_ndet);
-
- rs_local->ndet = mpi_ndet;
- rs_local->nview = mpi_nview;
- rs_local->det_inc = mpi_detinc;
- rs_local->phmlen = mpi_phmlen;
- rs_local->rot_inc = mpi_rotinc;
-
- if (opt_verbose)
- mpi_t1 = MPI_Wtime();
- mpi_scatter_rs(rs_global, rs_local, opt_debug);
- 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 scatter rs = %f secs, Max time = %f sec\n", mpi_t, mpi_t_g);
- }
-
- if (mpi_ct.my_rank == 0) {
- im_global = image_create (im_filename, nx, ny);
- sdf_add_label (LT_HISTORY, rs_global->remark, rs_global->calctime, im_global->dfp_2d->dfp);
- sdf_add_empty_label (im_global->dfp_2d->dfp);
- }
- im_local = image_create (NULL, nx, ny);
-
-#else
- rs_global = raysum_open (rs_name);
- raysum_read (rs_global);
- if (opt_verbose)
- print_raysum_info(rs_global);
-
- im_global = image_create (im_filename, nx, ny);
- sdf_add_label (LT_HISTORY, rs_global->remark, rs_global->calctime, im_global->dfp_2d->dfp);
- sdf_add_empty_label (im_global->dfp_2d->dfp);
-#endif
-
-#ifdef MPI_CT
- mpi_t1 = MPI_Wtime();
- image_reconst (im_local, rs_local, opt_filter, opt_filter_param,
- opt_interp, opt_interp_param, opt_backproj, opt_trace);
- 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 && opt_verbose)
- printf("Time to reconstruct = %f, Max time = %f\n", mpi_t, mpi_t_g);
-#else
- image_reconst (im_global, rs_global, opt_filter, opt_filter_param,
- opt_interp, opt_interp_param, opt_backproj, opt_trace);
-#endif
-
-#ifdef MPI_CT
- if (opt_verbose)
- mpi_t1 = MPI_Wtime();
-
- for (ix = 0; ix < im_local->nx; ix++) {
- void *recvbuf = NULL;
- if (mpi_ct.my_rank == 0)
- recvbuf = im_global->v[ix];
-
- MPI_Reduce(im_local->v[ix], recvbuf, im_local->ny, MPI_FLOAT, MPI_SUM, 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 reduce image = %f secs, max time = %f\n", mpi_t, mpi_t_g);
- }
-
- if (mpi_ct.my_rank == 0)
- time_end = MPI_Wtime();
-#else
- time_end = td_current_sec();
-#endif
-
-
-#ifdef MPI_CT
- if (mpi_ct.my_rank == 0)
-#endif
- {
- raysum_close (rs_global);
- strncpy (im_global->remark, remark, sizeof(im_global->remark));
- im_global->calctime = time_end - time_start;
- image_save (im_global);
- if (opt_verbose)
- fprintf (stdout, "Time active = %.2f\n", im_global->calctime);
- }
-
-#ifdef MPI_CT
- MPI_Finalize();
-#endif
-
- return (0);
-}
-
-
-#ifdef MPI_CT
-static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug)
-{
- int iproc;
- int end_work_unit;
- int iw = 0;
-
- 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;
-
- for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) {
- MPI_Send(&rs_global->view[iw]->ndet, 1, MPI_INT, iproc, 0, mpi_ct.comm);
- MPI_Send(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm);
- MPI_Send(rs_global->view[iw]->detval, rs_global->ndet, MPI_FLOAT, iproc, 0, mpi_ct.comm);
- }
- }
- }
-
- if (opt_debug)
- fprintf(stdout, "Receiving rs data in process %d\n", mpi_ct.my_rank);
-
- end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1;
- for (iw = 0; iw <= end_work_unit; iw++) {
- MPI_Status status;
-
- MPI_Recv(&rs_local->view[iw]->ndet, 1, MPI_INT, 0, 0, mpi_ct.comm, &status);
- MPI_Recv(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm, &status);
- MPI_Recv(rs_local->view[iw]->detval, rs_local->ndet, MPI_FLOAT, 0, 0, mpi_ct.comm, &status);
- }
- rs_local->nview = mpi_ct.local_work_units[mpi_ct.my_rank];
- if (opt_debug) {
- MPI_Barrier(MPI_COMM_WORLD);
- fprintf(stdout, "Done with mpi_scatter_rs in process %2d\n", mpi_ct.my_rank);
- }
-}
-
-#endif
-
-static void print_raysum_info(const RAYSUM *rs)
-{
- printf ("Number of detectors: %d\n", rs->ndet);
- printf (" Number of views: %d\n", rs->nview);
- printf (" Remark: %s\n", rs->remark);
- printf (" phmlen: %f\n", rs->phmlen);
- printf (" det_start: %f\n", rs->det_start);
- printf (" det_inc: %f\n", rs->det_inc);
- printf (" rot_start: %f\n", rs->rot_start);
- printf (" rot_inc: %f\n", rs->rot_inc);
-}
-
-#ifndef NO_MAIN
-int
-main (const int argc, char *const argv[])
-{
- return (ctrec_main(argc, argv));
-}
-#endif
-
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** PURPOSE
-** Generate raysum projections from phantom object
-**
-** HISTORY
-** 1984 -- Final DOS version
-** 1999 -- First UNIX version
-**
-** $Id: phm2rs.c,v 1.12 2000/05/24 22:50:04 kevin Exp $
-** $Log: phm2rs.c,v $
-** Revision 1.12 2000/05/24 22:50:04 kevin
-** Added support for new SGP library
-**
-** Revision 1.11 2000/05/16 04:33:59 kevin
-** Improved option processing
-**
-** Revision 1.9 2000/05/08 20:02:32 kevin
-** ANSI C changes
-**
-** Revision 1.8 2000/05/04 18:16:34 kevin
-** renamed filter definitions
-**
-** Revision 1.7 2000/05/03 08:49:50 kevin
-** Code cleanup
-**
-** Revision 1.6 2000/04/30 18:23:53 kevin
-** Code cleaning
-**
-** Revision 1.5 2000/04/30 10:13:27 kevin
-** Fixed MPI bugs
-**
-** 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/29 23:24:56 kevin
-** *** empty log message ***
-**
-** 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
-******************************************************************************/
-
-
-#include "ct.h"
-
-enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE,
- O_TRACE, O_VERBOSE, O_HELP, O_DEBUG, O_VERSION };
-
-static struct option phm2rs_options[] =
-{
- {"phantom", 1, 0, O_PHANTOM},
- {"phmfile", 1, 0, O_PHMFILE},
- {"desc", 1, 0, O_DESC},
- {"nray", 1, 0, O_NRAY},
- {"rotangle", 1, 0, O_ROTANGLE},
- {"trace", 1, 0, O_TRACE},
- {"verbose", 0, 0, O_VERBOSE},
- {"help", 0, 0, O_HELP},
- {"debug", 0, 0, O_DEBUG},
- {"version", 0, 0, O_VERSION},
- {0, 0, 0, 0}
-};
-
-
-void
-phm2rs_usage (const char *program)
-{
-#ifdef MPI_CT
-if (mpi_ct.my_rank == 0)
- {
-#endif
- fprintf(stdout,"usage: %s outfile ndet nview [--phantom phantom-name] [--phmfile filename] [OPTIONS]\n", kbasename(program));
- fprintf(stdout,"Calculate raysums (projections) through phantom object, either\n");
- fprintf(stdout,"a predefined --phantom or a --phmfile\n");
- fprintf(stdout,"\n");
- fprintf(stdout," outfile Name of output file for raysums\n");
- fprintf(stdout," ndet Number of detectors\n");
- fprintf(stdout," nview Number of rotated views\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 Get Phantom from phantom file\n");
- fprintf(stdout," --desc Description of raysum\n");
- fprintf(stdout," --nray Number of rays per detector (default = 1)\n");
- fprintf(stdout," --rotangle Degrees to rotate view through, multiple of PI (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 image\n");
- fprintf(stdout," rays Trace rays\n");
- fprintf(stdout," plot Trace plot\n");
- fprintf(stdout," clipping Trace clipping\n");
- fprintf(stdout," --verbose Verbose mode\n");
- fprintf(stdout," --debug Debug mode\n");
- fprintf(stdout," --version Print version\n");
- fprintf(stdout," --help Print this help message\n");
-#ifdef MPI_CT
- }
- MPI_Abort(mpi_ct.comm, 1);
-#endif
-}
-
-#ifdef MPI_CT
-void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug);
-#endif
-
-int
-phm2rs_main (const int argc, char *const argv[])
-{
- DETECTOR *det;
- PHANTOM *phm = NULL;
- RAYSUM *rs_global = NULL;
- char str[256], *opt_outfile = NULL, opt_desc[MAXREMARK+1];
- char opt_phmfilename[256];
- char *endptr, *endstr;
- int opt_ndet, opt_nview;
- int opt_nray = 1;
- int opt_trace = 0, opt_phmnum = -1;
- int opt_verbose = 0;
- int opt_debug = 0;
- double opt_rotangle = 1;
- double time_start = 0, time_end = 0;
-
-#ifndef MPI_CT
- time_start = td_current_sec();
-#else
- RAYSUM *rs_local;
- int mpi_argc = argc;
- char **mpi_argv = (char **) argv;
- double mpi_t1 = 0, mpi_t2 = 0, 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);
- exit(1);
- }
- time_start = MPI_Wtime();
-#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, "", phm2rs_options, NULL);
- char *endptr = NULL;
- char *endstr;
-
- if (c == -1)
- break;
-
- switch (c) {
- case O_PHANTOM:
- if ((opt_phmnum = opt_set_phantom (optarg)) < 0) {
- phm2rs_usage(argv[0]);
- return (1);
- }
- phm = phm_create (opt_phmnum);
- break;
- case O_PHMFILE:
-#ifdef MPI_CT
- if (mpi_ct.my_rank == 0)
- fprintf(stderr, "Can not read phantom from file in MPI mode\n");
- return (1);
-#endif
- strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename));
- phm = phm_create_from_file(opt_phmfilename);
- break;
- case O_VERBOSE:
- opt_verbose = 1;
- break;
- case O_DEBUG:
- opt_debug = 1;
- break;
- break;
- case O_TRACE:
- if ((opt_trace = opt_set_trace(optarg)) < 0) {
- phm2rs_usage(argv[0]);
- return (1);
- }
- break;
- case O_DESC:
- strncpy(opt_desc, optarg, sizeof(opt_desc));
- break;
- case O_ROTANGLE:
- opt_rotangle = strtod(optarg, &endptr);
- endstr = optarg + strlen(optarg);
- if (endptr != endstr) {
- fprintf(stderr,"Error setting --rotangle to %s\n", optarg);
- phm2rs_usage(argv[0]);
- return (1);
- }
- break;
- case O_NRAY:
- opt_nray = strtol(optarg, &endptr, 10);
- endstr = optarg + strlen(optarg);
- if (endptr != endstr) {
- fprintf(stderr,"Error setting --nray to %s\n", optarg);
- phm2rs_usage(argv[0]);
- return (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 '?':
- phm2rs_usage(argv[0]);
- return (0);
- default:
- phm2rs_usage(argv[0]);
- return (1);
- }
- }
-
- if (phm == NULL) {
- fprintf(stderr, "No phantom defined\n");
- phm2rs_usage(argv[0]);
- return (1);
- }
- if (optind + 3 != argc) {
- phm2rs_usage(argv[0]);
- return (1);
- }
-
- opt_outfile = argv[optind];
- opt_ndet = strtol(argv[optind+1], &endptr, 10);
- endstr = argv[optind+1] + strlen(argv[optind+1]);
- if (endptr != endstr) {
- fprintf(stderr,"Error setting --ndet to %s\n", argv[optind+1]);
- phm2rs_usage(argv[0]);
- return (1);
- }
- opt_nview = strtol(argv[optind+2], &endptr, 10);
- endstr = argv[optind+2] + strlen(argv[optind+2]);
- if (endptr != endstr) {
- fprintf(stderr,"Error setting --nview to %s\n", argv[optind+2]);
- phm2rs_usage(argv[0]);
- return (1);
- }
-
- snprintf(str, sizeof(str),
- "Raysum_Collect: NDet=%d, Nview=%d, NRay=%d, RotAngle=%.2f, ",
- opt_ndet, opt_nview, opt_nray, opt_rotangle);
- 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));
- }
- if (opt_desc[0]) {
- strncat(str, ": ", sizeof(str));
- strncat(str, opt_desc, sizeof(str));
- }
- strncpy(opt_desc, str, sizeof(opt_desc));
-#ifdef MPI_CT
- }
-#endif
-
-#ifdef MPI_CT
- MPI_Barrier(mpi_ct.comm);
- MPI_Bcast(&opt_rotangle, 1, MPI_DOUBLE, 0, mpi_ct.comm);
- MPI_Bcast(&opt_nview, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_ndet, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_nray, 1, MPI_INT, 0, mpi_ct.comm);
- MPI_Bcast(&opt_phmnum, 1, MPI_INT, 0, mpi_ct.comm);
- 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);
-
- if (mpi_ct.my_rank > 0 && opt_phmnum >= 0)
- phm = phm_create (opt_phmnum);
-#endif
-
- opt_rotangle *= PI;
- det = detector_create (phm, DETECTOR_PARALLEL, opt_ndet, opt_nview, opt_nray, opt_rotangle);
-
-#ifdef MPI_CT
- mpi_ct_calc_work_units(opt_nview);
- if (mpi_ct.my_rank == 0) {
- rs_global = raysum_create_from_det (opt_outfile, det);
- raysum_alloc_views(rs_global);
- }
-
- rs_local = raysum_create_from_det (NULL, det);
- rs_local->nview = mpi_ct.local_work_units[mpi_ct.my_rank];
- if (opt_debug)
- printf("rs_local->nview = %d (process %d)\n", rs_local->nview, mpi_ct.my_rank);
-
- if (opt_verbose)
- mpi_t1 = MPI_Wtime();
- raysum_collect (rs_local, det, phm, mpi_ct.start_work_unit[mpi_ct.my_rank], opt_trace, FALSE);
- 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 collect rs = %f secs, Max = %f secs\n", mpi_t, mpi_t_g);
- }
-
- if (opt_verbose)
- mpi_t1 = MPI_Wtime();
- mpi_gather_rs(rs_global, rs_local, opt_debug);
- 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 gather rs = %f secs, Max = %f secs\n", mpi_t, mpi_t_g);
- }
-#else
- rs_global = raysum_create_from_det (opt_outfile, det);
- raysum_collect (rs_global, det, phm, 0, opt_trace, FALSE);
-#endif
-
-#ifndef MPI_CT
- time_end = td_current_sec();
-#else
- time_end = MPI_Wtime();
- if (mpi_ct.my_rank == 0)
-#endif
- {
- rs_global->calctime = time_end - time_start;
- strncpy (rs_global->remark, opt_desc, sizeof(rs_global->remark));
- if (opt_verbose) {
- fprintf(stdout, "Remark: %s\n", rs_global->remark);
- fprintf(stdout, "Time active = %.2f secs\n", rs_global->calctime);
- }
- }
-
-#ifdef MPI_CT
- if (mpi_ct.my_rank == 0)
-#endif
- {
- raysum_write (rs_global);
- raysum_close (rs_global);
- }
-
- phm_free (phm);
- detector_free (det);
-
- return (0);
-}
-
-
-/* FUNCTION
- * mpi_gather_rs
- *
- * SYNOPSIS
- * Gather's raysums from all processes in rs_local in rs_global in process 0
- */
-
-#ifdef MPI_CT
-void mpi_gather_rs (RAYSUM *rs_global, RAYSUM *rs_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(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm);
- MPI_Send(&rs_local->view[iw]->ndet, 1, MPI_INT, 0, 0, mpi_ct.comm);
- MPI_Send(rs_local->view[iw]->detval, rs_local->ndet, 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\n", iproc);
-
- for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) {
- MPI_Status status;
-
- MPI_Recv(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm, &status);
- MPI_Recv(&rs_global->view[iw]->ndet, 1, MPI_INT, iproc, 0, mpi_ct.comm, &status);
- MPI_Recv(rs_global->view[iw]->detval, rs_global->ndet, MPI_FLOAT, iproc, 0, mpi_ct.comm, &status);
- }
- }
- }
-
-}
-#endif
-
-
-#ifndef NO_MAIN
-int
-main (const int argc, char *const argv[])
-{
- return (phm2rs_main(argc, argv));
-}
-#endif
-
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: phm2sdf.c,v 1.10 2000/05/24 22:50:04 kevin Exp $
-** $Log: phm2sdf.c,v $
-** 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;
- int opt_filter = -1;
- int 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
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: rs2sdf.c,v 1.3 2000/05/16 04:33:59 kevin Exp $
-** $Log: rs2sdf.c,v $
-** 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
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: sdf-1.c,v 1.6 2000/05/24 22:50:04 kevin Exp $
-** $Log: sdf-1.c,v $
-** 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
-
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: sdf-2.c,v 1.5 2000/05/24 22:50:04 kevin Exp $
-** $Log: sdf-2.c,v $
-** 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
-
+++ /dev/null
-/*****************************************************************************\r
-** This is part of the CTSim program\r
-** Copyright (C) 1983-2000 Kevin Rosenberg\r
-**\r
-** $Id: sdf2img.c,v 1.6 2000/06/03 07:57:51 kevin Exp $\r
-** $Log: sdf2img.c,v $
-** Revision 1.6 2000/06/03 07:57:51 kevin
-** Fixed PNG 16-bit format
-**\r
-** Revision 1.5 2000/06/03 06:29:57 kevin\r
-** *** empty log message ***\r
-**\r
-** Revision 1.4 2000/05/24 22:50:04 kevin\r
-** Added support for new SGP library\r
-**\r
-** Revision 1.3 2000/05/16 04:33:59 kevin\r
-** Improved option processing\r
-**\r
-** Revision 1.2 2000/05/08 20:02:32 kevin\r
-** ANSI C changes\r
-**\r
-** Revision 1.1.1.1 2000/04/28 13:02:44 kevin\r
-** Initial CVS import for first public release\r
-**\r
-**\r
-**\r
-** This program is free software; you can redistribute it and/or modify\r
-** it under the terms of the GNU General Public License (version 2) as\r
-** published by the Free Software Foundation.\r
-**\r
-** This program is distributed in the hope that it will be useful,\r
-** but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-** GNU General Public License for more details.\r
-**\r
-** You should have received a copy of the GNU General Public License\r
-** along with this program; if not, write to the Free Software\r
-** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-******************************************************************************/\r
-\r
-/* FILE\r
- * sdf2img.c Convert an SDF file to a viewable format image\r
- */\r
-\r
-#include "ct.h"\r
-\r
-#if HAVE_PNG\r
-void sdf2d_to_png (IMAGE *im, char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);\r
-#endif\r
-#if HAVE_GIF\r
-void sdf2d_to_gif (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax);\r
-#endif\r
-void sdf2d_to_pgm (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax);\r
-void sdf2d_to_pgmasc (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax);\r
-\r
-enum { O_SCALE, O_MIN, O_MAX, O_AUTO, O_CENTER, O_STATS, O_FORMAT, O_LABELS, \r
- O_HELP, O_VERBOSE, O_VERSION, O_DEBUG };\r
-\r
-static struct option my_options[] =\r
-{\r
- {"scale", 1, 0, O_SCALE},\r
- {"min", 1, 0, O_MIN},\r
- {"max", 1, 0, O_MAX},\r
- {"auto", 1, 0, O_AUTO},\r
- {"center", 1, 0, O_CENTER},\r
- {"format", 1, 0, O_FORMAT},\r
- {"labels", 0, 0, O_LABELS},\r
- {"stats", 0, 0, O_STATS},\r
- {"verbose", 0, 0, O_VERBOSE},\r
- {"debug", 0, 0, O_DEBUG},\r
- {"help", 0, 0, O_HELP},\r
- {"version", 0, 0, O_VERSION},\r
- {0, 0, 0, 0}\r
-};\r
-\r
-enum { O_AUTO_FULL, O_AUTO_STD0_1, O_AUTO_STD0_5, O_AUTO_STD1, O_AUTO_STD2, O_AUTO_STD3 };\r
-#define O_AUTO_FULL_STR "full"\r
-#define O_AUTO_STD0_1_STR "std0.1"\r
-#define O_AUTO_STD0_5_STR "std0.5"\r
-#define O_AUTO_STD1_STR "std1"\r
-#define O_AUTO_STD2_STR "std2"\r
-#define O_AUTO_STD3_STR "std3"\r
-\r
-enum { O_CENTER_MEAN, O_CENTER_MODE };\r
-#define O_CENTER_MEAN_STR "mean"\r
-#define O_CENTER_MODE_STR "mode"\r
-\r
-enum { O_FORMAT_GIF, O_FORMAT_PNG, O_FORMAT_PNG16, O_FORMAT_PGM, O_FORMAT_PGMASC, O_FORMAT_DISP };\r
-#define O_FORMAT_GIF_STR "gif"\r
-#define O_FORMAT_PNG_STR "png" \r
-#define O_FORMAT_PNG16_STR "png16" \r
-#define O_FORMAT_PGM_STR "pgm"\r
-#define O_FORMAT_PGMASC_STR "pgmasc"\r
-#define O_FORMAT_DISP_STR "disp"\r
-\r
-void \r
-sdf2img_usage (const char *program)\r
-{\r
- fprintf(stdout, "sdf2img_usage: %s sdfname outfile [OPTIONS]\n", kbasename(program));\r
- fprintf(stdout, "Convert SDF2D file to an image file\n");\r
- fprintf(stdout, "\n");\r
- fprintf(stdout, " sdfname Name of input SDF file\n");\r
- fprintf(stdout, " outfile Name of output file\n");\r
- fprintf(stdout, " --format Output format\n");\r
- fprintf(stdout, " pgm PGM (portable graymap) format (default)\n");\r
- fprintf(stdout, " pgmasc PGM (portable graymap) ASCII format\n");\r
-#ifdef HAVE_PNG\r
- fprintf(stdout, " png PNG (8-bit) format\n");\r
- fprintf(stdout, " png16 PNG (16-bit) format\n");\r
-#endif\r
-#ifdef HAVE_GIF\r
- fprintf(stdout, " gif GIF format\n");\r
-#endif\r
- fprintf(stdout, " disp Display on screen\n");\r
- fprintf(stdout, " --center Center of window\n");\r
- fprintf(stdout, " mode Mode is center of window (default)\n");\r
- fprintf(stdout, " mean Mean is center of window\n");\r
- fprintf(stdout, " --auto Set auto window\n");\r
- fprintf(stdout, " full Use full window (default)\n");\r
- fprintf(stdout, " std0.1 Use 0.1 standard deviation about center\n");\r
- fprintf(stdout, " std0.5 Use 0.5 standard deviation about center\n");\r
- fprintf(stdout, " std1 Use one standard deviation about center\n");\r
- fprintf(stdout, " std2 Use two standard deviations about center\n");\r
- fprintf(stdout, " std3 Use three standard deviations about center\n");\r
- fprintf(stdout, " --scale Scaling factor for output size\n");\r
- fprintf(stdout, " --min Set minimum intensity\n");\r
- fprintf(stdout, " --max Set maximum intensity\n");\r
- fprintf(stdout, " --stats Print image statistics\n");\r
- fprintf(stdout, " --labels Print image labels\n");\r
- fprintf(stdout, " --debug Set debug mode\n");\r
- fprintf(stdout, " --verbose Set verbose mode\n");\r
- fprintf(stdout, " --version Print version\n");\r
- fprintf(stdout, " --help Print this help message\n");\r
-}\r
-\r
-\r
-int \r
-sdf2img_main (int argc, char *const argv[])\r
-{\r
- IMAGE *im;\r
- double densmin = HUGE_VAL, densmax = -HUGE_VAL;\r
- char *in_file, *out_file;\r
- int opt_verbose = 0;\r
- int opt_scale = 1;\r
- int opt_auto = O_AUTO_FULL;\r
- int opt_set_max = 0;\r
- int opt_set_min = 0;\r
- int opt_stats = 0;\r
- int opt_debug = 0;\r
- int opt_center = O_CENTER_MODE;\r
- int opt_format = O_FORMAT_PGM;\r
- int opt_labels = 0;\r
-\r
- while (1)\r
- {\r
- int c = getopt_long (argc, argv, "", my_options, NULL);\r
- char *endptr = NULL;\r
- char *endstr;\r
- \r
- if (c == -1)\r
- break;\r
- \r
- switch (c)\r
- {\r
- case O_MIN:\r
- opt_set_min = 1;\r
- densmin = strtod(optarg, &endptr);\r
- endstr = optarg + strlen(optarg);\r
- if (endptr != endstr)\r
- {\r
- fprintf(stderr, "Error setting --min to %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_MAX:\r
- opt_set_max = 1;\r
- densmax = strtod(optarg, &endptr);\r
- endstr = optarg + strlen(optarg);\r
- if (endptr != endstr)\r
- {\r
- fprintf(stderr, "Error setting --max to %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_SCALE:\r
- opt_scale = strtol(optarg, &endptr, 10);\r
- endstr = optarg + strlen(optarg);\r
- if (endptr != endstr)\r
- {\r
- fprintf(stderr,"Error setting --scale to %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_AUTO:\r
- if (strcmp(optarg, O_AUTO_FULL_STR) == 0)\r
- opt_auto = O_AUTO_FULL;\r
- else if (strcmp(optarg, O_AUTO_STD1_STR) == 0)\r
- opt_auto = O_AUTO_STD1;\r
- else if (strcmp(optarg, O_AUTO_STD0_5_STR) == 0)\r
- opt_auto = O_AUTO_STD0_5;\r
- else if (strcmp(optarg, O_AUTO_STD0_1_STR) == 0)\r
- opt_auto = O_AUTO_STD0_1;\r
- else if (strcmp(optarg, O_AUTO_STD2_STR) == 0)\r
- opt_auto = O_AUTO_STD2;\r
- else if (strcmp(optarg, O_AUTO_STD3_STR) == 0)\r
- opt_auto = O_AUTO_STD3;\r
- else\r
- {\r
- fprintf(stderr, "Invalid auto mode %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_CENTER:\r
- if (strcmp(optarg, O_CENTER_MEAN_STR) == 0)\r
- opt_center = O_CENTER_MEAN;\r
- else if (strcmp(optarg, O_CENTER_MODE_STR) == 0)\r
- opt_center = O_CENTER_MODE;\r
- else\r
- {\r
- fprintf(stderr, "Invalid center mode %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_FORMAT:\r
- if (strcmp(optarg, O_FORMAT_PGM_STR) == 0)\r
- opt_format = O_FORMAT_PGM;\r
- else if (strcmp(optarg, O_FORMAT_PGMASC_STR) == 0)\r
- opt_format = O_FORMAT_PGMASC;\r
-#if HAVE_PNG\r
- else if (strcmp(optarg, O_FORMAT_PNG_STR) == 0)\r
- opt_format = O_FORMAT_PNG;\r
- else if (strcmp(optarg, O_FORMAT_PNG16_STR) == 0)\r
- opt_format = O_FORMAT_PNG16;\r
-#endif\r
-#if HAVE_GIF\r
- else if (strcmp(optarg, O_FORMAT_GIF_STR) == 0)\r
- opt_format = O_FORMAT_GIF;\r
-#endif\r
- else if (strcmp(optarg, O_FORMAT_DISP_STR) == 0)\r
- opt_format = O_FORMAT_DISP;\r
- else {\r
- fprintf(stderr, "Invalid format mode %s\n", optarg);\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- break;\r
- case O_LABELS:\r
- opt_labels = 1;\r
- break;\r
- case O_VERBOSE:\r
- opt_verbose = 1;\r
- break;\r
- case O_DEBUG:\r
- opt_debug = 1;\r
- break;\r
- case O_STATS:\r
- opt_stats = 1;\r
- break;\r
- case O_VERSION:\r
-#ifdef VERSION\r
- fprintf(stdout, "Version %s\n", VERSION);\r
-#else\r
- fprintf(stderr, "Unknown version number");\r
-#endif\r
- exit(0);\r
- case O_HELP:\r
- case '?':\r
- sdf2img_usage(argv[0]);\r
- return (0);\r
- default:\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- }\r
-\r
- if ((opt_format == O_FORMAT_DISP && optind + 1 != argc) \r
- || (opt_format != O_FORMAT_DISP && optind + 2 != argc))\r
- {\r
- sdf2img_usage(argv[0]);\r
- return (1);\r
- }\r
- \r
- in_file = argv[optind];\r
-\r
- if (opt_format != O_FORMAT_DISP)\r
- out_file = argv[optind+1];\r
- else out_file = NULL;\r
-\r
- if ((im = image_load (in_file)) == NULL)\r
- {\r
- fprintf(stderr, "File %s does not exist\n", in_file);\r
- return (1);\r
- }\r
-\r
- if (opt_labels) \r
- {\r
- int nlabels = im->dfp_2d->dfp->num_label;\r
- int i;\r
-\r
- for (i = 0; i < nlabels; i++)\r
- {\r
- SDF_BLK blk;\r
- if (sdf_read_label(&blk.lab, i, im->dfp_2d->dfp) != SDF_OK)\r
- break;\r
- if (blk.lab.label_type == LT_HISTORY) {\r
- fprintf(stdout, "History: %s\n", blk.lab.label_str);\r
- fprintf(stdout, " calc time = %.2f secs\n", blk.lab.calc_time);\r
- fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));\r
- } else if (blk.lab.label_type == LT_TITLE) {\r
- fprintf(stdout, "Title: %s\n", blk.lab.label_str);\r
- fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));\r
- } else if (blk.lab.label_type == LT_NOTE) {\r
- fprintf(stdout, "Note: %s\n", blk.lab.label_str);\r
- fprintf(stdout, " Timestamp = %s\n", td_str_tmdt(&blk.lab.timedate));\r
- }\r
- }\r
- }\r
-\r
- if (opt_stats || (! (opt_set_max && opt_set_min)))\r
- {\r
- double minfound = HUGE_VAL, maxfound = -HUGE_VAL;\r
- double mode = 0, mean = 0, stddev = 0, window = 0;\r
- double spread;\r
- int hist[256];\r
- int ibin, nbin = 256;\r
- int max_bin, max_binindex; \r
- double maxbin;\r
- int ix, iy;\r
-\r
- maxbin = nbin - 1;\r
- for (ix = 0; ix < im->nx; ix++)\r
- {\r
- for (iy = 0; iy < im->ny; iy++)\r
- {\r
- if (im->v[ix][iy] > maxfound)\r
- maxfound = im->v[ix][iy];\r
- if (im->v[ix][iy] < minfound)\r
- minfound = im->v[ix][iy];\r
- mean += im->v[ix][iy];\r
- }\r
- }\r
- spread = maxfound - minfound;\r
- if (spread == 0)\r
- mode = minfound;\r
- else\r
- {\r
- for (ibin = 0; ibin < nbin; ibin++)\r
- hist[ibin] = 0;\r
- for (ix = 0; ix < im->nx; ix++)\r
- {\r
- for (iy = 0; iy < im->ny; iy++)\r
- {\r
- int b = (int) ((((im->v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);\r
- hist[b]++;\r
- }\r
- }\r
- max_binindex = 0;\r
- max_bin = -1;\r
- for (ibin = 0; ibin < nbin; ibin++)\r
- {\r
- if (hist[ibin] > max_bin)\r
- {\r
- max_bin = hist[ibin];\r
- max_binindex = ibin;\r
- }\r
- }\r
- mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;\r
- }\r
-\r
- if (opt_auto == O_AUTO_FULL)\r
- {\r
- if (! opt_set_max)\r
- densmax = maxfound;\r
- if (! opt_set_min)\r
- densmin = minfound;\r
- }\r
- if (opt_stats || opt_auto != O_AUTO_FULL)\r
- {\r
- mean /= im->nx * im->ny;\r
- for (ix = 0; ix < im->nx; ix++)\r
- {\r
- for (iy = 0; iy < im->ny; iy++)\r
- {\r
- double diff = (im->v[ix][iy] - mean);\r
- stddev += diff * diff;\r
- }\r
- }\r
- stddev = sqrt(stddev / (im->nx * im->ny));\r
- if (opt_auto == O_AUTO_FULL)\r
- ;\r
- else if (opt_auto == O_AUTO_STD1)\r
- window = stddev;\r
- else if (opt_auto == O_AUTO_STD0_1)\r
- window = stddev * 0.1;\r
- else if (opt_auto == O_AUTO_STD0_5)\r
- window = stddev * 0.5;\r
- else if (opt_auto == O_AUTO_STD2)\r
- window = stddev * 2;\r
- else if (opt_auto == O_AUTO_STD3)\r
- window = stddev * 3;\r
- else\r
- {\r
- fprintf(stderr, "Internal Error: Invalid auto mode %d\n", opt_auto);\r
- return (1);\r
- }\r
- }\r
- if (opt_stats)\r
- {\r
- fprintf(stdout,"nx=%d\n", im->nx);\r
- fprintf(stdout,"ny=%d\n", im->ny);\r
- fprintf(stdout,"min=%f\n", minfound);\r
- fprintf(stdout,"max=%f\n", maxfound);\r
- fprintf(stdout,"mean=%f\n", mean);\r
- fprintf(stdout,"mode=%f\n", mode);\r
- fprintf(stdout,"stddev=%f\n", stddev);\r
- }\r
- if (opt_auto != O_AUTO_FULL)\r
- {\r
- double center;\r
-\r
- if (opt_center == O_CENTER_MODE)\r
- center = mode;\r
- else if (opt_center == O_CENTER_MEAN)\r
- center = mean;\r
- else\r
- {\r
- fprintf(stderr, "Internal Error: Invalid center mode %d\n", opt_center);\r
- return (1);\r
- }\r
- if (! opt_set_max)\r
- densmax = center + window;\r
- if (! opt_set_min)\r
- densmin = center - window;\r
- }\r
- }\r
-\r
- if (opt_stats)\r
- {\r
- fprintf(stdout,"min_disp=%f\n", densmin);\r
- fprintf(stdout,"max_disp=%f\n", densmax);\r
- }\r
- \r
- if (opt_format == O_FORMAT_PGM)\r
- sdf2d_to_pgm (im, out_file, opt_scale, opt_scale, densmin, densmax);\r
- else if (opt_format == O_FORMAT_PGMASC)\r
- sdf2d_to_pgmasc (im, out_file, opt_scale, opt_scale, densmin, densmax);\r
-#if HAVE_PNG\r
- else if (opt_format == O_FORMAT_PNG)\r
- sdf2d_to_png (im, out_file, 8, opt_scale, opt_scale, densmin, densmax);\r
- else if (opt_format == O_FORMAT_PNG16)\r
- sdf2d_to_png (im, out_file, 16, opt_scale, opt_scale, densmin, densmax);\r
-#endif\r
-#if HAVE_GIF\r
- else if (opt_format == O_FORMAT_GIF) \r
- sdf2d_to_gif (im, out_file, opt_scale, opt_scale, densmin, densmax);\r
-#endif\r
- else if (opt_format == O_FORMAT_DISP) {\r
-#if HAVE_SGP\r
- image_display_scale (im, opt_scale, densmin, densmax);\r
- cio_kb_getc();\r
- sgp2_close(sgp2_get_active_win());\r
-#endif\r
- }\r
- else\r
- {\r
- fprintf(stderr, "Internal Error: Invalid format mode %d\n", opt_format);\r
- return (1);\r
- }\r
- return (0);\r
-}\r
-\r
-\r
-void \r
-sdf2d_to_pgm (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax)\r
-{\r
- FILE *fp;\r
- int irow;\r
- unsigned char *rowp;\r
-\r
- rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img");\r
- if (rowp == NULL)\r
- return;\r
-\r
- if ((fp = fopen (outfile, "wb")) == NULL)\r
- return;\r
-\r
- fprintf(fp, "P5\n");\r
- fprintf(fp, "%d %d\n", im->nx, im->ny);\r
- fprintf(fp, "255\n");\r
-\r
- for (irow = im->ny - 1; irow >= 0; irow--)\r
- {\r
- int icol, ir;\r
-\r
- for (icol = 0; icol < im->nx; icol++)\r
- {\r
- double dens;\r
- int p;\r
- int pos = icol * nxcell;\r
- dens = (im->v[icol][irow] - densmin) / (densmax - densmin);\r
- if (dens < 0)\r
- dens = 0;\r
- else if (dens > 1)\r
- dens = 1;\r
- for (p = pos; p < pos + nxcell; p++)\r
- {\r
- rowp[p] = (unsigned int) (dens * 255.);\r
- }\r
- }\r
- for (ir = 0; ir < nycell; ir++)\r
- {\r
- int ic;\r
- for (ic = 0; ic < im->nx * nxcell; ic++) \r
- fprintf(fp, "%c ", rowp[ic]);\r
- }\r
- }\r
- sys_free(rowp, "sdf2img");\r
-\r
- fclose(fp);\r
-}\r
-\r
-void \r
-sdf2d_to_pgmasc (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax)\r
-{\r
- FILE *fp;\r
- int irow;\r
- unsigned char *rowp;\r
-\r
- rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img");\r
- if (rowp == NULL)\r
- return;\r
-\r
- if ((fp = fopen (outfile, "wb")) == NULL)\r
- return;\r
-\r
- fprintf(fp, "P2\n");\r
- fprintf(fp, "%d %d\n", im->nx, im->ny);\r
- fprintf(fp, "255\n");\r
-\r
- for (irow = im->ny - 1; irow >= 0; irow--)\r
- {\r
- int icol, ir;\r
-\r
- for (icol = 0; icol < im->nx; icol++)\r
- {\r
- double dens;\r
- int p;\r
- int pos = icol * nxcell;\r
- dens = (im->v[icol][irow] - densmin) / (densmax - densmin);\r
- if (dens < 0)\r
- dens = 0;\r
- else if (dens > 1)\r
- dens = 1;\r
- for (p = pos; p < pos + nxcell; p++)\r
- {\r
- rowp[p] = (unsigned int) (dens * 255.);\r
- }\r
- }\r
- for (ir = 0; ir < nycell; ir++)\r
- {\r
- int ic;\r
- for (ic = 0; ic < im->nx * nxcell; ic++) \r
- fprintf(fp, "%d ", rowp[ic]);\r
- fprintf(fp, "\n");\r
- }\r
- }\r
- sys_free(rowp, "sdf2img");\r
-\r
- fclose(fp);\r
-}\r
-\r
-\r
-#ifdef HAVE_PNG\r
-void \r
-sdf2d_to_png (IMAGE *im, char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax)\r
-{\r
- FILE *fp;\r
- png_structp png_ptr;\r
- png_infop info_ptr;\r
- int irow;\r
- unsigned char *rowp;\r
- double max_out_level = (1 << bitdepth) - 1;\r
-\r
- rowp = (unsigned char *) sys_alloc(im->nx * nxcell * (bitdepth / 8),"sdf2d_to_img");\r
- if (rowp == NULL)\r
- return;\r
-\r
- if ((fp = fopen (outfile, "wb")) == NULL)\r
- return;\r
-\r
- png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\r
- if (! png_ptr)\r
- return;\r
-\r
- info_ptr = png_create_info_struct(png_ptr);\r
- if (! info_ptr)\r
- {\r
- png_destroy_write_struct(&png_ptr, (png_infopp) NULL);\r
- fclose(fp);\r
- return;\r
- }\r
-\r
- if (setjmp(png_ptr->jmpbuf))\r
- {\r
- png_destroy_write_struct(&png_ptr, &info_ptr);\r
- fclose(fp);\r
- return;\r
- }\r
-\r
- png_init_io(png_ptr, fp);\r
-\r
- 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);\r
-\r
- png_write_info(png_ptr, info_ptr);\r
- for (irow = im->ny - 1; irow >= 0; irow--)\r
- {\r
- png_bytep row_pointer = rowp;\r
- int icol, ir;\r
-\r
- for (icol = 0; icol < im->nx; icol++)\r
- {\r
- double dens;\r
- int p;\r
- unsigned int outval;\r
- int pos = icol * nxcell;\r
- dens = (im->v[icol][irow] - densmin) / (densmax - densmin);\r
- if (dens < 0)\r
- dens = 0;\r
- else if (dens > 1)\r
- dens = 1;\r
- outval = dens * max_out_level;\r
- for (p = pos; p < pos + nxcell; p++)\r
- {\r
- if (bitdepth == 8)\r
- rowp[p] = outval;\r
- else {\r
- int rowpos = p * 2;\r
- rowp[rowpos] = (outval >> 8) & 0xFF;\r
- rowp[rowpos+1] = (outval & 0xFF);\r
- }\r
- }\r
- }\r
- for (ir = 0; ir < nycell; ir++)\r
- {\r
- png_write_rows (png_ptr, &row_pointer, 1);\r
- }\r
- }\r
- sys_free(rowp, "sdf2img");\r
-\r
- png_write_end(png_ptr, info_ptr);\r
- png_destroy_write_struct(&png_ptr, &info_ptr);\r
-\r
- fclose(fp);\r
-}\r
-#endif\r
-\r
-#ifdef HAVE_GD\r
-#include "gd.h"\r
-#define N_GRAYSCALE 256\r
-#endif\r
-\r
-void\r
-sdf2d_to_gif (IMAGE *im, char *outfile, int nxcell, int nycell, double densmin, double densmax)\r
-{\r
-#ifdef HAVE_GD\r
- gdImagePtr gif;\r
- FILE *out;\r
- int gs_indices[N_GRAYSCALE];\r
- int i;\r
- int irow;\r
- int lastrow;\r
- unsigned char *rowp;\r
-\r
- rowp = (unsigned char *) sys_alloc(im->nx * nxcell,"sdf2d_to_img");\r
- if (rowp == NULL)\r
- return;\r
-\r
- gif = gdImageCreate(im->nx * nxcell, im->ny * nycell);\r
- for (i = 0; i < N_GRAYSCALE; i++)\r
- gs_indices[i] = gdImageColorAllocate(gif, i, i, i);\r
-\r
- lastrow = im->ny * nycell - 1;\r
- for (irow = 0; irow < im->ny; irow++)\r
- {\r
- int icol, ir;\r
- int rpos = irow * nycell;\r
- for (ir = rpos; ir < rpos + nycell; ir++)\r
- {\r
- for (icol = 0; icol < im->nx; icol++)\r
- {\r
- double dens;\r
- int ic;\r
- int cpos = icol * nxcell;\r
- dens = (im->v[icol][irow] - densmin) / (densmax - densmin);\r
- if (dens < 0)\r
- dens = 0;\r
- else if (dens > 1)\r
- dens = 1;\r
- for (ic = cpos; ic < cpos + nxcell; ic++)\r
- {\r
- rowp[ic] = (unsigned int) (dens * (double) (N_GRAYSCALE - 1));\r
- gdImageSetPixel(gif, ic, lastrow - ir, gs_indices[rowp[ic]]);\r
- }\r
- }\r
- }\r
- }\r
- sys_free(rowp, "sdf2img");\r
-\r
- if ((out = fopen(outfile,"w")) == NULL)\r
- {\r
- fprintf(stderr,"Error opening output file %s for writing\n", outfile);\r
- exit(1);\r
- }\r
- gdImageGif(gif,out);\r
- fclose(out);\r
- gdImageDestroy(gif);\r
-#else\r
- fprintf(stderr, "This version does not support GIF");\r
-#endif\r
-}\r
-\r
-#ifndef NO_MAIN\r
-int \r
-main (int argc, char *const argv[])\r
-{\r
- return (sdf2img_main(argc, argv));\r
-}\r
-#endif\r
+++ /dev/null
-/*****************************************************************************
-** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: sdfinfo.c,v 1.3 2000/05/16 04:33:59 kevin Exp $
-** $Log: sdfinfo.c,v $
-** 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