r1018: *** empty log message ***
[ctsim.git] / tools / pjHinterp.cpp
1 /*****************************************************************************
2 * ** FILE IDENTIFICATION
3 * **
4 * **   Name:          phm2helix.cpp
5 * **   Purpose:       Take projections of a phantom object
6 * **   Programmer:    Ian Kay
7 * **   Date Started:  Aug 2001
8 * **
9 * **  This is part of the CTSim program
10 * **  Copyright (C) 1983-2000 Kevin Rosenberg
11 * **
12 * **  $Id: pjHinterp.cpp,v 1.1 2001/09/24 09:40:42 kevin Exp $
13 * **
14 * **  This program is free software; you can redistribute it and/or modify
15 * **  it under the terms of the GNU General Public License (version 2) as
16 * **  published by the Free Software Foundation.
17 * **
18 * **  This program is distributed in the hope that it will be useful,
19 * **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * **  GNU General Public License for more details.
22 * **
23 * **  You should have received a copy of the GNU General Public License
24 * **  along with this program; if not, write to the Free Software
25 * **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
26 * ******************************************************************************/
27
28 #include "ct.h"
29 #include "timer.h"
30
31
32 enum { O_INTERPVIEW, O_VERBOSE, O_TRACE, O_HELP, O_DEBUG, O_VERSION};
33
34
35 static struct option my_options[] =
36 {
37         {"interpview", 1, 0, O_INTERPVIEW},
38         {"trace", 1, 0, O_TRACE},
39         {"debug", 0, 0, O_DEBUG},
40         {"verbose", 0, 0, O_VERBOSE},
41         {"help", 0, 0, O_HELP},
42         {"version", 0, 0, O_VERSION},
43         {0, 0, 0, 0}
44 };
45
46 static const char* g_szIdStr = "$Id: pjHinterp.cpp,v 1.1 2001/09/24 09:40:42 kevin Exp $";
47
48 void pjHinterp_usage ( const char *program )
49 {
50         std::cout << "usage: " << fileBasename(program) << " raysum-file interp-raysum-file [OPTIONS]" << std::endl;
51         std::cout << "Interpolation of helical data in raw data space" << std::endl;
52         std::cout << "  raysum-file    Input raysum file" << std::endl;
53     std::cout << "  interp-file    Output interpolated raysum file " << std::endl;
54         std::cout << "  --trace        Set tracing to level" << std::endl;
55         std::cout << "     none        No tracing (default)" << std::endl;
56         std::cout << "     console     Text level tracing" << std::endl;
57         std::cout << "     phantom     Trace phantom" << std::endl;
58         std::cout << "     proj        Trace allrays" << std::endl;
59         std::cout << "     plot        Trace plotting" << std::endl;
60         std::cout << "     clipping    Trace clipping" << std::endl;
61         std::cout << "  --verbose      Turn on verbose mode" << std::endl;
62         std::cout << "  --debug        Turn on debug mode" << std::endl;
63         std::cout << "  --version      Print version" << std::endl;
64         std::cout << "  --help         Print this help message" << std::endl;
65 }
66
67
68 int
69 pjHinterp_main(int argc, char * const argv[])
70 {
71         Projections projGlobal;
72         char* pszProjFilename = NULL;
73         char* pszInterpFilename = NULL;
74         bool bOptVerbose = false;
75         bool bOptDebug = 1;
76         int optTrace = Trace::TRACE_NONE;
77         char *endptr = NULL;
78         char *endstr; 
79         int opt_interpview=-1;
80
81         while (1) {
82                 int c = getopt_long(argc, argv, "", my_options, NULL);
83
84                 if (c == -1)
85                  break;
86
87                 switch (c) {
88                 case O_INTERPVIEW:
89                         opt_interpview = strtol(optarg, &endptr, 10);
90                         endstr = optarg + strlen(optarg);
91                         if (endptr != endstr) { 
92                                 std::cerr << "Error setting --interpview to %s" << optarg << std::endl;
93                                 pjHinterp_usage(argv[0]);
94                                 return(1);
95                         }
96                         break;
97                 case O_VERBOSE:
98                         bOptVerbose = true;
99                         break;
100                 case O_DEBUG:
101                         bOptDebug = true;
102                         break;
103                 case O_TRACE:
104                         if ((optTrace = Trace::convertTraceNameToID(optarg)) 
105                                                         == Trace::TRACE_INVALID) {
106                                 pjHinterp_usage(argv[0]);
107                                 return (1);
108                         }
109                         break;
110                 case O_VERSION:
111 #ifdef VERSION
112                         std::cout <<  "Version " <<  VERSION << std::endl << 
113                                                                                                 g_szIdStr << std::endl;
114 #else
115                         std::cout << "Unknown version number" << std::endl;
116 #endif
117                         return (0);
118
119                 case O_HELP:
120                 case '?':      
121                         pjHinterp_usage(argv[0]);
122                         return (0);
123                 default:
124                         pjHinterp_usage(argv[0]);
125                         return (1);
126                 } // end switch
127         } // end while
128
129     if (optind + 2 != argc) {
130       pjHinterp_usage(argv[0]);
131       return (1);
132     }
133
134     pszProjFilename = argv[optind];
135
136     pszInterpFilename = argv[optind + 1];
137
138         Projections projections;
139         if ( projections.read(pszProjFilename) != true ){ 
140                         std::cerr << "Error reading input file " << pszProjFilename << std::endl;       
141                         return (1);
142         }
143         if (bOptVerbose) { 
144                         ostringstream os;
145                         projections.printScanInfo(os);
146                         std::cout << os.str();
147         }
148
149         int status = projections.Helical180LI(opt_interpview);
150         if ( status != 0 )  return (1);
151         status = projections.HalfScanFeather();
152         if ( status != 0 )  return (1);
153         projections.write( pszInterpFilename  );
154         
155         return (0);
156 }
157
158
159 #ifndef NO_MAIN
160 int
161 main (int argc, char* argv[])
162 {
163   int retval = 1;
164
165   try {
166     retval = pjHinterp_main(argc, argv);
167   } catch (exception e) {
168       std::cerr << "Exception: " << e.what() << std::endl;
169   } catch (...) {
170       std::cerr << "Unknown exception" << std::endl;
171   }
172
173   return (retval);
174 }
175 #endif