OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
alg_shift.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 #ifndef IMG_ALG_TRANSFORM_SHIFT_HH
22 #define IMG_ALG_TRANSFORM_SHIFT_HH
23 
24 #include <ost/img/image_state.hh>
25 #include <ost/img/value_util.hh>
27 
28 namespace ost { namespace img { namespace alg {
29 
30 namespace {
31 
32 unsigned int absmod(int x, unsigned int y)
33 {
34  return x<0 ? y+std::div(x,y).rem : std::div(x,y).rem;
35 }
36 
37 } // anon ns
38 
40 public:
41  ShiftFnc(): shift_() {}
42  ShiftFnc(const Point& s): shift_(s) {}
43 
44  template <typename T, class D>
45  ImageStateBasePtr VisitState(const ImageStateImpl<T,D>& in_state) const {
46  boost::shared_ptr<ImageStateImpl<T,D> > isi = in_state.CloneState(false);
47 
48  unsigned int depth=in_state.GetExtent().GetDepth();
49  unsigned int height=in_state.GetExtent().GetHeight();
50  unsigned int width=in_state.GetExtent().GetWidth();
51 
52  unsigned int p0=absmod(shift_[0],width);
53  unsigned int p1=absmod(shift_[1],height);
54  unsigned int p2=absmod(shift_[2],depth);
55 
56  for(unsigned int u=0;u<width;++u) {
57  for(unsigned int v=0;v<height;++v) {
58  for(unsigned int w=0;w<depth;++w) {
59  isi->Value(Index((u+p0)%width,(v+p1)%height,(w+p2)%depth))=in_state.Value(Index(u,v,w));
60  }
61  }
62  }
63 
64  return isi;
65  }
66 
67  static String GetAlgorithmName() {return "Shift";}
68 
69 private:
70  Point shift_;
71 };
72 
73 typedef ImageStateConstModOPAlgorithm<ShiftFnc> Shift;
74 
75 }}} // ns
76 
77 #endif
ImageStateConstModOPAlgorithm< ShiftFnc > Shift
Definition: alg_shift.hh:73
std::string String
Definition: base.hh:54
#define DLLEXPORT_IMG_ALG
ShiftFnc(const Point &s)
Definition: alg_shift.hh:42
static String GetAlgorithmName()
Definition: alg_shift.hh:67
boost::shared_ptr< ImageStateBase > ImageStateBasePtr
ImageStateBasePtr VisitState(const ImageStateImpl< T, D > &in_state) const
Definition: alg_shift.hh:45
class encapsulating 1D to 3D point
Definition: point.hh:43