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

to_image.hh

00001 // Copyright (C) 2007, 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_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   } // end of namespace mln::convert
00153 
00154 } // end of namespace mln
00155 
00156 
00157 #endif // ! MLN_CONVERT_TO_IMAGE_HH

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