void cycle_search::find_random_cycle(graph_access & G, std::vector<NodeID> & cycle) { //first perform a bfs starting from a random node and build the parent array std::deque<NodeID>* bfsqueue = new std::deque<NodeID>; NodeID v = random_functions::nextInt(0, G.number_of_nodes()-1); bfsqueue->push_back(v); std::vector<bool> touched(G.number_of_nodes(),false); std::vector<bool> is_leaf(G.number_of_nodes(),false); std::vector<NodeID> parent(G.number_of_nodes(),0); std::vector<NodeID> leafes; touched[v] = true; parent[v] = v; while(!bfsqueue->empty()) { NodeID source = bfsqueue->front(); bfsqueue->pop_front(); bool is_leaf = true; forall_out_edges(G, e, source) { NodeID target = G.getEdgeTarget(e); if(!touched[target]) { is_leaf = false; touched[target] = true; parent[target] = source; bfsqueue->push_back(target); } } endfor if(is_leaf) leafes.push_back(source); }
// StrokeLine BRect Painter::StrokeLine(BPoint a, BPoint b, const pattern& p) { _Transform(&a); _Transform(&b); BRect touched(a, b); // first, try an optimized version float penSize = _Transform(fPenSize); if (penSize == 1.0 && (fDrawingMode == B_OP_COPY || fDrawingMode == B_OP_OVER)) { pattern pat = *fPatternHandler->GetR5Pattern(); if (pat == B_SOLID_HIGH && StraightLine(a, b, fPatternHandler->HighColor().GetColor32())) { SetPenLocation(b); return _Clipped(touched); } else if (pat == B_SOLID_LOW && StraightLine(a, b, fPatternHandler->LowColor().GetColor32())) { SetPenLocation(b); return _Clipped(touched); } } agg::path_storage path; path.move_to(a.x, a.y); path.line_to(b.x, b.y); touched = _StrokePath(path, p); SetPenLocation(b); return _Clipped(touched); }
void ScrollMenu::fingerUpdated(const FingerEventArgs &e) { assert(modelview != NULL); if(touched != NULL) { touched(); } float axisOffset = (scrollDirection == VERTICAL) ? dAxis - e.getY() : dAxis - e.getX(); axisOffset /= modelview->getXScale(); int difference = (int)(axisOffset / itemDim); if(difference != 0) { index += difference; if(index < 0) { index = 0; } else if(index > (int)(itemCount - displayCount)) { index = itemCount - displayCount; } dAxis = (scrollDirection == VERTICAL) ? e.getY() : e.getX(); moved = true; } selected = false; dirty = true; }
void ScrollMenu::fingerRemoved(const FingerEventArgs &e) { if(touched != NULL) touched(); fingerDown = false; selected = false; dirty = true; }
const unsigned char * RadioButton::getGfxData() { int offset = 0; if (selected()) offset |= 1; if (touched()) offset |= 2; return (const u8*)&radiobutton_imgTiles[8*8*offset]; }
/* PUBLIC MEMBER FUNCTIONS */ void ScrollMenu::fingerAdded(const FingerEventArgs &e) { if(touched != NULL) touched(); down = e.getPosition(); dAxis = (scrollDirection == VERTICAL) ? e.getY() : e.getX(); fingerDown = true; moved = false; selected = false; }
/**************************************************************************//** * @brief Wait for touchscreen tap * @return Touchscreen tap position *****************************************************************************/ static POINT getTouchTapSample10bit( void ) { POINT sample = { 0, 0 }; for (;;) { if ( touched() ) { sample = getTouchSample10bit(); while ( touched() ) { delayMs( 25 ); } break; } delayMs( 25 ); } return sample; }
void Message::doubleClickedData() { if(!msg_hanging) { msg_send_box->setStyleSheet("background-color: red;color: yellow;"); msg_rcv_box->setStyleSheet("background-color: red;color: yellow;"); if(!msg_preserve_text) { msg_hang_text=msg_rcv_box->text(); msg_rcv_box->setText("<center><font size=\"36\"><br>Look Up!</font></center>"); } // msg_backdrop_label->show(); msg_hang_timer->start(msg_hang_time,true); msg_hanging=true; emit touched(); } }
void dynamics_mul::compute_intensity_force(){ HMesh::HalfEdgeAttributeVector<int> touched(s_dsc->get_no_halfedges(), 0); for (auto eit = s_dsc->halfedges_begin(); eit != s_dsc->halfedges_end(); eit++) { if(s_dsc->is_interface(*eit) and !touched[*eit]){ auto hew = s_dsc->walker(*eit); double c0 = mean_inten_[s_dsc->get_label(hew.face())]; double c1 = mean_inten_[s_dsc->get_label(hew.opp().face())]; // Loop on the edge auto p0 = s_dsc->get_pos(hew.opp().vertex()); auto p1 = s_dsc->get_pos(hew.vertex()); Vec2 L01 = p1 - p0; L01.normalize(); Vec2 N01(L01[1], -L01[0]); // Outward pointing normal int length = (int)(p1 - p0).length(); double f0 = 0.0, f1 = 0.0; Vec2 fg0(0.0), fg1(0.0); for (int i = 0; i <= length; i++) { auto p = p0 + (p1 - p0)*(double(i)/(double)length); double I = s_img->get_intensity(p[0], p[1]); // Normalize force int normalizedF = 1; double f ; switch (normalizedF) { case 1: f = ( (c0-c1)*(2*I - c0 - c1)) / ((c0-c1)*(c0-c1)); break; case 2: f = ( (c0-c1)*(2*I - c0 - c1)) / std::abs((c0 - c1)); break; case 3: f = (c0-c1)*(2*I - c0 - c1); break; default: f = 0.0; break; } Vec2 fu = N01*(c0-c1)*(2*I - c0 - c1); // Image gradient force int lengthM = 10; Vec2 gm(0.0); double max_grad = 0; for (int l = 0; l < lengthM; l++) { Vec2 curPt = p + fu*(l/(double)(lengthM)); Vec2 gg = s_img->grad((int)curPt[0], (int)curPt[1]); if (max_grad < gg.length()) { max_grad = gg.length(); gm = gg*(lengthM - l)/(double)lengthM; } } Vec2 fg = gm*(2*I - c0 - c1); Vec2 fv = (fu + fg)/((c0-c1)*(c0-c1)); fg0 += fv*(p-p1).length() / (double)length; fg1 += fv*(p-p0).length() / (double)length; // Barry Centric coordinate f0 += f*(p-p1).length() / (double)length; f1 += f*(p-p0).length() / (double)length; // Image gradient force // Vec2 fg = s_img->grad((int)p[0], (int)p[1]) * (2*I - c0 - c1) / ((c0-c1)*(c0-c1)); // fg0 += fg*(p-p1).length() / (double)length; // fg1 += fg*(p-p0).length() / (double)length; } // Set force Vec2 f_x0 = fg0; // N01*f0; Vec2 f_x1 = fg1; // N01*f1; s_dsc->add_node_external_force(hew.opp().vertex(), f_x0*g_param.beta); s_dsc->add_node_external_force(hew.vertex(), f_x1*g_param.beta); // Avoid retouch the edge touched[*eit] = 1; touched[hew.opp().halfedge()] = 1; } } }
int main(int argc, char* argv[]) { /* INITIALISATIONS DES BIBLIOTHEQUES : IMG, SDL, TTF */ IMG_Init(IMG_INIT_PNG); SDL_Init(SDL_INIT_VIDEO); TTF_Init(); Message msgs[NOMBRE_MESSAGES]; initMessage(msgs); SDL_Surface *ecran = SDL_SetVideoMode(LARGEUR, HAUTEUR, BPP, SDL_HWSURFACE | SDL_DOUBLEBUF); /* Titre */ SDL_WM_SetCaption("Duck Hunt", NULL); /* Icone */ SDL_WM_SetIcon(SDL_LoadBMP("sprites/icon.bmp"), NULL); /* Initialisation des variables en rapport avec le temps */ Time temps; initTime(temps); srand((unsigned)time(NULL)); int modeJeu = 0; // Le mode de jeu. int modeMenu = 1; // Détermine la page du menu à afficher. Partie partie; partie.score = 0; partie.niveau = 0; Sprites sprites; Chien chien; Boutons boutons; initBouton(boutons); chargerImages(sprites, chien, boutons, "classique"); boutons.bouton[BOUTON_THEME_CLASSIQUE].actif = true; Uint8 *keystate = SDL_GetKeyState(NULL); SourisEvent sourisEvent; initSourisEvent(sourisEvent); initFichiers(); SDL_ShowCursor(SDL_DISABLE); menu(ecran, sprites, boutons, modeMenu, modeJeu, sourisEvent, temps, msgs, partie, chien); while (modeJeu != 0) { if (modeMenu != 0) { menu(ecran, sprites, boutons, modeMenu, modeJeu, sourisEvent, temps, msgs, partie, chien); } temps.currentTime = SDL_GetTicks(); partie.alreadyShot = partie.alreadyGetEvent = partie.alreadyClic = false; for (int i = 0 ; i < sprites.canardActifs ; i++) { shoot(sourisEvent, sprites.canard[i], partie, temps, modeJeu); if ((temps.currentTime >= sprites.canard[i].vitesseTime + sprites.canard[i].vitesse)) { mouvementsCanard(sprites.canard[i]); detectionBordsCanard(sprites.canard[i], partie, i); changementDirection(sprites.canard[i]); if(sprites.canard[i].etat == TOUCHED) { touched(sprites.canard[i], temps); } sprites.canard[i].vitesseTime = temps.currentTime; } if (temps.currentTime >= sprites.canard[i].vitesseAnimationTime + sprites.canard[i].vitesseAnimation) { switchSpriteCanard(sprites.canard[i]); sprites.canard[i].vitesseAnimationTime = temps.currentTime; } } if(partie.shots <= 0) { for(int i = 0 ; i < sprites.canardActifs ; i++) { canardSurvivant(sprites, partie, i); } } if (temps.currentTime >= chien.vitesseAnimationTime + chien.vitesseAnimation) { switchSpriteChien(chien, partie); controlesChien(chien, partie, sprites); ramasserCanard(chien, partie, sprites); chien.vitesseAnimationTime = temps.currentTime; ramasserCanard(chien, partie, sprites); } if(partie.relancer) { relancerPartie(partie, sprites); } if(partie.round >= 5) { if(finPartie(partie)) { if (testHighScore("scoresClassic", partie)) { modeMenu = 8; } else { modeMenu = 9; } } else { partie.round = 0; partie.niveau ++; initPartie(partie, sprites.canardActifs); partie.jeu = true; for (int i=0; i<sprites.canardActifs; i++) { initCanard(sprites.canard[i], partie); } initTableau(partie.tableauChasse, sprites); modeMenu = 6; } } if (keystate[SDLK_ESCAPE]) { modeMenu = 5; } if (temps.currentTime >= temps.timeFps + temps.fpsTime) { genererRendu(ecran, sprites, sourisEvent, partie, chien, msgs); SDL_Flip(ecran); temps.timeFps = temps.currentTime; } SDL_Delay(1); } libererImages(sprites, chien, boutons); SDL_Quit(); IMG_Quit(); TTF_Quit(); return EXIT_SUCCESS; }
// METHODS void collide( Beast* b ){ touched( b->aggro() ); b->touched( m_aggro ); }
VOID PrintUntouchedRanges(SEC sec) { // Make a bool vector big enough to describe the whole section, 1 bool per byte vector<bool> touched(SEC_Size(sec)); // Put the rtn's that are touched in a set set<RTN> rtnSet; // Mark the ranges for bbls that have been executed for (list<const BBLSTATS*>::const_iterator bi = statsList.begin(); bi != statsList.end(); bi++) { const BBLSTATS * stats = *bi; // Is this bbl contained in the section? if (stats->_start < SEC_Address(sec) || stats->_start >= SEC_Address(sec) + SEC_Size(sec)) continue; // Is the bbl executed? if (!stats->_executed) continue; RTN rtn = RTN_FindByAddress(stats->_start); if (RTN_Valid(rtn)) rtnSet.insert(rtn); // Mark all the bytes of the bbl as executed for (ADDRINT i = stats->_start - SEC_Address(sec); i < stats->_start + stats->_size - SEC_Address(sec); i++) { ASSERTX(i < SEC_Size(sec)); touched[i] = true; } } // Print the routines that are not touched out << " Routines that are not executed" << endl; for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn)) { if (rtnSet.find(rtn) == rtnSet.end()) { out << " " << RTN_Name(rtn) << endl; } } // Print the ranges of untouched addresses out << " Code ranges that are not executed" << endl; string rtnName = ""; for (UINT32 i = 0; i < SEC_Size(sec);) { // Find the first not touched address while(touched[i]) { i++; if (i == SEC_Size(sec)) return; } UINT32 start = i; // Find the first touched address while(!touched[i] && i < SEC_Size(sec)) i++; ADDRINT startAddress = SEC_Address(sec) + start; // Print the rtn name, if it has changed IMG img = IMG_FindByAddress(startAddress); string imgName = (IMG_Valid(img) ? IMG_Name(img) : "InvalidImg"); RTN rtn = RTN_FindByAddress(startAddress); string newName = (RTN_Valid(rtn) ? RTN_Name(rtn) : "InvalidRtn"); if (rtnName != newName) { out << " Image: " << imgName << " Rtn: " << newName << endl; rtnName = newName; } out << " " << SEC_Address(sec) + start << ":" << SEC_Address(sec) + i - 1 << endl; } }
bool chessboard_coloring::run(viennamesh::algorithm_handle &) { viennamesh::info(1) << name() << std::endl; //get input mesh and create output mesh mesh_handle input_mesh = get_required_input<mesh_handle>("mesh"); mesh_handle output_mesh = make_data<mesh_handle>(); //Typedefs typedef viennagrid::mesh MeshType; // typedef viennagrid::result_of::element<MeshType>::type VertexType; typedef viennagrid::result_of::element<MeshType>::type EdgeType; typedef viennagrid::result_of::element<MeshType>::type TriangleType; //typedef viennagrid::result_of::element_range<MeshType, 0>::type VertexRange; typedef viennagrid::result_of::element_range<MeshType, 2>::type TriangleRange; typedef viennagrid::result_of::iterator<TriangleRange>::type TriangleIterator; typedef viennagrid::result_of::neighbor_range<MeshType, 1, 2>::type TriangleNeighborRangeType; typedef viennagrid::result_of::iterator<TriangleNeighborRangeType>::type TriangleNeighborIterator; //get number of vertices and triangles int num_vertices = viennagrid::vertex_count(input_mesh()); int num_triangles = viennagrid::element_count(input_mesh(), 2); /* viennamesh::info(2) << "Number of vertices in mesh : " << num_vertices << std::endl; viennamesh::info(2) << "Number of triangles in mesh: " << num_triangles << std::endl; */ //set up accessor std::vector<bool> color_triangles(num_triangles, false); std::vector<bool> touched (num_triangles, false); viennagrid::result_of::accessor<std::vector<bool>, TriangleType>::type color_accessor(color_triangles); //set first element to color "black" (BOOL = TRUE) color_accessor.set(viennagrid::cells(input_mesh())[0], true); //iterate triangles in mesh TriangleRange triangles(input_mesh()); //Iterate over all triangles in the mesh viennagrid_element_id * triangle_ids_begin; viennagrid_element_id * triangle_ids_end; viennagrid_dimension topological_dimension = viennagrid::cell_dimension( input_mesh() ); viennagrid_element_id * neighbor_begin; viennagrid_element_id * neighbor_end; viennagrid_dimension connector = 1; viennagrid_mesh_elements_get(input_mesh().internal(), topological_dimension, &triangle_ids_begin, &triangle_ids_end); viennagrid::quantity_field color_field(2,1); // viennagrid_quantity_field_create(&color_field); color_field.set_name("color"); //viennagrid_quantity_field_init(color_field, 2, VIENNAGRID_QUANTITY_FIELD_TYPE_NUMERIC, 1 , VIENNAGRID_QUANTITY_FIELD_STORAGE_DENSE); //get triangles from mesh for (viennagrid_element_id *tri = triangle_ids_begin; tri != triangle_ids_end; ++tri) { int tri_index = viennagrid_index_from_element_id( *tri ); //std::cout << tri_index << std::endl; if ( !touched[tri_index]) { //color_accessor.set(viennagrid::cells(input_mesh())[tri_index], true); color_triangles[tri_index] = true; touched[tri_index] = true; double clr = 1; color_field.set(*tri, clr); viennagrid_element_neighbor_elements(input_mesh().internal(), *tri, 0, 2, &neighbor_begin, &neighbor_end); for (viennagrid_element_id *n_tri = neighbor_begin; n_tri != neighbor_end; ++n_tri) { int n_tri_index = viennagrid_index_from_element_id( *n_tri ); //std::cout << " " << n_tri_index << std::endl; viennagrid_element_id * n_neighbor_begin; viennagrid_element_id * n_neighbor_end; viennagrid_element_neighbor_elements(input_mesh().internal(), *n_tri, 0, 2, &n_neighbor_begin, &n_neighbor_end); for (viennagrid_element_id *n_n_tri = n_neighbor_begin; n_n_tri != n_neighbor_end; ++n_n_tri) { int n_n_tri_index = viennagrid_index_from_element_id( *n_n_tri ); if ( !touched[n_n_tri_index]) { //color_accessor.set(viennagrid::cells(input_mesh())[n_tri_index], false); touched[n_n_tri_index] = true; clr = 0; color_field.set(*n_n_tri, clr); } } } } } output_mesh = input_mesh; quantity_field_handle quantities = make_data<viennagrid::quantity_field>(); quantities.set(color_field); set_output("color_field", quantities); set_output("mesh", output_mesh()); return true; } //end of bool chessboard_coloring::run(viennamesh::algorithm_handle &)
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { uint32_t buttons; POINT touchSample, P[ 3 ]; ADC_Init_TypeDef init = ADC_INIT_DEFAULT; /* Configure for 48MHz HFXO operation of core clock */ CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); /* Initialize DK board register access */ BSP_Init(BSP_INIT_DEFAULT); /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable( cmuClock_ADC0, true); /* Max ADC clock is 13MHz, use 14MHz/(1+1) or 48MHz/(5+1) */ init.prescale = 5; ADC_Init(ADC0, &init); sInit.reference = adcRefVDD; /* Set frame buffer start address */ frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2); /* Make sure CYCCNT is running, needed by delay functions. */ DWT_CTRL |= 1; /* Indicate we are waiting for AEM button state enabling EFM */ BSP_LedsSet(0x8001); while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM) { /* Show a short "strobe light" on DK LEDs, indicating wait */ BSP_LedsSet(0x8001); delayMs(200); BSP_LedsSet(0x4002); delayMs(50); } /* Initialize touch screen calibration factor matrix with approx. values */ setCalibrationMatrix( (POINT*)&lcdCalibPoints, /* Display coordinates */ (POINT*)&touchCalibPoints, /* Touch coordinates */ &calibFactors ); /* Calibration factor matrix */ while (1) { if ( TFT_DirectInit(&tftInit) ) { displayHelpScreen(); BSP_LedsSet(0x0000); BSP_PeripheralAccess(BSP_TOUCH, true); GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0); GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0); do { buttons = readButtons(); /* Draw on screen */ if ( buttons & BC_UIF_PB1 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ do { if ( touched() ) { touchSample = getTouchSample(); drawPixel( touchSample.x, touchSample.y, COLOR ); } delayMs( 2 ); buttons = readButtons() & ~BC_UIF_PB1; } while ( buttons == 0 ); } /* Calibrate touch screen */ else if ( buttons & BC_UIF_PB2 ) { memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR ); TFT_DrawString(30, 35, "Tap green marker" ); P[ 0 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR ); TFT_DrawString(40, 130, "Tap green marker" ); P[ 1 ] = getTouchTapSample10bit(); memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR ); TFT_DrawString(20, 180, "Tap green marker" ); P[ 2 ] = getTouchTapSample10bit(); setCalibrationMatrix( (POINT*)&lcdCalibPoints,/* Display coordinates*/ &P[0], /* Touch coordinates */ &calibFactors ); /* Calibration factor matrix*/ memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT ); /* Clear screen */ TFT_DrawString(10, 100, "The touch screen is" ); TFT_DrawString(30, 130, "now calibrated !" ); } /* Display help screen */ else if ( buttons & BC_UIF_PB3 ) { displayHelpScreen(); while ( readButtons() & BC_UIF_PB3 ) {} } } while ( ( buttons & EXIT_LOOP ) == 0 ); } else { BSP_LedsSet(0x8001); delayMs(200); } } }