OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fill.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_FILL_HH
22 #define IMG_ALG_FILL_HH
23 
24 #include <ost/img/image.hh>
25 #include <ost/img/image_state.hh>
27 
28 namespace ost { namespace img { namespace alg {
29 
30 namespace {
31 
32 template<typename T>
33 void set_val(T& v, Real rv, const Complex& cv);
34 
35 template<>
36 void set_val<Real>(Real& v, Real rv, const Complex& cv) {v=rv;}
37 
38 template<>
39 void set_val<Complex>(Complex& v, Real rv, const Complex& cv) {v=cv;}
40 
41 template<typename T>
42 void set_val(T& v, Real rv, const Complex& cv)
43 {
44  v=static_cast<T>(rv);
45 }
46 
47 struct FillFnc {
48  FillFnc() {}
49 
50  explicit FillFnc(Real f) {set_rval(f);}
51  explicit FillFnc(const Complex& f) {set_cval(f);}
52 
53  void SetFillValue(Real f) {set_rval(f);}
54  void SetFillValue(const Complex& f) {set_cval(f);}
55 
56  template <typename T, class D>
57  void VisitState(ImageStateImpl<T,D>& isi) const {
58  for(T* p = isi.Data().GetData(); p<isi.Data().GetEnd();++p) {
59  /*
60  set_val construct necessary due to missing
61  template function specialization...
62  */
63  set_val<T>(*p,r_fv_,c_fv_);
64  }
65  }
66 
67  static String GetAlgorithmName() {return "Fill";}
68 
69 private:
72 
73  void set_rval(Real f) {r_fv_=f; c_fv_=Val2Val<Real,Complex>(f);}
74  void set_cval(const Complex& f) {c_fv_=f; r_fv_=Val2Val<Complex,Real>(f);}
75 };
76 
77 } // anon ns
78 
79 typedef ImageStateConstModIPAlgorithm<FillFnc> Fill;
80 
81 }
82 
83 // completely inlined definition does not need template instantiation
84 
85 }} // ns
86 
87 
88 
89 #endif
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
Real Val2Val< Complex, Real >(const Complex &c)
Definition: value_util.hh:91
Real r_fv_
Definition: fill.hh:70
ImageStateConstModIPAlgorithm< FillFnc > Fill
Definition: fill.hh:79
Complex c_fv_
Definition: fill.hh:71