$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
histo3d_rgb.hh
1 // Copyright (C) 2009, 2010, 2013 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_ACCU_STAT_HISTO3D_RGB_HH
28 # define MLN_ACCU_STAT_HISTO3D_RGB_HH
29 
68 
69 
70 # include <iostream>
71 
72 # include <mln/accu/internal/base.hh>
73 
74 # include <mln/arith/plus.hh>
75 
76 # include <mln/core/macros.hh>
77 # include <mln/core/image/image3d.hh>
78 # include <mln/core/alias/point3d.hh>
79 # include <mln/core/alias/box3d.hh>
80 
81 # include <mln/literal/zero.hh>
82 
83 # include <mln/debug/trace.hh>
84 
85 # include <mln/trait/value/comp.hh>
86 
87 # include <mln/value/ops.hh>
88 
89 namespace mln
90 {
91 
92  namespace accu
93  {
94 
95  namespace stat
96  {
97 
98  // Forward declaration
99  template <typename V>
100  struct histo3d_rgb;
101 
102  } // end of namespace mln::accu::stat
103 
104  namespace meta
105  {
106 
107  namespace stat
108  {
109 
110  struct histo3d_rgb : public Meta_Accumulator<histo3d_rgb>
111  {
112  template <typename V>
113  struct with
114  {
116  };
117  };
118 
119  } // end of namespace mln::accu::meta::stat
120 
121  } // end of namespace mln::accu::meta
122 
123  } // end of namespace mln::accu
124 
125 
126  namespace trait
127  {
128 
129  template <typename V>
130  struct accumulator_< mln::accu::stat::histo3d_rgb<V> >
131  {
132  typedef accumulator::has_untake::no has_untake;
133  typedef accumulator::has_set_value::no has_set_value;
134  typedef accumulator::has_stop::no has_stop;
135  typedef accumulator::when_pix::use_v when_pix;
136  };
137 
138  template <typename V>
139  struct set_precise_binary_<op::eq,
140  accu::stat::histo3d_rgb<V>,
141  accu::stat::histo3d_rgb<V> >
142  {
143  typedef bool ret;
144  };
145 
146  } // end of namespace mln::trait
147 
148  namespace accu
149  {
150 
151  namespace stat
152  {
153 
164 
165  template <typename V>
166  struct histo3d_rgb :
167  public mln::accu::internal::base<image3d<unsigned>, histo3d_rgb<V> >
168  {
169  typedef V argument;
171  typedef result q_result;
172 
179  histo3d_rgb();
181 
182 
190  void init();
191 
192 
198  void take(const argument& t);
199 
200 
206  void take(const histo3d_rgb<V>& other);
208 
215  result to_result() const;
216  operator result () const;
218 
223  bool is_valid() const;
224 
225  protected:
227  };
228 
235  template <typename V>
236  bool operator==(const histo3d_rgb<V>& histo1,
237  const histo3d_rgb<V>& histo2);
238 
239 # ifndef MLN_INCLUDE_ONLY
240 
241  template <typename V>
242  inline
244  {
245  mln_trace("mln::accu::stat::histo3d_rgb::cstor");
246 
247  typedef mln_trait_value_comp(V,0) comp0;
248  typedef mln_trait_value_comp(V,1) comp1;
249  typedef mln_trait_value_comp(V,2) comp2;
250 
251  // comp keep a trace of the dimension of the theorical image.
252  // mln_min(comp) --> 0
253  // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ...
254 
255  count_.init_(box3d(point3d(mln_min(comp0),
256  mln_min(comp1),
257  mln_min(comp2)),
258  point3d(mln_max(comp0),
259  mln_max(comp1),
260  mln_max(comp2))));
261 
262  }
263 
264  template <typename V>
265  inline
266  void histo3d_rgb<V>::init()
267  {
268  data::fill(count_, literal::zero);
269  }
270 
271  template <typename V>
272  inline
273  void histo3d_rgb<V>::take(const argument& t)
274  {
275  // Just convert a greyscale value (int_u8 like) to a position for an
276  // iterator on the resulting image.
277  // Take care to the constructor : Point(slice, row, column)
278  ++count_(point3d(t.blue(), t.red(), t.green()));
279  }
280 
281 
282  template <typename V>
283  inline
284  void histo3d_rgb<V>::take(const histo3d_rgb<V>& other)
285  {
286  count_ += other.count_;
287  }
288 
289  template <typename V>
290  inline
291  typename histo3d_rgb<V>::result histo3d_rgb<V>::to_result() const
292  {
293  return count_;
294  }
295 
296  template <typename V>
297  inline
298  histo3d_rgb<V>::operator result() const
299  {
300  return count_;
301  }
302 
303  template <typename V>
304  inline
305  bool histo3d_rgb<V>::is_valid() const
306  {
307  bool result = count_.is_valid();
308 
309  return result;
310  }
311 
312  template <typename V>
313  bool operator==(const histo3d_rgb<V>& histo1,
314  const histo3d_rgb<V>& histo2)
315  {
316  mln_trace("mln::accu::stat::histo3d_rgb::operator==");
317 
318  bool result = true;
319  const image3d<unsigned>& res1 = histo1.to_result();
320  const image3d<unsigned>& res2 = histo2.to_result();
321 
322  mln_precondition(res1.is_valid());
323  mln_precondition(res2.is_valid());
324 
325  mln_piter(image3d<unsigned>) p1(res1.domain());
326  mln_piter(image3d<unsigned>) p2(res2.domain());
327 
328  for_all_2(p1, p2)
329  result &= (res1(p1) == res2(p2));
330 
331  return result;
332  }
333 
334 # endif // ! MLN_INCLUDE_ONLY
335 
336 
337  } // end of namespace mln::accu::stat
338 
339  } // end of namespace mln::accu
340 
341 } // end of namespace mln
342 
343 #endif // ! MLN_ACCU_STAT_HISTO3D_RGB_HH