r123: *** empty log message ***
[ctsim.git] / src / pj2if.cpp
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-2000 Kevin Rosenberg
11 **
12 **  $Id: pj2if.cpp,v 1.6 2000/06/28 15:25:34 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 /* FILE
29  *   pj2if.c                    Convert Raysum to image
30  *
31  * DATE
32  *   Apr 1999
33  */
34
35 #include "ct.h"
36 #include "timer.h"
37
38
39 enum { O_VERBOSE, O_HELP, O_VERSION };
40
41 static struct option my_options[] =
42 {
43   {"verbose", 0, 0, O_VERBOSE},
44   {"help", 0, 0, O_HELP},
45   {"version", 0, 0, O_VERSION},
46   {0, 0, 0, 0}
47 };
48
49
50 void 
51 pj2if_usage (const char *program)
52 {
53   cout << "usage: " << fileBasename(program) << " in-proj-file out-if-file [OPTIONS]" << endl;
54   cout << "Converts a projection file to a IF file" << endl;
55   cout << endl;
56   cout << "   --verbose   Verbose mode" << endl;
57   cout << "   --version   Print version" << endl;
58   cout << "   --help      Print this help message" << endl;
59 }
60
61           
62
63 int 
64 pj2if_main (const int argc, char *const argv[])
65 {
66   char *pj_name, *im_name;
67   bool optVerbose = false;
68   extern int optind;
69   Timer timerProgram;
70
71   while (1)
72     {
73       int c = getopt_long (argc, argv, "", my_options, NULL);
74       if (c == -1)
75         break;
76       
77       switch (c)
78         {
79         case O_VERBOSE:
80           optVerbose = true;
81           break;
82         case O_VERSION:
83 #ifdef VERSION
84           cout << "Version " << VERSION << endl;
85 #else
86           cout << "Unknown version number" << endl;
87 #endif
88           return (0);
89         case O_HELP:
90         case '?':
91           pj2if_usage(argv[0]);
92           return (0);
93         default:
94           pj2if_usage(argv[0]);
95           return (1);
96         }
97     }
98   
99   if (argc - optind != 2) {
100     pj2if_usage(argv[0]);
101     return (1);
102   }
103
104   pj_name = argv[optind];
105   im_name = argv[optind + 1];
106
107   Projections pj;
108   if (! pj.read (pj_name)) {
109     sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name);
110     return (1);
111   }
112
113   if (optVerbose)
114       pj.printScanInfo();
115   
116   ImageFile im (pj.nDet(), pj.nView());
117   
118   ImageFileArray v = im.getArray();
119
120   for (int iy = 0; iy < pj.nView(); iy++)
121     {
122       DetectorArray& detarray = pj.getDetectorArray (iy);
123       const DetectorValue* detval = detarray.detValues();
124       for (int ix = 0; ix < pj.nDet(); ix++)
125         {
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     cerr << "Exception: " << e.what() << endl;
148   } catch (...) {
149     cerr << "Unknown exception" << endl;
150   }
151
152   return (retval);
153 }
154 #endif