1 /*****************************************************************************
5 ** Purpose: Convert an projection data file to an image file
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: April 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2009 Kevin Rosenberg
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.
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.
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 ******************************************************************************/
27 * pjinfo.c Convert Raysum to image
37 enum { O_BINARYHEADER, O_BINARYVIEWS, O_STARTVIEW, O_ENDVIEW, O_DUMP, O_HELP, O_VERSION };
39 static struct option my_options[] =
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},
51 static const char* g_szIdStr = "$Id$";
54 pjinfo_usage (const char *program)
56 std::cout << "usage: " << fileBasename(program) << " proj-file [OPTIONS]\n";
57 std::cout << "Display projection file information\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";
71 pjinfo_main (const int argc, char *const argv[])
75 bool optBinaryHeader = false;
76 bool optBinaryViews = false;
78 int optEndView = -1; // tells copyViewData to use default last view
83 char *endptr, *endstr;
84 int c = getopt_long (argc, argv, "", my_options, NULL);
94 optBinaryHeader = true;
97 optBinaryViews = true;
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]);
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]);
119 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
121 std::cout << "Unknown version number\n";
126 pjinfo_usage(argv[0]);
129 pjinfo_usage(argv[0]);
134 if (argc - optind != 1) {
135 pjinfo_usage(argv[0]);
139 pj_name = argv[optind];
142 Projections::copyHeader (pj_name, std::cout);
143 else if (optBinaryViews)
144 Projections::copyViewData (pj_name, std::cout, optStartView, optEndView);
147 if (! pj.read (pj_name)) {
148 sys_error (ERR_SEVERE, "Can not open projection file %s", pj_name.c_str());
153 pj.printProjectionData (optStartView, optEndView);
155 std::ostringstream os;
156 pj.printScanInfo (os);
157 std::cout << os.str();
167 main (const int argc, char *const argv[])
172 retval = pjinfo_main(argc, argv);
173 } catch (exception e) {
174 std::cerr << "Exception: " << e.what() << std::endl;
176 std::cerr << "Unknown exception\n";