27 #ifndef MLN_TEST_PREDICATE_HH
28 # define MLN_TEST_PREDICATE_HH
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/function.hh>
36 # include <mln/core/concept/site_set.hh>
51 template <
typename I,
typename F>
52 bool predicate(
const Image<I>& ima,
const Function_v2b<F>& f);
62 template <
typename I,
typename J,
typename F>
64 const Function_vv2b<F>& f);
72 template <
typename S,
typename F>
73 bool predicate(
const Site_Set<S>& pset,
const Function_v2b<F>& f);
76 # ifndef MLN_INCLUDE_ONLY
84 template <
typename I,
typename F>
86 void predicate_tests(
const Image<I>& ima,
87 const Function_v2b<F>& f)
89 mln_precondition(
exact(ima).is_valid());
94 template <
typename I,
typename J,
typename F>
96 void predicate_tests(
const Image<I>& lhs_,
98 const Function_vv2b<F>& f)
100 const I& lhs =
exact(lhs_);
103 mln_precondition(lhs.is_valid());
104 mln_precondition(rhs.is_valid());
105 mln_precondition(lhs.domain() == rhs.domain());
111 template <
typename S,
typename F>
113 void predicate_tests(
const Site_Set<S>& pset,
114 const Function_v2b<F>& f)
116 mln_precondition(
exact(pset).is_valid());
129 template <
typename I,
typename F>
131 bool predicate_(trait::image::speed::any,
const I& ima,
const F& f)
133 internal::predicate_tests(ima, f);
135 mln_piter(I)
p(ima.domain());
142 template <typename I, typename F>
144 bool predicate_(trait::image::speed::fastest, const I& ima, const F& f)
146 internal::predicate_tests(ima, f);
148 mln_pixter(
const I) pxl(ima);
155 template <typename I, typename J, typename F>
157 bool predicate_(trait::image::speed::any,
158 trait::image::speed::any,
159 const I& lhs, const J& rhs, const F& f)
161 internal::predicate_tests(lhs, rhs, f);
163 mln_piter(I)
p(lhs.domain());
165 if (! f(lhs(
p), rhs(p)))
170 template <typename I, typename J, typename F>
172 bool predicate_(trait::image::speed::fastest,
173 trait::image::speed::fastest,
174 const I& lhs, const J& rhs, const F& f)
176 internal::predicate_tests(lhs, rhs, f);
178 mln_pixter(
const I) pxl1(lhs);
179 mln_pixter(const J) pxl2(rhs);
180 for_all_2(pxl1, pxl2)
181 if (! f(pxl1.val(), pxl2.val()))
186 template <typename S, typename F>
188 bool predicate_(const Site_Set<S>& pset, const F& f)
190 internal::predicate_tests(pset, f);
192 mln_piter(S) p(
exact(pset));
206 template <typename I, typename F>
208 bool predicate(const Image<I>& ima, const Function_v2b<F>& f)
210 mln_trace(
"test::predicate");
212 internal::predicate_tests(ima, f);
213 bool res = impl::predicate_(mln_trait_image_speed(I)(),
exact(ima),
220 template <
typename I,
typename J,
typename F>
222 bool predicate(
const Image<I>& lhs_,
const Image<J>& rhs_,
223 const Function_vv2b<F>& f)
225 mln_trace(
"test::predicate");
227 const I& lhs =
exact(lhs_);
228 const J& rhs =
exact(rhs_);
230 internal::predicate_tests(lhs_, rhs_, f);
232 bool res = impl::predicate_(mln_trait_image_speed(I)(),
233 mln_trait_image_speed(J)(),
240 template <
typename S,
typename F>
242 bool predicate(
const Site_Set<S>& pset,
const Function_v2b<F>& f)
244 mln_trace(
"test::predicate");
246 internal::predicate_tests(pset, f);
248 bool res = impl::predicate_(
exact(pset),
exact(f));
253 # endif // ! MLN_INCLUDE_ONLY
260 #endif // ! MLN_TEST_PREDICATE_HH