X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=tools%2Flinogram.cpp;h=fe9a0f674b83d7830e2048aa3242ba20bd9184df;hp=a244c0d9477015b5978d89b16f84b0d0fa72b91d;hb=e89023477e02d9332f87cab5a7975407625dbd60;hpb=fad03eb65e23652bb5ff46335d011413cccf03d5 diff --git a/tools/linogram.cpp b/tools/linogram.cpp index a244c0d..fe9a0f6 100644 --- a/tools/linogram.cpp +++ b/tools/linogram.cpp @@ -7,9 +7,7 @@ ** Date Started: April 2003 ** ** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: linogram.cpp,v 1.1 2003/04/01 18:34:42 kevin Exp $ +** Copyright (C) 1983-2009 Kevin Rosenberg ** ** 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 @@ -27,100 +25,163 @@ #include "ct.h" -enum { O_LABELS,, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG }; +enum { O_XY, O_POLAR_RT, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG }; static struct option my_options[] = { - {"debug", 0, 0, O_DEBUG}, + {"xy", 0, 0, O_XY}, + {"polar-rt", 0, 0, O_POLAR_RT}, + {"debug", 0, 0, O_DEBUG}, {"verbose", 0, 0, O_VERBOSE}, {"help", 0, 0, O_HELP}, {"version", 0, 0, O_VERSION}, {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: linogram.cpp,v 1.1 2003/04/01 18:34:42 kevin Exp $"; +static const char* g_szIdStr = "$Id$"; -void +void linogram_usage (const char *program) { std::cout << "usage: " << fileBasename(program) << " n d [OPTIONS]\n"; std::cout << "Imagefile information\n"; std::cout << std::endl; - std::cout << " infile Name of input IF file\n"; - std::cout << " --debug Debug mode\n"; + std::cout << " n Linogram N\n"; + std::cout << " d Max detector spacing\n"; + std::cout << " --xy Output x,y pairs\n"; + std::cout << " --polar-rt Output r,t pairs\n"; + std::cout << " --debug Debug mode\n"; std::cout << " --verbose Verbose mode\n"; std::cout << " --version Print version\n"; std::cout << " --help Print this help message\n"; } -int +int linogram_main (int argc, char *const argv[]) { - std::string in_n; + int opt_polar_rt = 0; + int opt_xy = 0; int opt_verbose = 0; int opt_debug = 0; - + UNUSED(opt_verbose); + UNUSED(opt_debug); + while (1) { int c = getopt_long (argc, argv, "", my_options, NULL); - + if (c == -1) - break; - + break; + switch (c) - { - case O_VERBOSE: - opt_verbose = 1; - break; - case O_DEBUG: - opt_debug = 0; - break; + { + case O_XY: + opt_xy = 1; + break; + case O_POLAR_RT: + opt_polar_rt = 1; + break; + case O_VERBOSE: + opt_verbose = 1; + break; + case O_DEBUG: + opt_debug = 0; + break; case O_VERSION: #ifdef VERSION - std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; + std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; #else std::cout << "Unknown version number\n"; #endif - return (0); - case O_HELP: - case '?': - linogram_usage(argv[0]); - return (0); - default: - linogram_usage(argv[0]); - return (1); - } + return (0); + case O_HELP: + case '?': + linogram_usage(argv[0]); + return (0); + default: + linogram_usage(argv[0]); + return (1); + } } if (optind + 2 != argc) { linogram_usage (argv[0]); return (1); } - - in_n = argv[optind]; - in_d = argv[optind+1]; + + const char* in_n = argv[optind]; + const char* in_d = argv[optind+1]; int n = atol (in_n); - double n = atof (in_d); - int size = 2 * (2 * n - 1) + 1; - double divisor = 4 * n + 3; - - for (int itheta = 0; itheta < size; itheta++) { - double theta = atan (2 * itheta / division); - printf ("%lf: ", theta); - double step = d * cos(theta); - for (int id = 0; id < size; id++) { - printf ("%lf ", id * step); + double d = atof (in_d); + int size = 4 * n + 3; + int max = 2 * n + 1; + int min = -max; + double theta_base = PI/4; + // theta_base = 0; + + double theta_vec [size]; + for (int i = 0; i < size; i++) { + int m = i - (2 * n + 1); + theta_vec[i] = atan (static_cast(2 * m) / size); + } + + if (opt_xy) { + int m; + for (m = 0; m < size; m++) { + double step = d * cos(theta_vec[m]); + for (int id = min; id <= max; id++) { + double r = id * step; + double x = r * cos(theta_vec[m] + theta_base); + double y = r * sin(theta_vec[m] + theta_base); + printf ("%lf,%lf ", x, y); + } + printf ("\n"); + } + + for (m = 0; m < size; m++) { + double step = d * cos(theta_vec[m]); + for (int id = min; id <= max; id++) { + double r = id * step; + double x = r * cos(theta_vec[m] + PI/2 + theta_base); + double y = r * sin(theta_vec[m] + PI/2 + theta_base); + printf ("%lf,%lf ", x, y); + } + printf ("\n"); + } + } else { + int m; + for (m = 0; m < size; m++) { + if (! opt_polar_rt) + printf ("%lf: ", theta_vec[m] + theta_base); + double step = d * cos(theta_vec[m]); + for (int id = min; id <= max; id++) { + if (opt_polar_rt) + printf ("%lf,", theta_vec[m] + theta_base); + printf ("%lf ", id * step); + } + printf ("\n"); + } + + for (m = 0; m < size; m++) { + if (! opt_polar_rt) + printf ("%lf: ", theta_vec[m] + PI/2 + theta_base); + double step = d * cos(theta_vec[m]); + for (int id = min; id <= max; id++) { + if (opt_polar_rt) + printf ("%lf,", theta_vec[m] + PI/2 + theta_base); + printf ("%lf ", id * step); + } + printf ("\n"); } - printf ("\n"); } - + return (0); } #ifndef NO_MAIN -int +int main (int argc, char *const argv[]) { int retval = 1; @@ -128,9 +189,9 @@ main (int argc, char *const argv[]) try { retval = linogram_main(argc, argv); } catch (exception e) { - std::cerr << "Exception: " << e.what() << std::endl; + std::cerr << "Exception: " << e.what() << std::endl; } catch (...) { - std::cerr << "Unknown exception\n"; + std::cerr << "Unknown exception\n"; } return (retval);