OpenStructure
Loading...
Searching...
No Matches
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-2020 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
25#include <ost/img/value_util.hh>
27
28namespace {
29
30unsigned int absmod(int x, unsigned int y)
31{
32 return x<0 ? y+std::div(x,y).rem : std::div(x,y).rem;
33}
34
35} // anon ns
36
37namespace ost { namespace img { namespace alg {
38
40public:
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
69private:
70 Point shift_;
71};
72
74
75}}} // ns
76
77#endif
int GetDepth() const
int GetWidth() const
int GetHeight() const
class encapsulating 1D to 3D point
Definition point.hh:47
ImageStateBasePtr VisitState(const ImageStateImpl< T, D > &in_state) const
Definition alg_shift.hh:45
ShiftFnc(const Point &s)
Definition alg_shift.hh:42
static String GetAlgorithmName()
Definition alg_shift.hh:67
out-of-place modifying image state const visitor plus op algorithm
SharedPtrType CloneState(bool cc=true) const
virtual Extent GetExtent() const
Retrieve Extent.
#define DLLEXPORT_IMG_ALG
std::string String
Definition base.hh:54
ImageStateConstModOPAlgorithm< ShiftFnc > Shift
Definition alg_shift.hh:73
Definition base.dox:1