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