$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
is_masked_impl_selector.hh
1 // Copyright (C) 2009, 2011, 2012 EPITA Research and Development
2 // 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_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
28 # define MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH
29 
33 
34 # include <mln/util/edge.hh>
35 
36 
37 namespace mln
38 {
39 
40  // Forward declarations.
41  template <typename G, typename F> class p_edges;
42  template <typename G, typename F> class p_vertices;
43 
44 
45 
46  namespace internal
47  {
48 
54  template <typename S, typename D, typename E>
56  {
58  bool is_masked(const mln_graph_element(S)& center,
59  const mln_graph_element(S)& element) const;
60  };
61 
66  template <typename G1, typename F1, typename G2, typename F2, typename E>
67  struct is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
68  {
70 
72  bool is_masked(const mln_graph_element(S)& center,
73  const mln_graph_element(S)& element) const;
74  };
75 
80  template <typename G1, typename F1, typename G2, typename F2, typename E>
81  struct is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
82  {
83  typedef p_edges<G1,F1> S;
84 
86  bool is_masked(const mln_graph_element(S)& center,
87  const mln_graph_element(S)& element) const;
88  };
89 
90 
91 # ifndef MLN_INCLUDE_ONLY
92 
93 
94  template <typename S, typename I, typename E>
95  inline
96  bool
97  is_masked_impl_selector<S,I,E>::is_masked(const mln_graph_element(S)& center,
98  const mln_graph_element(S)& element) const
99  {
100  (void) center;
101  E& iter = internal::force_exact<E>(*this);
102  return ! iter.target_()->mask()(element.id());
103  }
104 
105 
106  template <typename G1, typename F1, typename G2, typename F2, typename E>
107  inline
108  bool
109  is_masked_impl_selector< p_vertices<G1,F1>, p_edges<G2,F2>, E >
110  ::is_masked(const mln_graph_element(S)& center,
111  const mln_graph_element(S)& element) const
112  {
113  E& iter = internal::force_exact<E>(*this);
114 
115  util::edge<G1> e = center.edge_with(element);
116  mln_postcondition(e.is_valid());
117 
118  return ! iter.target_()->mask()(e.id());
119  }
120 
121 
128  template <typename G1, typename F1, typename G2, typename F2, typename E>
129  inline
130  bool
131  is_masked_impl_selector< p_edges<G1,F1>, p_vertices<G2,F2>, E >
132  ::is_masked(const mln_graph_element(S)& center,
133  const mln_graph_element(S)& element) const
134  {
135  E& iter = internal::force_exact<E>(*this);
136 
137  if (center.v1() == element.v2() || center.v2() == element.v2())
138  return ! iter.target_()->mask()(element.v1());
139 
140  //else if (center.v2() == element.v1() || center.v1() == element.v1())
141  return ! iter.target_()->mask()(element.v2());
142  }
143 
144 # endif // ! MLN_INCLUDE_ONLY
145 
146  } // end of namespace mln::internal
147 
148 } // end of namespace mln
149 
150 
151 #endif // ! MLN_CORE_INTERNAL_IS_MASKED_IMPL_SELECTOR_HH