last update 20 Sep 2009 |
#include <cvrQuickMedian.h>
Classes | |
class | parameters |
The parameters for the class quickMedian. More... | |
Public Member Functions | |
quickMedian () | |
quickMedian (const parameters ¶m) | |
quickMedian (const eMedianEvenCase medianEvenCase) | |
quickMedian (const quickMedian &other) | |
virtual | ~quickMedian () |
const std::string & | name () const |
template<typename T > | |
bool | apply (matrix< T > &src, T &median) const |
template<typename T > | |
bool | apply (const matrix< T > &src, T &median) const |
template<typename T > | |
bool | apply (const matrix< T > &src, matrix< T > &dest, T &median) const |
template<class V > | |
bool | apply (V &srcdest, typename V::value_type &median) const |
template<class V > | |
bool | apply (const V &src, typename V::value_type &median) const |
template<class V > | |
bool | apply (const V &src, V &dest, typename V::value_type &median) const |
template<class V > | |
V::value_type | median (const V &src) const |
quickMedian & | copy (const quickMedian &other) |
virtual quickMedian * | clone () const |
virtual quickMedian * | newInstance () const |
const parameters & | getParameters () const |
Protected Member Functions | |
template<class V > | |
V::value_type | findMedian (V &vct, const int begin, const int end, const int medianPos) const |
template<class V > | |
int | partition (V &vct, const int begin, const int end) const |
This class is used to extract the median of the elements of a given vector or matrix. The median is defined as the element at the middle position of the sorted vector. The algorithm used is based on the quick sort. For vectors (or matrices) with an even number n of elements, the median will be the element at (n/2) or (n/2)-1 depending on the parameter settings.
On-place applies are in this implementation faster than on copy ones.
The type of the vector elements (T) must accept the operators < and >.
cvr::quickMedian::quickMedian | ( | ) |
Default constructor.
cvr::quickMedian::quickMedian | ( | const parameters & | param | ) |
Constructor to set parameters.
cvr::quickMedian::quickMedian | ( | const eMedianEvenCase | medianEvenCase | ) |
Constructor with indicator what to do for even-sized vectors.
cvr::quickMedian::quickMedian | ( | const quickMedian & | other | ) |
virtual cvr::quickMedian::~quickMedian | ( | ) | [virtual] |
destructor
bool cvr::quickMedian::apply | ( | const V & | src, | |
V & | dest, | |||
typename V::value_type & | median | |||
) | const [inline] |
bool cvr::quickMedian::apply | ( | const V & | src, | |
typename V::value_type & | median | |||
) | const [inline] |
Operates on the given parameter.
src | vector with the source data. | |
median | the median value |
bool cvr::quickMedian::apply | ( | V & | srcdest, | |
typename V::value_type & | median | |||
) | const [inline] |
Find the median of a vector type V, which can be an cvr::genericVector or its derived classes, or a std::vector.
In principle the container type V just needs to support:
The resulting vector contains the elements less or equal than the median for the indexes x
such that x < size()/2
, and higher or equal otherwise.
srcdest | vector<T> with the source data. The result will be left here too. | |
median | the median value |
bool cvr::quickMedian::apply | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
T & | median | |||
) | const [inline] |
Calculates the median of src, the result is left in dest.
The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.
src | matrix<T> with the source data. | |
dest | partially sorted matrix. | |
median | the median value of the given matrix. |
bool cvr::quickMedian::apply | ( | const matrix< T > & | src, | |
T & | median | |||
) | const [inline] |
Calculates the median of the given matrix, which is NOT modified.
The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.
src | matrix<T> with the source data. | |
median | the median value of the given matrix. |
true
on success false
otherwise bool cvr::quickMedian::apply | ( | matrix< T > & | src, | |
T & | median | |||
) | const [inline] |
Calculates the median of the given matrix, which WILL BE modified.
The elements of the matrix will be considered as part of a vector with "columns()" times "rows()" elements.
src | matrix<T> with the source data. | |
median | the median value of the given matrix. |
true
on success false
otherwise virtual quickMedian* cvr::quickMedian::clone | ( | ) | const [virtual] |
quickMedian& cvr::quickMedian::copy | ( | const quickMedian & | other | ) |
V::value_type cvr::quickMedian::findMedian | ( | V & | vct, | |
const int | begin, | |||
const int | end, | |||
const int | medianPos | |||
) | const [inline, protected] |
This method calculates the median in a recursively form.
The template type V has to be a vector following an interface like the cvr::vector or the std::vector, implementing the operator[]
const parameters& cvr::quickMedian::getParameters | ( | ) | const |
V::value_type cvr::quickMedian::median | ( | const V & | src | ) | const [inline] |
const std::string& cvr::quickMedian::name | ( | ) | const [virtual] |
virtual quickMedian* cvr::quickMedian::newInstance | ( | ) | const [virtual] |
int cvr::quickMedian::partition | ( | V & | vct, | |
const int | begin, | |||
const int | end | |||
) | const [inline, protected] |
This method chooses a pivot-value and ensures that lower values lie at the left and higher values at the right of its final position, which will be returned.
The template type V has to be a vector following an interface like the cvr::vector or the std::vector, implementing the operator[]