OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
normalizer_impl.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 /*
22  normalizer interface
23 
24  Authors: Ansgar Philippsen, Andreas Schenk
25 */
26 
27 #ifndef IMG_NORMALIZER_IMPL_H
28 #define IMG_NORMALIZER_IMPL_H
29 
30 #include <boost/shared_ptr.hpp>
31 
32 #include <ost/img/image_state.hh>
33 #include <ost/img/value_util.hh>
34 #include "normalizer_fw.hh"
35 #include <ost/img/module_config.hh>
36 namespace ost { namespace img {
37 
39 // \internal
46 public:
47  virtual ~NormalizeFnc() {}
48  template <typename T, class D>
49  void VisitState(ImageStateImpl<T,D>& s) const {
50 
51  for(T* ptr = s.Data().GetData(); ptr<s.Data().GetEnd(); ++ptr) {
52  *ptr = static_cast<T>(Convert(*ptr));
53  }
54  }
55 
56  // normalizer abstract interface
57  virtual Real BackConvert(Real v) const = 0;
58  virtual Complex BackConvert(Complex v) const = 0;
59  virtual Real Convert(Real v) const = 0;
60  virtual Complex Convert(Complex v) const = 0;
61 
62  static String GetAlgorithmName() {return "Normalizer";}
63 };
64 
66 typedef ImageStateConstModIPAlgorithm<NormalizeFnc> NormalizerBase;
67 
70 public:
71  virtual NormalizerImpl* Clone() const =0;
72 };
73 
76 public:
77  // normalizer abstract interface
78  virtual Real BackConvert(Real v) const {return v;}
79  virtual Complex BackConvert(Complex v) const {return v;}
80  virtual Real Convert(Real v) const {return v;}
81  virtual Complex Convert(Complex v) const {return v;}
82  virtual NormalizerImpl* Clone() const {return new NoOpNormalizer((*this));}
83 };
84 
87 {
88 public:
89  RangeHandler():min_(),max_(){}
90  RangeHandler(Real min,Real max):min_(min),max_(max){}
91  Real GetMinimum() const{return min_;}
92  Real GetMaximum() const{return max_;}
93 protected:
94  Real Clip(Real val) const{return ClipMinMax(val,min_,max_);}
95  Complex Clip(Complex val) const{return ClipMinMax(val,min_,max_);}
96  Real ClipMinMax(Real val,Real minval,Real maxval) const{return std::max<Real>(std::min<Real>(val,maxval),minval);}
97  Complex ClipMinMax(Complex val,Real minval,Real maxval) const {
98  return (val == Complex(0.0)? 1.0 : val/std::abs(val))*std::max<Real>(std::min<Real>(std::abs(val),maxval),minval);
99  }
100 private:
101  Real min_;
102  Real max_;
103 };
104 
105 }} // namespace
106 
107 #endif
Complex ClipMinMax(Complex val, Real minval, Real maxval) const
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
std::complex< Real > Complex
Definition: base.hh:51
RangeHandler(Real min, Real max)
virtual Real BackConvert(Real v) const
Real ClipMinMax(Real val, Real minval, Real maxval) const
Real Clip(Real val) const
Abstract normalizer base class.
virtual NormalizerImpl * Clone() const =0
virtual Real Convert(Real v) const
virtual Complex BackConvert(Complex v) const
Complex Clip(Complex val) const
static String GetAlgorithmName()
virtual Complex Convert(Complex v) const
virtual NormalizerImpl * Clone() const
void VisitState(ImageStateImpl< T, D > &s) const
#define DLLEXPORT_OST_IMG_BASE
ImageStateConstModIPAlgorithm< NormalizeFnc > NormalizerBase