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

compute_with_weights.hh

00001 // Copyright (C) 2008, 2009, 2010 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_SET_COMPUTE_WITH_WEIGHTS_HH
00028 # define MLN_SET_COMPUTE_WITH_WEIGHTS_HH
00029 
00035 
00036 # include <mln/core/concept/meta_accumulator.hh>
00037 # include <mln/core/concept/image.hh>
00038 # include <mln/core/concept/site_set.hh>
00039 # include <mln/util/array.hh>
00040 # include <mln/convert/from_to.hh>
00041 # include <mln/value/next.hh>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   namespace set
00048   {
00049 
00055     //
00056     template <typename A, typename I>
00057     mln_result(A)
00058     compute_with_weights(const Accumulator<A>& a, const Image<I>& w);
00059 
00060 
00069     //
00070     template <typename A, typename I, typename L>
00071     util::array<mln_result(A)>
00072     compute_with_weights(const Accumulator<A>& a,
00073                          const Image<I>& w,
00074                          const Image<L>& label,
00075                          const mln_value(L)& nlabels);
00076 
00077 
00083     //
00084     template <typename A, typename I>
00085     mln_meta_accu_result(A, mln_site(I))
00086     compute_with_weights(const Meta_Accumulator<A>& a, const Image<I>& w);
00087 
00088 
00089 
00090 # ifndef MLN_INCLUDE_ONLY
00091 
00092 
00093     // Tests.
00094 
00095 
00096     namespace internal
00097     {
00098 
00099       template <typename A, typename I, typename L>
00100       void
00101       compute_with_weights_tests(const Accumulator<A>& a_,
00102                                  const Image<I>& w_,
00103                                  const Image<L>& label_)
00104       {
00105         const A& a = exact(a_);
00106         const I& w = exact(w_);
00107         const L& label = exact(label_);
00108 
00109         mln_precondition(w.is_valid());
00110         mln_precondition(label.is_valid());
00111         mln_precondition(w.domain() <= label.domain());
00112 
00113         (void) a;
00114         (void) w;
00115         (void) label;
00116       }
00117 
00118     } // end of namespace mln::internal
00119 
00120 
00121 
00122     // Implementations.
00123 
00124 
00125     namespace impl
00126     {
00127 
00128       namespace generic
00129       {
00130 
00138         //
00139         template <typename A, typename I>
00140         inline
00141         mln_result(A)
00142         compute_with_weights(const Accumulator<A>& a_, const Image<I>& w_)
00143         {
00144           trace::entering("set::impl::generic::compute_with_weights");
00145 
00146           mlc_converts_to(mln_site(I), mln_argument(A))::check();
00147           mlc_converts_to(mln_value(I), unsigned)::check();
00148 
00149           A a = exact(a_);
00150           const I& w = exact(w_);
00151 
00152           a.init();
00153           mln_piter(I) p(w.domain());
00154           for_all(p)
00155             a.take_n_times(w(p), p);
00156 
00157           trace::exiting("set::impl::generic::compute_with_weights");
00158           return a.to_result();
00159         }
00160 
00161 
00162 
00172         //
00173         template <typename A, typename I, typename L>
00174         util::array<mln_result(A)>
00175         compute_with_weights(const Accumulator<A>& a_,
00176                              const Image<I>& w_,
00177                              const Image<L>& label_,
00178                              const mln_value(L)& nlabels)
00179         {
00180           trace::entering("set::impl::generic::compute_with_weights");
00181 
00182           mlc_equal(mln_site(I), mln_site(L))::check();
00183           mlc_converts_to(mln_site(I), mln_argument(A))::check();
00184           mlc_converts_to(mln_value(I), unsigned)::check();
00185 
00186           A a = exact(a_);
00187           const I& w = exact(w_);
00188           const L& label = exact(label_);
00189 
00190           internal::compute_with_weights_tests(a, w, label);
00191 
00192           util::array<A> accus(value::next(nlabels), a);
00193 
00194           mln_piter(I) p(w.domain());
00195           for_all(p)
00196             accus[label(p)].take_n_times(w(p), p);
00197 
00198           util::array<mln_result(A)> r;
00199           convert::from_to(accus, r);
00200 
00201           trace::exiting("set::impl::generic::compute_with_weights");
00202           return r;
00203         }
00204 
00205       } // end of namespace mln::set::impl::generic
00206 
00207     } // end of namespace mln::set::impl
00208 
00209 
00210 
00211     // Facades.
00212 
00213 
00214     template <typename A, typename I>
00215     inline
00216     mln_result(A)
00217     compute_with_weights(const Accumulator<A>& a, const Image<I>& w)
00218     {
00219       trace::entering("set::compute_with_weights");
00220 
00221       mlc_converts_to(mln_site(I), mln_argument(A))::check();
00222       mlc_converts_to(mln_value(I), unsigned)::check();
00223       mln_precondition(exact(w).is_valid());
00224 
00225       mln_result(A) r = impl::generic::compute_with_weights(a, w);
00226 
00227       trace::exiting("set::compute_with_weights");
00228       return r;
00229     }
00230 
00231 
00232     template <typename A, typename I, typename L>
00233     util::array<mln_result(A)>
00234     compute_with_weights(const Accumulator<A>& a,
00235                          const Image<I>& w,
00236                          const Image<L>& label,
00237                          const mln_value(L)& nlabels)
00238     {
00239       trace::entering("set::compute_with_weights");
00240 
00241       mlc_equal(mln_site(I), mln_site(L))::check();
00242       mlc_converts_to(mln_site(I), mln_argument(A))::check();
00243       mlc_converts_to(mln_value(I), unsigned)::check();
00244 
00245       internal::compute_with_weights_tests(a, w, label);
00246 
00247       util::array<mln_result(A)> r;
00248       r = impl::generic::compute_with_weights(a, w, label, nlabels);
00249 
00250       trace::exiting("set::compute_with_weights");
00251       return r;
00252     }
00253 
00254 
00255     template <typename A, typename I>
00256     inline
00257     mln_meta_accu_result(A, mln_site(I))
00258     compute_with_weights(const Meta_Accumulator<A>& a, const Image<I>& w)
00259     {
00260       trace::entering("set::compute_with_weights");
00261 
00262       mlc_converts_to(mln_value(I), unsigned)::check();
00263 
00264       mln_precondition(exact(w).is_valid());
00265 
00266       typedef mln_site(I) P;
00267       typedef mln_accu_with(A, P) A_;
00268       A_ a_ = accu::unmeta(exact(a), P());
00269 
00270       mln_result(A_) r = impl::generic::compute_with_weights(a_, w);
00271 
00272       trace::exiting("set::compute_with_weights");
00273       return r;
00274     }
00275 
00276 # endif // ! MLN_INCLUDE_ONLY
00277 
00278   } // end of namespace mln::set
00279 
00280 } // end of namespace mln
00281 
00282 
00283 #endif // ! MLN_SET_COMPUTE_WITH_WEIGHTS_HH

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