| 1 |
/***************************************************************************** |
| 2 |
** FILE IDENTIFICATION |
| 3 |
** |
| 4 |
** Name: pj2if.cpp |
| 5 |
** Purpose: Convert an projection data file to an image file |
| 6 |
** Programmer: Kevin Rosenberg |
| 7 |
** Date Started: April 2000 |
| 8 |
** |
| 9 |
** This is part of the CTSim program |
| 10 |
** Copyright (C) 1983-2009 Kevin Rosenberg |
| 11 |
** |
| 12 |
** This program is free software; you can redistribute it and/or modify |
| 13 |
** it under the terms of the GNU General Public License (version 2) as |
| 14 |
** published by the Free Software Foundation. |
| 15 |
** |
| 16 |
** This program is distributed in the hope that it will be useful, |
| 17 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
** GNU General Public License for more details. |
| 20 |
** |
| 21 |
** You should have received a copy of the GNU General Public License |
| 22 |
** along with this program; if not, write to the Free Software |
| 23 |
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
******************************************************************************/ |
| 25 |
|
| 26 |
/* FILE |
| 27 |
* pj2if.c Convert Raysum to image |
| 28 |
* |
| 29 |
* DATE |
| 30 |
* Apr 1999 |
| 31 |
*/ |
| 32 |
|
| 33 |
#include "ct.h" |
| 34 |
#include "timer.h" |
| 35 |
|
| 36 |
|
| 37 |
enum { O_VERBOSE, O_HELP, O_VERSION, O_POLAR }; |
| 38 |
|
| 39 |
static struct option my_options[] = |
| 40 |
{ |
| 41 |
{"polar", 0, 0, O_POLAR}, |
| 42 |
{"verbose", 0, 0, O_VERBOSE}, |
| 43 |
{"help", 0, 0, O_HELP}, |
| 44 |
{"version", 0, 0, O_VERSION}, |
| 45 |
{0, 0, 0, 0} |
| 46 |
}; |
| 47 |
|
| 48 |
static const char* g_szIdStr = "$Id$"; |
| 49 |
|
| 50 |
void |
| 51 |
pj2if_usage (const char *program) |
| 52 |
{ |
| 53 |
std::cout << "usage: " << fileBasename(program) << " in-proj-file out-if-file [OPTIONS]\n"; |
| 54 |
std::cout << "Converts a projection file to a imagefile\n"; |
| 55 |
std::cout << std::endl; |
| 56 |
std::cout << " --polar Convert to polar format\n"; |
| 57 |
std::cout << " --verbose Verbose mode\n"; |
| 58 |
std::cout << " --version Print version\n"; |
| 59 |
std::cout << " --help Print this help message\n"; |
| 60 |
} |
| 61 |
|
| 62 |
int |
| 63 |
pj2if_main (const int argc, char *const argv[]) |
| 64 |
{ |
| 65 |
char *pj_name, *im_name; |
| 66 |
bool optVerbose = false; |
| 67 |
extern int optind; |
| 68 |
Timer timerProgram; |
| 69 |
|
| 70 |
while (1) |
| 71 |
{ |
| 72 |
int c = getopt_long (argc, argv, "", my_options, NULL); |
| 73 |
if (c == -1) |
| 74 |
break; |
| 75 |
|
| 76 |
switch (c) |
| 77 |
{ |
| 78 |
case O_VERBOSE: |
| 79 |
optVerbose = true; |
| 80 |
break; |
| 81 |
case O_VERSION: |
| 82 |
#ifdef VERSION |
| 83 |
std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl; |
| 84 |
#else |
| 85 |
std::cout << "Unknown version number\n"; |
| 86 |
#endif |
| 87 |
return (0); |
| 88 |
case O_HELP: |
| 89 |
case '?': |
| 90 |
pj2if_usage(argv[0]); |
| 91 |
return (0); |
| 92 |
default: |
| 93 |
pj2if_usage(argv[0]); |
| 94 |
return (1); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
if (argc - optind != 2) { |
| 99 |
pj2if_usage(argv[0]); |
| 100 |
return (1); |
| 101 |
} |
| 102 |
|
| 103 |
pj_name = argv[optind]; |
| 104 |
im_name = argv[optind + 1]; |
| 105 |
|
| 106 |
Projections pj; |
| 107 |
if (! pj.read (pj_name)) { |
| 108 |
sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name); |
| 109 |
return (1); |
| 110 |
} |
| 111 |
|
| 112 |
if (optVerbose) { |
| 113 |
std::ostringstream os; |
| 114 |
pj.printScanInfo (os); |
| 115 |
std::cout << os.str(); |
| 116 |
} |
| 117 |
|
| 118 |
ImageFile im (pj.nDet(), pj.nView()); |
| 119 |
|
| 120 |
ImageFileArray v = im.getArray(); |
| 121 |
|
| 122 |
for (int iy = 0; iy < pj.nView(); iy++) { |
| 123 |
const DetectorArray& detarray = pj.getDetectorArray (pj.nView() - iy - 1); |
| 124 |
const DetectorValue* detval = detarray.detValues(); |
| 125 |
for (int ix = 0; ix < pj.nDet(); ix++) { |
| 126 |
v[ix][iy] = detval[ix]; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
im.labelAdd (pj.getLabel()); |
| 131 |
im.labelAdd (Array2dFileLabel::L_HISTORY, "Conversion from .pj to .if", timerProgram.timerEnd()); |
| 132 |
im.fileWrite (im_name); |
| 133 |
|
| 134 |
return(0); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
#ifndef NO_MAIN |
| 139 |
int |
| 140 |
main (const int argc, char *const argv[]) |
| 141 |
{ |
| 142 |
int retval = 1; |
| 143 |
|
| 144 |
try { |
| 145 |
retval = pj2if_main(argc, argv); |
| 146 |
} catch (exception e) { |
| 147 |
std::cerr << "Exception: " << e.what() << std::endl; |
| 148 |
} catch (...) { |
| 149 |
std::cerr << "Unknown exception\n"; |
| 150 |
} |
| 151 |
|
| 152 |
return (retval); |
| 153 |
} |
| 154 |
#endif |