OpenCV  4.1.1-pre
Open Source Computer Vision
Looking for a C++ dev who knows OpenCV?
I'm looking for work. Hire me!
cv::SparseMat_< _Tp > Class Template Reference

Template sparse n-dimensional array class derived from SparseMat. More...

#include <opencv2/core/mat.hpp>

Inheritance diagram for cv::SparseMat_< _Tp >:
Collaboration diagram for cv::SparseMat_< _Tp >:

Public Types

enum  {
  MAGIC_VAL =0x42FD0000,
  MAX_DIM =32,
  HASH_SCALE =0x5bd1e995,
  HASH_BIT =0x80000000
}
 
typedef SparseMatConstIterator_< _Tp > const_iterator
 
typedef SparseMatIterator_< _Tp > iterator
 

Public Member Functions

 SparseMat_ ()
 the default constructor More...
 
 SparseMat_ (int dims, const int *_sizes)
 the full constructor equivalent to SparseMat(dims, _sizes, DataType<_Tp>::type) More...
 
 SparseMat_ (const SparseMat &m)
 the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted More...
 
 SparseMat_ (const SparseMat_ &m)
 the copy constructor. This is O(1) operation - no data is copied More...
 
 SparseMat_ (const Mat &m)
 converts dense matrix to the sparse form More...
 
void addref ()
 manually increments the reference counter to the header. More...
 
void assignTo (SparseMat &m, int type=-1) const
 
SparseMatIterator_< _Tp > begin ()
 returns sparse matrix iterator pointing to the first sparse matrix element More...
 
SparseMatConstIterator_< _Tp > begin () const
 returns read-only sparse matrix iterator pointing to the first sparse matrix element More...
 
int channels () const
 returns the number of channels in each matrix element More...
 
void clear ()
 sets all the sparse matrix elements to 0, which means clearing the hash table. More...
 
SparseMat_ clone () const CV_NODISCARD
 makes full copy of the matrix. All the elements are duplicated 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 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 create (int dims, const int *_sizes, int _type)
 reallocates sparse matrix. More...
 
void create (int dims, const int *_sizes)
 equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type) More...
 
int depth () const
 returns depth of the matrix elements More...
 
int dims () const
 returns the matrix dimensionality More...
 
size_t elemSize () const
 converts sparse matrix to the old-style representation; all the elements are copied. More...
 
size_t elemSize1 () const
 returns elemSize()/channels() More...
 
SparseMatIterator_< _Tp > end ()
 returns sparse matrix iterator pointing to the element following the last sparse matrix element More...
 
SparseMatConstIterator_< _Tp > end () const
 returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element 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...
 
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...
 
ucharnewNode (const int *idx, size_t hashval)
 
Nodenode (size_t nidx)
 
const Nodenode (size_t nidx) const
 
size_t nzcount () const
 returns the number of non-zero elements (=the number of hash table nodes) More...
 
_Tp operator() (int i0, size_t *hashval=0) const
 equivalent to SparseMat::value<_Tp>(i0, hashval) More...
 
_Tp operator() (int i0, int i1, size_t *hashval=0) const
 equivalent to SparseMat::value<_Tp>(i0, i1, hashval) More...
 
_Tp operator() (int i0, int i1, int i2, size_t *hashval=0) const
 equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval) More...
 
_Tp operator() (const int *idx, size_t *hashval=0) const
 equivalent to SparseMat::value<_Tp>(idx, hashval) More...
 
SparseMat_operator= (const SparseMat &m)
 converts the old-style sparse matrix to the C++ class. All the elements are copied More...
 
SparseMat_operator= (const SparseMat_ &m)
 the assignment operator. This is O(1) operation - no data is copied More...
 
SparseMat_operator= (const Mat &m)
 converts dense matrix to the sparse form More...
 
_Tp & ref (int i0, size_t *hashval=0)
 equivalent to SparseMat::ref<_Tp>(i0, hashval) More...
 
_Tp & ref (int i0, int i1, size_t *hashval=0)
 equivalent to SparseMat::ref<_Tp>(i0, i1, hashval) More...
 
_Tp & ref (int i0, int i1, int i2, size_t *hashval=0)
 equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval) More...
 
_Tp & ref (const int *idx, size_t *hashval=0)
 equivalent to SparseMat::ref<_Tp>(idx, hashval) More...
 
void release ()
 
void removeNode (size_t hidx, size_t nidx, size_t previdx)
 
void resizeHashTab (size_t newsize)
 
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 type () const
 converts sparse matrix to the old-style CvSparseMat. All the elements are copied 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...
 
ucharptr (int i0, bool createMissing, size_t *hashval=0)
 specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case. More...
 
ucharptr (int i0, int i1, bool createMissing, size_t *hashval=0)
 returns pointer to the specified element (2D case) More...
 
ucharptr (int i0, int i1, int i2, bool createMissing, size_t *hashval=0)
 returns pointer to the specified element (3D case) More...
 
ucharptr (const int *idx, bool createMissing, size_t *hashval=0)
 returns pointer to the specified element (nD case) More...
 
template<typename _Tp >
_Tp value (int i0, size_t *hashval=0) const
 return value of the specified sparse matrix element. 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
 Return pointer to the specified sparse matrix element if it exists. 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...
 

Public Attributes

int flags
 
Hdrhdr
 

Detailed Description

template<typename _Tp>
class cv::SparseMat_< _Tp >

Template sparse n-dimensional array class derived from SparseMat.

SparseMat_ is a thin wrapper on top of SparseMat created in the same way as Mat_ . It simplifies notation of some operations:

int sz[] = {10, 20, 30};
SparseMat_<double> M(3, sz);
...
M.ref(1, 2, 3) = M(4, 5, 6) + M(7, 8, 9);

Member Typedef Documentation

◆ const_iterator

template<typename _Tp>
typedef SparseMatConstIterator_<_Tp> cv::SparseMat_< _Tp >::const_iterator

◆ iterator

template<typename _Tp>
typedef SparseMatIterator_<_Tp> cv::SparseMat_< _Tp >::iterator

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
MAGIC_VAL 
MAX_DIM 
HASH_SCALE 
HASH_BIT 

Constructor & Destructor Documentation

◆ SparseMat_() [1/5]

template<typename _Tp>
cv::SparseMat_< _Tp >::SparseMat_ ( )

the default constructor

◆ SparseMat_() [2/5]

template<typename _Tp>
cv::SparseMat_< _Tp >::SparseMat_ ( int  dims,
const int *  _sizes 
)

the full constructor equivalent to SparseMat(dims, _sizes, DataType<_Tp>::type)

◆ SparseMat_() [3/5]

template<typename _Tp>
cv::SparseMat_< _Tp >::SparseMat_ ( const SparseMat m)

the copy constructor. If DataType<_Tp>.type != m.type(), the m elements are converted

◆ SparseMat_() [4/5]

template<typename _Tp>
cv::SparseMat_< _Tp >::SparseMat_ ( const SparseMat_< _Tp > &  m)

the copy constructor. This is O(1) operation - no data is copied

◆ SparseMat_() [5/5]

template<typename _Tp>
cv::SparseMat_< _Tp >::SparseMat_ ( const Mat m)

converts dense matrix to the sparse form

Member Function Documentation

◆ addref()

void cv::SparseMat::addref ( )
inherited

manually increments the reference counter to the header.

◆ assignTo()

void cv::SparseMat::assignTo ( SparseMat m,
int  type = -1 
) const
inherited

◆ begin() [1/2]

template<typename _Tp>
SparseMatIterator_<_Tp> cv::SparseMat_< _Tp >::begin ( )

returns sparse matrix iterator pointing to the first sparse matrix element

◆ begin() [2/2]

template<typename _Tp>
SparseMatConstIterator_<_Tp> cv::SparseMat_< _Tp >::begin ( ) const

returns read-only sparse matrix iterator pointing to the first sparse matrix element

◆ channels()

template<typename _Tp>
int cv::SparseMat_< _Tp >::channels ( ) const

returns the number of channels in each matrix element

◆ clear()

void cv::SparseMat::clear ( )
inherited

sets all the sparse matrix elements to 0, which means clearing the hash table.

◆ clone()

template<typename _Tp>
SparseMat_ cv::SparseMat_< _Tp >::clone ( ) const

makes full copy of the matrix. All the elements are duplicated

◆ convertTo() [1/2]

void cv::SparseMat::convertTo ( SparseMat m,
int  rtype,
double  alpha = 1 
) const
inherited

multiplies all the matrix elements by the specified scale factor alpha and converts the results to the specified data type

◆ convertTo() [2/2]

void cv::SparseMat::convertTo ( Mat m,
int  rtype,
double  alpha = 1,
double  beta = 0 
) const
inherited

converts sparse matrix to dense n-dim matrix with optional type conversion and scaling.

Parameters
[out]m- output matrix; if it does not have a proper size or type before the operation, it is reallocated
[in]rtype- desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.
[in]alpha- optional scale factor
[in]beta- optional delta added to the scaled values

◆ copyTo() [1/2]

void cv::SparseMat::copyTo ( SparseMat m) const
inherited

copies all the data to the destination matrix. All the previous content of m is erased

◆ copyTo() [2/2]

void cv::SparseMat::copyTo ( Mat m) const
inherited

converts sparse matrix to dense matrix.

◆ create() [1/2]

void cv::SparseMat::create ( int  dims,
const int *  _sizes,
int  _type 
)
inherited

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.

◆ create() [2/2]

template<typename _Tp>
void cv::SparseMat_< _Tp >::create ( int  dims,
const int *  _sizes 
)

equivalent to cv::SparseMat::create(dims, _sizes, DataType<_Tp>::type)

◆ depth()

template<typename _Tp>
int cv::SparseMat_< _Tp >::depth ( ) const

returns depth of the matrix elements

◆ dims()

int cv::SparseMat::dims ( ) const
inherited

returns the matrix dimensionality

◆ elemSize()

size_t cv::SparseMat::elemSize ( ) const
inherited

converts sparse matrix to the old-style representation; all the elements are copied.

returns the size of each element in bytes (not including the overhead - the space occupied by SparseMat::Node elements)

◆ elemSize1()

size_t cv::SparseMat::elemSize1 ( ) const
inherited

returns elemSize()/channels()

◆ end() [1/2]

template<typename _Tp>
SparseMatIterator_<_Tp> cv::SparseMat_< _Tp >::end ( )

returns sparse matrix iterator pointing to the element following the last sparse matrix element

◆ end() [2/2]

template<typename _Tp>
SparseMatConstIterator_<_Tp> cv::SparseMat_< _Tp >::end ( ) const

returns read-only sparse matrix iterator pointing to the element following the last sparse matrix element

◆ erase() [1/3]

void cv::SparseMat::erase ( int  i0,
int  i1,
size_t *  hashval = 0 
)
inherited

erases the specified element (2D case)

◆ erase() [2/3]

void cv::SparseMat::erase ( int  i0,
int  i1,
int  i2,
size_t *  hashval = 0 
)
inherited

erases the specified element (3D case)

◆ erase() [3/3]

void cv::SparseMat::erase ( const int *  idx,
size_t *  hashval = 0 
)
inherited

erases the specified element (nD case)

◆ find() [1/4]

template<typename _Tp >
const _Tp* cv::SparseMat::find ( int  i0,
size_t *  hashval = 0 
) const
inherited

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.returns pointer to the specified element (1D case)

◆ find() [2/4]

template<typename _Tp >
const _Tp* cv::SparseMat::find ( int  i0,
int  i1,
size_t *  hashval = 0 
) const
inherited

returns pointer to the specified element (2D case)

◆ find() [3/4]

template<typename _Tp >
const _Tp* cv::SparseMat::find ( int  i0,
int  i1,
int  i2,
size_t *  hashval = 0 
) const
inherited

returns pointer to the specified element (3D case)

◆ find() [4/4]

template<typename _Tp >
const _Tp* cv::SparseMat::find ( const int *  idx,
size_t *  hashval = 0 
) const
inherited

returns pointer to the specified element (nD case)

◆ hash() [1/4]

size_t cv::SparseMat::hash ( int  i0) const
inherited

computes the element hash value (1D case)

◆ hash() [2/4]

size_t cv::SparseMat::hash ( int  i0,
int  i1 
) const
inherited

computes the element hash value (2D case)

◆ hash() [3/4]

size_t cv::SparseMat::hash ( int  i0,
int  i1,
int  i2 
) const
inherited

computes the element hash value (3D case)

◆ hash() [4/4]

size_t cv::SparseMat::hash ( const int *  idx) const
inherited

computes the element hash value (nD case)

◆ newNode()

uchar* cv::SparseMat::newNode ( const int *  idx,
size_t  hashval 
)
inherited

◆ node() [1/2]

Node* cv::SparseMat::node ( size_t  nidx)
inherited

◆ node() [2/2]

const Node* cv::SparseMat::node ( size_t  nidx) const
inherited

◆ nzcount()

size_t cv::SparseMat::nzcount ( ) const
inherited

returns the number of non-zero elements (=the number of hash table nodes)

◆ operator()() [1/4]

template<typename _Tp>
_Tp cv::SparseMat_< _Tp >::operator() ( int  i0,
size_t *  hashval = 0 
) const

equivalent to SparseMat::value<_Tp>(i0, hashval)

◆ operator()() [2/4]

template<typename _Tp>
_Tp cv::SparseMat_< _Tp >::operator() ( int  i0,
int  i1,
size_t *  hashval = 0 
) const

equivalent to SparseMat::value<_Tp>(i0, i1, hashval)

◆ operator()() [3/4]

template<typename _Tp>
_Tp cv::SparseMat_< _Tp >::operator() ( int  i0,
int  i1,
int  i2,
size_t *  hashval = 0 
) const

equivalent to SparseMat::value<_Tp>(i0, i1, i2, hashval)

◆ operator()() [4/4]

template<typename _Tp>
_Tp cv::SparseMat_< _Tp >::operator() ( const int *  idx,
size_t *  hashval = 0 
) const

equivalent to SparseMat::value<_Tp>(idx, hashval)

◆ operator=() [1/3]

template<typename _Tp>
SparseMat_& cv::SparseMat_< _Tp >::operator= ( const SparseMat m)

converts the old-style sparse matrix to the C++ class. All the elements are copied

the assignment operator. If DataType<_Tp>.type != m.type(), the m elements are converted

◆ operator=() [2/3]

template<typename _Tp>
SparseMat_& cv::SparseMat_< _Tp >::operator= ( const SparseMat_< _Tp > &  m)

the assignment operator. This is O(1) operation - no data is copied

◆ operator=() [3/3]

template<typename _Tp>
SparseMat_& cv::SparseMat_< _Tp >::operator= ( const Mat m)

converts dense matrix to the sparse form

◆ ptr() [1/4]

uchar* cv::SparseMat::ptr ( int  i0,
bool  createMissing,
size_t *  hashval = 0 
)
inherited

specialized variants for 1D, 2D, 3D cases and the generic_type one for n-D case.

return pointer to the matrix element.

  • if the element is there (it's non-zero), the pointer to it is returned
  • if it's not there and createMissing=false, NULL pointer is returned
  • if it's not there and createMissing=true, then the new element is created and initialized with 0. Pointer to it is returned
  • if the optional hashval pointer is not NULL, the element hash value is not computed, but *hashval is taken instead.returns pointer to the specified element (1D case)

◆ ptr() [2/4]

uchar* cv::SparseMat::ptr ( int  i0,
int  i1,
bool  createMissing,
size_t *  hashval = 0 
)
inherited

returns pointer to the specified element (2D case)

◆ ptr() [3/4]

uchar* cv::SparseMat::ptr ( int  i0,
int  i1,
int  i2,
bool  createMissing,
size_t *  hashval = 0 
)
inherited

returns pointer to the specified element (3D case)

◆ ptr() [4/4]

uchar* cv::SparseMat::ptr ( const int *  idx,
bool  createMissing,
size_t *  hashval = 0 
)
inherited

returns pointer to the specified element (nD case)

◆ ref() [1/4]

template<typename _Tp>
_Tp& cv::SparseMat_< _Tp >::ref ( int  i0,
size_t *  hashval = 0 
)

equivalent to SparseMat::ref<_Tp>(i0, hashval)

◆ ref() [2/4]

template<typename _Tp>
_Tp& cv::SparseMat_< _Tp >::ref ( int  i0,
int  i1,
size_t *  hashval = 0 
)

equivalent to SparseMat::ref<_Tp>(i0, i1, hashval)

◆ ref() [3/4]

template<typename _Tp>
_Tp& cv::SparseMat_< _Tp >::ref ( int  i0,
int  i1,
int  i2,
size_t *  hashval = 0 
)

equivalent to SparseMat::ref<_Tp>(i0, i1, i2, hashval)

◆ ref() [4/4]

template<typename _Tp>
_Tp& cv::SparseMat_< _Tp >::ref ( const int *  idx,
size_t *  hashval = 0 
)

equivalent to SparseMat::ref<_Tp>(idx, hashval)

◆ release()

void cv::SparseMat::release ( )
inherited

◆ removeNode()

void cv::SparseMat::removeNode ( size_t  hidx,
size_t  nidx,
size_t  previdx 
)
inherited

◆ resizeHashTab()

void cv::SparseMat::resizeHashTab ( size_t  newsize)
inherited

◆ size() [1/2]

const int* cv::SparseMat::size ( ) const
inherited

returns the array of sizes, or NULL if the matrix is not allocated

◆ size() [2/2]

int cv::SparseMat::size ( int  i) const
inherited

returns the size of i-th matrix dimension (or 0)

◆ type()

template<typename _Tp>
int cv::SparseMat_< _Tp >::type ( ) const

converts sparse matrix to the old-style CvSparseMat. All the elements are copied

returns type of the matrix elements

◆ value() [1/6]

template<typename _Tp >
_Tp cv::SparseMat::value ( int  i0,
size_t *  hashval = 0 
) const
inherited

return value of the specified sparse matrix element.

value<_Tp>(i0,...[,hashval]) is equivalent to

{ const _Tp* p = find<_Tp>(i0,...[,hashval]); return p ? *p : _Tp(); }

That is, if the element did not exist, the methods return 0.returns value of the specified element (1D case)

◆ value() [2/6]

template<typename _Tp >
_Tp cv::SparseMat::value ( int  i0,
int  i1,
size_t *  hashval = 0 
) const
inherited

returns value of the specified element (2D case)

◆ value() [3/6]

template<typename _Tp >
_Tp cv::SparseMat::value ( int  i0,
int  i1,
int  i2,
size_t *  hashval = 0 
) const
inherited

returns value of the specified element (3D case)

◆ value() [4/6]

template<typename _Tp >
_Tp cv::SparseMat::value ( const int *  idx,
size_t *  hashval = 0 
) const
inherited

returns value of the specified element (nD case)

◆ value() [5/6]

template<typename _Tp >
_Tp& cv::SparseMat::value ( Node n)
inherited

returns the value stored in the sparse martix node

◆ value() [6/6]

template<typename _Tp >
const _Tp& cv::SparseMat::value ( const Node n) const
inherited

returns the value stored in the sparse martix node

Member Data Documentation

◆ flags

int cv::SparseMat::flags
inherited

◆ hdr

Hdr* cv::SparseMat::hdr
inherited

The documentation for this class was generated from the following file: