$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends 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  mln_trace("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  }
110 
111  } // end of namespace mln::arith::impl::generic
112 
113  } // end of namespace mln::arith::impl
114 
115 
116 
117  // Dispatch.
118 
119  namespace internal
120  {
121 
122  template <typename I, typename O>
123  inline
124  void
125  revert_dispatch(trait::image::speed::any, const I& input, O& output)
126  {
127  impl::generic::revert(input, output);
128  }
129 
130  template <typename I, typename O>
131  inline
132  void
133  revert_dispatch(trait::image::speed::fastest, const I& input, O& output)
134  {
135  impl::revert_fastest(input, output);
136  }
137 
138  template <typename I, typename O>
139  inline
140  void
141  revert_dispatch(const Image<I>& input, Image<O>& output)
142  {
143  revert_dispatch(mln_trait_image_speed(I)(),
144  exact(input), exact(output));
145 
146  }
147 
148 
149  } // end of namespace mln::arith::internal
150 
151 
152 
153  // Facades.
154 
155  template <typename I>
156  inline
157  mln_concrete(I) revert(const Image<I>& input)
158  {
159  mln_trace("arith::revert");
160 
161  mln_precondition(exact(input).is_valid());
162 
163  mln_concrete(I) output;
164  initialize(output, input);
165  internal::revert_dispatch(exact(input), exact(output));
166 
167  return output;
168  }
169 
170  template <typename I>
171  inline
172  void revert_inplace(Image<I>& input)
173  {
174  mln_trace("arith::revert_inplace");
175 
176  mln_precondition(exact(input).is_valid());
177 
178  internal::revert_dispatch(exact(input), exact(input));
179 
180  }
181 
182 # endif // ! MLN_INCLUDE_ONLY
183 
184  } // end of namespace mln::arith
185 
186 } // end of namespace mln
187 
188 
189 #endif // ! MLN_ARITH_REVERT_HH