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

transform_stop.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_ACCU_TRANSFORM_STOP_HH
00027 # define MLN_ACCU_TRANSFORM_STOP_HH
00028 
00033 
00034 # include <mln/core/concept/meta_accumulator.hh>
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/core/concept/window.hh>
00037 # include <mln/extension/adjust.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   namespace accu
00044   {
00045 
00046     template <typename I, typename A, typename W>
00047     mln_ch_value(I, mln_result(A))
00048     transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win);
00049 
00050     template <typename I, typename A, typename W>
00051     mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
00052     transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win);
00053 
00054 
00055 
00056 # ifndef MLN_INCLUDE_ONLY
00057 
00058 
00059     namespace impl
00060     {
00061 
00062       // Generic version.
00063 
00064       namespace generic
00065       {
00066 
00067         template <typename I, typename A, typename W>
00068         mln_ch_value(I, mln_result(A))
00069         transform_stop(const Image<I>& input_,
00070                        const Accumulator<A>& a_,
00071                        const Window<W>& win_)
00072         {
00073           trace::entering("accu::impl::generic::transform_stop");
00074 
00075           const I& input = exact(input_);
00076           const W& win   = exact(win_);
00077           A a = exact(a_);
00078 
00079           mln_precondition(input.is_valid());
00080           mln_precondition(win.is_valid());
00081 
00082           extension::adjust(input, win);
00083 
00084           mln_ch_value(I, mln_result(A)) output;
00085           initialize(output, input);
00086 
00087           mln_piter(I) p(input.domain());
00088           mln_qiter(W) q(win, p);
00089           for_all(p)
00090           {
00091             a.init();
00092             for_all(q) if (input.has(q))
00093             {
00094               a.take(input(q));
00095               if (a.can_stop())
00096                 break;
00097             }
00098             output(p) = a.to_result();
00099           }
00100 
00101           trace::exiting("accu::impl::generic::transform_stop");
00102           return output;
00103         }
00104 
00105       } // end of namespace mln::accu::impl::generic
00106 
00107 
00108       // Fastest version.
00109 
00110       template <typename I, typename A, typename W>
00111       mln_ch_value(I, mln_result(A))
00112       transform_stop_fastest(const Image<I>& input_, const Accumulator<A>& a_, const Window<W>& win_)
00113       {
00114         trace::entering("accu::impl::transform_stop_fastest");
00115 
00116         const I& input = exact(input_);
00117         const W& win   = exact(win_);
00118         A a = exact(a_);
00119 
00120         mln_precondition(input.is_valid());
00121         mln_precondition(win.is_valid());
00122 
00123         extension::adjust(input, win);
00124 
00125         typedef mln_ch_value(I, mln_result(A)) O;
00126         O output;
00127         initialize(output, input);
00128         mln_pixter(O) o(output);
00129 
00130         mln_pixter(const I)    p(input);
00131         mln_qixter(const I, W) q(p, win);
00132         for_all_2(p, o)
00133           {
00134             a.init();
00135             for_all(q)
00136             {
00137               a.take(q.val());
00138               if (a.can_stop())
00139                 break;
00140             }
00141             o.val() = a.to_result();
00142           }
00143 
00144         trace::exiting("accu::impl::transform_stop_fastest");
00145         return output;
00146       }
00147 
00148 
00149     } // end of namespace mln::accu::impl
00150 
00151 
00152     // Dispatch.
00153 
00154     namespace internal
00155     {
00156 
00157       template <typename I, typename A, typename W>
00158       mln_ch_value(I, mln_result(A))
00159       transform_stop_dispatch(metal::false_,
00160                               const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
00161       {
00162         return impl::generic::transform_stop(input, a, win);
00163       }
00164 
00165       template <typename I, typename A, typename W>
00166       mln_ch_value(I, mln_result(A))
00167       transform_stop_dispatch(metal::true_,
00168                               const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
00169       {
00170         return impl::transform_stop_fastest(input, a, win);
00171       }
00172 
00173       template <typename I, typename A, typename W>
00174       mln_ch_value(I, mln_result(A))
00175       transform_stop_dispatch(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
00176       {
00177         return transform_stop_dispatch(mln_is_fastest_IW(I, W)(),
00178                                        input, a, win);
00179       }
00180 
00181     } // end of namespace mln::accu::internal
00182 
00183 
00184     // Facades.
00185 
00186     template <typename I, typename A, typename W>
00187     inline
00188     mln_ch_value(I, mln_result(A))
00189     transform_stop(const Image<I>& input, const Accumulator<A>& a, const Window<W>& win)
00190     {
00191       trace::entering("accu::transform_stop");
00192 
00193       mln_precondition(exact(input).is_valid());
00194       mln_precondition(exact(win).is_valid());
00195 
00196       mln_ch_value(I, mln_result(A)) output;
00197       output = internal::transform_stop_dispatch(input, a, win);
00198 
00199       trace::exiting("accu::transform_stop");
00200       return output;
00201     }
00202 
00203     template <typename I, typename A, typename W>
00204     mln_ch_value(I, mln_meta_accu_result(A, mln_value(I)))
00205     transform_stop(const Image<I>& input, const Meta_Accumulator<A>& a, const Window<W>& win)
00206     {
00207       trace::entering("accu::transform_stop");
00208 
00209       mln_precondition(exact(input).is_valid());
00210       mln_precondition(exact(win).is_valid());
00211 
00212       typedef mln_accu_with(A, mln_value(I)) A_;
00213       A_ a_ = accu::unmeta(exact(a), mln_value(I)());
00214 
00215       mln_ch_value(I, mln_result(A_)) output;
00216       output = internal::transform_stop_dispatch(input, a_, win);
00217 
00218       trace::exiting("accu::transform_stop");
00219       return output;
00220     }
00221 
00222 # endif // ! MLN_INCLUDE_ONLY
00223 
00224   } // end of namespace mln::accu
00225 
00226 } // end of namespace mln
00227 
00228 
00229 #endif // ! MLN_ACCU_TRANSFORM_STOP_HH

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