$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vertical_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_VERTICAL_SYMMETRY_HH
32 # define MLN_GEOM_VERTICAL_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  vertical_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  vertical_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>
75  pi(input.domain()),
76  po(output.domain());
77 
78  unsigned ncols = input.ncols();
79 
80  for_all_2(pi, po)
81  {
82  mln_site(I) idi = pi, ido = po;
83  ido[1] = ncols - 1;
84  for (unsigned n = 0; n < ncols; ++n, ++idi[1], --ido[1])
85  output(ido) = input(idi);
86  }
87 
88  return output;
89  }
90 
91  } // end of namespace mln::geom::impl::generic
92 
93 
94  template <typename I>
95  mln_concrete(I)
96  vertical_symmetry_fastest(const Image<I>& input_)
97  {
98  const I& input = exact(input_);
99  mln_precondition(input.is_valid());
100 
101  mln_concrete(I) output(input.domain());
102 
103  typedef mln_site(I) P;
104  box_runstart_piter<P>
105  pi(input.domain()),
106  po(output.domain());
107 
108  unsigned ncols = input.ncols();
109 
110  typedef mln_value(I)* ptr_t;
111 
112  for_all_2(pi, po)
113  {
114  const mln_value(I)* ptr_in = & input(pi);
115  ptr_t ptr_out = (& output(po)) + ncols - 1;
116 
117  for (unsigned n = 0; n < ncols; ++n)
118  *ptr_out-- = *ptr_in++;
119  }
120 
121  return output;
122  }
123 
124 
125  } // end of namespace mln::geom::impl
126 
127 
128 
129  // Dispatch
130 
131  namespace internal
132  {
133 
134  template <typename I>
135  mln_concrete(I)
136  vertical_symmetry_dispatch(
137  trait::image::value_alignment::any,
138  trait::image::value_storage::any,
139  trait::image::value_access::any,
140  const Image<I>& input)
141  {
142  return impl::generic::vertical_symmetry(input);
143  }
144 
145 
146  template <typename I>
147  mln_concrete(I)
148  vertical_symmetry_dispatch(
149  trait::image::value_alignment::with_grid,
150  trait::image::value_storage::one_block,
151  trait::image::value_access::direct,
152  const Image<I>& input)
153  {
154  return impl::vertical_symmetry_fastest(input);
155  }
156 
157 
158  template <typename I>
159  mln_concrete(I)
160  vertical_symmetry_dispatch(const Image<I>& input)
161  {
162  return vertical_symmetry_dispatch(
163  mln_trait_image_value_alignment(I)(),
164  mln_trait_image_value_storage(I)(),
165  mln_trait_image_value_access(I)(),
166  input);
167  }
168 
169  } // end of namespace mln::geom::internal
170 
171 
172 
173  // Facade
174 
175  template <typename I>
176  mln_concrete(I)
177  vertical_symmetry(const Image<I>& input_)
178  {
179  mln_trace("geom::vertical_symmetry");
180 
181  const I& input = exact(input_);
182  mln_precondition(input.is_valid());
183 
184  mln_concrete(I) output = internal::vertical_symmetry_dispatch(input);
185 
186  return output;
187  }
188 
189 
190 # endif // ! MLN_INCLUDE_ONLY
191 
192 
193  } // end of namespace mln::geom
194 
195 } // end of namespace mln
196 
197 
198 #endif // ! MLN_GEOM_VERTICAL_SYMMETRY_HH