Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
resize.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_BORDER_RESIZE_HH
27 # define MLN_BORDER_RESIZE_HH
28 
37 
38 # include <mln/core/concept/image.hh>
39 # include <mln/core/routine/duplicate.hh>
40 # include <mln/core/routine/primary.hh>
41 # include <mln/border/get.hh>
42 # include <mln/data/fill.hh>
43 
44 
45 namespace mln
46 {
47 
48  namespace border
49  {
50 
62  template <typename I>
63  void resize(const Image<I>& ima, unsigned thickness);
64 
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69  namespace impl
70  {
71 
72  template <typename I>
73  inline
74  void resize(I& ima, unsigned thickness)
75  {
76  if (border::get(ima) == thickness)
77  return; // No-op.
78 
79  mln_concrete(I) memo = mln::duplicate(ima);
80  ima.resize_(thickness);
81  data::fill(ima, memo);
82 
83  mln_postcondition(border::get(ima) == thickness);
84  }
85 
86  } // end of namespace mln::border::impl
87 
88 
89  namespace internal
90  {
91 
92  template <typename I>
93  inline
94  void resize_dispatch(trait::image::ext_domain::any,
95  const Image<I>& ima, unsigned thickness)
96  {
97  // No-op.
98  (void) ima;
99  (void) thickness;
100  }
101 
102  template <typename I>
103  inline
104  void resize_dispatch(trait::image::ext_domain::extendable,
105  const Image<I>& ima, unsigned thickness)
106  {
107  // Effective resizing.
108  impl::resize(const_cast<I&>(exact(ima)), thickness);
109  }
110 
111  template <typename I>
112  inline
113  void resize_dispatch(const Image<I>& ima, unsigned thickness)
114  {
115  resize_dispatch(mln_trait_image_ext_domain(I)(),
116  ima, thickness);
117  }
118 
119  } // end of namespace mln::border::internal
120 
121 
123 
124  template <typename I>
125  inline
126  void resize(const Image<I>& ima, unsigned thickness)
127  {
128  trace::entering("border::resize");
129 
130  mln_precondition(exact(ima).is_valid());
131 
132  // Try to resize the primary image behind ima.
133  internal::resize_dispatch(primary(ima), thickness);
134 
135  trace::exiting("border::resize");
136  }
137 
138 # endif // ! MLN_INCLUDE_ONLY
139 
140  } // end of namespace mln::border
141 
142 } // end of namespace mln
143 
144 
145 #endif // ! MLN_BORDER_RESIZE_HH