$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
to_image.hh
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CONVERT_TO_IMAGE_HH
28 # define MLN_CONVERT_TO_IMAGE_HH
29 
33 
34 # include <mln/trait/image_from_grid.hh>
35 
36 # include <mln/core/concept/site_set.hh>
37 # include <mln/core/concept/window.hh>
38 # include <mln/core/concept/weighted_window.hh>
39 # include <mln/core/concept/neighborhood.hh>
40 
41 # include <mln/geom/bbox.hh>
42 # include <mln/data/fill.hh>
43 # include <mln/histo/array.hh>
44 
45 # include <mln/core/image/image1d.hh>
46 # include <mln/core/image/image2d.hh>
47 # include <mln/core/image/image3d.hh>
48 # include <mln/convert/from_to.hh>
49 
50 
51 namespace mln
52 {
53 
54  namespace convert
55  {
56 
57 
60  template <typename S>
61  mln_image_from_grid(mln_site(S)::grid, bool)
62  to_image(const Site_Set<S>& pset, unsigned border = 1);
63 
65  template <typename W>
66  mln_image_from_grid(mln_site(W)::grid, bool)
67  to_image(const Window<W>& win);
68 
70  template <typename W>
71  mln_image_from_grid(mln_site(W)::grid, mln_weight(W))
72  to_image(const Weighted_Window<W>& w_win);
73 
75  template <typename N>
76  mln_image_from_grid(mln_site(N)::grid, bool)
77  to_image(const Neighborhood<N>& nbh);
78 
80  template <typename T>
81  image1d<unsigned>
82  to_image(const histo::array<T>& h);
83 
84 
85 
86 # ifndef MLN_INCLUDE_ONLY
87 
88  template <typename S>
89  mln_image_from_grid(mln_site(S)::grid, bool)
90  to_image(const Site_Set<S>& pset_, unsigned border)
91  {
92  const S& pset = exact(pset_);
93  mln_image_from_grid(mln_site(S)::grid, bool) ima;
94  ima.init_(geom::bbox(pset).to_larger(border));
95  mln::data::fill(ima, false);
96  mln_piter(S) p(pset);
97  for_all(p)
98  ima(p) = true;
99  return ima;
100  }
101 
102  template <typename W>
103  mln_image_from_grid(mln_site(W)::grid, bool)
104  to_image(const Window<W>& win)
105  {
106  mln_is_simple_window(W)::check();
107  mln_precondition(exact(win).is_valid());
108  mln_image_from_grid(mln_site(W)::grid, bool) tmp;
109  convert::from_to(win, tmp);
110  return tmp;
111  }
112 
113  template <typename W>
114  mln_image_from_grid(mln_site(W)::grid, mln_weight(W))
115  to_image(const Weighted_Window<W>& w_win)
116  {
117  mln_is_simple_window(W)::check();
118  mln_precondition(exact(w_win).is_valid());
119  mln_image_from_grid(mln_site(W)::grid, mln_weight(W)) tmp;
120  convert::from_to(exact(w_win), tmp);
121  return tmp;
122  }
123 
124  template <typename N>
125  mln_image_from_grid(mln_site(N)::grid, bool)
126  to_image(const Neighborhood<N>& nbh)
127  {
128  mln_precondition(exact(nbh).is_valid());
129  return to_image(exact(nbh).win());
130  }
131 
132  template <typename T>
133  image1d<unsigned>
134  to_image(const histo::array<T>& h)
135  {
136  def::coord
137  n = static_cast<def::coord>(h.vset().nvalues()),
138  v_min = static_cast<def::coord>(h.vset()[0]),
139  v_max = static_cast<def::coord>(h.vset()[n - 1]);
140  image1d<unsigned> ima(make::box1d(v_min, v_max));
141  for (def::coord i = 0; i < n; ++i)
142  ima(point1d(i)) = h[i];
143  return ima;
144  }
145 
146 # endif // ! MLN_INCLUDE_ONLY
147 
148  } // end of namespace mln::convert
149 
150 } // end of namespace mln
151 
152 
153 #endif // ! MLN_CONVERT_TO_IMAGE_HH