Xmipp  v3.23.11-Nereus
angular_sph_alignment_gpu.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  * David Herreros Calero (dherreros@cnb.csic.es)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
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 _PROG_ANGULAR_SPH_ALIGNMENT_GPU
28 #define _PROG_ANGULAR_SPH_ALIGNMENT_GPU
29 
31 #include "core/rerunable_program.h"
32 #include "core/matrix1d.h"
33 #include "core/matrix2d.h"
34 #include "core/xmipp_image.h"
35 #include "data/numerical_tools.h"
36 #include "memory"
37 
39 
40 // Forward declaration: fourier filter includes fftw, which doesn't compile with cuda 8
41 class FourierFilter;
42 class CTFDescription;
43 
47 
50 {
51 public:
59  int L1, L2;
63  double maxShift;
67  double maxResol;
69  double Ts;
71  int Rmax;
72  // Optimize alignment
74  //Optimize deformation
76  //Optimize defocus
78  // Ignore CTF
79  bool ignoreCTF;
80  //Radius optimization
82  // Phase Flipped
84  // Regularization weight
85  double lambda;
86  // Maximum radius for the deformation
87  int RmaxDef;
88 
91 
92  // CUDA device to use
93  int device;
94 
95 public:
97  bool resume;
98  // 2D and 3D masks in real space
100  // Volume size
101  size_t Xdim;
102  // Input image
104  // Theoretical projection
106  // Filter
107  std::unique_ptr<FourierFilter> filter;
108  // Transformation matrix
110  // Original angles
112  // Original shift
114  // Original flip
115  bool old_flip;
116  // CTF Check
117  bool hasCTF;
118  // Original defocus
120  // Current defoci
122  // CTF
123  std::unique_ptr<CTFDescription> ctf;
124  // CTF filter
125  std::unique_ptr<FourierFilter> FilterCTF;
126  // Vector Size
127  int vecSize;
128  // Vector containing the degree of the spherical harmonics
130  //Copy of Optimizer steps
132  //Total Deformation, sumV, sumVd
134  // Show optimization
136  // Correlation
137  double correlation;
138  // GPU compute class
140  // Number of ones in steps array
142  // Switch between GPU and CPU version
144  // Rotation matrix
146 
147 public:
150 
153 
155  void readParams();
156 
158  void show() const override;
159 
161  void defineParams();
162 
165  void preProcess();
166 
170  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
171 
173  void numCoefficients(int l1, int l2, int &vecSize);
174 
176  // void minimizepos(Matrix1D<double> &vectpos);
177  void minimizepos(int L1, int l2, Matrix1D<double> &steps);
178 
180  void fillVectorTerms(int l1, int l2, Matrix1D<int> &vL1, Matrix1D<int> &vN,
181  Matrix1D<int> &vL2, Matrix1D<int> &vM);
182 
184  void deformVol(MultidimArray<double> &mVD, const MultidimArray<double> &mV, double &def,
185  double rot, double tilt, double psi);
186 
187  void updateCTFImage(double defocusU, double defocusV, double angle);
188 
189  double tranformImageSph(double *pclnm, double rot, double tilt, double psi,
190  Matrix2D<double> &A, double deltaDefocusU,
191  double deltaDefocusV, double deltaDefocusAngle);
192 
194  virtual void finishProcessing();
195 
197  virtual void writeImageParameters(const FileName &fnImg);
198  protected:
199  virtual void createWorkFiles() {
200  return Rerunable::createWorkFiles(resume, getInputMd());
201  }
202 
203  private:
205 
206  std::vector<MDLabel> getLabelsForEmpty() override {
207  return std::vector<MDLabel>{MDL_IMAGE,
208  MDL_ENABLED,
212  MDL_SHIFT_X,
213  MDL_SHIFT_Y,
214  MDL_FLIP,
217  MDL_COST};
218  }
219 };
221 #endif
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
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.
FileName fnOutDir
Output directory.
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
Is this image enabled? (int [-1 or 1])
~ProgAngularSphAlignmentGpu()
Destructor.
AngularAlignmentGpu::AngularSphAlignment angularAlignGpu
void updateCTFImage(double defocusU, double defocusV, double angle)
virtual void createWorkFiles(bool resume, MetaData *md)
Deformation in voxels.
Cost for the image (double)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
Flip the image? (bool)
void show() const override
Show.
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, Matrix2D< double > &A, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
void readParams()
Read argument from command line.
double steps
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
double psi(const double x)
Deformation coefficients.
ProgAngularSphAlignmentGpu()
Empty constructor.
std::unique_ptr< CTFDescription > ctf
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void defineParams()
Define parameters.
Shift for the image in the Y axis (double)
std::unique_ptr< FourierFilter > FilterCTF
Name of an image (std::string)
std::unique_ptr< FourierFilter > filter
virtual void writeImageParameters(const FileName &fnImg)