$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
win/diff.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_WIN_DIFF_HH
27 # define MLN_WIN_DIFF_HH
28 
32 
33 # include <mln/trait/op/minus.hh>
34 # include <mln/core/window.hh>
35 # include <mln/core/neighb.hh>
36 
37 
38 
39 namespace mln
40 {
41 
42  namespace win
43  {
44 
47  //
48  template <typename W1, typename W2>
49  mln_regular(W1)
50  diff(const Window<W1>& win1, const Window<W2>& win2);
51 
52 
55  //
56  template <typename N1, typename N2>
57  neighb<mln_deduce(N1, window, regular)>
58  diff(const Neighborhood<N1>& nbh1, const Neighborhood<N2>& nbh2);
59 
60  } // end of namespace mln::win
61 
62 
66  //
67  template <typename W1, typename W2>
68  mln_regular(W1)
69  operator-(const Window<W1>& win1, const Window<W2>& win2);
70 
73  //
74  template <typename N1, typename N2>
75  neighb<mln_deduce(N1, window, regular)>
76  operator-(const Neighborhood<N1>& nbh1, const Neighborhood<N2>& nbh2);
77 
78 
79  namespace trait
80  {
81 
82  template <typename W1, typename W2>
83  struct set_binary_< op::minus, mln::Window, W1, mln::Window, W2 >
84  {
85  typedef mln_regular(W1) ret;
86  };
87 
88 
89  template <typename N1, typename N2>
90  struct set_binary_< op::minus, mln::Neighborhood, N1, mln::Neighborhood, N2 >
91  {
93  };
94 
95  } // end of namespace mln::trait
96 
97 
98 
99 # ifndef MLN_INCLUDE_ONLY
100 
101  namespace win
102  {
103 
104  template <typename W1, typename W2>
105  inline
106  mln_regular(W1)
107  diff(const Window<W1>& win1_, const Window<W2>& win2_)
108  {
109  mln_trace("win::diff");
110 
111  mln_is_simple_window(W1)::check();
112  mln_is_simple_window(W2)::check();
113 
114  const W1& win1 = exact(win1_);
115  const W2& win2 = exact(win2_);
116  mln_regular(W1) tmp;
117 
118  const unsigned n = win1.size();
119  for (unsigned i = 0; i < n; ++i)
120  {
121  if (win2.has(win1.dp(i)))
122  continue;
123  tmp.insert(win1.dp(i));
124  }
125 
126  return tmp;
127  }
128 
129  template <typename N1, typename N2>
130  neighb<mln_deduce(N1, window, regular)>
131  diff(const Neighborhood<N1>& nbh1, const Neighborhood<N2>& nbh2)
132  {
133  typedef mln_deduce(N1, window, regular) W1;
134  W1 win = diff(exact(nbh1).win(), exact(nbh2).win());
135  neighb<W1> tmp(win);
136  return tmp;
137  }
138 
139  } // end of namespace mln::win
140 
141 
142  // Operators.
143 
144  template <typename W1, typename W2>
145  inline
146  mln_regular(W1)
147  operator-(const Window<W1>& win1, const Window<W2>& win2)
148  {
149  return win::diff(win1, win2);
150  }
151 
152  template <typename N1, typename N2>
153  neighb<mln_deduce(N1, window, regular)>
154  operator-(const Neighborhood<N1>& nbh1, const Neighborhood<N2>& nbh2)
155  {
156  return win::diff(nbh1, nbh2);
157  }
158 
159 # endif // ! MLN_INCLUDE_ONLY
160 
161 } // end of namespace mln
162 
163 
164 #endif // ! MLN_WIN_DIFF_HH