Bsoft  2.1.0
Bernard's software package
radon_util.cpp
Go to the documentation of this file.
1 
11 #include "radon_util.h"
12 #include "utilities.h"
13 
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16 
28 int
29 rotZ_cart (double x, double y, double z, double ang, double *xx, double *yy, double *zz)
30 {
31  *xx = cos (ang) * x - sin (ang) * y;
32  *yy = sin (ang) * x + cos (ang) * y;
33  *zz = z;
34 
35  return 0;
36 }
37 
49 int
50 rotY_cart (double x, double y, double z, double ang, double *xx, double *yy, double *zz)
51 {
52  *xx = cos (ang) * x + sin (ang) * z;
53  *yy = y;
54  *zz = -sin (ang) * x + cos (ang) * z;
55 
56  return 0;
57 }
58 
70 int
71 rotX_cart (double x, double y, double z, double ang, double *xx, double *yy, double *zz)
72 {
73  *xx = x;
74  *yy = cos (ang) * y - sin (ang) * z;
75  *zz = sin (ang) * y + cos (ang) * z;
76 
77  return 0;
78 }
79 
88 double
89 ang_one_two (double a1, double b1, double a2, double b2)
90 {
91  double coseno;
92  double sb1, sb2;
93 
94  sb1 = sin (b1);
95  sb2 = sin (b2);
96  coseno = sb1 * cos (a1) * sb2 * cos (a2) + sb1 * sin (a1) * sb2 * sin (a2) + cos (b1) * cos (b2);
97 
98  if (coseno > 1)
99  coseno = 1.;
100  if (coseno < -1)
101  coseno = -1.;
102 
103  double ang = acos (coseno);
104 
105  return (ang);
106 }
107 
113 int
115 {
116  int i, j, k, d, dmax, cont, ll, hx, hy, hz;
117  int rmax, r_int;
118  float mean, div, rl, rk, fct;
119  float wpix, wmean, i2, j2, k2;
120  float *pr, *pr1, *pr2;
121 
122  pr = (float *) p->data_pointer();
123 
124  hx = p->sizeX() / 2;
125  hy = p->sizeY() / 2;
126  hz = p->sizeZ() / 2;
127  ll = 2;
128  dmax = hz - 1;
129  pr1 = pr;
130  cont = 0;
131  mean = 0;
132  for (k = -hz; k < hz; k++)
133  for (j = -hy; j < hy; j++)
134  for (i = -hx; i < hx; i++)
135  {
136  d = k * k + j * j + i * i;
137  d = (int) sqrt (d);
138  if (d >= dmax - ll && d < dmax)
139  {
140  cont++;
141  mean += *pr1;
142  }
143  pr1++;
144  }
145  mean /= cont;
146  rmax = (hz - 1);
147  r_int = (hz - ll * 2 - 1);
148  div = (float) (2 * ll);
149  div = M_PI / div;
150  pr1 = pr;
151  for (k = -hz; k < hz; k++)
152  {
153  k2 = k * k;
154  for (i = -hy; i < hy; i++)
155  {
156  i2 = i * i;
157  for (j = -hx; j < hx; j++)
158  {
159  j2 = k2 + i2 + j * j;
160  fct = sqrt (j2);
161  if (fct >= r_int && fct <= rmax)
162  {
163  rl = fct - r_int;
164  rk = rmax - fct;
165  wpix = .5 + .5 * cos (rl * div);
166  wmean = .5 + .5 * cos (rk * div);
167  pr2 = pr1;
168  *pr1 = *pr2 * wpix + mean * wmean - mean;
169  }
170  else
171  {
172  if (fct > rmax)
173  *pr1 = 0.;
174  else
175  *pr1 -= mean;
176  }
177  pr1++;
178  }
179  }
180  }
181 
182  if (verbose & VERB_FULL)
183  cout << "count=" << cont << " mean=" << mean << endl << endl;
184 
185  return 0;
186 }
187 
194 {
195  unsigned long i, ntot;
196  float mean,*pr;
197 
198 
199  pr = (float *) p->data_pointer();
200  mean = *pr;
201  ntot = p->sizeX() * p->sizeY() * p->sizeZ() * p->images();
202 
203  if ( verbose & VERB_PROCESS )
204  printf("Shifting the values range of all images by %g\n\n", -mean);
205 
206  for (i = 0; i < ntot; i++,pr++)
207  *pr -= mean;
208 
209  return(0);
210 }
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
rotZ_cart
int rotZ_cart(double x, double y, double z, double ang, double *xx, double *yy, double *zz)
Rotates a vector of cartesian coordinates along the Z axis.
Definition: radon_util.cpp:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
verbose
int verbose
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
mean_to_0
int mean_to_0(Bimage *p)
Set each value equal to old_value-(first image pixel)
Definition: radon_util.cpp:193
Bimage::images
long images()
Definition: Bimage.h:504
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
ang_one_two
double ang_one_two(double a1, double b1, double a2, double b2)
Calculates the angle (in radians) from 2 vectors.
Definition: radon_util.cpp:89
Bimage
General image parameter class.
Definition: Bimage.h:177
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
rotY_cart
int rotY_cart(double x, double y, double z, double ang, double *xx, double *yy, double *zz)
Rotates a vector of cartesian coordinates along the Y axis.
Definition: radon_util.cpp:50
rotX_cart
int rotX_cart(double x, double y, double z, double ang, double *xx, double *yy, double *zz)
Rotates a vector of cartesian coordinates along the X axis.
Definition: radon_util.cpp:71
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:284
radon_util.h
sphere
int sphere(Bimage *p)
Definition: radon_util.cpp:114