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