Skip to content

Commit a45f9da

Browse files
authored
Merge pull request #1031 from I2PC/dh_shift_particles
Fix --shift_to parameter in apply geomtry
2 parents 87f0096 + 1a1b079 commit a45f9da

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/xmipp/libraries/data/transform_geometry.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,12 @@ void ProgTransformGeometry::processImage(const FileName &fnImg,
241241

242242
if (checkParam("--shift_to"))
243243
{
244-
double rot, tilt, psi;
244+
double rot, tilt, psi, sx, sy;
245245
rowIn.getValue(MDL_ANGLE_ROT, rot);
246246
rowIn.getValue(MDL_ANGLE_TILT, tilt);
247247
rowIn.getValue(MDL_ANGLE_PSI, psi);
248+
rowIn.getValue(MDL_SHIFT_X, sx);
249+
rowIn.getValue(MDL_SHIFT_Y, sy);
248250
Matrix1D<double> pos, posp;
249251
pos.initZeros(3);
250252
posp.initZeros(3);
@@ -256,16 +258,16 @@ void ProgTransformGeometry::processImage(const FileName &fnImg,
256258
if (checkParam("--inverse"))
257259
R = R.inv();
258260
posp = R * pos;
259-
rowOut.setValue(MDL_SHIFT_X, -posp(0));
260-
rowOut.setValue(MDL_SHIFT_Y, -posp(1));
261+
rowOut.setValue(MDL_SHIFT_X, sx + posp(0));
262+
rowOut.setValue(MDL_SHIFT_Y, sy + posp(1));
261263
T.initIdentity(3);
262264
int nx;
263265
rowIn.getValue(MDL_XCOOR, nx);
264-
nx += int(-posp(0));
266+
nx += int(sx + posp(0));
265267
rowOut.setValue(MDL_XCOOR, nx);
266268
int ny;
267269
rowIn.getValue(MDL_YCOOR, ny);
268-
ny += int(-posp(1));
270+
ny += int(sy + posp(1));
269271
rowOut.setValue(MDL_YCOOR, ny);
270272
geo2TransformationMatrix(rowOut, T, true);
271273
}
@@ -279,6 +281,33 @@ void ProgTransformGeometry::processImage(const FileName &fnImg,
279281
applyGeometry(splineDegree, imgOut(), img(), T, xmipp_transformation::IS_NOT_INV, wrap, 0.);
280282
imgOut.write(fnImgOut);
281283
rowOut.resetGeo(false);
284+
285+
// When param shift_to is passed, only shifts are applied. Therefore, we should keep any other alignment information
286+
// in the original images to no loose it
287+
if (checkParam("--shift_to")) {
288+
double rot, tilt, psi;
289+
rowIn.getValue(MDL_ANGLE_ROT, rot);
290+
rowIn.getValue(MDL_ANGLE_TILT, tilt);
291+
rowIn.getValue(MDL_ANGLE_PSI, psi);
292+
rowOut.setValue(MDL_ANGLE_ROT, rot);
293+
rowOut.setValue(MDL_ANGLE_TILT, tilt);
294+
rowOut.setValue(MDL_ANGLE_PSI, psi);
295+
296+
Matrix1D<double> pos, posp;
297+
pos.initZeros(3);
298+
posp.initZeros(3);
299+
pos(0) = getDoubleParam("--shift_to", 0);
300+
pos(1) = getDoubleParam("--shift_to", 1);
301+
pos(2) = getDoubleParam("--shift_to", 2);
302+
R.initIdentity(3);
303+
Euler_angles2matrix(rot, tilt, psi, R, false);
304+
if (checkParam("--inverse"))
305+
R = R.inv();
306+
posp = R * pos;
307+
308+
rowOut.setValue(MDL_SHIFT_X, -posp(0));
309+
rowOut.setValue(MDL_SHIFT_Y, -posp(1));
310+
}
282311
}
283312
else
284313
{

0 commit comments

Comments
 (0)