$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
win/inter.hh
1 // Copyright (C) 2007, 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_INTER_HH
27 # define MLN_WIN_INTER_HH
28 
32 
33 # include <mln/core/window.hh>
34 
35 
36 
37 namespace mln
38 {
39 
41  template <typename W1, typename W2>
42  mln_regular(W1)
43  operator && (const Window<W1>& win1, const Window<W2>& win2);
44 
45 
46 # ifndef MLN_INCLUDE_ONLY
47 
48  namespace win
49  {
50 
51  namespace impl
52  {
53 
54  template <typename W1, typename W2>
55  inline
56  mln_regular(W1)
57  inter(trait::window::definition::unique,
58  const W1& win1, const W2& win2)
59  {
60  mlc_is(mln_trait_window_size(W1),
61  trait::window::size::fixed)::check();
62  mlc_is(mln_trait_window_size(W2),
63  trait::window::size::fixed)::check();
64 
65  mln_regular(W1) tmp;
66  unsigned n = win1.size();
67  for (unsigned i = 0; i < n; ++i)
68  if (win2.has(win1.dp(i)))
69  tmp.insert(win1.dp(i));
70  return tmp;
71  }
72 
73  template <typename W1, typename W2>
74  inline
75  mln_regular(W1)
76  inter(trait::window::definition::multiple,
77  const W1& win1, const W2& win2)
78  {
79  mln_precondition(win1.nwindows() == win2.nwindows());
80  // FIXME: What about "win1.function() not equal win2.function()"!
81 
82  mln_regular(W1) tmp(win1.function());
83  const unsigned nw = win1.nwindows();
84  for (unsigned w = 0; w < nw; ++w)
85  tmp.set_window(w, win1.window(w) && win2.window(w));
86  return tmp;
87  }
88 
89  } // end of namespace mln::win::impl
90 
91  } // end of namespace mln::win
92 
93 
94  // Facade.
95  template <typename W1, typename W2>
96  inline
97  mln_regular(W1)
98  operator && (const Window<W1>& win1, const Window<W2>& win2)
99  {
100  mln_trace("win::inter");
101 
102  // Compatibility checks.
103  mlc_equal(mln_regular(W1), mln_regular(W2))::check();
104  mlc_converts_to(mln_dpsite(W1), mln_dpsite(W2))::check();
105 
106  // Support checks.
107  mlc_is(mln_trait_window_support(W1),
108  trait::window::support::regular)::check();
109  mlc_is(mln_trait_window_support(W2),
110  trait::window::support::regular)::check();
111 
112  // Definition checks.
113  mlc_equal(mln_trait_window_definition(W1),
114  mln_trait_window_definition(W2))::check();
115 
116  mlc_is_not(mln_trait_window_definition(W1),
117  trait::window::definition::varying)::check();
118 
119  mln_regular(W1) tmp = win::impl::inter(mln_trait_window_definition(W1)(),
120  exact(win1), exact(win2));
121 
122  return tmp;
123  }
124 
125 # endif // ! MLN_INCLUDE_ONLY
126 
127 } // end of namespace mln
128 
129 
130 #endif // ! MLN_WIN_INTER_HH