OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
clip_min_max.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 /*
22  Author: Andreas Schenk
23 */
24 
25 #ifndef CLIP_MIN_MAX_HH_
26 #define CLIP_MIN_MAX_HH_
27 
28 namespace ost { namespace img { namespace alg {
29 
30 namespace {
31 
32 template<typename T>
33 bool cbigger(T& v, Real rv, const Complex& cv);
34 
35 template<>
36 bool cbigger<Real>(Real& v, Real rv, const Complex& cv) {return v>=rv;}
37 
38 template<>
39 bool cbigger<Complex>(Complex& v, Real rv, const Complex& cv) {return std::abs(v)>=std::abs(cv);}
40 
41 template<typename T>
42 bool cbigger(T& v, Real rv, const Complex& cv)
43 {
44  return static_cast<Real>(v)>=rv;
45 }
46  template<typename T>
47  T get_t(Real rv, const Complex& cv);
48  template<>
49  Real get_t<Real>(Real rv, const Complex& cv){return rv;}
50  template<>
51  Complex get_t<Complex>(Real rv, const Complex& cv){return cv;}
52  template<typename T>
53  T get_t(Real rv, const Complex& cv){return static_cast<T>(rv);}
54 
55 struct ClipMinMaxFnc {
56  explicit ClipMinMaxFnc() { set_rl(0.0); set_ru(1.0); }
57  explicit ClipMinMaxFnc(Real l,Real u) {set_rl(l);set_ru(u);}
58  explicit ClipMinMaxFnc(const Complex& l, const Complex& u) {set_cl(l);set_cu(u);}
59 
60  void SetThresholds(Real l,Real u) {set_rl(l);set_ru(u);}
61  void SetThresholds(const Complex& l, const Complex& u) {set_cl(l);set_cu(u);}
62 
63  template <typename T, class D>
64  void VisitState(ImageStateImpl<T,D>& isi) const {
65  for(T* p = isi.Data().GetData(); p<isi.Data().GetEnd();++p) {
66  (*p)= cbigger<T>(*p,r_tl_,c_tl_)? (cbigger<T>(*p,r_tu_,c_tu_)? get_t<T>(r_tu_,c_tu_) :(*p)) :get_t<T>(r_tl_,c_tl_) ;
67  }
68  }
69 
70  static String GetAlgorithmName() {return "ClipMinMax";}
71 
72 private:
77 
78  void set_rl(Real f) {r_tl_=f; c_tl_=Val2Val<Real,Complex>(f);}
79  void set_ru(Real f) {r_tu_=f; c_tu_=Val2Val<Real,Complex>(f);}
80  void set_cl(const Complex& f) {c_tl_=f; r_tl_=Val2Val<Complex,Real>(f);}
81  void set_cu(const Complex& f) {c_tu_=f; r_tu_=Val2Val<Complex,Real>(f);}
82 
83 };
84 
85 } // anon ns
86 
87 typedef ImageStateConstModIPAlgorithm<ClipMinMaxFnc> ClipMinMax;
88 
89 }
90 
91 //no expl inst header only impl
92 
93  }} // ns
94 
95 
96 
97 #endif /*SET_MIN_MAX_HH_*/
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
Real r_tu_
Definition: clip_min_max.hh:74
Real Val2Val< Complex, Real >(const Complex &c)
Definition: value_util.hh:91
Complex c_tl_
Definition: clip_min_max.hh:75
Complex c_tu_
Definition: clip_min_max.hh:76
Real r_tl_
Definition: clip_min_max.hh:73
ImageStateConstModIPAlgorithm< ClipMinMaxFnc > ClipMinMax
Definition: clip_min_max.hh:87