$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
horizontal_symmetry.hh
1 // Copyright (C) 2010, 2012 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 
30 
31 #ifndef MLN_GEOM_HORIZONTAL_SYMMETRY_HH
32 # define MLN_GEOM_HORIZONTAL_SYMMETRY_HH
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/box_runend_piter.hh>
36 # include <mln/core/box_runstart_piter.hh>
37 
38 namespace mln
39 {
40 
41  namespace geom
42  {
43 
48  template <typename I>
49  mln_concrete(I)
50  horizontal_symmetry(const Image<I>& input);
51 
52 
53 # ifndef MLN_INCLUDE_ONLY
54 
55 
56  // Implementations
57 
58  namespace impl
59  {
60 
61  namespace generic
62  {
63 
64  template <typename I>
65  mln_concrete(I)
66  horizontal_symmetry(const Image<I>& input_)
67  {
68  const I& input = exact(input_);
69  mln_precondition(input.is_valid());
70 
71  mln_concrete(I) output(input.domain());
72 
73  typedef mln_site(I) P;
74  box_runstart_piter<P> pi(input.domain());
75  box_runend_piter<P> po(output.domain());
76 
77  unsigned ncols = input.ncols();
78 
79  for_all_2(pi, po)
80  {
81  mln_site(I) idi = pi, ido = po;
82  ido[1] -= ncols - 1;
83  for (unsigned n = 0; n < ncols; ++n, ++idi[1], ++ido[1])
84  output(ido) = input(idi);
85  }
86 
87  return output;
88  }
89 
90  } // end of namespace mln::geom::impl::generic
91 
92 
93  template <typename I>
94  mln_concrete(I)
95  horizontal_symmetry_fastest(const Image<I>& input_)
96  {
97  const I& input = exact(input_);
98  mln_precondition(input.is_valid());
99 
100  mln_concrete(I) output(input.domain());
101 
102  typedef mln_site(I) P;
103  box_runstart_piter<P> pi(input.domain());
104  box_runend_piter<P> po(output.domain());
105 
106  unsigned ncols = input.ncols();
107 
108  typedef mln_value(I)* ptr_t;
109 
110  for_all_2(pi, po)
111  {
112  const mln_value(I)* ptr_in = & input(pi);
113  ptr_t ptr_out = (& output(po)) - ncols + 1;
114 
115  for (unsigned n = 0; n < ncols; ++n)
116  *ptr_out++ = *ptr_in++;
117  }
118 
119  return output;
120  }
121 
122 
123  } // end of namespace mln::geom::impl
124 
125 
126 
127  // Dispatch
128 
129  namespace internal
130  {
131 
132  template <typename I>
133  mln_concrete(I)
134  horizontal_symmetry_dispatch(
135  trait::image::value_alignment::any,
136  trait::image::value_storage::any,
137  trait::image::value_access::any,
138  const Image<I>& input)
139  {
141  }
142 
143 
144  template <typename I>
145  mln_concrete(I)
146  horizontal_symmetry_dispatch(
147  trait::image::value_alignment::with_grid,
148  trait::image::value_storage::one_block,
149  trait::image::value_access::direct,
150  const Image<I>& input)
151  {
152  return impl::horizontal_symmetry_fastest(input);
153  }
154 
155 
156  template <typename I>
157  mln_concrete(I)
158  horizontal_symmetry_dispatch(const Image<I>& input)
159  {
160  return horizontal_symmetry_dispatch(
161  mln_trait_image_value_alignment(I)(),
162  mln_trait_image_value_storage(I)(),
163  mln_trait_image_value_access(I)(),
164  input);
165  }
166 
167  } // end of namespace mln::geom::internal
168 
169 
170 
171  // Facade
172 
173  template <typename I>
174  mln_concrete(I)
175  horizontal_symmetry(const Image<I>& input_)
176  {
177  mln_trace("geom::horizontal_symmetry");
178 
179  const I& input = exact(input_);
180  mln_precondition(input.is_valid());
181 
182  mln_concrete(I) output = internal::horizontal_symmetry_dispatch(input);
183 
184  return output;
185  }
186 
187 
188 # endif // ! MLN_INCLUDE_ONLY
189 
190 
191  } // end of namespace mln::geom
192 
193 } // end of namespace mln
194 
195 
196 #endif // ! MLN_GEOM_HORIZONTAL_SYMMETRY_HH