00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
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   
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         
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             
00083             while (p.is_valid() && input(p) == false)
00084               p.next();
00085             if (! p.is_valid()) 
00086               break;
00087             mln_invariant(input(p) == true);
00088             P start = p, q;
00089             
00090             do
00091             {
00092               q = p;
00093               p.next();
00094             }
00095             while (p.is_valid() && input(p) == true &&
00096                 
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()) 
00116               break;
00117             mln_value(I) v = input(p);
00118             P start = p, q;
00119             
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       } 
00169 
00170 
00171       
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     } 
00184 
00185   } 
00186 
00187 } 
00188 
00189 
00190 #endif // ! MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH