Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
dir_struct_elt_incr_update.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 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 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 
48 
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 
97  extern const dir_struct_elt_incr_update_t dir_struct_elt_incr_update;
98 
99 # ifndef MLN_INCLUDE_ONLY
100 
101 # ifndef MLN_WO_GLOBAL_VARS
102 
103  const dir_struct_elt_incr_update_t dir_struct_elt_incr_update;
104 
105 # endif // ! MLN_WO_GLOBAL_VARS
106 
107  inline
108  dir_struct_elt_incr_update_t::dir_struct_elt_incr_update_t()
109  {
110  }
111 
112  template <typename F>
113  inline
114  void
115  dir_struct_elt_incr_update_t::operator()(F& f) const
116  {
117  trace::entering("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  std::cout << "init" << std::endl;
152  for (ct = pmin_dir; ct < pmin_dir_plus_half_length; ++ ct)
153  if (f.input.has(pt))
154  {
155  std::cout << '+' << pt << ' ';
156  f.add_point(pt);
157  }
158 
159  // left columns (just take new points)
160  std::cout << "left" << std::endl;
161  for (p_dir = pmin_dir; p_dir <= pmin_dir_plus_half_length; ++p_dir, ++ct)
162  {
163  if (f.input.has(pt))
164  {
165  std::cout << '+' << pt << ' ';
166  f.add_point(pt);
167  }
168  f.next();
169  }
170 
171  // middle columns (both take and untake)
172  std::cout << "middle" << std::endl;
173  cu = pmin_dir;
174  for (; p_dir <= pmax_dir_minus_half_length; ++cu, ++p_dir, ++ct)
175  {
176  if (f.input.has(pt))
177  {
178  std::cout << '+' << pt << ' ';
179  f.add_point(pt);
180  }
181  if (f.input.has(pu))
182  {
183  std::cout << '-' << pu << ' ';
184  f.remove_point(pu);
185  }
186  f.next();
187  }
188 
189  // right columns (now just untake old points)
190  std::cout << "right" << std::endl;
191  for (; p_dir <= pmax_dir; ++cu, ++p_dir)
192  {
193  if (f.input.has(pu))
194  {
195  std::cout << '-' << pu << ' ';
196  f.remove_point(pu);
197  }
198  f.next();
199  }
200 
201  p_dir = pmin_dir;
202 
203  for (int c = F::dim - 1; c >= 0; --c)
204  {
205  if (c == int(f.dir))
206  continue;
207  if (f.p[c] != pmax[c])
208  {
209  ++f.p[c];
210  break;
211  }
212  f.p[c] = pmin[c];
213  }
214  } while (f.p != pmin);
215 
216  f.final();
217  trace::exiting("canvas::browsing::dir_struct_elt_incr_update");
218  }
219 
220 # endif // ! MLN_INCLUDE_ONLY
221 
222  } // end of namespace mln::canvas::browsing
223 
224  } // end of namespace mln::canvas
225 
226 } // end of namespace mln
227 
228 #endif // ! MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH