00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_ACCU_STAT_HISTO3D_RGB_HH
00028 # define MLN_ACCU_STAT_HISTO3D_RGB_HH
00029
00068
00069
00070 # include <iostream>
00071
00072 # include <mln/accu/internal/base.hh>
00073
00074 # include <mln/arith/plus.hh>
00075
00076 # include <mln/core/macros.hh>
00077 # include <mln/core/image/image3d.hh>
00078 # include <mln/core/alias/point3d.hh>
00079 # include <mln/core/alias/box3d.hh>
00080
00081 # include <mln/literal/zero.hh>
00082
00083 # include <mln/trace/entering.hh>
00084 # include <mln/trace/exiting.hh>
00085
00086 # include <mln/trait/value/comp.hh>
00087
00088 # include <mln/value/ops.hh>
00089
00090 namespace mln
00091 {
00092
00093 namespace accu
00094 {
00095
00096 namespace stat
00097 {
00098
00099
00100 template <typename V>
00101 struct histo3d_rgb;
00102
00103 }
00104
00105 namespace meta
00106 {
00107
00108 namespace stat
00109 {
00110
00111 struct histo3d_rgb : public Meta_Accumulator<histo3d_rgb>
00112 {
00113 template <typename V>
00114 struct with
00115 {
00116 typedef accu::stat::histo3d_rgb<V> ret;
00117 };
00118 };
00119
00120 }
00121
00122 }
00123
00124 }
00125
00126
00127 namespace trait
00128 {
00129
00130 template <typename V>
00131 struct accumulator_< mln::accu::stat::histo3d_rgb<V> >
00132 {
00133 typedef accumulator::has_untake::no has_untake;
00134 typedef accumulator::has_set_value::no has_set_value;
00135 typedef accumulator::has_stop::no has_stop;
00136 typedef accumulator::when_pix::use_v when_pix;
00137 };
00138
00139 template <typename V>
00140 struct set_precise_binary_<op::eq,
00141 accu::stat::histo3d_rgb<V>,
00142 accu::stat::histo3d_rgb<V> >
00143 {
00144 typedef bool ret;
00145 };
00146
00147 }
00148
00149 namespace accu
00150 {
00151
00152 namespace stat
00153 {
00154
00165
00166 template <typename V>
00167 struct histo3d_rgb :
00168 public mln::accu::internal::base<image3d<unsigned>, histo3d_rgb<V> >
00169 {
00170 typedef V argument;
00171 typedef image3d<unsigned> result;
00172 typedef result q_result;
00173
00180 histo3d_rgb();
00182
00183
00191 void init();
00192
00193
00199 void take(const argument& t);
00200
00201
00207 void take(const histo3d_rgb<V>& other);
00209
00216 result to_result() const;
00217 operator result () const;
00219
00224 bool is_valid() const;
00225
00226 protected:
00227 result count_;
00228 };
00229
00236 template <typename V>
00237 bool operator==(const histo3d_rgb<V>& histo1,
00238 const histo3d_rgb<V>& histo2);
00239
00240 # ifndef MLN_INCLUDE_ONLY
00241
00242 template <typename V>
00243 inline
00244 histo3d_rgb<V>::histo3d_rgb()
00245 {
00246 trace::entering("mln::accu::stat::histo3d_rgb::cstor");
00247
00248 typedef mln_trait_value_comp(V,0) comp0;
00249 typedef mln_trait_value_comp(V,1) comp1;
00250 typedef mln_trait_value_comp(V,2) comp2;
00251
00252
00253
00254
00255
00256 count_.init_(box3d(point3d(mln_min(comp0),
00257 mln_min(comp1),
00258 mln_min(comp2)),
00259 point3d(mln_max(comp0),
00260 mln_max(comp1),
00261 mln_max(comp2))));
00262
00263 trace::exiting("mln::accu::stat::histo3d_rgb::cstor");
00264 }
00265
00266 template <typename V>
00267 inline
00268 void histo3d_rgb<V>::init()
00269 {
00270 data::fill(count_, literal::zero);
00271 }
00272
00273 template <typename V>
00274 inline
00275 void histo3d_rgb<V>::take(const argument& t)
00276 {
00277
00278
00279
00280 ++count_(point3d(t.blue(), t.red(), t.green()));
00281 }
00282
00283
00284 template <typename V>
00285 inline
00286 void histo3d_rgb<V>::take(const histo3d_rgb<V>& other)
00287 {
00288 count_ += other.count_;
00289 }
00290
00291 template <typename V>
00292 inline
00293 typename histo3d_rgb<V>::result histo3d_rgb<V>::to_result() const
00294 {
00295 return count_;
00296 }
00297
00298 template <typename V>
00299 inline
00300 histo3d_rgb<V>::operator result() const
00301 {
00302 return count_;
00303 }
00304
00305 template <typename V>
00306 inline
00307 bool histo3d_rgb<V>::is_valid() const
00308 {
00309 bool result = count_.is_valid();
00310
00311 return result;
00312 }
00313
00314 template <typename V>
00315 bool operator==(const histo3d_rgb<V>& histo1,
00316 const histo3d_rgb<V>& histo2)
00317 {
00318 trace::entering("mln::accu::stat::histo3d_rgb::operator==");
00319
00320 bool result = true;
00321 const image3d<unsigned>& res1 = histo1.to_result();
00322 const image3d<unsigned>& res2 = histo2.to_result();
00323
00324 mln_precondition(res1.is_valid());
00325 mln_precondition(res2.is_valid());
00326
00327 mln_piter(image3d<unsigned>) p1(res1.domain());
00328 mln_piter(image3d<unsigned>) p2(res2.domain());
00329
00330 for_all_2(p1, p2)
00331 result &= (res1(p1) == res2(p2));
00332
00333 trace::exiting("mln::accu::stat::histo3d_rgb::operator==");
00334 return result;
00335 }
00336
00337 # endif // ! MLN_INCLUDE_ONLY
00338
00339
00340 }
00341
00342 }
00343
00344 }
00345
00346 #endif // ! MLN_ACCU_STAT_HISTO3D_RGB_HH