$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/concept/neighborhood.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_CORE_CONCEPT_NEIGHBORHOOD_HH
28 # define MLN_CORE_CONCEPT_NEIGHBORHOOD_HH
29 
33 
34 # include <mln/core/concept/window.hh>
35 # include <mln/trait/windows.hh>
36 
37 
38 
39 # define mln_is_simple_neighborhood(N) mln_is_simple_window(mln_window(N))
40 
41 
42 
43 
44 namespace mln
45 {
46 
47 
48  // Forward declaration.
49  template <typename E> struct Neighborhood;
50 
53  template <>
54  struct Neighborhood<void>
55  {
57  };
59 
60 
66  template <typename E>
67  struct Neighborhood : public Object<E>
68  {
70 
71  /*
72  typedef niter;
73  typedef fwd_niter;
74  typedef bkd_niter;
75 
76  typedef window;
77  either
78  const window& win() const;
79  or
80  window win() const;
81  */
82 
83  protected:
84  Neighborhood();
85  };
86 
87 
89  template <typename L, typename R>
90  bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs);
91 
93  template <typename N>
94  std::ostream&
95  operator<<(std::ostream&ostr, const Neighborhood<N>& nbh);
96 
97 
98  // FIXME: Move as a method of Image?
100  template <typename I, typename N>
102  offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
103 
104  // FIXME: Move as a method of Image?
106  template <typename I, typename N>
108  positive_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
109 
110  // FIXME: Move as a method of Image?
112  template <typename I, typename N>
114  negative_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
115 
116 
117 
118 # ifndef MLN_INCLUDE_ONLY
119 
120  template <typename E>
121  inline
123  {
124  typedef mln_niter(E) niter;
125  typedef mln_fwd_niter(E) fwd_niter;
126  typedef mln_bkd_niter(E) bkd_niter;
127 
128  typedef mln_window(E) window;
129  bool m = (& E::win) == (& E::win);
130  (void) m;
131  bool (E::*m2)() const = &E::is_valid;
132  (void) m2;
133 
134 # if 0
135  /* FIXME: Disabled, as win() can either return a const reference
136  or a copy of the window (see documentation above). Hence the
137  simpler, relaxed check above (m0). */
138  const window& (E::*m1)() const = & E::win;
139  (void) m1;
140 # endif
141  }
142 
143 
144  template <typename L, typename R>
145  inline
146  bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs)
147  {
148  return exact(lhs).win() == exact(rhs).win();
149  }
150 
151  template <typename N>
152  inline
153  std::ostream&
154  operator<<(std::ostream&ostr, const Neighborhood<N>& nbh)
155  {
156  return ostr << exact(nbh).win();
157  }
158 
159  template <typename I, typename N>
160  inline
161  util::array<int>
162  offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
163  {
164  mln_is_simple_neighborhood(N)::check();
165 
166  const I& ima = exact(ima_);
167  const N& nbh = exact(nbh_);
168  mln_precondition(ima.is_valid());
169  mln_precondition(nbh.is_valid());
170 
171  return offsets_wrt(ima, nbh.win());
172  }
173 
174  template <typename I, typename N>
175  util::array<int>
176  positive_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
177  {
178  mln_is_simple_neighborhood(N)::check();
179 
180  const I& ima = exact(ima_);
181  const N& nbh = exact(nbh_);
182  mln_precondition(ima.is_valid());
183  mln_precondition(nbh.is_valid());
184 
185  return positive_offsets_wrt(ima, nbh.win());
186  }
187 
188  template <typename I, typename N>
189  util::array<int>
190  negative_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
191  {
192  mln_is_simple_neighborhood(N)::check();
193 
194  const I& ima = exact(ima_);
195  const N& nbh = exact(nbh_);
196  mln_precondition(ima.is_valid());
197  mln_precondition(nbh.is_valid());
198 
199  return negative_offsets_wrt(ima, nbh.win());
200  }
201 
202 # endif // ! MLN_INCLUDE_ONLY
203 
204 } // end of namespace mln
205 
206 
207 #endif // ! MLN_CORE_CONCEPT_NEIGHBORHOOD_HH