Xmipp  v3.23.11-Nereus
Public Member Functions | List of all members
GridVolumeT< T > Class Template Reference

#include <grids.h>

Public Member Functions

 GridVolumeT ()
 
 GridVolumeT (const GridVolumeT &_RV)
 
 GridVolumeT (const Grid &_grid)
 
GridVolumeToperator= (const GridVolumeT &RV)
 
void assign (const GridVolumeT &RV)
 
 ~GridVolumeT ()
 
void adapt_to_grid (const Grid &_grid)
 
void resize (const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
 
template<class T1 >
void resize (const GridVolumeT< T1 > &GV)
 
void initZeros ()
 
void clear ()
 
Image< T > & operator() (size_t n)
 
void get_volume (size_t n, Image< T > &V)
 
const Image< T > & operator() (size_t n) const
 
const SimpleGridgrid (size_t n) const
 
void get_SimpleGrid (size_t n, SimpleGrid &G)
 
const Gridgrid () const
 
void get_Grid (Grid &G)
 
size_t VolumesNo () const
 
GridVolumeT< T > operator+ (T f) const
 
GridVolumeT< T > operator- (T f) const
 
GridVolumeT< T > operator* (T f) const
 
GridVolumeT< T > operator/ (T f) const
 
GridVolumeT< T > friend operator+ (T f, const GridVolumeT< T > &GV)
 
GridVolumeT< T > friend operator* (T f, const GridVolumeT< T > &GV)
 
GridVolumeT< T > operator+ (const GridVolumeT< T > &GV)
 
GridVolumeT< T > operator- (const GridVolumeT< T > &GV)
 
GridVolumeT< T > operator* (const GridVolumeT< T > &GV)
 
GridVolumeT< T > operator/ (const GridVolumeT< T > &GV)
 
void operator+= (const GridVolumeT< T > &GV)
 
void operator-= (const GridVolumeT< T > &GV)
 
void operator*= (const GridVolumeT< T > &GV)
 
void operator/= (const GridVolumeT< T > &GV)
 
Grids I/O

The reconstructing volume is stored in the Xmipp format. Although it is not a true volume some special structure is used to store each subgrid and subvolume.

  • a first slice contains control information about the subvolume which is behind
  • the subvolume is stored after its control information and it can be represented by a volume viewer. The structure inside the control slice is the following:
    Subgrid information: (19 doubles)
    - basis 9 doubles
    - lowest 3 doubles
    - highest 3 doubles
    - relative_size 1 double
    - origin 3 doubles
    Subvolume information (6 doubles)
    - Zdim, Ydim, Xdim 3 doubles
    - Zinit, Yinit, Xinit 3 doubles

With respect to the volume structure, if the volume is smaller (Ydim,Xdim) than the size assigned to the file then the data is right justified and the extra data is filled with zeros.

void write (const FileName &fn) const
 
void read (const FileName &fn, const std::string &basisName)
 

Detailed Description

template<class T>
class GridVolumeT< T >

Grid Volume class. The grid volumes are a special kind of volumes used in reconstructions where the volumes are understood as a 3D matrix of coefficients placed at the points defined by a Grid (BCC, FCC, ...) Remember that a complex grid like these ones are seen as lists of simpler grids. That is why this Grid Volumes are compound of a list of volumes. The first volume of the grid volume should contain the coefficients for the first grid in the list of grids, and so on.

Definition at line 41 of file grids.h.

Constructor & Destructor Documentation

◆ GridVolumeT() [1/3]

template<class T>
GridVolumeT< T >::GridVolumeT ( )
inline

Empty constructor. The volume list is empty, and the grid is also empty

Definition at line 782 of file grids.h.

783  {
784  LV.clear();
785  (Grid) G;
786  }
Definition: grids.h:479

◆ GridVolumeT() [2/3]

template<class T>
GridVolumeT< T >::GridVolumeT ( const GridVolumeT< T > &  _RV)
inline

Copy constructor.

Definition at line 789 of file grids.h.

790  {
791  *this = _RV;
792  }

◆ GridVolumeT() [3/3]

template<class T>
GridVolumeT< T >::GridVolumeT ( const Grid _grid)
inline

Create using a grid as pattern and basis. Create the grid volume using this grid as pattern. This function calls adapt_to_grid , so look at there to know exactly what is performed

Definition at line 798 of file grids.h.

799  {
800  adapt_to_grid(_grid);
801  }
void adapt_to_grid(const Grid &_grid)
Definition: grids.h:838

◆ ~GridVolumeT()

template<class T>
GridVolumeT< T >::~GridVolumeT ( )
inline

Destructor.

Definition at line 827 of file grids.h.

828  {
829  clear();
830  }
void clear()
Definition: grids.h:943

Member Function Documentation

◆ adapt_to_grid()

template<class T>
void GridVolumeT< T >::adapt_to_grid ( const Grid _grid)
inline

Reset current volume and use the given grid as pattern. The current grid volume is cleared. Then the given grid is taken as the grid for this grid volume. Zero-valued volumes are added to the volume list according to the number of grids inside the complex grid. The size and starting point of the volumes added are fixed by the lowest and highest fields of each SimpleGrid .

Definition at line 838 of file grids.h.

839  {
840  // Clear old list of volumes
841  for (size_t i = 0; i < VolumesNo(); i++)
842  if (LV[i]!=nullptr)
843  delete LV[i];
844  LV.clear();
845 
846  // Keep the incoming Grid at the same time the old grid is forgotten
847  G = _grid;
848 
849  // Generate a volume for each subgrid
850  int Zdim;
851  int Ydim;
852  int Xdim;
853  Image<T> * Vol_aux;
854  for (size_t i = 0; i < G.GridsNo(); i++)
855  {
856  SimpleGrid & grid = G(i);
857  grid.getSize(Zdim, Ydim, Xdim);
858  Vol_aux = new Image<T>;
859  (*Vol_aux)().resize(Zdim, Ydim, Xdim); // Using this function
860  // after empty creation the volume
861  // is zero-valued.
862  STARTINGX((*Vol_aux)()) = (int) XX(grid.lowest); // This values are already
863  STARTINGY((*Vol_aux)()) = (int) YY(grid.lowest); // integer although they
864  STARTINGZ((*Vol_aux)()) = (int) ZZ(grid.lowest); // are stored as float
865  LV.push_back(Vol_aux);
866  }
867  }
const Grid & grid() const
Definition: grids.h:991
void resize(const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.h:873
size_t GridsNo() const
Definition: grids.h:536
Matrix1D< double > lowest
Definition: grids.h:158
#define STARTINGX(v)
#define i
#define STARTINGY(v)
size_t VolumesNo() const
Definition: grids.h:1003
#define XX(v)
Definition: matrix1d.h:85
#define YY(v)
Definition: matrix1d.h:93
#define STARTINGZ(v)
#define ZZ(v)
Definition: matrix1d.h:101
void getSize(int &Zdim, int &Ydim, int &Xdim) const
Definition: grids.h:245

◆ assign()

template<class T>
void GridVolumeT< T >::assign ( const GridVolumeT< T > &  RV)
inline

Another function for assignment.

Definition at line 821 of file grids.h.

822  {
823  *this = RV;
824  }

◆ clear()

template<class T>
void GridVolumeT< T >::clear ( )
inline

Clear the volume

Definition at line 943 of file grids.h.

944  {
945  for (size_t i = 0; i < VolumesNo(); i++)
946  delete LV[i];
947  LV.clear();
948  G.clear();
949  }
#define i
size_t VolumesNo() const
Definition: grids.h:1003
void clear()
Definition: grids.h:559

◆ get_Grid()

template<class T>
void GridVolumeT< T >::get_Grid ( Grid G)
inline

Get grid.

Definition at line 997 of file grids.h.

998  {
999  G = grid();
1000  }
const Grid & grid() const
Definition: grids.h:991

◆ get_SimpleGrid()

template<class T>
void GridVolumeT< T >::get_SimpleGrid ( size_t  n,
SimpleGrid G 
)
inline

Get simple grid.

Definition at line 984 of file grids.h.

985  {
986  G = grid(n);
987  }
const Grid & grid() const
Definition: grids.h:991
int * n

◆ get_volume()

template<class T>
void GridVolumeT< T >::get_volume ( size_t  n,
Image< T > &  V 
)
inline

Another function for access to one of the volumes in the list.

Definition at line 961 of file grids.h.

962  {
963  V = (*this)(n);
964  }
int * n

◆ grid() [1/2]

template<class T>
const SimpleGrid& GridVolumeT< T >::grid ( size_t  n) const
inline

Constant access to a simple grid. The grid is the SimpleGrid associated to the volume which occupies position n in the volume list.

Definition at line 978 of file grids.h.

979  {
980  return G(n);
981  }
int * n

◆ grid() [2/2]

template<class T>
const Grid& GridVolumeT< T >::grid ( ) const
inline

Constant access to the whole grid. The grid is the whole Grid associated to the volume.

Definition at line 991 of file grids.h.

992  {
993  return G;
994  }

◆ initZeros()

template<class T>
void GridVolumeT< T >::initZeros ( )
inline

Set to zero with the actual size and origin.

Definition at line 936 of file grids.h.

937  {
938  for (size_t i = 0; i < VolumesNo(); i++)
939  (*this)(i)().initZeros();
940  }
#define i
size_t VolumesNo() const
Definition: grids.h:1003

◆ operator()() [1/2]

template<class T>
Image<T>& GridVolumeT< T >::operator() ( size_t  n)
inline

Access to one of the volumes in the list. The first volume is the number 0.

Definition at line 953 of file grids.h.

954  {
955  if (n>LV.size())
956  REPORT_ERROR(ERR_VALUE_INCORRECT, "The Grid Volume hasn't got so many Simple Volumes");
957  return *(LV[n]);
958  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect value received.
Definition: xmipp_error.h:195
int * n

◆ operator()() [2/2]

template<class T>
const Image<T>& GridVolumeT< T >::operator() ( size_t  n) const
inline

Constant access to a volume in the list. The first volume is the number 0.

Definition at line 968 of file grids.h.

969  {
970  if (n>LV.size())
971  REPORT_ERROR(ERR_VALUE_INCORRECT, "The Grid Volume hasn't got so many Simple Volumes");
972  return *(LV[n]);
973  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect value received.
Definition: xmipp_error.h:195
int * n

◆ operator*() [1/3]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator* ( f) const
inline

Multiply by a constant. The constant is multiplied with all simple volumes. \Ex: V2=V1*6;

Definition at line 1035 of file grids.h.

1036  {
1037  GRIDVOLUME_BY_SCALAR('*');
1038  }
#define GRIDVOLUME_BY_SCALAR(op)
Definition: grids.h:1008

◆ operator*() [2/3]

template<class T>
GridVolumeT<T> friend GridVolumeT< T >::operator* ( f,
const GridVolumeT< T > &  GV 
)
inline

Multiply by a constant. The constant is multiplied with all simple volumes. \Ex: V2=6*V1;

Definition at line 1059 of file grids.h.

1060  {
1061  return GV*f;
1062  }
double * f

◆ operator*() [3/3]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator* ( const GridVolumeT< T > &  GV)
inline

Multiply by another volume. The two volumes must be equally the same in shape (size, origin, number of simple volumes, ...) if they aren't an exception is thrown. \Ex: V3=V1*V2;

Definition at line 1113 of file grids.h.

1114  {
1115  GRIDVOL_BY_GRIDVOL('*');
1116  }
#define GRIDVOL_BY_GRIDVOL(op)
Definition: grids.h:1064

◆ operator*=()

template<class T>
void GridVolumeT< T >::operator*= ( const GridVolumeT< T > &  GV)
inline

Multiply by another volume.

Definition at line 1155 of file grids.h.

1156  {
1158  }
#define GRIDVOL_BY_GRIDVOLASSIG(op)
Definition: grids.h:1128

◆ operator+() [1/3]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator+ ( f) const
inline

Sum a constant. The constant is added to all simple volumes. \Ex: V2=V1+6;

Definition at line 1019 of file grids.h.

1020  {
1021  GRIDVOLUME_BY_SCALAR('+');
1022  }
#define GRIDVOLUME_BY_SCALAR(op)
Definition: grids.h:1008

◆ operator+() [2/3]

template<class T>
GridVolumeT<T> friend GridVolumeT< T >::operator+ ( f,
const GridVolumeT< T > &  GV 
)
inline

Sum a constant. The constant is added to all simple volumes. \Ex: V2=6+V1;

Definition at line 1051 of file grids.h.

1052  {
1053  return GV + f;
1054  }
double * f

◆ operator+() [3/3]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator+ ( const GridVolumeT< T > &  GV)
inline

Sum another volume. The two volumes must be equally the same in shape (size, origin, number of simple volumes, ...) if they aren't an exception is thrown. \Ex: V3=V1+V2;

Definition at line 1093 of file grids.h.

1094  {
1095  GRIDVOL_BY_GRIDVOL('+');
1096  }
#define GRIDVOL_BY_GRIDVOL(op)
Definition: grids.h:1064

◆ operator+=()

template<class T>
void GridVolumeT< T >::operator+= ( const GridVolumeT< T > &  GV)
inline

Sum another volume.

Definition at line 1143 of file grids.h.

1144  {
1146  }
#define GRIDVOL_BY_GRIDVOLASSIG(op)
Definition: grids.h:1128

◆ operator-() [1/2]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator- ( f) const
inline

Subtract a constant. The constant is subtracted from all simple volumes. \Ex: V2=V1-6;

Definition at line 1027 of file grids.h.

1028  {
1029  GRIDVOLUME_BY_SCALAR('-');
1030  }
#define GRIDVOLUME_BY_SCALAR(op)
Definition: grids.h:1008

◆ operator-() [2/2]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator- ( const GridVolumeT< T > &  GV)
inline

Subtract another volume. The two volumes must be equally the same in shape (size, origin, number of simple volumes, ...) if they aren't an exception is thrown. \Ex: V3=V1-V2;

Definition at line 1103 of file grids.h.

1104  {
1105  GRIDVOL_BY_GRIDVOL('-');
1106  }
#define GRIDVOL_BY_GRIDVOL(op)
Definition: grids.h:1064

◆ operator-=()

template<class T>
void GridVolumeT< T >::operator-= ( const GridVolumeT< T > &  GV)
inline

Subtract another volume.

Definition at line 1149 of file grids.h.

1150  {
1152  }
#define GRIDVOL_BY_GRIDVOLASSIG(op)
Definition: grids.h:1128

◆ operator/() [1/2]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator/ ( f) const
inline

Divide by a constant. The constant divides all simple volumes. \Ex: V2=V1/6;

Definition at line 1043 of file grids.h.

1044  {
1045  GRIDVOLUME_BY_SCALAR('/');
1046  }
#define GRIDVOLUME_BY_SCALAR(op)
Definition: grids.h:1008

◆ operator/() [2/2]

template<class T>
GridVolumeT<T> GridVolumeT< T >::operator/ ( const GridVolumeT< T > &  GV)
inline

Divide by another volume. The two volumes must be equally the same in shape (size, origin, number of simple volumes, ...) if they aren't an exception is thrown. \Ex: V3=V1/V2;

Definition at line 1123 of file grids.h.

1124  {
1125  GRIDVOL_BY_GRIDVOL('/');
1126  }
#define GRIDVOL_BY_GRIDVOL(op)
Definition: grids.h:1064

◆ operator/=()

template<class T>
void GridVolumeT< T >::operator/= ( const GridVolumeT< T > &  GV)
inline

Divide by another volume.

Definition at line 1161 of file grids.h.

1162  {
1164  }
#define GRIDVOL_BY_GRIDVOLASSIG(op)
Definition: grids.h:1128

◆ operator=()

template<class T>
GridVolumeT& GridVolumeT< T >::operator= ( const GridVolumeT< T > &  RV)
inline

Assignment.

Definition at line 804 of file grids.h.

805  {
806  if (this != &RV)
807  {
808  clear();
809  G = RV.G;
810  for (size_t i = 0; i < RV.VolumesNo(); i++)
811  {
812  auto *V = new Image<T>;
813  *V = RV(i);
814  LV.push_back(V);
815  }
816  }
817  return *this;
818  }
void clear()
Definition: grids.h:943
#define i
size_t VolumesNo() const
Definition: grids.h:1003

◆ read()

template<class T>
void GridVolumeT< T >::read ( const FileName fn,
const std::string &  basisName 
)
inline

Read grid volume. The volume is read from a Xmipp volume with a special structure at several slices.

Definition at line 1330 of file grids.h.

1331  {
1332  Image<T> V;
1333  Image<T> * sV;
1334  SimpleGrid sG;
1335  size_t sli = 0;
1336 
1337  float temp_float;
1338  size_t floatsize;
1339  const std::type_info &typeinfoT = typeid(T); // We need to know what kind
1340  // of variable is T
1341  const std::type_info &typeinfoD = typeid(double);
1342  const std::type_info &typeinfoI = typeid(int);
1343 
1344  floatsize = (size_t) sizeof(float);
1345  // We use a trick to save the grid information in the volume
1346  // If the following if is true the trick can not be used
1347  if ((typeid(T) == typeid(int)) && (sizeof(float) != sizeof(int)))
1348  REPORT_ERROR(ERR_TYPE_INCORRECT,"Error: GridVolume is integer and (sizeof(float)!= sizeof(int)");
1349 
1350  // Allocate memory ......................................................
1351  sG.basis.resize(3, 3);
1352  sG.lowest.resize(3);
1353  sG.highest.resize(3);
1354  sG.origin.resize(3);
1355 
1356  // Read Reconstructing volume from file .................................
1357  V.read(fn);
1358  if (basisName=="voxels")
1359  {
1360  V().setXmippOrigin();
1361  sV=new Image<double>;
1362  *sV=V;
1363  LV.push_back(sV);
1364  G=Create_CC_grid(1.0,ZSIZE(V()),YSIZE(V()),XSIZE(V()));
1365  }
1366  else
1367  {
1368 #define UNPACK_DOUBLE(v,cast) \
1369  {jj=pos%VOLMATRIX(V).xdim; ii=pos/VOLMATRIX(V).xdim; pos++; \
1370  (v)=(cast)VOLVOXEL(V,sli,ii,jj);}
1371 #define UNPACK_INT(v,cast) \
1372  {jj=pos%VOLMATRIX(V).xdim; ii=pos/VOLMATRIX(V).xdim; pos++; \
1373  memcpy( &temp_float, &(VOLVOXEL(V,sli,ii,jj)),floatsize);\
1374  (v)=(cast)temp_float;}
1375 
1376  while (sli < ZSIZE(V()))
1377  {
1378  int pos; // Position inside the control slice
1379  int ii; // Position inside the control slice
1380  int jj; // Position inside the control slice
1381  size_t k; // Auxiliary counters
1382  size_t i; // Auxiliary counters
1383  size_t j; // Auxiliary counters
1384  size_t Zdim;
1385  size_t Ydim;
1386  size_t Xdim;
1387  int Zinit;
1388  int Yinit;
1389  int Xinit;
1390 
1391  // Read Grid data ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1392  pos = 0;
1393  if (typeinfoT == typeinfoD)
1394  {
1395  for (i = 0; i < 3; i++)
1396  for (j = 0; j < 3; j++)
1397  UNPACK_DOUBLE((sG.basis)(i, j), double);
1398  for (i = 0; i < 3; i++)
1399  UNPACK_DOUBLE((sG.lowest)(i), int);
1400  for (i = 0; i < 3; i++)
1401  UNPACK_DOUBLE((sG.highest)(i), int);
1402  UNPACK_DOUBLE(sG.relative_size, double);
1403  for (i = 0; i < 3; i++)
1404  UNPACK_DOUBLE((sG.origin)(i), double);
1405  UNPACK_DOUBLE(sG.R2, double);
1406  }
1407  else if (typeinfoT == typeinfoI)
1408  {
1409  // We use a trick to save the grid information in the volume
1410  // If the following if is true the trick can not be used
1411  if (sizeof(float) != sizeof(int))
1413  "GridVolume is integer and (sizeof(float)!= sizeof(int)");
1414 
1415  for (i = 0; i < 3; i++)
1416  for (j = 0; j < 3; j++)
1417  UNPACK_INT((sG.basis)(i, j), double);
1418  for (i = 0; i < 3; i++)
1419  UNPACK_INT((sG.lowest)(i), int);
1420  for (i = 0; i < 3; i++)
1421  UNPACK_INT((sG.highest)(i), int);
1422  UNPACK_INT(sG.relative_size, double);
1423  for (i = 0; i < 3; i++)
1424  UNPACK_INT((sG.origin)(i), double);
1425  UNPACK_INT(sG.R2, double);
1426  }
1427  sG.inv_basis = sG.basis.inv();
1428 
1429  // Store Grid in the list of the grid volume
1430  G.add_grid(sG);
1431 
1432  // Read Volume Control Information ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1433  if (typeinfoT == typeinfoD)
1434  {
1435  UNPACK_DOUBLE(Zdim, int);
1436  UNPACK_DOUBLE(Ydim, int);
1437  UNPACK_DOUBLE(Xdim, int);
1438  UNPACK_DOUBLE(Zinit, int);
1439  UNPACK_DOUBLE(Yinit, int);
1440  UNPACK_DOUBLE(Xinit, int);
1441  }
1442  else if (typeinfoT == typeinfoI)
1443  {
1444  UNPACK_INT(Zdim, int);
1445  UNPACK_INT(Ydim, int);
1446  UNPACK_INT(Xdim, int);
1447  UNPACK_INT(Zinit, int);
1448  UNPACK_INT(Yinit, int);
1449  UNPACK_INT(Xinit, int);
1450  }
1451 
1452  // Set volume size and origin
1453  sV = new Image<T>;
1454  VOLMATRIX(*sV).initZeros(Zdim, Ydim, Xdim);
1455  STARTINGZ(VOLMATRIX(*sV)) = Zinit;
1456  STARTINGY(VOLMATRIX(*sV)) = Yinit;
1457  STARTINGX(VOLMATRIX(*sV)) = Xinit;
1458 #ifdef DEBUG
1459 
1460  std::cout << "The read grid is \n" << sG;
1461  std::cout << "Volume dimensions: " << Zdim << " x " << Ydim << " x "
1462  << Xdim << std::endl;
1463  std::cout << "Volume init: " << Zinit << " x " << Yinit << " x "
1464  << Xinit << std::endl;
1465 #endif
1466 
1467  sli++;
1468 
1469  // Read volume ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1470  for (k = 0; k < ZSIZE(VOLMATRIX(*sV)); k++)
1471  {
1472  for (i = 0; i < YSIZE(VOLMATRIX(*sV)); i++)
1473  for (j = 0; j < XSIZE(VOLMATRIX(*sV)); j++)
1474  {
1475 #ifdef DEBUG
1476  std::cout << "Reading from file position (" << sli << "," << i
1477  << "," << j << ") to subvolume position ("
1478  << k << "," << i << "," << j << ")\n";
1479 #endif
1480 
1481  DIRECT_VOLVOXEL(*sV, k, i, j) = DIRECT_VOLVOXEL(V, sli, i, j);
1482  }
1483  sli++;
1484  }
1485 
1486  // Store volume in the list
1487  LV.push_back(sV);
1488  }
1489 #undef UNPACK_DOUBLE
1490 #undef UNPACK_INT
1491  }
1492  }
#define YSIZE(v)
Matrix1D< double > highest
Definition: grids.h:161
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
SimpleGrid Create_CC_grid(double relative_size, const Matrix1D< double > &corner1, const Matrix1D< double > &corner2, const Matrix1D< double > &origin)
Definition: grids.cpp:196
#define VOLMATRIX(V)
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
Matrix1D< double > lowest
Definition: grids.h:158
#define UNPACK_INT(v, cast)
Matrix2D< double > basis
Definition: grids.h:148
#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
double R2
Definition: grids.h:170
#define DIRECT_VOLVOXEL(I, k, i, j)
#define STARTINGY(v)
Matrix2D< double > inv_basis
Definition: grids.h:153
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
#define XSIZE(v)
#define ZSIZE(v)
double relative_size
Measuring unit in the grid coordinate system.
Definition: grids.h:163
#define j
#define UNPACK_DOUBLE(v, cast)
Matrix1D< double > origin
Origin of the grid in the Universal coordinate system.
Definition: grids.h:165
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Incorrect type received.
Definition: xmipp_error.h:190
#define STARTINGZ(v)
void resize(size_t Ydim, size_t Xdim, bool noCopy=false)
Definition: matrix2d.cpp:1022

◆ resize() [1/2]

template<class T>
void GridVolumeT< T >::resize ( const Matrix1D< double > &  corner1,
const Matrix1D< double > &  corner2 
)
inline

Resize. The grid volume is resized such that the space delimited by the two given corners is covered. Overlapping grid points are retained while non-overlapping ones are set to 0.

Definition at line 873 of file grids.h.

875  {
876  Image<T> * Vol_aux;
877  std::vector<Image<T> * > LV_aux;
878 
879  for (size_t n = 0; n < G.GridsNo(); n++)
880  {
881  SimpleGrid &grid = G(n);
882 
883  // Resize grid
884  grid.universe2grid(corner1, grid.lowest);
885  grid.lowest.selfFLOOR();
886  grid.universe2grid(corner2, grid.highest);
887  grid.highest.selfCEIL();
888 
889  // Resize auxiliary volume
890  int Zdim;
891  int Ydim;
892  int Xdim;
893  grid.getSize(Zdim, Ydim, Xdim);
894  Vol_aux = new Image<T>;
895  (*Vol_aux)().resize(Zdim, Ydim, Xdim);
896  STARTINGX((*Vol_aux)()) = (int) XX(grid.lowest); // This values are already
897  STARTINGY((*Vol_aux)()) = (int) YY(grid.lowest); // integer although they
898  STARTINGZ((*Vol_aux)()) = (int) ZZ(grid.lowest); // are stored as float
899 
900  // Copy values in common
901  Image<T> * origin = LV[n];
904  {
905  VOLVOXEL(*Vol_aux, k, i, j) = VOLVOXEL(*origin, k, i, j);
906  }
907 
908  // Extract old volume and push new one
909  delete LV[n];
910  LV_aux.push_back(Vol_aux);
911  }
912  LV = LV_aux;
913  }
const Grid & grid() const
Definition: grids.h:991
void universe2grid(const Matrix1D< double > &uv, Matrix1D< double > &gv) const
Definition: grids.h:349
#define VOLVOXEL(V, k, i, j)
Matrix1D< double > highest
Definition: grids.h:161
void resize(const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.h:873
#define VOLMATRIX(V)
size_t GridsNo() const
Definition: grids.h:536
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 XX(v)
Definition: matrix1d.h:85
#define j
#define YY(v)
Definition: matrix1d.h:93
void selfFLOOR()
Definition: matrix1d.cpp:499
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)
#define STARTINGZ(v)
int * n
#define ZZ(v)
Definition: matrix1d.h:101
void selfCEIL()
Definition: matrix1d.cpp:476
void getSize(int &Zdim, int &Ydim, int &Xdim) const
Definition: grids.h:245

◆ resize() [2/2]

template<class T>
template<class T1 >
void GridVolumeT< T >::resize ( const GridVolumeT< T1 > &  GV)
inline

Resize after a pattern. The volume is of the same shape, the grids are copied, and the volume coeeficients are set to 0.

Definition at line 919 of file grids.h.

920  {
921  clear();
922  for (size_t n = 0; n < GV.VolumesNo(); n++)
923  {
925  grid = GV.grid(n);
926  G.add_grid(grid);
927 
928  Image<T> *Vol_aux;
929  Vol_aux = new Image<T>;
930  (*Vol_aux)().resize(GV(n)());
931  LV.push_back(Vol_aux);
932  }
933  }
const Grid & grid() const
Definition: grids.h:991
void clear()
Definition: grids.h:943
void resize(const Matrix1D< double > &corner1, const Matrix1D< double > &corner2)
Definition: grids.h:873
size_t VolumesNo() const
Definition: grids.h:1003
const SimpleGrid & grid(size_t n) const
Definition: grids.h:978
void add_grid(const SimpleGrid &SG)
Definition: grids.h:491
int * n

◆ VolumesNo()

template<class T>
size_t GridVolumeT< T >::VolumesNo ( ) const
inline

Number of volumes inside structure.

Definition at line 1003 of file grids.h.

1004  {
1005  return LV.size();
1006  }

◆ write()

template<class T>
void GridVolumeT< T >::write ( const FileName fn) const
inline

Write grid volume. The Filename is compulsory, an exception is thrown if the volume is too small to hold the control information of each layer.

Definition at line 1196 of file grids.h.

1197  {
1198  Image<T> V;
1199  float temp_float;
1200  size_t floatsize;
1201  const std::type_info &typeinfoT = typeid(T); // We need to know what kind
1202  // of variable is T
1203  const std::type_info &typeinfoD = typeid(double);
1204  const std::type_info &typeinfoI = typeid(int);
1205 
1206  floatsize = (size_t) sizeof(float);
1207 
1208  if (VolumesNo() == 0)
1209  return;
1210 
1211  // Create the writing volume ............................................
1212  size_t Zdim = 0;
1213  size_t Ydim = 0;
1214  size_t Xdim = 0;
1215  for (size_t v = 0; v < VolumesNo(); v++)
1216  {
1217  const Image<T> & this_vol = (*this)(v);
1218  Zdim += ZSIZE(this_vol());
1219  Ydim = XMIPP_MAX(Ydim, YSIZE(this_vol()));
1220  Xdim = XMIPP_MAX(Xdim, XSIZE(this_vol()));
1221  }
1222 
1223  // Check if there is enough space for the control slice
1224  if (Xdim*Ydim < 25)
1225  Ydim = (int) CEIL(25.0f / Xdim);
1226 
1227  // A slice is added for control information for each subvolume
1228  VOLMATRIX(V).initZeros(Zdim + VolumesNo(), Ydim, Xdim);
1229 
1230  // Write Grid volume ....................................................
1231 #define PACK_DOUBLE(v) \
1232 {jj=pos%Xdim; ii=pos/Xdim; pos++; VOLVOXEL(V,sli,ii,jj)=(T)(v);}
1233 #define PACK_INT(v) \
1234  {jj=pos%Xdim; ii=pos/Xdim; pos++; \
1235  temp_float = (float) (v); \
1236  memcpy( &(VOLVOXEL(V,sli,ii,jj)) , &temp_float, floatsize); \
1237  }
1238 
1239  int sli = 0;
1240  for (size_t v = 0; v < VolumesNo(); v++)
1241  {
1242  int pos; // Position inside the control slice
1243  int ii; // Position inside the control slice
1244  int jj; // Position inside the control slice
1245  size_t k; // Auxiliar counters
1246  size_t i; // Auxiliar counters
1247  size_t j; // Auxiliar counters
1248 
1249  // Choose grid and volume
1250  const SimpleGrid & this_grid = grid(v);
1251  const Image<T> & this_vol = (*this)(v);
1252 
1253  // Store Grid data ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1254  pos = 0;
1255 
1256  if (typeinfoT == typeinfoD)
1257  {
1258  for (i = 0; i < 3; i++)
1259  for (j = 0; j < 3; j++)
1260  PACK_DOUBLE((this_grid.basis)(i, j));
1261  for (i = 0; i < 3; i++)
1262  PACK_DOUBLE((this_grid.lowest)(i));
1263  for (i = 0; i < 3; i++)
1264  PACK_DOUBLE((this_grid.highest)(i));
1265  PACK_DOUBLE(this_grid.relative_size);
1266  for (i = 0; i < 3; i++)
1267  PACK_DOUBLE((this_grid.origin)(i));
1268  PACK_DOUBLE(this_grid.R2);
1269 
1270  // Store volume control ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1271  PACK_DOUBLE(ZSIZE(this_vol()));
1272  PACK_DOUBLE(YSIZE(this_vol()));
1273  PACK_DOUBLE(XSIZE(this_vol()));
1274  PACK_DOUBLE(STARTINGZ(this_vol()));
1275  PACK_DOUBLE(STARTINGY(this_vol()));
1276  PACK_DOUBLE(STARTINGX(this_vol()));
1277  }
1278  else if (typeinfoT == typeinfoI)
1279  {
1280  // We use a trick to save the grid information in the volume
1281  // If the following if is true the trick can not be used
1282  if (sizeof(float) != sizeof(int))
1284  "GridVolume is integer and (sizeof(float)!= sizeof(int)");
1285 
1286  for (i = 0; i < 3; i++)
1287  for (j = 0; j < 3; j++)
1288  PACK_INT((this_grid.basis)(i, j));
1289  for (i = 0; i < 3; i++)
1290  PACK_INT((this_grid.lowest)(i));
1291  for (i = 0; i < 3; i++)
1292  PACK_INT((this_grid.highest)(i));
1293  PACK_INT(this_grid.relative_size);
1294  for (i = 0; i < 3; i++)
1295  PACK_INT((this_grid.origin)(i));
1296  PACK_INT(this_grid.R2);
1297 
1298  // Store volume control ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1299  PACK_INT(ZSIZE(this_vol()));
1300  PACK_INT(YSIZE(this_vol()));
1301  PACK_INT(XSIZE(this_vol()));
1302  PACK_INT(STARTINGZ(this_vol()));
1303  PACK_INT(STARTINGY(this_vol()));
1304  PACK_INT(STARTINGX(this_vol()));
1305  }
1306  else
1307  REPORT_ERROR(ERR_TYPE_INCORRECT, "GridVolume must be double or int\n");
1308 
1309  sli++;
1310 
1311  // Write the whole volume ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1312  for (k = 0; k < ZSIZE(VOLMATRIX(this_vol)); k++)
1313  {
1314  for (i = 0; i < YSIZE(VOLMATRIX(this_vol)); i++)
1315  for (j = 0; j < XSIZE(VOLMATRIX(this_vol)); j++)
1316  DIRECT_VOLVOXEL(V, sli, i, j) = DIRECT_VOLVOXEL(this_vol, k, i, j);
1317  sli++;
1318  }
1319  }
1320 #undef PACK_DOUBLE
1321 #undef PACK_INT
1322 
1323  // Effectively write the volume .........................................
1324  V.write(fn);
1325  }
const Grid & grid() const
Definition: grids.h:991
#define YSIZE(v)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
Matrix1D< double > highest
Definition: grids.h:161
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define VOLMATRIX(V)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
#define PACK_INT(v)
Matrix1D< double > lowest
Definition: grids.h:158
Matrix2D< double > basis
Definition: grids.h:148
#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
double R2
Definition: grids.h:170
#define DIRECT_VOLVOXEL(I, k, i, j)
#define STARTINGY(v)
size_t VolumesNo() const
Definition: grids.h:1003
#define CEIL(x)
Definition: xmipp_macros.h:225
double * f
#define XSIZE(v)
#define ZSIZE(v)
double relative_size
Measuring unit in the grid coordinate system.
Definition: grids.h:163
#define j
Matrix1D< double > origin
Origin of the grid in the Universal coordinate system.
Definition: grids.h:165
Incorrect type received.
Definition: xmipp_error.h:190
#define PACK_DOUBLE(v)
#define STARTINGZ(v)

The documentation for this class was generated from the following file: