void EventEndTurn::apply(Core& core) const { core.deselectedAnyUnits(); core.cleanFow(); core.refreshUnits(newID()); for (auto* p : core.players()) { if (p->id == newID()) { if (core.currentPlayer().id == oldID()) { core.setCurrentPlayer(p); } return; } } }
NS_OVERRIDE virtual bool RecvVibrate(const InfallibleTArray<unsigned int>& pattern, const InfallibleTArray<uint64> &id, PBrowserParent *browserParent) { // Check whether browserParent is active. We should have already // checked that the corresponding window is active, but this check // isn't redundant. A window may be inactive in an active // browser. And a window is not notified synchronously when it's // deactivated, so the window may think it's active when the tab // is actually inactive. TabParent *tabParent = static_cast<TabParent*>(browserParent); if (!tabParent->Active()) { HAL_LOG(("RecvVibrate: Tab is not active. Cancelling.")); return true; } // Forward to hal::, not hal_impl::, because we might be a // subprocess of another sandboxed process. The hal:: entry point // will do the right thing. nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(tabParent->GetBrowserDOMWindow()); WindowIdentifier newID(id, window); hal::Vibrate(pattern, newID); return true; }
co::int32 InstanceManager::addInstance( co::IObject* instance, const std::string& lesseeEndpoint ) { co::int32 instanceID = newID(); _instances[instanceID] = new InstanceContainer( instance ); return instanceID; }
void rfid::receiveID(QString _ID) { //If a card is detected, request the ID of it if(_ID.toInt() == 253) { sendRequestID(); } //If we are in the process of receiving an ID, add it to receivedData else if(_ID.toInt() != 251) { if(_ID.toInt() < 10) receivedData += (QString::number(0) + QString::number(0) + _ID); else if (_ID.toInt() < 100) receivedData += (QString::number(0) + _ID); else receivedData += _ID; } // If we get the endofline command (251), and receivedData is not empty, emit newID. else if(_ID.toInt() == 251 && !receivedData.isEmpty()) { emit newID(receivedData); //qDebug() << receivedData; receivedData.clear(); } //Always send reset to prevent getting stuck if card is removed too quickly.. :) sendReset(); }
void XComboBox::sHandleNewIndex(int pIndex) { if (DEBUG) qDebug("%s::sHandleNewIndex(%d)",objectName().toAscii().data(), pIndex); if ((pIndex >= 0) && (pIndex < _ids.count()) && (_ids.at(pIndex) != _lastId)) { _lastId = _ids.at(pIndex); emit newID(_lastId); if (DEBUG) qDebug("%s::sHandleNewIndex() emitted %d", objectName().toAscii().data(), _lastId); if (allowNull()) { emit valid((pIndex != 0)); emit notNull((pIndex != 0)); } } if (DEBUG) qDebug("%s::sHandleNewIndex() returning", objectName().toAscii().data()); }
void CancelVibrate(const WindowIdentifier &id) { HAL_LOG("CancelVibrate: Sending to parent process."); WindowIdentifier newID(id); newID.AppendProcessID(); Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow())); }
co::int32 InstanceManager::publishInstance( co::IObject* instance, const std::string& key ) { co::int32 instanceID = newID(); _instances[instanceID] = new InstanceContainer( instance ); _published.insert( std::pair<std::string, co::int32>( key, instanceID ) ); return instanceID; }
void Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id) { HAL_LOG("Vibrate: Sending to parent process."); AutoTArray<uint32_t, 8> p(pattern); WindowIdentifier newID(id); newID.AppendProcessID(); Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow())); }
NS_OVERRIDE virtual bool RecvCancelVibrate(const InfallibleTArray<uint64> &id, PBrowserParent *browserParent) { TabParent *tabParent = static_cast<TabParent*>(browserParent); nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(tabParent->GetBrowserDOMWindow()); WindowIdentifier newID(id, window); hal::CancelVibrate(newID); return true; }
void XComboBox::setNull() { if (allowNull()) { _lastId = -1; setCurrentIndex(0); emit newID(-1); emit valid(FALSE); emit notNull(FALSE); } }
void Identifier::algorithm_nearestFit(std::list<Frame> & frames) { Frame * current = &frames.front(); Frame * previous = &(*(++frames.begin())); static std::list<std::list<Error>> errorMapping; static std::vector<std::list<std::list<Error>::iterator>> errorMapIterators; errorMapping.clear(); errorMapIterators.clear(); float distanceError, areaError, error; std::list<Error>::iterator errorMapIteratorIterator; std::list<std::list<Error>>::iterator errorMapIterator; int pIndex; for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { errorMapIterator = errorMapping.insert(errorMapping.end(), std::list<Error>()); errorMapIterators.push_back(std::list<std::list<Error>::iterator>()); pIndex = 0; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { distanceError = std::pow(c->x - p->x - p->dx, 2) + std::pow(c->y - p->y - p->dy, 2); error = distanceError; errorMapIteratorIterator = errorMapping.back().insert(errorMapping.back().end(),Error(&(*p), &(*c), pIndex, error)); errorMapIterators[pIndex].push_back(errorMapIteratorIterator); pIndex++; } errorMapping.back().sort(); } for(int i = 0; i < std::min(current->objects.size(), previous->objects.size()); i++) { errorMapping.sort(); errorMapping.front().front().current->id = errorMapping.front().front().previous->id; errorMapping.front().front().current->model = errorMapping.front().front().previous->model; errorMapping.front().front().current->isDecided = true; while(it != errorMapIterator->end()) .erase(it) } for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { if(!c->isDecided) c->id = newID(); } }
virtual mozilla::ipc::IPCResult RecvCancelVibrate(InfallibleTArray<uint64_t> &&id, PBrowserParent *browserParent) override { //TabParent *tabParent = TabParent::GetFrom(browserParent); /* XXXkhuey wtf nsCOMPtr<nsIDOMWindow> window = tabParent->GetBrowserDOMWindow(); */ WindowIdentifier newID(id, nullptr); hal::CancelVibrate(newID); return IPC_OK(); }
/** Adds a client to the list. */ bool Clients::add(TCPsocket newsd){ int newid = newID(); if (newid != 0){ //modified = true; Client* cl = new Client(newsd); operator[](newid) = cl; cl->id = newid; cl->state = cl->CHOOSE; mute || cout << ticks() << ": client #" << newid << " joined" << endl; }; return newid; }
CFontDescription& Fonts::AddSystem(const char* fontName, const char* id, int height) { std::string newID(id); m_fontMap[newID].first = CFontDescription(); m_fontMap[newID].first.SetTypefaceName(fontName); m_fontMap[newID].first.SetFontType(FONT_SYSTEM); m_fontMap[newID].first.SetAntiAlias(true); m_fontMap[newID].first.SetHeight(height); m_fontMap[newID].first.SetID(id); m_fontMap[newID].second = CFontObject(m_fontMap[newID].first); return m_fontMap[newID].first; }
virtual mozilla::ipc::IPCResult RecvVibrate(InfallibleTArray<unsigned int>&& pattern, InfallibleTArray<uint64_t>&& id, PBrowserParent *browserParent) override { // We give all content vibration permission. // TabParent *tabParent = TabParent::GetFrom(browserParent); /* xxxkhuey wtf nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(tabParent->GetBrowserDOMWindow()); */ WindowIdentifier newID(id, nullptr); hal::Vibrate(pattern, newID); return IPC_OK(); }
CFontDescription& Fonts::AddFreetype(const char* fontPath, const char* id, int height) { std::string newFontPath = Util::FixFilePath(fontPath, "fonts/", ".ttf"); std::string newID(id); m_fontMap[newID].first = CFontDescription(); m_fontMap[newID].first.SetTypefaceName( newFontPath.c_str() ); m_fontMap[newID].first.SetFontType(FONT_FREETYPE); m_fontMap[newID].first.SetAntiAlias(true); m_fontMap[newID].first.SetHeight(height); m_fontMap[newID].first.SetID(id); m_fontMap[newID].second = CFontObject(m_fontMap[newID].first); return m_fontMap[newID].first; }
quickRelocateLot::quickRelocateLot(QWidget *parent, const char *name, bool modal, Qt::WFlags f1) : XDialog(parent, name, modal, f1) { setupUi(this); _itemloc->addColumn(tr("Item #"), -1, Qt::AlignLeft, true, "item_number"); _itemloc->addColumn(tr("Location"), 200, Qt::AlignLeft, true, "locationname"); _itemloc->addColumn(tr("Qty."), _qtyColumn, Qt::AlignRight, true, "itemloc_qty"); _itemloc->setPopulateLinear(true); // signals and slots connections connect(_lotSerial, SIGNAL(editingFinished()), this, SLOT(sFillList())); connect(_warehous, SIGNAL(newID()), this, SLOT(sFillList())); connect(_assign, SIGNAL(clicked()), this, SLOT(sPost())); connect(_cancel, SIGNAL(clicked()), this, SLOT(reject())); }
/* assemble the force vector B (A*X = B). */ int XC::SymSparseLinSOE::addB(const XC::Vector &in_v, const ID &in_id,const double &fact) { // check for a quick return if(fact == 0.0) return 0; int idSize = in_id.Size(); // check that m and id are of similar size if(idSize != in_v.Size() ) { std::cerr << "XC::SymSparseLinSOE::addB() "; std::cerr << " - Vector and XC::ID not of similar sizes\n"; return -1; } // construct v and id based on non-negative id values. int newPt = 0; std::vector<int> id(idSize); Vector v(idSize); for(int ii = 0; ii < idSize; ii++) { if(in_id(ii) >= 0 && in_id(ii) < size) { id[newPt] = in_id(ii); v[newPt] = in_v(ii); newPt++; } } idSize = newPt; if(idSize == 0) return 0; ID newID(idSize); for(int i=0; i<idSize; i++) { newID[i]= id[i]; if(newID[i] >= 0) newID[i] = invp[newID[i]]; } SparseSOEBase::addB(v,newID,fact); return 0; }
void XComboBox::populate(XSqlQuery &pQuery, int pSelected) { int selected = 0; int counter = 0; // Clear any old data clear(); if (allowNull()) counter++; // Load the combobox with the contents of the passed query, if any if (pQuery.first()) { do { append(pQuery.value(0).toInt(), pQuery.value(1).toString(), pQuery.value(2).toString()); if (pQuery.value(0).toInt() == pSelected) selected = counter; counter++; } while(pQuery.next()); } setCurrentIndex(selected); if (_ids.count()) { _lastId = _ids.at(selected); if (allowNull()) emit notNull(TRUE); } else { _lastId = -1; if (allowNull()) emit notNull(FALSE); } emit newID(_lastId); emit valid((_lastId != -1)); }
jumpTableID jumpTable::allocate(int number_of_entries) { int id = newID(); jumpTableEntry* entry = major_at(id); assert(entry->is_unused(), "cannot allocate used jump entry"); if (number_of_entries == 1) { entry->initialize_nmethod_stub(NULL); return jumpTableID(id); } else { char* new_block = allocate_jump_entries(number_of_entries); // Initialize the first entry as a nmethod stub jump_entry_for_at(new_block, 0)->initialize_nmethod_stub(NULL); // initialize the rest as block closure stubs for(int i = 1; i < number_of_entries; i++) { jump_entry_for_at(new_block, i)->initialize_block_closure_stub(); } entry->initialize_as_link(new_block); return jumpTableID(id,0); } }
void XComboBox::setText(const QString &pString) { if (pString == currentText()) return; if (count()) { for (int counter = ((allowNull()) ? 1 : 0); counter < count(); counter++) { if (text(counter) == pString) { setCurrentIndex(counter); emit newID(id()); return; } } } if (editable()) { setId(-1); setCurrentText(pString); } }
void MainWindow::triggerId(){ emit newID((unsigned int)(ui->idBox->value())); }
//Let the user input all required info of the new Staff //re-enter if the info is invalid //After all the info has been filled, display options: //1. Add Staff //call addStaff() //2. Re enter info //mainAddStaff() //0. return; void StaffList::createStaff() { string new_name, new_dob, new_address, new_dept, new_pos; int new_sal_rate; cout << "Name: "; cin.ignore(); getline(cin, new_name); cout << "DOB: "; //cin.ignore(); getline(cin, new_dob); cout << "Address: "; //cin.ignore(); getline(cin, new_address); cout << "Department: "; cin.ignore(); getline(cin, new_dept); cout << "Position: "; //cin.ignore(); getline(cin, new_pos); cout << "Salary rate: "; while (!(cin >> new_sal_rate)||new_sal_rate<0) { cout << "Invalid number!" << endl; cin.clear(); cin.ignore(256,'\n'); } int new_id = newID(); Staff newbie( new_id, new_name, new_dob, new_address, new_dept, new_pos, new_sal_rate); cout << "Choose one: " << endl; cout << "1. Add a staff member" << endl; cout << "0. Back" << endl; cout << "Enter Your option: "; int command; while (true) { cin >> command; if (cin && (command < 4) && (command > -1)) break; cout << "Invalid command!" << endl; cin.clear(); cin.ignore(256,'\n'); } switch (command) { case 1: if (userConfirm()) { addStaff(newbie); cout << "Add success! New staff member info: " << endl; newbie.Print(); cout << endl; } else { cout << "No change is commited"; } break; case 0: return; default: cout << "Invalid command!" << endl; break; } }
void XComboBox::setId(int pTarget) { // reports are a special case: they should really be stored by name, not id if (_type == Reports) { XSqlQuery query; query.prepare("SELECT report_id " "FROM report " "WHERE (report_name IN (SELECT report_name " " FROM report " " WHERE (report_id=:report_id)));"); query.bindValue(":report_id", pTarget); query.exec(); while (query.next()) { int id = query.value("report_id").toInt(); for (int counter = 0; counter < count(); counter++) { if (_ids.at(counter) == id) { setCurrentIndex(counter); if(_lastId!=id) { _lastId = id; emit newID(pTarget); emit valid(TRUE); if (allowNull()) emit notNull(TRUE); } return; } } } } else { for (int counter = 0; counter < count(); counter++) { if (_ids.at(counter) == pTarget) { setCurrentIndex(counter); if(_lastId!=pTarget) { _lastId = pTarget; emit newID(pTarget); emit valid(TRUE); if (allowNull()) emit notNull(TRUE); } return; } } } setNull(); }
void Fonts::Update(const char* id) { std::string newID(id); m_fontMap[newID].second = CFontObject(m_fontMap[newID].first); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { unsigned int sig = 123456; unsigned int port = 54545; std::string addressString = "255.255.255.255"; bool noconfig = false; try { TCLAP::CmdLine cmd("iyptclock", ' ', "0.9"); TCLAP::ValueArg<unsigned int> portArg("p", "port","Port to listen on", false, 54545, "unsigned integer"); TCLAP::ValueArg<unsigned int> sigArg("s", "signature","Signature to use", false, 123456 , "unsigned integer"); TCLAP::ValueArg<std::string> bcastArg("b", "broadcast","Broadcast address to send packets to", false, "255.255.255.255", "ip address"); TCLAP::SwitchArg noconfigArg("n", "noconfig", "disable configuration", false); cmd.add( portArg ); cmd.add( sigArg ); cmd.add( bcastArg ); cmd.add( noconfigArg ); cmd.parse( QApplication::argc(), QApplication::argv() ); port = portArg.getValue(); sig = sigArg.getValue(); addressString = bcastArg.getValue(); noconfig = noconfigArg.getValue(); } catch (TCLAP::ArgException &e) { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } ui->setupUi(this); connect(ui->idButton, SIGNAL(clicked()), this, SLOT(triggerId())); connect(ui->portButton, SIGNAL(clicked()), this, SLOT(triggerPort())); connect(ui->startstop, SIGNAL(clicked()), this, SLOT(toggleStartPause())); connect(ui->delButton, SIGNAL(clicked()), this, SLOT(triggerDel())); connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveStages())); ad = new AboutDialog(); connect(ui->actionAbout_IYPTClock, SIGNAL(triggered()), ad, SLOT(exec())); timer = new QTimer(); connect(timer, SIGNAL(timeout()), ui->graphicsView, SLOT(act())); timer->start(30); thc = new ThemeClock(); connect(thc, SIGNAL(timeUpdate(int)), ui->graphicsView, SLOT(setTime(int))); connect(thc, SIGNAL(timeUpdate(int)), this, SLOT(setLcdWidthForTime(int))); connect(thc, SIGNAL(allowedTimeChanged(int)), ui->graphicsView, SLOT(setAllowedTime(int))); connect(thc, SIGNAL(started(int)), ui->graphicsView, SLOT(setTime(int))); connect(thc, SIGNAL(paused(int)), ui->graphicsView, SLOT(setTime(int))); connect(thc, SIGNAL(restarted(int)), ui->graphicsView, SLOT(setTime(int))); connect(thc, SIGNAL(stopped(int)), ui->graphicsView, SLOT(setTime(int))); connect(ui->startstop, SIGNAL(clicked()), thc, SLOT(startorpause())); connect(ui->resetButton, SIGNAL(clicked()), thc, SLOT(reset())); connect(ui->setTimeButton, SIGNAL(clicked()), this, SLOT(setTime())); ui->setTimeComboBox->addItem(tr("last saved time"), QVariant(TIME_SAVED)); ui->setTimeComboBox->addItem(tr("elapsed time"), QVariant(TIME_ELAPSED)); ui->setTimeComboBox->addItem(tr("remaining time"), QVariant(TIME_LEFT)); connect(thc, SIGNAL(timeUpdate(QString)), ui->lcdNumber, SLOT(display(QString))); lc = new ListController(); connect(ui->ffwd, SIGNAL(clicked()), lc, SLOT(forward())); connect(ui->bwd, SIGNAL(clicked()), lc, SLOT(backward())); connect(ui->addButton, SIGNAL(clicked()), lc, SLOT(add())); connect(thc, SIGNAL(started(int)), lc, SLOT(checkAutoStart())); connect(this, SIGNAL(itemShouldBeDeleted(QModelIndex)), lc, SLOT(del(QModelIndex))); connect(lc, SIGNAL(allowedTimeChanged(int)), thc, SLOT(setAllowedTime(int))); connect(lc, SIGNAL(roomClockChanged(bool)), ui->graphicsView, SLOT(setRoomclock(bool))); connect(lc, SIGNAL(resetTime()), thc, SLOT(reset())); connect(lc, SIGNAL(endOfStage()), thc, SLOT(stop())); connect(lc, SIGNAL(stageNameChanged(QString)), ui->stageLabel, SLOT(setText(QString))); connect(lc, SIGNAL(modelChanged(QAbstractTableModel*)), this, SLOT(propagateModel(QAbstractTableModel*))); ui->portBox->setValue(port); ui->idBox->setValue(sig); bs = new BroadcastServer(this, QHostAddress(addressString.c_str()), port, sig); connect(thc, SIGNAL(timeUpdate(int)), bs, SLOT(updateTime(int))); connect(thc, SIGNAL(restarted(int)), bs, SLOT(updateTime(int))); connect(thc, SIGNAL(stopped(int)), bs, SLOT(updateTime(int))); connect(thc, SIGNAL(allowedTimeChanged(int)), bs, SLOT(setAllowedTime(int))); connect(lc, SIGNAL(roomClockChanged(bool)), bs, SLOT(setRoomclock(bool))); connect(lc, SIGNAL(stageNameChanged(QString)), bs, SLOT(setStageName(QString))); connect(this, SIGNAL(newPort(uint)), bs, SLOT(setBroadcastPort(uint))); connect(this, SIGNAL(newID(uint)), bs, SLOT(setSignature(uint))); connect(lc, SIGNAL(overTimeChanged(int)), thc, SLOT(setOverTime(int))); connect(thc, SIGNAL(overtimed(int)), lc, SLOT(handleOvertime(int))); connect(lc, SIGNAL(elapsedTimeChanged(int)), thc, SLOT(setElapsedTime(int))); connect(lc, SIGNAL(elapsedTimeChanged(int)), ui->graphicsView, SLOT(setTime(int))); connect(lc, SIGNAL(elapsedTimeChanged(int)), bs, SLOT(updateTime(int))); connect(lc, SIGNAL(getElapsedOverTime()), thc, SLOT(getElapsedOverTime())); connect(thc, SIGNAL(elapsedOverTime(int)), lc, SLOT(setElapsedOverTime(int))); if (noconfig) { ui->tabWidget->setTabEnabled(1,false); } if (QFile("stages.txt").exists()){ lc->loadListFromFile("stages.txt"); } else if (QFile("/usr/share/iyptclock/stages.txt").exists()){ lc->loadListFromFile("/usr/share/iyptclock/stages.txt"); } else { lc->loadListFromFile(""); } thc->stop(); timer2 = new QTimer(); connect(timer2, SIGNAL(timeout()), this, SLOT(toggleStartPause())); connect(timer2, SIGNAL(timeout()), this, SLOT(toggleTimeSpinBox())); timer2->start(100); savefile = QString("/var/run/iyptclock/autosave_"); savefile += QString::number(sig); as = new AutoSave(this,savefile,this); as->load(); timer3 = new QTimer(); connect(timer3, SIGNAL(timeout()),as,SLOT(save())); timer3->start(1000); }
/* Perform the element stiffness assembly here. */ int XC::SymSparseLinSOE::addA(const XC::Matrix &in_m, const XC::ID &in_id, double fact) { // check for a quick return if(fact == 0.0) return 0; int idSize = in_id.Size(); if(idSize == 0) return 0; // check that m and id are of similar size if(idSize != in_m.noRows() && idSize != in_m.noCols()) { std::cerr << "XC::SymSparseLinSOE::addA() "; std::cerr << " - Matrix and XC::ID not of similiar sizes\n"; return -1; } // construct m and id based on non-negative id values. int newPt = 0; std::vector<int> id(idSize); for(int jj = 0; jj < idSize; jj++) { if(in_id(jj) >= 0 && in_id(jj) < size) { id[newPt] = in_id(jj); newPt++; } } idSize = newPt; if(idSize == 0) return 0; std::vector<double> m(idSize*idSize); int newII = 0; for (int ii = 0; ii < in_id.Size(); ii++) { if(in_id(ii) >= 0 && in_id(ii) < size) { int newJJ = 0; for (int jj = 0; jj < in_id.Size(); jj++) { if(in_id(jj) >= 0 && in_id(jj) < size) { m[newII*idSize + newJJ] = in_m(ii, jj); newJJ++; } } newII++; } } // forming the new_ id based on invp. std::vector<int> newID(idSize); std::vector<int> isort(idSize); for (int kk=0; kk<idSize; kk++) { newID[kk] = id[kk]; if(newID[kk] >= 0) newID[kk] = invp[newID[kk]]; } long int i_eq, j_eq; int i, j, nee, lnee; int k, ipos, jpos; int it, jt; int iblk; OFFDBLK *ptr; OFFDBLK *saveblk; double *fpt, *iloc, *loc; nee = idSize; lnee = nee; /* initialize isort */ for( i = 0, k = 0; i < lnee ; i++ ) { if( newID[i] >= 0 ) { isort[k] = i; k++; } } lnee = k; /* perform the sorting of isort here */ i = k - 1; do { k = 0 ; for (j = 0 ; j < i ; j++) { if( newID[isort[j]] > newID[isort[j+1]]) { isort[j] ^= isort[j+1] ; isort[j+1] ^= isort[j] ; isort[j] ^= isort[j+1] ; k = j ; } } i = k ; } while ( k > 0) ; i = 0 ; ipos = isort[i] ; k = rowblks[newID[ipos]] ; saveblk = begblk[k] ; /* iterate through the element stiffness matrix, assemble each entry */ for (i=0; i<lnee; i++) { ipos = isort[i] ; i_eq = newID[ipos] ; iblk = rowblks[i_eq] ; iloc = penv[i_eq +1] - i_eq ; if(k < iblk) while (saveblk->row != i_eq) saveblk = saveblk->bnext ; ptr = saveblk ; for (j=0; j< i ; j++) { jpos = isort[j] ; j_eq = newID[jpos] ; if(ipos > jpos) { jt = ipos; it = jpos; } else { it = ipos; jt = jpos; } if(j_eq >= xblk[iblk]) /* diagonal block (profile) */ { loc = iloc + j_eq ; *loc += m[it*idSize + jt] * fact; } else /* row segment */ { while((j_eq >= (ptr->next)->beg) && ((ptr->next)->row == i_eq)) ptr = ptr->next ; fpt = ptr->nz ; fpt[j_eq - ptr->beg] += m[it*idSize + jt] * fact; } } diag[i_eq] += m[ipos*idSize + ipos] * fact; /* diagonal element */ } return 0; }
void process(NIC* ni) { static uint32_t myip = 0xc0a86402; // 192.168.100.2 Packet* packet = nic_input(ni); if(!packet) return; Ether* ether = (Ether*)(packet->buffer + packet->start); if(endian16(ether->type) == ETHER_TYPE_ARP) { // ARP response ARP* arp = (ARP*)ether->payload; if(endian16(arp->operation) == 1 && endian32(arp->tpa) == myip) { ether->dmac = ether->smac; ether->smac = endian48(ni->mac); arp->operation = endian16(2); arp->tha = arp->sha; arp->tpa = arp->spa; arp->sha = ether->smac; arp->spa = endian32(myip); nic_output(ni, packet); packet = NULL; } } else if(endian16(ether->type) == ETHER_TYPE_IPv4) { IP* ip = (IP*)ether->payload; if(ip->protocol == IP_PROTOCOL_ICMP && endian32(ip->destination) == myip) { // Echo reply ICMP* icmp = (ICMP*)ip->body; icmp->type = 0; icmp->checksum = 0; icmp->checksum = endian16(checksum(icmp, packet->end - packet->start - ETHER_LEN - IP_LEN)); ip->destination = ip->source; ip->source = endian32(myip); ip->ttl = endian8(64); ip->checksum = 0; ip->checksum = endian16(checksum(ip, ip->ihl * 4)); ether->dmac = ether->smac; ether->smac = endian48(ni->mac); nic_output(ni, packet); packet = NULL; } else if(ip->protocol == IP_PROTOCOL_UDP) { UDP* udp = (UDP*)ip->body; if(endian16(udp->destination) == 9000) { reply_count = 2; // Control packet uint32_t idx = 0; seq = read_u16(udp->body, &idx); user_mac = endian48(ether->smac); user_ip = endian32(ip->source); user_port = endian16(udp->source); uint8_t msg = read_u8(udp->body, &idx); switch(msg) { case 1: // MSG_CREATE { idx++; // read ctype uint32_t clen = read_u32(udp->body, &idx); char collection[clen + 1]; collection[clen] = '\0'; memcpy(collection, udp->body + idx, clen); idx += clen; uint64_t id = newID(collection); memmove(udp->body + idx + 9, udp->body + idx, endian16(udp->length) - 8 - idx); packet->end += 9; udp->length = endian16(endian16(udp->length) + 9); ip->length = endian16(endian16(ip->length) + 9); write_u8(udp->body, 4, &idx); write_u64(udp->body, id, &idx); } break; case 2: // MSG_READ reply_count = 1; break; case 3: // MSG_RETRIEVE break; case 4: // MSG_UPDATE break; case 5: // MSG_DELETE break; case 6: // MSG_HELLO reply_count = 1; break; } udp->source = endian16(9999); udp->destination = endian16(9001); udp->checksum = 0; ip->destination = ip->source; ip->source = endian32(myip); ip->ttl = endian8(ip->ttl) - 1; ip->checksum = 0; ip->checksum = endian16(checksum(ip, ip->ihl * 4)); ether->dmac = ether->smac; ether->smac = endian48(ni->mac); nic_output_dup(ni, packet); udp->destination = endian16(9002); ip->checksum = 0; ip->checksum = endian16(checksum(ip, ip->ihl * 4)); nic_output_dup(ni, packet); udp->destination = endian16(9003); ip->checksum = 0; ip->checksum = endian16(checksum(ip, ip->ihl * 4)); nic_output(ni, packet); packet = NULL; } else if(endian16(udp->destination) == 9999) { uint32_t idx = 0; uint16_t seq2 = read_u16(udp->body, &idx); if(seq == seq2 && --reply_count == 0) { udp->checksum = 0; udp->destination = endian16(user_port); udp->source = endian16(9000); ip->destination = endian32(user_ip); ip->source = endian32(myip); ip->ttl = endian8(64); ip->checksum = 0; ip->checksum = endian16(checksum(ip, ip->ihl * 4)); ether->dmac = endian48(user_mac); ether->smac = endian48(ni->mac); nic_output(ni, packet); packet = NULL; } } } } if(packet) nic_free(packet); }
/* // Select the objects in the previous frame that are candidates to the unidentified in the current frame std::vector<Object *> candidates; candidates.clear(); for(std::vector<Object>::iterator c = previous->objects.begin(); c != previous->objects.end(); c++) { if(!probablyOutsideOfImage(*c)) candidates.push_back(&(*c)); } */ void Identifier::algorithm3(std::list<Frame> & frames) { /* * Objects overlapp * */ Frame * current = &frames.front(); Frame * previous = &(*(++frames.begin())); // Move lost objects std::cout << "\n---------------------\n"; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { std::cout << "(" << p->id << ") (dx,dy):(x,y):(xHat,yHat) = (" << p->dx << ", " << p->dy << "):(" << p->x << ", " << p->y << "):(" << p->xHat << ", " << p->yHat << ")\n"; if(p->isLost) { } } // Find the previous object which is probably the current object float distanceError, error; int pIndex, prevpIndex; mostProbable_.clear(); undecidedObjects.clear(); isDecided.clear(); for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) isDecided.push_back(false); for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { mostProbable_.push_back(ProbabilityContainer(-1, -1, 1000000)); pIndex = 0; prevpIndex = -1; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { float area1 = c->containedAreaQuotient(*p); float area2 = p->containedAreaQuotient(*c); //std::cout << "(id1,id2)=(" << c->id << "," << p->id << "): " << area1 << " | " << area2 << "\n"; /* * distanceError = (x-x0-vx0)^2 + (y-y0-vy0)^2 */ distanceError = std::pow(c->x - p->x - p->dx, 2) + std::pow(c->y - p->y - p->dy, 2); error = distanceError; if(!isDecided[pIndex] && mostProbable_.back().error > error && error < 10000) { mostProbable_.back().error = error; mostProbable_.back().index = pIndex; if(prevpIndex >= 0) isDecided[prevpIndex] = false; isDecided[pIndex] = true; prevpIndex = pIndex; } pIndex++; } } pIndex = 0; for(std::list<ProbabilityContainer>::iterator p = mostProbable_.begin(); p != mostProbable_.end(); p++) { if(p->index >= 0) { current->objects[pIndex].id = previous->objects[p->index].id; current->objects[pIndex].model = previous->objects[p->index].model; } else // Unidentified { current->objects[pIndex].id = newID(); } current->objects[pIndex].isLost = false; pIndex++; } // Find objects from last frame that was not "found" (lost) at the current frame bool lost; pIndex = 0; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { lost = true; for(std::list<ProbabilityContainer>::iterator pr = mostProbable_.begin(); pr != mostProbable_.end(); pr++) { if(pr->index == pIndex) { lost = false; break; } } if(lost) { undecidedObjects.push_back(pIndex); } pIndex++; } int lostAmount = 0, lostAmount2 = 0; for(std::vector<Object>::iterator p = previous->objects.begin(); p != previous->objects.end(); p++) { if(p->isLost) lostAmount++; } for(std::vector<Object>::iterator c = current->objects.begin(); c != current->objects.end(); c++) { if(c->isLost) lostAmount2++; } //std::cout << "previous: " << previous->objects.size() << " prevlost: " << lostAmount << " currlost: " << lostAmount2 << "\n"; int decidedAmount = current->objects.size(); Object * cObject, * pObject; // Manage objects from last frame that was not "found" at the current frame for(std::list<int>::iterator l = undecidedObjects.begin(); l != undecidedObjects.end(); l++) { pObject = &previous->objects[*l]; // Did it probably leave the screen? //... // Is it contained within a currently identified object? for(int cIndex = 0; cIndex < decidedAmount; cIndex++) { cObject = ¤t->objects[cIndex]; float area1 = cObject->containedAreaQuotient(*pObject); float area2 = pObject->containedAreaQuotient(*cObject); //std::cout << "(id1,id2)=(" << cObject->id << "," << pObject->id << "): " << area1 << " | " << area2 << "\n"; if(area2 > 0.1) //How much of the later that 'was' inside of what *c now is { isDecided[*l] = true; pObject->isLost = true; current->objects.push_back(*pObject); break; } } /* // Is it just hidden behind something? if(!pObject->lost) { pObject->lost = true; current->objects.push_back(*pObject); }*/ } current->profileData["#objectsID'd"] = decidedAmount; current->profileData["#objects lost"] = current->objects.size()-decidedAmount; }
void Identifier::algorithm2(std::list<Frame> & frames) { Frame * current = &frames.front(); Frame * previous = &(*(++frames.begin())); mostProbable.clear(); undecidedObjects.clear(); float distanceError, error; for(int i = 0; i < current->objects.size(); i++) { undecidedObjects.push_back(i); mostProbable.push_back(std::list<ProbabilityContainer>()); for(int j = 0; j < previous->objects.size(); j++) { /* * distanceError = (x-x0-vx0)^2 + (y-y0-vy0)^2 */ distanceError = std::pow(current->objects[i].x - previous->objects[j].x - previous->objects[j].dx, 2) + std::pow(current->objects[i].y - previous->objects[j].y - previous->objects[j].dy, 2); error = distanceError; mostProbable[i].push_back(ProbabilityContainer(j,previous->objects[j].id,error)); } mostProbable[i].sort(); } //std::cout << "\nFind most probable previous object:\n"; std::list<int>::iterator bestMatch; int matchingPrevious; float min; for(int candidate = 0; candidate < std::min(previous->objects.size(), current->objects.size()); candidate++) { min = 1000000; for(std::list<int>::iterator i = undecidedObjects.begin(); i != undecidedObjects.end(); i++) { if(mostProbable[*i].front().error < min) { min = mostProbable[*i].front().error; bestMatch = i; } } //A most probable candidate found! matchingPrevious = mostProbable[*bestMatch].front().index; current->objects[*bestMatch].id = previous->objects[matchingPrevious].id; //std::cout << "\tObject " << mostProbable[*bestMatch].front().probableId << " found with minError " << mostProbable[*bestMatch].front().error << "\n"; for(std::list<int>::iterator i = undecidedObjects.begin(); i != undecidedObjects.end(); i++) { std::list<ProbabilityContainer>::iterator it = mostProbable[*i].begin(); while(it != mostProbable[*i].end()) { if(it->index == matchingPrevious) mostProbable[*i].erase(it++); else it++; } mostProbable[*i].sort(); } undecidedObjects.erase(bestMatch); } //Take care of the new objects detected (still undecided): for(std::list<int>::iterator i = undecidedObjects.begin(); i != undecidedObjects.end(); i++) { current->objects[*i].id = newID(); } }