Xmipp  v3.23.11-Nereus
angular_assignment_mag.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jeison Méndez García (jmendez@utp.edu.co)
4  *
5  * Instituto de Investigaciones en Matemáticas Aplicadas y en Sistemas -- IIMAS
6  * Universidad Nacional Autónoma de México -UNAM
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #ifndef __ANGULAR_ASSIGNMENT_MAG_H
28 #define __ANGULAR_ASSIGNMENT_MAG_H
29 
31 #include "core/matrix1d.h"
32 #include "core/metadata_vec.h"
33 #include <core/xmipp_fftw.h>
34 #include <core/multidim_array.h>
35 #include <core/symmetries.h>
36 #include <core/xmipp_image.h>
37 #include <data/mask.h>
38 #include <data/filters.h>
39 #include "CTPL/ctpl_stl.h"
40 
41 
42 #include <vector>
43 
47 
50 {
51 public:
52  void defineParams() override;
53  void readParams() override;
54  void show() const override;
55  void preProcess() override;
56  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut) override;
57  void postProcess() override;
60  void applyRotation(const MultidimArray<double> &, double &, MultidimArray<double> &) const;
61  void applyShiftAndRotation(const MultidimArray<double> &MDaRef, double &rot, double &tx, double &ty, MultidimArray<double> &MDaRefRot) const;
62 
64  virtual void synchronize() {}
65 
66  size_t rank;
67  size_t Nprocessors;
68 
69 private:
70  double angDistance(int &, int &, Matrix1D<double> &, Matrix1D<double> &);
71  void bestCand(const MultidimArray<double> &MDaIn, const MultidimArray<std::complex<double> > &MDaInF, const MultidimArray<double> &MDaRef, std::vector<double> &cand, double &bestCandRot, double &shift_x, double &shift_y, double &bestCoeff);
72  void completeFourierShift(const MultidimArray<double> &in, MultidimArray<double> &out) const;
73  void ccMatrix(const MultidimArray<std::complex<double> > &F1, const MultidimArray<std::complex<double> > &F2, MultidimArray<double> &result, FourierTransformer &transformer);
74  void checkStorageSpace();
75  void computingNeighborGraph();
76  void computeEigenvectors();
77  void computeLaplacianMatrix (Matrix2D<double> &L, const std::vector< std::vector<int> > &allNeighborsjp, const std::vector< std::vector<double> > &allWeightsjp) const;
78  void computeCircular();
79  void circularWindow(MultidimArray<double> &in) const;
80  void getShift(MultidimArray<double> &ccVector, double &shift, const size_t &size) const;
81  void graphFourierFilter(const Matrix1D<double> &ccVecIn, Matrix1D<double> &ccVecOut) const;
82  MultidimArray<double> imToPolar(MultidimArray<double> &cartIm, size_t &start, size_t &end);
83  double interpolate(MultidimArray<double> &cartIm, double &x_coord, double &y_coord) const;
84  void maxByColumn(const MultidimArray<double> &in, MultidimArray<double> &out) const;
85  void maxByRow(const MultidimArray<double> &in, MultidimArray<double> &out) const;
86 
87  void processGallery(FileName &);
88  void psiCandidates(const MultidimArray<double> &in, std::vector<double> &cand, const size_t &size);
89  void validateAssignment(int &, int &, double &, double &, const MDRow &, MDRow &, MultidimArray<double> &, Matrix1D<double> &);
90 
91  ctpl::thread_pool threadPool;
92 
94  FileName fnIn;
95  FileName fnOut;
96  FileName fnDir;
97  FileName fnSym;
98  FileName fnRef;
99 
100  // Metadata with input images and input volumes
101  MetaDataVec mdIn;
102  MetaDataVec mdRef;
103  MetaDataVec mdOut;
104 
105  // Transformers
106  std::vector<FourierTransformer> transformersForImages;
107  FourierTransformer transformerPolarImage;
108  FourierTransformer transformerImage;
109  FourierTransformer transformerPolarRealSpace;
110  std::vector<FourierTransformer> ccMatrixBestCandidTransformers;
111  FourierTransformer ccMatrixProcessImageTransformer;
112 
113  std::vector<MultidimArray<double>> ccMatrixShifts;
114 
115  // vector of reference images
116  std::vector< MultidimArray<double> > vecMDaRef;
117 
118  // vector of Fourier of reference images
119  std::vector< MultidimArray< std::complex<double> > > vecMDaRefF;
120 
121  // vector of Fourier of polar representation of reference image in real space
122  std::vector< MultidimArray< std::complex<double> > > vecMDaRef_polarF;
123 
124  // vector of Fourier of polar representation of magnitude spectrum of reference images
125  std::vector< MultidimArray< std::complex<double> > > vecMDaRefFMs_polarF;
126 
127  // Size of the images
128  size_t Xdim;
129  size_t Ydim;
130 
131  MultidimArray<double> C; // circular mask
132 
133  // eigenDecomposition
134  Matrix1D<double> eigenvalues;
135  Matrix2D<double> eigenvectors;
136 
137  int peaksFound = 0; // peaksFound in ccVectorRot
138 
139  // matrix for neighbors and angular distance
140  std::vector< std::vector<int> > neighborsMatrix; // this should be global
141  std::vector< std::vector<double> > neighboursDistance; // not sure if necessary this global
142  std::vector< std::vector<double> > neighborsWeights; // this variable should be global
143 
144  //reference image - projection coordinates
145  std::vector<double> referenceRot;
146  std::vector<double> referenceTilt;
147 
149  FileName inputReference_volume;
150  Image<double> refVol;
151  // Size of the reference volume
152  int refXdim;
153  int refYdim;
154  int refZdim;
155 
156  // threads to use
157  int threads;
158 
159  int sizeMdRef;
160  int sizeMdIn;
161  size_t n_bands;
162  size_t startBand;
163  size_t finalBand;
164  size_t n_rad;
165  size_t n_ang;
166  size_t n_ang2;
167  double maxShift;
168  double sampling;
169  double angStep;
170 
171  // Symmetry list
172  SymList SL;
173  // Left matrices for the symmetry transformations
174  std::vector< Matrix2D<double> > L;
175  // Right matrices for the symmetry transformations
176  std::vector< Matrix2D<double> > R;
177 
179  bool useForValidation;
180 
181 };
183 
184 
185 #endif
void applyShiftAndRotation(const MultidimArray< double > &MDaRef, double &rot, double &tx, double &ty, MultidimArray< double > &MDaRefRot) const
virtual void synchronize()
Synchronize with other processors.
int in
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut) override
void applyRotation(const MultidimArray< double > &, double &, MultidimArray< double > &) const