Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
neighborhood_base.hh
1 // Copyright (C) 2008, 2009 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 
26 #ifndef MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH
27 # define MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH
28 
35 
36 # include <mln/core/concept/neighborhood.hh>
37 # include <mln/core/concept/window.hh>
38 
39 
40 namespace mln
41 {
42 
43 
44  // Forward declaration.
45  namespace win
46  {
47  template <unsigned n, typename W, typename F>
48  class multiple_size;
49  }
50 
51 
52  namespace internal
53  {
54 
55  template <typename W, typename E>
56  struct neighborhood_extra_impl
57  : public Neighborhood<E>
58  {
59  };
60 
61  template <typename W, typename F, typename E>
62  struct neighborhood_extra_impl< win::multiple_size<2,W,F>, E >
63  : public Neighborhood<E>
64  {
65 
69 
70  neighb<W> foreground() const
71  {
72  W win = internal::force_exact<E>(*this).win().window_(1); // True, so object.
73  neighb<W> nbh(win);
74  return nbh;
75  }
76 
80 
81  neighb<W> background() const
82  {
83  W win = internal::force_exact<E>(*this).win().window_(0); // False, so background.
84  neighb<W> nbh(win);
85  return nbh;
86  }
87 
88  };
89 
90 
91 
92 
93  template <typename W, typename E>
94  struct neighborhood_impl : public neighborhood_extra_impl<W,E>
95  {
96  // Optional methods...
97 
100  unsigned size() const;
101 
104  unsigned delta() const;
105 
108  const mln_dpsite(W)& dp(unsigned i) const;
109 
110  // end of Optional methods.
111  };
112 
113 
117 
118  template <typename W, typename E>
119  struct neighborhood_base : public neighborhood_impl<W,E>
120  {
122  typedef W window;
123 
125  typedef mln_dpsite(W) dpsite;
126 
128  typedef mln_psite(W) psite;
129 
131  typedef mln_site(W) site;
132 
134  bool is_valid() const;
135 
136  protected:
137  neighborhood_base();
138  };
139 
140 
141 
142 
143 # ifndef MLN_INCLUDE_ONLY
144 
145 
146  // neighborhood_base
147 
148  template <typename W, typename E>
149  inline
150  neighborhood_base<W,E>::neighborhood_base()
151  {
152  }
153 
154  template <typename W, typename E>
155  inline
156  bool
157  neighborhood_base<W,E>::is_valid() const
158  {
159  return true;
160  }
161 
162  // neighborhood_impl
163 
164  template <typename W, typename E>
165  inline
166  unsigned
167  neighborhood_impl<W,E>::size() const
168  {
169  mlc_is(mln_trait_window_size(W),
170  trait::window::size::fixed)::check();
171  return exact(this)->win().size();
172  }
173 
174  template <typename W, typename E>
175  inline
176  unsigned
177  neighborhood_impl<W,E>::delta() const
178  {
179  mlc_is(mln_trait_window_support(W),
180  trait::window::support::regular)::check();
181  mlc_is_not(mln_trait_window_definition(W),
182  trait::window::definition::varying)::check();
183  return exact(this)->win().delta();
184  }
185 
186  template <typename W, typename E>
187  inline
188  const mln_dpsite(W)&
189  neighborhood_impl<W,E>::dp(unsigned i) const
190  {
191  mlc_is(mln_trait_window_support(W),
192  trait::window::support::regular)::check();
193  mlc_is(mln_trait_window_definition(W),
194  trait::window::definition::unique)::check();
195  return exact(this)->win().dp(i);
196  }
197 
198 # endif // ! MLN_INCLUDE_ONLY
199 
200  } // end of namespace mln::internal
201 
202 } // end of namespace mln
203 
204 
205 #endif // ! MLN_CORE_INTERNAL_NEIGHBORHOOD_BASE_HH