int rules_callback(int message, void *message_data, void *user_data) { if (message == CALLBACK_MSG_RULE_MATCHING) { YR_RULE* rule = (YR_RULE*) message_data; char* ns = rule->ns->name; if(ns == NULL) { ns = ""; } newMatch(user_data, ns, (char*)rule->identifier); YR_META* meta; yr_rule_metas_foreach(rule, meta) { switch (meta->type) { case META_TYPE_INTEGER: addMetaInt(user_data, (char*)meta->identifier, meta->integer); break; case META_TYPE_STRING: addMetaString(user_data, (char*)meta->identifier, meta->string); break; case META_TYPE_BOOLEAN: addMetaBool(user_data, (char*)meta->identifier, meta->integer); break; } } const char* tag_name; yr_rule_tags_foreach(rule, tag_name) { addTag(user_data, (char*)tag_name); }
//---------------------------------------:move bool Puck::update() { //Update Times float diffTime, currTime; currTime = timeGetTime()/1000.0; diffTime = currTime - t_lastUpdate; t_lastUpdate = currTime; if(goal) // if goal wait for goalsplash then countdown to start new match { if(--goalCountDown<= 0) { newMatch(); goal = false; } } if(--startCountDown==0) speed= SPEED; else if(startCountDown <0) speed += 0.001; else speed = 0.0; /* Update Puck Position */ position[0] += velocity[0]*speed*diffTime; position[2] += velocity[2]*speed*diffTime; /// calculate the reflection here... // bounce off imaginary walls so puck is channelled nicely from player to player // LEFT if(position[0]-radius <= -WALLX){ position[0] = -WALLX+radius; velocity[0] = -(velocity[0])+(0.2*RandFloat()-0.1); velocity[2] = (velocity[2])+(0.1*RandFloat()-0.05); } // RIGHT if(position[0]+radius >= WALLX){ position[0] = WALLX-radius; velocity[0] = -(velocity[0])+(0.2*RandFloat()-0.1); velocity[2] = (velocity[2])+(0.1*RandFloat()-0.05); } if(!goal && goalScored()) { goal = true; speed = 0.0; startCountDown = goalCountDown = 130; } // adjust translation matrix appropriately updatePosition(); return goal; }
void OpenCalaisTextMatchPlugin::slotResult( KJob* job ) { kDebug(); if ( !job->error() ) { // cancel previous worker start m_worker->disconnect( this ); m_worker->cancel(); // restart the worker m_worker->setData( static_cast<OpenCalais::LookupJob*>( job )->resultGraph() ); connect( m_worker, SIGNAL( finished() ), this, SLOT( emitFinished() ) ); connect( m_worker, SIGNAL( newMatch( Scribo::TextMatch ) ), this, SLOT( addNewMatch( Scribo::TextMatch ) ), Qt::QueuedConnection ); m_worker->start(); } else { emitFinished(); } }
//extract blobs, get there 3D position, check which point they correspond to in HashTable void GH::getModelPointsFromImage(const cv::Mat& img, std::vector<DetectionGH> &matches) const { //get blobs vector<KeyPoint> blobs; extractBlobs(img, blobs); //plot them //for(int p=0;p<blobs.size();p++) // cv::circle(img, blobs[p].pt, (blobs[p].size - 1) / 2 + 1, cv::Scalar(255, 0, 0), -1); //get list of points from blob (will have to be removed later as just a copy of blobs) vector<Point2f> mPoints; for(unsigned int p=0;p<blobs.size();p++)mPoints.push_back(toMeters(cameraCalibration.cameraMatrix,blobs[p].pt)); //empty output vectors matches.clear(); //loop through all points for(unsigned int p=0;p<mPoints.size();p++) { //for each point need to accumulate votes from HT float votesId[nbIds]; //init all votes to 0 for(int id=0;id<nbIds;id++) votesId[id]=0; //for each point have to find the nbPtBasis closest points vector<unsigned int> idNeigbors; getClosestNeigbors(p, mPoints, idNeigbors); //for each positively oriented possible triangle in closest neigbors //define basis and project all points on it to fill HT for(unsigned int tp2=0;tp2<idNeigbors.size();tp2++) { //get index of point 2 in mVerticesDes unsigned int p2=idNeigbors[tp2]; //define first basis vector Point2f basis1= mPoints[p2]-mPoints[p]; for(unsigned int tp3=0;tp3<idNeigbors.size();tp3++) if(p2!=idNeigbors[tp3]) { unsigned int p3=idNeigbors[tp3]; //define second basis Point2f basis2= mPoints[p3]-mPoints[p]; //check direction of triangle if(testDirectionBasis(basis1,basis2)) { //put basis in a 2x2 matrix to inverse it and express all other points i this basis Matx22f tBasis(basis1.x,basis2.x,basis1.y,basis2.y); Matx22f tBasisInv=tBasis.inv(); //good basis => project all points and fill HT for(unsigned int i=0;i<mPoints.size();i++) if(i!=p && i!=p2 && i!=p3) { //project in current basis Point2f relCoord=tBasisInv*(mPoints[i]-mPoints[p]); //get bin Point2i bin=toCell(relCoord); //read HT with vote for p if(bin.x>=0 && bin.x<nbBinPerDim.x && bin.y>=0 && bin.y<nbBinPerDim.y) for(int id=0;id<nbIds;id++) votesId[id]+=HashTable[bin.x*(nbBinPerDim.y*nbIds) + bin.y*nbIds + id]; } } } } //if had votes, then find the id with max value int idPointEstim=-1; int nbVotesForId=0; for(int id=0;id<nbIds;id++) if(votesId[id]>nbVotesForId) { idPointEstim=id; nbVotesForId=votesId[id]; } //find second best id to compute discriminative power int idPointSecondBest=-1; (void)idPointSecondBest; int nbVotesForSecondBest=0; for(int id=0;id<nbIds;id++) if(id!=idPointEstim && votesId[id]>nbVotesForSecondBest) { idPointSecondBest=id; nbVotesForSecondBest=votesId[id]; } //add the point&id pair to output if id not already in list; if it is then need to check which one has most votes if(nbVotesForId>0) { std::vector<DetectionGH>::iterator it; it = find_if (matches.begin(), matches.end(), findIdInDetections(idPointEstim)); if (it != matches.end())//point exist, check which one is the best { int posInList=it-matches.begin(); if(matches[posInList].nbVotes<nbVotesForId)//if new one better than existing one, then replace it { matches[posInList].position=blobs[p].pt; matches[posInList].id=idPointEstim; matches[posInList].nbVotes=nbVotesForId; matches[posInList].discriminativePower=nbVotesForId-nbVotesForSecondBest; } } else { DetectionGH newMatch(blobs[p].pt,idPointEstim,nbVotesForId,nbVotesForId-nbVotesForSecondBest); matches.push_back(newMatch); } } } }
void Worker::addNewMatch( const Scribo::TextMatch& match ) { emit newMatch( match ); }
// match a phrase (output of a transition) against the prefix // return a vector of matches with best error (multiple due to different number of prefix words matched) inline vector< Match > MainCaitra::string_edit_distance( int alreadyMatched, const vector< Word > &transition ) { vector< Match > matches; int toMatch = prefix.size() - alreadyMatched; int **cost = (int**) calloc( sizeof( int* ), toMatch+1 ); //for( int j=1; j<=transition.size(); j++ ) //printf("\t%s",surface[transition[ j-1 ]].c_str()); for( int i=0; i<=toMatch; i++ ) { //if (i==0) printf("\n\t\t"); //else printf("\n\t\t%s",surface[prefix[alreadyMatched+i-1]].c_str()); cost[i] = (int*) calloc( sizeof(int), transition.size()+1 ); for( int j=0; j<=transition.size(); j++ ) { if (i==0 && j==0) { // origin cost[i][j] = 0; //printf("\t0"); } else { int lowestError =error_unit * (prefix.size()*2+2); if (i>0) { // deletion lowestError = cost[i-1][j] + error_unit; } if (j>0) { // insertion int thisError = cost[i][j-1] + error_unit; if (thisError < lowestError) { lowestError = thisError; } } if (i>0 && j>0) { // match or subsitution int thisError = cost[i-1][j-1]; if (prefix[ alreadyMatched + i-1 ] != transition[ j-1 ]) { // mismatch -> substitution // ... unless partially matching last prefix token if (! (last_word_may_match_partially && ((alreadyMatched + i-1) == (prefix.size()-1)) && partially_matches_last_token.count( transition[ j-1 ] )) && // ... and unless allowing case-insensitive matching ! (case_insensitive_matching && lowercase_word_match.count( make_pair( prefix[ alreadyMatched + i-1 ], transition[ j-1 ] )))) { // if allowing approximate matching, count as half an error if ((approximate_word_match_threshold > 0.0 && approximate_word_match.count( make_pair( prefix[ alreadyMatched + i-1 ], transition[ j-1 ] ))) || (suffix_insensitive_max_suffix > 0 && suffix_insensitive_word_match.count( make_pair( prefix[ alreadyMatched + i-1 ], transition[ j-1 ] )))) { thisError += 1; } else { // really is a mismatch thisError += error_unit; } } } if (thisError < lowestError) { lowestError = thisError; } } cost[i][j] = lowestError; //printf("\t%d",lowestError); } } } // matches that consumed the prefix for(int j=1; j<transition.size(); j++ ) { Match newMatch( cost[toMatch][j], prefix.size(), j ); matches.push_back( newMatch ); } // matches that consumed the transition for(int i=1; i<=toMatch; i++ ) { Match newMatch( cost[i][transition.size()], alreadyMatched + i, transition.size() ); matches.push_back( newMatch ); } for( int i=0; i<=toMatch; i++ ) { free( cost[i] ); } free( cost ); return matches; }
int main(int argc, char **argv) { if (argc > 1) { Time_Seed = atoi(argv[1]); } init_path(); srand(Time_Seed); std::string config_file; if (!search_path(CONFIG_FILE, config_file)) { DEBUG_ERROR("error loading config file " << CONFIG_FILE); } loadConfig(config_file, &Config_Info); if (glfwInit() != true) { std::cerr << "glfwInit() fail!" << std::endl; return 1; } if (glfwOpenWindow(1000, 600, 8, 8, 8, 8, 8, 8, GLFW_WINDOW) != GL_TRUE) { /* 1000 because the player big timer doesn't show if 800 */ std::cerr << "glfwOpenWindow() fail!" << std::endl; } generalStartup(&Resources_Manager); gameInitialize(); newMatch(); glfwSetWindowTitle("maze rush"); glfwSetWindowSizeCallback(reshape); glfwSetWindowCloseCallback(closeCallback); glfwSetMousePosCallback(mouseMotion); glfwSetMouseButtonCallback(mouseButton); glfwSetKeyCallback(keypressCallback); const double fps = 1/30.0; double lastTime = 0.0; double fpsCountTime = 0.0f; int framesThisSecond = 0; Quit = false; while (!Quit) { pollKeyboard(); double timeNow = glfwGetTime(); if ((timeNow - lastTime) >= fps) { // one "time tick between frames" update(); display(); Quit = (Quit || !glfwGetWindowParam(GLFW_OPENED)); ++framesThisSecond; lastTime = timeNow; } if (timeNow - fpsCountTime >= 1.0) { // one second Current_FPS = framesThisSecond; // global containing the Current_FPS; fpsCountTime = timeNow; framesThisSecond = 0; } } return 0; }
void CmdLoarder::addMatchKey(String key, MATCHHANDLE handle, bool ignoreCase) { Match newMatch(key, handle, ignoreCase); _matchList.push_back(newMatch); }