Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <volume_deform_sph_gpu.h>

Inheritance diagram for ProgVolumeDeformSphGpu:
Inheritance graph
[legend]
Collaboration diagram for ProgVolumeDeformSphGpu:
Collaboration graph
[legend]

Public Member Functions

void defineParams ()
 Define params. More...
 
void readParams ()
 Read arguments from command line. More...
 
void show () const override
 Show. More...
 
double distance (double *pclnm)
 Distance. More...
 
void run ()
 Run. More...
 
void minimizepos (int L1, int l2, Matrix1D< double > &steps)
 Determine the positions to be minimize of a vector containing spherical harmonic coefficients. More...
 
void numCoefficients (int l1, int l2, int &vecSize)
 Length of coefficients vector. More...
 
void fillVectorTerms (int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
 Zernike and SPH coefficients allocation. More...
 
void computeStrain ()
 Compute strain. More...
 
void writeVector (std::string outPath, Matrix1D< double > v, bool append)
 Save vector to file. More...
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

VolumeDeformSph volDefSphGpu
 GPU computer. More...
 
FileName fnVolI
 Volume to deform. More...
 
FileName fnVolR
 Reference volume. More...
 
FileName fnVolOut
 Output Volume (deformed input volume) More...
 
FileName fnRoot
 Root name for several output files. More...
 
bool analyzeStrain
 Save the deformation of each voxel for local strain and rotation analysis. More...
 
bool optimizeRadius
 Radius optimization. More...
 
int L1
 Degree of Zernike polynomials and spherical harmonics. More...
 
int L2
 
Matrix1D< int > vL1
 Zernike and SPH coefficients vectors. More...
 
Matrix1D< int > vN
 
Matrix1D< int > vL2
 
Matrix1D< int > vM
 
std::vector< double > sigma
 Gaussian width to filter the volumes. More...
 
std::vector< Image< double > > volumesI
 Image Vector. More...
 
std::vector< Image< double > > volumesR
 
double Rmax
 Maximum radius for the transformation. More...
 
int vecSize
 Coefficient vector size. More...
 
Image< double > VI
 Images. More...
 
Image< double > VR
 
Image< double > VO
 
Image< double > Gx
 
Image< double > Gy
 
Image< double > Gz
 
std::vector< double > absMaxR_vec
 Maxima of reference volumes (in absolute value) More...
 
Matrix1D< double > clnm
 
Matrix1D< double > steps_cp
 
unsigned onesInSteps
 
unsigned Ncount
 
double deformation
 
double sumVI
 
double sumVD
 
double lambda
 
bool applyTransformation
 
bool saveDeformation
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Sph Alignment Parameters.

Definition at line 39 of file volume_deform_sph_gpu.h.

Member Function Documentation

◆ computeStrain()

void ProgVolumeDeformSphGpu::computeStrain ( )

Compute strain.

Definition at line 515 of file volume_deform_sph_gpu.cpp.

516 {
517  Image<double> LS, LR;
518  LS().initZeros(Gx());
519  LR().initZeros(Gx());
520 
521  // Gaussian filter of the derivatives
525  f.w1=2;
526  f.applyMaskSpace(Gx());
527  f.applyMaskSpace(Gy());
528  f.applyMaskSpace(Gz());
529 
530  Gx.write(fnRoot+"_PPPGx.vol");
531  Gy.write(fnRoot+"_PPPGy.vol");
532  Gz.write(fnRoot+"_PPPGz.vol");
533 
534  MultidimArray<double> &mLS=LS();
535  MultidimArray<double> &mLR=LR();
536  MultidimArray<double> &mGx=Gx();
537  MultidimArray<double> &mGy=Gy();
538  MultidimArray<double> &mGz=Gz();
539  Matrix2D<double> U(3,3), D(3,3), H(3,3);
540  std::vector< std::complex<double> > eigs;
541  H.initZeros();
542  for (int k=STARTINGZ(mLS)+2; k<=FINISHINGZ(mLS)-2; ++k)
543  {
544  int km1=k-1;
545  int kp1=k+1;
546  int km2=k-2;
547  int kp2=k+2;
548  for (int i=STARTINGY(mLS)+2; i<=FINISHINGY(mLS)-2; ++i)
549  {
550  int im1=i-1;
551  int ip1=i+1;
552  int im2=i-2;
553  int ip2=i+2;
554  for (int j=STARTINGX(mLS)+2; j<=FINISHINGX(mLS)-2; ++j)
555  {
556  int jm1=j-1;
557  int jp1=j+1;
558  int jm2=j-2;
559  int jp2=j+2;
560  MAT_ELEM(U,0,0)=Dx(mGx); MAT_ELEM(U,0,1)=Dy(mGx); MAT_ELEM(U,0,2)=Dz(mGx);
561  MAT_ELEM(U,1,0)=Dx(mGy); MAT_ELEM(U,1,1)=Dy(mGy); MAT_ELEM(U,1,2)=Dz(mGy);
562  MAT_ELEM(U,2,0)=Dx(mGz); MAT_ELEM(U,2,1)=Dy(mGz); MAT_ELEM(U,2,2)=Dz(mGz);
563 
564  MAT_ELEM(D,0,0) = MAT_ELEM(U,0,0);
565  MAT_ELEM(D,0,1) = MAT_ELEM(D,1,0) = 0.5*(MAT_ELEM(U,0,1)+MAT_ELEM(U,1,0));
566  MAT_ELEM(D,0,2) = MAT_ELEM(D,2,0) = 0.5*(MAT_ELEM(U,0,2)+MAT_ELEM(U,2,0));
567  MAT_ELEM(D,1,1) = MAT_ELEM(U,1,1);
568  MAT_ELEM(D,1,2) = MAT_ELEM(D,2,1) = 0.5*(MAT_ELEM(U,1,2)+MAT_ELEM(U,2,1));
569  MAT_ELEM(D,2,2) = MAT_ELEM(U,2,2);
570 
571  MAT_ELEM(H,0,1) = 0.5*(MAT_ELEM(U,0,1)-MAT_ELEM(U,1,0));
572  MAT_ELEM(H,0,2) = 0.5*(MAT_ELEM(U,0,2)-MAT_ELEM(U,2,0));
573  MAT_ELEM(H,1,2) = 0.5*(MAT_ELEM(U,1,2)-MAT_ELEM(U,2,1));
574  MAT_ELEM(H,1,0) = -MAT_ELEM(H,0,1);
575  MAT_ELEM(H,2,0) = -MAT_ELEM(H,0,2);
576  MAT_ELEM(H,2,1) = -MAT_ELEM(H,1,2);
577 
578  A3D_ELEM(mLS,k,i,j)=fabs(D.det());
579  allEigs(H,eigs);
580  for (size_t n=0; n < eigs.size(); n++)
581  {
582  double imagabs=fabs(eigs[n].imag());
583  if (imagabs>1e-6)
584  {
585  A3D_ELEM(mLR,k,i,j)=imagabs*180/PI;
586  break;
587  }
588  }
589  }
590  }
591  LS.write(fnVolOut.withoutExtension()+"_strain.mrc");
592  LR.write(fnVolOut.withoutExtension()+"_rotation.mrc");
593  }
594 }
#define FINISHINGX(v)
#define Dy(V)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
#define FINISHINGZ(v)
#define STARTINGX(v)
FileName fnRoot
Root name for several output files.
#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
#define STARTINGY(v)
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define A3D_ELEM(V, k, i, j)
double * f
FileName fnVolOut
Output Volume (deformed input volume)
#define Dz(V)
void allEigs(const Matrix2D< double > &A, std::vector< std::complex< double > > &eigs)
Definition: matrix2d.cpp:345
#define j
#define FINISHINGY(v)
FileName withoutExtension() const
#define Dx(V)
#define REALGAUSSIAN
#define PI
Definition: tools.h:43
#define STARTINGZ(v)
int * n
#define LOWPASS
void applyMaskSpace(MultidimArray< double > &v)

◆ defineParams()

void ProgVolumeDeformSphGpu::defineParams ( )
virtual

Define params.

Reimplemented from XmippProgram.

Definition at line 34 of file volume_deform_sph_gpu.cpp.

34  {
35  addUsageLine("Compute the deformation that properly fits two volumes using spherical harmonics (GPU accelerated)");
36  addParamsLine(" -i <volume> : Volume to deform");
37  addParamsLine(" -r <volume> : Reference volume");
38  addParamsLine(" [-o <volume=\"\">] : Output volume which is the deformed input volume");
39  addParamsLine(" [--oroot <rootname=\"Volumes\">] : Root name for output files");
40  addParamsLine(" : By default, the input file is rewritten");
41  addParamsLine(" [--sigma <Matrix1D=\"\">] : Sigma values to filter the volume to perform a multiresolution analysis");
42  addParamsLine(" [--analyzeStrain] : Save the deformation of each voxel for local strain and rotation analysis");
43  addParamsLine(" [--optimizeRadius] : Optimize the radius of each spherical harmonic");
44  addParamsLine(" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
45  addParamsLine(" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
46  addParamsLine(" [--regularization <l=0.00025>] : Regularization weight");
47  addParamsLine(" [--Rmax <r=-1>] : Maximum radius for the transformation");
48  addExampleLine("xmipp_volume_deform_sph -i vol1.vol -r vol2.vol -o vol1DeformedTo2.vol");
49 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ distance()

double ProgVolumeDeformSphGpu::distance ( double *  pclnm)

Distance.

Definition at line 99 of file volume_deform_sph_gpu.cpp.

100 {
102  {
103  VO().initZeros(VR());
104  VO().setXmippOrigin();
105  }
106 
108  VEC_ELEM(clnm,i)=pclnm[i+1];
109 #ifdef DEBUG
110  std::cout << "Starting to evaluate\n" << clnm << std::endl;
111 #endif
112 
113  double diff2=0.0;
114  sumVD = 0.0;
115  double modg=0.0;
116 
117 // GPU computation
119 
121 
123 
124  auto result = volDefSphGpu.getOutputs();
125  diff2 = result.diff2;
126  modg = result.modg;
127  sumVD = result.sumVD;
128 // GPU computation end
129 
131 
132 #ifdef DEBUG
133  Image<double> save;
134  save() = VI();
135  save.write(fnRoot+"_PPPIdeformed.vol");
136  save()-=VR();
137  save.write(fnRoot+"_PPPdiff.vol");
138  save()=VR();
139  save.write(fnRoot+"_PPPR.vol");
140  if (saveDeformation)
141  {
142  save() = Gx();
143  save.write(fnRoot+"_PPPGx.vol");
144  save() = Gy();
145  save.write(fnRoot+"_PPPGy.vol");
146  save() = Gz();
147  save.write(fnRoot+"_PPPGz.vol");
148  }
149  std::cout << "Error=" << deformation << " " << std::sqrt(diff2/totalVal) << std::endl;
150  std::cout << "Press any key\n";
151  char c; std::cin >> c;
152 #endif
153 
155  VO.write(fnVolOut);
156 
157  double massDiff=std::abs(sumVI-sumVD)/sumVI;
158  return std::sqrt(diff2/Ncount)+lambda*(deformation+massDiff);
159 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
Image< double > VI
Images.
doublereal * c
KernelOutputs getOutputs()
void sqrt(Image< double > &op)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void abs(Image< double > &op)
FileName fnRoot
Root name for several output files.
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
FileName fnVolOut
Output Volume (deformed input volume)
VolumeDeformSph volDefSphGpu
GPU computer.

◆ fillVectorTerms()

void ProgVolumeDeformSphGpu::fillVectorTerms ( int  l1,
int  l2,
Matrix1D< int > &  vL1,
Matrix1D< int > &  vN,
Matrix1D< int > &  vL2,
Matrix1D< int > &  vM 
)

Zernike and SPH coefficients allocation.

Definition at line 467 of file volume_deform_sph_gpu.cpp.

469 {
470  int idx = 0;
471  vL1.initZeros(vecSize);
472  vN.initZeros(vecSize);
473  vL2.initZeros(vecSize);
474  vM.initZeros(vecSize);
475  for (int h=0; h<=l2; h++)
476  {
477  int totalSPH = 2*h+1;
478  int aux = std::floor(totalSPH/2);
479  for (int l=h; l<=l1; l+=2)
480  {
481  for (int m=0; m<totalSPH; m++)
482  {
483  VEC_ELEM(vL1,idx) = l;
484  VEC_ELEM(vN,idx) = h;
485  VEC_ELEM(vL2,idx) = h;
486  VEC_ELEM(vM,idx) = m-aux;
487  idx++;
488  }
489  }
490  }
491 }
int vecSize
Coefficient vector size.
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
__host__ __device__ float2 floor(const float2 v)
void initZeros()
Definition: matrix1d.h:592
int m

◆ minimizepos()

void ProgVolumeDeformSphGpu::minimizepos ( int  L1,
int  l2,
Matrix1D< double > &  steps 
)

Determine the positions to be minimize of a vector containing spherical harmonic coefficients.

Definition at line 417 of file volume_deform_sph_gpu.cpp.

418 {
419  int size = 0;
420  numCoefficients(L1,l2,size);
421  onesInSteps = size;
422  int totalSize = steps.size()/3;
423  for (int idx=0; idx<size; idx++)
424  {
425  VEC_ELEM(steps,idx) = 1;
426  VEC_ELEM(steps,idx+totalSize) = 1;
427  VEC_ELEM(steps,idx+2*totalSize) = 1;
428  }
429 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
size_t size() const
Definition: matrix1d.h:508
int L1
Degree of Zernike polynomials and spherical harmonics.
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.

◆ numCoefficients()

void ProgVolumeDeformSphGpu::numCoefficients ( int  l1,
int  l2,
int &  vecSize 
)

Length of coefficients vector.

Definition at line 453 of file volume_deform_sph_gpu.cpp.

454 {
455  for (int h=0; h<=l2; h++)
456  {
457  int numSPH = 2*h+1;
458  int count=l1-h+1;
459  int numEven=(count>>1)+(count&1 && !(h&1));
460  if (h%2 == 0)
461  vecSize += numSPH*numEven;
462  else
463  vecSize += numSPH*(l1-h+1-numEven);
464  }
465 }
int vecSize
Coefficient vector size.

◆ readParams()

void ProgVolumeDeformSphGpu::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 52 of file volume_deform_sph_gpu.cpp.

52  {
53  std::string aux;
54  fnVolI = getParam("-i");
55  fnVolR = getParam("-r");
56  L1 = getIntParam("--l1");
57  L2 = getIntParam("--l2");
58  fnRoot = getParam("--oroot");
59 
60  aux = getParam("--sigma");
61  // Transform string ov values separated by white spaces into substrings stored in a vector
62  std::stringstream ss(aux);
63  std::istream_iterator<std::string> begin(ss);
64  std::istream_iterator<std::string> end;
65  std::vector<std::string> vstrings(begin, end);
66  sigma.resize(vstrings.size());
67  std::transform(vstrings.begin(), vstrings.end(), sigma.begin(), [](const std::string& val)
68  {
69  return std::stod(val);
70  });
71 
72  fnVolOut = getParam("-o");
73  if (fnVolOut=="")
74  fnVolOut=fnVolI;
75  analyzeStrain=checkParam("--analyzeStrain");
76  optimizeRadius=checkParam("--optimizeRadius");
77  lambda = getDoubleParam("--regularization");
78  Rmax = getDoubleParam("--Rmax");
79  applyTransformation = false;
80 }
double getDoubleParam(const char *param, int arg=0)
FileName fnRoot
Root name for several output files.
int L1
Degree of Zernike polynomials and spherical harmonics.
const char * getParam(const char *param, int arg=0)
std::vector< double > sigma
Gaussian width to filter the volumes.
FileName fnVolOut
Output Volume (deformed input volume)
bool optimizeRadius
Radius optimization.
FileName fnVolI
Volume to deform.
bool checkParam(const char *param)
bool analyzeStrain
Save the deformation of each voxel for local strain and rotation analysis.
double Rmax
Maximum radius for the transformation.
int getIntParam(const char *param, int arg=0)
FileName fnVolR
Reference volume.

◆ run()

void ProgVolumeDeformSphGpu::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 169 of file volume_deform_sph_gpu.cpp.

169  {
170 
171  saveDeformation=false;
172 
173  VI.read(fnVolI);
174  VR.read(fnVolR);
175  sumVI = 0.0;
176  if (Rmax<0)
177  Rmax=XSIZE(VI())/2;
178 
179  VI().setXmippOrigin();
180  VR().setXmippOrigin();
181 
182  //GPU preparation
184  //GPU preparation end
185 
186  // Filter input and reference volumes according to the values of sigma
187  FourierFilter filter;
188  filter.FilterShape = REALGAUSSIAN;
189  filter.FilterBand = LOWPASS;
190  filter.generateMask(VI());
191 
192  // We need also to normalized the filtered volumes to compare them appropiately
193  Image<double> auxI = VI;
194  Image<double> auxR = VR;
195 
196  MultidimArray<int> bg_mask;
197  bg_mask.resizeNoCopy(VI().zdim, VI().ydim, VI().xdim);
198  bg_mask.setXmippOrigin();
199  normalize_Robust(auxI(), bg_mask, true);
200  bg_mask *= 0;
201  normalize_Robust(auxR(), bg_mask, true);
202 
204  {
205  if (DIRECT_A3D_ELEM(auxI(),k,i,j) >= 0.0)
206  sumVI += DIRECT_A3D_ELEM(auxI(),k,i,j);
207  }
208 
209  if (sigma.size() == 1 && sigma[0] == 0)
210  {
211  volumesI.push_back(auxI());
212  volumesR.push_back(auxR());
213  }
214  else
215  {
216  volumesI.push_back(auxI());
217  volumesR.push_back(auxR());
218  for (unsigned ids=0; ids<sigma.size(); ids++)
219  {
220  Image<double> auxI = VI;
221  Image<double> auxR = VR;
222  filter.w1 = sigma[ids];
223 
224  // Filer input vol
225  filter.do_generate_3dmask = true;
226  filter.applyMaskSpace(auxI());
227  bg_mask *= 0;
228  normalize_Robust(auxI(), bg_mask, true);
229  volumesI.push_back(auxI);
231  {
232  if (DIRECT_A3D_ELEM(auxI(),k,i,j) >= 0.0)
233  sumVI += DIRECT_A3D_ELEM(auxI(),k,i,j);
234  }
235  filter.applyMaskSpace(auxR());
236  bg_mask *= 0;
237  normalize_Robust(auxR(), bg_mask, true);
238  volumesR.push_back(auxR);
239  }
240  }
241 
244  vecSize = 0;
246  size_t totalSize = 3*vecSize;
248  clnm.initZeros(totalSize);
249  x.initZeros(totalSize);
250 
251  // GPU preparation
253  Ncount = volumesR.size() * VR().getSize();
254  // GPU preparation end
255 
256  for (int h=0;h<=L2;h++)
257  {
258  steps.clear();
259  steps.initZeros(totalSize);
260  minimizepos(L1,h,steps);
261  steps_cp = steps;
262 
263  std::cout<<std::endl;
264  std::cout<<"-------------------------- Basis Degrees: ("<<L1<<","<<h<<") --------------------------"<<std::endl;
265  // if (h==0)
266  // {
267 
268  // }
269  // else
270  // {
271  // x.resize(VEC_XSIZE(steps),false);
272  // copyvectors(clnm,x);
273  // clnm=x;
274  // }
275 
276  // for(int d=VEC_XSIZE(x)-L+prevL;d<VEC_XSIZE(x);d++)
277  // {
278  // x(d)=Rmax;
279  // clnm(d)=Rmax;
280  // }
281 #ifdef NEVERDEFINED
282  for (int d=0;d<VEC_XSIZE(x);d++)
283  {
284  if (x(d)==0)
285  {
286  steps(d) = 1;
287  }
288  else if (d>=VEC_XSIZE(steps)+nh(h)-nh(h+1)&d<VEC_XSIZE(steps)+nh(h+1))
289  {
290  steps(d) = 1;
291  }
292  else
293  {
294  steps(d) = 0;
295  }
296  //std::cout<<steps(d)<<" ";
297  }
298  //std::cout<<std::endl;
299 #endif
300  // if (h!=0)
301  // {
302  // minimizepos(steps,prevsteps);
303  // }
304  // else
305  // {
306  // steps(VEC_XSIZE(steps)-1)=0;
307  // }
308  int iter;
309  double fitness;
310  powellOptimizer(x, 1, totalSize, &volDeformSphGoal, this,
311  0.01, fitness, iter, steps, true);
312 
313  std::cout<<std::endl;
314  std::cout << "Deformation " << deformation << std::endl;
315  std::ofstream deformFile;
316  deformFile.open (fnRoot+"_deformation.txt");
317  deformFile << deformation;
318  deformFile.close();
319 
320 // #define DEBUG
321 #ifdef DEBUG
322  Image<double> save;
323  save() = VI();
324  save.write(fnRoot+"_PPPIdeformed.vol");
325  save()-=VR();
326  save.write(fnRoot+"_PPPdiff.vol");
327  save()=VR();
328  save.write(fnRoot+"_PPPR.vol");
329  std::cout << "Error=" << deformation << std::endl;
330  std::cout << "Press any key\n";
331  char c; std::cin >> c;
332 #endif
333 
334  }
335  applyTransformation=true;
336  // x.write(fnRoot+"_clnm.txt");
337  Matrix1D<double> degrees;
338  degrees.initZeros(3);
339  VEC_ELEM(degrees,0) = L1;
340  VEC_ELEM(degrees,1) = L2;
341  VEC_ELEM(degrees,2) = Rmax;
342  writeVector(fnRoot+"_clnm.txt", degrees, false);
343  writeVector(fnRoot+"_clnm.txt", x, true);
344  if (analyzeStrain)
345  {
346  saveDeformation=true;
347  Gx().initZeros(VR());
348  Gy().initZeros(VR());
349  Gz().initZeros(VR());
350  Gx().setXmippOrigin();
351  Gy().setXmippOrigin();
352  Gz().setXmippOrigin();
353  }
354 
355  distance(x.adaptForNumericalRecipes()); // To save the output volume
356 
357 #ifdef DEBUG
358  Image<double> save;
359  save() = Gx();
360  save.write(fnRoot+"_PPPGx.vol");
361  save() = Gy();
362  save.write(fnRoot+"_PPPGy.vol");
363  save() = Gz();
364  save.write(fnRoot+"_PPPGz.vol");
365 #endif
366 
367  if (analyzeStrain)
368  computeStrain();
369 }
int vecSize
Coefficient vector size.
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
Image< double > VI
Images.
void clear()
Definition: matrix1d.cpp:67
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
doublereal * c
void resizeNoCopy(const MultidimArray< T1 > &v)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
size_t getSize() const
Definition: xmipp_image.h:1091
double distance(double *pclnm)
Distance.
void powellOptimizer(Matrix1D< double > &p, int i0, int n, double(*f)(double *x, void *), void *prm, double ftol, double &fret, int &iter, const Matrix1D< double > &steps, bool show)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
glob_prnt iter
FileName fnRoot
Root name for several output files.
doublereal * x
#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
doublereal * d
int L1
Degree of Zernike polynomials and spherical harmonics.
void associateWith(ProgVolumeDeformSphGpu *prog)
std::vector< double > sigma
Gaussian width to filter the volumes.
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
void computeStrain()
Compute strain.
#define XSIZE(v)
void normalize_Robust(MultidimArray< double > &I, const MultidimArray< int > &bg_mask, bool clip)
Definition: normalize.cpp:265
Matrix1D< double > steps_cp
Matrix1D< int > vL1
Zernike and SPH coefficients vectors.
double volDeformSphGoal(double *p, void *vprm)
std::vector< Image< double > > volumesI
Image Vector.
void initZeros()
Definition: matrix1d.h:592
#define DIRECT_A3D_ELEM(v, k, i, j)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
#define j
double steps
VolumeDeformSph volDefSphGpu
GPU computer.
std::vector< Image< double > > volumesR
FileName fnVolI
Volume to deform.
void writeVector(std::string outPath, Matrix1D< double > v, bool append)
Save vector to file.
bool analyzeStrain
Save the deformation of each voxel for local strain and rotation analysis.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
double Rmax
Maximum radius for the transformation.
#define REALGAUSSIAN
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
T * adaptForNumericalRecipes() const
Definition: matrix1d.h:844
FileName fnVolR
Reference volume.
void generateMask(MultidimArray< double > &v)
double fitness(double *p)
#define LOWPASS
void applyMaskSpace(MultidimArray< double > &v)

◆ show()

void ProgVolumeDeformSphGpu::show ( ) const
overridevirtual

Show.

Reimplemented from XmippProgram.

Definition at line 83 of file volume_deform_sph_gpu.cpp.

83  {
84  if (verbose==0)
85  return;
86  std::cout
87  << "Volume to deform: " << fnVolI << std::endl
88  << "Reference volume: " << fnVolR << std::endl
89  << "Output volume: " << fnVolOut << std::endl
90  << "Zernike Degree: " << L1 << std::endl
91  << "SH Degree: " << L2 << std::endl
92  << "Save deformation: " << analyzeStrain << std::endl
93  << "Regularization: " << lambda << std::endl
94  ;
95 }
int L1
Degree of Zernike polynomials and spherical harmonics.
FileName fnVolOut
Output Volume (deformed input volume)
int verbose
Verbosity level.
FileName fnVolI
Volume to deform.
bool analyzeStrain
Save the deformation of each voxel for local strain and rotation analysis.
FileName fnVolR
Reference volume.

◆ writeVector()

void ProgVolumeDeformSphGpu::writeVector ( std::string  outPath,
Matrix1D< double >  v,
bool  append 
)

Save vector to file.

Definition at line 596 of file volume_deform_sph_gpu.cpp.

597 {
598  std::ofstream outFile;
599  if (append == false)
600  outFile.open(outPath);
601  else
602  outFile.open(outPath, std::ios_base::app);
604  outFile << VEC_ELEM(v,i) << " ";
605  outFile << std::endl;
606 }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define i
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72

Member Data Documentation

◆ absMaxR_vec

std::vector<double> ProgVolumeDeformSphGpu::absMaxR_vec

Maxima of reference volumes (in absolute value)

Definition at line 86 of file volume_deform_sph_gpu.h.

◆ analyzeStrain

bool ProgVolumeDeformSphGpu::analyzeStrain

Save the deformation of each voxel for local strain and rotation analysis.

Definition at line 58 of file volume_deform_sph_gpu.h.

◆ applyTransformation

bool ProgVolumeDeformSphGpu::applyTransformation

Definition at line 107 of file volume_deform_sph_gpu.h.

◆ clnm

Matrix1D<double> ProgVolumeDeformSphGpu::clnm

Definition at line 89 of file volume_deform_sph_gpu.h.

◆ deformation

double ProgVolumeDeformSphGpu::deformation

Definition at line 101 of file volume_deform_sph_gpu.h.

◆ fnRoot

FileName ProgVolumeDeformSphGpu::fnRoot

Root name for several output files.

Definition at line 55 of file volume_deform_sph_gpu.h.

◆ fnVolI

FileName ProgVolumeDeformSphGpu::fnVolI

Volume to deform.

Definition at line 46 of file volume_deform_sph_gpu.h.

◆ fnVolOut

FileName ProgVolumeDeformSphGpu::fnVolOut

Output Volume (deformed input volume)

Definition at line 52 of file volume_deform_sph_gpu.h.

◆ fnVolR

FileName ProgVolumeDeformSphGpu::fnVolR

Reference volume.

Definition at line 49 of file volume_deform_sph_gpu.h.

◆ Gx

Image<double> ProgVolumeDeformSphGpu::Gx

Definition at line 83 of file volume_deform_sph_gpu.h.

◆ Gy

Image<double> ProgVolumeDeformSphGpu::Gy

Definition at line 83 of file volume_deform_sph_gpu.h.

◆ Gz

Image<double> ProgVolumeDeformSphGpu::Gz

Definition at line 83 of file volume_deform_sph_gpu.h.

◆ L1

int ProgVolumeDeformSphGpu::L1

Degree of Zernike polynomials and spherical harmonics.

Definition at line 64 of file volume_deform_sph_gpu.h.

◆ L2

int ProgVolumeDeformSphGpu::L2

Definition at line 64 of file volume_deform_sph_gpu.h.

◆ lambda

double ProgVolumeDeformSphGpu::lambda

Definition at line 104 of file volume_deform_sph_gpu.h.

◆ Ncount

unsigned ProgVolumeDeformSphGpu::Ncount

Definition at line 98 of file volume_deform_sph_gpu.h.

◆ onesInSteps

unsigned ProgVolumeDeformSphGpu::onesInSteps

Definition at line 95 of file volume_deform_sph_gpu.h.

◆ optimizeRadius

bool ProgVolumeDeformSphGpu::optimizeRadius

Radius optimization.

Definition at line 61 of file volume_deform_sph_gpu.h.

◆ Rmax

double ProgVolumeDeformSphGpu::Rmax

Maximum radius for the transformation.

Definition at line 76 of file volume_deform_sph_gpu.h.

◆ saveDeformation

bool ProgVolumeDeformSphGpu::saveDeformation

Definition at line 110 of file volume_deform_sph_gpu.h.

◆ sigma

std::vector<double> ProgVolumeDeformSphGpu::sigma

Gaussian width to filter the volumes.

Definition at line 70 of file volume_deform_sph_gpu.h.

◆ steps_cp

Matrix1D<double> ProgVolumeDeformSphGpu::steps_cp

Definition at line 92 of file volume_deform_sph_gpu.h.

◆ sumVD

double ProgVolumeDeformSphGpu::sumVD

Definition at line 101 of file volume_deform_sph_gpu.h.

◆ sumVI

double ProgVolumeDeformSphGpu::sumVI

Definition at line 101 of file volume_deform_sph_gpu.h.

◆ vecSize

int ProgVolumeDeformSphGpu::vecSize

Coefficient vector size.

Definition at line 80 of file volume_deform_sph_gpu.h.

◆ VI

Image<double> ProgVolumeDeformSphGpu::VI

Images.

Definition at line 83 of file volume_deform_sph_gpu.h.

◆ vL1

Matrix1D<int> ProgVolumeDeformSphGpu::vL1

Zernike and SPH coefficients vectors.

Definition at line 67 of file volume_deform_sph_gpu.h.

◆ vL2

Matrix1D<int> ProgVolumeDeformSphGpu::vL2

Definition at line 67 of file volume_deform_sph_gpu.h.

◆ vM

Matrix1D<int> ProgVolumeDeformSphGpu::vM

Definition at line 67 of file volume_deform_sph_gpu.h.

◆ vN

Matrix1D<int> ProgVolumeDeformSphGpu::vN

Definition at line 67 of file volume_deform_sph_gpu.h.

◆ VO

Image<double> ProgVolumeDeformSphGpu::VO

Definition at line 83 of file volume_deform_sph_gpu.h.

◆ volDefSphGpu

VolumeDeformSph ProgVolumeDeformSphGpu::volDefSphGpu

GPU computer.

Definition at line 43 of file volume_deform_sph_gpu.h.

◆ volumesI

std::vector<Image<double> > ProgVolumeDeformSphGpu::volumesI

Image Vector.

Definition at line 73 of file volume_deform_sph_gpu.h.

◆ volumesR

std::vector<Image<double> > ProgVolumeDeformSphGpu::volumesR

Definition at line 73 of file volume_deform_sph_gpu.h.

◆ VR

Image<double> ProgVolumeDeformSphGpu::VR

Definition at line 83 of file volume_deform_sph_gpu.h.


The documentation for this class was generated from the following files: