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>
72 bool check(
const I& ima,
const mln_psite(I)& p)
const;
75 bool check__(
const I& ima,
unsigned p)
const;
77 template <
typename I,
typename N2>
78 unsigned nb_connectivity2d(
const I&,
const N2& nbh,
79 const mln_psite(I)& p,
bool object)
const;
80 template <
typename I,
typename N2>
81 unsigned nb_connectivity2d__(
const I&,
const N2& nbh,
82 unsigned p,
bool object)
const;
90 # ifndef MLN_INCLUDE_ONLY
95 static const unsigned char connectivity_number_c8[256] =
97 0, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1,
98 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
99 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
100 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1,
102 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
103 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
104 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
105 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
107 1, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2,
108 1, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
109 2, 3, 3, 3, 3, 4, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2,
110 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1,
112 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
113 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
114 1, 2, 2, 2, 2, 3, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1,
115 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
119 static const unsigned char connectivity_number_c4[256] =
121 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
122 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
123 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
124 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
126 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2,
127 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 3, 3, 3, 3, 2,
128 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2, 1,
129 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 1,
131 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
132 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
133 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1,
134 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
136 1, 1, 2, 2, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2, 3, 2,
137 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 2, 2, 2, 2, 1,
138 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 2, 1,
139 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1
144 template <
typename N>
145 is_simple_2d_t<N>::is_simple_2d_t(
const Neighborhood<N>& nbh)
148 mln_precondition(nbh_.is_valid());
153 template <
typename N>
154 template <
typename I,
typename N2>
156 is_simple_2d_t<N>::nb_connectivity2d(
const I& ima,
const N2& nbh,
157 const mln_psite(I)& p,
bool b)
const
159 mln_precondition(ima.is_valid());
160 mln_precondition(nbh.is_valid());
165 mln_fwd_niter(N2) n(
c8(), p);
169 if (ima.has(n) && ima(n) == b)
176 return internal::connectivity_number_c4[res];
178 return internal::connectivity_number_c8[res];
188 template <
typename N>
189 template <
typename I,
typename N2>
191 is_simple_2d_t<N>::nb_connectivity2d__(
const I& ima,
const N2& nbh,
192 unsigned p,
bool b)
const
194 mln_precondition(ima.is_valid());
195 mln_precondition(nbh.is_valid());
199 static util::array<int>
200 noffset = mln::offsets_wrt(ima,
c8());
202 for (
unsigned i = 0; i < noffset.nelements(); ++i)
205 if (ima.element(p + noffset[i]) == b)
212 return internal::connectivity_number_c4[res];
214 return internal::connectivity_number_c8[res];
224 template <
typename N>
225 template <
typename I>
228 is_simple_2d_t<N>::check(
const I& ima,
const mln_psite(I)& p)
const
230 mln_precondition(ima.is_valid());
231 return (nb_connectivity2d(ima, nbh_.foreground(), p,
true) == 1)
232 && (nb_connectivity2d(ima, nbh_.background(), p,
false) == 1);
238 template <
typename N>
239 template <
typename I>
242 is_simple_2d_t<N>::check__(
const I& ima,
unsigned p)
const
244 mln_precondition(ima.is_valid());
245 return (nb_connectivity2d__(ima, nbh_.foreground(), p,
true) == 1)
246 && (nb_connectivity2d__(ima, nbh_.background(), p,
false) == 1);
251 # endif // MLN_INCLUDE_ONLY
257 #endif // ! MLN_TOPO_IS_SIMPLE_2D_HH