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>
63 bool predicate(
const Image<I>& lhs,
const Image<J>& rhs,
const Function_vv2b<F>& f);
71 template <
typename S,
typename F>
72 bool predicate(
const Site_Set<S>& pset,
const Function_v2b<F>& f);
75 # ifndef MLN_INCLUDE_ONLY
83 template <
typename I,
typename F>
85 void predicate_tests(
const Image<I>& ima,
86 const Function_v2b<F>& f)
88 mln_precondition(exact(ima).is_valid());
93 template <
typename I,
typename J,
typename F>
95 void predicate_tests(
const Image<I>& lhs_,
97 const Function_vv2b<F>& f)
99 const I& lhs = exact(lhs_);
100 const J& rhs = exact(rhs_);
102 mln_precondition(lhs.is_valid());
103 mln_precondition(rhs.is_valid());
104 mln_precondition(lhs.domain() == rhs.domain());
110 template <
typename S,
typename F>
112 void predicate_tests(
const Site_Set<S>& pset,
113 const Function_v2b<F>& f)
115 mln_precondition(exact(pset).is_valid());
128 template <
typename I,
typename F>
130 bool predicate_(trait::image::speed::any,
const I& ima,
const F& f)
132 internal::predicate_tests(ima, f);
134 mln_piter(I) p(ima.domain());
141 template <typename I, typename F>
143 bool predicate_(trait::image::speed::fastest, const I& ima, const F& f)
145 internal::predicate_tests(ima, f);
147 mln_pixter(
const I) pxl(ima);
154 template <typename I, typename J, typename F>
156 bool predicate_(trait::image::speed::any,
157 trait::image::speed::any,
158 const I& lhs, const J& rhs, const F& f)
160 internal::predicate_tests(lhs, rhs, f);
162 mln_piter(I) p(lhs.domain());
164 if (! f(lhs(p), rhs(p)))
169 template <typename I, typename J, typename F>
171 bool predicate_(trait::image::speed::fastest,
172 trait::image::speed::fastest,
173 const I& lhs, const J& rhs, const F& f)
175 internal::predicate_tests(lhs, rhs, f);
177 mln_pixter(
const I) pxl1(lhs);
178 mln_pixter(const J) pxl2(rhs);
179 for_all_2(pxl1, pxl2)
180 if (! f(pxl1.val(), pxl2.val()))
185 template <typename S, typename F>
187 bool predicate_(const Site_Set<S>& pset, const F& f)
189 internal::predicate_tests(pset, f);
191 mln_piter(S) p(exact(pset));
205 template <typename I, typename F>
209 trace::entering(
"test::predicate");
211 internal::predicate_tests(ima, f);
212 bool res = impl::predicate_(mln_trait_image_speed(I)(), exact(ima),
215 trace::exiting(
"test::predicate");
220 template <
typename I,
typename J,
typename F>
224 trace::entering(
"test::predicate");
226 const I& lhs = exact(lhs_);
227 const J& rhs = exact(rhs_);
229 internal::predicate_tests(lhs_, rhs_, f);
231 bool res = impl::predicate_(mln_trait_image_speed(I)(),
232 mln_trait_image_speed(J)(),
236 trace::exiting(
"test::predicate");
240 template <
typename S,
typename F>
244 trace::entering(
"test::predicate");
246 internal::predicate_tests(pset, f);
248 bool res = impl::predicate_(exact(pset), exact(f));
250 trace::exiting(
"test::predicate");
254 # endif // ! MLN_INCLUDE_ONLY
261 #endif // ! MLN_TEST_PREDICATE_HH