| Bsoft 2.0.5 Bernard's software package

kernlut.cpp
Go to the documentation of this file.
1
10 #include "kernlut.h"
11
12 #include "utilities.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
22 int
23 kernlut (kernel * ker)
24 {
25 float *kern1;
26 double s1, s2, c, arg1, arg2, ink, pink;
27 int i, j, rnkern = ker->nkern, rnk = ker->nk, rnkm1;
28 double fnkm1, arg, incr;
29
30 if (ker->nk % 2 == 0)
31 rnkm1 = ker->nk / 2 - 1;
32 else
33 rnkm1 = (ker->nk - 1) / 2;
34 i = 1;
35 ink = (float) i / (float) ker->nk;
36 pink = M_PI * ink;
37 incr = (float) 1 / (float) rnkern;
38 kern1 = ker->kern + rnkm1;
39 fnkm1 = (float) rnkm1;
40 *kern1 = 1.;
41 kern1 = ker->kern + rnk;
42 arg = incr;
43 for (i = 1; i < rnkern; i++)
44 {
45 arg1 = M_PI * (arg + fnkm1);
46 s1 = ink * sin (arg1);
47 arg2 = arg1 * ink;
48 for (j = 0; j < rnk; j++)
49 {
50 s2 = sin (arg2);
51 c = cos (arg2);
52 *kern1 = (s1 / s2) * pow (c, ker->power);
53 kern1++;
54 arg2 -= pink;
55 s1 = -s1;
56 }
57 arg += incr;
58 }
59 kern1 += rnkm1 + 1;
60 *kern1 = 1.;
61 return 0;
62 }
63
64
65 kernel *
66 kernel_prep (int nk, int power)
67 {
68 kernel *ker = NULL;
69
70 if ((ker = (kernel *) calloc (1, sizeof (kernel))) == NULL)
71 {
72 perror ("kernel_prep: ker error calloc");
73 exit (0);
74 }
75
76 if (verbose & VERB_FULL)
77 cout << "Preparing the kernel: nk = " << nk << ", power = " << power << endl;
78
79 ker->nk = nk;
80 ker->power = power;
81
82 ker->nkern = 512;
83 ker->nker = ker->nkern * ker->nk + ker->nk;
84 if ((ker->kern = (float *) calloc (ker->nker, sizeof (float))) == 0)
85 {
86 perror ("kernel_prep: ker->kern error calloc");
87 exit (0);
88 }
89
90 if (ker->power == -1)
91 {
92 ker->bordo = 1;
93 ker->nk = 1;
94 } // linear interp. //
95 else if ((ker->nk % 2) == 0)
96 ker->bordo = ker->nk / 2 - 1;
97 else
98 ker->bordo = (ker->nk - 1) / 2;
99
100 if (ker->power >= 0)
101 kernlut (ker);
102
103 return (ker);
104 }
kernel::power
int power
Definition: kernlut.h:16
kernel::nk
int nk
Definition: kernlut.h:15
verbose
int verbose
kernlut
int kernlut(kernel *ker)
Prepare coefficients table for interpolation.
Definition: kernlut.cpp:23
utilities.h
Header file for general utilities.
kernel::nkern
int nkern
Definition: kernlut.h:17
M_PI
#define M_PI
Definition: utilities.h:59
kernel::nker
int nker
Definition: kernlut.h:18
kernel::bordo
int bordo
Definition: kernlut.h:19
kernel
Definition: kernlut.h:13
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
kernel_prep
kernel * kernel_prep(int nk, int power)
Definition: kernlut.cpp:66
kernlut.h
kernel::kern
float * kern
Definition: kernlut.h:20