$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
detach_pair.hh
1 // Copyright (C) 2011 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_TOPO_DETACH_PAIR_HH
27 # define MLN_TOPO_DETACH_PAIR_HH
28 
32 
33 # include <mln/core/concept/function.hh>
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 
37 # include <mln/topo/is_simple_pair.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace topo
44  {
45 
55  template <typename I, typename NL, typename NH>
57  {
58  public:
61 
70  detach_pair(const Neighborhood<NL>& lower_adj_nbh,
71  const Neighborhood<NH>& higher_adj_nbh);
72 
87  const Neighborhood<NL>& lower_adj_nbh,
88  const Neighborhood<NH>& higher_adj_nbh);
90 
91  /* FIXME: Rename as init() or something like this? See how other
92  functors are written. */
94  void set_image(mln::Image<I>& ima);
95 
100  void operator()(const mln_psite(I)& f, const mln_psite(I)& g);
101 
105  void operator()(const mln_psite(I)& f);
106 
107  private:
108  I* ima_;
109  const NL& lower_adj_nbh_;
110  const NH& higher_adj_nbh_;
112  is_simple_pair<I, NL, NH> is_simple_;
113  };
114 
115 
116 
117 # ifndef MLN_INCLUDE_ONLY
118 
119  template <typename I, typename NL, typename NH>
120  inline
122  const Neighborhood<NH>& higher_adj_nbh)
123  : ima_(0),
124  lower_adj_nbh_(exact(lower_adj_nbh)),
125  higher_adj_nbh_(exact(higher_adj_nbh)),
126  is_simple_(lower_adj_nbh, higher_adj_nbh)
127  {
128  mlc_equal(mln_value(I), bool)::check();
129  }
130 
131  template <typename I, typename NL, typename NH>
132  inline
134  const Neighborhood<NL>& lower_adj_nbh,
135  const Neighborhood<NH>& higher_adj_nbh)
136  : ima_(exact(&ima)),
137  lower_adj_nbh_(exact(lower_adj_nbh)),
138  higher_adj_nbh_(exact(higher_adj_nbh)),
139  is_simple_(ima, lower_adj_nbh, higher_adj_nbh)
140  {
141  mlc_equal(mln_value(I), bool)::check();
142  }
143 
144  template <typename I, typename NL, typename NH>
145  inline
146  void
148  {
149  ima_ = exact(&ima);
150  is_simple_.set_image(ima);
151  }
152 
153  template <typename I, typename NL, typename NH>
154  inline
155  void
156  detach_pair<I, NL, NH>::operator()(const mln_psite(I)& f,
157  const mln_psite(I)& g)
158  {
159  mln_precondition(ima_);
160  mln_precondition(is_simple_(f, g));
161 
162  // Shortcut.
163  // FIXME: Introduce an `ima()' accessor instead?
164  I& ima = *ima_;
165 
166  ima(f) = false;
167  ima(g) = false;
168  }
169 
170  // FIXME: What about moving this operator() into its own functor?
171  template <typename I, typename NL, typename NH>
172  inline
173  void
174  detach_pair<I, NL, NH>::operator()(const mln_psite(I)& f)
175  {
176  mln_niter(NL) g(lower_adj_nbh_, f);
177  for_all(g)
178  {
179  if (is_simple_(f, g))
180  // Delegate the detach operation to the binary operator().
181  return (*this)(f, g);
182  }
183  }
184 
185 # endif // MLN_INCLUDE_ONLY
186 
187  } // end of namespace mln::topo
188 
189 } // end of namespace mln
190 
191 #endif // ! MLN_TOPO_DETACH_PAIR_HH