Xmipp  v3.23.11-Nereus
forward_zernike_images_priors.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_FORWARD_ZERNIKE_IMAGES_PRIORS
28 #define _PROG_FORWARD_ZERNIKE_IMAGES_PRIORS
29 
31 #include "core/rerunable_program.h"
32 #include "core/matrix1d.h"
33 #include <data/blobs.h>
34 #include "core/xmipp_image.h"
35 #include "data/fourier_filter.h"
37 
41 
44 {
45 public:
55  int L1, L2;
59  double maxShift;
63  double maxResol;
65  double Ts;
67  int Rmax;
68  // Optimize alignment
70  //Optimize defocus
72  // Ignore CTF
73  bool ignoreCTF;
74  //Radius optimization
76  // Phase Flipped
78  // Regularization weight
79  double lambda;
80  // Maximum radius for the deformation
81  int RmaxDef;
82  // Number of images (execution mode) (single image == 1, pair == 2, or triplet == 3)
84  // Number alignment parameters to minimize
86  // Number CTF parameters to minimize
91  bool useCTF;
92 
93 public:
95  bool resume;
96  // 2D and 3D masks in real space
99  std::vector<std::vector<double>> priors;
100  // Volume size
101  size_t Xdim;
102  // Images Filename
103  std::vector<FileName> fnImage;
104  // Input image
106  std::vector<Image<double>> I;
107  std::vector<Image<double>> Ifiltered;
108  std::vector<Image<double>> Ifilteredp;
109  // Theoretical projections
110  std::vector<Image<double>> P;
111  // Filter
113  // Transformation matrix
115  // Original angles
116  std::vector<double> old_rot, old_tilt, old_psi, deltaRot, deltaTilt, deltaPsi;
117  // Original shift
118  std::vector<double> old_shiftX, old_shiftY, deltaX, deltaY;
119  // Original flip
120  bool old_flip;
121  // CTF Check
122  bool hasCTF;
123  // Original defocus
125  // Current defoci
127  // CTF filter
131  // Vector Size
132  int vecSize;
133  // Vector containing the linear combination coefficients for the priors
135  // Deformation coefficients
137  //Copy of Optimizer steps
139  //Total Deformation
141  std::vector<double> prior_deformations;
142  // Show optimization
144  // Correlation
145  double correlation;
146  // Loop step
148  // Blob
149  struct blobtype blob;
150  double blob_r;
152 
153 public:
154  enum class Direction { ROTATE, UNROTATE };
155 
158 
161 
163  void readParams();
164 
166  void show();
167 
169  void defineParams();
170 
173  void preProcess();
174 
178  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
179 
181  void numCoefficients(int l1, int l2, int &vecSize);
182 
184  // void minimizepos(Matrix1D<double> &vectpos);
186 
188  void fillVectorTerms(int l1, int l2, Matrix1D<int> &vL1, Matrix1D<int> &vN,
189  Matrix1D<int> &vL2, Matrix1D<int> &vM);
190 
192  void deformVol(MultidimArray<double> &mVD, const MultidimArray<double> &mV, double &def,
193  double rot, double tilt, double psi);
194 
195  void updateCTFImage(double defocusU, double defocusV, double angle);
196 
197  double transformImageSph(double *pc_priors);
198 
199  //AJ new
201  virtual void finishProcessing();
202 
204  virtual void writeImageParameters(MDRow &row);
205  //END AJ
206 
207  virtual void checkPoint();
208 
209  Matrix1D<double> weightsInterpolation3D(double x, double y, double z);
210 
211  void splattingAtPos(std::array<double, 3> r, double weight, MultidimArray<double> &mP, const MultidimArray<double> &mV);
212 
213  std::vector<double> string2vector(std::string const &s) const;
214 
215  void linearCombinationClnm();
216 
217  void optimalPowellOrder();
218 
219  double bspline1(double x);
220 
221 protected:
223 
224 private:
225  std::vector<MDLabel> getLabelsForEmpty() override
226  {
227  std::vector<MDLabel> labels = getInputMd()->getActiveLabels();
228  labels.push_back(MDL_SPH_DEFORMATION);
229  labels.push_back(MDL_SPH_COEFFICIENTS);
230  labels.push_back(MDL_COST);
231  return labels;
232  }
233 };
235 #endif
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
std::vector< Image< double > > Ifiltered
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
static double * y
std::vector< std::vector< double > > priors
std::vector< double > string2vector(std::string const &s) const
doublereal * x
virtual void createWorkFiles(bool resume, MetaData *md)
Deformation in voxels.
Cost for the image (double)
~ProgForwardZernikeImagesPriors()
Destructor.
double z
double steps
void readParams()
Read argument from command line.
double psi(const double x)
Deformation coefficients.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
virtual std::vector< MDLabel > getActiveLabels() const =0
void minimizepos(Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
std::vector< Image< double > > Ifilteredp
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
void updateCTFImage(double defocusU, double defocusV, double angle)
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.