| 1 |
/***************************************************************************** |
| 2 |
** FILE IDENTIFICATION |
| 3 |
** |
| 4 |
** Name: pjHinterp.cpp |
| 5 |
** Purpose: Interpolate helical data in projection space |
| 6 |
** Programmer: Ian Kay and Kevin Rosenberg |
| 7 |
** Date Started: Aug 2001 |
| 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 |
#include "ct.h" |
| 27 |
#include "timer.h" |
| 28 |
|
| 29 |
|
| 30 |
enum { O_INTERPVIEW, O_VERBOSE, O_TRACE, O_HELP, O_DEBUG, O_VERSION}; |
| 31 |
|
| 32 |
static struct option my_options[] = |
| 33 |
{ |
| 34 |
{"interpview", 1, 0, O_INTERPVIEW}, |
| 35 |
{"trace", 1, 0, O_TRACE}, |
| 36 |
{"debug", 0, 0, O_DEBUG}, |
| 37 |
{"verbose", 0, 0, O_VERBOSE}, |
| 38 |
{"help", 0, 0, O_HELP}, |
| 39 |
{"version", 0, 0, O_VERSION}, |
| 40 |
{0, 0, 0, 0} |
| 41 |
}; |
| 42 |
|
| 43 |
static const char* g_szIdStr = "$Id$"; |
| 44 |
|
| 45 |
void pjHinterp_usage ( const char *program ) |
| 46 |
{ |
| 47 |
std::cout << "usage: " << fileBasename(program) << " projection-file interp-projection-file [OPTIONS]" << std::endl; |
| 48 |
std::cout << "Interpolation of helical data in raw data space" << std::endl; |
| 49 |
std::cout << " projection-file Input projection file" << std::endl; |
| 50 |
std::cout << " interp-file Output interpolated projection file " << std::endl; |
| 51 |
std::cout << " --trace Set tracing to level" << std::endl; |
| 52 |
std::cout << " none No tracing (default)" << std::endl; |
| 53 |
std::cout << " console Text level tracing" << std::endl; |
| 54 |
std::cout << " --verbose Turn on verbose mode" << std::endl; |
| 55 |
std::cout << " --debug Turn on debug mode" << std::endl; |
| 56 |
std::cout << " --version Print version" << std::endl; |
| 57 |
std::cout << " --help Print this help message" << std::endl; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
int |
| 62 |
pjHinterp_main(int argc, char * const argv[]) |
| 63 |
{ |
| 64 |
Projections projGlobal; |
| 65 |
char* pszProjFilename = NULL; |
| 66 |
char* pszInterpFilename = NULL; |
| 67 |
bool bOptVerbose = false; |
| 68 |
bool bOptDebug = false; |
| 69 |
int optTrace = Trace::TRACE_NONE; |
| 70 |
char *endptr = NULL; |
| 71 |
char *endstr; |
| 72 |
int opt_interpview=-1; |
| 73 |
UNUSED(bOptDebug); |
| 74 |
|
| 75 |
while (1) { |
| 76 |
int c = getopt_long(argc, argv, "", my_options, NULL); |
| 77 |
|
| 78 |
if (c == -1) |
| 79 |
break; |
| 80 |
|
| 81 |
switch (c) { |
| 82 |
case O_INTERPVIEW: |
| 83 |
opt_interpview = strtol(optarg, &endptr, 10); |
| 84 |
endstr = optarg + strlen(optarg); |
| 85 |
if (endptr != endstr) { |
| 86 |
std::cerr << "Error setting --interpview to %s" << optarg << std::endl; |
| 87 |
pjHinterp_usage(argv[0]); |
| 88 |
return(1); |
| 89 |
} |
| 90 |
break; |
| 91 |
case O_VERBOSE: |
| 92 |
bOptVerbose = true; |
| 93 |
break; |
| 94 |
case O_DEBUG: |
| 95 |
bOptDebug = true; |
| 96 |
break; |
| 97 |
case O_TRACE: |
| 98 |
if ((optTrace = Trace::convertTraceNameToID(optarg)) |
| 99 |
== Trace::TRACE_INVALID) { |
| 100 |
pjHinterp_usage(argv[0]); |
| 101 |
return (1); |
| 102 |
} |
| 103 |
break; |
| 104 |
case O_VERSION: |
| 105 |
#ifdef VERSION |
| 106 |
std::cout << "Version " << VERSION << std::endl << |
| 107 |
g_szIdStr << std::endl; |
| 108 |
#else |
| 109 |
std::cout << "Unknown version number" << std::endl; |
| 110 |
#endif |
| 111 |
return (0); |
| 112 |
|
| 113 |
case O_HELP: |
| 114 |
case '?': |
| 115 |
pjHinterp_usage(argv[0]); |
| 116 |
return (0); |
| 117 |
default: |
| 118 |
pjHinterp_usage(argv[0]); |
| 119 |
return (1); |
| 120 |
} // end switch |
| 121 |
} // end while |
| 122 |
|
| 123 |
if (optind + 2 != argc) { |
| 124 |
pjHinterp_usage(argv[0]); |
| 125 |
return (1); |
| 126 |
} |
| 127 |
|
| 128 |
pszProjFilename = argv[optind]; |
| 129 |
|
| 130 |
pszInterpFilename = argv[optind + 1]; |
| 131 |
|
| 132 |
Projections projections; |
| 133 |
if ( projections.read(pszProjFilename) != true ){ |
| 134 |
std::cerr << "Error reading input file " << pszProjFilename << std::endl; |
| 135 |
return (1); |
| 136 |
} |
| 137 |
if (bOptVerbose) { |
| 138 |
std::ostringstream os; |
| 139 |
projections.printScanInfo(os); |
| 140 |
std::cout << os.str(); |
| 141 |
} |
| 142 |
|
| 143 |
int status = projections.Helical180LI(opt_interpview); |
| 144 |
if ( status != 0 ) return (1); |
| 145 |
status = projections.HalfScanFeather(); |
| 146 |
if ( status != 0 ) return (1); |
| 147 |
projections.write( pszInterpFilename ); |
| 148 |
|
| 149 |
return (0); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
#ifndef NO_MAIN |
| 154 |
int |
| 155 |
main (int argc, char* argv[]) |
| 156 |
{ |
| 157 |
int retval = 1; |
| 158 |
|
| 159 |
try { |
| 160 |
retval = pjHinterp_main(argc, argv); |
| 161 |
} catch (exception e) { |
| 162 |
std::cerr << "Exception: " << e.what() << std::endl; |
| 163 |
} catch (...) { |
| 164 |
std::cerr << "Unknown exception" << std::endl; |
| 165 |
} |
| 166 |
|
| 167 |
return (retval); |
| 168 |
} |
| 169 |
#endif |