Xmipp  v3.23.11-Nereus
Functions | Variables
Collaboration diagram for Splines:

Functions

double spatial_Bspline03 (const Matrix1D< double > &r)
 
double Bspline03LUT (double x)
 
double spatial_Bspline03LUT (const Matrix1D< double > &r)
 
double sum_spatial_Bspline03_Grid (const Grid &grid)
 
double spatial_Bspline03_proj (const Matrix1D< double > &r, const Matrix1D< double > &u)
 
void spatial_Bspline032voxels (const GridVolume &vol_splines, MultidimArray< double > *vol_voxels, int Zdim=0, int Ydim=0, int Xdim=0)
 

Variables

const int BSPLINE03_SUBSAMPLING = 2000
 

Detailed Description

Function Documentation

◆ Bspline03LUT()

double Bspline03LUT ( double  x)

Value of a Bspline of order 3 in a Look-Up Table.

Definition at line 30 of file splines.cpp.

31 {
32  static bool firstCall = true;
34  static const double deltax = 2.0 / BSPLINE03_SUBSAMPLING;
35  static const double ideltax = 1.0 / deltax;
36  if (firstCall)
37  {
39  table(i) = Bspline03(i * deltax);
40  firstCall = false;
41  }
42  auto i = (size_t)round(fabs(x) * ideltax);
43  if (i >= XSIZE(table)) return 0;
44  else return table(i);
45 }
doublereal * x
#define i
#define XSIZE(v)
double Bspline03(double Argument)
const int BSPLINE03_SUBSAMPLING
Definition: splines.h:53
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
int round(double x)
Definition: ap.cpp:7245

◆ spatial_Bspline03()

double spatial_Bspline03 ( const Matrix1D< double > &  r)
inline

Spline value. This function returns the value of a Bspline of order 3 at a given point

Definition at line 44 of file splines.h.

45 {
46  if (-2 <= XX(r) && XX(r) < 2 &&
47  -2 <= YY(r) && YY(r) < 2 &&
48  -2 <= ZZ(r) && ZZ(r) < 2)
49  return Bspline03(XX(r))*Bspline03(YY(r))*Bspline03(ZZ(r));
50  else return 0.0;
51 }
#define XX(v)
Definition: matrix1d.h:85
double Bspline03(double Argument)
#define YY(v)
Definition: matrix1d.h:93
#define ZZ(v)
Definition: matrix1d.h:101

◆ spatial_Bspline032voxels()

void spatial_Bspline032voxels ( const GridVolume vol_splines,
MultidimArray< double > *  vol_voxels,
int  Zdim = 0,
int  Ydim = 0,
int  Xdim = 0 
)

Splines —> Voxels. The voxel size is defined in the same grid as the spline volume.

However, you might give a size, usually set to 0, i.e., no external size. If no size is provided a size is produced such that all spline centers fit into the output volume.

Definition at line 386 of file splines.cpp.

388 {
389  // Resize and set starting corner .......................................
390  if (Zdim == 0 || Ydim == 0 || Xdim == 0)
391  {
392  Matrix1D<double> size = vol_splines.grid(0).highest -
393  vol_splines.grid(0).lowest;
394  Matrix1D<double> corner = vol_splines.grid(0).lowest;
395  (*vol_voxels).initZeros(CEIL(ZZ(size)), CEIL(YY(size)), CEIL(XX(size)));
396  STARTINGX(*vol_voxels) = FLOOR(XX(corner));
397  STARTINGY(*vol_voxels) = FLOOR(YY(corner));
398  STARTINGZ(*vol_voxels) = FLOOR(ZZ(corner));
399  }
400  else
401  {
402  (*vol_voxels).initZeros(Zdim, Ydim, Xdim);
403  (*vol_voxels).setXmippOrigin();
404  }
405 
406  // Convert each subvolume ...............................................
407  for (size_t i = 0; i < vol_splines.VolumesNo(); i++)
408  {
409  spatial_Bspline032voxels_SimpleGrid(vol_splines(i)(), vol_splines.grid(i),
410  vol_voxels);
411 #ifdef DEBUG
412  std::cout << "Spline grid no " << i << " stats: ";
413  vol_splines(i)().printStats();
414  std::cout << std::endl;
415  std::cout << "So far vol stats: ";
416  (*vol_voxels).printStats();
417  std::cout << std::endl;
418  VolumeXmipp save;
419  save() = *vol_voxels;
420  save.write((std::string)"PPPvoxels" + integerToString(i));
421 #endif
422  }
423 
424  // Now normalise the resulting volume ..................................
425  double inorm = 1.0 / sum_spatial_Bspline03_Grid(vol_splines.grid());
426  FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels)
427  A3D_ELEM(*vol_voxels, k, i, j) *= inorm;
428 
429  // Set voxels outside interest region to minimum value .................
430  double R = vol_splines.grid(0).get_interest_radius();
431  if (R != -1)
432  {
433  double R2 = (R - 6) * (R - 6);
434 
435  // Compute minimum value within sphere
436  double min_val = A3D_ELEM(*vol_voxels, 0, 0, 0);
437  FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels)
438  if (j*j + i*i + k*k <= R2 - 4)
439  min_val = XMIPP_MIN(min_val, A3D_ELEM(*vol_voxels, k, i, j));
440 
441  // Substitute minimum value
442  R2 = (R - 2) * (R - 2);
443  FOR_ALL_ELEMENTS_IN_ARRAY3D(*vol_voxels)
444  if (j*j + i*i + k*k >= R2)
445  A3D_ELEM(*vol_voxels, k, i, j) = min_val;
446  }
447 }
Matrix1D< double > highest
Definition: grids.h:161
String integerToString(int I, int _width, char fill_with)
Matrix1D< double > lowest
Definition: grids.h:158
#define STARTINGX(v)
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define STARTINGY(v)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
size_t VolumesNo() const
Definition: grids.h:1003
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define XX(v)
Definition: matrix1d.h:85
#define CEIL(x)
Definition: xmipp_macros.h:225
void write(const FileName &fn) const
void initZeros()
Definition: matrix1d.h:592
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
void spatial_Bspline032voxels_SimpleGrid(const MultidimArray< double > &vol_splines, const SimpleGrid &grid, MultidimArray< double > *vol_voxels, const MultidimArray< double > *vol_mask=nullptr)
Definition: splines.cpp:205
#define j
#define YY(v)
Definition: matrix1d.h:93
const SimpleGrid & grid(size_t n) const
Definition: grids.h:978
double sum_spatial_Bspline03_Grid(const Grid &grid)
Definition: splines.cpp:72
double get_interest_radius() const
Get reconstruction radius.
Definition: grids.h:268
#define STARTINGZ(v)
#define ZZ(v)
Definition: matrix1d.h:101

◆ spatial_Bspline03_proj()

double spatial_Bspline03_proj ( const Matrix1D< double > &  r,
const Matrix1D< double > &  u 
)

Spline projection. This function returns the value of the spline line integral through a straight line which passes through the point r with direction u

Definition at line 103 of file splines.cpp.

105 {
106  // Avoids divisions by zero and allows orthogonal rays computation
107  static Matrix1D<double> ur(3);
108  if (XX(u) == 0) XX(ur) = XMIPP_EQUAL_ACCURACY;
109  else XX(ur) = XX(u);
110  if (YY(u) == 0) YY(ur) = XMIPP_EQUAL_ACCURACY;
111  else YY(ur) = YY(u);
112  if (ZZ(u) == 0) ZZ(ur) = XMIPP_EQUAL_ACCURACY;
113  else ZZ(ur) = ZZ(u);
114 
115  // Some precalculated variables
116  double x_sign = SGN(XX(ur));
117  double y_sign = SGN(YY(ur));
118  double z_sign = SGN(ZZ(ur));
119 
120  // Compute the minimum and maximum alpha for the ray
121  double alpha_xmin = (-2 - XX(r)) / XX(ur);
122  double alpha_xmax = (2 - XX(r)) / XX(ur);
123  double alpha_ymin = (-2 - YY(r)) / YY(ur);
124  double alpha_ymax = (2 - YY(r)) / YY(ur);
125  double alpha_zmin = (-2 - ZZ(r)) / ZZ(ur);
126  double alpha_zmax = (2 - ZZ(r)) / ZZ(ur);
127 
128  double alpha_min = XMIPP_MAX(XMIPP_MIN(alpha_xmin, alpha_xmax),
129  XMIPP_MIN(alpha_ymin, alpha_ymax));
130  alpha_min = XMIPP_MAX(alpha_min, XMIPP_MIN(alpha_zmin, alpha_zmax));
131  double alpha_max = XMIPP_MIN(XMIPP_MAX(alpha_xmin, alpha_xmax),
132  XMIPP_MAX(alpha_ymin, alpha_ymax));
133  alpha_max = XMIPP_MIN(alpha_max, XMIPP_MAX(alpha_zmin, alpha_zmax));
134  if (alpha_max - alpha_min < XMIPP_EQUAL_ACCURACY) return 0.0;
135 
136 #ifdef DEBUG
137  std::cout << "Pixel: " << r.transpose() << std::endl
138  << "Dir: " << ur.transpose() << std::endl
139  << "Alpha x:" << alpha_xmin << " " << alpha_xmax << std::endl
140  << " " << (r + alpha_xmin*ur).transpose() << std::endl
141  << " " << (r + alpha_xmax*ur).transpose() << std::endl
142  << "Alpha y:" << alpha_ymin << " " << alpha_ymax << std::endl
143  << " " << (r + alpha_ymin*ur).transpose() << std::endl
144  << " " << (r + alpha_ymax*ur).transpose() << std::endl
145  << "Alpha z:" << alpha_zmin << " " << alpha_zmax << std::endl
146  << " " << (r + alpha_zmin*ur).transpose() << std::endl
147  << " " << (r + alpha_zmax*ur).transpose() << std::endl
148  << "alpha :" << alpha_min << " " << alpha_max << std::endl
149  << std::endl;
150 #endif
151 
152  // Compute the first point in the volume intersecting the ray
153  static Matrix1D<double> v(3);
154  V3_BY_CT(v, ur, alpha_min);
155  V3_PLUS_V3(v, r, v);
156 
157 #ifdef DEBUG
158  std::cout << "First entry point: " << v.transpose() << std::endl;
159  std::cout << " Alpha_min: " << alpha_min << std::endl;
160 #endif
161 
162  // Follow the ray
163  double alpha = alpha_min;
164  double ray_sum = 0;
165  do
166  {
167  double alpha_x = (XX(v) + x_sign - XX(r)) / XX(ur);
168  double alpha_y = (YY(v) + y_sign - YY(r)) / YY(ur);
169  double alpha_z = (ZZ(v) + z_sign - ZZ(r)) / ZZ(ur);
170 
171  // Which dimension will ray move next step into?, it isn't necessary to be only
172  // one.
173  double diffx = ABS(alpha - alpha_x);
174  double diffy = ABS(alpha - alpha_y);
175  double diffz = ABS(alpha - alpha_z);
176  double diff_alpha = XMIPP_MIN(XMIPP_MIN(diffx, diffy), diffz);
177  ray_sum += spatial_Bspline03_integral(r, ur, alpha, alpha + diff_alpha);
178 
179  // Update alpha and the next entry point
180  if (ABS(diff_alpha - diffx) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_x;
181  if (ABS(diff_alpha - diffy) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_y;
182  if (ABS(diff_alpha - diffz) <= XMIPP_EQUAL_ACCURACY) alpha = alpha_z;
183  XX(v) += diff_alpha * XX(ur);
184  YY(v) += diff_alpha * YY(ur);
185  ZZ(v) += diff_alpha * ZZ(ur);
186 
187 #ifdef DEBUG
188  std::cout << "Alpha x,y,z: " << alpha_x << " " << alpha_y
189  << " " << alpha_z << " ---> " << alpha << std::endl;
190 
191  std::cout << " Next entry point: " << v.transpose() << std::endl
192  << " diff_alpha: " << diff_alpha << std::endl
193  << " ray_sum: " << ray_sum << std::endl
194  << " Alfa tot: " << alpha << "alpha_max: " << alpha_max <<
195  std::endl;
196 
197 #endif
198  }
199  while ((alpha_max - alpha) > XMIPP_EQUAL_ACCURACY);
200  return ray_sum;
201 }
double alpha
Smoothness parameter.
Definition: blobs.h:121
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
double spatial_Bspline03_integral(const Matrix1D< double > &r, const Matrix1D< double > &u, double alpha0, double alphaF)
Definition: splines.cpp:92
Matrix1D< T > transpose() const
Definition: matrix1d.cpp:644
#define V3_BY_CT(a, b, c)
Definition: matrix1d.h:238
#define XX(v)
Definition: matrix1d.h:85
void transpose(double *array, int size)
#define XMIPP_EQUAL_ACCURACY
Definition: xmipp_macros.h:119
#define ABS(x)
Definition: xmipp_macros.h:142
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
#define YY(v)
Definition: matrix1d.h:93
#define SGN(x)
Definition: xmipp_macros.h:155
#define ZZ(v)
Definition: matrix1d.h:101
#define V3_PLUS_V3(a, b, c)
Definition: matrix1d.h:190

◆ spatial_Bspline03LUT()

double spatial_Bspline03LUT ( const Matrix1D< double > &  r)
inline

Spline value with Look-Up Table. This function returns the value of a Bspline of order 3 at a given point

Definition at line 60 of file splines.h.

61 {
62  if (-2 <= XX(r) && XX(r) < 2 &&
63  -2 <= YY(r) && YY(r) < 2 &&
64  -2 <= ZZ(r) && ZZ(r) < 2)
65  return Bspline03LUT(XX(r))*Bspline03LUT(YY(r))*Bspline03LUT(ZZ(r));
66  else return 0.0;
67 }
#define XX(v)
Definition: matrix1d.h:85
#define YY(v)
Definition: matrix1d.h:93
double Bspline03LUT(double x)
Definition: splines.cpp:30
#define ZZ(v)
Definition: matrix1d.h:101

◆ sum_spatial_Bspline03_Grid()

double sum_spatial_Bspline03_Grid ( const Grid grid)

Sum of a single spline over a grid. As a normalisation factor, the sum of the splines values over a given grid is needed. This function puts a spline at coordinate (0,0,0) and sums all the splines values at points of the grid which are inside the spline. It doesn't matter if the grid is compound or not.

Definition at line 72 of file splines.cpp.

73 {
74  double sum = 0;
75  for (size_t i = 0; i < grid.GridsNo(); i++)
76  sum += sum_spatial_Bspline03_SimpleGrid(grid(i));
77  return sum;
78 }
size_t GridsNo() const
Definition: grids.h:536
double sum_spatial_Bspline03_SimpleGrid(const SimpleGrid &grid)
Definition: splines.cpp:48
#define i

Variable Documentation

◆ BSPLINE03_SUBSAMPLING

const int BSPLINE03_SUBSAMPLING = 2000

Definition at line 53 of file splines.h.