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

compute_attribute_image.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_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH
00027 # define MLN_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH
00028 
00034 
00035 # include <mln/core/routine/duplicate.hh>
00036 # include <mln/core/concept/image.hh>
00037 # include <mln/morpho/tree/data.hh>
00038 # include <mln/trait/accumulators.hh>
00039 # include <mln/util/pix.hh>
00040 # include <mln/data/fill.hh>
00041 
00042 
00043 namespace mln
00044 {
00045 
00046   namespace morpho
00047   {
00048 
00049     namespace tree
00050     {
00051 
00079       template <typename A, typename T>
00080       mln_ch_value(typename T::function, mln_result(A))
00081       compute_attribute_image(const Accumulator<A>& a,
00082                               const T& t,
00083                               mln_ch_value(typename T::function, A)* accu_image = 0);
00084 
00085 
00086 
00097       template <typename A, typename T, typename V>
00098       mln_ch_value(typename T::function, mln_result(A))
00099       compute_attribute_image_from(const Accumulator<A>& a,
00100                                    const T& t,
00101                                    const Image<V>& values,
00102                                    mln_ch_value(typename T::function, A)* accu_image = 0);
00103 
00104 
00105 
00106 # ifndef MLN_INCLUDE_ONLY
00107       // Take_as_init specialization
00108 
00109       namespace internal
00110       {
00111         template <typename A, typename I, typename P>
00112         void take_as_init (trait::accumulator::when_pix::use_none, A& accu,
00113                            const I& input, const P& p)
00114         {
00115           (void)input;
00116           (void)p;
00117           accu.take_as_init();
00118         }
00119 
00120         template <typename A, typename I, typename P>
00121         void take_as_init (trait::accumulator::when_pix::use_pix, A& accu,
00122                            const I& input, const P& p)
00123         {
00124           accu.take_as_init(make::pix(input, p));
00125         }
00126 
00127         template <typename A, typename I, typename P>
00128         void take_as_init (trait::accumulator::when_pix::use_v, A& accu,
00129                            const I& input, const P& p)
00130         {
00131           accu.take_as_init(input(p));
00132         }
00133 
00134         template <typename A, typename I, typename P>
00135         void take_as_init (trait::accumulator::when_pix::use_p, A& accu,
00136                            const I& input, const P& p)
00137         {
00138           (void) input;
00139           accu.take_as_init(p);
00140         }
00141 
00142 
00143         template <typename A, typename I, typename P>
00144         void take_as_init (A& accu, const I& input, const P& p)
00145         {
00146           take_as_init (mln_trait_accumulator_when_pix(A)(), accu, input, p);
00147         }
00148 
00149 
00150         template <typename A, typename T, typename V>
00151         inline
00152         mln_ch_value(typename T::function, mln_result(A))
00153           compute_attribute_image(const A& a,
00154                                   const T& t,
00155                                   const V& values,
00156                                   mln_ch_value(typename T::function, A)* accu_image = 0)
00157         {
00158 
00159           typedef typename T::function I;
00160           mln_ch_value(I, A) acc;
00161           initialize(acc, t.f());
00162 
00163           {
00164             // Transmit "dynamic data" (state) of 'a' to every values of
00165             // 'acc'.  It is usually a no-op (so useless) except for a
00166             // few accumulators, e.g., for accu::stat::rank which has the 'k'
00167             // attribute.
00168             mln::data::fill(acc, a);
00169           }
00170 
00171           {
00172             // Initialize every attribute with the corresponding pixel.
00173             mln_site_piter(T) p(t);
00174             for_all(p)
00175               take_as_init(acc(p), values, p);
00176           }
00177 
00178           {
00179             mln_up_site_piter(T) p(t);
00180             // Propagate attribute from a site to its parent.
00181             for_all(p)
00182               if (! t.is_root(p))
00183                 acc(t.parent(p)).take(acc(p));
00184 
00185             // Back-propagate attribute from a node to sites of its
00186             // component.  Below, p is a non-node component site and
00187             // parent(p) is a node, that is, the site representative of
00188             // the component p belongs to.
00189             for_all(p)
00190               if (! t.is_a_node(p))
00191                 {
00192                   mln_assertion(t.is_a_node(t.parent(p)));
00193                   acc(p) = acc(t.parent(p));
00194                 }
00195           }
00196 
00197 
00198           // Store accumulator image.
00199           if (accu_image)
00200             *accu_image = duplicate(acc);
00201 
00202           typedef typename T::function I;
00203           mln_ch_value(I, mln_result(A)) output;
00204           initialize(output, acc);
00205           mln::data::fill(output, acc);
00206 
00207           return output;
00208         }
00209       }
00210 
00211       // Facade.
00212 
00213       template <typename A, typename T>
00214       inline
00215       mln_ch_value(typename T::function, mln_result(A))
00216       compute_attribute_image(const Accumulator<A>& a_,
00217                               const T& t,
00218                               mln_ch_value(typename T::function, A)* accu_image = 0)
00219       {
00220         trace::entering("morpho::tree::compute_attribute_image");
00221 
00222         mln_ch_value(typename T::function, mln_result(A)) output;
00223         output = internal::compute_attribute_image(exact(a_), t, t.f(),
00224                                                    accu_image);
00225 
00226         trace::exiting("morpho::tree::compute_attribute_image");
00227         return (output);
00228       }
00229 
00230       template <typename A, typename T, typename V>
00231       inline
00232       mln_ch_value(typename T::function, mln_result(A))
00233       compute_attribute_image_from(const Accumulator<A>& a_,
00234                                    const T& t,
00235                                    const Image<V>& values,
00236                                    mln_ch_value(typename T::function, A)* accu_image = 0)
00237       {
00238         trace::entering("morpho::tree::compute_attribute_image_from");
00239 
00240 
00241         mln_ch_value(typename T::function, mln_result(A)) output;
00242         output = internal::compute_attribute_image(exact(a_), t, exact(values),
00243                                                    accu_image);
00244 
00245         trace::exiting("morpho::tree::compute_attribute_image_from");
00246         return output;
00247       }
00248 
00249 
00250 
00251 
00252 # endif // ! MLN_INCLUDE_ONLY
00253 
00254     }  // end of namespace mln::morpho::tree
00255 
00256   }  // end of namespace mln::morpho
00257 
00258 }  // end of namespace mln
00259 
00260 
00261 #endif // ! MLN_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH

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