r4311: *** empty log message ***
[ctsim.git] / tools / linogram.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          linogram.cpp
5 **   Purpose:       Display linogram sampling
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  April 2003
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: linogram.cpp,v 1.1 2003/04/01 18:34: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
30 enum { O_LABELS,, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
31
32 static struct option my_options[] =
33 {
34    {"debug", 0, 0, O_DEBUG},
35   {"verbose", 0, 0, O_VERBOSE},
36   {"help", 0, 0, O_HELP},
37   {"version", 0, 0, O_VERSION},
38   {0, 0, 0, 0}
39 };
40
41 static const char* g_szIdStr = "$Id: linogram.cpp,v 1.1 2003/04/01 18:34:42 kevin Exp $";
42
43
44 void 
45 linogram_usage (const char *program)
46 {
47   std::cout << "usage: " << fileBasename(program) << " n d [OPTIONS]\n";
48   std::cout << "Imagefile information\n";
49   std::cout << std::endl;
50   std::cout << "     infile       Name of input IF file\n";
51    std::cout << "     --debug      Debug mode\n";
52   std::cout << "     --verbose    Verbose mode\n";
53   std::cout << "     --version    Print version\n";
54   std::cout << "     --help       Print this help message\n";
55 }
56
57 int 
58 linogram_main (int argc, char *const argv[])
59 {
60   std::string in_n;
61   int opt_verbose = 0;
62   int opt_debug = 0;
63
64   while (1)
65     {
66       int c = getopt_long (argc, argv, "", my_options, NULL);
67       
68       if (c == -1)
69         break;
70       
71       switch (c)
72         {
73         case O_VERBOSE:
74           opt_verbose = 1;
75           break;
76         case O_DEBUG:
77           opt_debug = 0;
78           break;
79         case O_VERSION:
80 #ifdef VERSION
81           std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
82 #else
83           std::cout << "Unknown version number\n";
84 #endif
85           return (0);
86         case O_HELP:
87         case '?':
88           linogram_usage(argv[0]);
89           return (0);
90         default:
91           linogram_usage(argv[0]);
92           return (1);
93         }
94     }
95
96   if (optind + 2 != argc) {
97     linogram_usage (argv[0]);
98     return (1);
99   }
100   
101   in_n = argv[optind];
102   in_d = argv[optind+1];
103
104   int n = atol (in_n);
105   double n = atof (in_d);
106   int size = 2 * (2 * n - 1) + 1;
107   double divisor = 4 * n + 3;
108   
109   for (int itheta = 0; itheta < size; itheta++) {
110     double theta = atan (2 * itheta / division);
111     printf ("%lf: ", theta);
112     double step = d * cos(theta);
113     for (int id = 0; id < size; id++) {
114       printf ("%lf ", id * step);
115     }
116     printf ("\n");
117   }
118   
119   return (0);
120 }
121
122 #ifndef NO_MAIN
123 int 
124 main (int argc, char *const argv[])
125 {
126   int retval = 1;
127
128   try {
129     retval = linogram_main(argc, argv);
130   } catch (exception e) {
131           std::cerr << "Exception: " << e.what() << std::endl;
132   } catch (...) {
133           std::cerr << "Unknown exception\n";
134   }
135
136   return (retval);
137 }
138 #endif