119 addUsageLine(
"Compute the deformation that properly fits two volumes using spherical harmonics");
122 addParamsLine(
" [-o <volume=\"\">] : Output volume which is the deformed input volume");
124 addParamsLine(
" [--maskr <m=\"\">] : Reference volume mask");
125 addParamsLine(
" [--oroot <rootname=\"Volumes\">] : Root name for output files");
127 addParamsLine(
" [--analyzeStrain] : Save the deformation of each voxel for local strain and rotation analysis");
128 addParamsLine(
" [--optimizeRadius] : Optimize the radius of each spherical harmonic");
129 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
130 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
131 addParamsLine(
" [--regularization <l=0.00025>] : Regularization weight");
132 addParamsLine(
" [--Rmax <r=-1>] : Maximum radius for the transformation");
133 addParamsLine(
" [--blobr <b=4>] : Blob radius for forward mapping splatting");
135 addParamsLine(
" [--clnm <metadata_file=\"\">] : List of deformation coefficients");
136 addExampleLine(
"xmipp_forward_zernike_volume -i vol1.vol -r vol2.vol -o vol1DeformedTo2.vol");
152 VI().setXmippOrigin();
153 VR().setXmippOrigin();
155 VR2().initZeros(
VR());
156 VR2().setXmippOrigin();
255 Rmax = basisParams[2];
274 <<
"Volume to deform: " <<
fnVolI << std::endl
275 <<
"Reference volume: " <<
fnVolR << std::endl
276 <<
"Output volume: " <<
fnVolOut << std::endl
277 <<
"Reference mask: " <<
fnMaskR << std::endl
278 <<
"Zernike Degree: " <<
L1 << std::endl
279 <<
"SH Degree: " <<
L2 << std::endl
281 <<
"Regularization: " <<
lambda << std::endl
283 <<
"Blob radius: " <<
blob_r << std::endl
288 template<
bool SAVE_DEFORMATION>
291 size_t idxZ0=2*idxY0;
292 const auto &mVI =
VI();
298 const double iRmax = 1.0 /
Rmax;
299 auto stepsMask = std::vector<size_t>();
301 for (
size_t idx = 0; idx < idxY0; idx++)
305 stepsMask.emplace_back(idx);
310 for (
size_t idx = 0; idx < idxY0; idx++)
312 stepsMask.emplace_back(idx);
331 double gx=0.0, gy=0.0, gz=0.0;
338 double rr=
sqrt(r2)*iRmax;
339 for (
auto idx : stepsMask) {
357 auto pos = std::array<double, 3>{};
362 double voxel_mVI =
A3D_ELEM(mVI,k,i,j);
365 if (SAVE_DEFORMATION) {
400 for (
int k = k0;
k <= kF;
k++)
402 double k2 = (z_pos -
k) * (z_pos -
k);
403 for (
int i = i0;
i <= iF;
i++)
405 double y2 = (y_pos -
i) * (y_pos -
i);
406 for (
int j = j0;
j <= jF;
j++)
408 double mod =
sqrt((x_pos -
j) * (x_pos -
j) + y2 + k2);
409 double didx = mod * 1000;
410 int idx =
ROUND(didx);
436 for (
int k = k0;
k <= kF;
k++)
438 double k2 = (z_pos -
k) * (z_pos -
k);
439 for (
int i = i0;
i <= iF;
i++)
441 double y2 = (y_pos -
i) * (y_pos -
i);
442 for (
int j = j0;
j <= jF;
j++)
444 double mod =
sqrt((x_pos -
j) * (x_pos -
j) + y2 + k2);
460 deformVolume<true>();
462 deformVolume<false>();
503 VO().initZeros(
VR());
504 VO().setXmippOrigin();
505 VO2().initZeros(
VR());
506 VO2().setXmippOrigin();
528 VR.
write(
"reference_blob.vol");
546 auto pos = std::array<double, 3>{};
567 for (
int idx=0; idx<
vec.size(); idx++){
574 for (
int h=start;h<=
L2;h++)
584 std::cout<<std::endl;
585 std::cout<<
"-------------------------- Basis Degrees: ("<<
L1<<
","<<h<<
") --------------------------"<<std::endl;
589 0.01, fitness, iter, steps,
true);
591 std::cout<<std::endl;
592 std::cout <<
"Deformation " <<
deformation << std::endl;
593 std::ofstream deformFile;
594 deformFile.open (
fnRoot+
"_deformation.txt");
606 std::cout <<
"Error=" << deformation << std::endl;
607 std::cout <<
"Press any key\n";
608 char c; std::cin >>
c;
624 Gx().initZeros(
VR());
625 Gy().initZeros(
VR());
626 Gz().initZeros(
VR());
627 Gx().setXmippOrigin();
628 Gy().setXmippOrigin();
629 Gz().setXmippOrigin();
637 save.write(
fnRoot+
"_PPPGx.vol");
639 save.write(
fnRoot+
"_PPPGy.vol");
641 save.write(
fnRoot+
"_PPPGz.vol");
698 int totalSize = steps.
size()/3;
699 for (
int idx=0; idx<size; idx++)
703 VEC_ELEM(steps,idx+2*totalSize) = 1;
731 for (
int h=0; h<=l2; h++)
735 int numEven=(count>>1)+(count&1 && !(h&1));
737 vecSize += numSPH*numEven;
739 vecSize += numSPH*(l1-h+1-numEven);
750 for (
int h=0; h<=l2; h++) {
751 int totalSPH = 2*h+1;
753 for (
int l=h;
l<=l1;
l+=2) {
754 for (
int m=0;
m<totalSPH;
m++) {
783 #define Dx(V) (A3D_ELEM(V,k,i,jm2)-8*A3D_ELEM(V,k,i,jm1)+8*A3D_ELEM(V,k,i,jp1)-A3D_ELEM(V,k,i,jp2))/12.0 784 #define Dy(V) (A3D_ELEM(V,k,im2,j)-8*A3D_ELEM(V,k,im1,j)+8*A3D_ELEM(V,k,ip1,j)-A3D_ELEM(V,k,ip2,j))/12.0 785 #define Dz(V) (A3D_ELEM(V,km2,i,j)-8*A3D_ELEM(V,km1,i,j)+8*A3D_ELEM(V,kp1,i,j)-A3D_ELEM(V,kp2,i,j))/12.0 790 LS().initZeros(
Gx());
791 LR().initZeros(
Gx());
812 std::vector< std::complex<double> > eigs;
852 for (
size_t n=0;
n < eigs.size();
n++)
854 double imagabs=fabs(eigs[
n].imag());
870 std::ofstream outFile;
872 outFile.open(outPath);
874 outFile.open(outPath, std::ios_base::app);
877 outFile << std::endl;
886 for(
int i = 0;
i < N; ++
i)
895 std::stringstream iss(s);
897 std::vector<double> v;
898 while (iss >> number)
914 auto pos = std::array<double, 3>{};
959 double diff2v1 = 1.0;
962 double diff2v2 = 1.0;
967 val += 0.5 * ((diffv1 * diffv1) + (diffv2 * diffv2));
double kaiser_value(double r, double a, double alpha, int m)
bool analyzeStrain
Save the deformation of each voxel for local strain and rotation analysis.
double alpha
Smoothness parameter.
double getDoubleParam(const char *param, int arg=0)
Matrix1D< double > steps_cp
__host__ __device__ float2 floor(const float2 v)
double continuousZernikeCostVol(double *p, void *vprm)
std::string readNthLine(int N) const
void volume2Blobs(MultidimArray< double > &vol, MultidimArray< double > &vol2, const MultidimArray< double > &mV, const MultidimArray< int > &mask)
void computeStrain()
Compute strain.
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)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
FileName fnMaskR
Filename of the reference volume mask.
FileName fnVolR
Reference volume.
int vecSize
Coefficient vector size.
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
Matrix1D< double > gaussianProjectionTable2
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
Image< double > VI
Images.
const char * getParam(const char *param, int arg=0)
double splatVal(std::array< double, 3 > r, double weight, const MultidimArray< double > &mV)
double Rmax
Maximum radius for the transformation.
void resize(size_t Xdim, bool copy=true)
MultidimArray< int > V_maskr
FileName fnVolI
Volume to deform.
void addExampleLine(const char *example, bool verbatim=true)
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.
void writeVector(std::string outPath, Matrix1D< double > v, bool append)
Save vector to file.
int verbose
Verbosity level.
void defineParams()
Define params.
MultidimArray< int > V_maski
3D mask for reference volume
int L1
Degree of Zernike polynomials and spherical harmonics.
void mod(const MultidimArray< T > &x, MultidimArray< T > &m, double y)
double distance(double *pclnm)
Distance.
void allEigs(const Matrix2D< double > &A, std::vector< std::complex< double > > &eigs)
std::vector< double > vec
std::vector< double > string2vector(std::string const &s) const
void generate_mask(bool apply_geo=false)
bool optimizeRadius
Radius optimization.
Matrix1D< double > gaussianProjectionTable
void rmsd(MultidimArray< double > vol1, MultidimArray< double > vol2, double &val)
FileName withoutExtension() const
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mVO1, MultidimArray< double > &mVO2)
#define BINARY_CIRCULAR_MASK
FileName fnRoot
Root name for several output files.
int order
Derivation order and Bessel function order.
bool checkParam(const char *param)
MultidimArray< int > V_mask2
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
const MultidimArray< int > & get_binary_mask() const
T * adaptForNumericalRecipes() const
int getIntParam(const char *param, int arg=0)
double radius
Spatial radius in Universal System units.
void readParams()
Read arguments from command line.
double fitness(double *p)
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
FileName fnVolOut
Output Volume (deformed input volume)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
void volume2Mask(MultidimArray< double > &vol, double thr)
double gaussian1D(double x, double sigma, double mu)