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

compute.hh

00001 // Copyright (C) 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_LABELING_COMPUTE_HH
00027 # define MLN_LABELING_COMPUTE_HH
00028 
00046 
00047 # include <mln/core/concept/image.hh>
00048 # include <mln/core/concept/accumulator.hh>
00049 # include <mln/core/concept/meta_accumulator.hh>
00050 # include <mln/util/array.hh>
00051 # include <mln/convert/from_to.hh>
00052 
00053 
00054 namespace mln
00055 {
00056 
00057   namespace labeling
00058   {
00059 
00068     //
00069     template <typename A, typename I, typename L>
00070     util::array<mln_result(A)>
00071     compute(util::array<A>& a,
00072             const Image<I>& input,
00073             const Image<L>& label,
00074             const mln_value(L)& nlabels);
00075 
00076 
00085     //
00086     template <typename A, typename I, typename L>
00087     util::array<mln_result(A)>
00088     compute(const Accumulator<A>& a,
00089             const Image<I>& input,
00090             const Image<L>& label,
00091             const mln_value(L)& nlabels);
00092 
00093 
00102     //
00103     template <typename A, typename I, typename L>
00104     util::array<mln_meta_accu_result(A, mln_value(I))>
00105     compute(const Meta_Accumulator<A>& a,
00106             const Image<I>& input,
00107             const Image<L>& label,
00108             const mln_value(L)& nlabels);
00109 
00110 
00118     //
00119     template <typename A, typename L>
00120     util::array<mln_result(A)>
00121     compute(const Accumulator<A>& a,
00122             const Image<L>& label,
00123             const mln_value(L)& nlabels);
00124 
00125 
00133     //
00134     template <typename A, typename L>
00135     util::array<mln_meta_accu_result(A, mln_psite(L))>
00136     compute(const Meta_Accumulator<A>& a,
00137             const Image<L>& label,
00138             const mln_value(L)& nlabels);
00139 
00140 
00141 
00142 # ifndef MLN_INCLUDE_ONLY
00143 
00144     namespace internal
00145     {
00146 
00147       template <typename A, typename L>
00148       inline
00149       void
00150       compute_tests(const Accumulator<A>& a,
00151                     const Image<L>& label,
00152                     const mln_value(L)& nlabels)
00153       {
00154         mln_precondition(exact(label).is_valid());
00155         // mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
00156         (void) a;
00157         (void) label;
00158         (void) nlabels;
00159       }
00160 
00161 
00162       template <typename A, typename I, typename L>
00163       inline
00164       void
00165       compute_tests(const Accumulator<A>& a,
00166                     const Image<I>& input,
00167                     const Image<L>& label,
00168                     const mln_value(L)& nlabels)
00169       {
00170         mln_precondition(exact(input).is_valid());
00171         mln_precondition(exact(label).is_valid());
00172         // mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
00173         (void) a;
00174         (void) input;
00175         (void) label;
00176         (void) nlabels;
00177       }
00178 
00179     } // end of namespace mln::labeling::internal
00180 
00181 
00182 
00183     namespace impl
00184     {
00185 
00186       namespace generic
00187       {
00188 
00189 
00197         //
00198         template <typename A, typename L>
00199         inline
00200         util::array<mln_result(A)>
00201         compute(const Accumulator<A>& a_,
00202                 const Image<L>& label_,
00203                 const mln_value(L)& nlabels)
00204         {
00205           trace::entering("labeling::impl::generic::compute");
00206           internal::compute_tests(a_, label_, nlabels);
00207 
00208           const A& a = exact(a_);
00209           const L& label = exact(label_);
00210 
00211           util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
00212 
00213           mln_piter(L) p(label.domain());
00214           for_all(p)
00215             accus[label(p)].take(p);
00216 
00217           util::array<mln_result(A)> res;
00218           convert::from_to(accus, res);
00219 
00220           trace::exiting("labeling::impl::generic::compute");
00221           return res;
00222         }
00223 
00224 
00233         //
00234         template <typename A, typename I, typename L>
00235         inline
00236         util::array<mln_result(A)>
00237         compute(const Accumulator<A>& a_,
00238                 const Image<I>& input_,
00239                 const Image<L>& label_,
00240                 const mln_value(L)& nlabels)
00241         {
00242           trace::entering("labeling::impl::generic::compute");
00243           internal::compute_tests(a_, input_, label_, nlabels);
00244 
00245           const A& a = exact(a_);
00246           const I& input = exact(input_);
00247           const L& label = exact(label_);
00248 
00249           util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
00250 
00251           mln_piter(I) p(input.domain());
00252           for_all(p)
00253             accus[label(p)].take(input(p));
00254 
00255           util::array<mln_result(A)> res;
00256           convert::from_to(accus, res);
00257 
00258           trace::exiting("labeling::impl::generic::compute");
00259           return res;
00260         }
00261 
00262 
00271         //
00272         template <typename A, typename I, typename L>
00273         inline
00274         util::array<mln_result(A)>
00275         compute(util::array<A>& accus,
00276                 const Image<I>& input_,
00277                 const Image<L>& label_,
00278                 const mln_value(L)& nlabels)
00279         {
00280           trace::entering("labeling::impl::generic::compute");
00281           //internal::compute_tests(a_, input_, label_, nlabels);
00282 
00283           //const A& a = exact(a_);
00284           const I& input = exact(input_);
00285           const L& label = exact(label_);
00286           (void) nlabels;
00287 
00288           // FIXME: Check accus size with nlabels.
00289           //util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
00290 
00291           mln_piter(I) p(input.domain());
00292           for_all(p)
00293             accus[label(p)].take(input(p));
00294 
00295           util::array<mln_result(A)> res;
00296           convert::from_to(accus, res);
00297 
00298           trace::exiting("labeling::impl::generic::compute");
00299           return res;
00300         }
00301 
00302       } // end of namespace mln::labeling::impl::generic
00303 
00304     } // end of namespace mln::labeling::impl
00305 
00306 
00307 
00308     namespace internal
00309     {
00310 
00311 
00312       template <typename A, typename L>
00313       inline
00314       util::array<mln_result(A)>
00315       compute_dispatch(const Accumulator<A>& a,
00316                        const Image<L>& label,
00317                        const mln_value(L)& nlabels)
00318       {
00319         return impl::generic::compute(a, label, nlabels);
00320       }
00321 
00322 
00323       template <typename A, typename I, typename L>
00324       inline
00325       util::array<mln_result(A)>
00326       compute_dispatch(const Accumulator<A>& a,
00327                        const Image<I>& input,
00328                        const Image<L>& label,
00329                        const mln_value(L)& nlabels)
00330       {
00331         return impl::generic::compute(a, input, label, nlabels);
00332       }
00333 
00334 
00335       template <typename A, typename I, typename L>
00336       inline
00337       util::array<mln_result(A)>
00338       compute_dispatch(util::array<A>& a,
00339                        const Image<I>& input,
00340                        const Image<L>& label,
00341                        const mln_value(L)& nlabels)
00342       {
00343         return impl::generic::compute(a, input, label, nlabels);
00344       }
00345 
00346 
00347     } // end of namespace mln::labeling::internal
00348 
00349 
00350 
00351     // Facades.
00352 
00353     template <typename A, typename I, typename L>
00354     inline
00355     util::array<mln_result(A)>
00356     compute(util::array<A>& a,
00357             const Image<I>& input,
00358             const Image<L>& label,
00359             const mln_value(L)& nlabels)
00360     {
00361       trace::entering("labeling::compute");
00362 
00363       //internal::compute_tests(a, input, label, nlabels);
00364 
00365       typedef util::array<mln_result(A)> R;
00366       R res = internal::compute_dispatch(a, input, label, nlabels);
00367 
00368       trace::exiting("labeling::compute");
00369       return res;
00370     }
00371 
00372     template <typename A, typename I, typename L>
00373     inline
00374     util::array<mln_result(A)>
00375     compute(const Accumulator<A>& a,
00376             const Image<I>& input,
00377             const Image<L>& label,
00378             const mln_value(L)& nlabels)
00379     {
00380       trace::entering("labeling::compute");
00381 
00382       internal::compute_tests(a, input, label, nlabels);
00383 
00384       typedef util::array<mln_result(A)> R;
00385       R res = internal::compute_dispatch(a, input, label, nlabels);
00386 
00387       trace::exiting("labeling::compute");
00388       return res;
00389     }
00390 
00391     template <typename A, typename I, typename L>
00392     inline
00393     util::array<mln_meta_accu_result(A, mln_value(I))>
00394     compute(const Meta_Accumulator<A>& a,
00395             const Image<I>& input,
00396             const Image<L>& label,
00397             const mln_value(L)& nlabels)
00398     {
00399       typedef mln_accu_with(A, mln_value(I)) A_;
00400       A_ a_ = accu::unmeta(exact(a), mln_value(I)());
00401 
00402       return compute(a_, input, label, nlabels);
00403     }
00404 
00405 
00406     template <typename A, typename L>
00407     inline
00408     util::array<mln_result(A)>
00409     compute(const Accumulator<A>& a,
00410             const Image<L>& label,
00411             const mln_value(L)& nlabels)
00412     {
00413       trace::entering("labeling::compute");
00414 
00415       internal::compute_tests(a, label, nlabels);
00416 
00417       typedef util::array<mln_result(A)> R;
00418       R res = internal::compute_dispatch(a, label, nlabels);
00419 
00420       mln_postcondition(res.nelements() == static_cast<unsigned>(nlabels) + 1);
00421 
00422       trace::exiting("labeling::compute");
00423       return res;
00424     }
00425 
00426 
00427     template <typename A, typename L>
00428     inline
00429     util::array<mln_meta_accu_result(A, mln_psite(L))>
00430     compute(const Meta_Accumulator<A>& a,
00431             const Image<L>& label,
00432             const mln_value(L)& nlabels)
00433     {
00434       typedef mln_accu_with(A, mln_psite(L)) A_;
00435       A_ a_ = accu::unmeta(exact(a), mln_psite(L)());
00436 
00437       return compute(a_, label, nlabels);
00438     }
00439 
00440 
00441 # endif // ! MLN_INCLUDE_ONLY
00442 
00443   } // end of namespace mln::labeling
00444 
00445 } // end of namespace mln
00446 
00447 
00448 #endif // ! MLN_LABELING_COMPUTE_HH

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