Xmipp  v3.23.11-Nereus
Classes | Typedefs | Functions
Collaboration diagram for Grids:

Classes

class  SimpleGrid
 
class  Grid
 
class  GridVolumeT< T >
 

Typedefs

typedef GridVolumeT< double > GridVolume
 

Functions

template<class T >
std::ostream & operator<< (std::ostream &o, const GridVolumeT< T > &GV)
 

UsefulGrids Some useful grids

These are already-built grids to make your task easier. You can find here Simple Cubic (CC), Face-Centered (FCC) and Body-Centered Cubic (BCC) grids. Most of them are supposed to have its origin in the middle of the two defining corners. The defining corners (corner1 and corner2) are directly related with lowest and highest indexes inside the grid respectively. The difference is that the corners are given ALWAYS in the universal coordinate system while the lowest and highest are vectors in the grid coordinate system

SimpleGrid Create_CC_grid (double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
 
Grid Create_CC_grid (double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
 
Grid Create_CC_grid (double relative_size, int Zdim, int Ydim, int Xdim)
 
Grid Create_BCC_grid (double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
 
Grid Create_FCC_grid (double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
 
SimpleGrid Create_grid_within_sphere (double relative_size, const Matrix1D< double > &origin, const Matrix1D< double > &X, const Matrix1D< double > &Y, const Matrix1D< double > &Z, double R2)
 
Grid Create_CC_grid (double relative_size, double R)
 
Grid Create_BCC_grid (double relative_size, double R)
 
Grid Create_FCC_grid (double relative_size, double R)
 
#define CC   0
 CC identifier. More...
 
#define FCC   1
 FCC identifier. More...
 
#define BCC   2
 BCC identifier. More...
 

Detailed Description

The grids are one of the most basic things in the reconstruction process, since the reconstructed volumes are expressed as a linear combination of a volume basis function weighted and shifted to all positions defined by the grid. Grids in Xmipp may be as complex as you liked, a complex grid is supposed to be a superposition of simpler grids. Simple grids maintain information about the simple grids themselves (orientation, spacing, ...) while complex ones are only collections of simple grids. Usual grids as BCC (Body Centered Cubic) or FCC (Face Centered Cubic), can be expressed as the superposition of two CC (Cubic) grids.

It is important to notice that the existence of this class makes the reconstruction algorithms independent from the underlying grid, incrementing the reusability of the code.

Macro Definition Documentation

◆ BCC

#define BCC   2

BCC identifier.

Definition at line 589 of file grids.h.

◆ CC

#define CC   0

CC identifier.

Definition at line 585 of file grids.h.

◆ FCC

#define FCC   1

FCC identifier.

Definition at line 587 of file grids.h.

Typedef Documentation

◆ GridVolume

typedef GridVolumeT<double> GridVolume

Definition at line 1496 of file grids.h.

Function Documentation

◆ Create_BCC_grid() [1/2]

Grid Create_BCC_grid ( double  relative_size,
const Matrix1D< double > &  corner1,
const Matrix1D< double > &  corner2 
)

Create a BCC grid as a Complex grid (two corners). This function constructs two CC Simple grids with the following parameters

Grid(0) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: ROUNDnD((corner1+corner2)/2)
Grid(1) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: ROUNDnD((corner1+corner2)/2)+relative_size/2*vectorR3(1,1,1)

As you see the BCC grid is the superposition of 2 CC grids one shifted with the other by (0.5,0.5,0.5) units in the grid coordinate system.

Definition at line 251 of file grids.cpp.

253 {
254  Grid result;
255  SimpleGrid aux_grid;
256  Matrix1D<double> origin = (corner1 + corner2) / 2;
257  origin.selfROUND();
258 
259  //Even Slice
260  // 0 1 2 3 4 5 6 7 8 9 10 11 12 (Col)
261  // 0 A A A A A A A
262  // 1
263  // 2 A A A A A A A
264  // 3
265  // 4 A A A A A A A
266  // 5
267  // 6 A A A A A A A
268  // 7
269  // 8 A A A A A A A
270  // 9
271  // 10 A A A A A A A
272  // 11
273  // 12 A A A A A A A
274  //(Row)
275  //
276  //Odd Slice
277  // 0 1 2 3 4 5 6 7 8 9 10 11 12 (Col)
278  // 0
279  // 1 B B B B B B
280  // 2
281  // 3 B B B B B B
282  // 4
283  // 5 B B B B B B
284  // 6
285  // 7 B B B B B B
286  // 8
287  // 9 B B B B B B
288  // 10
289  // 11 B B B B B B
290  // 12
291  //(Row)
292 
293  // Grid A
294  aux_grid = Create_CC_grid(relative_size, corner1, corner2, origin);
295  result.add_grid(aux_grid);
296 
297  // Grid B
298  origin = origin + relative_size / 2 * vectorR3(1., 1., 1.);
299  aux_grid = Create_CC_grid(relative_size, corner1, corner2, origin);
300  result.add_grid(aux_grid);
301 
302  return result;
303 }
void selfROUND()
Definition: matrix1d.cpp:522
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
Matrix1D< double > vectorR3(double x, double y, double z)
Definition: matrix1d.cpp:892
Definition: grids.h:479
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_BCC_grid() [2/2]

Grid Create_BCC_grid ( double  relative_size,
double  R 
)

Create a BCC grid such that a sphere of radius R and centered at the origin is inside.

origin=(0,0,0);
x=(0.5,0.5,-0.5);
y=(0.5,-0.5,0.5);
z=(-0.5,0.5,0.5);

Definition at line 446 of file grids.cpp.

447 {
448  Grid result;
449  SimpleGrid aux_grid;
450 
451  Matrix1D<double> origin(3);
452  origin.initZeros();
453  Matrix1D<double> x(3);
454  Matrix1D<double> y(3);
455  Matrix1D<double> z(3);
456  VECTOR_R3(x, 0.5, 0.5, -0.5);
457  VECTOR_R3(y, 0.5, -0.5, 0.5);
458  VECTOR_R3(z, -0.5, 0.5, 0.5);
459  aux_grid = Create_grid_within_sphere(relative_size, origin, x, y, z, R * R);
460  result.add_grid(aux_grid);
461  return result;
462 }
SimpleGrid Create_grid_within_sphere(double relative_size, const Matrix1D< double > &origin, const Matrix1D< double > &X, const Matrix1D< double > &Y, const Matrix1D< double > &Z, double R2)
Definition: grids.cpp:376
static double * y
Definition: grids.h:479
doublereal * x
double z
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_CC_grid() [1/4]

SimpleGrid Create_CC_grid ( double  relative_size,
const Matrix1D< double > &  corner1,
const Matrix1D< double > &  corner2,
const Matrix1D< double > &  origin 
)

Create a CC grid as a Simple grid. The parameters of the CC grid are:

axes: (1,0,0),(0,1,0),(0,0,1)
lowest: FLOORnD(grid.universe2grid(corner1))
highest: CEILnD (grid.universe2grid(corner2))
relative_size: specified
origin: specified

where the specified means that it has been specified as a parameter of the function. The resulting grid is ready to work. There are two roundings for the lowest and highest indexes, they are such that corner1 and corner2 are guaranteed to be inside the Cubic grid. It might be that due to the relative size you are including more points in the universal grid that needed. Look at the following example, imagine that you have a relative size of 2.75 and that you want a cubic grid between (-1,-1,-1) and (1,1,1) (in the universal coord. system), with origin at (0,0,0); then the smallest cubic grid that includes the corners is also defined between (-1,-1,-1) and (1,1,1) in the grid system, but in the universal system these points corresponds to (-2.75,-2.75,-2.75) and (2.75,2.75,2.75). You see that you are including points (specifically, (-2,-2,-2), (-2,-2,-1), ...) that you didn't intend at the beginning, but remember that with this relative size, the resulting CC grid is the smallest one which includes the given corners.

Definition at line 196 of file grids.cpp.

198 {
199  SimpleGrid grid;
200 
201  // The vectors of the grid are the default ones of (1,0,0), (0,1,0),
202  // and (0,0,1), and its inverse matrix is already computed
203  grid.relative_size = relative_size;
204  grid.origin = origin;
205 
206  // Compute the lowest and highest indexes inside the grid
207  grid.universe2grid(corner1, grid.lowest);
208  grid.lowest.selfFLOOR();
209  grid.universe2grid(corner2, grid.highest);
210  grid.highest.selfCEIL();
211 
212  grid.R2 = -1;
213  return grid;
214 }
void universe2grid(const Matrix1D< double > &uv, Matrix1D< double > &gv) const
Definition: grids.h:349
Matrix1D< double > highest
Definition: grids.h:161
Matrix1D< double > lowest
Definition: grids.h:158
double R2
Definition: grids.h:170
double relative_size
Measuring unit in the grid coordinate system.
Definition: grids.h:163
void selfFLOOR()
Definition: matrix1d.cpp:499
Matrix1D< double > origin
Origin of the grid in the Universal coordinate system.
Definition: grids.h:165
void selfCEIL()
Definition: matrix1d.cpp:476

◆ Create_CC_grid() [2/4]

Grid Create_CC_grid ( double  relative_size,
const Matrix1D< double > &  corner1,
const Matrix1D< double > &  corner2 
)

Create a CC grid as a Complex grid (two corners). This function makes a call to the previous one with

corner1: specified
corner2: specified
relative_size: specified
origin: ROUNDnD((corner1+corner2)/2)

That is to say, the origin of the grid is at its center, lowest and highest indexes are nearly symmetrical (lowest=-highest). The possible asymetries come from the ROUNDnD in the origin calculation.

Definition at line 217 of file grids.cpp.

219 {
220  Grid result;
221  SimpleGrid aux_grid;
222 
223  Matrix1D<double> origin = (corner1 + corner2) / 2;
225  if (ABS(ROUND(origin(i))-origin(i))<0.45)
226  origin(i)=ROUND(origin(i));
227  else
228  origin(i)=CEIL(origin(i));
229  aux_grid = Create_CC_grid(relative_size, corner1, corner2, origin);
230  result.add_grid(aux_grid);
231  return result;
232 }
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
Definition: grids.h:479
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
#define CEIL(x)
Definition: xmipp_macros.h:225
#define ABS(x)
Definition: xmipp_macros.h:142
#define ROUND(x)
Definition: xmipp_macros.h:210
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_CC_grid() [3/4]

Grid Create_CC_grid ( double  relative_size,
int  Zdim,
int  Ydim,
int  Xdim 
)

Create a CC grid as a Complex grid (size). This function makes a call to the previous one with

corner1: -origin
corner2: vectorR3(Xdim,Ydim,Zdim)-origin-1
relative_size: specified
origin: vectorR3((int)(Xdim/2.0),(int)(Ydim/2.0),(int)(Zdim/2.0))

That is to say, the origin of the grid is at its center, corner1 and corner2 are chosen such that from corner1 to corner2 (both included) there are exactly (Xdim,Ydim,Zdim) samples in the universal grid. The resulting volume is symmetrical (corner1=-corner2) if the sizes are odd in all directions, and is not if the sizes are even.

Definition at line 234 of file grids.cpp.

235 {
236  Grid result;
237  SimpleGrid aux_grid;
238 
239  Matrix1D<double> origin =
240  vectorR3((double)FLOOR(Xdim / 2.0), (double)FLOOR(Ydim / 2.0),
241  (double)FLOOR(Zdim / 2.0));
242  aux_grid = Create_CC_grid(relative_size, -origin,
243  vectorR3((double)Xdim, (double)Ydim, (double)Zdim) - origin - 1,
244  vectorR3(0.0,0.0,0.0));
245  result.add_grid(aux_grid);
246 
247  return result;
248 }
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
Matrix1D< double > vectorR3(double x, double y, double z)
Definition: matrix1d.cpp:892
Definition: grids.h:479
#define FLOOR(x)
Definition: xmipp_macros.h:240
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_CC_grid() [4/4]

Grid Create_CC_grid ( double  relative_size,
double  R 
)

Create a CC grid such that a sphere of radius R and centered at the origin is inside.

origin=(0,0,0);
x=(1,0,0);
y=(0,1,0);
z=(0,0,1);

Definition at line 427 of file grids.cpp.

428 {
429  Grid result;
430  SimpleGrid aux_grid;
431 
432  Matrix1D<double> origin(3);
433  origin.initZeros();
434  Matrix1D<double> x(3);
435  Matrix1D<double> y(3);
436  Matrix1D<double> z(3);
437  VECTOR_R3(x, 1, 0, 0);
438  VECTOR_R3(y, 0, 1, 0);
439  VECTOR_R3(z, 0, 0, 1);
440  aux_grid = Create_grid_within_sphere(relative_size, origin, x, y, z, R * R);
441  result.add_grid(aux_grid);
442  return result;
443 }
SimpleGrid Create_grid_within_sphere(double relative_size, const Matrix1D< double > &origin, const Matrix1D< double > &X, const Matrix1D< double > &Y, const Matrix1D< double > &Z, double R2)
Definition: grids.cpp:376
static double * y
Definition: grids.h:479
doublereal * x
double z
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_FCC_grid() [1/2]

Grid Create_FCC_grid ( double  relative_size,
const Matrix1D< double > &  corner1,
const Matrix1D< double > &  corner2 
)

Create a FCC grid as a Complex grid (two corners). This function constructs four CC Simple grids with the following parameters

origin: ROUNDnD((corner1+corner2)/2)
Grid(0) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: origin
Grid(1) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: origin+relative_size/2*vectorR3(0,1,1)
Grid(2) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: origin+relative_size/2*vectorR3(1,0,1)
Grid(3) -------------------------------------
corner1: specified
corner2: specified
relative_size: specified
origin: origin+relative_size/2*vectorR3(1,1,0)

Definition at line 306 of file grids.cpp.

308 {
309 
310  Grid result;
311  SimpleGrid aux_grid;
312  Matrix1D<double> aux_origin;
313  Matrix1D<double> cornerb;
314  Matrix1D<double> origin = (corner1 + corner2) / 2;
315  origin.selfROUND();
316 
317  //Even Slice
318  // 0 1 2 3 4 5 6 7 8 9 10 11 12 (Col)
319  // 0 A A A A A A A
320  // 1 B B B B B B
321  // 2 A A A A A A A
322  // 3 B B B B B B
323  // 4 A A A A A A A
324  // 5 B B B B B B
325  // 6 A A A A A A A
326  // 7 B B B B B B
327  // 8 A A A A A A A
328  // 9 B B B B B B
329  // 10 A A A A A A A
330  // 11 B B B B B B
331  // 12 A A A A A A A
332  //(Row)
333  //
334  //Odd Slice
335  // 0 1 2 3 4 5 6 7 8 9 10 11 12 (Col)
336  // 0 C C C C C C
337  // 1 D D D D D D D
338  // 2 C C C C C C
339  // 3 D D D D D D D
340  // 4 C C C C C C
341  // 5 D D D D D D D
342  // 6 C C C C C C
343  // 7 D D D D D D D
344  // 8 C C C C C C
345  // 9 D D D D D D D
346  // 10 C C C C C C
347  // 11 D D D D D D D
348  // 12 C C C C C C
349  //(Row)
350 
351  // Grid A
352  aux_grid = Create_CC_grid(relative_size, corner1, corner2, origin);
353  result.add_grid(aux_grid);
354  // Grid D
355  aux_origin = origin + relative_size / 2 * vectorR3(0., 1., 1.);
356  aux_grid = Create_CC_grid(relative_size, corner1, corner2, aux_origin);
357  result.add_grid(aux_grid);
358  // Grid C
359  aux_origin = origin + relative_size / 2 * vectorR3(1., 0., 1.);
360  aux_grid = Create_CC_grid(relative_size, corner1, corner2, aux_origin);
361  result.add_grid(aux_grid);
362  // Grid B
363  cornerb = corner2;
364  cornerb(0) = cornerb(0) - 1;
365  cornerb(1) = cornerb(1) - 1;
366  aux_origin = origin + relative_size / 2 * vectorR3(1., 1., 0.);
367  aux_grid = Create_CC_grid(relative_size, corner1, cornerb, aux_origin);
368  result.add_grid(aux_grid);
369 
370  return result;
371 }
void selfROUND()
Definition: matrix1d.cpp:522
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
Matrix1D< double > vectorR3(double x, double y, double z)
Definition: matrix1d.cpp:892
Definition: grids.h:479
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_FCC_grid() [2/2]

Grid Create_FCC_grid ( double  relative_size,
double  R 
)

Create a FCC grid such that a sphere of radius R and centered at the origin is inside.

origin=(0,0,0);
x=(0.5,0.5,0);
y=(0.5,0,0.5);
z=(0,0.5,0.5);

Definition at line 465 of file grids.cpp.

466 {
467  Grid result;
468  SimpleGrid aux_grid;
469 
470  Matrix1D<double> origin(3);
471  origin.initZeros();
472  Matrix1D<double> x(3);
473  Matrix1D<double> y(3);
474  Matrix1D<double> z(3);
475  VECTOR_R3(x, 0.5, 0.5, 0);
476  VECTOR_R3(y, 0.5, 0, 0.5);
477  VECTOR_R3(z, 0, 0.5, 0.5);
478  aux_grid = Create_grid_within_sphere(relative_size, origin, x, y, z, R * R);
479  result.add_grid(aux_grid);
480  return result;
481 }
SimpleGrid Create_grid_within_sphere(double relative_size, const Matrix1D< double > &origin, const Matrix1D< double > &X, const Matrix1D< double > &Y, const Matrix1D< double > &Z, double R2)
Definition: grids.cpp:376
static double * y
Definition: grids.h:479
doublereal * x
double z
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491

◆ Create_grid_within_sphere()

SimpleGrid Create_grid_within_sphere ( double  relative_size,
const Matrix1D< double > &  origin,
const Matrix1D< double > &  X,
const Matrix1D< double > &  Y,
const Matrix1D< double > &  Z,
double  R2 
)

Create a simple grid fitting the given sphere. Not all index combinations are within the sphere, so attention must be paid whether a certain point is within it or not.

The formula for the grid limits are computed as

XX(highest)=CEIL((R/relative_size)/X.module());
XX(lowest)=-XX(highest);

Definition at line 376 of file grids.cpp.

380 {
381  SimpleGrid grid;
382  double R = sqrt(R2);
383 
384  grid.set_X(X);
385  grid.set_Y(Y);
386  grid.set_Z(Z);
387  grid.relative_size = relative_size;
388  grid.origin = origin;
389  grid.R2 = R2;
390  grid.lowest.initZeros(3);
391  grid.highest.initZeros(3);
392  grid.prepare_grid();
393 
394  // Find grid limits
395  int iR = CEIL(R);
396  Matrix1D<double> univ_position(3);
397  Matrix1D<double> grid_position(3);
398  for (int k = -iR; k <= iR; k++)
399  for (int i = -iR; i <= iR; i++)
400  for (int j = -iR; j <= iR; j++)
401  {
402  VECTOR_R3(univ_position, j, i, k);
403  if (univ_position.module() > R) continue;
404  grid.universe2grid(univ_position, grid_position);
405  XX(grid.lowest) = XMIPP_MIN(XX(grid.lowest), FLOOR(XX(grid_position)));
406  YY(grid.lowest) = XMIPP_MIN(YY(grid.lowest), FLOOR(YY(grid_position)));
407  ZZ(grid.lowest) = XMIPP_MIN(ZZ(grid.lowest), FLOOR(ZZ(grid_position)));
408  XX(grid.highest) = XMIPP_MAX(XX(grid.highest), CEIL(XX(grid_position)));
409  YY(grid.highest) = XMIPP_MAX(YY(grid.highest), CEIL(YY(grid_position)));
410  ZZ(grid.highest) = XMIPP_MAX(ZZ(grid.highest), CEIL(ZZ(grid_position)));
411  }
412 
413 #ifdef DEBUG
414  std::cout << "Sphere radius = " << R << std::endl
415  << "relative size = " << relative_size << std::endl
416  << "X module = " << X.module() << std::endl
417  << "Y module = " << Y.module() << std::endl
418  << "Z module = " << Z.module() << std::endl
419  << grid
420  ;
421 #endif
422  return grid;
423 }
void set_Y(const Matrix1D< double > &v)
Definition: grids.h:198
void universe2grid(const Matrix1D< double > &uv, Matrix1D< double > &gv) const
Definition: grids.h:349
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
Matrix1D< double > highest
Definition: grids.h:161
double module() const
Definition: matrix1d.h:983
void sqrt(Image< double > &op)
void set_X(const Matrix1D< double > &v)
Definition: grids.h:191
Matrix1D< double > lowest
Definition: grids.h:158
#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
double R2
Definition: grids.h:170
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define XX(v)
Definition: matrix1d.h:85
#define CEIL(x)
Definition: xmipp_macros.h:225
void set_Z(const Matrix1D< double > &v)
Definition: grids.h:205
void initZeros()
Definition: matrix1d.h:592
double relative_size
Measuring unit in the grid coordinate system.
Definition: grids.h:163
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
#define j
#define YY(v)
Definition: matrix1d.h:93
Matrix1D< double > origin
Origin of the grid in the Universal coordinate system.
Definition: grids.h:165
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void prepare_grid()
Definition: grids.cpp:103
#define ZZ(v)
Definition: matrix1d.h:101

◆ operator<<()

template<class T >
std::ostream & operator<< ( std::ostream &  o,
const GridVolumeT< T > &  GV 
)

Show a grid.

Definition at line 1501 of file grids.h.

1502 {
1503  o << "Grid Volume -----------\n";
1504  o << GV.G;
1505  o << "Number of volumes= " << GV.VolumesNo() << std::endl;
1506  for (int i = 0; i < GV.VolumesNo(); i++)
1507  {
1508  o << "Volume " << i << "------------" << std::endl;
1509  o << GV(i)();
1510  }
1511  return o;
1512 }
#define i
size_t VolumesNo() const
Definition: grids.h:1003