Initial snark14m import
[snark14.git] / src / snark / select.cpp
1 /*      
2  ***********************************************************
3  $SNARK_Header: S N A R K  1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4  $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/select.cpp $
5  $LastChangedRevision: 96 $
6  $Date: 2014-07-02 20:06:42 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  PROCESS THE SELECT COMMAND AND SET THE VARIABLES IN /RAYSEL/ FOR
11  USE BY PICK
12  */
13
14 #include <cstdlib>
15 #include <cstdio>
16
17 #include "blkdta.h"
18 #include "raysel.h"
19 #include "uiod.h"
20
21 #include "geom.h" 
22 #include "effpick.h" 
23 #include "int2str.h"
24 #include "infile.h"
25
26 #include "select.h"
27
28 void select(BOOLEAN isdefault)                    //add isdefault option, by wei
29 {
30
31         // modified calls to getwrd() to use the 4-parameter version. Lajos, Dec 16, 2004
32         static const INTEGER sel_type[] =
33         {
34                         CHAR2INT('r', 'a', 'y', 's'), CHAR2INT('p', 'r', 'o', 'j'),
35                         CHAR2INT('r', 'a', 'n', 'd'), CHAR2INT('e', 'f', 'f', 'i') // adding efficient mode
36         };
37
38         static const INTEGER user = CHAR2INT('u', 's', 'e', 'r');
39         static const INTEGER snark = CHAR2INT('s', 'n', 'a', 'r');
40
41         // modified calls to getwrd() to use the 4-parameter version. Lajos, Dec 16, 2004
42         static const INTEGER select_codes[3] =
43         { CHAR2INT('u', 's', 'e', 'r'), CHAR2INT('s', 'n', 'a', 'r'), CHAR2INT('s', 't', 'e', 'p') };
44
45 //  static const INTEGER step = 35;  // commented out since it is unused. Lajos, Jan 13, 2005
46
47         int i;
48         int NumRay;  //for efficient mode
49         INTEGER word;
50         BOOLEAN eol;
51
52         if (isdefault)
53                 goto L40;
54         //default select efficient, by wei
55
56         word = InFile.getwrd(FALSE, &eol, select_codes, 2);
57         if ((word != user) && (word != snark))
58         {
59                 fprintf(output, "\n **** select must be followed by either USER or SNARK");
60                 fprintf(output, "\n **** program aborted\n");
61                 exit(666);
62         }
63
64         RaySel.useray = (word == user);
65         word = InFile.getwrd(FALSE, &eol, sel_type, 4);
66         for (i = 0; i < 3; i++)
67         {
68                 if (word == sel_type[i])
69                         goto L20;
70         }
71
72         if (word == sel_type[3])
73         { //efficient way
74
75                 word = InFile.getwrd(FALSE, &eol, sel_type, 4);
76                 if (eol)
77                 {
78                         RaySel.stype = 7;
79                         goto L40;
80                 }
81                 else
82                 {
83                         fprintf(output, "\n **** unknown selection type %s", int2str(word));
84                         fprintf(output, "\n **** program aborted\n");
85                         exit(666);
86                 }
87         }
88
89         if (!eol)
90         {
91 // ERROR
92                 fprintf(output, "\n **** unknown selection type %s", int2str(word));
93                 fprintf(output, "\n **** program aborted\n");
94                 exit(666);
95         }
96
97 //RaySel.stype = 0;
98         RaySel.stype = 7;
99         goto L40;                       // efficient mode by default wei 1/2005
100
101         L20: RaySel.stype = i;
102         word = InFile.getint(FALSE, &eol);
103         if (eol)
104                 goto L30;
105         if (word < 0)
106         {
107                 fprintf(output, "\n **** illegal selection : %s %s, the number after a selection type must be greater than zero", int2str(sel_type[RaySel.stype]), int2str(word));
108                 fprintf(output, "\n **** program aborted\n");
109                 exit(666);
110         }
111
112         RaySel.rn1 = word;
113         word = InFile.getwrd(FALSE, &eol, sel_type, 3);
114         if (eol)
115         {
116                 // ERROR
117                 fprintf(output, "\n **** illegal selection : %s, %i", int2str(sel_type[RaySel.stype]), RaySel.rn1);
118                 fprintf(output, "\n **** program aborted\n");
119                 exit(666);
120         }
121
122         for (i = 0; i < 3; i++)
123         {
124                 if (word == sel_type[i])
125                         goto L25;
126         }
127 // ERROR
128         fprintf(output, "\n **** unknown selection type %s", int2str(word));
129         fprintf(output, "\n **** program aborted\n");
130         exit(666);
131
132         L25: if ((RaySel.stype == 0) && (i == 2))
133                 RaySel.stype = 5;
134         if ((RaySel.stype == 1) && (i == 2))
135                 RaySel.stype = 6;
136         if ((RaySel.stype == 2) && (i == 0))
137                 RaySel.stype = 3;
138         if ((RaySel.stype == 2) && (i == 1))
139                 RaySel.stype = 4;
140
141         if (!((RaySel.stype != 0) && (RaySel.stype != 1) && (RaySel.stype != 2)))
142         {
143
144                 // ERROR
145                 fprintf(output, "\n **** illegal select combination : %s, %s", int2str(sel_type[RaySel.stype]), int2str(sel_type[i]));
146                 fprintf(output, "\n **** program aborted\n");
147                 exit(666);
148         }
149
150         word = InFile.getint(FALSE, &eol);
151         if ((!eol) && (word <= 0))
152         {
153                 fprintf(output, "\n **** illegal selection : %s %s, the number after a selection type must be greater than zero", int2str(sel_type[RaySel.stype]), int2str(word));
154                 fprintf(output, "\n **** program aborted\n");
155                 exit(666);
156         }
157
158         RaySel.rn2 = word;
159
160         L30: if (RaySel.stype != 2)
161         {
162
163                 ///if(getwrd(input, &eol) != keywd[step]) {
164                 if (InFile.getwrd(TRUE, &eol, &(select_codes[2]), 1) != CHAR2INT('s','t','e','p'))
165                 {
166                         fprintf(output, "\n **** keyword STEP missing");
167                         fprintf(output, "\n **** program aborted\n");
168                         exit(666);
169                 }
170
171                 RaySel.prjinc = InFile.getint(FALSE, &eol);
172                 RaySel.rayinc = InFile.getint(FALSE, &eol);
173                 if ((RaySel.prjinc <= 0) || (RaySel.rayinc <= 0))
174                 {
175                         fprintf(output, "\n **** both mod1 and mod2 must be positive.");
176                         fprintf(output, "\n      mod1 = %5i, mod2 = %5i", RaySel.prjinc, RaySel.rayinc);
177                         fprintf(output, "\n **** program aborted\n");
178                         exit(666);
179                 }
180
181         }
182
183         // ECHO INPUT
184
185         if (RaySel.stype == 3 && eol)
186         {
187                 fprintf(output, "\n         a fixed number of %5i rays at random, followed by sequential ray selection", RaySel.rn1);
188                 fprintf(output, "\n         with ray-step %5i and projection-step %5i", RaySel.rayinc, RaySel.prjinc);
189                 return;
190         }
191
192         if (RaySel.stype == 4 && eol)
193         {
194                 fprintf(output, "\n         a fixed number of %5i rays at random followed by sequential projection selection", RaySel.rn1);
195                 fprintf(output, "\n         with projection-step %5i and ray-step %5i", RaySel.prjinc, RaySel.rayinc);
196                 return;
197         }
198
199         if (RaySel.stype == 5 && eol)
200         {
201                 fprintf(output, "\n         a fixed number of, %5i sequential rays, with ray-step, %5i and projection-step %5i", RaySel.rn1, RaySel.rayinc, RaySel.prjinc);
202                 fprintf(output, "\n         followed by random selection of rays and projections");
203                 return;
204         }
205
206         if (RaySel.stype == 6 && eol)
207         {
208                 fprintf(output, "\n         a fixed number of, %5i sequential rays, with ray-step, %5i and projection-step %5i", RaySel.rn1, RaySel.prjinc, RaySel.rayinc);
209                 fprintf(output, "\n         followed by random selection of rays and projections");
210                 return;
211         }
212
213         L40: switch (RaySel.stype)
214         {
215         case 0:
216                 fprintf(output, "\n         sequential ray selection with ray-step %5i and projection-step %5i", RaySel.rayinc, RaySel.prjinc);
217                 return;
218
219         case 1:
220                 fprintf(output, "\n         sequential projection selection with projection-step %5i and ray-step %5i", RaySel.prjinc, RaySel.rayinc);
221                 return;
222
223         case 2:
224                 fprintf(output, "\n         random selection of rays and projections");
225                 return;
226
227         case 3:
228                 fprintf(output, "\n         cycles of %5i rays at random", RaySel.rn1);
229                 fprintf(output, "\n         followed by a fixed number of %5i sequential rays with ray-step %5i and projection-step %5i", RaySel.rn2, RaySel.rayinc, RaySel.prjinc);
230                 return;
231
232         case 4:
233                 fprintf(output, "\n         cycles of %5i rays at random", RaySel.rn1);
234                 fprintf(output, "\n         followed by a fixed number of %5i sequential projection selection with projection-step %5i and ray-step %5i", RaySel.rn2, RaySel.prjinc, RaySel.rayinc);
235                 return;
236
237         case 5:
238                 fprintf(output, "\n         cycles of %5i sequential rays with ray-step %5i and projection-step %5i", RaySel.rn1, RaySel.rayinc, RaySel.prjinc);
239                 fprintf(output, "\n         followed by %5i rays at random", RaySel.rn2);
240                 return;
241
242         case 6:
243                 fprintf(output, "\n         cycles of %5i sequential projection selection with projection-step %5i and ray-step %5i", RaySel.rn1, RaySel.prjinc, RaySel.rayinc);
244                 fprintf(output, "\n         followed by %5i rays at random", RaySel.rn2);
245
246                 return;
247
248         case 7:
249                 if (!isdefault)
250                         fprintf(output, "\n         efficient data access");
251
252                 if (!RaySel.useray)
253                         NumRay = GeoPar.snrays;
254                 else
255                         NumRay = GeoPar.usrays;
256
257                 factorization(GeoPar.prjnum, &RaySel.decompprj, &RaySel.num_digprj);
258                 factorization(NumRay, &RaySel.decompray, &RaySel.num_digray);
259                 //factorization(30, &RaySel.decompray, &RaySel.num_digray);
260
261                 get_base(RaySel.decompprj, RaySel.num_digprj, &RaySel.baseprj);
262                 get_base(RaySel.decompray, RaySel.num_digray, &RaySel.baseray);
263
264                 if (RaySel.old_numray != NULL)
265                         delete[] RaySel.old_numray;
266                 if (RaySel.old_numprj != NULL)
267                         delete[] RaySel.old_numprj;
268                 if (RaySel.new_numray != NULL)
269                         delete[] RaySel.new_numray;
270                 if (RaySel.new_numprj != NULL)
271                         delete[] RaySel.new_numprj; //added to avoid memory leak, by wei 1/2005
272
273                 RaySel.old_numray = new INTEGER[RaySel.num_digray];
274                 RaySel.old_numprj = new INTEGER[RaySel.num_digprj];
275                 RaySel.new_numray = new INTEGER[RaySel.num_digray];
276                 RaySel.new_numprj = new INTEGER[RaySel.num_digprj];
277
278                 RaySel.old_numprj[0] = -1;
279
280                 return;
281         }
282
283 }