#include <core.hpp>
Classes | |
struct | Hdr |
the sparse matrix header More... | |
struct | Node |
sparse matrix node - element of a hash table More... | |
Public Types | |
enum | { MAGIC_VAL =0x42FD0000, MAX_DIM =CV_MAX_DIM, HASH_SCALE =0x5bd1e995, HASH_BIT =0x80000000 } |
typedef SparseMatIterator | iterator |
typedef SparseMatConstIterator | const_iterator |
Public Member Functions | |
SparseMat () | |
default constructor More... | |
SparseMat (int dims, const int *_sizes, int _type) | |
creates matrix of the specified size and type More... | |
SparseMat (const SparseMat &m) | |
copy constructor More... | |
SparseMat (const Mat &m) | |
converts dense 2d matrix to the sparse form More... | |
SparseMat (const CvSparseMat *m) | |
converts old-style sparse matrix to the new-style. All the data is copied More... | |
~SparseMat () | |
the destructor More... | |
SparseMat & | operator= (const SparseMat &m) |
assignment operator. This is O(1) operation, i.e. no data is copied More... | |
SparseMat & | operator= (const Mat &m) |
equivalent to the corresponding constructor More... | |
SparseMat | clone () const |
creates full copy of the matrix More... | |
void | copyTo (SparseMat &m) const |
copies all the data to the destination matrix. All the previous content of m is erased More... | |
void | copyTo (Mat &m) const |
converts sparse matrix to dense matrix. More... | |
void | convertTo (SparseMat &m, int rtype, double alpha=1) const |
multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type More... | |
void | convertTo (Mat &m, int rtype, double alpha=1, double beta=0) const |
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling. More... | |
void | assignTo (SparseMat &m, int type=-1) const |
void | create (int dims, const int *_sizes, int _type) |
reallocates sparse matrix. More... | |
void | clear () |
sets all the sparse matrix elements to 0, which means clearing the hash table. More... | |
void | addref () |
manually increments the reference counter to the header. More... | |
void | release () |
operator CvSparseMat * () const | |
converts sparse matrix to the old-style representation; all the elements are copied. More... | |
size_t | elemSize () const |
returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements) More... | |
size_t | elemSize1 () const |
returns elemSize()/channels() More... | |
int | type () const |
returns type of sparse matrix elements More... | |
int | depth () const |
returns the depth of sparse matrix elements More... | |
int | channels () const |
returns the number of channels More... | |
const int * | size () const |
returns the array of sizes, or NULL if the matrix is not allocated More... | |
int | size (int i) const |
returns the size of i-th matrix dimension (or 0) More... | |
int | dims () const |
returns the matrix dimensionality More... | |
size_t | nzcount () const |
returns the number of non-zero elements (=the number of hash table nodes) More... | |
size_t | hash (int i0) const |
computes the element hash value (1D case) More... | |
size_t | hash (int i0, int i1) const |
computes the element hash value (2D case) More... | |
size_t | hash (int i0, int i1, int i2) const |
computes the element hash value (3D case) More... | |
size_t | hash (const int *idx) const |
computes the element hash value (nD case) More... | |
SparseMatIterator | end () |
returns the sparse matrix iterator at the matrix end More... | |
SparseMatConstIterator | end () const |
returns the read-only sparse matrix iterator at the matrix end More... | |
template<typename _Tp > | |
SparseMatIterator_< _Tp > | end () |
returns the typed sparse matrix iterator at the matrix end More... | |
template<typename _Tp > | |
SparseMatConstIterator_< _Tp > | end () const |
returns the typed read-only sparse matrix iterator at the matrix end More... | |
template<typename _Tp > | |
_Tp & | value (Node *n) |
returns the value stored in the sparse martix node More... | |
template<typename _Tp > | |
const _Tp & | value (const Node *n) const |
returns the value stored in the sparse martix node More... | |
Node * | node (size_t nidx) |
const Node * | node (size_t nidx) const |
uchar * | newNode (const int *idx, size_t hashval) |
void | removeNode (size_t hidx, size_t nidx, size_t previdx) |
void | resizeHashTab (size_t newsize) |
uchar * | ptr (int i0, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (1D case) More... | |
uchar * | ptr (int i0, int i1, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (2D case) More... | |
uchar * | ptr (int i0, int i1, int i2, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (3D case) More... | |
uchar * | ptr (const int *idx, bool createMissing, size_t *hashval=0) |
returns pointer to the specified element (nD case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, size_t *hashval=0) |
returns reference to the specified element (1D case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, int i1, size_t *hashval=0) |
returns reference to the specified element (2D case) More... | |
template<typename _Tp > | |
_Tp & | ref (int i0, int i1, int i2, size_t *hashval=0) |
returns reference to the specified element (3D case) More... | |
template<typename _Tp > | |
_Tp & | ref (const int *idx, size_t *hashval=0) |
returns reference to the specified element (nD case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, size_t *hashval=0) const |
returns value of the specified element (1D case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, int i1, size_t *hashval=0) const |
returns value of the specified element (2D case) More... | |
template<typename _Tp > | |
_Tp | value (int i0, int i1, int i2, size_t *hashval=0) const |
returns value of the specified element (3D case) More... | |
template<typename _Tp > | |
_Tp | value (const int *idx, size_t *hashval=0) const |
returns value of the specified element (nD case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, size_t *hashval=0) const |
returns pointer to the specified element (1D case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, int i1, size_t *hashval=0) const |
returns pointer to the specified element (2D case) More... | |
template<typename _Tp > | |
const _Tp * | find (int i0, int i1, int i2, size_t *hashval=0) const |
returns pointer to the specified element (3D case) More... | |
template<typename _Tp > | |
const _Tp * | find (const int *idx, size_t *hashval=0) const |
returns pointer to the specified element (nD case) More... | |
void | erase (int i0, int i1, size_t *hashval=0) |
erases the specified element (2D case) More... | |
void | erase (int i0, int i1, int i2, size_t *hashval=0) |
erases the specified element (3D case) More... | |
void | erase (const int *idx, size_t *hashval=0) |
erases the specified element (nD case) More... | |
SparseMatIterator | begin () |
returns the sparse matrix iterator at the matrix beginning More... | |
template<typename _Tp > | |
SparseMatIterator_< _Tp > | begin () |
returns the sparse matrix iterator at the matrix beginning More... | |
SparseMatConstIterator | begin () const |
returns the read-only sparse matrix iterator at the matrix beginning More... | |
template<typename _Tp > | |
SparseMatConstIterator_< _Tp > | begin () const |
returns the read-only sparse matrix iterator at the matrix beginning More... | |
Public Attributes | |
int | flags |
Hdr * | hdr |
Sparse matrix class.
The class represents multi-dimensional sparse numerical arrays. Such a sparse array can store elements of any type that cv::Mat is able to store. "Sparse" means that only non-zero elements are stored (though, as a result of some operations on a sparse matrix, some of its stored elements can actually become 0. It's user responsibility to detect such elements and delete them using cv::SparseMat::erase(). The non-zero elements are stored in a hash table that grows when it's filled enough, so that the search time remains O(1) in average. Elements can be accessed using the following methods:
Query operations: cv::SparseMat::ptr() and the higher-level cv::SparseMat::ref(), cv::SparseMat::value() and cv::SparseMat::find, for example:
Sparse matrix iterators. Like cv::Mat iterators and unlike cv::Mat iterators, the sparse matrix iterators are STL-style, that is, the iteration is done as following:
If you run this loop, you will notice that elements are enumerated in no any logical order (lexicographical etc.), they come in the same order as they stored in the hash table, i.e. semi-randomly.
You may collect pointers to the nodes and sort them to get the proper ordering. Note, however, that pointers to the nodes may become invalid when you add more elements to the matrix; this is because of possible buffer reallocation.
|
inline |
default constructor
creates matrix of the specified size and type
|
inline |
copy constructor
|
explicit |
converts dense 2d matrix to the sparse form
m | the input matrix |
cv::SparseMat::SparseMat | ( | const CvSparseMat * | m | ) |
converts old-style sparse matrix to the new-style. All the data is copied
|
inline |
the destructor
|
inline |
manually increments the reference counter to the header.
|
inline |
returns the sparse matrix iterator at the matrix beginning
return the sparse matrix iterator pointing to the first sparse matrix element
|
inline |
returns the sparse matrix iterator at the matrix beginning
|
inline |
returns the read-only sparse matrix iterator at the matrix beginning
|
inline |
returns the read-only sparse matrix iterator at the matrix beginning
|
inline |
returns the number of channels
void cv::SparseMat::clear | ( | ) |
sets all the sparse matrix elements to 0, which means clearing the hash table.
|
inline |
creates full copy of the matrix
multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type
converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.
m | Destination matrix |
rtype | The output matrix data type. When it is =-1, the output array will have the same data type as (*this) |
alpha | The scale factor |
beta | The optional delta added to the scaled values before the conversion |
copies all the data to the destination matrix. All the previous content of m is erased
reallocates sparse matrix.
If the matrix already had the proper size and type, it is simply cleared with clear(), otherwise, the old matrix is released (using release()) and the new one is allocated.
|
inline |
returns the depth of sparse matrix elements
|
inline |
returns the matrix dimensionality
|
inline |
returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)
|
inline |
returns elemSize()/channels()
|
inline |
returns the sparse matrix iterator at the matrix end
return the sparse matrix iterator pointing to the element following the last sparse matrix element
|
inline |
returns the read-only sparse matrix iterator at the matrix end
|
inline |
returns the typed sparse matrix iterator at the matrix end
|
inline |
returns the typed read-only sparse matrix iterator at the matrix end
erases the specified element (2D case)
erases the specified element (3D case)
erases the specified element (nD case)
|
inline |
returns pointer to the specified element (1D case)
Return pointer to the specified sparse matrix element if it exists
find<_Tp>(i0,...[,hashval]) is equivalent to (_const Tp*)ptr(i0,...false[,hashval]).
If the specified element does not exist, the methods return NULL.
|
inline |
returns pointer to the specified element (2D case)
|
inline |
returns pointer to the specified element (3D case)
|
inline |
returns pointer to the specified element (nD case)
|
inline |
computes the element hash value (1D case)
computes the element hash value (2D case)
computes the element hash value (3D case)
|
inline |
computes the element hash value (nD case)
|
inline |
|
inline |
|
inline |
returns the number of non-zero elements (=the number of hash table nodes)
cv::SparseMat::operator CvSparseMat * | ( | ) | const |
converts sparse matrix to the old-style representation; all the elements are copied.
assignment operator. This is O(1) operation, i.e. no data is copied
equivalent to the corresponding constructor
returns pointer to the specified element (1D case)
specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case.
return pointer to the matrix element.
returns pointer to the specified element (2D case)
returns pointer to the specified element (3D case)
returns pointer to the specified element (nD case)
|
inline |
returns reference to the specified element (1D case)
return read-write reference to the specified sparse matrix element.
ref<_Tp>(i0,...[,hashval]) is equivalent to *(_Tp*)ptr(i0,...,true[,hashval]). The methods always return a valid reference. If the element did not exist, it is created and initialiazed with 0.
returns reference to the specified element (2D case)
|
inline |
returns reference to the specified element (3D case)
|
inline |
returns reference to the specified element (nD case)
|
inline |
void cv::SparseMat::removeNode | ( | size_t | hidx, |
size_t | nidx, | ||
size_t | previdx | ||
) |
void cv::SparseMat::resizeHashTab | ( | size_t | newsize | ) |
|
inline |
returns the array of sizes, or NULL if the matrix is not allocated
|
inline |
returns type of sparse matrix elements
|
inline |
returns value of the specified element (1D case)
return value of the specified sparse matrix element.
value<_Tp>(i0,...[,hashval]) is equivalent
That is, if the element did not exist, the methods return 0.
|
inline |
returns value of the specified element (2D case)
|
inline |
returns value of the specified element (3D case)
|
inline |
returns value of the specified element (nD case)
|
inline |
returns the value stored in the sparse martix node
|
inline |
returns the value stored in the sparse martix node
int cv::SparseMat::flags |
Hdr* cv::SparseMat::hdr |