OpenStructure
transcendentals.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  "overloaded" transcendentals for images; instead of providing the
23  typical func(image) interface, which would limit the use to out-of-place
24  application, a full fletched img::alg interface is given for each:
25 
26  cos, exp, log, log10, pow, sin, sqrt, tan
27 
28  Author: Ansgar Philippsen
29 */
30 
31 #ifndef IMG_ALG_TRANS_HH
32 #define IMG_ALG_TRANS_HH
33 
34 #include <ost/img/image.hh>
35 #include <ost/img/image_state.hh>
37 
38 
39 #define IMG_ALG_TRANSCENDENTALS_BLOCK(FF,NN,SS) \
40 struct FF { \
41  FF() {} \
42  ~FF() {} \
43  template <typename T, class D> \
44  void VisitState(ImageStateImpl<T,D>& isi) const { \
45  const T* end = isi.Data().GetEnd(); \
46  for(T* it = isi.Data().GetData(); it!=end; ++it) { \
47  (*it) = SS (*it); \
48  } \
49  } \
50  template <class D> \
51  void VisitState(ImageStateImpl<Word,D>& isi) const { \
52  const Word* end = isi.Data().GetEnd(); \
53  for(Word* it = isi.Data().GetData(); it!=end; ++it) { \
54  (*it) = static_cast<Word>(SS(static_cast<Real>(*it))); \
55  } \
56  } \
57  static String GetAlgorithmName() {return "";} \
58 }; \
59 typedef ImageStateConstModIPAlgorithm<FF> NN;
60 
61 namespace ost { namespace img { namespace alg {
62 
70 
71 
72 struct PowFnc {
73  PowFnc():exp_(1.0) {}
74  PowFnc(Real exp): exp_(exp) {}
75 
76  template <typename T, class D>
77  void VisitState(ImageStateImpl<T,D>& isi) const {
78  const T* end = isi.Data().GetEnd();
79  for(T* it = isi.Data().GetData(); it!=end; ++it) {
80  (*it) = std::pow(*it,exp_);
81  }
82  }
83  static String GetAlgorithmName() {return "";}
84  private:
85  Real exp_;
86 };
87 
89 
90 
91 }}} // ns
92 
93 #undef IMG_ALG_TRANSCENDENTALS_BLOCK
94 
95 
96 #endif
in-place modifying image state const visitor plus ip algorithm
ValueHolder< T > & Data()
direct access to value holder
VPtr GetData()
return pointer to raw data
float Real
Definition: base.hh:44
std::string String
Definition: base.hh:54
ImageStateConstModIPAlgorithm< PowFnc > Pow
pointer_it< T > end(const std::vector< T > &values)
Definition: base.dox:1
static String GetAlgorithmName()
void VisitState(ImageStateImpl< T, D > &isi) const
#define IMG_ALG_TRANSCENDENTALS_BLOCK(FF, NN, SS)