diff --git a/modules/img/alg/pymod/wrap_alg.cc b/modules/img/alg/pymod/wrap_alg.cc index 7185f34021a1b70e7f6a8f380896ec7feeafcdc6..b024609d30df25346d118fbfaa133b1526908a6a 100644 --- a/modules/img/alg/pymod/wrap_alg.cc +++ b/modules/img/alg/pymod/wrap_alg.cc @@ -236,7 +236,7 @@ BOOST_PYTHON_MODULE(_ost_img_alg) .def("GetBlocksize",&alg::DiscreteShrink::GetBlocksize) ; - class_<alg::FractionalShift, bases<ModIPAlgorithm> >("FractionalShift", init<optional <Real,Real,Real> >() ) + class_<alg::FractionalShift, bases<ConstModIPAlgorithm> >("FractionalShift", init<optional <Real,Real,Real> >() ) .def(init<const Vec3&>()) .def("SetShift",frac_shift0) .def("SetShift",frac_shift1) diff --git a/modules/img/alg/src/fractional_shift.cc b/modules/img/alg/src/fractional_shift.cc index 1d10dac297ab035d9a22643540abc8fa3aa6a882..c9ac40bc9e06ba14524670e3c3d7c71d0ea9c787 100644 --- a/modules/img/alg/src/fractional_shift.cc +++ b/modules/img/alg/src/fractional_shift.cc @@ -29,12 +29,12 @@ namespace ost { namespace img { namespace alg { FractionalShift::FractionalShift(Real sx, Real sy, Real sz): - ModIPAlgorithm("FractionalShift"), + ConstModIPAlgorithm("FractionalShift"), shift_(sx,sy,sz) { } FractionalShift::FractionalShift(const Vec3& v): - ModIPAlgorithm("FractionalShift"), + ConstModIPAlgorithm("FractionalShift"), shift_(v) { } @@ -54,7 +54,7 @@ Vec3 FractionalShift::GetShift() const return shift_; } -void FractionalShift::Visit(ImageHandle& ih) +void FractionalShift::Visit(ImageHandle& ih) const { Vec3 ao=ih.GetAbsoluteOrigin(); diff --git a/modules/img/alg/src/fractional_shift.hh b/modules/img/alg/src/fractional_shift.hh index 9d739f3021623ddab8b25e2bfbc6fa5c54ea59e0..ad787c1dd94020b4e91ebd06746bd8dbb41fcd07 100644 --- a/modules/img/alg/src/fractional_shift.hh +++ b/modules/img/alg/src/fractional_shift.hh @@ -29,7 +29,7 @@ namespace ost { namespace img { namespace alg { -class FractionalShift: public ModIPAlgorithm +class DLLEXPORT_IMG_ALG FractionalShift: public ConstModIPAlgorithm { public: FractionalShift(Real sx=0.0, Real sy=0.0, Real sz=0.0); @@ -38,7 +38,7 @@ public: void SetShift(Real sx=0.0, Real sy=0.0, Real sz=0.0); void SetShift(const Vec3& v); Vec3 GetShift() const; - virtual void Visit(ImageHandle& ih); + virtual void Visit(ImageHandle& ih) const; private: Vec3 shift_; diff --git a/modules/io/src/img/map_io_mrc_handler.cc b/modules/io/src/img/map_io_mrc_handler.cc index c4db2b02c33a8bb3498260309a807c9e10514fbc..c80ec39aba853070679aefdfd7b890cd5b876de0 100644 --- a/modules/io/src/img/map_io_mrc_handler.cc +++ b/modules/io/src/img/map_io_mrc_handler.cc @@ -76,9 +76,11 @@ u v w x . . . d*c*b*a b c d 3 #include <ost/img/image_state.hh> #include <ost/img/alg/stat.hh> #include <ost/img/alg/normalizer_factory.hh> -#include <ost/io/io_exception.hh> #include <ost/img/util.hh> #include <ost/img/progress.hh> +#include <ost/img/alg/fractional_shift.hh> +#include <ost/img/alg/alg_shift.hh> +#include <ost/io/io_exception.hh> #include <ost/io/img/image_format.hh> #include <ost/io/swap_util.hh> #include <ost/io/converting_streams.hh> @@ -987,12 +989,29 @@ void MapIOMrcHandler::Export(const img::MapHandle& sh, std::ostream& loc,const I } else { assert (formatstruct.GetFormatString()==UndefinedImageFormat::FORMAT_STRING); } + img::MapHandle sh2=sh; + if(geom::Length2(sh.GetAbsoluteOrigin())>0.0) { + /* + CCP4/MRC format does not allow arbitrary absolute origin to be used, hence + this correction routine to re-sample the map appropriately + */ + LOG_VERBOSE("mrc io: applying absolute origin shift correction"); + geom::Vec3 frac_shift=geom::CompDivide(sh.GetAbsoluteOrigin(),sh.GetSpatialSampling()); + // apply fractional shift via Fourier space -> will wrap around! + sh2=sh.Apply(img::alg::FractionalShift(frac_shift)); + // force origin to be zero now + sh2.SetAbsoluteOrigin(geom::Vec3(0.0,0.0,0.0)); + // and correct for most of the wrap-around + img::Point int_shift(frac_shift); + sh2.ApplyIP(img::alg::Shift(-int_shift)); + sh2.SetSpatialOrigin(int_shift); + } if (formatmrc.GetSubformat()==MRC_OLD_FORMAT) { LOG_DEBUG("mrc io: exporting old style format"); - detail::export_endianess_switcher<detail::mrc_header>(sh,loc,formatmrc); + detail::export_endianess_switcher<detail::mrc_header>(sh2,loc,formatmrc); } else { LOG_DEBUG("mrc io: exporting new style format"); - detail::export_endianess_switcher<detail::ccp4_header>(sh,loc,formatmrc); + detail::export_endianess_switcher<detail::ccp4_header>(sh2,loc,formatmrc); } }