r4313: *** 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.3 2003/04/01 19:49:41 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.3 2003/04/01 19:49:41 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   int opt_verbose = 0;
61   int opt_debug = 0;
62
63   while (1)
64     {
65       int c = getopt_long (argc, argv, "", my_options, NULL);
66       
67       if (c == -1)
68         break;
69       
70       switch (c)
71         {
72         case O_VERBOSE:
73           opt_verbose = 1;
74           break;
75         case O_DEBUG:
76           opt_debug = 0;
77           break;
78         case O_VERSION:
79 #ifdef VERSION
80           std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
81 #else
82           std::cout << "Unknown version number\n";
83 #endif
84           return (0);
85         case O_HELP:
86         case '?':
87           linogram_usage(argv[0]);
88           return (0);
89         default:
90           linogram_usage(argv[0]);
91           return (1);
92         }
93     }
94
95   if (optind + 2 != argc) {
96     linogram_usage (argv[0]);
97     return (1);
98   }
99   
100   const char* in_n = argv[optind];
101   const char* in_d = argv[optind+1];
102
103   int n = atol (in_n);
104   double d = atof (in_d);
105   int size = 4 * n + 3;
106   double theta_base = PI/8;
107   
108   double theta_vec [size];
109   for (int i = 0; i < size; i++) {
110     int m = i - (2 * n + 1);
111     theta_vec[i] = atan (static_cast<double>(2 * m) / size);
112   }
113
114   int m;
115   for (m = 0; m < size; m++) {
116     printf ("%lf: ", theta_vec[m] + theta_base);
117     double step = d * cos(theta_vec[m]);
118     for (int id = 0; id < size; id++) {
119       printf ("%lf ", id * step);
120     }
121     printf ("\n");
122   }
123
124   for (m = 0; m < size; m++) {
125     printf ("%lf: ", theta_vec[m] + PI/2. + theta_base);
126     double step = d * cos(theta_vec[m]);
127     for (int id = 0; id < size; id++) {
128       printf ("%lf ", id * step);
129     }
130     printf ("\n");
131   }
132   
133   return (0);
134 }
135
136 #ifndef NO_MAIN
137 int 
138 main (int argc, char *const argv[])
139 {
140   int retval = 1;
141
142   try {
143     retval = linogram_main(argc, argv);
144   } catch (exception e) {
145           std::cerr << "Exception: " << e.what() << std::endl;
146   } catch (...) {
147           std::cerr << "Unknown exception\n";
148   }
149
150   return (retval);
151 }
152 #endif