00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef IMG_ALG_TRANSFORM_SHIFT_HH
00022 #define IMG_ALG_TRANSFORM_SHIFT_HH
00023
00024 #include <ost/img/image_state.hh>
00025 #include <ost/img/value_util.hh>
00026 #include <ost/img/alg/module_config.hh>
00027
00028 namespace ost { namespace img { namespace alg {
00029
00030 namespace {
00031
00032 unsigned int absmod(int x, unsigned int y)
00033 {
00034 return x<0 ? y+std::div(x,y).rem : std::div(x,y).rem;
00035 }
00036
00037 }
00038
00039 class DLLEXPORT_IMG_ALG ShiftFnc {
00040 public:
00041 ShiftFnc(): shift_() {}
00042 ShiftFnc(const Point& s): shift_(s) {}
00043
00044 template <typename T, class D>
00045 ImageStateBasePtr VisitState(const ImageStateImpl<T,D>& in_state) const {
00046 boost::shared_ptr<ImageStateImpl<T,D> > isi = in_state.CloneState(false);
00047
00048 unsigned int depth=in_state.GetExtent().GetDepth();
00049 unsigned int height=in_state.GetExtent().GetHeight();
00050 unsigned int width=in_state.GetExtent().GetWidth();
00051
00052 unsigned int p0=absmod(shift_[0],width);
00053 unsigned int p1=absmod(shift_[1],height);
00054 unsigned int p2=absmod(shift_[2],depth);
00055
00056 for(unsigned int u=0;u<width;++u) {
00057 for(unsigned int v=0;v<height;++v) {
00058 for(unsigned int w=0;w<depth;++w) {
00059 isi->Value(Index((u+p0)%width,(v+p1)%height,(w+p2)%depth))=in_state.Value(Index(u,v,w));
00060 }
00061 }
00062 }
00063
00064 return isi;
00065 }
00066
00067 static String GetAlgorithmName() {return "Shift";}
00068
00069 private:
00070 Point shift_;
00071 };
00072
00073 typedef ImageStateConstModOPAlgorithm<ShiftFnc> Shift;
00074
00075 }}}
00076
00077 #endif