$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
extension/fill.hh
1 // Copyright (C) 2007, 2008, 2009, 2012 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_EXTENSION_FILL_HH
28 # define MLN_EXTENSION_FILL_HH
29 
36 
37 # include <mln/core/concept/image.hh>
38 # include <mln/trait/image/props.hh>
39 # include <mln/border/fill.hh>
40 # include <mln/data/fill_with_value.hh>
41 
42 
43 namespace mln
44 {
45 
46  namespace extension
47  {
48 
61  template <typename I>
62  void fill(const Image<I>& ima, const mln_value(I)& val);
63 
64 
65 # ifndef MLN_INCLUDE_ONLY
66 
67 
68  namespace internal
69  {
70 
71  // Do it.
72 
73  template <typename I>
74  void do_fill(I& ima, const mln_value(I)& val); // Entry point.
75 
76  template <typename I>
77  void do_fill(mln::trait::image::ext_domain::some,
78  mln::trait::image::ext_value::single,
79  mln::trait::image::ext_domain::none,
80  I& ima, const mln_value(I)& val)
81  {
82  ima.change_extension(val);
83  }
84 
85  template <typename I>
86  void do_fill(mln::trait::image::ext_domain::some,
87  mln::trait::image::ext_value::multiple,
88  mln::trait::image::ext_domain::none,
89  I& ima, const mln_value(I)& val)
90  {
91  border::fill(ima, val);
92  ima.change_extension(val);
93  }
94 
95  template <typename I>
96  void do_fill(mln::trait::image::ext_domain::some,
97  mln::trait::image::ext_value::any,
98  mln::trait::image::ext_domain::some,
99  I& ima, const mln_value(I)& val)
100  {
101  mln::extension::fill(ima.unmorph_(), val);
102  }
103 
104  template <typename I>
105  void do_fill(mln::trait::image::ext_domain::none,
106  mln::trait::image::ext_value::any,
107  mln::trait::image::ext_domain::any,
108  I& ima, const mln_value(I)& val)
109  {
110  (void) ima;
111  (void) val;
112  // Oops...
113  }
114 
115  template <typename I>
116  void do_fill(I& ima, const mln_value(I)& val)
117  {
118  typedef typename I::delegatee D;
119  do_fill(mln_trait_image_ext_domain(I)(),
120  mln_trait_image_ext_value(I)(),
121  mln_trait_image_ext_domain(D)(),
122  ima, val);
123  }
124 
125 
126 
127  // Dispatch.
128 
129  template <typename I>
130  void fill_dispatch(mln::trait::image::ext_domain::none,
131  mln::trait::image::ext_io::any,
132  I& /* ima */, const mln_value(I)& /* val */)
133  {
134  // No-op cause no extension domain, no border.
135  }
136 
137  template <typename I>
138  void fill_dispatch(mln::trait::image::ext_domain::some,
139  mln::trait::image::ext_io::read_only,
140  I& ima, const mln_value(I)& val)
141  {
142  // No-op for the extension domain, yet:
143  border::fill(ima, val);
144  }
145 
146  template <typename I>
147  void fill_dispatch(mln::trait::image::ext_domain::extendable,
148  mln::trait::image::ext_io::read_write,
149  I& ima, const mln_value(I)& val)
150  {
151  // Just fill the border.
152  border::fill(ima, val);
153  }
154 
155  template <typename I>
156  void fill_dispatch(mln::trait::image::ext_domain::some,
157  mln::trait::image::ext_io::read_write,
158  I& ima, const mln_value(I)& val)
159  {
160  do_fill(ima, val);
161  }
162 
163  template <typename I>
164  void fill_dispatch(const Image<I>& ima_, const mln_value(I)& val)
165  {
166  I& ima = const_cast<I&>(exact(ima_));
167  fill_dispatch(mln_trait_image_ext_domain(I)(),
168  mln_trait_image_ext_io(I)(),
169  ima, val);
170  }
171 
172  } // end of namespace mln::extension::internal
173 
174 
175  // Facade.
176 
177  template <typename I>
178  void fill(const Image<I>& ima, const mln_value(I)& val)
179  {
180  mln_trace("extension::fill");
181 
182  mln_precondition(exact(ima).is_valid());
183  internal::fill_dispatch(ima, val);
184 
185  }
186 
187 # endif // ! MLN_INCLUDE_ONLY
188 
189  } // end of namespace mln::extension
190 
191 } // end of namespace mln
192 
193 
194 #endif // ! MLN_EXTENSION_FILL_HH