Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
revert.hh
1 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_ARITH_REVERT_HH
28 # define MLN_ARITH_REVERT_HH
29 
35 
36 # include <mln/core/concept/image.hh>
37 # include <mln/trait/value_.hh>
38 
39 // Specializations are in:
40 # include <mln/arith/revert.spe.hh>
41 
42 
43 // FIXME: Rely instead on mln/fun/v2v/revert.hh.
44 // FIXME: Revert on int value 0 does not give 0 (since min != - max;
45 // idem for float etc.)
46 
47 
48 namespace mln
49 {
50 
51  namespace arith
52  {
53 
55 
65  template <typename I>
66  mln_concrete(I) revert(const Image<I>& input);
67 
68 
70 
79  template <typename I>
80  void revert_inplace(Image<I>& input);
81 
82 
83 # ifndef MLN_INCLUDE_ONLY
84 
85  namespace impl
86  {
87 
88  namespace generic
89  {
90 
91  template <typename I, typename O>
92  inline
93  void revert(const Image<I>& input_, Image<O>& output_)
94  {
95  trace::entering("arith::impl::generic::revert_");
96 
97  const I& input = exact(input_);
98  O& output = exact(output_);
99 
100  mln_precondition(input.is_valid());
101  mln_precondition(output.is_valid());
102  mln_precondition(input.domain() == output.domain());
103 
104  typedef mln_value(I) V;
105  mln_piter(I) p(input.domain());
106  for_all(p)
107  output(p) = mln_min(V) + (mln_max(V) - input(p));
108 
109  trace::exiting("arith::impl::generic::revert_");
110  }
111 
112  } // end of namespace mln::arith::impl::generic
113 
114  } // end of namespace mln::arith::impl
115 
116 
117 
118  // Dispatch.
119 
120  namespace internal
121  {
122 
123  template <typename I, typename O>
124  inline
125  void
126  revert_dispatch(trait::image::speed::any, const I& input, O& output)
127  {
128  impl::generic::revert(input, output);
129  }
130 
131  template <typename I, typename O>
132  inline
133  void
134  revert_dispatch(trait::image::speed::fastest, const I& input, O& output)
135  {
136  impl::revert_fastest(input, output);
137  }
138 
139  template <typename I, typename O>
140  inline
141  void
142  revert_dispatch(const Image<I>& input, Image<O>& output)
143  {
144  revert_dispatch(mln_trait_image_speed(I)(),
145  exact(input), exact(output));
146 
147  }
148 
149 
150  } // end of namespace mln::arith::internal
151 
152 
153 
154  // Facades.
155 
156  template <typename I>
157  inline
158  mln_concrete(I) revert(const Image<I>& input)
159  {
160  trace::entering("arith::revert");
161 
162  mln_precondition(exact(input).is_valid());
163 
164  mln_concrete(I) output;
165  initialize(output, input);
166  internal::revert_dispatch(exact(input), exact(output));
167 
168  trace::exiting("arith::revert");
169  return output;
170  }
171 
172  template <typename I>
173  inline
175  {
176  trace::entering("arith::revert_inplace");
177 
178  mln_precondition(exact(input).is_valid());
179 
180  internal::revert_dispatch(exact(input), exact(input));
181 
182  trace::exiting("arith::revert_inplace");
183  }
184 
185 # endif // ! MLN_INCLUDE_ONLY
186 
187  } // end of namespace mln::arith
188 
189 } // end of namespace mln
190 
191 
192 #endif // ! MLN_ARITH_REVERT_HH