static CvSubdiv2DEdge cvSubdiv2DMakeEdge( CvSubdiv2D * subdiv ) { CvQuadEdge2D *edge = 0; CvSubdiv2DEdge edgehandle = 0; CV_FUNCNAME( "cvSubdiv2DMakeEdge" ); __BEGIN__; if( !subdiv ) CV_ERROR( CV_StsNullPtr, "" ); edge = (CvQuadEdge2D*)cvSetNew( (CvSet*)subdiv->edges ); CV_CHECK(); memset( edge->pt, 0, sizeof( edge->pt )); edgehandle = (CvSubdiv2DEdge) edge; edge->next[0] = edgehandle; edge->next[1] = edgehandle + 3; edge->next[2] = edgehandle + 2; edge->next[3] = edgehandle + 1; subdiv->quad_edges++; __END__; return edgehandle; }
static CvSubdiv2DPoint * cvSubdiv2DAddPoint( CvSubdiv2D * subdiv, CvPoint2D32f pt, int is_virtual ) { CvSubdiv2DPoint* subdiv_point = (CvSubdiv2DPoint*)cvSetNew( (CvSet*)subdiv ); if( subdiv_point ) { memset( subdiv_point, 0, subdiv->elem_size ); subdiv_point->pt = pt; subdiv_point->first = 0; subdiv_point->flags |= is_virtual ? CV_SUBDIV2D_VIRTUAL_POINT_FLAG : 0; subdiv_point->id = -1; } return subdiv_point; }
CV_IMPL CvStringHashNode* cvGetHashedKey( CvFileStorage* fs, const char* str, int len, int create_missing ) { CvStringHashNode* node = 0; unsigned hashval = 0; int i, tab_size; if( !fs ) return 0; CvStringHash* map = fs->str_hash; if( len < 0 ) { for( i = 0; str[i] != '\0'; i++ ) hashval = hashval*CV_HASHVAL_SCALE + (unsigned char)str[i]; len = i; } else for( i = 0; i < len; i++ ) hashval = hashval*CV_HASHVAL_SCALE + (unsigned char)str[i]; hashval &= INT_MAX; tab_size = map->tab_size; if( (tab_size & (tab_size - 1)) == 0 ) i = (int)(hashval & (tab_size - 1)); else i = (int)(hashval % tab_size); for( node = (CvStringHashNode*)(map->table[i]); node != 0; node = node->next ) { if( node->hashval == hashval && node->str.len == len && memcmp( node->str.ptr, str, len ) == 0 ) break; } if( !node && create_missing ) { node = (CvStringHashNode*)cvSetNew( (CvSet*)map ); node->hashval = hashval; node->str = cvMemStorageAllocString( map->storage, str, len ); node->next = (CvStringHashNode*)(map->table[i]); map->table[i] = node; } return node; }
static CvSubdiv2DEdge cvSubdiv2DMakeEdge( CvSubdiv2D * subdiv ) { if( !subdiv ) CV_Error( CV_StsNullPtr, "" ); CvQuadEdge2D* edge = (CvQuadEdge2D*)cvSetNew( (CvSet*)subdiv->edges ); memset( edge->pt, 0, sizeof( edge->pt )); CvSubdiv2DEdge edgehandle = (CvSubdiv2DEdge) edge; edge->next[0] = edgehandle; edge->next[1] = edgehandle + 3; edge->next[2] = edgehandle + 2; edge->next[3] = edgehandle + 1; subdiv->quad_edges++; return edgehandle; }
/* dst = src */ CV_IMPL void cvCopy( const void* srcarr, void* dstarr, const void* maskarr ) { if( CV_IS_SPARSE_MAT(srcarr) && CV_IS_SPARSE_MAT(dstarr)) { CV_Assert( maskarr == 0 ); CvSparseMat* src1 = (CvSparseMat*)srcarr; CvSparseMat* dst1 = (CvSparseMat*)dstarr; CvSparseMatIterator iterator; CvSparseNode* node; dst1->dims = src1->dims; memcpy( dst1->size, src1->size, src1->dims*sizeof(src1->size[0])); dst1->valoffset = src1->valoffset; dst1->idxoffset = src1->idxoffset; cvClearSet( dst1->heap ); if( src1->heap->active_count >= dst1->hashsize*CV_SPARSE_HASH_RATIO ) { cvFree( &dst1->hashtable ); dst1->hashsize = src1->hashsize; dst1->hashtable = (void**)cvAlloc( dst1->hashsize*sizeof(dst1->hashtable[0])); } memset( dst1->hashtable, 0, dst1->hashsize*sizeof(dst1->hashtable[0])); for( node = cvInitSparseMatIterator( src1, &iterator ); node != 0; node = cvGetNextSparseNode( &iterator )) { CvSparseNode* node_copy = (CvSparseNode*)cvSetNew( dst1->heap ); int tabidx = node->hashval & (dst1->hashsize - 1); CV_MEMCPY_AUTO( node_copy, node, dst1->heap->elem_size ); node_copy->next = (CvSparseNode*)dst1->hashtable[tabidx]; dst1->hashtable[tabidx] = node_copy; } return; } cv::Mat src = cv::cvarrToMat(srcarr, false, true, 1), dst = cv::cvarrToMat(dstarr, false, true, 1); CV_Assert( src.depth() == dst.depth() && src.size() == dst.size() ); int coi1 = 0, coi2 = 0; if( CV_IS_IMAGE(srcarr) ) coi1 = cvGetImageCOI((const IplImage*)srcarr); if( CV_IS_IMAGE(dstarr) ) coi2 = cvGetImageCOI((const IplImage*)dstarr); if( coi1 || coi2 ) { CV_Assert( (coi1 != 0 || src.channels() == 1) && (coi2 != 0 || dst.channels() == 1) ); int pair[] = { std::max(coi1-1, 0), std::max(coi2-1, 0) }; cv::mixChannels( &src, 1, &dst, 1, pair, 1 ); return; } else CV_Assert( src.channels() == dst.channels() ); if( !maskarr ) src.copyTo(dst); else src.copyTo(dst, cv::cvarrToMat(maskarr)); }
CvSetElem * cvSetNew_wrap(CvSet * set_header ){ return cvSetNew(/*CvSet*//***/set_header); }
CV_IMPL CvFileNode* cvGetFileNode( CvFileStorage* fs, CvFileNode* _map_node, const CvStringHashNode* key, int create_missing ) { CvFileNode* value = 0; int k = 0, attempts = 1; if( !fs ) return 0; CV_CHECK_FILE_STORAGE(fs); if( !key ) CV_Error( CV_StsNullPtr, "Null key element" ); if( _map_node ) { if( !fs->roots ) return 0; attempts = fs->roots->total; } for( k = 0; k < attempts; k++ ) { int i, tab_size; CvFileNode* map_node = _map_node; CvFileMapNode* another; CvFileNodeHash* map; if( !map_node ) map_node = (CvFileNode*)cvGetSeqElem( fs->roots, k ); CV_Assert(map_node != NULL); if( !CV_NODE_IS_MAP(map_node->tag) ) { if( (!CV_NODE_IS_SEQ(map_node->tag) || map_node->data.seq->total != 0) && CV_NODE_TYPE(map_node->tag) != CV_NODE_NONE ) CV_Error( CV_StsError, "The node is neither a map nor an empty collection" ); return 0; } map = map_node->data.map; tab_size = map->tab_size; if( (tab_size & (tab_size - 1)) == 0 ) i = (int)(key->hashval & (tab_size - 1)); else i = (int)(key->hashval % tab_size); for( another = (CvFileMapNode*)(map->table[i]); another != 0; another = another->next ) if( another->key == key ) { if( !create_missing ) { value = &another->value; return value; } CV_PARSE_ERROR( "Duplicated key" ); } if( k == attempts - 1 && create_missing ) { CvFileMapNode* node = (CvFileMapNode*)cvSetNew( (CvSet*)map ); node->key = key; node->next = (CvFileMapNode*)(map->table[i]); map->table[i] = node; value = (CvFileNode*)node; } } return value; }