Xmipp  v3.23.11-Nereus
volume_deform_sph.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar coss@cnb.csic.es
4  * David Herreros Calero dherreros@cnb.csic.es
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307 USA
20  *
21  * All comments concerning this program package may be sent to the
22  * e-mail address 'xmipp@cnb.uam.es'
23  ***************************************************************************/
24 
25 #ifndef _PROG_VOL_DEFORM_SPH
26 #define _PROG_VOL_DEFORM_SPH
27 
28 #include <vector>
29 #include <CTPL/ctpl_stl.h>
30 #include "core/xmipp_program.h"
31 #include "core/xmipp_image.h"
32 #include "data/point3D.h"
33 
39 {
40 public:
43 
46 
49 
52 
55 
58 
60  int L1;
61  int L2;
62 
64  std::vector<double> sigma;
65 
67  std::vector<Image<double>> volumesI;
68  std::vector<Image<double>> volumesR;
69 
71  double Rmax;
72 
73 public:
75  int vecSize;
76 
84 
86  std::vector<double> absMaxR_vec;
87 
88  //Deformation in pixels, sumVI, sumVD
89  double deformation;
90  double sumVI;
91  double sumVD;
92 
93  // Regularization
94  double lambda;
95 
96  // Save output volume
98 
99  // Save the values of gx, gy and gz for local strain and rotation analysis
101 
102 public:
104  void defineParams();
105 
107  void readParams();
108 
110  void show();
111 
113  double distance(double *pclnm);
114 
116  void run();
117 
119  void minimizepos(int l2, Matrix1D<double> &steps) const;
120 
122  void numCoefficients(int l1, int l2, int &nc) const;
123 
125  void fillVectorTerms(int l1, int l2);
126 
128  void computeStrain();
129 
131  void writeVector(std::string const &outPath, Matrix1D<double> const &v, bool append) const;
132 
133 private:
134  ctpl::thread_pool m_threadPool;
135  struct ZSH_vals {
136  int l1;
137  int n;
138  int l2;
139  int m;
140  };
141 
142  struct Radius_vals {
143  Radius_vals(int i, int j, int k, double iRmax) {
144  double k2 = k * k;
145  double k2i2 = k2 + i * i;
146  r2 = k2i2 + j * j;
147  ir = i * iRmax;
148  jr = j * iRmax;
149  kr = k * iRmax;
150  rr = std::sqrt(r2) * iRmax;
151  }
152  double r2;
153  double jr;
154  double ir;
155  double kr;
156  double rr;
157 
158  };
159 
160  struct Distance_vals {
161  double VD;
162  double diff;
163  double modg;
164  size_t count;
165  Distance_vals& operator+=(const Distance_vals& rhs) {
166  this->VD += rhs.VD;
167  this->diff += rhs.diff;
168  this->modg += rhs.modg;
169  this->count += rhs.count;
170  return *this;
171  }
172  friend Distance_vals operator+(Distance_vals lhs, const Distance_vals& rhs) {
173  lhs += rhs;
174  return lhs;
175  }
176  };
177 
178  // Zernike and SPH coefficients vectors
179  std::vector<ZSH_vals> m_zshVals;
180 
181  //Vector containing the degree of the Zernike-Spherical harmonics
182  std::vector<Point3D<double>> m_clnm;
183 
184  void computeShift(int k);
185 
186  void computeDistance(int k, Distance_vals &vals);
187 
188  template<bool APPLY_TRANSFORM, bool SAVE_DEFORMATION>
189  void computeDistance(Distance_vals &vals);
190 
191  Distance_vals computeDistance();
192 
193  std::vector<Point3D<double>> m_shifts;
194 };
195 
197 #endif
std::vector< Image< double > > volumesR
std::vector< Image< double > > volumesI
Image Vector.
void computeStrain()
Compute strain.
void computeDistance(const Matrix2D< double > &X, Matrix2D< double > &distance, DimRedDistance2 f, bool computeSqrt)
void sqrt(Image< double > &op)
Image< double > VI
Images.
FileName fnRoot
Root name for several output files.
std::vector< T > operator+(const std::vector< T > &v, const T &a)
Definition: vector_ops.h:51
Image< double > Gy
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.
#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
void readParams()
Read arguments from command line.
int L1
Degree of Zernike polynomials and spherical harmonics.
void numCoefficients(int l1, int l2, int &nc) const
Length of coefficients vector.
std::vector< double > absMaxR_vec
Maxima of reference volumes (in absolute value)
Image< double > Gx
void writeVector(std::string const &outPath, Matrix1D< double > const &v, bool append) const
Save vector to file.
bool optimizeRadius
Radius optimization.
#define j
double steps
Image< double > Gz
int m
Image< double > VO
double distance(double *pclnm)
Distance.
FileName fnVolI
Volume to deform.
bool analyzeStrain
Save the deformation of each voxel for local strain and rotation analysis.
std::vector< T > & operator+=(std::vector< T > &_v1, const std::vector< T > &_v2)
Definition: vector_ops.h:193
double Rmax
Maximum radius for the transformation.
int vecSize
Coefficient vector size.
Image< double > VR
float r2
FileName fnVolR
Reference volume.
std::vector< double > sigma
Gaussian width to filter the volumes.
void minimizepos(int l2, Matrix1D< double > &steps) const
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
void defineParams()
Define params.
int * n
FileName fnVolOut
Output Volume (deformed input volume)
int ir