Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
interpolation.hh
1 #ifndef INTERPOLATION_HH
2 # define INTERPOLATION_HH
3 
4 # include "definitions.hh"
5 # include "topology.hh"
6 # include "op.hh"
7 # include "accu.hh"
8 
9 
10 namespace mln
11 {
12 
13  // point2d
14 
15 
16  point2d immerse(const point2d& p)
17  {
18  if (! is_primary(p))
19  std::abort();
20  return point2d((p.row() + 1) * 4, (p.col() + 1) * 4);
21  }
22 
23 
24  point2d unimmerse(const point2d& p)
25  {
26  if (! is_primary(p))
27  std::abort();
28  return point2d(p.row() / 4 - 1, p.col() / 4 - 1);
29  }
30 
31 
32 
33  // step by step
34 
35 
36  void
37  immerse_primary_2_faces(F_type& F,
38  const I& f,
39  V_type b) // border value
40  {
41  p_iter p(F.domain());
42  for_all(p)
43  {
44  if (! is_primary(p))
45  continue;
46  point2d p_ = unimmerse(p);
47  if (f.domain().has(p_))
48  F(p) = f(p_);
49  else
50  F(p) = b;
51  }
52  }
53 
54 
55  template <typename A>
56  void
57  immerse_separating_2_faces(F_type& F, A a)
58  {
59  bool c25_vals[] = { 1, 1, 1, 1, 1,
60  1, 1, 1, 1, 1,
61  1, 1, 1, 1, 1,
62  1, 1, 1, 1, 1,
63  1, 1, 1, 1, 1 };
64  neighb2d c25 = make::neighb2d(c25_vals);
65 
66  p_iter p(F.domain());
67  for_all(p)
68  if (is_2_face(p) && ! is_primary(p))
69  {
70  a.reset();
71  n_iter n(c25, p);
72  for_all(n)
73  if (D.has(n) && is_primary(n))
74  a.take(F(n));
75  F(p) = a.result();
76  }
77  }
78 
79 
80  template <typename A>
81  void
82  immerse_0_and_1_faces(F_type& F, A a)
83  {
84  p_iter p(F.domain());
85 
86  // 1-faces
87  for_all(p)
88  if (is_1_face(p))
89  {
90  a.reset();
91  n_iter n(c4(), p);
92  for_all(n)
93  if (D.has(n) && is_2_face(n))
94  a.take(F(n));
95  F(p) = a.result();
96  }
97 
98  // 0-faces
99  for_all(p)
100  if (is_0_face(p))
101  {
102  a.reset();
103  n_iter n(c4(), p);
104  for_all(n)
105  if (D.has(n))
106  a.take(F(n));
107  F(p) = a.result();
108  }
109  }
110 
111 
112  // 0 1
113  //
114  // 0 X Y
115 
116  // immersion -->
117 
118  // 0 4 8 12
119  // + - + - + - + - + - + - + - +
120  // 0 | b | | b | | b | | b |
121  // + - + - + - + - + - + - + - +
122  // | | | | | | | |
123  // + - + - + - + - + - + - + - +
124  // 4 | b | | X | | Y | | b |
125  // + - + - + - + - + - + - + - +
126  // | | | | | | | |
127  // + - + - + - + - + - + - + - +
128  // 8 | b | | b | | b | | b |
129  // + - + - + - + - + - + - + - +
130 
131 
132 
133  F_type
134  immerse(const image2d<value::int_u8>& f)
135  {
136  box2d D = make::box2d(// p_min
137  -1, -1,
138  // p_max
139  4 * f.nrows() + 5,
140  4 * f.ncols() + 5);
141  F_type F(D);
142  data::fill(F, 0); // FIXME
143 
144  // primary 2-faces
145  range<unsignedh> b = border_median(f);
146  immerse_primary_2_faces(F, f, b);
147 
148  // separating 2-faces
149  immerse_separating_2_faces(F, accu_max_range());
150 
151  // 0-faces and 1-faces
152  immerse_0_and_1_faces(F, accu_span_range());
153 
154  return F;
155  }
156 
157 
158 
159  namespace alt
160  {
161 
162  /*
163  F_type
164  immerse(const image2d<value::int_u8>& f)
165  {
166  // add border to f
167  // f -> K1
168  // set values for 0- and 1-faces in K1
169  // K1 -> K2 (0- and 1- faces are now the "separating 2-faces"
170  // set values for 0- and 1-faces in K2
171  }
172  */
173 
174  } // mln::alt
175 
176 
177 } // mln
178 
179 
180 #endif // ndef INTERPOLATION_HH