Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_ACCU_STAT_RANK_HIGH_QUANT_HH 00027 # define MLN_ACCU_STAT_RANK_HIGH_QUANT_HH 00028 00032 00033 # include <vector> 00034 # include <mln/accu/internal/base.hh> 00035 # include <mln/core/concept/meta_accumulator.hh> 00036 # include <mln/trait/value_.hh> 00037 # include <mln/util/pix.hh> 00038 00039 00040 namespace mln 00041 { 00042 00043 namespace accu 00044 { 00045 00046 namespace stat 00047 { 00048 00049 00051 00056 template <typename T> 00057 struct rank_high_quant : public mln::accu::internal::base< const T&, rank_high_quant<T> > 00058 { 00059 typedef T argument; 00060 00061 rank_high_quant(unsigned k, unsigned n); 00062 00065 void init(); 00066 void take_as_init_(const argument& t); 00067 void take(const argument& t); 00068 void take(const rank_high_quant<T>& other); 00069 void sort(); 00071 00073 const T& to_result() const; 00074 00077 bool is_valid() const; 00078 00079 protected: 00080 00081 std::vector<T> elts_; 00082 bool is_sorted_; 00083 unsigned k_; // 0 <= k_ < n 00084 unsigned n_; 00085 }; 00086 00087 00088 template <typename I> struct rank_high_quant< util::pix<I> >; 00089 00090 00091 } // end of mln::accu::stat 00092 00093 00094 namespace meta 00095 { 00096 00097 namespace stat 00098 { 00099 00101 00102 struct rank_high_quant : public Meta_Accumulator< rank_high_quant > 00103 { 00104 rank_high_quant(unsigned k_, unsigned n_) : k(k_), n(n_) {} 00105 00106 template <typename T> 00107 struct with 00108 { 00109 typedef accu::stat::rank_high_quant<T> ret; 00110 }; 00111 00112 unsigned k; 00113 unsigned n; 00114 }; 00115 00116 } // end of namespace mln::accu::meta::stat 00117 00118 } // end of namespace mln::accu::meta 00119 00120 00121 template <typename T> 00122 stat::rank_high_quant<T> unmeta(const meta::stat::rank_high_quant& m, T) 00123 { 00124 stat::rank_high_quant<T> a(m.k, m.n); 00125 return a; 00126 } 00127 00128 00129 namespace stat 00130 { 00131 00132 # ifndef MLN_INCLUDE_ONLY 00133 00134 template <typename T> 00135 inline 00136 rank_high_quant<T>::rank_high_quant(unsigned k, unsigned n) 00137 : k_(k), 00138 n_(n), 00139 is_sorted_(false) 00140 { 00141 mln_assertion(k_ < n_); 00142 init(); 00143 } 00144 00145 template <typename T> 00146 inline 00147 void 00148 rank_high_quant<T>::init() 00149 { 00150 elts_.clear(); 00151 } 00152 00153 template <typename T> 00154 inline 00155 void rank_high_quant<T>::take_as_init_(const argument& t) 00156 { 00157 elts_.push_back(t); 00158 is_sorted_ = false; 00159 } 00160 00161 template <typename T> 00162 inline 00163 void rank_high_quant<T>::take(const argument& t) 00164 { 00165 elts_.push_back(t); 00166 is_sorted_ = false; 00167 } 00168 00169 template <typename T> 00170 inline 00171 void 00172 rank_high_quant<T>::take(const rank_high_quant<T>& other) 00173 { 00174 elts_.insert(elts_.end(), 00175 other.elts_.begin(), 00176 other.elts_.end()); 00177 is_sorted_ = false; 00178 } 00179 00180 template <typename T> 00181 inline 00182 const T& 00183 rank_high_quant<T>::to_result() const 00184 { 00185 const_cast<rank_high_quant<T>&>(*this).sort(); 00186 00187 if (n_ == elts_.size()) 00188 return elts_[k_]; 00189 else 00190 // FIXME : This alternative is used to handle images edges. 00191 return elts_[(elts_.size() * k_) / n_]; 00192 } 00193 00194 template <typename T> 00195 inline 00196 bool 00197 rank_high_quant<T>::is_valid() const 00198 { 00199 return true; 00200 } 00201 00202 template <typename T> 00203 inline 00204 void 00205 rank_high_quant<T>::sort() 00206 { 00207 if (! is_sorted_) 00208 { 00209 is_sorted_ = true; 00210 std::sort(elts_.begin(), elts_.end()); 00211 } 00212 } 00213 00214 # endif // ! MLN_INCLUDE_ONLY 00215 00216 } // end of namespace mln::accu::stat 00217 00218 } // end of namespace mln::accu 00219 00220 } // end of namespace mln 00221 00222 // #include <mln/accu/stat/rank_bool.hh> ?? 00223 00224 #endif // ! MLN_ACCU_STAT_RANK_HIGH_QUANT_HH