int Grafo::indexElementoMenor(QQueue<vertice*> cola) { int indexMin = 0; for(int i = 0; i < cola.size(); i++) { if(cola.at(i)->costoHastaAhora < cola.at(indexMin)->costoHastaAhora) indexMin = i; } return indexMin; }
void BFS::initializeAnimation(){ setMenu(false); int r=255, g=255, b=0; int color_step= 25; m_operations.push_back([=,this](){ getNode(_currentNode)->setColor(QColor(r, g, b));colorNode(_currentNode); }); r-=color_step; g-=color_step; QQueue<int> queue; queue.append(_currentNode); getNode(_currentNode)->setVisited(true); while(!queue.empty()){ int curr = queue.at(0); queue.pop_front(); NodeList list = getNeighbours(curr); for (auto iter : list){ if(!getNode(iter)->visited()){ getNode(iter)->setVisited(true); m_operations.push_back([=,this](){getEdge(curr, iter)->setColor(QColor(r,g,b)); colorEdge(curr, iter); emit highlightLine(10);}); m_operations.push_back([=,this](){getNode(iter)->setColor(QColor(r,g,b)); colorNode(iter);}); queue.append(iter); } } r-=color_step; g-=color_step; } m_animationInitialized= true; m_currentStepInAnimation= 0; m_numberOfStepsInAnimation= m_operations.size(); }
int BleRtmpSendThread::service(BleRtmpMuxer & muxer) { int ret = BLE_SUCESS; if ((ret = sendVideoSh(muxer)) != BLE_SUCESS) { return ret; } if ((ret = sendAudioSh(muxer)) != BLE_SUCESS) { return ret; } while (!m_stop) { QQueue<BleAVPacket *> pkts = BleAVQueue::instance()->dequeue(); if (pkts.isEmpty()) { msleep(50); continue; } BleAutoLocker(m_mutex); while (!pkts.empty()) { BleAVPacket *pkt = pkts.dequeue(); BleAutoFree(BleAVPacket, pkt); MStream &data = pkt->data; if (pkt->pktType == Packet_Type_Video) { if (muxer.addH264(data, pkt->dts) != TRUE ) { ret = BLE_RTMPSEND_ERROR; break; } m_videoKbps += (data.size() + 11); m_fps += 1; } else if (pkt->pktType == Packet_Type_Audio) { if (muxer.addAAC(data, pkt->dts) != TRUE ) { ret = BLE_RTMPSEND_ERROR; break; } m_audioKbps += (data.size() + 11); } m_sendDataCount += (data.size() + 11); } // if send failed, then pkts may has some pkt // we should delete it. for (int i = 0; i < pkts.size(); ++i) { BleAVPacket *pkt = pkts.at(i); BleFree(pkt); } } return ret; }
void DeintFilter::addFramesToDeinterlace(QQueue<FrameBuffer> &framesQueue, bool checkSize) { while (!framesQueue.isEmpty()) { const VideoFrame &videoFrame = framesQueue.at(0).frame; if (((deintFlags & AutoDeinterlace) && !videoFrame.interlaced) || (checkSize && videoFrame.hasNoData())) break; internalQueue.enqueue(framesQueue.dequeue()); } }
QList<vertice> Grafo::Dijkstra(vertice *ini, vertice* fin) { for(int i = 0; i < this->vertices.size();i++) { this->vertices.at(i)->costoHastaAhora = INT_MAX; this->vertices.at(i)->predecesor = NULL; } int indexOrigen = this->EncontrarIndexVertice(ini); int indexMeta = this->EncontrarIndexVertice(fin); int indexMinimoCola, indexMinimoVertices; this->vertices.at(indexOrigen)->costoHastaAhora = 0; QQueue<vertice*> cola; vertice *u; float peso; cola.append(this->vertices.at(indexOrigen)); while(!cola.empty()) { indexMinimoCola = this->indexElementoMenor(cola); u = cola.at(indexMinimoCola); indexMinimoVertices = this->EncontrarIndexVertice(u); cola.removeAll(u); this->vertices.at(indexMinimoVertices)->visitado = true; for(int j = 0; j < this->vertices.at(indexMinimoVertices)->adyacentes.size(); j++) { if(!this->vertices.at(indexMinimoVertices)->adyacentes.at(j)->visitado) { peso = this->vertices.at(indexMinimoVertices)->configuracion.Distanica(&this->vertices.at(indexMinimoVertices)->adyacentes.at(j)->configuracion); if(this->vertices.at(indexMinimoVertices)->adyacentes.at(j)->costoHastaAhora > this->vertices.at(indexMinimoVertices)->costoHastaAhora + peso) { this->vertices.at(indexMinimoVertices)->adyacentes.at(j)->costoHastaAhora = this->vertices.at(indexMinimoVertices)->costoHastaAhora + peso; this->vertices.at(indexMinimoVertices)->adyacentes.at(j)->predecesor = this->vertices.at(indexMinimoVertices); cola.append(this->vertices.at(indexMinimoVertices)->adyacentes.at(j)); } } } //SE debe remover de la cola el elemento } QList<vertice> ruta; vertice *actual = this->vertices.at(indexMeta); while(actual != NULL) { ruta.push_front(*actual); actual = actual->predecesor; } return ruta; }
void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue<float> &samples) { int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2; int sampleCount = samples.size(), x = XMARGIN + w, y; if(sampleCount > 0) { path.moveTo(x, YMARGIN + h); for(int i = 0; i < sampleCount; ++i) { x = XMARGIN + w - w * i / DESIRED_SAMPLES; y = YMARGIN + h - (int)(h * samples.at(i) / fMax); path.lineTo(x, y); } path.lineTo(x, YMARGIN + h); } }
bool SBusController::isBusy( const QString & bus ) { const QStringList & keys = active_buses->keys(); if( keys.contains(bus) ) return true; if( !queued_buses->contains(bus) ) return false; QQueue<SBusController*> *list = queued_buses->value(bus); for( int i=0 ; i<list->count() ; i++ ) if( !list->at(i)->passUpAndWait() ) return true; return false; }
void SBusController::finish( const QString & bus ) { if( bus.isEmpty() ) return; SBusController *core = (*active_buses)[bus]; if( core != this ) { qCritical() << QString("SBusController::finish : This SBusController Object can't remove \"%1\" from SBusController.").arg(bus); return ; } active_buses->remove(bus); /*! ---------- Dequeue first not pass up process ------------ */ SBusController *item = 0; if( !queued_buses->contains(bus) ) return; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) return; for( int i=0 ; i<queue->count() ; i++ ) { if( !queue->at(i)->passUpAndWait() ) { item = queue->takeAt( i ); break; } } if( item == 0 ) return; /*! --------------------------------------------------------- */ if( queued_buses->value(bus)->isEmpty() ) delete queued_buses->take( bus ); active_buses->insert( bus , item ); emit item->go(); }
void BleEncoderThread::run() { BleImageProcessThread * imageProcessThread = dynamic_cast<BleImageProcessThread *> (m_imageProcessThread); BleAssert(imageProcessThread); while (!m_stop) { QQueue<BleImage*> images = BleAVContext::instance()->captureThread->getQueue(); // if can't get image, then sleep 50 ms. if (images.isEmpty()) { msleep(5); continue; } while (!images.empty()) { BleImage * image = images.dequeue(); BleAutoFree(BleImage, image); if (image->dataSize <= 0) continue; IplImage* imgYUV = cvCreateImage(cvSize(image->width, image->height * 3 / 2), IPL_DEPTH_8U, 1); IplImage *cvImage = cvCreateImageHeader(cvSize(image->width, image->height), IPL_DEPTH_8U, 3); cvImage->imageData = image->data; cvImage->imageDataOrigin = image->data; cvCvtColor(cvImage, imgYUV, CV_BGR2YUV_I420); m_x264Encoder->encode((uchar*)imgYUV->imageData, image->pts, image->opaque); cvReleaseImageHeader(&cvImage); cvReleaseImage(&imgYUV); if (m_stop) break; } // do clean for (int i = 0; i > images.size(); ++i) { BleImage *img = images.at(i); BleFree(img); } } log_trace("BleEncoderThread exit normally."); }
void MainWindow::ffmpegGraphPlot(QQueue<int> LL, QQueue<int> RR) { qLL = LL; qRR = RR; widget.PlotView0->addGraph(); widget.PlotView0->graph()->setPen(QPen(Qt::blue)); widget.PlotView0->graph()->setBrush(QBrush(QColor(0, 0, 255, 20))); widget.PlotView0->graph()->setPen(QPen(Qt::red)); widget.PlotView1->addGraph(); widget.PlotView1->graph()->setPen(QPen(Qt::blue)); widget.PlotView1->graph()->setBrush(QBrush(QColor(0, 0, 255, 20))); widget.PlotView1->graph()->setPen(QPen(Qt::red)); //int size = qLL.size(); int size = LL.size() / 5; QVector<double> x0(size), y0(size); // initialize with entries 0..100 QVector<double> x1(size), y1(size); // initialize with entries 0..100 for (int i = 0; i < size; i += 1) { x0[i] = i; // x goes from -1 to 1 y0[i] = LL.at(i); // let's plot a quadratic function // y1[i] = LL.at(i+1); // let's plot a quadratic function // y0[i] = rand()*1000; // cout<<LL.at(i)<<endl; // y1[i] = Samples[100000 + i + 1] / 20; // let's plot a quadratic function } widget.PlotView0->addGraph(); widget.PlotView0->graph(0)->setData(x0, y0); widget.PlotView0->xAxis->setRange(0, 1000); widget.PlotView0->yAxis->setRange(-255, 255); widget.PlotView0->replot(); widget.PlotView1->addGraph(); widget.PlotView1->graph(0)->setData(x0, y0); widget.PlotView1->xAxis->setRange(0, 1000); widget.PlotView1->yAxis->setRange(-255, 255); widget.PlotView1->replot(); cout << size << endl; }
void SBusController::finish() { QStringList keys; keys = queued_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !queued_buses->contains(bus) ) continue; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) continue; for( int j=0 ; j<queue->count() ; j++ ) if( queue->at(j) == this ) { queue->removeAt( j ); j--; } if( queued_buses->value(bus)->isEmpty() ) delete queued_buses->take( bus ); } keys = active_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !active_buses->contains(bus) ) continue; if( active_buses->value(bus) == this ) finish( bus ); } }
void SBusController::setPassUpAndWait( bool state ) { if( p->pass_up_and_wait == state ) return; p->pass_up_and_wait = state; if( state ) { /*! ----------------- Find Active Buses ---------------- */ QStringList keys = active_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( !active_buses->contains(bus) ) continue; SBusController *controller = active_buses->value( bus ); if( controller == this ) { finish( bus ); getAccess( bus ); } } } else { /*! ----------------- Find Disabled Buses ---------------- */ QStringList keys = queued_buses->keys(); for( int i=0 ; i<keys.count() ; i++ ) { const QString & bus = keys.at(i); if( active_buses->contains(bus) ) continue; /*! ---------- Find First Deactived Processes to Active --------- */ if( !queued_buses->contains(bus) ) continue; QQueue<SBusController*> *queue = queued_buses->value(bus); if( queue == 0 ) continue; for( int j=0 ; j<queue->count() ; j++ ) { if( queue->at(j) != this ) continue; queue->removeAt( j ); if( queue->isEmpty() ) delete queued_buses->take( bus ); active_buses->insert( bus , this ); emit go(); break; } } } }
void RefInterface::range() { if(radioNum == 0) { radioFd = radioCom; if(antennaNum == 0) { buffer.reqNode = "101A"; //range to the controller using radio A if (rcmRangeTo(destNode, ANTENNAMODE_A, 0, NULL, &RangeInfo, &dataInfo, &scanInfo, &fullScanInfo) == 0) { //This gets the precision range measurement if (RangeInfo.rangeMeasurementType & RCM_RANGE_TYPE_PRECISION) { ////qDebug()<<"Precision range: "<< RangeInfo.precisionRangeMm; r0 = RangeInfo.precisionRangeMm; } //if the status comes back as 0, the radio ranged correctly if (RangeInfo.rangeStatus == 0) { // add range to buffer structure r0 = r0/1000; buffer.R0 = r0; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; ////qDebug()<<"Range Successful"; } else if(RangeInfo.precisionRangeErrEst > 60) { if(!msg.isEmpty()) { buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; thresholdErrorCountR0++; emit sendThresholdCount(thresholdErrorCountR0, thresholdErrorCountR1, thresholdErrorCountR2, thresholdErrorCountR3); emit display(buffer.x, buffer.y, buffer.z, RangeInfo.precisionRangeMm, buffer.R1, buffer.R2, buffer.R3,buffer.roll, buffer.pitch,buffer.yaw, buffer.mError,buffer.status); r0 = msg.at(0).R0; buffer.R0 = r0; } } else { r0 = msg.at(0).R0; buffer.R0 = r0; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; errorCountR0++; emit sendErrorCount(errorCountR0, errorCountR1, errorCountR2, errorCountR3); } } //end if antennaNum = 1; return; } if(antennaNum == 1) { buffer.reqNode = "101B"; //range to controller using radio B if (rcmRangeTo(destNode, ANTENNAMODE_B, 0, NULL, &RangeInfo, &dataInfo, &scanInfo, &fullScanInfo) == 0) { // Get precision range measurement from msg received if (RangeInfo.rangeMeasurementType & RCM_RANGE_TYPE_PRECISION) { ////qDebug()<<"Precision range: "<< RangeInfo.precisionRangeMm; r1 = RangeInfo.precisionRangeMm; } //if the status is 0, range was successful if (RangeInfo.rangeStatus == 0) { ////qDebug()<<"Range Successful"; //add range to buffer struct r1 = r1/1000; buffer.R1 = r1; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; } else if(RangeInfo.precisionRangeErrEst >60) { if(!msg.isEmpty()) { buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; thresholdErrorCountR1++; emit sendThresholdCount(thresholdErrorCountR0, thresholdErrorCountR1, thresholdErrorCountR2, thresholdErrorCountR3); emit display(buffer.x, buffer.y, buffer.z, buffer.R0, RangeInfo.precisionRangeMm, buffer.R2, buffer.R3,buffer.roll, buffer.pitch,buffer.yaw, buffer.mError,buffer.status); r1 = msg.at(0).R1; buffer.R1 = r1; } } else { r1 = msg.at(0).R1; buffer.R1 = r1; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; errorCountR1++; emit sendErrorCount(errorCountR0, errorCountR1, errorCountR2, errorCountR3); } } //end if antennaNum = 0; radioNum = 1; return; } } if(radioNum == 1) { radioFd = radioCom1; if(antennaNum == 0) { buffer.reqNode = "102A"; if (rcmRangeTo(destNode, ANTENNAMODE_A, 0, NULL, &RangeInfo, &dataInfo, &scanInfo, &fullScanInfo) == 0) { //This gets the precision range measurement if (RangeInfo.rangeMeasurementType & RCM_RANGE_TYPE_PRECISION) { ////qDebug()<<"Precision range: "<< RangeInfo.precisionRangeMm; r2 = RangeInfo.precisionRangeMm; } //if the status comes back as 0, the radio ranged correctly if (RangeInfo.rangeStatus == 0) { ////qDebug()<<"Range Successful"; // add range to buffer structure r2 = r2/1000; buffer.R2 = r2; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; } else if(RangeInfo.precisionRangeErrEst > 60) { if(!msg.isEmpty()) { buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; thresholdErrorCountR3++; emit sendThresholdCount(thresholdErrorCountR0, thresholdErrorCountR1, thresholdErrorCountR2, thresholdErrorCountR3); emit display(buffer.x, buffer.y, buffer.z, buffer.R0,buffer.R1 , RangeInfo.precisionRangeMm, buffer.R3,buffer.roll, buffer.pitch,buffer.yaw, buffer.mError,buffer.status); r2 = msg.at(0).R2; buffer.R2 = r2; } } else { r2 = msg.at(0).R2; buffer.R2 = r2; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; errorCountR2++; emit sendErrorCount(errorCountR0, errorCountR1, errorCountR2, errorCountR3); } } //end if antennaNum = 1; return; } if(antennaNum == 1) { buffer.reqNode = "102B"; if (rcmRangeTo(destNode, ANTENNAMODE_B, 0, NULL, &RangeInfo, &dataInfo, &scanInfo, &fullScanInfo) == 0) { // Get precision range measurement from msg received if (RangeInfo.rangeMeasurementType & RCM_RANGE_TYPE_PRECISION) { ////qDebug()<<"Precision range: "<< RangeInfo.precisionRangeMm; r3 = RangeInfo.precisionRangeMm; } //if the status is 0, range was successful if (RangeInfo.rangeStatus == 0) { ////qDebug()<<"Range Successful"<<" r3"<<r3; //add range to buffer struct r3 = r3/1000; buffer.R3 = r3; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; } else if(RangeInfo.precisionRangeErrEst > 60) { if(!msg.isEmpty()) { buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; thresholdErrorCountR3++; emit sendThresholdCount(thresholdErrorCountR0, thresholdErrorCountR1, thresholdErrorCountR2, thresholdErrorCountR3); emit display(buffer.x, buffer.y, buffer.z, buffer.R0,buffer.R1 , buffer.R2, RangeInfo.precisionRangeMm,buffer.roll, buffer.pitch,buffer.yaw, buffer.mError,buffer.status); r3 = msg.at(0).R3; buffer.R3 = r3; } } else { r3 = msg.at(0).R3; buffer.R3 = r3; buffer.mError = RangeInfo.precisionRangeErrEst; buffer.status = RangeInfo.rangeStatus; errorCountR3++; emit sendErrorCount(errorCountR0, errorCountR1, errorCountR2, errorCountR3); } } //end if antennaNum = 0; radioNum = 0; return; } } }