void GolPattern::evolve( ) { Cells maybes; // Update adjacence for( Cells::iterator it = mAlives.begin(); it != mAlives.end(); ++it ) { for( int i = 0; i < 8; ++i ) { Vecteur2i c = it->first + deltaPosAround[i]; if( mAlives.find( c ) != mAlives.end() ) { ++it->second; } else { // update maybes Cells::iterator it2 = maybes.find( c ); if( it2 == maybes.end() ) { maybes[c] = 1; } else { ++it2->second; } } } } // kill cells for( Cells::iterator it = mAlives.begin(); it != mAlives.end(); /* no increment */ ) { const int adj = it->second; if( (unsigned int)( adj - 2 ) > 1 ) // only if adj is 2 or 3 { mAlives.erase( it++ ); } else { // reset it->second = 0; ++it; } } // resume life for( Cells::const_iterator it = maybes.begin(); it != maybes.end(); ++it ) { const int adj = it->second; if( adj == 3 ) // only if adj is 3 { mAlives[it->first] = 0; } } maybes.clear(); }
std::set<Cell> tileCells (const nm::MapMetaData& info, const float d, const Pred& pred) { ROS_DEBUG_NAMED ("tile", "Tiling %ux%u map", info.height, info.width); Cells cells; Cells forbidden; int rad = ceil(d/info.resolution); for (size_t x=0; x<info.width; x++) { for (size_t y=0; y<info.height; y++) { const Cell c(x, y); if (!pred(c)) continue; ROS_DEBUG_STREAM_NAMED("tile", "Cell " << c << " satisfies condition"); if (forbidden.find(c)!=forbidden.end()) continue; ROS_DEBUG_STREAM_NAMED ("tile", " Sufficiently far"); cells.insert(c); ROS_DEBUG_STREAM_NAMED ("tile", " Inserted"); for (int dx=0; dx<=rad; dx++) { for (int dy=-rad; dy<=rad; dy++) { const Cell c2(int(x)+dx, int(y)+dy); if (dx*dx+dy*dy <= rad*rad && withinBounds(info, c2)) { ROS_DEBUG_STREAM_NAMED ("tile", " Blocking " << c2); forbidden.insert(c2); } } } } } ROS_DEBUG_NAMED("tile", "Done tiling"); return cells; }