Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
graph_elt_window_if.hh
1 // Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
2 // (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_IMAGE_GRAPH_ELT_WINDOW_IF_HH
28 # define MLN_CORE_IMAGE_GRAPH_ELT_WINDOW_IF_HH
29 
35 
36 # include <mln/core/concept/window.hh>
37 # include <mln/core/internal/neighborhood_base.hh>
38 # include <mln/core/internal/graph_window_base.hh>
39 # include <mln/core/internal/is_masked_impl_selector.hh>
40 # include <mln/core/image/graph_window_if_piter.hh>
41 
42 
43 namespace mln
44 {
45 
47  template <typename G, typename S, typename I> class graph_elt_window_if;
48  template <typename G, typename F> class p_edges;
49  template <typename G, typename F> class p_vertices;
50 
51 
52  namespace internal
53  {
54 
55  template <typename G, typename S, typename I, typename E>
56  struct neighborhood_impl<graph_elt_window_if<G,S,I>,E>
57  : public neighborhood_extra_impl<graph_elt_window_if<G,S,I>,E>
58  {
59  };
60 
61 
64  template <typename G, typename S>
66 
67  template <typename G, typename F>
68  struct graph_window_if_iter_dispatch<G, p_edges<G,F> >
69  {
70  typedef mln_edge_nbh_edge_fwd_iter(G) nbh_fwd_iter_;
71  typedef mln_edge_nbh_edge_bkd_iter(G) nbh_bkd_iter_;
72  };
73 
74  template <typename G, typename F>
75  struct graph_window_if_iter_dispatch<G, p_vertices<G,F> >
76  {
77  typedef mln_vertex_nbh_vertex_fwd_iter(G) nbh_fwd_iter_;
78  typedef mln_vertex_nbh_vertex_bkd_iter(G) nbh_bkd_iter_;
79  };
80 
81 
82  } // end of namespace mln::internal
83 
84 
85  namespace trait
86  {
87 
88  template <typename G, typename S, typename I>
89  struct window_< mln::graph_elt_window_if<G,S,I> >
90  {
91  typedef trait::window::size::unknown size;
92  typedef trait::window::support::irregular support;
93  typedef trait::window::definition::varying definition;
94  };
95 
96  } // end of namespace mln::trait
97 
98 
105  template <typename G, typename S, typename I>
107  : public graph_window_base<mln_result(S::fun_t),
108  graph_elt_window_if<G,S,I> >,
109  public internal::graph_window_if_iter_dispatch<G,S>,
110  private mlc_is(mln_value(I), bool)::check_t
111  {
113  typedef internal::graph_window_if_iter_dispatch<G,S> super_;
114 
115  typedef typename super_::nbh_fwd_iter_ nbh_fwd_iter_;
116  typedef typename super_::nbh_bkd_iter_ nbh_bkd_iter_;
117 
118  public:
120  typedef I mask_t;
121 
126 
130  graph_elt_window_if(const Image<I>& mask);
132 
135 
137  typedef S target;
138 
140  typedef mln_psite(target) psite;
141 
144  typedef graph_window_if_piter<target,self_,nbh_fwd_iter_> fwd_qiter;
145 
148  typedef graph_window_if_piter<target,self_,nbh_bkd_iter_> bkd_qiter;
149 
151  typedef fwd_qiter qiter;
153 
155  const I& mask() const;
156 
158  void change_mask(const Image<I>& mask);
159 
161  bool is_valid() const;
162 
163  private:
164  // FIXME: Should be const!
165  I mask_;
166  };
167 
168 
169 
170 # ifndef MLN_INCLUDE_ONLY
171 
172 
173  template <typename G, typename S, typename I>
174  inline
176  {
177  }
178 
179 
180  template <typename G, typename S, typename I>
181  inline
183  : mask_(exact(mask))
184  {
185  }
186 
187 
188  template <typename G, typename S, typename I>
189  inline
190  const I&
192  {
193  return mask_;
194  }
195 
196 
197  template <typename G, typename S, typename I>
198  inline
199  void
201  {
202  mln_precondition(exact(mask).is_valid());
203  mask_ = exact(mask);
204  }
205 
206  template <typename G, typename S, typename I>
207  inline
208  bool
210  {
211  return mask_.is_valid();
212  }
213 
214 
215 # endif // ! MLN_INCLUDE_ONLY
216 
217 
218 } // end of namespace mln
219 
220 
221 #endif // ! MLN_CORE_IMAGE_GRAPH_ELT_WINDOW_IF_HH