27 #ifndef MLN_TOPO_IS_SIMPLE_2D_HH
28 # define MLN_TOPO_IS_SIMPLE_2D_HH
40 #include <mln/core/concept/image.hh>
41 #include <mln/core/concept/neighborhood.hh>
43 #include <mln/core/alias/point2d.hh>
44 #include <mln/core/alias/neighb2d.hh>
63 template<
typename I,
typename N>
67 const mln_psite(I)&
p,
bool b);
82 template<
typename I,
typename N>
84 is_simple_2d(
const Image<I>& ima,
const Neighborhood<N>& nbh,
85 const mln_psite(I)&
p);
95 bool check(
const I& ima,
const mln_psite(I)&
p)
const;
98 bool check__(
const I& ima,
unsigned p)
const;
100 template <
typename I,
typename N2>
102 const mln_psite(I)& p,
bool object)
const;
103 template <
typename I,
typename N2>
105 unsigned p,
bool object)
const;
113 # ifndef MLN_INCLUDE_ONLY
121 static const unsigned char connectivity_number_c8[256] =
123 0, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1,
124 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
125 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
126 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1,
128 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
129 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
130 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
131 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
133 1, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2,
134 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
135 2, 3, 3, 3, 3, 4, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2,
136 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1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 template<
typename I,
typename N>
176 const mln_psite(I)&
p,
bool b)
178 const I& ima =
exact(ima_);
179 const N& nbh =
exact(nbh_);
183 mln_fwd_niter(neighb2d) n(
c8(), p);
190 if (ima.has(n) && ima(n) == b)
197 number = internal::connectivity_number_c4[res];
198 else if (nbh ==
c8())
199 number = internal::connectivity_number_c8[res];
206 template<
typename I,
typename N>
209 is_simple_2d(
const Image<I>& ima,
const Neighborhood<N>& nbh_,
210 const mln_psite(I)& p)
212 const N& nbh =
exact(nbh_);
220 template <
typename N>
224 mln_precondition(nbh_.is_valid());
229 template <
typename N>
230 template <
typename I,
typename N2>
233 const mln_psite(I)& p,
bool b)
const
235 mln_precondition(ima.is_valid());
236 mln_precondition(nbh.is_valid());
241 mln_fwd_niter(N2) n(c8(), p);
248 if (ima.has(n) && ima(n) == b)
255 number = internal::connectivity_number_c4[res];
256 else if (nbh ==
c8())
257 number = internal::connectivity_number_c8[res];
265 template <
typename N>
266 template <
typename I,
typename N2>
269 unsigned p,
bool b)
const
271 mln_precondition(ima.is_valid());
272 mln_precondition(nbh.is_valid());
277 static util::array<int>
278 noffset = mln::offsets_wrt(ima,
c8());
284 for (
unsigned i = 0; i < noffset.nelements(); ++i)
286 if (ima.element(p + noffset[i]) == b)
293 number = internal::connectivity_number_c4[res];
294 else if (nbh ==
c8())
295 number = internal::connectivity_number_c8[res];
303 template <
typename N>
304 template <
typename I>
309 mln_precondition(ima.is_valid());
310 return (nb_connectivity2d(ima, nbh_.foreground(),
p,
true) == 1)
311 && (nb_connectivity2d(ima, nbh_.background(),
p,
false) == 1);
317 template <
typename N>
318 template <
typename I>
323 mln_precondition(ima.is_valid());
324 return (nb_connectivity2d__(ima, nbh_.foreground(),
p,
true) == 1)
325 && (nb_connectivity2d__(ima, nbh_.background(),
p,
false) == 1);
330 # endif // MLN_INCLUDE_ONLY
336 #endif // ! MLN_TOPO_IS_SIMPLE_2D_HH