r4312: *** 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.2 2003/04/01 18:56:59 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.2 2003/04/01 18:56:59 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 = 2 * (2 * n - 1) + 1;
106   double divisor = 4 * n + 3;
107   
108   for (int itheta = 0; itheta < size; itheta++) {
109     double theta = atan (2 * itheta / divisor);
110     printf ("%lf: ", theta);
111     double step = d * cos(theta);
112     for (int id = 0; id < size; id++) {
113       printf ("%lf ", id * step);
114     }
115     printf ("\n");
116   }
117   
118   return (0);
119 }
120
121 #ifndef NO_MAIN
122 int 
123 main (int argc, char *const argv[])
124 {
125   int retval = 1;
126
127   try {
128     retval = linogram_main(argc, argv);
129   } catch (exception e) {
130           std::cerr << "Exception: " << e.what() << std::endl;
131   } catch (...) {
132           std::cerr << "Unknown exception\n";
133   }
134
135   return (retval);
136 }
137 #endif