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

from_image_to_site_set.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_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
00027 # define MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
00028 
00036 
00037 # include <utility>
00038 # include <mln/core/site_set/p_run.hh>
00039 # include <mln/core/site_set/p_array.hh>
00040 # include <mln/metal/converts_to.hh>
00041 
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   // Forward declarations.
00048   template <typename E> struct Site_Set;
00049   template <typename E> struct Image;
00050   template <typename E> struct Gpoint;
00051 
00052   namespace convert
00053   {
00054 
00055     namespace impl
00056     {
00057 
00059       template <typename I, typename S>
00060       void
00061       from_image_to_site_set(const Image<I>& from, Site_Set<S>& to);
00062 
00063 
00064 
00065 # ifndef MLN_INCLUDE_ONLY
00066 
00067       namespace internal
00068       {
00069 
00070         // Case: binary image -> set of point runs.
00071 
00072         template <typename I, typename P, typename S>
00073         void
00074         from_image_to_site_set(const I& input, const Gpoint<P>&,
00075                                S& s,           const mln::p_run<P>&)
00076         {
00077           s.clear();
00078           mln_fwd_piter(I) p(input.domain());
00079           p.start();
00080           for (;;)
00081           {
00082             // Skip background.
00083             while (p.is_valid() && input(p) == false)
00084               p.next();
00085             if (! p.is_valid()) // The end.
00086               break;
00087             mln_invariant(input(p) == true);
00088             P start = p, q;
00089             // Go to run end.
00090             do
00091             {
00092               q = p;
00093               p.next();
00094             }
00095             while (p.is_valid() && input(p) == true &&
00096                 // p follows q in a run, i.e., "p == q + right":
00097                 cut_(p.to_site()) == cut_(q) && p.last_coord() == q.last_coord() + 1);
00098             s.insert(p_run<P>(start, q));
00099           }
00100         }
00101 
00102 
00103         template <typename I, typename P, typename S>
00104         void
00105         from_image_to_site_set(const I& input, const Gpoint<P>&,
00106                                S& s,
00107                                const std::pair< mln_value(I), p_run<P> >&)
00108         {
00109           s.clear();
00110           mln_value(I) O = literal::zero;
00111           mln_fwd_piter(I) p(input.domain());
00112           p.start();
00113           for (;;)
00114           {
00115             if (! p.is_valid()) // The end.
00116               break;
00117             mln_value(I) v = input(p);
00118             P start = p, q;
00119             // Go to run end.
00120             do
00121             {
00122               q = p;
00123               p.next();
00124             }
00125             while (p.is_valid() && input(p) == v &&
00126                 cut_(p.to_site()) == cut_(q) && p.last_coord() == q.last_coord() + 1);
00127             s.insert(v, p_run<P>(start, q));
00128           }
00129         }
00130 
00131 
00132         template <typename I, typename P, typename S>
00133         void
00134         from_image_to_site_set(const I& input, const Gpoint<P>&,
00135                                S& s,
00136                                const std::pair< mln_value(I), P >&)
00137         {
00138           s.clear();
00139           mln_fwd_piter(I) p(input.domain());
00140           for_all(p)
00141             s.insert(input(p), p);
00142         }
00143 
00144 
00145         template <typename I, typename S>
00146         inline
00147         void
00148         from_image_to_site_set(const Image<I>& from, Site_Set<S>& to)
00149         {
00150           from_image_to_site_set(exact(from), mln_deduce(I, domain_t, element)(),
00151                                  exact(to),   mln_i_element(S)());
00152         }
00153 
00154         template <typename I>
00155         inline
00156         void
00157         from_image_to_site_set(const Image<I>& from_, p_array<mln_psite(I)>& to)
00158         {
00159           const I& from = exact(from_);
00160 
00161           mln_piter(I) p(from.domain());
00162           for_all(p)
00163             if (from(p))
00164               to.append(p);
00165         }
00166 
00167 
00168       } // end of namespace mln::convert::impl::internal
00169 
00170 
00171       // Facade.
00172 
00173       template <typename I, typename S>
00174       inline
00175       void
00176       from_image_to_site_set(const Image<I>& from, Site_Set<S>& to)
00177       {
00178         internal::from_image_to_site_set(exact(from), exact(to));
00179       }
00180 
00181 # endif // ! MLN_INCLUDE_ONLY
00182 
00183     } // end of namespace mln::convert::impl
00184 
00185   } // end of namespace mln::convert
00186 
00187 } // end of namespace mln
00188 
00189 
00190 #endif // ! MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH

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