void Pokedex::freePokemon(int pokemonID) { if (pokemonID <= 0) { throw InvalidInput(); } Pokemon pokemon(pokemonID, NO_POKEMON, NO_POKEMON); avlNode<Pokemon, pokemonCompareByID>* pokemonNode = mainIdTree.find( pokemon); if (!pokemonNode) { throw Failure(); } Pokemon toRemove(pokemonID, pokemonNode->getData().getTrainerId(), pokemonNode->getData().getLevel()); bool status = mainIdTree.remove(toRemove); if (!status) { throw Failure(); } bool status2 = mainLevelTree.remove(toRemove); if (!status2) { throw Failure(); } int trainerID = toRemove.getTrainerId(); Iterator<Trainer> trainer = trainers.find(TrainerCompare(trainerID)); bool status3 = (*trainer).getIdTree().remove(toRemove); if (!status3) { throw Failure(); } bool status4 = (*trainer).getLevelTree().remove(toRemove); if (!status4) { throw Failure(); } (*trainer).updateMax(); this->updateMax(); }
void ProjectBuild::clean() { cmd->showM(); cmd->clearAll(); for(int i = 0; i<paths.size(); i++) { cmd->addLine("Cleaning " + paths.at(i), Qt::black); QDir toRemove(paths.at(i)); StaticMethods::removeDirectory(toRemove); cmd->addLine("Done!", Qt::black); } }
void GroupSelectedItems() { LIST<_TREEITEM> toRemove(1); intlist ids; bool selected = false; HTREEITEM hPlace = NULL; // Find items HTREEITEM hItem = m_tree.GetRoot(); TVITEMEX tvi = { 0 }; tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT | TVIF_STATE; while (hItem) { if (m_tree.IsSelected(hItem)) { if (hPlace == NULL) hPlace = hItem; tvi.hItem = hItem; m_tree.GetItem(&tvi); intlist *iids = (intlist*)tvi.lParam; for (int i = 0; i < iids->count; i++) ids.add(iids->data[i]); if ((tvi.state & INDEXTOSTATEIMAGEMASK(3)) == INDEXTOSTATEIMAGEMASK(2)) selected = true; toRemove.insert(hItem); } hItem = m_tree.GetNextSibling(hItem); } if (hPlace != NULL) { // Add new HTREEITEM hNew = Tree_AddExtraIconGroup(ids, selected, hPlace); // Remove old for (int i = 0; i < toRemove.getCount(); i++) { delete Tree_GetIDs(toRemove[i]); m_tree.DeleteItem(toRemove[i]); } // Select m_tree.UnselectAll(); m_tree.SelectItem(hNew); } }
std::vector<ClientPtr> GameWorld::processClients() { std::vector<ClientPtr> toRemove(0); // process clients for(ClientList::const_iterator itor = _clients.begin(); itor != _clients.end(); ){ ClientPtr client = *itor; TCPMessagePtr result = client->processClient(); if (result->type == TCPMessage::MSG_QUIT || result->type == TCPMessage::MSG_DISCONNECT) { std::cout << "Client " << client->getId() << " quit " << ( result->type == TCPMessage::MSG_DISCONNECT ? "abnormally" : "" ) << "\n"; toRemove.push_back(client); // broadcast to clients if they saw it before if (client->isLoggedIn()){ broadcastMessage( TCPMessage( TCPMessage::MSG_PLAYER_LEFT, client->getCurrentCharacter()->getName() ), client.get() ); } // save the account data client->save(); // remove from list itor = _clients.erase(itor); } else{ // send message to other clients if (result->type == TCPMessage::MSG_CHAT){ broadcastMessage(result); } else if (result->type == TCPMessage::MSG_SELECT_CHAR){ // character selected { // send the map to the player int mapSizes[] = { MAP_MAX_WIDTH, MAP_MAX_HEIGHT }; TCPMessagePtr msg = TCPMessage::createMessage(TCPMessage::MSG_MAP, mapSizes, 2, std::string(_mapData.contents().begin(), _mapData.contents().end())); msg->sendToSocket(client->getSocket()); } if ( _clients.size() > 1 ) { // send the existing players list (except us) std::string playerStr; playerStr += ( _clients.size() - 1 ); for ( ClientList::const_iterator it = _clients.begin(); it != _clients.end(); ++it) { ClientPtr other = *it; if ( other != client && other->isLoggedIn() ) { int data[] = { other->getCurrentCharacter()->position().x, other->getCurrentCharacter()->position().y, other->getCurrentCharacter()->level() }; std::string tmpStr; tmpStr += other->getCurrentCharacter()->getClass(); tmpStr += other->getCurrentCharacter()->getName(); playerStr += TCPMessage::createMessage(TCPMessage::MSG_LIST_PLAYERS, data, 3, tmpStr)->data; playerStr += '\0'; } } TCPMessage playersMsg( TCPMessage::MSG_LIST_PLAYERS, playerStr ); playersMsg.sendToSocket( client->getSocket() ); } { // announce the players about the new player miniui::vec2 position = client->getCurrentCharacter()->position(); std::string tmpStr; tmpStr += client->getCurrentCharacter()->getClass(); tmpStr += client->getCurrentCharacter()->getName(); int data[] = { position.x, position.y, client->getCurrentCharacter()->level() }; TCPMessagePtr joinMsg = TCPMessage::createMessage(TCPMessage::MSG_PLAYER_JOINED, data, 3, tmpStr); broadcastMessage(joinMsg, client.get()); } } ++itor; } } return toRemove; }
bool DetectPolygons::processFrameContainer(BaseFrameContainer *frm, BaseFrameSource *frameSource) { Shapes* shapes = frm->getShapes(); std::vector<Point> approxCurve; unsigned int size = 0; ///for each contour, analyze if it is a paralelepiped likely to be the marker for (unsigned int i=0;i<shapes->getContours().size();i++) { unsigned int contourSize = shapes->getContours()[i].size(); //check it is a possible element by first checking is has enough points if (contourSize>(unsigned int)(frm->getFrame()->getMat().cols /15)) { //approximate to a polygon - 1. limit slozitosti (pocet bodu krat cislo vs konstanta), 2. uzavreny double complexity = double(contourSize)*complexityKoef; complexity = complexity > maxComplexity ? maxComplexity : (complexity < minComplexity ? minComplexity : complexity); cv::approxPolyDP( cv::Mat (shapes->getContours()[i]),approxCurve , complexity , onlyClosed); size = approxCurve.size(); unsigned int one, two; if (approxCurve.size() >= 3) { // remove inline points for (unsigned int i = 0; i < size; i++) { one = (i + 1)%size; two = (i + 2)%size; // rozdil smernic double x1 = approxCurve[i].x, y1 = approxCurve[i].y, x2 = approxCurve[one].x, y2 = approxCurve[one].y, x3 = approxCurve[two].x, y3 = approxCurve[two].y; float k = std::abs(((y2-y1)/(x2-x1)) - ((y3-y1)/(x3-x1))); float d1 = std::sqrt((float) (approxCurve[i].x-approxCurve[one].x)*(approxCurve[i].x-approxCurve[one].x) + (approxCurve[i].y-approxCurve[one].y)*(approxCurve[i].y-approxCurve[one].y)); float d2 = std::sqrt((float) (approxCurve[i].x-approxCurve[two].x)*(approxCurve[i].x-approxCurve[two].x) + (approxCurve[i].y-approxCurve[two].y)*(approxCurve[i].y-approxCurve[two].y)); // if angle is too small or points are too close if (k < 0.2 || d1 < 0.04*d2) { approxCurve.erase(approxCurve.begin()+one); size--; } } } if (size >= minimalPolygonLines && size <= maximalPolygonLines) { //and is convex if (!onlyConvex || cv::isContourConvex(Mat (approxCurve))) { float minDist=1e10; if (minDistance > 0) { for (int i=0;i<size;i++) { float d= std::sqrt((float) (approxCurve[i].x-approxCurve[(i+1)%size].x)*(approxCurve[i].x-approxCurve[(i+1)%size].x) + (approxCurve[i].y-approxCurve[(i+1)%size].y)*(approxCurve[i].y-approxCurve[(i+1)%size].y)); if (d<minDist) minDist=d; } } if (minDist>=minDistance) { shapes->getMarkers().push_back(Marker()); for (unsigned int i=0;i<size;i++) { shapes->getMarkers().back().push_back( Point2f(approxCurve[i].x,approxCurve[i].y)); } } } } } } /// remove these elements whise corners are too close to each other //first detect candidates size = shapes->getMarkers().size(); if (minimalPolygonLines==4 && maximalPolygonLines == 4) { for (unsigned int i=0;i<shapes->getMarkers().size();i++) { //trace a line between the first and second point. //if the thrid point is at the right side, then the points are anti-clockwise double dx1 = shapes->getMarkers()[i][1].x - shapes->getMarkers()[i][0].x; double dy1 = shapes->getMarkers()[i][1].y - shapes->getMarkers()[i][0].y; double dx2 = shapes->getMarkers()[i][2].x - shapes->getMarkers()[i][0].x; double dy2 = shapes->getMarkers()[i][2].y - shapes->getMarkers()[i][0].y; double o = (dx1*dy2)-(dy1*dx2); if (o < 0.0) //if the third point is in the left side, then sort in anti-clockwise order { swap(shapes->getMarkers()[i][1],shapes->getMarkers()[i][3]); } } } vector<pair<int,int> > TooNearCandidates; for (unsigned int i=0;i < size;i++) { // cout<<"Marker i="<<i<<MarkerCanditates[i]<<endl; //calculate the average distance of each corner to the nearest corner of the other marker candidate for (unsigned int j=i+1;j<size;j++) { unsigned int vertexCount = shapes->getMarkers()[i].size(); if (vertexCount == shapes->getMarkers()[j].size()) { float dist=0; for (unsigned int c=0;c<vertexCount;c++) dist+= std::sqrt( (shapes->getMarkers()[i][c].x-shapes->getMarkers()[j][c].x)*(shapes->getMarkers()[i][c].x-shapes->getMarkers()[j][c].x)+(shapes->getMarkers()[i][c].y-shapes->getMarkers()[j][c].y)*(shapes->getMarkers()[i][c].y-shapes->getMarkers()[j][c].y)); dist/=vertexCount; //if distance is too small if (dist< 14) { TooNearCandidates.push_back(pair<int,int>(i,j)); } } } } //mark for removal the element of the pair with smaller perimeter vector<bool> toRemove (shapes->getMarkers().size(),false); for (unsigned int i=0;i<TooNearCandidates.size();i++) { if ( perimeter(shapes->getMarkers()[TooNearCandidates[i].first ])>perimeter(shapes->getMarkers()[ TooNearCandidates[i].second] )) toRemove[TooNearCandidates[i].second]=true; else toRemove[TooNearCandidates[i].first]=true; } //remove the invalid ones removeElements(shapes->getMarkers(),toRemove); return true; }
bool UsdGeomPointInstancer::ActivateIds(VtInt64Array const &ids) const { std::vector<int64_t> toRemove(ids.begin(), ids.end()); return _SetOrMergeOverOp(toRemove, SdfListOpTypeDeleted, GetPrim()); }
bool UsdGeomPointInstancer::ActivateId(int64_t id) const { std::vector<int64_t> toRemove(1, id); return _SetOrMergeOverOp(toRemove, SdfListOpTypeDeleted, GetPrim()); }
static bool _SetOrMergeOverOp(std::vector<int64_t> const &items, SdfListOpType op, UsdPrim const &prim) { SdfInt64ListOp proposed, current; UsdStagePtr stage = prim.GetStage(); UsdEditTarget editTarget = stage->GetEditTarget(); SdfPrimSpecHandle primSpec = editTarget.GetPrimSpecForScenePath(prim.GetPath()); if (primSpec){ VtValue existingOp = primSpec->GetInfo(UsdGeomTokens->inactiveIds); if (existingOp.IsHolding<SdfInt64ListOp>()){ current = existingOp.UncheckedGet<SdfInt64ListOp>(); } } proposed.SetItems(items, op); if (current.IsExplicit()){ std::vector<int64_t> explicitItems = current.GetExplicitItems(); proposed.ApplyOperations(&explicitItems); current.SetExplicitItems(explicitItems); } else { // We can't use ApplyOperations on an extant, non-explicit listOp // because the result is always flat and explicit. current.ComposeOperations(proposed, op); // ComposeOperations() is too narrow in functionality - it does not // consider that if we "remove over" an existing set of added items, // we need to additionally ensure the removed items get removed // from the added in current, since when applying ops, we first // remove, then add. Bug #139215 filed to track; when it gets fixed // we can remove this code! if (op == SdfListOpTypeDeleted){ std::vector<int64_t> addedItems = current.GetAddedItems(); if (!addedItems.empty()){ std::set<int64_t> toRemove(items.begin(), items.end()); std::vector<int64_t> newAdded; newAdded.reserve(addedItems.size()); for (auto elt : addedItems){ if (!toRemove.count(elt)) newAdded.push_back(elt); } if (newAdded.size() != addedItems.size()) current.SetAddedItems(newAdded); } } else if (op == SdfListOpTypeAdded){ std::vector<int64_t> deletedItems = current.GetDeletedItems(); if (!deletedItems.empty()){ std::set<int64_t> toAdd(items.begin(), items.end()); std::vector<int64_t> newDeleted; newDeleted.reserve(deletedItems.size()); for (auto elt : deletedItems){ if (!toAdd.count(elt)) newDeleted.push_back(elt); } if (newDeleted.size() != deletedItems.size()) current.SetDeletedItems(newDeleted); } } } return prim.SetMetadata(UsdGeomTokens->inactiveIds, current); }
void MarkerDetector::recognizeMarkers(const cv::Mat& grayscale, std::vector<Marker>& detectedMarkers) { std::vector<Marker> goodMarkers; // Identify the markers for (size_t i=0;i<detectedMarkers.size();i++) { Marker& marker = detectedMarkers[i]; // Find the perspective transformation that brings current marker to rectangular form //cv::Mat markerTransform = cv::getPerspectiveTransform(marker.points, m_markerCorners2d); cv::Mat markerTransform = cv::findHomography(marker.points, m_markerCorners2d); // Transform image to get a canonical marker image cv::warpPerspective(grayscale, canonicalMarkerImage, markerTransform, cv::Size(markerLength,markerLength)); int nRotations; int id = Marker::getMarkerId(canonicalMarkerImage, nRotations); if (id !=- 1) { marker.id = id; //sort the points so that they are always in the same order no matter the camera orientation std::rotate(marker.points.begin(), marker.points.begin() + 4 - nRotations, marker.points.end()); goodMarkers.push_back(marker); } } // Refine marker corners using sub pixel accuracy if (goodMarkers.size() > 0) { std::vector<cv::Point2f> preciseCorners(4 * goodMarkers.size()); for (size_t i=0; i<goodMarkers.size(); i++) { const Marker& marker = goodMarkers[i]; for (int c = 0; c <4; c++) { preciseCorners[i*4 + c] = marker.points[c]; } } //cv::TermCriteria termCriteria = cv::TermCriteria(cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, 30, 0.01); //cv::TermCriteria termCriteria = cv::TermCriteria(cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, 3, 0.05); cv::TermCriteria termCriteria = cv::TermCriteria(cv::TermCriteria::MAX_ITER | cv::TermCriteria::EPS, 30, 0.01); cv::cornerSubPix(grayscale, preciseCorners, cvSize(5,5), cvSize(-1,-1), termCriteria); // Copy refined corners position back to markers for (size_t i=0; i<goodMarkers.size(); i++) { Marker& marker = goodMarkers[i]; for (int c=0;c<4;c++) { marker.points[c] = preciseCorners[i*4 + c]; } } } //sort by id std::sort ( goodMarkers.begin(),goodMarkers.end() ); //there might be still the case that a marker is detected twice because of the double border indicated earlier, //detect and remove these cases std::vector<bool> toRemove ( goodMarkers.size(),false ); for ( int i=0;i<int ( goodMarkers.size() )-1;i++ ) { if ( goodMarkers[i].id==goodMarkers[i+1].id && !toRemove[i+1] ) { //std::cout<<"remove: "<<goodMarkers[i].id<<std::endl; //deletes the one with smaller perimeter if ( getPerimeter ( goodMarkers[i].points ) >getPerimeter ( goodMarkers[i+1].points ) ) toRemove[i+1]=true; else toRemove[i]=true; } } detectedMarkers.clear(); for (size_t i=0;i<goodMarkers.size();i++) { if (!toRemove[i]) detectedMarkers.push_back(goodMarkers[i]); } }