Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator 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  trace::entering("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  trace::exiting("morpho::impl::generic::general_on_function");
135  return output;
136  }
137 
138  // On set.
139 
140  template <typename Op, typename I, typename W>
141  inline
142  mln_concrete(I)
143  general_on_set(const Op& op, const Image<I>& input, const Window<W>& win)
144  {
145  trace::entering("morpho::impl::generic::general_on_set");
146 
147  internal::general_tests(op, input, win);
148 
149  extension::adjust_fill(input, win, op.neutral(input));
150  mln_concrete(I) output;
151  output = accu::transform_stop(input, op.accu(input), win);
152 
153  trace::exiting("morpho::impl::generic::general_on_set");
154  return output;
155  }
156 
157  } // end of namespace mln::morpho::impl::generic
158 
159  } // end of namespace mln::morpho::impl
160 
161 
162 
163  // Facades.
164 
165  template <typename Op, typename I, typename W>
166  inline
167  mln_concrete(I)
168  general(const Op& op, const Image<I>& input, const Window<W>& win)
169  {
170  trace::entering("morpho::general");
171  mln_precondition(exact(input).is_valid());
172  mln_precondition(! exact(win).is_empty());
173 
174  internal::general_tests(op, input, win);
175  mln_concrete(I) output = internal::general_dispatch(op, input, win);
176 
177  trace::exiting("morpho::general");
178  return output;
179  }
180 
181 # endif // ! MLN_INCLUDE_ONLY
182 
183  } // end of namespace mln::morpho
184 
185 } // end of namespace mln
186 
187 
188 #endif // ! MLN_MORPHO_GENERAL_HH