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

Function cvCloneGraph

deps/opencv/modules/core/src/datastructs.cpp:3243–3324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3241
3242
3243CV_IMPL CvGraph*
3244cvCloneGraph( const CvGraph* graph, CvMemStorage* storage )
3245{
3246 int* flag_buffer = 0;
3247 CvGraphVtx** ptr_buffer = 0;
3248 CvGraph* result = 0;
3249
3250 int i, k;
3251 int vtx_size, edge_size;
3252 CvSeqReader reader;
3253
3254 if( !CV_IS_GRAPH(graph))
3255 CV_Error( CV_StsBadArg, "Invalid graph pointer" );
3256
3257 if( !storage )
3258 storage = graph->storage;
3259
3260 if( !storage )
3261 CV_Error( CV_StsNullPtr, "NULL storage pointer" );
3262
3263 vtx_size = graph->elem_size;
3264 edge_size = graph->edges->elem_size;
3265
3266 flag_buffer = (int*)cvAlloc( graph->total*sizeof(flag_buffer[0]));
3267 ptr_buffer = (CvGraphVtx**)cvAlloc( graph->total*sizeof(ptr_buffer[0]));
3268 result = cvCreateGraph( graph->flags, graph->header_size,
3269 vtx_size, edge_size, storage );
3270 memcpy( result + sizeof(CvGraph), graph + sizeof(CvGraph),
3271 graph->header_size - sizeof(CvGraph));
3272
3273 // Pass 1. Save flags, copy vertices:
3274 cvStartReadSeq( (CvSeq*)graph, &reader );
3275 for( i = 0, k = 0; i < graph->total; i++ )
3276 {
3277 if( CV_IS_SET_ELEM( reader.ptr ))
3278 {
3279 CvGraphVtx* vtx = (CvGraphVtx*)reader.ptr;
3280 CvGraphVtx* dstvtx = 0;
3281 cvGraphAddVtx( result, vtx, &dstvtx );
3282 flag_buffer[k] = dstvtx->flags = vtx->flags;
3283 vtx->flags = k;
3284 ptr_buffer[k++] = dstvtx;
3285 }
3286 CV_NEXT_SEQ_ELEM( vtx_size, reader );
3287 }
3288
3289 // Pass 2. Copy edges:
3290 cvStartReadSeq( (CvSeq*)graph->edges, &reader );
3291 for( i = 0; i < graph->edges->total; i++ )
3292 {
3293 if( CV_IS_SET_ELEM( reader.ptr ))
3294 {
3295 CvGraphEdge* edge = (CvGraphEdge*)reader.ptr;
3296 CvGraphEdge* dstedge = 0;
3297 CvGraphVtx* new_org = ptr_buffer[edge->vtx[0]->flags];
3298 CvGraphVtx* new_dst = ptr_buffer[edge->vtx[1]->flags];
3299 cvGraphAddEdgeByPtr( result, new_org, new_dst, edge, &dstedge );
3300 dstedge->flags = edge->flags;

Callers 1

icvCloneGraphFunction · 0.85

Calls 6

cvAllocFunction · 0.85
cvCreateGraphFunction · 0.85
cvStartReadSeqFunction · 0.85
cvGraphAddVtxFunction · 0.85
cvGraphAddEdgeByPtrFunction · 0.85
cvGetErrStatusFunction · 0.85

Tested by

no test coverage detected