Debian Codegraph @

tools/pjinfo.cpp

raw
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 ** Name: pjinfo.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 * pjinfo.c Convert Raysum to image
28 *
29 * DATE
30 * August 2000
31 */
32
33 #include "ct.h"
34 #include "timer.h"
35
36
37 enum { O_BINARYHEADER, O_BINARYVIEWS, O_STARTVIEW, O_ENDVIEW, O_DUMP, O_HELP, O_VERSION };
38
39 static struct option my_options[] =
40 {
41 {"binaryheader", 0, 0, O_BINARYHEADER},
42 {"binaryviews", 0, 0, O_BINARYVIEWS},
43 {"startview", 1, 0, O_STARTVIEW},
44 {"endview", 1, 0, O_ENDVIEW},
45 {"dump", 0, 0, O_DUMP},
46 {"help", 0, 0, O_HELP},
47 {"version", 0, 0, O_VERSION},
48 {0, 0, 0, 0}
49 };
50
51 static const char* g_szIdStr = "$Id$";
52
53 void
54 pjinfo_usage (const char *program)
55 {
56 std::cout << "usage: " << fileBasename(program) << " proj-file [OPTIONS]\n";
57 std::cout << "Display projection file information\n";
58 std::cout << "\n";
59 std::cout << " --binaryheader Dump binary header data\n";
60 std::cout << " --binaryviews Dump binary view data\n";
61 std::cout << " --startview n Beginning view number to display (default=0)\n";
62 std::cout << " --endview n Ending view number to display (default=last view)\n";
63 std::cout << " --dump Print all scan data ASCII format\n";
64 std::cout << " --version Print version\n";
65 std::cout << " --help Print this help message\n";
66 }
67
68
69
70 int
71 pjinfo_main (const int argc, char *const argv[])
72 {
73 std::string pj_name;
74 bool optDump = false;
75 bool optBinaryHeader = false;
76 bool optBinaryViews = false;
77 int optStartView = 0;
78 int optEndView = -1; // tells copyViewData to use default last view
79 extern int optind;
80
81 while (1)
82 {
83 char *endptr, *endstr;
84 int c = getopt_long (argc, argv, "", my_options, NULL);
85 if (c == -1)
86 break;
87
88 switch (c)
89 {
90 case O_DUMP:
91 optDump = true;
92 break;
93 case O_BINARYHEADER:
94 optBinaryHeader = true;
95 break;
96 case O_BINARYVIEWS:
97 optBinaryViews = true;
98 break;
99 case O_STARTVIEW:
100 optStartView = strtol(optarg, &endptr, 10);
101 endstr = optarg + strlen(optarg);
102 if (endptr != endstr) {
103 std::cerr << "Error setting --startview to %s" << optarg << std::endl;
104 pjinfo_usage(argv[0]);
105 return (1);
106 }
107 break;
108 case O_ENDVIEW:
109 optEndView = strtol(optarg, &endptr, 10);
110 endstr = optarg + strlen(optarg);
111 if (endptr != endstr) {
112 std::cerr << "Error setting --endview to %s" << optarg << std::endl;
113 pjinfo_usage(argv[0]);
114 return (1);
115 }
116 break;
117 case O_VERSION:
118 #ifdef VERSION
119 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
120 #else
121 std::cout << "Unknown version number\n";
122 #endif
123 return (0);
124 case O_HELP:
125 case '?':
126 pjinfo_usage(argv[0]);
127 return (0);
128 default:
129 pjinfo_usage(argv[0]);
130 return (1);
131 }
132 }
133
134 if (argc - optind != 1) {
135 pjinfo_usage(argv[0]);
136 return (1);
137 }
138
139 pj_name = argv[optind];
140
141 if (optBinaryHeader)
142 Projections::copyHeader (pj_name, std::cout);
143 else if (optBinaryViews)
144 Projections::copyViewData (pj_name, std::cout, optStartView, optEndView);
145 else {
146 Projections pj;
147 if (! pj.read (pj_name)) {
148 sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str());
149 return (1);
150 }
151
152 if (optDump) {
153 pj.printProjectionData (optStartView, optEndView);
154 } else {
155 std::ostringstream os;
156 pj.printScanInfo (os);
157 std::cout << os.str();
158 }
159 }
160
161 return(0);
162 }
163
164
165 #ifndef NO_MAIN
166 int
167 main (const int argc, char *const argv[])
168 {
169 int retval = 1;
170
171 try {
172 retval = pjinfo_main(argc, argv);
173 } catch (exception e) {
174 std::cerr << "Exception: " << e.what() << std::endl;
175 } catch (...) {
176 std::cerr << "Unknown exception\n";
177 }
178
179 return (retval);
180 }
181 #endif