$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
general.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_MORPHO_GENERAL_HH
27 # define MLN_MORPHO_GENERAL_HH
28 
35 
36 # include <mln/core/concept/image.hh>
37 # include <mln/core/concept/window.hh>
38 # include <mln/core/concept/neighborhood.hh>
39 
40 # include <mln/extension/adjust_fill.hh>
41 # include <mln/accu/transform.hh>
42 
43 // Specializations are in:
44 # include <mln/morpho/general.spe.hh>
45 
46 
47 # define mln_morpho_select_accu(I, S, F) \
48 typename mln::metal::if_< mln::metal::is< mln_trait_image_kind(I), \
49  trait::image::kind::binary >, \
50  mln::accu::meta::S, \
51  mln::accu::meta::F >::ret
52 
53 
54 namespace mln
55 {
56 
57  namespace morpho
58  {
59 
61  template <typename Op, typename I, typename W>
62  mln_concrete(I)
63  general(const Op& op, const Image<I>& input, const Window<W>& win);
64 
65 
66 # ifndef MLN_INCLUDE_ONLY
67 
68 
69  namespace internal
70  {
71 
72  template <typename Op, typename I, typename W>
73  inline
74  void
75  general_tests(const Op& op, const Image<I>& input_, const Window<W>& win_)
76  {
77  const I& input = exact(input_);
78  const W& win = exact(win_);
79 
80  mln_precondition(input.is_valid());
81  mln_precondition(! win.is_empty());
82  mln_precondition(win.is_valid());
83 
84  (void) op;
85  (void) input;
86  (void) win;
87  }
88 
89 
90  // Temporary code; see 'todo' above.
91  template <typename I, bool is_binary> // true
92  struct neutral_impl
93  {
94  static mln_value(I) infimum() { return false; }
95  static mln_value(I) supremum() { return true; }
96  };
97  template <typename I>
98  struct neutral_impl< I, false >
99  {
100  static mln_value(I) infimum() { return mln_min(mln_value(I)); }
101  static mln_value(I) supremum() { return mln_max(mln_value(I)); }
102  };
103  template <typename I>
104  struct neutral : neutral_impl< I, mlc_is(mln_trait_image_kind(I),
105  trait::image::kind::binary)::value >
106  {
107  };
108 
109  } // end of mln::morpho::internal
110 
111 
112  namespace impl
113  {
114 
115  namespace generic
116  {
117 
118 
119  // On function.
120 
121  template <typename Op, typename I, typename W>
122  inline
123  mln_concrete(I)
124  general_on_function(const Op& op, const Image<I>& input, const Window<W>& win)
125  {
126  mln_trace("morpho::impl::generic::general_on_function");
127 
128  internal::general_tests(op, input, win);
129 
130  extension::adjust_fill(input, win, op.neutral(input));
131  mln_concrete(I) output;
132  output = accu::transform(input, op.accu(input), win);
133 
134  return output;
135  }
136 
137  // On set.
138 
139  template <typename Op, typename I, typename W>
140  inline
141  mln_concrete(I)
142  general_on_set(const Op& op, const Image<I>& input, const Window<W>& win)
143  {
144  mln_trace("morpho::impl::generic::general_on_set");
145 
146  internal::general_tests(op, input, win);
147 
148  extension::adjust_fill(input, win, op.neutral(input));
149  mln_concrete(I) output;
150  output = accu::transform_stop(input, op.accu(input), win);
151 
152  return output;
153  }
154 
155  } // end of namespace mln::morpho::impl::generic
156 
157  } // end of namespace mln::morpho::impl
158 
159 
160 
161  // Facades.
162 
163  template <typename Op, typename I, typename W>
164  inline
165  mln_concrete(I)
166  general(const Op& op, const Image<I>& input, const Window<W>& win)
167  {
168  mln_trace("morpho::general");
169  mln_precondition(exact(input).is_valid());
170  mln_precondition(! exact(win).is_empty());
171 
172  internal::general_tests(op, input, win);
173  mln_concrete(I) output = internal::general_dispatch(op, input, win);
174 
175  return output;
176  }
177 
178 # endif // ! MLN_INCLUDE_ONLY
179 
180  } // end of namespace mln::morpho
181 
182 } // end of namespace mln
183 
184 
185 #endif // ! MLN_MORPHO_GENERAL_HH