template class cv::SparseMat_

Overview

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

#include <mat.hpp>

template <typename _Tp>
class SparseMat_: public cv::SparseMat
{
public:
    // typedefs

    typedef SparseMatConstIterator_<_Tp> const_iterator;
    typedef SparseMatIterator_<_Tp> iterator;

    // construction

    SparseMat_();

    SparseMat_(
        int dims,
        const int* _sizes
        );

    SparseMat_(const SparseMat& m);
    SparseMat_(const SparseMat_& m);
    SparseMat_(const Mat& m);

    // methods

    SparseMatIterator_<_Tp>
    begin();

    SparseMatConstIterator_<_Tp>
    begin() const;

    int
    channels() const;

    SparseMat_
    clone() const;

    void
    create(
        int dims,
        const int* _sizes
        );

    int
    depth() const;

    SparseMatIterator_<_Tp>
    end();

    SparseMatConstIterator_<_Tp>
    end() const;

    _Tp
    operator()(
        int i0,
        size_t* hashval = 0
        ) const;

    _Tp
    operator()(
        int i0,
        int i1,
        size_t* hashval = 0
        ) const;

    _Tp
    operator()(
        int i0,
        int i1,
        int i2,
        size_t* hashval = 0
        ) const;

    _Tp
    operator()(
        const int* idx,
        size_t* hashval = 0
        ) const;

    SparseMat_&
    operator=(const SparseMat& m);

    SparseMat_&
    operator=(const SparseMat_& m);

    SparseMat_&
    operator=(const Mat& m);

    _Tp&
    ref(
        int i0,
        size_t* hashval = 0
        );

    _Tp&
    ref(
        int i0,
        int i1,
        size_t* hashval = 0
        );

    _Tp&
    ref(
        int i0,
        int i1,
        int i2,
        size_t* hashval = 0
        );

    _Tp&
    ref(
        const int* idx,
        size_t* hashval = 0
        );

    int
    type() const;
};

Inherited Members

public:
    // typedefs

    typedef SparseMatConstIterator const_iterator;
    typedef SparseMatIterator iterator;

    // enums

    enum
    {
        MAGIC_VAL  =0x42FD0000,
        MAX_DIM    =32,
        HASH_SCALE =0x5bd1e995,
        HASH_BIT   =0x80000000,
    };

    // structs

    struct Hdr;
    struct Node;

    // fields

    int flags;
    Hdr* hdr;

    // methods

    uchar*
    ptr(
        int i0,
        bool createMissing,
        size_t* hashval = 0
        );

    uchar*
    ptr(
        int i0,
        int i1,
        bool createMissing,
        size_t* hashval = 0
        );

    uchar*
    ptr(
        int i0,
        int i1,
        int i2,
        bool createMissing,
        size_t* hashval = 0
        );

    uchar*
    ptr(
        const int* idx,
        bool createMissing,
        size_t* hashval = 0
        );

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

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

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

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

    template <typename _Tp>
    _Tp
    value(
        int i0,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    _Tp
    value(
        int i0,
        int i1,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    _Tp
    value(
        int i0,
        int i1,
        int i2,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    _Tp
    value(
        const int* idx,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    const _Tp*
    find(
        int i0,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    const _Tp*
    find(
        int i0,
        int i1,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    const _Tp*
    find(
        int i0,
        int i1,
        int i2,
        size_t* hashval = 0
        ) const;

    template <typename _Tp>
    const _Tp*
    find(
        const int* idx,
        size_t* hashval = 0
        ) const;

    SparseMatIterator
    begin();

    template <typename _Tp>
    SparseMatIterator_<_Tp>
    begin();

    SparseMatConstIterator
    begin() const;

    template <typename _Tp>
    SparseMatConstIterator_<_Tp>
    begin() const;

    void
    addref();

    void
    assignTo(
        SparseMat& m,
        int type = -1
        ) const;

    int
    channels() const;

    void
    clear();

    SparseMat
    clone() const;

    void
    convertTo(
        SparseMat& m,
        int rtype,
        double alpha = 1
        ) const;

    void
    convertTo(
        Mat& m,
        int rtype,
        double alpha = 1,
        double beta = 0
        ) const;

    void
    copyTo(SparseMat& m) const;

    void
    copyTo(Mat& m) const;

    void
    create(
        int dims,
        const int* _sizes,
        int _type
        );

    int
    depth() const;

    int
    dims() const;

    size_t
    elemSize() const;

    size_t
    elemSize1() const;

    SparseMatIterator
    end();

    SparseMatConstIterator
    end() const;

    template <typename _Tp>
    SparseMatIterator_<_Tp>
    end();

    template <typename _Tp>
    SparseMatConstIterator_<_Tp>
    end() const;

    void
    erase(
        int i0,
        int i1,
        size_t* hashval = 0
        );

    void
    erase(
        int i0,
        int i1,
        int i2,
        size_t* hashval = 0
        );

    void
    erase(
        const int* idx,
        size_t* hashval = 0
        );

    size_t
    hash(int i0) const;

    size_t
    hash(
        int i0,
        int i1
        ) const;

    size_t
    hash(
        int i0,
        int i1,
        int i2
        ) const;

    size_t
    hash(const int* idx) const;

    uchar*
    newNode(
        const int* idx,
        size_t hashval
        );

    Node*
    node(size_t nidx);

    const Node*
    node(size_t nidx) const;

    size_t
    nzcount() const;

    SparseMat&
    operator=(const SparseMat& m);

    SparseMat&
    operator=(const Mat& m);

    void
    release();

    void
    removeNode(
        size_t hidx,
        size_t nidx,
        size_t previdx
        );

    void
    resizeHashTab(size_t newsize);

    const int*
    size() const;

    int
    size(int i) const;

    int
    type() const;

    template <typename _Tp>
    _Tp&
    value(Node* n);

    template <typename _Tp>
    const _Tp&
    value(const Node* n) const;

Detailed Documentation

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);

Construction

SparseMat_()

the default constructor

SparseMat_(
    int dims,
    const int* _sizes
    )

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

SparseMat_(const SparseMat& m)

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

SparseMat_(const SparseMat_& m)

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

SparseMat_(const Mat& m)

converts dense matrix to the sparse form

Methods

SparseMatIterator_<_Tp>
begin()

returns sparse matrix iterator pointing to the first sparse matrix element

SparseMatConstIterator_<_Tp>
begin() const

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

int
channels() const

returns the number of channels in each matrix element

SparseMat_
clone() const

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

void
create(
    int dims,
    const int* _sizes
    )

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

int
depth() const

returns depth of the matrix elements

SparseMatIterator_<_Tp>
end()

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

SparseMatConstIterator_<_Tp>
end() const

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

_Tp
operator()(
    int i0,
    size_t* hashval = 0
    ) const

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

_Tp
operator()(
    int i0,
    int i1,
    size_t* hashval = 0
    ) const

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

_Tp
operator()(
    int i0,
    int i1,
    int i2,
    size_t* hashval = 0
    ) const

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

_Tp
operator()(
    const int* idx,
    size_t* hashval = 0
    ) const

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

SparseMat_&
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

SparseMat_&
operator=(const SparseMat_& m)

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

SparseMat_&
operator=(const Mat& m)

converts dense matrix to the sparse form

_Tp&
ref(
    int i0,
    size_t* hashval = 0
    )

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

_Tp&
ref(
    int i0,
    int i1,
    size_t* hashval = 0
    )

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

_Tp&
ref(
    int i0,
    int i1,
    int i2,
    size_t* hashval = 0
    )

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

_Tp&
ref(
    const int* idx,
    size_t* hashval = 0
    )

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

int
type() const

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

returns type of the matrix elements