$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
max_site.hh
1 // Copyright (C) 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_ACCU_MAX_SITE_HH
27 # define MLN_ACCU_MAX_SITE_HH
28 
35 
36 # include <mln/core/concept/meta_accumulator.hh>
37 # include <mln/accu/internal/base.hh>
38 # include <mln/util/pix.hh>
39 
40 namespace mln
41 {
42 
43  namespace accu
44  {
45 
46 
51  //
52  template <typename I>
53  struct max_site : public mln::accu::internal::base< mln_psite(I), max_site<I> >
54  {
56  typedef mln_psite(I) result;
57 
58  max_site();
59 
62  void init();
63  void take(const argument& t);
64  void take(const max_site<I>& other);
66 
68  mln_psite(I) to_result() const;
69  operator mln_psite(I) () const;
70 
72  mln_value(I) value_() const;
73 
76  bool is_valid() const;
77 
78  protected:
79  bool is_valid_;
80  mln_psite(I) max_p_;
81  mln_value(I) max_v_;
82  };
83 
84 
85 
86  namespace meta
87  {
88 
90  struct max_site : public Meta_Accumulator< max_site >
91  {
92  template <typename I>
93  struct with
94  {
96  };
97  };
98 
99  } // end of namespace mln::accu::meta
100 
101 
102 # ifndef MLN_INCLUDE_ONLY
103 
104  template <typename I>
105  inline
107  {
108  init();
109  }
110 
111  template <typename I>
112  inline
113  void
115  {
116  is_valid_ = false;
117  max_v_ = mln_min(mln_value(I));
118  }
119 
120  template <typename I>
121  inline
122  void max_site<I>::take(const argument& t)
123  {
124  if (t.v() > max_v_)
125  {
126  max_v_ = t.v();
127  max_p_ = t.p();
128  is_valid_ = true;
129  }
130  }
131 
132  template <typename I>
133  inline
134  void
135  max_site<I>::take(const max_site<I>& other)
136  {
137  mln_precondition(other.is_valid());
138 
139  if (other.value_() > max_v_)
140  {
141  max_v_ = other.value_();
142  max_p_ = other.to_result();
143  is_valid_ = true;
144  }
145  }
146 
147  template <typename I>
148  inline
149  mln_psite(I)
150  max_site<I>::to_result() const
151  {
152  mln_precondition(is_valid());
153  return max_p_;
154  }
155 
156  template <typename I>
157  inline
158  max_site<I>::operator mln_psite(I)() const
159  {
160  return to_result();
161  }
162 
163  template <typename I>
164  inline
165  mln_value(I)
166  max_site<I>::value_() const
167  {
168  return max_v_;
169  }
170 
171  template <typename I>
172  inline
173  bool
174  max_site<I>::is_valid() const
175  {
176  return is_valid_;
177  }
178 
179 # endif // ! MLN_INCLUDE_ONLY
180 
181  } // end of namespace mln::accu
182 
183 } // end of namespace mln
184 
185 
186 #endif // ! MLN_ACCU_MAX_SITE_HH