Xmipp  v3.23.11-Nereus
Macros | Functions
splines.cpp File Reference
#include "splines.h"
#include "integration.h"
Include dependency graph for splines.cpp:

Go to the source code of this file.

Macros

#define x0   STARTINGX(*vol_voxels)
 
#define xF   FINISHINGX(*vol_voxels)
 
#define y0   STARTINGY(*vol_voxels)
 
#define yF   FINISHINGY(*vol_voxels)
 
#define z0   STARTINGZ(*vol_voxels)
 
#define zF   FINISHINGZ(*vol_voxels)
 

Functions

double Bspline03LUT (double x)
 
double sum_spatial_Bspline03_SimpleGrid (const SimpleGrid &grid)
 
double sum_spatial_Bspline03_Grid (const Grid &grid)
 
double spatial_Bspline03_integralf (double alpha)
 
double spatial_Bspline03_integral (const Matrix1D< double > &r, const Matrix1D< double > &u, double alpha0, double alphaF)
 
double spatial_Bspline03_proj (const Matrix1D< double > &r, const Matrix1D< double > &u)
 
void spatial_Bspline032voxels_SimpleGrid (const MultidimArray< double > &vol_splines, const SimpleGrid &grid, MultidimArray< double > *vol_voxels, const MultidimArray< double > *vol_mask=nullptr)
 
void spatial_Bspline032voxels (const GridVolume &vol_splines, MultidimArray< double > *vol_voxels, int Zdim, int Ydim, int Xdim)
 

Macro Definition Documentation

◆ x0

#define x0   STARTINGX(*vol_voxels)

◆ xF

#define xF   FINISHINGX(*vol_voxels)

◆ y0

#define y0   STARTINGY(*vol_voxels)

◆ yF

#define yF   FINISHINGY(*vol_voxels)

◆ z0

#define z0   STARTINGZ(*vol_voxels)

◆ zF

#define zF   FINISHINGZ(*vol_voxels)

Function Documentation

◆ spatial_Bspline032voxels_SimpleGrid()

void spatial_Bspline032voxels_SimpleGrid ( const MultidimArray< double > &  vol_splines,
const SimpleGrid grid,
MultidimArray< double > *  vol_voxels,
const MultidimArray< double > *  vol_mask = nullptr 
)

Definition at line 205 of file splines.cpp.

209 {
210  Matrix1D<double> act_coord(3); // Coord: Actual position inside
211  // the voxel volume without deforming
212  Matrix1D<double> beginZ(3); // Coord: Voxel coordinates of the
213  // blob at the 3D point
214  // (z0,YY(lowest),XX(lowest))
215  Matrix1D<double> beginY(3); // Coord: Voxel coordinates of the
216  // blob at the 3D point
217  // (z0,y0,XX(lowest))
218  Matrix1D<int> corner2(3), corner1(3); // Coord: Corners of the blob in the voxel volume
219  Matrix1D<double> gcurrent(3); // Position in g of current point
220  int i, j, k; // Index within the blob volume
221  bool process; // True if this blob has to be
222  // processed
223  double spline_radius = 2 * sqrt(3.0);
224 
225  // Some aliases
226 #define x0 STARTINGX(*vol_voxels)
227 #define xF FINISHINGX(*vol_voxels)
228 #define y0 STARTINGY(*vol_voxels)
229 #define yF FINISHINGY(*vol_voxels)
230 #define z0 STARTINGZ(*vol_voxels)
231 #define zF FINISHINGZ(*vol_voxels)
232 
233 #ifdef DEBUG
234  bool condition = true;
235  (*vol_voxels)().printShape();
236  std::cout << std::endl;
237  std::cout << "x0= " << x0 << " xF= " << xF << std::endl;
238  std::cout << "y0= " << y0 << " yF= " << yF << std::endl;
239  std::cout << "z0= " << z0 << " zF= " << zF << std::endl;
240  std::cout << grid;
241 #endif
242 
243  // Convert the whole grid ...............................................
244  // Corner of the plane defined by Z. These coordinates are in the
245  // universal coord. system
246  grid.grid2universe(grid.lowest, beginZ);
247 
248  Matrix1D<double> grid_index(3);
249  for (k = (int) ZZ(grid.lowest); k <= (int) ZZ(grid.highest); k++)
250  {
251  // Corner of the row defined by Y
252  beginY = beginZ;
253  for (i = (int) YY(grid.lowest); i <= (int) YY(grid.highest); i++)
254  {
255  // First point in the row
256  act_coord = beginY;
257  for (j = (int) XX(grid.lowest); j <= (int) XX(grid.highest); j++)
258  {
259  VECTOR_R3(grid_index, j, i, k);
260 #ifdef DEBUG
261  if (condition)
262  {
263  printf("Dealing spline at (%d,%d,%d) = %f\n", j, i, k, A3D_ELEM(vol_splines, k, i, j));
264  std::cout << "Center of the blob "
265  << act_coord.transpose() << std::endl;
266  }
267 #endif
268 
269  // These two corners are also real valued
270  process = true;
271  if (XX(act_coord) >= xF) process = false;
272  if (YY(act_coord) >= yF) process = false;
273  if (ZZ(act_coord) >= zF) process = false;
274  if (XX(act_coord) <= x0) process = false;
275  if (YY(act_coord) <= y0) process = false;
276  if (ZZ(act_coord) <= z0) process = false;
277 #ifdef DEBUG
278  if (!process && condition) std::cout << " It is outside output volume\n";
279 #endif
280  if (!grid.is_interesting(act_coord))
281  {
282 #ifdef DEBUG
283  if (process && condition) std::cout << " It is not interesting\n";
284 #endif
285  process = false;
286  }
287 
288  if (process)
289  {
290  V3_PLUS_CT(corner1, act_coord, -spline_radius);
291  V3_PLUS_CT(corner2, act_coord, spline_radius);
292 #ifdef DEBUG
293  if (condition)
294  {
295  std::cout << "Corner 1 for this point " << corner1.transpose() << std::endl;
296  std::cout << "Corner 2 for this point " << corner2.transpose() << std::endl;
297  }
298 #endif
299 
300  // Clip the corners to the volume borders
301  XX(corner1) = ROUND(CLIP(XX(corner1), x0, xF));
302  YY(corner1) = ROUND(CLIP(YY(corner1), y0, yF));
303  ZZ(corner1) = ROUND(CLIP(ZZ(corner1), z0, zF));
304  XX(corner2) = ROUND(CLIP(XX(corner2), x0, xF));
305  YY(corner2) = ROUND(CLIP(YY(corner2), y0, yF));
306  ZZ(corner2) = ROUND(CLIP(ZZ(corner2), z0, zF));
307 #ifdef DEBUG
308  if (condition)
309  {
310  std::cout << "Clipped and rounded Corner 1 " << corner1.transpose() << std::endl;
311  std::cout << "Clipped and rounded Corner 2 " << corner2.transpose() << std::endl;
312  }
313 #endif
314 
315  // Effectively convert
316  for (int iz = ZZ(corner1); iz <= ZZ(corner2); iz++)
317  {
318  double intz=iz;
319  for (int iy = YY(corner1); iy <= YY(corner2); iy++)
320  {
321  double inty=iy;
322  for (int ix = XX(corner1); ix <= XX(corner2); ix++)
323  {
324  if (vol_mask != nullptr)
325  if (!A3D_ELEM(*vol_mask, iz, iy, ix)) continue;
326  double intx=ix;
327 
328  // Compute the spline value at this point
329  VECTOR_R3(gcurrent, static_cast<double>(intx),
330  static_cast<double>(inty), static_cast<double>(intz));
331  V3_MINUS_V3(gcurrent, act_coord, gcurrent);
332  double spline_value = spatial_Bspline03(gcurrent);
333 #ifdef DEBUG_MORE
334  if (condition)
335  {
336  std::cout << "At (" << intx << ","
337  << inty << "," << intz << ") value="
338  << spline_value;
339  std::cout.flush();
340  }
341 #endif
342 
343  // Add at that position the corresponding spline value
344  A3D_ELEM(*vol_voxels, iz, iy, ix) +=
345  A3D_ELEM(vol_splines, k, i, j) * spline_value;
346 #ifdef DEBUG_MORE
347  if (condition)
348  {
349  std::cout << " adding " << A3D_ELEM(vol_splines, k, i, j)
350  << " * " << value_spline << " = "
351  << A3D_ELEM(vol_splines, k, i, j)*
352  value_spline << std::endl;
353  std::cout.flush();
354  }
355 #endif
356  }
357  }
358  }
359  }
360 
361  // Prepare for next iteration
362  XX(act_coord) = XX(act_coord) + grid.relative_size * grid.basis(0, 0);
363  YY(act_coord) = YY(act_coord) + grid.relative_size * grid.basis(1, 0);
364  ZZ(act_coord) = ZZ(act_coord) + grid.relative_size * grid.basis(2, 0);
365  }
366  XX(beginY) = XX(beginY) + grid.relative_size * grid.basis(0, 1);
367  YY(beginY) = YY(beginY) + grid.relative_size * grid.basis(1, 1);
368  ZZ(beginY) = ZZ(beginY) + grid.relative_size * grid.basis(2, 1);
369  }
370  XX(beginZ) = XX(beginZ) + grid.relative_size * grid.basis(0, 2);
371  YY(beginZ) = YY(beginZ) + grid.relative_size * grid.basis(1, 2);
372  ZZ(beginZ) = ZZ(beginZ) + grid.relative_size * grid.basis(2, 2);
373  }
374 }
#define zF
#define V3_PLUS_CT(a, b, c)
Definition: matrix1d.h:220
void grid2universe(const Matrix1D< double > &gv, Matrix1D< double > &uv) const
Definition: grids.h:318
#define y0
void sqrt(Image< double > &op)
#define xF
#define V3_MINUS_V3(a, b, c)
Definition: matrix1d.h:202
double spatial_Bspline03(const Matrix1D< double > &r)
Definition: splines.h:44
#define z0
#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 CLIP(x, x0, xF)
Definition: xmipp_macros.h:260
#define A3D_ELEM(V, k, i, j)
#define XX(v)
Definition: matrix1d.h:85
#define ROUND(x)
Definition: xmipp_macros.h:210
#define j
#define YY(v)
Definition: matrix1d.h:93
#define x0
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
#define yF
#define ZZ(v)
Definition: matrix1d.h:101

◆ spatial_Bspline03_integral()

double spatial_Bspline03_integral ( const Matrix1D< double > &  r,
const Matrix1D< double > &  u,
double  alpha0,
double  alphaF 
)

Definition at line 92 of file splines.cpp.

94 {
95  global_r = r;
96  global_u = u;
97  return integrateNewtonCotes(&spatial_Bspline03_integralf, alpha0, alphaF, 9);
98 }
double spatial_Bspline03_integralf(double alpha)
Definition: splines.cpp:84
double integrateNewtonCotes(double(*f)(double), double a, double b, int N)
Definition: integration.cpp:32
doublereal * u

◆ spatial_Bspline03_integralf()

double spatial_Bspline03_integralf ( double  alpha)

Definition at line 84 of file splines.cpp.

85 {
86  XX(global_aux) = XX(global_r) + alpha * XX(global_u);
87  YY(global_aux) = YY(global_r) + alpha * YY(global_u);
88  ZZ(global_aux) = ZZ(global_r) + alpha * ZZ(global_u);
89  return spatial_Bspline03LUT(global_aux);
90 }
double alpha
Smoothness parameter.
Definition: blobs.h:121
double spatial_Bspline03LUT(const Matrix1D< double > &r)
Definition: splines.h:60
#define XX(v)
Definition: matrix1d.h:85
#define YY(v)
Definition: matrix1d.h:93
#define ZZ(v)
Definition: matrix1d.h:101

◆ sum_spatial_Bspline03_SimpleGrid()

double sum_spatial_Bspline03_SimpleGrid ( const SimpleGrid grid)

Definition at line 48 of file splines.cpp.

49 {
50  Matrix1D<double> gr(3), ur(3), corner1(3), corner2(3);
51  int i, j, k;
52  double sum = 0.0;
53 
54 // Compute the limits of the spline in the grid coordinate system
55  grid.universe2grid(vectorR3(-2.0, -2.0, -2.0), corner1);
56  grid.universe2grid(vectorR3(2.0, 2.0, 2.0), corner2);
57 
58 // Compute the sum in the points inside the grid
59 // The integer part of the vectors is taken for not picking points
60 // just in the border of the spline, which we know they are 0.
61  for (i = (int)XX(corner1); i <= (int)XX(corner2); i++)
62  for (j = (int)YY(corner1); j <= (int)YY(corner2); j++)
63  for (k = (int)ZZ(corner1); k <= (int)ZZ(corner2); k++)
64  {
65  VECTOR_R3(gr, i, j, k);
66  grid.grid2universe(gr, ur);
67  sum += spatial_Bspline03(ur);
68  }
69  return sum;
70 }
void universe2grid(const Matrix1D< double > &uv, Matrix1D< double > &gv) const
Definition: grids.h:349
void grid2universe(const Matrix1D< double > &gv, Matrix1D< double > &uv) const
Definition: grids.h:318
Matrix1D< double > vectorR3(double x, double y, double z)
Definition: matrix1d.cpp:892
double spatial_Bspline03(const Matrix1D< double > &r)
Definition: splines.h:44
#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 XX(v)
Definition: matrix1d.h:85
#define j
#define YY(v)
Definition: matrix1d.h:93
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
#define ZZ(v)
Definition: matrix1d.h:101