$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fill_with_value.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
2 // (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_DATA_FILL_WITH_VALUE_HH
28 # define MLN_DATA_FILL_WITH_VALUE_HH
29 
38 
39 # include <cstdlib>
40 
41 # include <mln/core/concept/image.hh>
42 
43 
44 
45 // Specializations are in:
46 # include <mln/data/fill_with_value.spe.hh>
47 
48 
49 namespace mln
50 {
51 
52  namespace data
53  {
54 
63  template <typename I, typename V>
64  void fill_with_value(Image<I>& ima, const V& val);
66 
67 
68 
69 # ifndef MLN_INCLUDE_ONLY
70 
71  namespace internal
72  {
73 
74  template <typename I, typename V>
75  inline
76  void fill_with_value_tests(Image<I>& ima, const V&)
77  {
78  mlc_converts_to(mln_exact(V), mln_value(I))::check();
79  mln_precondition(exact(ima).is_valid());
80 
81  // Avoid a warning about an undefined variable when NDEBUG
82  (void) ima;
83  }
84 
85  } // end of namespace mln::data::internal
86 
87 
88  namespace impl
89  {
90 
91  namespace generic
92  {
93 
101  //
102  template <typename I, typename V>
103  void fill_with_value(Image<I>& ima_, const V& val)
104  {
105  mln_trace("data::impl::generic::fill_with_value");
106 
107  I& ima = exact(ima_);
108 
109  internal::fill_with_value_tests(ima, val);
110  mlc_is(mln_trait_image_pw_io(I),
111  trait::image::pw_io::read_write)::check();
112 
113  mln_value(I) v = static_cast<mln_value(I)>(exact(val));
114  mln_piter(I) p(ima.domain());
115  for_all(p)
116  ima(p) = v;
117 
118  }
119 
120  } // end if namespace mln::data::impl::generic
121 
122  } // end of namespace mln::data::impl
123 
124 
125  // Facade.
126 
127  template <typename I, typename V>
128  inline
129  void fill_with_value(Image<I>& ima, const V& val)
130  {
131  mln_trace("data::fill_with_value");
132 
133  internal::fill_with_value_tests(ima, val);
134  internal::fill_with_value_dispatch(ima, val);
135 
136  }
137 
138 
139 # endif // ! MLN_INCLUDE_ONLY
140 
141  } // end of namespace mln::data
142 
143 } // end of namespace mln
144 
145 
146 #endif // ! MLN_DATA_FILL_WITH_VALUE_HH