void DaoxDebugger::Matching( int i, int j ) { if( i >0 && codesim[i][j] == codesim[i-1][j] ){ Matching( i-1, j ); align1.append( i-1 ); align2.append( -1 ); }else if( j >0 && codesim[i][j] == codesim[i][j-1] ){ Matching( i, j-1 ); align1.append( -1 ); align2.append( j-1 ); }else if( i >0 && j >0 ){ Matching( i-1, j-1 ); align1.append( i-1 ); align2.append( j-1 ); } }
void DaoxDebugger::Matching( QList<DaoVmCode> & x, QList<DaoVmCode> & y ) { align1.clear(); align2.clear(); Similarity( x, y ); Matching( x.size(), y.size() ); int i, j, k, m, n = align1.size(); #if 0 //printf( "x: %i; y: %i\n", x.size(), y.size() ); for(i=0; i<x.size(); i++) DaoVmCode_Print( x[i], NULL ); for(i=0; i<y.size(); i++) DaoVmCode_Print( y[i], NULL ); #endif for(i=0; i<n; i++){ DaoCnode xnode, ynode; int a1 = align1[i]; int a2 = align2[i]; #if 0 //printf( "%3i: %3i %3i\n", i, a1, a2 ); if( a1 >=0 ) DaoVmCode_Print( x[a1], NULL ); if( a2 >=0 ) DaoVmCode_Print( y[a2], NULL ); #endif if( a1 < 0 || a2 < 0 ) continue; memset( & xnode, 0, sizeof(DaoCnode) ); memset( & ynode, 0, sizeof(DaoCnode) ); DaoCnode_InitOperands( & xnode, & x[a1] ); DaoCnode_InitOperands( & ynode, & y[a2] ); switch( xnode.type ){ case DAO_OP_NONE : break; case DAO_OP_SINGLE : if( regmap.find( xnode.first ) == regmap.end() ) regmap[ xnode.first ] = ynode.first; break; case DAO_OP_PAIR : if( regmap.find( xnode.first ) == regmap.end() ) regmap[ xnode.first ] = ynode.first; if( regmap.find( xnode.second ) == regmap.end() ) regmap[ xnode.second ] = ynode.second; break; case DAO_OP_TRIPLE : if( regmap.find( xnode.first ) == regmap.end() ) regmap[ xnode.first ] = ynode.first; if( regmap.find( xnode.second ) == regmap.end() ) regmap[ xnode.second ] = ynode.second; if( regmap.find( xnode.third ) == regmap.end() ) regmap[ xnode.third ] = ynode.third; break; case DAO_OP_RANGE : case DAO_OP_RANGE2 : for(i=xnode.first; i<=xnode.second; i++){ if( regmap.find( i ) == regmap.end() ) regmap[i] = ynode.first + i - xnode.first; } if( xnode.type == DAO_OP_RANGE2 ){ if( regmap.find( xnode.third ) == regmap.end() ) regmap[ xnode.third ] = ynode.third; } break; } } }
bool DaoxDebugger::EditContinue ( DaoProcess *process, int newEntryLine, QList<int> & lineMap, QStringList & newCodes, QStringList & routCodes ) { DaoRoutine *oldrout = process->activeRoutine; int i, j, k, dest = 0; //printf( "=======%s\n", routCodes.join("\n").toLocal8Bit().data() ); //printf( "=======%s\n", newCodes.join("\n").toLocal8Bit().data() ); if( routCodes.size() == newCodes.size() ){ DaoLexer *lexer = DaoLexer_New(); bool eq = true; for(i=0; i<routCodes.size(); i++){ QString s1 = NormalizeCodes( routCodes[i], lexer ); QString s2 = NormalizeCodes( newCodes[i], lexer ); if( s1 != s2 ){ eq = false; break; } } DaoLexer_Delete( lexer ); if( eq ) return true; } QString codes = newCodes.join( "\n" ); DaoParser *parser = DaoParser_New(); DaoRoutine *routine = DaoRoutine_New( oldrout->nameSpace, oldrout->routHost, 1 ); routine->routType = oldrout->routType; routine->parCount = oldrout->parCount; routine->attribs = oldrout->attribs; routine->defLine = oldrout->defLine; parser->routine = routine; parser->nameSpace = routine->nameSpace = oldrout->nameSpace; parser->vmSpace = oldrout->nameSpace->vmSpace; DString_Assign( parser->fileName, oldrout->nameSpace->name ); routine->body->codeStart = oldrout->body->codeStart; routine->body->codeEnd = oldrout->body->codeStart + newCodes.size() + 1; parser->regCount = routine->parCount; parser->levelBase = oldrout->defLine != 0; bool res = DaoParser_LexCode( parser, codes.toLocal8Bit().data(), 1 ); for(i=0; i<(int)parser->tokens->size; i++){ parser->tokens->items.pToken[i]->line += routine->body->codeStart; } for(i=0; i<(int)oldrout->body->defLocals->size; i++){ DaoToken *tok = oldrout->body->defLocals->items.pToken[i]; if( tok->index >= oldrout->parCount || tok->type ==0 ) break; MAP_Insert( DList_Top( parser->lookupTables ), & tok->string, i ); DList_Append( routine->body->defLocals, tok ); } res = res && DaoParser_ParseRoutine( parser ); DaoParser_Delete( parser ); if( res == false ){ DaoRoutine_Delete( routine ); return false; } if( (process->stackSize - process->stackTop) < (routine->body->regCount + DAO_MAX_PARAM) ){ DaoProcess_PushFrame( process, routine->body->regCount ); DaoProcess_PopFrame( process ); } DaoType **regTypes = routine->body->regType->items.pType; DaoValue **newValues = process->activeValues; DaoValue **oldValues = (DaoValue**)calloc( oldrout->body->regCount, sizeof(DaoValue*) ); memcpy( oldValues, newValues, oldrout->body->regCount * sizeof(DaoValue*) ); memset( newValues, 0, oldrout->body->regCount * sizeof(DaoValue*) ); DaoProcess_InitTopFrame( process, routine, process->activeObject ); #if 0 DaoStream *stream = DaoStream_New(); DaoRoutine_PrintCode( oldrout, stream ); DaoRoutine_PrintCode( routine, stream ); #endif regmap.clear(); for(i=0; i<oldrout->parCount; i++) regmap[i] = i; DaoVmCode *oldVMC = oldrout->body->vmCodes->data.codes; DaoVmCode *newVMC = routine->body->vmCodes->data.codes; DaoVmCodeX **oldAnnot = oldrout->body->annotCodes->items.pVmc; DaoVmCodeX **newAnnot = routine->body->annotCodes->items.pVmc; int M = oldrout->body->vmCodes->size; int N = routine->body->vmCodes->size; j = k = 0; for(i=0; i<lineMap.size(); i++){ QList<DaoVmCode> oldLineCodes; QList<DaoVmCode> newLineCodes; if( lineMap[i] <0 ) continue; int old = lineMap[i] + oldrout->body->codeStart + 1; int niu = i + routine->body->codeStart + 1; //printf( "%3i %3i: %3i %3i; %3i %3i\n", j, k, i, niu, lineMap[i], old ); while( j<M && oldAnnot[j]->line < old ) ++j; while( k<N && newAnnot[k]->line < niu ) ++k; while( j<M && oldAnnot[j]->line == old ){ oldLineCodes.append( oldVMC[j] ); ++j; } while( k<N && newAnnot[k]->line == niu ){ newLineCodes.append( newVMC[k] ); ++k; } Matching( oldLineCodes, newLineCodes ); } QMap<int,int>::iterator it, end = regmap.end(); for(it=regmap.begin(); it != end; ++it){ j = it.key(); i = it.value(); DaoValue_Move( oldValues[j], & newValues[i], regTypes[i] ); } int offset = 0; if( newEntryLine <0 ){ DaoVmCodeX **annotCodes = oldrout->body->annotCodes->items.pVmc; int entry = (process->activeCode - process->topFrame->codes) + 1; int entryline = oldrout->body->annotCodes->items.pVmc[entry]->line; /* if the entry line is NOT modified, use it */ entryline -= oldrout->body->codeStart + 1; for(i=0; i<lineMap.size(); i++) if( lineMap[i] == entryline ) break; int newEntryLine = i < lineMap.size() ? i : -1; if( newEntryLine >=0 ){ entryline += oldrout->body->codeStart + 1; while( (--entry) >=0 && annotCodes[entry]->line == entryline ) offset ++; } /* if the entry line IS modified, set the entry line to the first modified line */ if( newEntryLine <0 ){ for(i=0; i<lineMap.size(); i++) if( lineMap[i] <0 ) break; newEntryLine = i; } /* if the entry line is manually set: */ newEntryLine += routine->body->codeStart + 1; } //XXX GC_ShiftRC( routine, oldrout ); GC_IncRC( routine ); oldrout->body->revised = routine; process->activeRoutine = routine; process->activeTypes = regTypes; process->topFrame->codes = routine->body->vmCodes->data.codes; ResetExecution( process, newEntryLine, offset ); i = newCodes.size() - routCodes.size(); DaoNS_UpdateLineInfo( routine->nameSpace, routine->body->codeStart, i ); return true; }
void main() { // capture image IplImage* image1 = cvLoadImage(IMAGE_FILE_NAME_1); IplImage* image2 = cvLoadImage(IMAGE_FILE_NAME_2); IplImage* grayImage1 = cvCreateImage(cvGetSize(image1), IPL_DEPTH_8U, 1); IplImage* grayImage2 = cvCreateImage(cvGetSize(image2), IPL_DEPTH_8U, 1); IplImage* resultImage = cvCreateImage(cvSize(image1->width*2, image1->height), IPL_DEPTH_8U, 3); cvCvtColor(image1, grayImage1, CV_BGR2GRAY); cvCvtColor(image2, grayImage2, CV_BGR2GRAY); windage::Algorithms::FeatureDetector* detector = new windage::Algorithms::SIFTGPUdetector(); windage::Algorithms::SearchTree* tree = new windage::Algorithms::FLANNtree(); windage::Algorithms::HomographyEstimator* estimator = new windage::Algorithms::RANSACestimator(); windage::Algorithms::OutlierChecker* checker = new windage::Algorithms::OutlierChecker(); std::vector<windage::FeaturePoint>* feature = NULL; std::vector<windage::FeaturePoint> feature1; std::vector<windage::FeaturePoint> feature2; std::vector<windage::FeaturePoint> matching1; std::vector<windage::FeaturePoint> matching2; tree->SetRatio(0.3); estimator->AttatchReferencePoint(&matching1); estimator->AttatchScenePoint(&matching2); estimator->SetReprojectionError(REPROJECTION_ERRPR); checker->AttatchEstimator(estimator); checker->SetReprojectionError(REPROJECTION_ERRPR); cvNamedWindow("result"); bool processing = true; while(processing) { feature1.clear(); feature2.clear(); matching1.clear(); matching2.clear(); detector->DoExtractKeypointsDescriptor(grayImage1); feature = detector->GetKeypoints(); for(unsigned int i=0; i<feature->size(); i++) { feature1.push_back((*feature)[i]); } detector->DoExtractKeypointsDescriptor(grayImage2); feature = detector->GetKeypoints(); for(unsigned int i=0; i<feature->size(); i++) { feature2.push_back((*feature)[i]); } Matching(tree, &feature1, &feature2, &matching1, &matching2); estimator->Calculate(); checker->Calculate(); cvSetImageROI(resultImage, cvRect(0, 0, image1->width, image1->height)); cvCopyImage(image1, resultImage); cvSetImageROI(resultImage, cvRect(image1->width, 0, image1->width, image1->height)); cvCopyImage(image2, resultImage); cvResetImageROI(resultImage); int count = (int)matching1.size(); for(int i=0; i<count; i++) { double R = (count - i)/(double)count * 255.0; double G = (i+1)/(double)count * 255.0; if(matching1[i].IsOutlier() == false) cvLine(resultImage, cvPoint((int)matching1[i].GetPoint().x, (int)matching1[i].GetPoint().y), cvPoint(image1->width + (int)matching2[i].GetPoint().x, (int)matching2[i].GetPoint().y), CV_RGB(0, 255, 0)); else cvLine(resultImage, cvPoint((int)matching1[i].GetPoint().x, (int)matching1[i].GetPoint().y), cvPoint(image1->width + (int)matching2[i].GetPoint().x, (int)matching2[i].GetPoint().y), CV_RGB(255, 0, 0)); } cvShowImage("result", resultImage); char ch = cvWaitKey(1); switch(ch) { case 's': case 'S': cvSaveImage("FeaturePairMatching.png", resultImage); break; case 'q': case 'Q': case 27: processing = false; break; } } cvDestroyAllWindows(); }
TYPED_TEST_P(BipartiteGraphTest, defaultConstructor) { ASSERT_EQ(this->g.numOfVertices(), 0); ASSERT_EQ(this->g.numOfEdges(), 0); ASSERT_EQ(Matching(), findMaximumMatching(this->g)); }