Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <reconstruct_wbp.h>

Inheritance diagram for ProgRecWbp:
Inheritance graph
[legend]
Collaboration diagram for ProgRecWbp:
Collaboration graph
[legend]

Public Member Functions

void readParams ()
 Read arguments from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void run ()
 
virtual void showProgress ()
 
virtual void finishProcessing ()
 
void setIO (const FileName &fn_in, const FileName &fn_out)
 
virtual void produceSideInfo ()
 Fill arrays with relevant transformation matrices. More...
 
virtual bool getImageToProcess (size_t &objId)
 Get 1 image to process. More...
 
void getAnglesForImage (size_t id, double &rot, double &tilt, double &psi, double &xoff, double &yoff, bool &flip, double &weight)
 Get angles (either from reading the header or from a docfile) More...
 
void getAllMatrices (MetaData &SF)
 Fill array with transformation matrices needed for arbitrary geometry filter. More...
 
void getSampledMatrices (MetaData &SF)
 
void simpleBackprojection (Projection &img, MultidimArray< double > &vol, int diameter)
 
void filterOneImage (Projection &proj, Tabsinc &TSINC)
 
void apply2DFilterArbitraryGeometry ()
 
- Public Member Functions inherited from ProgReconsBase
virtual ~ProgReconsBase ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_out
 
FileName fn_sym
 
FileName fn_sel
 
MetaDataVec SF
 
double threshold
 
int count_thr
 
int diameter
 
size_t dim
 
int no_mats
 
WBPInfomat_g
 
WBPInfomat_f
 
double sampling
 
bool do_all_matrices
 
bool do_weights
 
SymList SL
 
size_t time_bar_step
 Time bar variables. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
std::unique_ptr< MetaDataVec::id_iteratoriter
 Iterator over input metadata. More...
 
Image< double > reconstructedVolume
 Reconstructed volume. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

WBP parameters.

Definition at line 47 of file reconstruct_wbp.h.

Member Function Documentation

◆ apply2DFilterArbitraryGeometry()

void ProgRecWbp::apply2DFilterArbitraryGeometry ( )

Definition at line 517 of file reconstruct_wbp.cpp.

518 {
519  double rot, tilt, psi, xoff, yoff, weight;
520  bool flip;
521  Projection proj;
522  Matrix2D<double> L(4, 4), R(4, 4), A;
523  FileName fn_img;
524 
525  MultidimArray<double> &mReconstructedVolume = reconstructedVolume();
526  mReconstructedVolume.initZeros(dim, dim, dim);
527  mReconstructedVolume.setXmippOrigin();
528  count_thr = 0;
529 
530  // Initialize time bar
531  if (verbose > 0)
532  {
533  std::cerr << "--> Back-projecting ..." << std::endl;
535  }
536 
537  mat_f = (WBPInfo*) malloc(no_mats * sizeof(WBPInfo));
538  Tabsinc TSINC(0.0001, dim);
539 
540  size_t objId;
541  while (getImageToProcess(objId))
542  {
543  SF.getValue(MDL_IMAGE, fn_img, objId);
544  proj.read(fn_img, false);
545  getAnglesForImage(objId, rot, tilt, psi, xoff, yoff, flip, weight);
546  proj.setRot(rot);
547  proj.setTilt(tilt);
548  proj.setPsi(psi);
549  proj.setShifts(xoff, yoff);
550  proj.setFlip(flip);
551  proj.setWeight(weight);
552  proj.getTransformationMatrix(A, true);
553  if (!A.isIdentity())
554  selfApplyGeometry(xmipp_transformation::BSPLINE3, proj(), A, xmipp_transformation::IS_INV, xmipp_transformation::WRAP);
555  if (do_weights)
556  proj() *= proj.weight();
557  proj().setXmippOrigin();
558  filterOneImage(proj, TSINC);
559  simpleBackprojection(proj, mReconstructedVolume, diameter);
560 
561  showProgress();
562  }
563  if (verbose > 0)
565 
566  // Symmetrize if necessary
567  if (fn_sym != "")
568  {
570  Vaux.resize(mReconstructedVolume);
571  symmetrizeVolume(SL, mReconstructedVolume, Vaux);
572  mReconstructedVolume = Vaux;
573  Mask mask_prm;
574  mask_prm.mode = INNER_MASK;
575  mask_prm.R1 = diameter / 2.;
576  mask_prm.type = BINARY_CIRCULAR_MASK;
577  mask_prm.generate_mask(mReconstructedVolume);
578  mask_prm.apply_mask(mReconstructedVolume, mReconstructedVolume, 0.);
579  }
580 }
void filterOneImage(Projection &proj, Tabsinc &TSINC)
void selfApplyGeometry(int Splinedegree, MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside)
Image< double > reconstructedVolume
Reconstructed volume.
void init_progress_bar(long total)
bool isIdentity() const
Definition: matrix2d.cpp:1323
void setRot(double rot, const size_t n=0)
virtual void showProgress()
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void symmetrizeVolume(const SymList &SL, const MultidimArray< double > &V_in, MultidimArray< double > &V_out, int spline, bool wrap, bool do_outside_avg, bool sum, bool helical, bool dihedral, bool helicalDihedral, double rotHelical, double rotPhaseHelical, double zHelical, double heightFraction, const MultidimArray< double > *mask, int Cn)
Definition: symmetrize.cpp:117
Definition: mask.h:360
size_t time_bar_size
void simpleBackprojection(Projection &img, MultidimArray< double > &vol, int diameter)
FileName fn_sym
void setPsi(double psi, const size_t n=0)
double weight(const size_t n=0) const
void getAnglesForImage(size_t id, double &rot, double &tilt, double &psi, double &xoff, double &yoff, bool &flip, double &weight)
Get angles (either from reading the header or from a docfile)
void setShifts(double xoff, double yoff, double zoff=0., const size_t n=0)
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
Definition: mask.h:635
WBPInfo * mat_f
void setFlip(bool flip, const size_t n=0)
double R1
Definition: mask.h:413
virtual bool getImageToProcess(size_t &objId)
Get 1 image to process.
void progress_bar(long rlen)
int type
Definition: mask.h:402
int verbose
Verbosity level.
bool getValue(MDObject &mdValueOut, size_t id) const override
MetaDataVec SF
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
void setTilt(double tilt, const size_t n=0)
#define BINARY_CIRCULAR_MASK
Definition: mask.h:365
double psi(const double x)
void read(const FileName &fn, const bool only_apply_shifts=false, DataMode datamode=DATA, MDRow *row=nullptr)
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
void initZeros(const MultidimArray< T1 > &op)
void setWeight(double weight, const size_t n=0)
Name of an image (std::string)
int mode
Definition: mask.h:407
constexpr int INNER_MASK
Definition: mask.h:47

◆ defineParams()

void ProgRecWbp::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 90 of file reconstruct_wbp.cpp.

91 {
92  // To screen
94  "Generate 3D reconstruction from projections using the Weighted BackProjection algorithm.");
96  "+This program allows you to generate 3D reconstructions from projections ");
98  "+using the Weighted BackProjection algorithm with arbitrary geometry as ");
100  "+described by Radermacher, M. (1992) Weighted back-projection methods. ");
101  addUsageLine("+Electron Tomography, ed. by J. Frank, Plenum Press.");
103  "angular_projection_matching, angular_discrete_assign, angular_continuous_assign");
105  " -i <input_selfile> : selection file with input images and Euler angles");
107  " [ -o <name=\"wbp.vol\"> ] : filename for output volume ");
109  " [ --doc <docfile=\"\"> ] : Ignore headers and get angles from this docfile ");
111  " [ --radius <int=-1> ] : Reconstruction radius. int=-1 means radius=dim/2 ");
113  " : The volume will be zero outside this radius");
114  addParamsLine(" [ --sym <sym=\"\"> ] : Enforce symmetry ");
116  " :+A symmetry file or point-group description.");
118  " :+Valid point-group descriptions are: C1, Ci, Cs, Cn ");
120  " :+(from here on n must be an integer number with no ");
122  " :+more than 2 digits) Cnv, Cnh, Sn, Dn, Dnv, Dnh, T, ");
124  " :+Td, Th, O, Oh I, I1, I2, I3, I4, I5, Ih. For a full ");
126  " :+description of symmetries look at http://xmipp.cnb.csic.es/twiki/bin/view/Xmipp/Symmetry");
128  " [ --threshold+ <float=0.005> ] : Lower (relative) threshold for filter values ");
130  " :+This is to avoid divisions by zero and consequent ");
132  " :+enhancement of noise. The threshold is given as a relative ");
134  " :+value with respect to the total number of images. The absolute");
136  " :+threshold will be calculated internally as the relative threshold");
138  " :+multiplied by the total number of (symmetry generated) projections.");
140  " [ --filsam+ <float=5>] : Angular sampling rate for geometry filter ");
142  " :+Instead of summing over all experimental images to calculate ");
144  " :+the arbitrary geometry filter, we bin all images in representative ");
146  " :+projection directions, which are sampled every filsam degrees.");
148  " [ --use_each_image+] : Use each image instead of sampled representatives for filter ");
150  " :+If this option is given, all experimental images will be used ");
152  " :+in the summation to calculate the arbitrary geometry filter. For ");
154  " :+large datasets this may be considerably slower than the default ");
156  " :+option of using representative projection directions");
158  " [ --weight] : Use weights stored in image headers or the input metadata");
159  addExampleLine("xmipp_reconstruct_wbp -i images.sel -o reconstruction.vol");
160 }
void addSeeAlsoLine(const char *seeAlso)
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ filterOneImage()

void ProgRecWbp::filterOneImage ( Projection proj,
Tabsinc TSINC 
)

Definition at line 437 of file reconstruct_wbp.cpp.

438 {
440  Matrix2D<double> A(3, 3);
441  double factor, argum, weight, x, y;
442 
443  factor = diameter;
444 
445  //Euler_angles2matrix(proj.rot(), -proj.tilt(), proj.psi(), A);
446  //A = A.inv();
447  Euler_angles2matrix(-proj.rot(), proj.tilt(), -proj.psi(), A);
448  FourierTransform(proj(), IMG);
449  CenterFFT(IMG, true);
450 
451  // loop over all transformation matrices
452  double a00 = MAT_ELEM(A,0,0);
453  double a01 = MAT_ELEM(A,0,1);
454  double a10 = MAT_ELEM(A,1,0);
455  double a11 = MAT_ELEM(A,1,1);
456  double a20 = MAT_ELEM(A,2,0);
457  double a21 = MAT_ELEM(A,2,1);
458  for (int k = 0; k < no_mats; k++)
459  {
460  mat_f[k].x = a00 * mat_g[k].x + a10 * mat_g[k].y + a20 * mat_g[k].z;
461  mat_f[k].y = a01 * mat_g[k].x + a11 * mat_g[k].y + a21 * mat_g[k].z;
462  }
463 
464  double K = ((double) diameter) / dim;
466  {
467  y = K * i;
468  x = K * j;
469  weight = 0.;
470  for (int k = 0; k < no_mats; k++)
471  {
472  argum = x * mat_f[k].x + y * mat_f[k].y;
473  double daux;
474  TSINCVALUE(TSINC, argum, daux);
475  weight += mat_g[k].count * daux;
476  }
477 
478  if (fabs(weight) < threshold)
479  {
480  count_thr++;
481  A2D_ELEM(IMG, i, j) /= SGN(weight) * (threshold * factor);
482  }
483  else
484  {
485  A2D_ELEM(IMG, i, j) /= (weight * factor);
486  }
487  }
488 
489  // Calculate back-projection with the filtered projection
490  CenterFFT(IMG, false);
491  InverseFourierTransform(IMG, proj());
492 }
#define A2D_ELEM(v, i, j)
double threshold
double psi(const size_t n=0) const
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
static double * y
double count
void InverseFourierTransform(const MultidimArray< std::complex< double > > &in, MultidimArray< double > &out)
Definition: xmipp_fft.cpp:155
double rot(const size_t n=0) const
doublereal * x
#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 FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
double tilt(const size_t n=0) const
double z
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
void CenterFFT(MultidimArray< T > &v, bool forward)
Definition: xmipp_fft.h:291
WBPInfo * mat_f
WBPInfo * mat_g
#define TSINCVALUE(Tsinc, x, y)
Definition: xmipp_funcs.h:94
void FourierTransform(const MultidimArray< double > &in, MultidimArray< std::complex< double > > &out)
Definition: xmipp_fft.cpp:124
#define j
constexpr int K
double y
#define SGN(x)
Definition: xmipp_macros.h:155
double x

◆ finishProcessing()

void ProgRecWbp::finishProcessing ( )
virtual

Finish processing

Reimplemented in ProgMPIRecWbp.

Definition at line 170 of file reconstruct_wbp.cpp.

171 {
172  free(mat_g);
173  free(mat_f);
174  if (verbose > 0)
175  std::cerr << "Fourier pixels for which the threshold was not reached: "
176  << (float) (count_thr * 100.) / (SF.size() * dim * dim) << " %"
177  << std::endl;
179 }
Image< double > reconstructedVolume
Reconstructed volume.
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)
size_t size() const override
WBPInfo * mat_f
WBPInfo * mat_g
FileName fn_out
free((char *) ob)
int verbose
Verbosity level.
MetaDataVec SF

◆ getAllMatrices()

void ProgRecWbp::getAllMatrices ( MetaData SF)

Fill array with transformation matrices needed for arbitrary geometry filter.

Definition at line 308 of file reconstruct_wbp.cpp.

309 {
310  Matrix2D<double> A(3, 3);
311  Matrix2D<double> L(4, 4), R(4, 4);
312  double rot, tilt, psi, weight, dum, newrot, newtilt, newpsi, totimgs = 0.;
313  bool dumB;
314  int NN;
315 
316  no_mats = 0;
317 
318  NN = SF.size();
319  NN *= (SL.symsNo() + 1);
320  mat_g = (WBPInfo*) malloc(NN * sizeof(WBPInfo));
321  FileName fn_img;
322 
323  for (size_t objId : SF.ids())
324  {
325  SF.getValue(MDL_IMAGE, fn_img, objId);
326  getAnglesForImage(objId, rot, tilt, psi, dum, dum, dumB, weight);
327  Euler_angles2matrix(rot, -tilt, psi, A);
328  mat_g[no_mats].x = MAT_ELEM(A, 2, 0);
329  mat_g[no_mats].y = MAT_ELEM(A, 2, 1);
330  mat_g[no_mats].z = MAT_ELEM(A, 2, 2);
331  if (do_weights)
332  mat_g[no_mats].count = weight;
333  else
334  mat_g[no_mats].count = 1.;
335  totimgs += mat_g[no_mats].count;
336  no_mats++;
337  // Also add symmetry-related projection directions
338  for (int i = 0; i < SL.symsNo(); i++)
339  {
340  SL.getMatrices(i, L, R);
341  L.resize(3, 3);
342  R.resize(3, 3);
343  Euler_apply_transf(L, R, rot, -tilt, psi, newrot, newtilt, newpsi);
344  Euler_angles2matrix(newrot, newtilt, newpsi, A);
345  mat_g[no_mats].x = MAT_ELEM(A, 2, 0);
346  mat_g[no_mats].y = MAT_ELEM(A, 2, 1);
347  mat_g[no_mats].z = MAT_ELEM(A, 2, 2);
348  if (do_weights)
349  mat_g[no_mats].count = weight;
350  else
351  mat_g[no_mats].count = 1.;
352  totimgs += mat_g[no_mats].count;
353  no_mats++;
354  }
355  }
356 
357  // Adjust relative threshold
358  threshold *= totimgs;
359 }
void getMatrices(int i, Matrix2D< double > &L, Matrix2D< double > &R, bool homogeneous=true) const
Definition: symmetries.cpp:348
double threshold
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
double count
int symsNo() const
Definition: symmetries.h:268
virtual IdIteratorProxy< false > ids()
void getAnglesForImage(size_t id, double &rot, double &tilt, double &psi, double &xoff, double &yoff, bool &flip, double &weight)
Get angles (either from reading the header or from a docfile)
void Euler_apply_transf(const Matrix2D< double > &L, const Matrix2D< double > &R, double rot, double tilt, double psi, double &newrot, double &newtilt, double &newpsi)
Definition: geometry.cpp:1038
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
#define i
double z
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
WBPInfo * mat_g
virtual size_t size() const =0
double psi(const double x)
double y
Name of an image (std::string)
double x

◆ getAnglesForImage()

void ProgRecWbp::getAnglesForImage ( size_t  id,
double &  rot,
double &  tilt,
double &  psi,
double &  xoff,
double &  yoff,
bool &  flip,
double &  weight 
)

Get angles (either from reading the header or from a docfile)

Definition at line 217 of file reconstruct_wbp.cpp.

219 {
220  SF.getValue(MDL_ANGLE_ROT, rot, id);
221  SF.getValue(MDL_ANGLE_TILT, tilt, id);
223  SF.getValue(MDL_SHIFT_X, xoff, id);
224  SF.getValue(MDL_SHIFT_Y, yoff, id);
225  flip = 0;
226  SF.getValue(MDL_FLIP, flip, id);
227  weight = 1;
228  SF.getValue(MDL_WEIGHT, weight, id);
229 }
Rotation angle of an image (double,degrees)
Tilting angle of an image (double,degrees)
Shift for the image in the X axis (double)
Special label to be used when gathering MDs in MpiMetadataPrograms.
Flip the image? (bool)
bool getValue(MDObject &mdValueOut, size_t id) const override
MetaDataVec SF
double psi(const double x)
Shift for the image in the Y axis (double)
< Score 4 for volumes

◆ getImageToProcess()

bool ProgRecWbp::getImageToProcess ( size_t &  objId)
virtual

Get 1 image to process.

Reimplemented in ProgMPIRecWbp.

Definition at line 494 of file reconstruct_wbp.cpp.

495 {
496  if (time_bar_done == 0) {
497  iter = std::unique_ptr<MetaDataVec::id_iterator>(new MetaDataVec::id_iterator(SF.ids().begin()));
498  } else {
499  ++(*iter);
500  }
501 
502  bool isValid = *iter != SF.ids().end();
503  if (isValid) {
504  ++time_bar_done;
505  objId = **iter;
506  }
507  return isValid;
508 }
virtual IdIteratorProxy< false > ids()
std::unique_ptr< MetaDataVec::id_iterator > iter
Iterator over input metadata.
size_t time_bar_done
MetaDataVec SF
idIterator< false > id_iterator

◆ getSampledMatrices()

void ProgRecWbp::getSampledMatrices ( MetaData SF)

Fill array with transformation matrices for representative evenly sampled projection directions

Definition at line 231 of file reconstruct_wbp.cpp.

232 {
233  FileName fn_tmp;
234  Matrix2D<double> A(3, 3);
235  Matrix2D<double> L(4, 4), R(4, 4);
236  double newrot, newtilt, newpsi, rot, tilt, dum, weight, totimgs = 0.;
237  rot = 0;
238  tilt = 0;
239  bool dumB;
240  std::vector<double> count_imgs;
241 
242  if (verbose > 0)
243  std::cerr << "--> Sampling the filter ..." << std::endl;
244 
245  // Create an (asymmetric part of an) even projection direction distribution
246  std::vector<double> rotList, tiltList;
247  make_even_distribution(rotList, tiltList, sampling, SL, true);
248  size_t NN = rotList.size();
249  count_imgs.resize(NN);
250  // Each experimental image contributes to the nearest of these directions
251  FileName fn_img;
252  for (size_t objId : SF.ids())
253  {
254  SF.getValue(MDL_IMAGE, fn_img, objId);
255  getAnglesForImage(objId, rot, tilt, dum, dum, dum, dumB, weight);
256  int idx = find_nearest_direction(rot, tilt, rotList, tiltList, SL, L,
257  R);
258  if (do_weights)
259  count_imgs[idx] += weight;
260  else
261  count_imgs[idx] += 1.;
262  }
263 
264  // Now calculate transformation matrices for all representative directions
265  no_mats = 0;
266  int SL_SymsNo = SL.symsNo();
267  int SL_SymsNo_1 = SL_SymsNo + 1;
268  for (size_t i = 0; i < NN; i++)
269  if (count_imgs[i] > 0.)
270  no_mats += SL_SymsNo_1;
271  mat_g = (WBPInfo*) malloc(no_mats * sizeof(WBPInfo));
272 
273  no_mats = 0;
274  for (size_t i = 0; i < NN; i++)
275  {
276  auto count_i = (int)count_imgs[i];
277  if (count_i > 0)
278  {
279  Euler_angles2matrix(rotList[i], -tiltList[i], 0.0, A);
280  mat_g[no_mats].x = MAT_ELEM(A, 2, 0);
281  mat_g[no_mats].y = MAT_ELEM(A, 2, 1);
282  mat_g[no_mats].z = MAT_ELEM(A, 2, 2);
283  mat_g[no_mats].count = count_i;
284  totimgs += count_i;
285  no_mats++;
286 
287  // Expand symmetric directions
288  for (int j = 0; j < SL_SymsNo; j++)
289  {
290  SL.getMatrices(j, L, R, false);
291  Euler_apply_transf(L, R, rot, tilt, 0., newrot, newtilt, newpsi);
292  Euler_angles2matrix(newrot, -newtilt, newpsi, A);
293  mat_g[no_mats].x = MAT_ELEM(A, 2, 0);
294  mat_g[no_mats].y = MAT_ELEM(A, 2, 1);
295  mat_g[no_mats].z = MAT_ELEM(A, 2, 2);
296  mat_g[no_mats].count = count_i;
297  totimgs += count_i;
298  no_mats++;
299  }
300  }
301  }
302 
303  // Adjust relative threshold
304  threshold *= totimgs;
305 }
void getMatrices(int i, Matrix2D< double > &L, Matrix2D< double > &R, bool homogeneous=true) const
Definition: symmetries.cpp:348
double threshold
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
void make_even_distribution(std::vector< double > &rotList, std::vector< double > &tiltList, double sampling, SymList &SL, bool include_mirror)
Make even distribution, taking symmetry into account.
Definition: directions.cpp:133
double count
int symsNo() const
Definition: symmetries.h:268
virtual IdIteratorProxy< false > ids()
void getAnglesForImage(size_t id, double &rot, double &tilt, double &psi, double &xoff, double &yoff, bool &flip, double &weight)
Get angles (either from reading the header or from a docfile)
void Euler_apply_transf(const Matrix2D< double > &L, const Matrix2D< double > &R, double rot, double tilt, double psi, double &newrot, double &newtilt, double &newpsi)
Definition: geometry.cpp:1038
virtual bool getValue(MDObject &mdValueOut, size_t id) const =0
#define i
double z
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
int find_nearest_direction(double rot1, double tilt1, std::vector< double > &rotList, std::vector< double > &tiltList, SymList &SL, Matrix2D< double > &Laux, Matrix2D< double > &Raux)
Determine which of the entries in DFlib is closest to [rot1,tilt1].
Definition: directions.cpp:194
WBPInfo * mat_g
int verbose
Verbosity level.
#define j
double sampling
double y
Name of an image (std::string)
double x

◆ produceSideInfo()

void ProgRecWbp::produceSideInfo ( )
virtual

Fill arrays with relevant transformation matrices.

Reimplemented in ProgMPIRecWbp.

Definition at line 187 of file reconstruct_wbp.cpp.

188 {
189  // Read-in stuff
190  SF.read(fn_sel);
191  if (do_weights)
192  {
194  if (SF.size() == 0)
196  "there is no input file with weight!=0");
197  }
198 
199  size_t zdim, ndim;
200  getImageSize(SF, dim, dim, zdim, ndim);
201  if (fn_sym != "")
203  if (diameter <= 0)
204  diameter = dim;
205 
206  // Fill arrays of transformation matrices
207  if (do_all_matrices)
209  else
211 
212  time_bar_size = SF.size();
213  time_bar_step = CEIL((double)time_bar_size / 60.0);
214  time_bar_done = 0;
215 }
void removeObjects(const std::vector< size_t > &toRemove) override
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
size_t time_bar_size
int readSymmetryFile(FileName fn_sym, double accuracy=SYM_ACCURACY)
Definition: symmetries.cpp:33
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
FileName fn_sel
void getSampledMatrices(MetaData &SF)
size_t time_bar_step
Time bar variables.
FileName fn_sym
size_t size() const override
Incorrect number of objects in Metadata.
Definition: xmipp_error.h:160
void getAllMatrices(MetaData &SF)
Fill array with transformation matrices needed for arbitrary geometry filter.
#define CEIL(x)
Definition: xmipp_macros.h:225
size_t time_bar_done
MetaDataVec SF
< Score 4 for volumes
bool do_all_matrices

◆ readParams()

void ProgRecWbp::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 38 of file reconstruct_wbp.cpp.

39 {
40  fn_sel = getParam("-i");
41  fn_out = getParam("-o");
42  fn_sym = getParam("--sym");
43  threshold = getDoubleParam("--threshold");
44  diameter = 2 * getIntParam("--radius");
45 
46  sampling = getDoubleParam("--filsam");
47  do_all_matrices = checkParam("--use_each_image");
48  do_weights = checkParam("--weight");
49 }
double getDoubleParam(const char *param, int arg=0)
double threshold
FileName fn_sel
FileName fn_sym
const char * getParam(const char *param, int arg=0)
FileName fn_out
double sampling
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)
bool do_all_matrices

◆ run()

void ProgRecWbp::run ( )
virtual

Do the job

Reimplemented from XmippProgram.

Definition at line 162 of file reconstruct_wbp.cpp.

163 {
164  show();
165  produceSideInfo();
168 }
virtual void produceSideInfo()
Fill arrays with relevant transformation matrices.
void show()
Show.
void apply2DFilterArbitraryGeometry()
virtual void finishProcessing()

◆ setIO()

void ProgRecWbp::setIO ( const FileName fn_in,
const FileName fn_out 
)
virtual

Set IO for a new reconstruction

Implements ProgReconsBase.

Definition at line 181 of file reconstruct_wbp.cpp.

182 {
183  fn_sel = fnIn;
184  fn_out = fnOut;
185 }
FileName fn_sel
FileName fnOut

◆ show()

void ProgRecWbp::show ( )

Show.

Definition at line 52 of file reconstruct_wbp.cpp.

53 {
54  if (verbose > 0)
55  {
56  // To screen
57  std::cerr
58  << " ================================================================="
59  << std::endl;
60  std::cerr << " Weighted-back projection (arbitrary geometry) "
61  << std::endl;
62  std::cerr
63  << " ================================================================="
64  << std::endl;
65  std::cerr << " Input selfile : " << fn_sel << std::endl;
66  std::cerr << " Output volume : " << fn_out << std::endl;
67  if (diameter > 0)
68  std::cerr << " Reconstruction radius : " << diameter / 2
69  << std::endl;
70  std::cerr << " Relative filter threshold : " << threshold << std::endl;
71  if (fn_sym != "")
72  std::cerr << " Symmetry file: : " << fn_sym << std::endl;
73  if (do_all_matrices)
74  std::cerr
75  << " --> Use all projection directions in arbitrary geometry filter"
76  << std::endl;
77  else
78  std::cerr << " --> Use sampled directions for filter, sampling = "
79  << sampling << std::endl;
80  if (do_weights)
81  std::cerr << " --> Use weights stored in the image headers"
82  << std::endl;
83  std::cerr
84  << " -----------------------------------------------------------------"
85  << std::endl;
86  }
87 }
double threshold
FileName fn_sel
FileName fn_sym
FileName fn_out
int verbose
Verbosity level.
double sampling
bool do_all_matrices

◆ showProgress()

void ProgRecWbp::showProgress ( )
virtual

Show progress

Reimplemented in ProgMPIRecWbp.

Definition at line 510 of file reconstruct_wbp.cpp.

511 {
512  if (verbose > 0 && time_bar_done % time_bar_step == 0)
514 }
size_t time_bar_step
Time bar variables.
void progress_bar(long rlen)
int verbose
Verbosity level.
size_t time_bar_done

◆ simpleBackprojection()

void ProgRecWbp::simpleBackprojection ( Projection img,
MultidimArray< double > &  vol,
int  diameter 
)

Definition at line 362 of file reconstruct_wbp.cpp.

364 {
365  //this should be int not size_t ROB
366  int i, j, k, l, m;
367  Matrix2D<double> A(3, 3);
368  double dim2, x, y, z, xp, yp;
369  double value1, value2, scalex, scaley, value;
370  double radius2, x2, y2, z2, z2_plus_y2;
371 
372  // Use minus-tilt, because code copied from OldXmipp
373  Euler_angles2matrix(img.rot(), -img.tilt(), img.psi(), A);
374  A = A.inv();
375 
376  radius2 = diameter / 2.;
377  radius2 = radius2 * radius2;
378  dim2 = dim / 2;
379  double a00 = MAT_ELEM(A,0,0);
380  double a01 = MAT_ELEM(A,0,1);
381  double a10 = MAT_ELEM(A,1,0);
382  double a11 = MAT_ELEM(A,1,1);
383  double a20 = MAT_ELEM(A,2,0);
384  double a21 = MAT_ELEM(A,2,1);
385 
386  double dim1 = dim - 1;
387  const MultidimArray<double> mImg = img();
388  int idim;
389  idim = dim;//cast to int from size_t
390  for (i = 0; i < idim; i++)
391  {
392  z = -i + dim2; /*** Z points upwards ***/
393  z2 = z * z;
394  if (z2 > radius2)
395  continue;
396  double xpz = z * a20 + dim2;
397  double ypz = z * a21 + dim2;
398  for (j = 0; j < idim; j++)
399  {
400  y = j - dim2;
401  y2 = y * y;
402  z2_plus_y2 = z2 + y2;
403  if (z2_plus_y2 > radius2)
404  continue;
405  x = 0 - dim2; /***** X for k == 0 *****/
406  xp = x * a00 + y * a10 + xpz;
407  yp = x * a01 + y * a11 + ypz;
408  if (yp >= dim1 || yp < 0.0)
409  continue;
410  l = (int) yp;
411  scaley = yp - l;
412  double scale1y = 1. - scaley;
413  for (k = 0; k < idim; k++, xp += a00, yp += a01, x++)
414  {
415  x2 = x * x;
416  if (x2 + z2_plus_y2 > radius2)
417  continue;
418  if (xp >= dim1 || xp < 0.0)
419  continue;
420 
421  /**** interpolation ****/
422  m = (int) xp;
423  scalex = xp - m;
424  double scale1x = 1. - scalex;
425  value1 = scalex * dAij(mImg, l, m + 1)
426  + scale1x * dAij(mImg, l, m);
427  value2 = scalex * dAij(mImg, l + 1, m + 1)
428  + scale1x * dAij(mImg, l + 1, m);
429  value = scaley * value2 + scale1y * value1;
430  dAkij(vol, i, j, k) += value;
431  }
432  }
433  }
434 }
double psi(const size_t n=0) const
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
#define dAij(M, i, j)
static double * y
double rot(const size_t n=0) const
doublereal * x
#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 tilt(const size_t n=0) const
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define dAkij(V, k, i, j)
double z
#define j
int m

Member Data Documentation

◆ count_thr

int ProgRecWbp::count_thr

Counter for how many times the threshold was not reached

Definition at line 57 of file reconstruct_wbp.h.

◆ diameter

int ProgRecWbp::diameter

Diameter for reconstruction

Definition at line 59 of file reconstruct_wbp.h.

◆ dim

size_t ProgRecWbp::dim

verbosity flag dimensions of the images

Definition at line 63 of file reconstruct_wbp.h.

◆ do_all_matrices

bool ProgRecWbp::do_all_matrices

Flag whether to use all experimental projection directions instead of sampled projection directions for arbitrary geometry filter

Definition at line 72 of file reconstruct_wbp.h.

◆ do_weights

bool ProgRecWbp::do_weights

Flag whether to use the weights in the image headers

Definition at line 74 of file reconstruct_wbp.h.

◆ fn_out

FileName ProgRecWbp::fn_out

Filenames

Definition at line 51 of file reconstruct_wbp.h.

◆ fn_sel

FileName ProgRecWbp::fn_sel

Definition at line 51 of file reconstruct_wbp.h.

◆ fn_sym

FileName ProgRecWbp::fn_sym

Definition at line 51 of file reconstruct_wbp.h.

◆ iter

std::unique_ptr<MetaDataVec::id_iterator> ProgRecWbp::iter

Iterator over input metadata.

Definition at line 80 of file reconstruct_wbp.h.

◆ mat_f

WBPInfo * ProgRecWbp::mat_f

Definition at line 67 of file reconstruct_wbp.h.

◆ mat_g

WBPInfo* ProgRecWbp::mat_g

columns of matrices

Definition at line 67 of file reconstruct_wbp.h.

◆ no_mats

int ProgRecWbp::no_mats

Number of elements in matrix array

Definition at line 65 of file reconstruct_wbp.h.

◆ reconstructedVolume

Image<double> ProgRecWbp::reconstructedVolume

Reconstructed volume.

Definition at line 82 of file reconstruct_wbp.h.

◆ sampling

double ProgRecWbp::sampling

Angular sampling for projection directions of arbitrary geometry filter

Definition at line 69 of file reconstruct_wbp.h.

◆ SF

MetaDataVec ProgRecWbp::SF

SelFile containing all projections and angles

Definition at line 53 of file reconstruct_wbp.h.

◆ SL

SymList ProgRecWbp::SL

Symmetry list for symmetric volumes

Definition at line 76 of file reconstruct_wbp.h.

◆ threshold

double ProgRecWbp::threshold

Lower threshold for the filter

Definition at line 55 of file reconstruct_wbp.h.

◆ time_bar_done

size_t ProgRecWbp::time_bar_done

Definition at line 78 of file reconstruct_wbp.h.

◆ time_bar_size

size_t ProgRecWbp::time_bar_size

Definition at line 78 of file reconstruct_wbp.h.

◆ time_bar_step

size_t ProgRecWbp::time_bar_step

Time bar variables.

Definition at line 78 of file reconstruct_wbp.h.


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