$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dir_struct_elt_incr_update.hh
1 // Copyright (C) 2007, 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development 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 MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH
28 # define MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH
29 
33 
34 # include <mln/core/concept/browsing.hh>
35 # include <mln/core/concept/image.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace canvas
42  {
43 
44  namespace browsing
45  {
46 
87  struct dir_struct_elt_incr_update_t : public Browsing< dir_struct_elt_incr_update_t >
88  {
89  // This default constructor is needed for compilation with gcc
90  // 4.6.0, gcc 4.6.1 and Clang.
92 
93  template <typename F>
94  void operator()(F& f) const;
95  };
96 
98 
99 # ifndef MLN_INCLUDE_ONLY
100 
101 # ifndef MLN_WO_GLOBAL_VARS
102 
104 
105 # endif // ! MLN_WO_GLOBAL_VARS
106 
107  inline
109  {
110  }
111 
112  template <typename F>
113  inline
114  void
116  {
117  mln_trace("canvas::browsing::dir_struct_elt_incr_update");
118  mln_precondition(f.dir < f.dim);
119  typedef typename F::I I;
120 
121  const mln_psite(I)
122  pmin = f.input.domain().pmin(),
123  pmax = f.input.domain().pmax();
124 
125  typedef mln_deduce(I, site, coord) C;
126  const C
127  pmin_dir = pmin[f.dir],
128  pmax_dir = pmax[f.dir],
129  pmin_dir_plus_half_length = static_cast<C>(pmin_dir + f.length / 2),
130  pmax_dir_minus_half_length = static_cast<C>(pmax_dir - f.length / 2);
131 
132  mln_psite(I) pt, pu;
133 
134  def::coord&
135  ct = pt[f.dir],
136  cu = pu[f.dir],
137  p_dir = f.p[f.dir];
138 
139  f.p = pmin;
140 
141  f.init();
142 
143  do
144  {
145  pt = f.p;
146  pu = f.p;
147 
148  f.init_line();
149 
150  // initialization (before first point of the line)
151  for (ct = pmin_dir; ct < pmin_dir_plus_half_length; ++ ct)
152  if (f.input.has(pt))
153  f.add_point(pt);
154 
155  // left columns (just take new points)
156  for (p_dir = pmin_dir; p_dir <= pmin_dir_plus_half_length; ++p_dir, ++ct)
157  {
158  if (f.input.has(pt))
159  f.add_point(pt);
160  f.next();
161  }
162 
163  // middle columns (both take and untake)
164  cu = pmin_dir;
165  for (; p_dir <= pmax_dir_minus_half_length; ++cu, ++p_dir, ++ct)
166  {
167  if (f.input.has(pt))
168  f.add_point(pt);
169  if (f.input.has(pu))
170  f.remove_point(pu);
171  f.next();
172  }
173 
174  // right columns (now just untake old points)
175  for (; p_dir <= pmax_dir; ++cu, ++p_dir)
176  {
177  if (f.input.has(pu))
178  f.remove_point(pu);
179  f.next();
180  }
181 
182  p_dir = pmin_dir;
183 
184  for (int c = F::dim - 1; c >= 0; --c)
185  {
186  if (c == int(f.dir))
187  continue;
188  if (f.p[c] != pmax[c])
189  {
190  ++f.p[c];
191  break;
192  }
193  f.p[c] = pmin[c];
194  }
195  } while (f.p != pmin);
196 
197  f.final();
198  }
199 
200 # endif // ! MLN_INCLUDE_ONLY
201 
202  } // end of namespace mln::canvas::browsing
203 
204  } // end of namespace mln::canvas
205 
206 } // end of namespace mln
207 
208 #endif // ! MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH