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
00027 #ifndef MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
00028 # define MLN_CONVERT_IMPL_FROM_IMAGE_TO_SITE_SET_HH
00029
00037
00038 # include <utility>
00039 # include <mln/core/site_set/p_run.hh>
00040 # include <mln/core/site_set/p_array.hh>
00041 # include <mln/metal/converts_to.hh>
00042
00043
00044
00045 namespace mln
00046 {
00047
00048
00049 template <typename E> struct Site_Set;
00050 template <typename E> struct Image;
00051 template <typename E> struct Gpoint;
00052
00053 namespace convert
00054 {
00055
00056 namespace impl
00057 {
00058
00060 template <typename I, typename S>
00061 void
00062 from_image_to_site_set(const Image<I>& from, Site_Set<S>& to);
00063
00064
00065
00066 # ifndef MLN_INCLUDE_ONLY
00067
00068 namespace internal
00069 {
00070
00071
00072
00073 template <typename I, typename P, typename S>
00074 void
00075 from_image_to_site_set(const I& input, const Gpoint<P>&,
00076 S& s, const mln::p_run<P>&)
00077 {
00078 s.clear();
00079 mln_fwd_piter(I) p(input.domain());
00080 p.start();
00081 for (;;)
00082 {
00083
00084 while (p.is_valid() && input(p) == false)
00085 p.next();
00086 if (! p.is_valid())
00087 break;
00088 mln_invariant(input(p) == true);
00089 P start = p, q;
00090
00091 do
00092 {
00093 q = p;
00094 p.next();
00095 }
00096 while (p.is_valid() && input(p) == true &&
00097
00098 cut_(p.to_site()) == cut_(q) && p.last_coord() == q.last_coord() + 1);
00099 s.insert(p_run<P>(start, q));
00100 }
00101 }
00102
00103
00104 template <typename I, typename P, typename S>
00105 void
00106 from_image_to_site_set(const I& input, const Gpoint<P>&,
00107 S& s,
00108 const std::pair< mln_value(I), p_run<P> >&)
00109 {
00110 s.clear();
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