Initial snark14m import
[snark14.git] / src / snark / quad_blurck.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/quad_blurck.cpp $
5  $LastChangedRevision: 80 $
6  $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
7  $Author: agulati $
8  ***********************************************************
9  */
10
11 #include <cstdio>
12
13 #include "blkdta.h"
14 #include "consts.h"
15 #include "uiod.h"
16 #include "int2str.h"
17
18 #include "quad.h"
19
20 void quad_class::blurck(REAL b1, REAL b2, REAL b3, INTEGER bcon, INTEGER npow,
21                 BOOLEAN* alg1)
22 {
23
24         static const INTEGER hsnar = CHAR2INT('s', 'n', 'a', 'r');
25         static const INTEGER hkami = CHAR2INT('k', 'a', 'm', 'i');
26         static const INTEGER hsajz = CHAR2INT('s', 'a', 'j', 'z');
27         static const INTEGER hsajc = CHAR2INT('s', 'a', 'j', 'c');
28
29         REAL bsum;
30         BOOLEAN psd;
31         BOOLEAN pos;
32
33         if (!((bcon == hsnar) || (bcon == hkami) || (bcon == hsajz)
34                         || (bcon == hsajc)))
35         {
36                 *alg1 = TRUE;
37                 fprintf(output,
38                                 "\n\n      ***unrecognized parameter %4s, program stops***",
39                                 int2str(bcon));
40
41                 return;
42         }
43         bsum = b1 + (REAL) 4.0 * (b2 + b3);
44         fprintf(output, "\n\n      variance of density in an arbitrary pixel is  %9.5f", b1);
45         fprintf(output, "\n       covariance of densities in neighboring pixels is %9.5f", b2);
46         fprintf(output, "\n       covariance of densities in diagonally neighboring pixels is %9.5f", b3);
47
48         fprintf(output, "\n\n      %4s boundary conditions", int2str(bcon));
49         fprintf(output, "\n       sum of weights %9.4f", bsum);
50
51         if (!((bcon != hkami) || (npow == 1)))
52         {
53                 fprintf(output,
54                                 "\n\n      ***for kami only first power is allowed, program stops***");
55
56                 *alg1 = TRUE;
57                 return;
58         }
59         if (bcon == hkami)
60                 return;
61
62         // CHECKING ON POSITIVE-DEFINITENESS OF SMOOTHING MATRIX
63         psd = TRUE;
64         if (bsum <= -.000001)
65                 psd = FALSE;
66         if ((b1 - 4.0 * b2 + 4.0 * b3) <= -.000001)
67                 psd = FALSE;
68         if ((b1 - 4.0 * b3) <= -.000001)
69                 psd = FALSE;
70         *alg1 = !psd;
71         if (*alg1)
72         {
73                 fprintf(output,
74                                 "\n\n      ***warning, smoothing matrix is not positive semi definite");
75         }
76         if (bcon != hsnar)
77                 return;
78
79 //  PERFORMING TRADITIONAL SNARK CHECK ON POSITIVITY
80         pos = FALSE;
81         if ((b1 > Consts.zero) && (b2 >= 0.0) && (b3 >= 0.0))
82                 pos = TRUE;
83         *alg1 = !pos;
84         if (*alg1)
85         {
86                 fprintf(output, "\n\n      ***elements of smoothing matrix too small or negative, program stops***"); //hstau
87         }
88         return;
89 }