Initial snark14m import
[snark14.git] / src / snark / basis.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/basis.cpp $
5  $LastChangedRevision: 85 $
6  $Date: 2014-07-02 16:07:08 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9
10  basis() establishes the basis function. The basis can be either "blob" or "voronoi". If blob basis, then one should also specify the support of the blob "blob.support", shape of the blob "Blob.shape", and the grid resolution "Blob.delta"
11
12  */
13
14 #include <cstdio>
15 #include <cmath>
16 #include <cstdlib>
17
18 #include "consts.h"
19 #include "blkdta.h"
20 #include "blob.h"
21 #include "geom.h"
22 #include "basis.h"
23 #include "uiod.h"
24 #include "int2str.h"
25 #include "infile.h"
26
27 void basis()
28 {
29         INTEGER word;
30         REAL aux;
31
32         BOOLEAN eol;
33
34         static const INTEGER blob = CHAR2INT('b', 'l', 'o', 'b');
35         static const INTEGER pixel = CHAR2INT('p', 'i', 'x', 'e');
36
37         // modified calls to getwrd() to use the 4-parameter version. Lajos, Dec 13, 2004
38         static const INTEGER basis_codes[2] =
39         { CHAR2INT('b', 'l', 'o', 'b'), CHAR2INT('p', 'i', 'x', 'e') };
40
41         Blob.pix_basis = TRUE;
42
43         for (;;)
44         {
45
46                 word = InFile.getwrd(FALSE, &eol, basis_codes, 2);
47
48                 if (eol)
49                 {
50                         break;
51                 }
52
53                 if (word == blob)
54                 {
55                         Blob.pix_basis = FALSE;
56                         //default values
57                         Blob.delta = 2.0 * Consts.isqrt3 * GeoPar.pixsiz;
58                         //Blob.delta =   4.0 * Consts.isqrt3 * GeoPar.pixsiz;
59                         Blob.shape = 11.2828631556;
60                         Blob.support = 1.7865601396 * Blob.delta;
61                         //Blob.support = 2 * 1.7865601396 * Blob.delta;
62                         aux = InFile.getnum(FALSE, &eol);
63                         if (!eol)
64                         {
65                                 Blob.support = aux;
66                                 Blob.shape = InFile.getnum(FALSE, &eol);
67                                 if (Blob.shape < 0.0)
68                                 {
69                                         fprintf(output,
70                                                         "\n **** shape of a blob cannot be negative");
71                                         fprintf(output, "\n **** program aborted\n");
72                                         exit(333);
73                                 }
74
75                                 //delta = getnum(NULL, &eol);
76                                 Blob.delta = InFile.getnum(FALSE, &eol);
77                                 if ((Blob.delta <= Consts.zero)
78                                                 || (Blob.support <= Consts.zero))
79                                 {
80                                         fprintf(output,
81                                                         "\n **** delta and support must be greater than ZERO");
82                                         fprintf(output, "\n **** program aborted\n");
83                                         exit(333);
84                                 }
85                         }
86
87                         Blob.setparam();
88                         Blob.table();
89
90                         break;
91                 }
92
93                 else if (word == pixel)
94                 {
95                         Blob.pix_basis = TRUE;
96                         break;
97                 }
98
99                 else
100                 {
101                         fprintf(output, "\n **** unknown basis %s", int2str(word));
102                         fprintf(output, "\n **** program aborted\n");
103                         exit(333);
104                 }
105         }
106         // ECHO OPTION SELECTED
107
108         if (Blob.pix_basis)
109         {
110                 fprintf(output, "\n          pixel basis");
111         }
112
113         else
114         {
115                 fprintf(output,
116                                 "\n          blob basis with parameters: support = %10.4f shape = %10.4f delta = %10.4f",
117                                 Blob.support, Blob.shape, Blob.delta);
118
119         }
120 }