00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_TEST_PREDICATE_HH
00028 # define MLN_TEST_PREDICATE_HH
00029
00033
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/function.hh>
00036 # include <mln/core/concept/site_set.hh>
00037
00038
00039 namespace mln
00040 {
00041
00042 namespace test
00043 {
00044
00050
00051 template <typename I, typename F>
00052 bool predicate(const Image<I>& ima, const Function_v2b<F>& f);
00053
00054
00061
00062 template <typename I, typename J, typename F>
00063 bool predicate(const Image<I>& lhs, const Image<J>& rhs, const Function_vv2b<F>& f);
00064
00065
00070
00071 template <typename S, typename F>
00072 bool predicate(const Site_Set<S>& pset, const Function_v2b<F>& f);
00073
00074
00075 # ifndef MLN_INCLUDE_ONLY
00076
00077
00078
00079
00080 namespace internal
00081 {
00082
00083 template <typename I, typename F>
00084 inline
00085 void predicate_tests(const Image<I>& ima,
00086 const Function_v2b<F>& f)
00087 {
00088 mln_precondition(exact(ima).is_valid());
00089 (void) ima;
00090 (void) f;
00091 }
00092
00093 template <typename I, typename J, typename F>
00094 inline
00095 void predicate_tests(const Image<I>& lhs_,
00096 const Image<J>& rhs_,
00097 const Function_vv2b<F>& f)
00098 {
00099 const I& lhs = exact(lhs_);
00100 const J& rhs = exact(rhs_);
00101
00102 mln_precondition(lhs.is_valid());
00103 mln_precondition(rhs.is_valid());
00104 mln_precondition(lhs.domain() == rhs.domain());
00105 (void) lhs;
00106 (void) rhs;
00107 (void) f;
00108 }
00109
00110 template <typename S, typename F>
00111 inline
00112 void predicate_tests(const Site_Set<S>& pset,
00113 const Function_v2b<F>& f)
00114 {
00115 mln_precondition(exact(pset).is_valid());
00116 (void) pset;
00117 (void) f;
00118 }
00119
00120 }
00121
00122
00123
00124
00125 namespace impl
00126 {
00127
00128 template <typename I, typename F>
00129 inline
00130 bool predicate_(trait::image::speed::any, const I& ima, const F& f)
00131 {
00132 internal::predicate_tests(ima, f);
00133
00134 mln_piter(I) p(ima.domain());
00135 for_all(p)
00136 if (! f(ima(p)))
00137 return false;
00138 return true;
00139 }
00140
00141 template <typename I, typename F>
00142 inline
00143 bool predicate_(trait::image::speed::fastest, const I& ima, const F& f)
00144 {
00145 internal::predicate_tests(ima, f);
00146
00147 mln_pixter(const I) pxl(ima);
00148 for_all(pxl)
00149 if (! f(pxl.val()))
00150 return false;
00151 return true;
00152 }
00153
00154 template <typename I, typename J, typename F>
00155 inline
00156 bool predicate_(trait::image::speed::any,
00157 trait::image::speed::any,
00158 const I& lhs, const J& rhs, const F& f)
00159 {
00160 internal::predicate_tests(lhs, rhs, f);
00161
00162 mln_piter(I) p(lhs.domain());
00163 for_all(p)
00164 if (! f(lhs(p), rhs(p)))
00165 return false;
00166 return true;
00167 }
00168
00169 template <typename I, typename J, typename F>
00170 inline
00171 bool predicate_(trait::image::speed::fastest,
00172 trait::image::speed::fastest,
00173 const I& lhs, const J& rhs, const F& f)
00174 {
00175 internal::predicate_tests(lhs, rhs, f);
00176
00177 mln_pixter(const I) pxl1(lhs);
00178 mln_pixter(const J) pxl2(rhs);
00179 for_all_2(pxl1, pxl2)
00180 if (! f(pxl1.val(), pxl2.val()))
00181 return false;
00182 return true;
00183 }
00184
00185 template <typename S, typename F>
00186 inline
00187 bool predicate_(const Site_Set<S>& pset, const F& f)
00188 {
00189 internal::predicate_tests(pset, f);
00190
00191 mln_piter(S) p(exact(pset));
00192 for_all(p)
00193 if (! f(p))
00194 return false;
00195 return true;
00196 }
00197
00198 }
00199
00200
00201
00202
00203
00204
00205 template <typename I, typename F>
00206 inline
00207 bool predicate(const Image<I>& ima, const Function_v2b<F>& f)
00208 {
00209 trace::entering("test::predicate");
00210
00211 internal::predicate_tests(ima, f);
00212 bool res = impl::predicate_(mln_trait_image_speed(I)(), exact(ima),
00213 exact(f));
00214
00215 trace::exiting("test::predicate");
00216 return res;
00217 }
00218
00219
00220 template <typename I, typename J, typename F>
00221 inline
00222 bool predicate(const Image<I>& lhs_, const Image<J>& rhs_, const Function_vv2b<F>& f)
00223 {
00224 trace::entering("test::predicate");
00225
00226 const I& lhs = exact(lhs_);
00227 const J& rhs = exact(rhs_);
00228
00229 internal::predicate_tests(lhs_, rhs_, f);
00230
00231 bool res = impl::predicate_(mln_trait_image_speed(I)(),
00232 mln_trait_image_speed(J)(),
00233 lhs, rhs,
00234 exact(f));
00235
00236 trace::exiting("test::predicate");
00237 return res;
00238 }
00239
00240 template <typename S, typename F>
00241 inline
00242 bool predicate(const Site_Set<S>& pset, const Function_v2b<F>& f)
00243 {
00244 trace::entering("test::predicate");
00245
00246 internal::predicate_tests(pset, f);
00247
00248 bool res = impl::predicate_(exact(pset), exact(f));
00249
00250 trace::exiting("test::predicate");
00251 return res;
00252 }
00253
00254 # endif // ! MLN_INCLUDE_ONLY
00255
00256 }
00257
00258 }
00259
00260
00261 #endif // ! MLN_TEST_PREDICATE_HH