$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/shape/height.hh
1 // Copyright (C) 2007, 2008, 2009 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_ACCU_SHAPE_HEIGHT_HH
28 # define MLN_ACCU_SHAPE_HEIGHT_HH
29 
34 /*
35 This accumulator uses an mln::util::pix (pixel) to update the
36 height information of the component.
37 
38 The class mln/accu/height is not a general-purpose accumulator;
39 it is used to implement height-based connected filters.
40 \see mln::morpho::closing::height
41 \see mln::morpho::opening::height
42 */
43 
44 # include <mln/accu/internal/base.hh>
45 # include <mln/core/concept/meta_accumulator.hh>
46 
47 # include <mln/util/pix.hh>
48 # include <mln/math/min.hh>
49 # include <mln/math/max.hh>
50 
51 namespace mln
52 {
53 
54  namespace accu
55  {
56 
57  namespace shape
58  {
59 
66  //
67  template <typename I>
68  struct height
69  : public mln::accu::internal::base< unsigned , height<I> >
70  {
80  typedef typename argument::value value;
81 
82  height();
83 
86  void init();
87  void take(const argument&);
88  void take(const height<I>& other);
89 
91  void set_value(unsigned h);
93 
95  unsigned to_result() const;
96 
99  bool is_valid() const;
100 
101  protected:
107  unsigned height_;
108  };
109 
110 
111  } // end of mln::accu::shape
112 
113 
114  namespace meta
115  {
116 
117  namespace shape
118  {
119 
121  struct height : public Meta_Accumulator< height >
122  {
123  template <typename I>
124  struct with
125  {
127  };
128  };
129 
130  } // end of namespace mln::accu::meta::shape
131 
132  } // end of namespace mln::accu::meta
133 
134 
135 # ifndef MLN_INCLUDE_ONLY
136 
137  namespace shape
138  {
139 
140  template <typename I>
141  inline
143  {
144  init();
145  }
146 
147  template <typename I>
148  inline
149  void
151  {
152  min_level__ = mln_max(value);
153  max_level__ = mln_min(value);
154  height_ = 0;
155  }
156 
157  template <typename I>
158  inline
159  void
160  height<I>::take(const argument& t)
161  {
162  min_level__ = mln::math::min(min_level__, t.v());
163  max_level__ = mln::math::max(max_level__, t.v());
164  height_ = max_level__ - min_level__;
165  }
166 
167  template <typename I>
168  inline
169  void
170  height<I>::take(const height<I>& other)
171  {
172  min_level__ = mln::math::min(min_level__, other.min_level__);
173  max_level__ = mln::math::max(max_level__, other.max_level__);
174  height_ = max_level__ - min_level__;
175  }
176 
177  template <typename I>
178  inline
179  unsigned
180  height<I>::to_result() const
181  {
182  return height_;
183  }
184 
185  template <typename I>
186  inline
187  void
188  height<I>::set_value(unsigned h)
189  {
190  height_ = h;
191  // Reset the other members.
192  min_level__ = mln_max(value);
193  max_level__ = mln_min(value);
194  }
195 
196  template <typename I>
197  inline
198  bool
199  height<I>::is_valid() const
200  {
201  return true;
202  }
203 
204  } // end of namespace mln::accu::shape
205 
206 # endif // ! MLN_INCLUDE_ONLY
207 
208  } // end of namespace mln::accu
209 
210 } // end of namespace mln
211 
212 
213 #endif // ! MLN_ACCU_SHAPE_HEIGHT_HH