Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
complementation.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_COMPLEMENTATION_HH
27 # define MLN_MORPHO_COMPLEMENTATION_HH
28 
36 # include <mln/data/compare.hh>
37 # include <mln/logical/not.hh>
38 # include <mln/arith/revert.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace morpho
45  {
46 
51  template <typename I>
52  mln_concrete(I) complementation(const Image<I>& input);
53 
54 
59  template <typename I>
60  void complementation_inplace(Image<I>& input);
61 
62 
63 # ifndef MLN_INCLUDE_ONLY
64 
65  namespace impl
66  {
67 
68  // Binary => morphology on sets.
69 
70  template <typename I>
71  inline
72  mln_concrete(I)
73  complementation_(trait::image::kind::logic,
74  const Image<I>& input)
75  {
76  return logical::not_(input);
77  }
78 
79  template <typename I>
80  inline
81  void
82  complementation_inplace_(trait::image::kind::logic,
83  Image<I>& input)
84  {
85  logical::not_inplace(input);
86  }
87 
88 
89  // Otherwise => morphology on functions.
90 
91  template <typename I>
92  inline
93  mln_concrete(I)
94  complementation_(trait::image::kind::any,
95  const Image<I>& input)
96  {
97  return arith::revert(input);
98  }
99 
100  template <typename I>
101  inline
102  void
103  complementation_inplace_(trait::image::kind::any,
104  Image<I>& input)
105  {
106  arith::revert_inplace(input);
107  }
108 
109  } // end of namespace mln::morpho::impl
110 
111 
112  // Facades.
113 
114  template <typename I>
115  inline
116  mln_concrete(I) complementation(const Image<I>& input)
117  {
118  trace::entering("morpho::complementation");
119  mln_precondition(exact(input).is_valid());
120 
121  mln_concrete(I) output = impl::complementation_(mln_trait_image_kind(I)(),
122  input);
123 
124  trace::exiting("morpho::complementation");
125  return output;
126  }
127 
128  template <typename I>
129  inline
131  {
132  trace::entering("morpho::complementation_inplace");
133  mln_precondition(exact(input).is_valid());
134 
135  impl::complementation_inplace_(mln_trait_image_kind(I)(),
136  input);
137 
138  trace::exiting("morpho::complementation_inplace");
139  }
140 
141 # endif // ! MLN_INCLUDE_ONLY
142 
143  } // end of namespace mln::morpho
144 
145 } // end of namespace mln
146 
147 
148 #endif // ! MLN_MORPHO_COMPLEMENTATION_HH