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_TO_P_SET_HH
00027 # define MLN_CONVERT_TO_P_SET_HH
00028
00032
00033 # include <set>
00034
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/core/concept/window.hh>
00037 # include <mln/core/concept/point_site.hh>
00038 # include <mln/core/site_set/p_set.hh>
00039 # include <mln/pw/image.hh>
00040 # include <mln/pw/cst.hh>
00041 # include <mln/metal/templated_by.hh>
00042 # include <mln/metal/is_a.hh>
00043
00044
00045 namespace mln
00046 {
00047
00048 namespace convert
00049 {
00050
00052 template <typename N>
00053 p_set<mln_psite(N)>
00054 to_p_set(const Neighborhood<N>& nbh);
00055
00057 template <typename I>
00058 p_set<mln_psite(I)>
00059 to_p_set(const Image<I>& ima);
00060
00062 template <typename W>
00063 p_set<mln_psite(W)>
00064 to_p_set(const Window<W>& win);
00065
00068 template <typename P, typename C>
00069 p_set<P>
00070 to_p_set(const std::set<P, C>& s);
00071
00073 template <typename S>
00074 p_set<mln_psite(S)>
00075 to_p_set(const Site_Set<S>& ps);
00076
00077
00078 # ifndef MLN_INCLUDE_ONLY
00079
00080 template <typename N>
00081 inline
00082 p_set<mln_psite(N)>
00083 to_p_set(const Neighborhood<N>& nbh_)
00084 {
00085 const N& nbh = exact(nbh_);
00086 typedef mln_psite(N) P;
00087 p_set<P> pset;
00088 mln_niter(N) n(nbh, P::origin);
00089 for_all(n)
00090 pset.insert(n);
00091 return pset;
00092 }
00093
00094 template <typename I>
00095 inline
00096 p_set<mln_psite(I)>
00097 to_p_set(const Image<I>& ima_)
00098 {
00099 const I& ima = exact(ima_);
00100 mln_precondition(ima.is_valid());
00101
00102
00103
00104
00105 typedef mln_psite(I) P;
00106 p_set<P> pset;
00107 mln_piter(I) p(ima.domain());
00108 for_all(p)
00109 if (ima(p))
00110 pset.insert(p);
00111 return pset;
00112 }
00113
00114 template <typename W>
00115 inline
00116 p_set<mln_psite(W)>
00117 to_p_set(const Window<W>& win)
00118 {
00119 typedef mln_psite(W) P;
00120 p_set<P> pset;
00121 mln_qiter(W) q(exact(win), P::origin);
00122 for_all(q)
00123 pset.insert(q);
00124 return pset;
00125 }
00126
00127 template <typename P, typename C>
00128 inline
00129 p_set<P>
00130 to_p_set(const std::set<P, C>& s)
00131 {
00132 P titi;
00133 mln::metal::is_a<P, Site>::check();
00134 p_set<P> pset;
00135 for (typename std::set<P, C>::const_iterator i = s.begin();
00136 i != s.end(); ++i)
00137 pset.insert(*i);
00138 return pset;
00139 }
00140
00141 template <typename S>
00142 inline
00143 p_set<mln_psite(S)>
00144 to_p_set(const Site_Set<S>& ps_)
00145 {
00146 const S& ps = exact(ps_);
00147 p_set<mln_psite(S)> tmp;
00148 mln_piter(S) p(ps);
00149 for_all(p)
00150 tmp.insert(p);
00151 return tmp;
00152 }
00153
00154 # endif // ! MLN_INCLUDE_ONLY
00155
00156 }
00157
00158 }
00159
00160
00161 #endif // ! MLN_CONVERT_TO_P_SET_HH