$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
rotate_90.hh
1 // Copyright (C) 2010, 2011, 2014 EPITA Research and Development
2 // Laboratory (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 SCRIBO_PREPROCESSING_ROTATE_90_HH
28 # define SCRIBO_PREPROCESSING_ROTATE_90_HH
29 
33 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/geom/all.hh>
37 
38 // FIXME: not generic
39 # include <mln/core/alias/dpoint2d.hh>
40 
41 //FIXME: add more preconditions + a dispatch !?
42 
43 namespace scribo
44 {
45 
46  namespace preprocessing
47  {
48 
49  using namespace mln;
50 
59  template <typename I>
60  mln_concrete(I)
61  rotate_90(const Image<I>& input, bool positive);
62 
65  //
66  template <typename I>
67  mln_concrete(I)
68  rotate_90(const Image<I>& input);
69 
70 
71 
72 # ifndef MLN_INCLUDE_ONLY
73 
74 
75  template <typename I>
76  mln_concrete(I)
77  rotate_90(const Image<I>& input_, bool positive)
78  {
79  mln_trace("scribo::preprocessing::rotate_90");
80 
81  const I& input = exact(input_);
82  mln_precondition(input.is_valid());
83 
84  // FIXME: Does this routine accept images with an origin
85  // different from (0,0) and with negative coordinates?
86  //
87  // mln_precondition(input.domain().pmin().row() > 0);
88  // mln_precondition(input.domain().pmin().col() > 0);
89 
90  // Works only on one block images.
91  mlc_is(mln_trait_image_value_access(I),
92  mln::trait::image::value_access::direct)::check();
93  mlc_is(mln_trait_image_value_storage(I),
94  mln::trait::image::value_storage::one_block)::check();
95 
96  // Initialize output domain and make sure the border size is the
97  // same as input's.
98  typedef mln_domain(I) domain_t;
99  mln_site(I) pmax(input.domain().pmax().col(),
100  input.domain().pmax().row());
101  mln_concrete(I) output(domain_t(input.domain().pmin(), pmax),
102  input.border());
103 
104  mln_assertion(output.is_valid());
105 
106  const mln_value(I)* in_ptr = input.buffer();
107 
108  unsigned
109  in_ncols = geom::ncols(input) + 2 * input.border(),
110  in_nrows = geom::nrows(input) + 2 * input.border();
111 
112  unsigned
113  out_ncols = geom::ncols(output) + 2 * input.border(),
114  out_nrows = geom::nrows(output) + 2 * input.border();
115 
116  int
117  out_next_offset,
118  out_next_p_offset;
119 
120  mln_value(I)* out_ptr = output.buffer();
121 
122  if (positive) // +90 deg
123  {
124  dpoint2d dp(out_nrows, + 1);
125  out_next_offset = output.delta_offset(dp);
126 
127  out_next_p_offset = output.delta_offset(dpoint2d(-1, 0));
128 
129  out_ptr += output.delta_offset(dpoint2d(out_nrows - 1, 0));
130  }
131  else // -90 deg
132  {
133  dpoint2d dp(- out_nrows, - 1);
134  out_next_offset = output.delta_offset(dp);
135 
136  out_next_p_offset = output.delta_offset(dpoint2d(+1, 0));
137 
138  out_ptr += out_ncols - 1;
139  }
140 
141  for (unsigned row = 0; row < in_nrows; ++row)
142  {
143  for (unsigned col = 0; col < in_ncols;
144  ++col, ++in_ptr, out_ptr += out_next_p_offset)
145  *out_ptr = *in_ptr;
146 
147  out_ptr += out_next_offset;
148  }
149 
150  return output;
151  }
152 
153 
154  template <typename I>
155  mln_concrete(I)
156  rotate_90(const Image<I>& input)
157  {
158  return rotate_90(input, true);
159  }
160 
161 
162 # endif // ! MLN_INCLUDE_ONLY
163 
164 
165  } // end of namespace scribo::preprocessing
166 
167 } // end of namespace mln
168 
169 
170 # endif // SCRIBO_PREPROCESSING_ROTATE_90_HH
171