OpenStructure
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-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_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 /* While the functions below are employed by the OST unit tests, GCC does not
36  notice this and complains about "unused functions".
37 */
38 #pragma GCC diagnostic push
39 #pragma GCC diagnostic ignored "-Wunused-function"
40 template<>
41 void set_val<Real>(Real& v, Real rv, const Complex& cv) {v=rv;}
42 
43 template<>
44 void set_val<Complex>(Complex& v, Real rv, const Complex& cv) {v=cv;}
45 #pragma GCC diagnostic pop
46 
47 template<typename T>
48 void set_val(T& v, Real rv, const Complex& cv)
49 {
50  v=static_cast<T>(rv);
51 }
52 
53 struct FillFnc {
54  FillFnc() {}
55 
56  explicit FillFnc(Real f) {set_rval(f);}
57  explicit FillFnc(const Complex& f) {set_cval(f);}
58 
59  void SetFillValue(Real f) {set_rval(f);}
60  void SetFillValue(const Complex& f) {set_cval(f);}
61 
62  template <typename T, class D>
63  void VisitState(ImageStateImpl<T,D>& isi) const {
64  for(T* p = isi.Data().GetData(); p<isi.Data().GetEnd();++p) {
65  /*
66  set_val construct necessary due to missing
67  template function specialization...
68  */
69  set_val<T>(*p,r_fv_,c_fv_);
70  }
71  }
72 
73  static String GetAlgorithmName() {return "Fill";}
74 
75 private:
76  Real r_fv_;
77  Complex c_fv_;
78 
79  void set_rval(Real f) {r_fv_=f; c_fv_=Val2Val<Real,Complex>(f);}
80  void set_cval(const Complex& f) {c_fv_=f; r_fv_=Val2Val<Complex,Real>(f);}
81 };
82 
83 } // anon ns
84 
86 
87 }
88 
89 // completely inlined definition does not need template instantiation
90 
91 }} // ns
92 
93 
94 
95 #endif
in-place modifying image state const visitor plus ip algorithm
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
std::string String
Definition: base.hh:54
ImageStateConstModIPAlgorithm< FillFnc > Fill
Definition: fill.hh:85
Real Val2Val< Complex, Real >(const Complex &c)
Definition: value_util.hh:91
Definition: base.dox:1