$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sharpness.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
2 // Laboratory (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_MORPHO_ATTRIBUTE_SHARPNESS_HH
28 # define MLN_MORPHO_ATTRIBUTE_SHARPNESS_HH
29 
34 
35 # include <mln/core/concept/accumulator.hh>
36 # include <mln/accu/internal/base.hh>
37 # include <mln/morpho/attribute/volume.hh>
38 # include <mln/morpho/attribute/height.hh>
39 
40 
41 namespace mln
42 {
43 
44  // Forward declaration.
45  namespace morpho {
46  namespace attribute {
47  template <typename I>
48  struct sharpness;
49  }
50  }
51 
52 
53  // Traits.
54 
55  namespace trait
56  {
57 
58  template <typename I>
59  struct accumulator_< morpho::attribute::sharpness<I> >
60  {
61  typedef accumulator::has_untake::no has_untake;
62  typedef accumulator::has_set_value::no has_set_value;
63  typedef accumulator::has_stop::no has_stop;
64  typedef accumulator::when_pix::use_v when_pix;
65  };
66 
67  } // end of namespace mln::trait
68 
69 
70  namespace morpho
71  {
72 
73  namespace attribute
74  {
75 
80  template <typename I>
81  struct sharpness
82  : public mln::accu::internal::base< double, sharpness<I> >
83  {
84  typedef mln_value(I) argument;
85 
86  sharpness();
87 
90  void init();
91 
92  void take(const mln_value(I)& v);
93  void take(const sharpness<I>& other);
94 
95  void take_as_init_(const mln_value(I)& v);
97 
99  double to_result() const;
100 
103  bool is_valid() const;
104 
106  unsigned area() const;
107 
109  unsigned height() const;
110 
112  unsigned volume() const;
113 
114  protected:
116  typename mln::morpho::attribute::height<I> height_;
118  typename mln::morpho::attribute::volume<I> volume_;
119  };
120 
121 
122 
123 # ifndef MLN_INCLUDE_ONLY
124 
125  template <typename I>
126  inline
128  {
129  init();
130  }
131 
132  template <typename I>
133  inline
134  void
136  {
137  volume_.init();
138  }
139 
140  template <typename I>
141  inline
142  void
143  sharpness<I>::take(const mln_value(I)& v)
144  {
145  if (! is_valid())
146  {
147  take_as_init_(v);
148  return;
149  }
150  volume_.take(v);
151  height_.take(v);
152  }
153 
154  template <typename I>
155  inline
156  void
157  sharpness<I>::take(const sharpness<I>& other)
158  {
159  mln_invariant(is_valid());
160  volume_.take(other.volume_);
161  height_.take(other.height_);
162  }
163 
164  template <typename I>
165  inline
166  void
167  sharpness<I>::take_as_init_(const mln_value(I)& v)
168  {
169  volume_.take_as_init_(v);
170  height_.take_as_init_(v);
171  }
172 
173  template <typename I>
174  inline
175  double
177  {
178  double d = 0;
179  if (height_.to_result() != 0)
180  {
181  d = (double) volume_.to_result() /
182  (double)((volume_.area() - 1) * (height_.to_result() + 1) + 1);
183  }
184  mln_postcondition(d >= 0 && d <= 1);
185  return d;
186  }
187 
188  template <typename I>
189  inline
190  unsigned
191  sharpness<I>::area() const
192  {
193  return volume_.area();
194  }
195 
196  template <typename I>
197  inline
198  unsigned
199  sharpness<I>::volume() const
200  {
201  return volume_.to_result();
202  }
203 
204  template <typename I>
205  inline
206  unsigned
207  sharpness<I>::height() const
208  {
209  return height_.to_result();
210  }
211 
212  template <typename I>
213  inline
214  bool
215  sharpness<I>::is_valid() const
216  {
217  return volume_.is_valid() && height_.is_valid();
218  }
219 
220 # endif // ! MLN_INCLUDE_ONLY
221 
222  } // end of namespace mln::morpho::attribute
223 
224  } // end of namespace mln::morpho
225 
226 } // end of namespace mln
227 
228 
229 #endif // ! MLN_MORPHO_ATTRIBUTE_SHARPNESS_HH