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

influence_zone_geodesic.hh

00001 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
00002 // (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_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH
00028 # define MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH
00029 
00033 
00034 # include <mln/extension/adjust.hh>
00035 # include <mln/canvas/distance_geodesic.hh>
00036 # include <mln/transform/internal/influence_zone_functor.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   namespace transform
00043   {
00044 
00051     //
00052     template <typename I, typename N>
00053     mln_concrete(I)
00054     influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh);
00055 
00056 
00057 
00058 # ifndef MLN_INCLUDE_ONLY
00059 
00060 
00061     namespace internal
00062     {
00063 
00064       template <typename I, typename N>
00065       void
00066       influence_zone_geodesic_tests(const Image<I>& input,
00067                                     const Neighborhood<N>& nbh)
00068       {
00069         mln_precondition(exact(input).is_valid());
00070         mln_precondition(exact(nbh).is_valid());
00071 
00072         (void) input;
00073         (void) nbh;
00074       }
00075 
00076     } // end of namespace mln::transform::internal
00077 
00078 
00079     namespace impl
00080     {
00081 
00082       namespace generic
00083       {
00084 
00085         template <typename I, typename N>
00086         mln_concrete(I)
00087         influence_zone_geodesic(const Image<I>& input,
00088                                 const Neighborhood<N>& nbh)
00089         {
00090           // FIXME: To be written...
00091           mlc_abort(I)::check();
00092         }
00093 
00094       } // end of namespace mln::transform::impl::generic
00095 
00096 
00097       template <typename I, typename N>
00098       mln_concrete(I)
00099       influence_zone_geodesic_fastest(const Image<I>& input_,
00100                                       const Neighborhood<N>& nbh_)
00101       {
00102         trace::entering("transform::impl::influence_zone_geodesic_fastest");
00103 
00104         const I& input = exact(input_);
00105         const N& nbh = exact(nbh_);
00106 
00107         internal::influence_zone_geodesic_tests(input, nbh);
00108 
00109         std::queue<mln_value(I)*> q;
00110         mln_concrete(I) output;
00111 
00112         util::array<int> dp = offsets_wrt(input, nbh);
00113         const unsigned n_nbhs = dp.nelements();
00114 
00115         // Initialization.
00116         {
00117           extension::adjust(input, nbh);
00118           output = duplicate(input);
00119           // For the extension to be ignored:
00120           extension::fill(input, 0);  // in initialization
00121           extension::fill(output, 1); // in propagation
00122 
00123           const unsigned nelts = input.nelements();
00124           const mln_value(I)* p_i = input.buffer();
00125           mln_value(I)* p_o = output.buffer();
00126           for (unsigned i = 0; i < nelts; ++i, ++p_i, ++p_o)
00127           {
00128             if (*p_i == 0)
00129               continue;
00130             for (unsigned j = 0; j < n_nbhs; ++j)
00131             {
00132               const mln_value(I)* n_i = p_i + dp[j];
00133               if (*n_i == 0)
00134               {
00135                 q.push(p_o);
00136                 break;
00137               }
00138             }
00139           }
00140 
00141         }
00142 
00143         // Propagation.
00144         {
00145           mln_value(I)* ptr;
00146 
00147           while (! q.empty())
00148           {
00149             ptr = q.front();
00150             q.pop();
00151             mln_invariant(*ptr != 0);
00152             for (unsigned j = 0; j < n_nbhs; ++j)
00153             {
00154               mln_value(I)* ntr = ptr + dp[j];
00155               if (*ntr == 0)
00156               {
00157                 *ntr = *ptr;
00158                 q.push(ntr);
00159               }
00160             }
00161           }
00162         }
00163 
00164         trace::exiting("transform::impl::influence_zone_geodesic_fastest");
00165         return output;
00166       }
00167 
00168 
00169     } // end of namespace mln::transform::impl
00170 
00171 
00172     namespace internal
00173     {
00174 
00175       template <typename I, typename N>
00176       mln_concrete(I)
00177       influence_zone_geodesic_dispatch(trait::image::value_alignment::any,
00178                                        trait::image::value_storage::any,
00179                                        trait::image::value_access::any,
00180                                        const I& input,
00181                                        const N& nbh)
00182       {
00183         return impl::generic::influence_zone_geodesic(input, nbh);
00184       }
00185 
00186 
00187       template <typename I, typename N>
00188       mln_concrete(I)
00189       influence_zone_geodesic_dispatch(trait::image::value_alignment::with_grid,
00190                                        trait::image::value_storage::one_block,
00191                                        trait::image::value_access::direct,
00192                                        const I& input,
00193                                        const N& nbh)
00194       {
00195         return impl::influence_zone_geodesic_fastest(input, nbh);
00196       }
00197 
00198 
00199       template <typename I, typename N>
00200       mln_concrete(I)
00201       influence_zone_geodesic_dispatch(const Image<I>& input,
00202                                        const Neighborhood<N>& nbh)
00203       {
00204         return
00205           influence_zone_geodesic_dispatch(mln_trait_image_value_alignment(I)(),
00206                                            mln_trait_image_value_storage(I)(),
00207                                            mln_trait_image_value_access(I)(),
00208                                            exact(input), exact(nbh));
00209       }
00210 
00211     } // end of namespace mln::transform::internal
00212 
00213 
00214     template <typename I, typename N>
00215     mln_concrete(I)
00216     influence_zone_geodesic(const Image<I>& input, const Neighborhood<N>& nbh)
00217     {
00218       trace::entering("transform::influence_zone_geodesic");
00219 
00220       internal::influence_zone_geodesic_tests(input, nbh);
00221 
00222       mln_concrete(I)
00223         output = internal::influence_zone_geodesic_dispatch(input, nbh);
00224 
00225       trace::exiting("transform::influence_zone_geodesic");
00226       return output;
00227     }
00228 
00229 # endif // ! MLN_INCLUDE_ONLY
00230 
00231   } // end of namespace mln::transform
00232 
00233 } // end of namespace mln
00234 
00235 
00236 #endif // ! MLN_TRANSFORM_INFLUENCE_ZONE_GEODESIC_HH

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