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_IMAGE_HH
00027 # define MLN_CONVERT_TO_IMAGE_HH
00028
00032
00033 # include <mln/trait/image_from_grid.hh>
00034
00035 # include <mln/core/concept/site_set.hh>
00036 # include <mln/core/concept/window.hh>
00037 # include <mln/core/concept/weighted_window.hh>
00038 # include <mln/core/concept/neighborhood.hh>
00039
00040 # include <mln/geom/bbox.hh>
00041 # include <mln/data/fill.hh>
00042 # include <mln/histo/array.hh>
00043
00044 # include <mln/core/image/image1d.hh>
00045 # include <mln/core/image/image2d.hh>
00046 # include <mln/core/image/image3d.hh>
00047 # include <mln/convert/from_to.hh>
00048
00049
00050 namespace mln
00051 {
00052
00053 namespace convert
00054 {
00055
00056
00059 template <typename S>
00060 mln_image_from_grid(mln_site(S)::grid, bool)
00061 to_image(const Site_Set<S>& pset, unsigned border = 1);
00062
00064 template <typename W>
00065 mln_image_from_grid(mln_site(W)::grid, bool)
00066 to_image(const Window<W>& win);
00067
00069 template <typename W>
00070 mln_image_from_grid(mln_site(W)::grid, mln_weight(W))
00071 to_image(const Weighted_Window<W>& w_win);
00072
00074 template <typename N>
00075 mln_image_from_grid(mln_site(N)::grid, bool)
00076 to_image(const Neighborhood<N>& nbh);
00077
00079 template <typename T>
00080 image1d<unsigned>
00081 to_image(const histo::array<T>& h);
00082
00083
00084
00085 # ifndef MLN_INCLUDE_ONLY
00086
00087 template <typename S>
00088 inline
00089 mln_image_from_grid(mln_site(S)::grid, bool)
00090 to_image(const Site_Set<S>& pset_, unsigned border)
00091 {
00092 const S& pset = exact(pset_);
00093 mln_image_from_grid(mln_site(S)::grid, bool) ima;
00094 ima.init_(geom::bbox(pset).to_larger(border));
00095 data::fill(ima, false);
00096 mln_piter(S) p(pset);
00097 for_all(p)
00098 ima(p) = true;
00099 return ima;
00100 }
00101
00102 template <typename W>
00103 inline
00104 mln_image_from_grid(mln_site(W)::grid, bool)
00105 to_image(const Window<W>& win)
00106 {
00107 mln_is_simple_window(W)::check();
00108 mln_precondition(exact(win).is_valid());
00109 mln_image_from_grid(mln_site(W)::grid, bool) tmp;
00110 convert::from_to(win, tmp);
00111 return tmp;
00112 }
00113
00114 template <typename W>
00115 inline
00116 mln_image_from_grid(mln_site(W)::grid, mln_weight(W))
00117 to_image(const Weighted_Window<W>& w_win)
00118 {
00119 mln_is_simple_window(W)::check();
00120 mln_precondition(exact(w_win).is_valid());
00121 mln_image_from_grid(mln_site(W)::grid, mln_weight(W)) tmp;
00122 convert::from_to(exact(w_win), tmp);
00123 return tmp;
00124 }
00125
00126 template <typename N>
00127 inline
00128 mln_image_from_grid(mln_site(N)::grid, bool)
00129 to_image(const Neighborhood<N>& nbh)
00130 {
00131 mln_precondition(exact(nbh).is_valid());
00132 return to_image(exact(nbh).win());
00133 }
00134
00135 template <typename T>
00136 inline
00137 image1d<unsigned>
00138 to_image(const histo::array<T>& h)
00139 {
00140 def::coord
00141 n = static_cast<def::coord>(h.vset().nvalues()),
00142 v_min = static_cast<def::coord>(h.vset()[0]),
00143 v_max = static_cast<def::coord>(h.vset()[n - 1]);
00144 image1d<unsigned> ima(make::box1d(v_min, v_max));
00145 for (def::coord i = 0; i < n; ++i)
00146 ima(point1d(i)) = h[i];
00147 return ima;
00148 }
00149
00150 # endif // ! MLN_INCLUDE_ONLY
00151
00152 }
00153
00154 }
00155
00156
00157 #endif // ! MLN_CONVERT_TO_IMAGE_HH