Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory 00002 // (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 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 // Forward declaration 00100 template <typename V> 00101 struct histo3d_rgb; 00102 00103 } // end of namespace mln::accu::stat 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 } // end of namespace mln::accu::meta::stat 00121 00122 } // end of namespace mln::accu::meta 00123 00124 } // end of namespace mln::accu 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 } // end of namespace mln::trait 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 // comp keep a trace of the dimension of the theorical image. 00253 // mln_min(comp) --> 0 00254 // mln_max(comp) --> 2^(n-1) [127 for n=7][255 for n=8] ... 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 // Just convert a greyscale value (int_u8 like) to a position for an 00278 // iterator on the resulting image. 00279 // Take care to the constructor : Point(slice, row, column) 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 } // end of namespace mln::accu::stat 00341 00342 } // end of namespace mln::accu 00343 00344 } // end of namespace mln 00345 00346 #endif // ! MLN_ACCU_STAT_HISTO3D_RGB_HH