31 void ProgApplyCoeffZernike3D::defineParams()
33 addUsageLine(
"Deform a PDB according to a list of SPH deformation coefficients");
36 addParamsLine(
"--clnm <metadata_file> : List of deformation coefficients");
39 addParamsLine(
" [--blobr <b=4>] : Blob radius for forward mapping splatting");
40 addExampleLine(
"xmipp_apply_deform_sph -i input.vol -o volume_deformed.vol --clnm coefficients.txt");
43 void ProgApplyCoeffZernike3D::readParams()
53 void ProgApplyCoeffZernike3D::show()
const 58 <<
"Volume: " << fn_vol << std::endl
59 <<
"Reference mask: " << fn_mask << std::endl
60 <<
"Coefficient list: " << fn_sph << std::endl
61 <<
"Step: " << loop_step << std::endl
62 <<
"Blob radius: " << blob_r << std::endl
63 <<
"Output: " << fn_out << std::endl
67 void ProgApplyCoeffZernike3D::run()
73 VI().setXmippOrigin();
75 VO().setXmippOrigin();
83 line = readNthLine(0);
84 basisParams = string2vector(line);
85 line = readNthLine(1);
86 clnm = string2vector(line);
88 size_t idxY0=(clnm.size())/3;
93 double Rmax=basisParams[2];
94 double Rmax2=Rmax*Rmax;
95 double iRmax=1.0/Rmax;
122 double deformation = 0.0;
143 for (
size_t idx=0; idx<idxY0; idx++)
152 gx += clnm[idx] *zsph;
153 gy += clnm[idx+idxY0] *zsph;
154 gz += clnm[idx+idxZ0] *zsph;
159 auto pos = std::array<double, 3>{};
160 pos[0] = (double)j + gx;
161 pos[1] = (double)i + gy;
162 pos[2] = (double)k + gz;
163 double voxel_mV =
A3D_ELEM(mVI,k,i,j);
164 splattingAtPos(pos, voxel_mV, mVO);
165 deformation += gx*gx+gy*gy+gz*gz;
172 deformation =
sqrt(deformation/Ncount);
173 std::cout <<
"Deformation = " << deformation << std::endl;
177 std::string ProgApplyCoeffZernike3D::readNthLine(
int N)
const 183 for(
int i = 0;
i < N; ++
i)
190 std::vector<double> ProgApplyCoeffZernike3D::string2vector(std::string
const &s)
const 192 std::stringstream iss(s);
194 std::vector<double> v;
195 while (iss >> number)
200 void ProgApplyCoeffZernike3D::fillVectorTerms()
203 auto vecSize = (int)((clnm.size())/3);
208 for (
int h=0; h<=basisParams[1]; h++)
210 int totalSPH = 2*h+1;
212 for (
int l=h; l<=basisParams[0]; l+=2)
214 for (
int m=0;
m<totalSPH;
m++)
226 void ProgApplyCoeffZernike3D::splattingAtPos(std::array<double, 3> r,
double weight,
const MultidimArray<double> &mVO) {
238 for (
int k = k0;
k <= kF;
k++)
240 double z_val = bspline1(
k - z_pos);
241 for (
int i = i0;
i <= iF;
i++)
243 double y_val = bspline1(
i - y_pos);
244 for (
int j = j0;
j <= jF;
j++)
246 double x_val = bspline1(
j - x_pos);
247 A3D_ELEM(mVO,
k,
i,
j) += weight * x_val * y_val * z_val;
253 double ProgApplyCoeffZernike3D::bspline1(
double x)
255 double m = 1 / blob_r;
256 if (0. < x && x < blob_r)
257 return m * (blob_r -
x);
258 else if (-blob_r < x && x <= 0.)
259 return m * (blob_r +
x);
double alpha
Smoothness parameter.
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
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)
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 A3D_ELEM(V, k, i, j)
const char * getParam(const char *param, int arg=0)
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
void generate_mask(bool apply_geo=false)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
#define BINARY_CIRCULAR_MASK
int order
Derivation order and Bessel function order.
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)
const MultidimArray< int > & get_binary_mask() const
int getIntParam(const char *param, int arg=0)
double radius
Spatial radius in Universal System units.
void addParamsLine(const String &line)