82 <<
"Output directory: " <<
fnOutDir << std::endl
83 <<
"Reference volume: " <<
fnVolR << std::endl
84 <<
"Reference mask: " <<
fnMaskR << std::endl
85 <<
"Max. Shift: " <<
maxShift << std::endl
87 <<
"Max. Resolution: " <<
maxResol << std::endl
88 <<
"Sampling: " <<
Ts << std::endl
89 <<
"Max. Radius: " <<
Rmax << std::endl
90 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
91 <<
"Zernike Degree: " <<
L1 << std::endl
92 <<
"SH Degree: " <<
L2 << std::endl
97 <<
"Regularization: " <<
lambda << std::endl
98 <<
"Device: " <<
device << std::endl
105 addUsageLine(
"Make a continuous angular assignment with deformations");
109 defaultComments[
"-o"].addComment(
"Metadata with the angular alignment and deformation parameters");
113 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
114 addParamsLine(
" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
115 addParamsLine(
" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
116 addParamsLine(
" [--max_resolution <f=4>] : Maximum resolution (A)");
117 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
118 addParamsLine(
" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
119 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
120 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
121 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
122 addParamsLine(
" [--optimizeAlignment] : Optimize alignment");
123 addParamsLine(
" [--optimizeDeformation] : Optimize deformation");
125 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
126 addParamsLine(
" [--regularization <l=0.01>] : Regularization weight");
128 addParamsLine(
" [--useCPU] : Uses fake kernel (CPU) instead of GPU kernel");
129 addParamsLine(
" [--device <dev=0>] : GPU device to use. 0th by default");
131 addExampleLine(
"xmipp_cuda_angular_sph_alignment -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
139 V().setXmippOrigin();
183 filter = std::make_unique<FourierFilter>();
184 FilterCTF = std::make_unique<FourierFilter>();
185 ctf = std::make_unique<CTFDescription>();
188 std::cout <<
"Preprocess begins" << std::endl;
197 FilterCTF->FilterBand =
CTF;
198 FilterCTF->ctf.enable_CTFnoise =
false;
199 FilterCTF->ctf.produceSideInfo();
219 double deltaDefocusU,
double deltaDefocusV,
double deltaDefocusAngle)
224 double deformation=0.0;
227 P().setXmippOrigin();
228 deformVol(
P(), mV, deformation, rot, tilt, psi);
260 std::cout <<
"A=" << A << std::endl;
263 save.
write(
"PPPtheo.xmp");
265 save.
write(
"PPPfilteredp.xmp");
267 save.
write(
"PPPfiltered.xmp");
269 std::cout <<
"Cost=" << cost <<
" deformation=" << deformation << std::endl;
270 std::cout <<
"Press any key" << std::endl;
271 char c; std::cin >>
c;
276 std::cout <<
"A=" << A << std::endl;
278 save.
write(
"PPPtheo.xmp");
280 save.
write(
"PPPfilteredp.xmp");
282 save.
write(
"PPPfiltered.xmp");
284 std::cout <<
"Cost=" << cost <<
" corr=" << corr << std::endl;
286 std::cout <<
"Press any key" << std::endl;
287 char c; std::cin >>
c;
291 double retval=cost+
lambda*(deformation + massDiff);
293 std::cout << cost <<
" " << deformation <<
" " <<
lambda*deformation <<
" " <<
sumV <<
" " <<
sumVd <<
" " << massDiff <<
" " << retval << std::endl;
300 int idx = 3*(
prm->vecSize);
301 double deltax=x[idx+1];
302 double deltay=x[idx+2];
303 double deltaRot=x[idx+3];
304 double deltaTilt=x[idx+4];
305 double deltaPsi=x[idx+5];
306 double deltaDefocusU=x[idx+6];
307 double deltaDefocusV=x[idx+7];
308 double deltaDefocusAngle=x[idx+8];
311 if (
prm->maxAngularChange>0 && (fabs(deltaRot)>
prm->maxAngularChange || fabs(deltaTilt)>
prm->maxAngularChange || fabs(deltaPsi)>
prm->maxAngularChange))
321 return prm->tranformImageSph(x,
prm->old_rot+deltaRot,
prm->old_tilt+deltaTilt,
prm->old_psi+deltaPsi,
322 prm->A, deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
356 ctf->readFromMdRow(rowIn);
358 ctf->produceSideInfo();
367 std::cout <<
"Processing " << fnImg << std::endl;
369 I().setXmippOrigin();
377 for (
int h=1;h<=
L2;h++)
381 std::cout<<std::endl;
382 std::cout<<
"------------------------------ Basis Degrees: ("<<
L1<<
","<<h<<
") ----------------------------"<<std::endl;
420 std::cout<<std::endl;
421 for (
int j=1;
j<4;
j++)
426 std::cout <<
"X Coefficients=(";
429 std::cout <<
"Y Coefficients=(";
432 std::cout <<
"Z Coefficients=(";
441 std::cout <<
")" << std::endl;
443 std::cout <<
"Radius=" <<
RmaxDef << std::endl;
444 std::cout <<
" Dshift=(" <<
p(totalSize-5) <<
"," <<
p(totalSize-4) <<
") " 445 <<
"Drot=" <<
p(totalSize-3) <<
" Dtilt=" <<
p(totalSize-2)
446 <<
" Dpsi=" <<
p(totalSize-1) << std::endl;
448 std::cout<<std::endl;
453 std::cerr << XE.what() << std::endl;
454 std::cerr <<
"Warning: Cannot refine " << fnImg << std::endl;
484 std::vector<double> vectortemp;
486 vectortemp.push_back(
clnm(
j));
495 for (
int h=0; h<=l2; h++)
499 int numEven=(count>>1)+(count&1 && !(h&1));
501 vecSize += numSPH*numEven;
504 vecSize += numSPH*(l1-h+1-numEven);
514 int totalSize = (steps.
size()-8)/3;
515 for (
int idx=0; idx<size; idx++) {
518 VEC_ELEM(steps,idx+2*totalSize) = 1.;
530 for (
int h=0; h<=l2; h++) {
531 int totalSPH = 2*h+1;
533 for (
int l=h; l<=l1; l+=2) {
534 for (
int m=0;
m<totalSPH;
m++) {
551 ctf->produceSideInfo();
579 sumVd = outputs.sumVD;
580 def =
sqrt(outputs.modg/outputs.count);
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
void setupConstantParameters()
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void sqrt(Image< double > &op)
MultidimArray< int > V_mask
Image< double > Vdeformed
Image< double > Ifilteredp
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)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
void inv(Matrix2D< T > &result) const
void abs(Image< double > &op)
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.
void setFileName(const FileName &fn)
virtual void createWorkFiles()
virtual void finishProcessing()
~ProgAngularSphAlignmentGpu()
Destructor.
AngularAlignmentGpu::AngularSphAlignment angularAlignGpu
#define MAT_ELEM(m, i, j)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
void updateCTFImage(double defocusU, double defocusV, double angle)
const FileName & getFileName() const
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
Image< double > Ifiltered
MultidimArray< int > mask2D
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
void associateWith(ProgAngularSphAlignmentGpu *prog)
void show() const override
Show.
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
double maxShift
Maximum shift.
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, Matrix2D< double > &A, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
int verbose
Verbosity level.
void readParams()
Read argument from command line.
void setupChangingParameters()
double continuousSphCost(double *x, void *_prm)
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
void generate_mask(bool apply_geo=false)
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
#define BINARY_CIRCULAR_MASK
double psi(const double x)
ProgAngularSphAlignmentGpu()
Empty constructor.
std::unique_ptr< CTFDescription > ctf
bool checkParam(const char *param)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void defineParams()
Define parameters.
void addUsageLine(const char *line, bool verbatim=false)
const MultidimArray< int > & get_binary_mask() const
Matrix1D< double > steps_cp
KernelOutputs getOutputs()
std::unique_ptr< FourierFilter > FilterCTF
T * adaptForNumericalRecipes() const
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)
std::unique_ptr< FourierFilter > filter
std::map< String, CommentList > defaultComments
virtual void writeImageParameters(const FileName &fnImg)