Initial snark14m import
[snark14.git] / src / snark / geom.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/geom.cpp $
5  $LastChangedRevision: 85 $
6  $Date: 2014-07-02 16:07:08 -0400 (Wed, 02 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9  */
10
11 #include <cstdlib>
12 #include <cstdio>
13 #include <cmath>
14
15 #include "blkdta.h"
16 #include "geom.h"
17 #include "consts.h"
18 #include "uiod.h"
19
20 Geometry_class GeoPar;
21
22 Geometry_class::Geometry_class()
23 {
24         nelem = 0;
25         prjnum = 0;
26         nave2 = 0;
27         div = FALSE;
28         tang = FALSE;
29         arc = FALSE;
30         par = FALSE;
31         uni = FALSE;
32         vri = FALSE;
33         strip = FALSE;
34         line = FALSE;
35         //  rebinf = FALSE;    // bug 151 - swr - 08/07/2005
36         lino = FALSE;  /// bug #135. Lajos, 08/01/2005
37         radius = 0.0;
38         stod = 0.0;
39         aveden = 0.0;
40
41         naper[0] = 1;
42         for (int i = 1; i < 13; i++)
43         {
44                 naper[i] = 0;
45         }
46 }
47
48 /*
49  COMPUTE THE NUMBER OF RAYS NECESSARY TO SPAN AN SQUARE OBJECT
50  MELEN*ZISXIP UNITS ON A SIDE
51  */
52
53 INTEGER Geometry_class::numray(INTEGER melen, REAL zisxip)
54 {
55         REAL diag;
56         REAL pmin;
57         INTEGER numb;
58         REAL xleg;
59
60         diag = (REAL) (melen * zisxip / 1.414);
61
62         pmin = diag / pinc;
63
64         if (!div)
65         {
66
67                 if (uni)
68                         numb = (INTEGER) (2.0 * pmin);
69                 if (vri)
70                         numb = (INTEGER) (2.0 * 1.414 * pmin);
71         }
72         else
73         {
74                 xleg = (radius / pinc) * (radius / pinc) - pmin * pmin;
75                 if (xleg <= Consts.zero)
76                 {
77
78                         fprintf(output,
79                                         "\n **** source to origin distance is %10.4f it must be at least %10.4f",
80                                         radius, diag);
81                         fprintf(output, "\n **** program aborted\n");
82                         exit(700);
83                 }
84
85                 xleg = (REAL) sqrt(xleg);
86                 if (tang)
87                         numb = (INTEGER) (2.0 * stod * pmin / (xleg * pinc));
88                 if (arc)
89                         numb = (INTEGER) (2.0 * stod * atan2(pmin, xleg) / pinc);
90         }
91
92         return numb + (numb + 1) % 2 + 2;
93 }
94
95 void Geometry_class::print(char *comment)
96 {
97         fprintf(output, "\n%s\n", comment);
98         fprintf(output, "prjnum=%d, pinc=%f, nrays=%d, midray=%d, snrays=%d ", prjnum, pinc, nrays, midray, snrays);
99         fprintf(output, "usrays=%d, fsnray=%d, lsnray=%d, fusray=%d, lusray=%d\n", usrays, fsnray, lsnray, fusray, lusray);
100         fprintf(output, "div=%d, tang=%d, arc=%d, radius=%f, stod=%f ", div, tang, arc, radius, stod);
101         fprintf(output, "par=%d, uni=%d, vri=%d, strip=%d, line=%d, lino=%d\n", par, uni, vri, strip, line, lino);  // bug 151 - swr - 08/07/2005
102         fprintf(output, "aveden=%f nave2=%d naper=[%d", aveden, nave2, naper[0]);
103         for (int i = 1; i < 13; i++)
104         fprintf(output, ",%d", naper[i]);
105         fprintf(output, "]\n");
106 };