Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
data/saturate.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_DATA_SATURATE_HH
27 # define MLN_DATA_SATURATE_HH
28 
32 
33 # include <mln/fun/v2v/saturate.hh>
34 # include <mln/data/apply.hh>
35 # include <mln/data/transform.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace data
42  {
43 
44 
54  template <typename V, typename I>
55  mln_ch_value(I, V)
56  saturate(V v, const Image<I>& input);
57 
58 
65  template <typename I, typename V>
66  mln_ch_value(I, V)
67  saturate(const Image<I>& input,
68  const V& min, const V& max);
69 
70 
77  template <typename I>
78  void saturate_inplace(Image<I>& input,
79  const mln_value(I)& min, const mln_value(I)& max);
80 
81 
82 # ifndef MLN_INCLUDE_ONLY
83 
84  template <typename V, typename I>
85  inline
86  mln_ch_value(I, V)
87  saturate(V, const Image<I>& input)
88  {
89  trace::entering("data::saturate");
90 
91  mln_precondition(exact(input).is_valid());
92 
93  fun::v2v::saturate<V> f;
94  mln_ch_value(I, V) output = data::transform(input, f);
95 
96  trace::exiting("data::saturate");
97  return output;
98  }
99 
100  template <typename I, typename V>
101  inline
102  mln_ch_value(I, V)
103  saturate(const Image<I>& input,
104  const V& min, const V& max)
105  {
106  trace::entering("data::saturate");
107 
108  mln_precondition(exact(input).is_valid());
109 
110  fun::v2v::saturate<V> f(min, max);
111  mln_ch_value(I, V) output = data::transform(input, f);
112 
113  trace::exiting("data::saturate");
114  return output;
115  }
116 
117  template <typename I>
118  inline
120  const mln_value(I)& min, const mln_value(I)& max)
121  {
122  trace::entering("data::saturate_inplace");
123 
124  mln_precondition(exact(input).is_valid());
125 
126  fun::v2v::saturate<mln_value(I)> f(min, max);
127  data::apply(input, f);
128 
129  trace::exiting("data::saturate_inplace");
130  }
131 
132 # endif // ! MLN_INCLUDE_ONLY
133 
134  } // end of namespace mln::data
135 
136 } // end of namespace mln
137 
138 
139 #endif // ! MLN_DATA_SATURATE_HH