• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

predicate.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
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     // Tests.
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     } // end of namespace mln::test::internal
00121 
00122 
00123     // Implementations.
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     } // end of namespace mln::test::impl
00199 
00200 
00201 
00202     // Facades.
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   } // end of namespace mln::test
00257 
00258 } // end of namespace mln
00259 
00260 
00261 #endif // ! MLN_TEST_PREDICATE_HH

Generated on Tue Oct 4 2011 15:24:20 for Milena (Olena) by  doxygen 1.7.1