MCPcopy Create free account
hub / github.com/creatale/node-dv / icvWriteSparseMat

Function icvWriteSparseMat

deps/opencv/modules/core/src/persistence.cpp:3738–3805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3736
3737
3738static void
3739icvWriteSparseMat( CvFileStorage* fs, const char* name,
3740 const void* struct_ptr, CvAttrList /*attr*/ )
3741{
3742 CvMemStorage* memstorage = 0;
3743 const CvSparseMat* mat = (const CvSparseMat*)struct_ptr;
3744 CvSparseMatIterator iterator;
3745 CvSparseNode* node;
3746 CvSeq* elements;
3747 CvSeqReader reader;
3748 int i, dims;
3749 int *prev_idx = 0;
3750 char dt[16];
3751
3752 assert( CV_IS_SPARSE_MAT(mat) );
3753
3754 memstorage = cvCreateMemStorage();
3755
3756 cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_SPARSE_MAT );
3757 dims = cvGetDims( mat, 0 );
3758
3759 cvStartWriteStruct( fs, "sizes", CV_NODE_SEQ + CV_NODE_FLOW );
3760 cvWriteRawData( fs, mat->size, dims, "i" );
3761 cvEndWriteStruct( fs );
3762 cvWriteString( fs, "dt", icvEncodeFormat( CV_MAT_TYPE(mat->type), dt ), 0 );
3763 cvStartWriteStruct( fs, "data", CV_NODE_SEQ + CV_NODE_FLOW );
3764
3765 elements = cvCreateSeq( CV_SEQ_ELTYPE_PTR, sizeof(CvSeq), sizeof(int*), memstorage );
3766
3767 node = cvInitSparseMatIterator( mat, &iterator );
3768 while( node )
3769 {
3770 int* idx = CV_NODE_IDX( mat, node );
3771 cvSeqPush( elements, &idx );
3772 node = cvGetNextSparseNode( &iterator );
3773 }
3774
3775 cvSeqSort( elements, icvSortIdxCmpFunc, &dims );
3776 cvStartReadSeq( elements, &reader, 0 );
3777
3778 for( i = 0; i < elements->total; i++ )
3779 {
3780 int* idx;
3781 void* val;
3782 int k = 0;
3783
3784 CV_READ_SEQ_ELEM( idx, reader );
3785 if( i > 0 )
3786 {
3787 for( ; idx[k] == prev_idx[k]; k++ )
3788 assert( k < dims );
3789 if( k < dims - 1 )
3790 fs->write_int( fs, 0, k - dims + 1 );
3791 }
3792 for( ; k < dims; k++ )
3793 fs->write_int( fs, 0, idx[k] );
3794 prev_idx = idx;
3795

Callers

nothing calls this directly

Calls 12

cvStartWriteStructFunction · 0.85
cvGetDimsFunction · 0.85
cvWriteRawDataFunction · 0.85
cvEndWriteStructFunction · 0.85
cvWriteStringFunction · 0.85
icvEncodeFormatFunction · 0.85
cvCreateSeqFunction · 0.85
cvInitSparseMatIteratorFunction · 0.85
cvSeqPushFunction · 0.85
cvSeqSortFunction · 0.85
cvStartReadSeqFunction · 0.85
cvReleaseMemStorageFunction · 0.85

Tested by

no test coverage detected