Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
morpho/min.hh
1 // Copyright (C) 2007, 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_MORPHO_MIN_HH
27 # define MLN_MORPHO_MIN_HH
28 
36 # include <mln/data/compare.hh>
37 # include <mln/logical/and.hh>
38 # include <mln/arith/min.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace morpho
45  {
46 
50  template <typename I, typename J>
51  mln_concrete(I)
52  min(const Image<I>& lhs, const Image<J>& rhs);
53 
54 
59  template <typename I, typename J>
60  void min_inplace(Image<I>& lhs, const Image<J>& rhs);
61 
62 
63 # ifndef MLN_INCLUDE_ONLY
64 
65  namespace impl
66  {
67 
68  // Binary => morphology on sets.
69 
70  template <typename I, typename J, typename O>
71  inline
72  mln_concrete(I) min_(trait::image::kind::logic,
73  const I& lhs, const J& rhs)
74  {
75  return logical::and_(lhs, rhs);
76  }
77 
78  template <typename I, typename J>
79  inline
80  void min_inplace_(trait::image::kind::logic,
81  I& lhs, const J& rhs)
82  {
83  logical::and_inplace(lhs, rhs);
84  }
85 
86  // Otherwise => morphology on functions.
87 
88  template <typename I, typename J>
89  inline
90  mln_concrete(I) min_(trait::image::kind::any,
91  const I& lhs, const J& rhs)
92  {
93  return arith::min(lhs, rhs);
94  }
95 
96  template <typename I, typename J>
97  inline
98  void min_inplace_(trait::image::kind::any,
99  I& lhs, const J& rhs)
100  {
101  arith::min_inplace(lhs, rhs);
102  }
103 
104  } // end of namespace mln::morpho::impl
105 
106 
107  // Facades.
108 
109  template <typename I, typename J>
110  inline
111  mln_concrete(I)
112  min(const Image<I>& lhs, const Image<J>& rhs)
113  {
114  trace::entering("morpho::min");
115  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
116 
117  mln_concrete(I) output = impl::min_(mln_trait_image_kind(I)(), exact(lhs), exact(rhs));
118 
119  trace::exiting("morpho::min");
120  return output;
121  }
122 
123  template <typename I, typename J>
124  inline
125  void min_inplace(Image<I>& lhs, const Image<J>& rhs)
126  {
127  trace::entering("morpho::min_inplace");
128  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
129 
130  impl::min_inplace_(mln_trait_image_kind(I)(), exact(lhs), exact(rhs));
131 
132  trace::exiting("morpho::min_inplace_");
133  }
134 
135 # endif // ! MLN_INCLUDE_ONLY
136 
137  } // end of namespace mln::morpho
138 
139 } // end of namespace mln
140 
141 
142 #endif // ! MLN_MORPHO_MIN_HH