$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
is_simple_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_IS_SIMPLE_PAIR_HH
27 # define MLN_TOPO_IS_SIMPLE_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_facet.hh>
38 
39 
40 namespace mln
41 {
42 
43  namespace topo
44  {
45 
59  template <typename I, typename NL, typename NH>
61  : public mln::Function_v2b< is_simple_pair<I, NL, NH> >
62  {
63  public:
65  typedef bool result;
66 
69 
78  is_simple_pair(const Neighborhood<NL>& lower_adj_nbh,
79  const Neighborhood<NH>& higher_adj_nbh);
80 
93  is_simple_pair(const mln::Image<I>& ima,
94  const Neighborhood<NL>& lower_adj_nbh,
95  const Neighborhood<NH>& higher_adj_nbh);
97 
98  /* FIXME: Rename as init() or something like this? See how other
99  functors are written. */
101  void set_image(const mln::Image<I>& ima);
102 
108  bool operator()(const mln_psite(I)& f, const mln_psite(I)& g) const;
109 
113  bool operator()(const mln_psite(I)& f) const;
114 
115  private:
116  const I* ima_;
117  const NL& lower_adj_nbh_;
118  const NH& higher_adj_nbh_;
119  };
120 
121 
122 
123 # ifndef MLN_INCLUDE_ONLY
124 
125  template <typename I, typename NL, typename NH>
126  inline
128  const Neighborhood<NH>& higher_adj_nbh)
129  : ima_(0),
130  lower_adj_nbh_(exact(lower_adj_nbh)),
131  higher_adj_nbh_(exact(higher_adj_nbh))
132  {
133  mlc_equal(mln_value(I), bool)::check();
134  }
135 
136  template <typename I, typename NL, typename NH>
137  inline
139  const Neighborhood<NL>& lower_adj_nbh,
140  const Neighborhood<NH>& higher_adj_nbh)
141  : ima_(exact(&ima)),
142  lower_adj_nbh_(exact(lower_adj_nbh)),
143  higher_adj_nbh_(exact(higher_adj_nbh))
144  {
145  mlc_equal(mln_value(I), bool)::check();
146  }
147 
148  template <typename I, typename NL, typename NH>
149  inline
150  void
152  {
153  ima_ = exact(&ima);
154  }
155 
156  template <typename I, typename NL, typename NH>
157  inline
158  bool
159  is_simple_pair<I, NL, NH>::operator()(const mln_psite(I)& f,
160  const mln_psite(I)& g) const
161  {
162  mln_precondition(ima_);
163  // Shortcut.
164  // FIXME: Introduce an `ima()' accessor instead?
165  const I& ima = *ima_;
166 
167  // (F, G) cannot be a simple pair unless they are part of
168  // objects in IMA.
169  if (!ima(f) || !ima(g))
170  return false;
171 
172  // F cannot be part of a simple pair unless it is a facet.
173  if (!is_facet(ima, f, higher_adj_nbh_))
174  return false;
175 
176  /* FIXME: It would be nice if we could skip this check when G is
177  passed by the unary operator(), since this one already
178  ensuress that F and G are adjacent. */
179  // Ensure the (n-1)-face G is adjacent to the n-face F.
180  {
181  bool f_g_adjacent = false;
182  mln_niter(NH) h(higher_adj_nbh_, g);
183  for_all(h)
184  if (h == f)
185  {
186  f_g_adjacent = true;
187  break;
188  }
189  if (!f_g_adjacent)
190  return false;
191  }
192 
193  // Check whether G is stricly included in F.
194  mln_niter(NH) h(higher_adj_nbh_, g);
195  for_all(h)
196  if (h != f && ima.has(h) && ima(h))
197  return false;
198  return true;
199  }
200 
201  // FIXME: What about moving this operator() into its own functor
202  // called e.g. mln::topo::is_in_simple_pair?
203  template <typename I, typename NL, typename NH>
204  inline
205  bool
206  is_simple_pair<I, NL, NH>::operator()(const mln_psite(I)& f) const
207  {
208  mln_niter(NL) g(lower_adj_nbh_, f);
209  for_all(g)
210  {
211  // Delegate the computation to the binary operator().
212  if ((*this)(f, g))
213  // (F, G) is a simple pair.
214  return true;
215  }
216  return false;
217  }
218 
219 # endif // MLN_INCLUDE_ONLY
220 
221  } // end of namespace mln::topo
222 
223 } // end of namespace mln
224 
225 #endif // ! MLN_TOPO_IS_SIMPLE_PAIR_HH