Xmipp  v3.23.11-Nereus
parallel_forward_art_zernike3d.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Herreros Calero dherreros@cnb.csic.es
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 
27 #ifndef _PROG_PARALLEL_FORWARD_ART_ZERNIKE3D
28 #define _PROG_PARALLEL_FORWARD_ART_ZERNIKE3D
29 
31 #include <core/matrix1d.h>
32 #include <core/xmipp_image.h>
33 #include <data/fourier_filter.h>
35 #include <core/xmipp_error.h>
36 #include <data/blobs.h>
37 #include <CTPL/ctpl_stl.h>
38 // #include <atomic>
39 
40 
43 {
44 public:
54  int L1, L2;
58  double Ts;
60  int RmaxDef;
61  // Phase Flipped
63  // Ignore CTF
64  bool ignoreCTF;
65  // Regularization ART
66  double lambda;
67  // Save each # iter
68  int save_iter;
69  // Correct CTF
70  bool useCTF;
71  // Apply Zernike
72  bool useZernike;
73  // Flag for enable/disabled image
75 
76 public:
78  bool resume;
79  // Number of ART iterations
80  int niter;
81  // Sort last N projections
83  // 2D and 3D masks in real space
85  // Volume size
86  size_t Xdim;
87  // Input image
89  // INput image
91  // Spherical mask
93  // Theoretical projection
94  std::vector<Image<double>> P;
95  // Weight Image
96  std::vector<Image<double>> W;
97  // Atomic mutex
98  std::vector<std::unique_ptr<std::atomic<double*>>> p_busy_elem;
99  std::vector<std::unique_ptr<std::atomic<double*>>> w_busy_elem;
100  // std::atomic<double*> v_busy_elem{ nullptr };
101  // Difference Image
103  // Transformation matrix
105  // Original angles
106  double rot, tilt, psi;
107  // Original shift
108  double shiftX, shiftY;
109  // Original flip
110  bool flip;
111  // CTF Check
112  bool hasCTF;
113  // Original defocus
115  // CTF
117  // CTF filter
119  // Vector Size
120  int vecSize;
121  // Vector containing the degree of the spherical harmonics
122  std::vector<double> clnm;
123  // Show optimization
125  // Row ids ordered in a orthogonal fashion
127  // Save iter counter
129  // Image counter
131  // Current ART iteration
133  // Volume dimensions
135  // Loop step
137  // Sigma
138  std::vector<double> sigma;
139 
140  // Filter
142 
143  // Parallelization
145  int threads;
146 
147 public:
148  enum class Mode { Proj, Vol };
149 
152 
155 
157  void readParams();
158 
160  void show();
161 
163  void defineParams();
164 
167  void preProcess();
168 
172  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
173 
175  void numCoefficients(int l1, int l2, int &vecSize);
176 
178  void fillVectorTerms(int l1, int l2, Matrix1D<int> &vL1, Matrix1D<int> &vN,
179  Matrix1D<int> &vL2, Matrix1D<int> &vM);
180 
183  const MultidimArray<double> &mV,
184  double rot, double tilt, double psi);
185 
186  void recoverVol();
187  virtual void finishProcessing();
188 
189  private:
190  enum class Direction { Forward, Backward };
191 
192  // ART algorithm
193  template <Direction DIRECTION>
194  void artModel();
195 
196  // Apply Zernike codeformation
197  template<bool USESZERNIKE, Direction DIRECTION>
198  void zernikeModel();
199 
200  // Spaltting at position r
201  void splattingAtPos(std::array<double, 2> r, double weight,
203  MultidimArray<double> &mV, double &sg);
204 
205  virtual void run();
206 
207  // Sort images in an orthogonal fashion
208  void sortOrthogonal();
209 
210  void forwardModel(int k, bool usesZernike);
211  void backwardModel(int k, bool usesZernike);
212 
213 };
215 #endif
std::vector< std::unique_ptr< std::atomic< double * > > > w_busy_elem
void deformVol(MultidimArray< double > &mP, MultidimArray< double > &mW, const MultidimArray< double > &mV, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
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
~ProgParallelForwardArtZernike3D()
Destructor.
std::vector< std::unique_ptr< std::atomic< double * > > > p_busy_elem
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void readParams()
Read argument from command line.