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

predicate.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_TEST_PREDICATE_HH
00027 # define MLN_TEST_PREDICATE_HH
00028 
00032 
00033 # include <mln/core/concept/image.hh>
00034 # include <mln/core/concept/function.hh>
00035 # include <mln/core/concept/site_set.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace test
00042   {
00043 
00049     //
00050     template <typename I, typename F>
00051     bool predicate(const Image<I>& ima, const Function_v2b<F>& f);
00052 
00053 
00060     //
00061     template <typename I, typename J, typename F>
00062     bool predicate(const Image<I>& lhs, const Image<J>& rhs, const Function_vv2b<F>& f);
00063 
00064 
00069     //
00070     template <typename S, typename F>
00071     bool predicate(const Site_Set<S>& pset, const Function_v2b<F>& f);
00072 
00073 
00074 # ifndef MLN_INCLUDE_ONLY
00075 
00076 
00077     // Tests.
00078 
00079     namespace internal
00080     {
00081 
00082       template <typename I, typename F>
00083       inline
00084       void predicate_tests(const Image<I>& ima,
00085                            const Function_v2b<F>& f)
00086       {
00087         mln_precondition(exact(ima).is_valid());
00088         (void) ima;
00089         (void) f;
00090       }
00091 
00092       template <typename I, typename J, typename F>
00093       inline
00094       void predicate_tests(const Image<I>& lhs_,
00095                            const Image<J>& rhs_,
00096                            const Function_vv2b<F>& f)
00097       {
00098         const I& lhs = exact(lhs_);
00099         const J& rhs = exact(rhs_);
00100 
00101         mln_precondition(lhs.is_valid());
00102         mln_precondition(rhs.is_valid());
00103         mln_precondition(lhs.domain() == rhs.domain());
00104         (void) lhs;
00105         (void) rhs;
00106         (void) f;
00107       }
00108 
00109       template <typename S, typename F>
00110       inline
00111       void predicate_tests(const Site_Set<S>& pset,
00112                            const Function_v2b<F>& f)
00113       {
00114         mln_precondition(exact(pset).is_valid());
00115         (void) pset;
00116         (void) f;
00117       }
00118 
00119     } // end of namespace mln::test::internal
00120 
00121 
00122     // Implementations.
00123 
00124     namespace impl
00125     {
00126 
00127       template <typename I, typename F>
00128       inline
00129       bool predicate_(trait::image::speed::any, const I& ima, const F& f)
00130       {
00131         internal::predicate_tests(ima, f);
00132 
00133         mln_piter(I) p(ima.domain());
00134         for_all(p)
00135           if (! f(ima(p)))
00136             return false;
00137         return true;
00138       }
00139 
00140       template <typename I, typename F>
00141       inline
00142       bool predicate_(trait::image::speed::fastest, const I& ima, const F& f)
00143       {
00144         internal::predicate_tests(ima, f);
00145 
00146         mln_pixter(const I) pxl(ima);
00147         for_all(pxl)
00148           if (! f(pxl.val()))
00149             return false;
00150         return true;
00151       }
00152 
00153       template <typename I, typename J, typename F>
00154       inline
00155       bool predicate_(trait::image::speed::any,
00156                       trait::image::speed::any,
00157                       const I& lhs, const J& rhs, const F& f)
00158       {
00159         internal::predicate_tests(lhs, rhs, f);
00160 
00161         mln_piter(I) p(lhs.domain());
00162         for_all(p)
00163           if (! f(lhs(p), rhs(p)))
00164             return false;
00165         return true;
00166       }
00167 
00168       template <typename I, typename J, typename F>
00169       inline
00170       bool predicate_(trait::image::speed::fastest,
00171                       trait::image::speed::fastest,
00172                       const I& lhs, const J& rhs, const F& f)
00173       {
00174         internal::predicate_tests(lhs, rhs, f);
00175 
00176         mln_pixter(const I) pxl1(lhs);
00177         mln_pixter(const J) pxl2(rhs);
00178         for_all_2(pxl1, pxl2)
00179           if (! f(pxl1.val(), pxl2.val()))
00180             return false;
00181         return true;
00182       }
00183 
00184       template <typename S, typename F>
00185       inline
00186       bool predicate_(const Site_Set<S>& pset, const F& f)
00187       {
00188         internal::predicate_tests(pset, f);
00189 
00190         mln_piter(S) p(exact(pset));
00191         for_all(p)
00192           if (! f(p))
00193             return false;
00194         return true;
00195       }
00196 
00197     } // end of namespace mln::test::impl
00198 
00199 
00200 
00201     // Facades.
00202 
00203 
00204     template <typename I, typename F>
00205     inline
00206     bool predicate(const Image<I>& ima, const Function_v2b<F>& f)
00207     {
00208       trace::entering("test::predicate");
00209 
00210       internal::predicate_tests(ima, f);
00211       bool res = impl::predicate_(mln_trait_image_speed(I)(), exact(ima),
00212                                   exact(f));
00213 
00214       trace::exiting("test::predicate");
00215       return res;
00216     }
00217 
00218 
00219     template <typename I, typename J, typename F>
00220     inline
00221     bool predicate(const Image<I>& lhs_, const Image<J>& rhs_, const Function_vv2b<F>& f)
00222     {
00223       trace::entering("test::predicate");
00224 
00225       const I& lhs = exact(lhs_);
00226       const J& rhs = exact(rhs_);
00227 
00228       internal::predicate_tests(lhs_, rhs_, f);
00229 
00230       bool res = impl::predicate_(mln_trait_image_speed(I)(),
00231                                   mln_trait_image_speed(J)(),
00232                                   lhs, rhs,
00233                                   exact(f));
00234 
00235       trace::exiting("test::predicate");
00236       return res;
00237     }
00238 
00239     template <typename S, typename F>
00240     inline
00241     bool predicate(const Site_Set<S>& pset, const Function_v2b<F>& f)
00242     {
00243       trace::entering("test::predicate");
00244 
00245       internal::predicate_tests(pset, f);
00246 
00247       bool res = impl::predicate_(exact(pset), exact(f));
00248 
00249       trace::exiting("test::predicate");
00250       return res;
00251     }
00252 
00253 # endif // ! MLN_INCLUDE_ONLY
00254 
00255   } // end of namespace mln::test
00256 
00257 } // end of namespace mln
00258 
00259 
00260 #endif // ! MLN_TEST_PREDICATE_HH

Generated on Thu Sep 8 2011 18:32:21 for Milena (Olena) by  doxygen 1.7.1