Initial snark14m import
[snark14.git] / src / snark / doline.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/doline.cpp $
5  $LastChangedRevision: 79 $
6  $Date: 2014-07-01 15:33:39 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  **********************************************************************
9
10  POST-PROCESSING ROUTINE TO GENERATE LINE DISPLAYS OF
11  RECONSTRUCTIONS.
12  */
13
14 #include <cstdio>
15
16 #include "blkdta.h"
17 #include "uiod.h"
18
19 #include "lines.h"
20
21 //#include "int2str.h"
22 #include "recfile.h"
23 #include "infile.h"
24
25 #include "doline.h"
26
27 void doline()
28 {
29         // was in post but it is realy local
30         CHAR prjnam[81];
31         CHAR phnnam[81];
32         CHAR recnam[81];
33
34         // was in geo but it is realy local
35         INTEGER nelem;
36         INTEGER area;
37
38         REAL scale, denmin, denmax;
39         INTEGER word, lineno, linumb[4], flag[51];
40         REAL* Phantom;
41         REAL* Recon;
42         CHAR algn[5];
43         unsigned INTEGER count, iter;
44         BOOLEAN eol;
45         BOOLEAN minfl, maxfl;
46
47         INTEGER index;
48
49         int i;
50
51         static const INTEGER hscal = CHAR2INT('s', 'c', 'a', 'l');
52         static const INTEGER hcolu = CHAR2INT('c', 'o', 'l', 'u');
53
54         // modified calls to getwrd() to use the 4-parameter version. Lajos, Dec 13, 2004
55         static const INTEGER doline_codes[2] = { CHAR2INT('s', 'c', 'a', 'l'), CHAR2INT('c', 'o', 'l', 'u') };
56
57         if (RecFile.Open("recfil") != 0)
58         {
59                 fprintf(output, "\n **** unable to open recfil");
60                 fprintf(output, "\n **** LINE execution aborted\n");
61                 return;
62         }
63
64         if (RecFile.GetNelem(&nelem) != 0)
65         {
66                 ;
67         }
68
69         if (RecFile.GetProjName(prjnam) != 0)
70         {
71                 ;
72         }
73
74         area = nelem * nelem;
75         //GeoPar.midpix = (GeoPar.nelem + 1) / 2;
76
77         lineno = 0;
78         minfl = FALSE;
79         maxfl = FALSE;
80         scale = 1.0;
81
82         for (;;)
83         {
84                 word = InFile.getwrd(FALSE, &eol, doline_codes, 2);
85
86                 if (eol)
87                 {
88                         fprintf(output, "\n **** no columns requested");
89                         fprintf(output, "\n **** LINE execution aborted\n");
90                         RecFile.Close();
91                         return;
92                 }
93
94                 if (word == hscal)
95                 {
96                         scale = InFile.getnum(FALSE, &eol);
97                         continue;
98                 };
99
100                 if (word == hcolu)
101                         break;
102         }
103
104         for (;;)
105         {
106                 index = InFile.getint(FALSE, &eol);
107
108                 if (eol)
109                         break;
110
111                 if ((index >= 0) && (index < nelem))
112                 {
113
114                         if (lineno >= 4)
115                                 break;
116                         linumb[lineno++] = index;
117                 }
118                 else
119                 {
120                         fprintf(output,
121                                         "\n **** requested column %d is not in the range (0, %d)",
122                                         index, nelem - 1);
123                         fprintf(output, "\n **** COLUMN %d ignored", index);
124                 }
125
126         }
127
128         if (lineno == 0)
129         {
130                 fprintf(output, "\n **** no columns requested");
131                 fprintf(output, "\n **** LINE execution aborted\n");
132                 RecFile.Close();
133                 return;
134         }
135
136         InFile.listit(flag);
137
138         Phantom = new REAL[area];
139         Recon = new REAL[area];
140
141         // load phantom
142         if (RecFile.ReadPhan(phnnam, Phantom) != 0)
143         {
144                 fprintf(output, "\n **** phantom not present");
145                 fprintf(output, "\n **** LINE execution aborted\n");
146                 RecFile.Close();
147                 return;
148         }
149
150         if (!minfl)
151         {
152                 denmin = Phantom[0];
153                 for (i = 1; i < area; i++)
154                 {
155                         if (Phantom[i] < denmin)
156                                 denmin = Phantom[i];
157                 }
158         }
159         if (!maxfl)
160         {
161                 denmax = Phantom[0];
162                 for (i = 1; i < area; i++)
163                 {
164                         if (Phantom[i] > denmax)
165                                 denmax = Phantom[i];
166                 }
167         }
168
169         // Load reconstructed images
170         while (RecFile.ReadRec(recnam, algn, &count, &iter, Recon) == 0)
171         {
172
173                 if (flag[iter - 1] != 0)
174                 {
175                         fprintf(output,
176                                         "\n     lines display of reconstruction using %s iter %d\n",
177                                         algn, count);
178                         fprintf(output, "\n     phantom name:    %s", phnnam);
179                         fprintf(output, "\n     projection data: %s", prjnam);
180                         fprintf(output, "\n     execution name:  %s", recnam);
181                         lines(Phantom, Recon, nelem, nelem, scale, lineno, linumb, output);
182                 }
183         }
184
185         delete[] Recon;  // bug 92 - Lajos - 03/02/2005
186         delete[] Phantom;  // bug 92 - Lajos - 03/02/2005
187
188         fprintf(output, "\n ");
189
190         RecFile.Close();
191         return;
192 }