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