Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
fill_non_primary_from_primary_2_faces.hh
1 // Copyright (C) 2012 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_WORLD_K2_BORDER_FILL_NON_PRIMARY_FROM_PRIMARY_2_FACES_HH
31 # define MLN_WORLD_K2_BORDER_FILL_NON_PRIMARY_FROM_PRIMARY_2_FACES_HH
32 
33 # include <mln/core/concept/image.hh>
34 # include <mln/core/concept/function.hh>
35 # include <mln/world/kn/safe_cast.hh>
36 # include <mln/world/k2/is_non_primary_2_face_horizontal.hh>
37 # include <mln/world/k2/is_non_primary_2_face_vertical.hh>
38 # include <mln/geom/min_row.hh>
39 # include <mln/geom/min_col.hh>
40 # include <mln/geom/max_row.hh>
41 # include <mln/geom/max_col.hh>
42 
43 
44 namespace mln
45 {
46 
47  namespace world
48  {
49 
50  namespace k2
51  {
52 
53  namespace border
54  {
55 
65  template <typename I, typename F>
66  void fill_non_primary_from_primary_2_faces(const Image<I>& inout,
67  const Function_vv2v<F>& f);
68 
69 
70 
71 # ifndef MLN_INCLUDE_ONLY
72 
73 
74  template <typename I, typename F>
75  void fill_non_primary_from_primary_2_faces(const Image<I>& inout_,
76  const Function_vv2v<F>& f_)
77  {
78  trace::entering("mln::world::k2::fill_non_primary_from_primary_2_faces");
79 
80  mln_precondition(exact(inout_).is_valid());
81  mln_precondition(exact(inout_).border() >= 1);
82  mln_precondition(exact(inout_).domain() == exact(aux_).domain());
83  I& inout = const_cast<I&>(exact(inout_));
84  const F& f = exact(f_);
85 
86  typedef mln_argument(F) V;
87 
88  def::coord
89  min_row_1 = geom::min_row(inout) - 1,
90  max_row_1 = geom::max_row(inout) + 1,
91  min_col_1 = geom::min_col(inout) - 1,
92  max_col_1 = geom::max_col(inout) + 1;
93 
94  // Fill horizontal border
95  for (def::coord col = min_col_1; col <= max_col_1; ++col)
96  if (is_non_primary_2_face_vertical(min_row_1, col))
97  {
98  // First row
99  inout.at_(min_row_1, col) = f(inout.at_(min_row_1, col - 2),
100  inout.at_(min_row_1, col + 2));
101  // Last row
102  inout.at_(max_row_1, col) = f(inout.at_(max_row_1, col - 2),
103  inout.at_(max_row_1, col + 2));
104  }
105 
106  // Fill vertical border
107  for (def::coord row = min_row_1; row <= max_row_1; ++row)
108  if (is_non_primary_2_face_horizontal(row, min_col_1))
109  {
110  // First col
111  inout.at_(row, min_col_1) = f(inout.at_(row - 2, min_col_1),
112  inout.at_(row + 2, min_col_1));
113  // Last col
114  inout.at_(row, max_col_1) = f(inout.at_(row - 2, max_col_1),
115  inout.at_(row + 2, max_col_1));
116  }
117 
118  trace::exiting("mln::world::k2::fill_non_primary_from_primary_2_faces");
119  }
120 
121 
122 # endif // ! MLN_INCLUDE_ONLY
123 
124  } // end of namespace mln::world::k2::border
125 
126  } // end of namespace mln::world::k2
127 
128  } // end of namespace mln::world
129 
130 } // end of namespace mln
131 
132 #endif // ! MLN_WORLD_K2_BORDER_FILL_NON_PRIMARY_FROM_PRIMARY_2_FACES_HH