Example #1
0
void MainWindow::updateData(QString data)
{
    QTime t;
    t.start();

    m_model.loadFromCSV( data );

    qDebug("Time for loading data %s: %d ms", data.toLatin1().constData(), t.elapsed());
    t.restart();

    QSize size1 = QSize( 200, 200 );
    QSize size2 = QSize( 800, 800 );
    m_pix1 = drawIntoPixmap( size1, m_chart );
    m_pix2 = drawIntoPixmap( size2, m_chart );

    qDebug("Time for drawing pixmap %s: %d ms", data.toLatin1().constData(), t.elapsed());
    t.restart();

    m_lines->setModel( &m_model );

    qDebug("Time for setting model %s: %d ms", data.toLatin1().constData(), t.elapsed());
    t.restart();

    m_smallChart1->setPixmap( m_pix1 );
    m_smallChart2->setPixmap( m_pix2 );

    m_smallChart1->show();
    m_smallChart2->show();

    qDebug("Time for setting pixmap %s: %d ms", data.toLatin1().constData(), t.elapsed());
    t.restart();

}
void PlayerHandler::computeBaseState()
{
	static QTime reloj=QTime::currentTime();
	static float xant;
	static float yant;
// 	float x = posIface->data->pose.pos.y*1000.;
// 	float z = posIface->data->pose.pos.x*1000.;
// 	client->Read();
	float x = pos->GetYPos()*1000.;
	float z = pos->GetXPos()*1000.;
	float dl = float ( x - xant );
	float dr = float ( z - yant );
	xant = bState.x;
	yant = bState.z;
	float incA = sqrt(dl*dl+dr*dr);
	mutex->lock();
		//Compute increments through robot kinematics
		client->Read();
		bState.adv = incA;
// 		bState.rotV = -posIface->data->velocity.yaw;
		bState.rotV = -pos->GetYawSpeed();
		bState.advV = incA / (float) reloj.restart() * 1000;
		bState.rotV = -pos->GetYawSpeed() / (float) reloj.restart() * 1000;
		bState.isMoving = (bState.advV!=0 or bState.rotV!=0);
		//position
// 		bState.alpha = posIface->data->pose.yaw - alfa;
		bState.alpha = pos->GetYaw();
		bState.x = ( r00*x + r01*z ) - (r00*t0 + r01*t1);
		bState.z = ( r10*x + r11*z ) - (r10*t0 + r11*t1);
// 		qDebug()<<bState.x<<bState.z<<rtod(bState.alpha);
	mutex->unlock();
}
Example #3
0
QGraphicsScene * ClusteredArranger::arrange(SegmentList const & segments) const {
   QGraphicsScene * arrangement = new QGraphicsScene();

   QTime time;
   time.start();

   // determine background
   Segment * background = determineBackground(segments);
   SegmentList segmentsWOBack = removeBackground(segments, background);
   arrangement->setBackgroundBrush(QBrush(QColor(background->color().toQRgb())));
   segmentsWOBack.calculateFeatureVariances();

   // initialize layout
   //initializeLayout(segmentsWOBack, segmentsWOBack.featX(), segmentsWOBack.featY());
   initializeLayout(segmentsWOBack, xAxisBox->currentIndex(), yAxisBox->currentIndex());

   // find clusters
   time.restart();
   QList<SegmentList> clusters = meanShift(segmentsWOBack);
   qDebug("Segments clustered in %f seconds", time.restart()/1000.0);
   qDebug("  %d clusters found", clusters.size());

   // refine clusters
   //int counter = 0;
   foreach (SegmentList cluster, clusters) {
      if (clusterBox->currentIndex() == 0) {
         refineLayoutCircles(cluster);
      }
      else if (clusterBox->currentIndex() == 1) {
         refineLayoutPiles(cluster);
      }

      // debug output
      /*QGraphicsScene scene;
      scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
      foreach(Segment * const segment, cluster) {
         scene.addItem(segment->toQGraphicsItem());
         // without the following line QPainter tends to crash
         scene.width();
      }
      ++counter;
      saveScene(&scene, QString("Test%1.png").arg(counter, 2));*/
   }

   // refine layout
   if (clusterBox->currentIndex() == 0) {
      refineLayoutByPlace(clusters);
   }
   else if (clusterBox->currentIndex() == 1) {
      refineLayoutBySize(clusters);
   }

   // convert the segments to QGraphicsItems and add to QGraphicsScene
   foreach(Segment const * const segment, segmentsWOBack) {
      arrangement->addItem(segment->toQGraphicsItem());
      // without the following line QPainter tends to crash
      arrangement->width();
   }
Example #4
0
void MainWindow::on_pushButton_9_clicked()
{
    QStringList times;
    std::string testString="Test string é!";
    std::string preparedString="sdflgsdfgpml$ùù";

    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            if(testString!=preparedString)
            {}
            if(testString==preparedString)
            {}
            index++;
        }
        times << QString("Condition with != and ==: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            testString+preparedString;
            index++;
        }
        times << QString("concat by +: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            stringreplaceAll(testString,preparedString,testString);
            index++;
        }
        times << QString("replace format to QString: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            stringreplaceAll(testString,preparedString,preparedString);
            index++;
        }
        times << QString("replace format to format: %1ms").arg(time.elapsed());
    }

    qDebug() << QString("Prepared c++11: \n%1").arg(times.join("\n"));
}
Example #5
0
VoiceSignature::VoiceSignature(const Sound& sound)
{
 	static uint temp_wind=0, temp_fft=0, temp_moy=0;
 	QTime t;
 	t.start();
	
	unsigned int start , stop;
	if(!window(sound,&start,&stop))
	{
		kWarning() << "No voice found in the sound" 	;
		return;
	}
	
	temp_wind+=t.restart();

	uint length=stop-start;

	for(int wind=0; wind<WINDOW_NUMBER; wind++)
	{
		unsigned int w_start=MAX(start, start+ (int)((wind - WINDOW_SUPER)*length/WINDOW_NUMBER));
		unsigned int w_stop =MIN(stop , start+ (int)((wind+1.0+WINDOW_SUPER)*length/WINDOW_NUMBER));
		

		QVector<double> fourrier=fft(sound, w_start,w_stop);
		
		temp_fft+=t.restart();

		//MEL conversion
		double mel_start=HZ_TO_MEL(FFT_RANGE_INF);
		uint mel_stop=HZ_TO_MEL(FFT_RANGE_SUP);
		
		for(int four=0; four<FOUR_NUMBER; four++)
		{
			unsigned int wf_start=mel_start + four*(mel_stop-mel_start)/FOUR_NUMBER;
			unsigned int wf_stop=mel_start + (four+1)*(mel_stop-mel_start)/FOUR_NUMBER;

			unsigned int f_start=MEL_TO_HZ( wf_start )*fourrier.size()/sound.fs();
			unsigned int f_stop=MEL_TO_HZ( wf_stop )*fourrier.size()/sound.fs();
			unsigned int f_size=f_stop-f_start;
			
			double nb=0;
			for(uint f=f_start; f<f_stop; f++)
			{
				int freq=f*fourrier.size()/sound.fs();
				nb+=fourrier[f]*FFT_PONDERATION(freq);
			}
			nb/=(f_size);
			data[wind][four]=nb;
		}
		
		temp_moy+=t.restart();

	}
	
//	kDebug() << "wind: "<< temp_wind << "  - fft: " << temp_fft << "  - moy: " << temp_moy;
}
Example #6
0
void App::applyEffect(QRectF rect, float zoom, float opacityA, float opacityB, float opacityC, float opacityD)
{
	QTime t;
	t.start();

	QRectF targetRect(0, 0, m_displayWidth, m_displayHeight);
	QRectF sourceRect(rect.x() / zoom, rect.y() / zoom, rect.width(), rect.height());

	QImage resultImage(QSize(m_displayWidth, m_displayHeight), QImage::Format_ARGB32_Premultiplied);

	QImage baseImage = Helper::createImageFromTile(m_tile, m_displayWidth, m_displayHeight);
	baseImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);

	QDir imageDir = QDir::current();
	imageDir.cd("app/native/assets/images");

	QImage overlay1(imageDir.absoluteFilePath("effect1.png"));
	overlay1.convertToFormat(QImage::Format_ARGB32_Premultiplied);

	QImage overlay2(imageDir.absoluteFilePath("effect2.png"));
	overlay2.convertToFormat(QImage::Format_ARGB32_Premultiplied);

	QImage overlay3(imageDir.absoluteFilePath("effect3.png"));
	overlay3.convertToFormat(QImage::Format_ARGB32_Premultiplied);

	QImage overlay4(imageDir.absoluteFilePath("effect4.png"));
	overlay4.convertToFormat(QImage::Format_ARGB32_Premultiplied);

	qDebug() << "TIME: loading images:" << t.elapsed();
	t.restart();

	QPainter p(&resultImage);
	p.drawImage(targetRect, baseImage, sourceRect);
	p.setCompositionMode(QPainter::CompositionMode_SourceOver);
	p.setOpacity(opacityA);
	p.drawImage(0,0, overlay1);
	p.setOpacity(opacityB);
	p.drawImage(0,0, overlay2);
	p.setOpacity(opacityC);
	p.drawImage(0,0, overlay3);
	p.setOpacity(opacityD);
	p.drawImage(0,0, overlay4);
	p.end();

	qDebug() << "TIME drawing final image:" << t.elapsed();
	t.restart();

	m_bigImageCache = resultImage;

	bb::cascades::Image cimg = Helper::convertImage(resultImage);
	setBigImage(cimg);

	qDebug() << "TIME converting final image:" << t.elapsed();
	t.restart();
}
Example #7
0
void testOctree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vector<vcg::Point3f>& randomSamples)
{
    std::cout << "==================================================="<< std::endl;
    std::cout << "Octree" << std::endl;
    QTime time;
    time.start();

    // Construction of the uniform grid
    typedef vcg::Octree<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
    MeshGrid uniformGrid;
    uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
    std::cout << "Build: " << time.elapsed() <<  " ms" << std::endl;

    // Test with the radius search
    std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
    float  avgTime = 0.0f;
    for (int ii = 0; ii < num_test; ii++)
    {
        time.restart();
        std::vector<CMesh::VertexPointer> vertexPtr;
        std::vector<CMesh::VertexType::CoordType> points;
        std::vector<float> dists;
        vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
        avgTime += time.elapsed();
    }
    std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)"  << std::endl;

    // Test with the k-nearest search
    std::cout << "k-Nearest search (" << num_test*10 << " tests)"<< std::endl;
    avgTime = 0.0f;
    for (int ii = 0; ii < num_test * 10; ii++)
    {
        time.restart();
        std::vector<CMesh::VertexPointer> vertexPtr;
        std::vector<CMesh::VertexType::CoordType> points;
        std::vector<float> dists;
        vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points);
        avgTime += time.elapsed();
    }
    std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)"  << std::endl;

    // Test with the Closest search
    std::cout << "Closest search (" << num_test*10 << " tests)"<< std::endl;
    avgTime = 0.0f;
    for (int ii = 0; ii < num_test * 10; ii++)
    {
        time.restart();
        float minDist;
        vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist);
        avgTime += time.elapsed();
    }
    std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)"  << std::endl << std::endl;
}
static bool HasSomethingToPaste (kpMainWindow *mw)
{
#if DEBUG_KP_MAIN_WINDOW
    kdDebug () << "kpMainWindow(" << mw->name () << "):HasSomethingToPaste()" << endl;
    QTime timer;
    timer.start ();
#else
    (void) mw;
#endif

    bool hasSomething = false;

    QMimeSource *ms = QApplication::clipboard ()->data (QClipboard::Clipboard);
    if (ms)
    {
        // It's faster to test for QTextDrag::canDecode() first due to the
        // lazy evaluation of the '||' operator.
        hasSomething = (QTextDrag::canDecode (ms) ||
                        kpSelectionDrag::canDecode (ms));
    #if DEBUG_KP_MAIN_WINDOW
        kdDebug () << "\t" << mw->name () << "***canDecode=" << timer.restart () << endl;
        for (int i = 0; ; i++)
        {
            const char *fmt = ms->format (i);
            if (!fmt)
                break;

            kdDebug () << "\t'" << fmt << "'" << endl;
        }
    #endif
    }

    return hasSomething;
}
void SpecificWorker::compute()
{
	static QTime reloj = QTime::currentTime();
	static int fps=0;
	
	Mat frame, frameRGB;
	grabber.read(frame); 	
	cvtColor( frame, frameRGB, CV_BGR2RGB );
	memcpy( &writeBuffer[0], frameRGB.data, frameRGB.size().area() * 3);
// 	qDebug() << "Reading..."; // at" << grabber.get(CV_CAP_PROP_FPS) << "fps";
// 	imshow("img", frame);
	QMutexLocker ml(mutex);
	readBuffer.swap( writeBuffer);
	
	if( reloj.elapsed() > 1000)
	{
		qDebug() << "Grabbing at"<< fps << "FPS ";
		fps=0;
		reloj.restart();
	}
	fps++;
	
	//if(waitKey(30) >= 0) exit(-1);
	
}
Example #10
0
static void artisticSleep(int sleepTime)
{
    QTime time;
    time.restart();
    while (time.elapsed() < sleepTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
}
Example #11
0
void testPerfectSpatialHashing(CMesh& mesh, std::vector<unsigned int>& test_indeces)
{
    std::cout << "==================================================="<< std::endl;
    std::cout << "Perfect Spatial Hashing" << std::endl;
    QTime time;
    time.start();

    // Construction of the uniform grid
    typedef vcg::SpatialHashTable<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
    MeshGrid uniformGrid;
    uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
    std::cout << "Build: " << time.elapsed() <<  " ms" << std::endl;

    // Test with the radius search
    std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
    float  avgTime = 0.0f;
    for (int ii = 0; ii < num_test; ii++)
    {
        time.restart();
        std::vector<CMesh::VertexPointer> vertexPtr;
        std::vector<CMesh::VertexType::CoordType> points;
        std::vector<float> dists;
        vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
        avgTime += time.elapsed();
    }
    std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)"  << std::endl << std::endl;
}
void SpecificWorker::compute( )
{
	static QTime reloj = QTime::currentTime();
	static bool first=true;

	if (first)
	{
		qLog::getInstance()->setProxy("both", logger_proxy);
		rDebug2(("navigationAgent started"));
		first = false;
	}

	if (worldModel->getIdentifierByType("robot") < 0)
	{
		try
		{
			RoboCompAGMWorldModel::World w = agmexecutive_proxy->getModel();
			structuralChange(w);
		}
		catch(...)
		{
			printf("The executive is probably not running, waiting for first AGM model publication...");
		}
	}
	actionExecution();
	worker_params_mutex->lock();
		//save framerate in params
		worker_params["frameRate"].value = std::to_string(reloj.restart()/1000.f);
	worker_params_mutex->unlock();
}
Example #13
0
void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
    if (lastReceivedBytes == 0) {
        ui->progressBar_FullScan->setMaximum(bytesTotal);
    }

    ui->progressBar_FullScan->setValue(bytesReceived);

    QTime nowTime;
    nowTime.restart();

    int delta = lastReceivedBytesTime.msecsTo(nowTime);

    if (delta < 500 && bytesReceived < bytesTotal)
        return;

    QString downloadingFile = filesToDownload.at(nextFileToDownload);
    downloadingFile = downloadingFile.mid(downloadingFile.lastIndexOf("/") + 1);

    int speed = 0;

    if (delta != 0)
        speed = ((bytesReceived - lastReceivedBytes) / delta);

    QString label = "Downloading: " + downloadingFile + " " + QString::number(bytesReceived / 1000) + " kB / " + QString::number(bytesTotal / 1000) + " kB " + QString::number(speed) + " kB/s";
    ui->label_current_work->setStyleSheet("color:black");
    ui->label_current_work->setText(label);

    lastReceivedBytesTime.restart();
    lastReceivedBytes = bytesReceived;
}
bool QGalleryTrackerResultSet::waitForFinished(int msecs)
{
    Q_D(QGalleryTrackerResultSet);

    QTime timer;
    timer.start();

    do {
        if (d->flags & QGalleryTrackerResultSetPrivate::Active) {
            if (d->waitForSyncFinish(msecs)) {
                d->parserThread.wait();

                d->_q_parseFinished();

                if (!(d->flags & QGalleryTrackerResultSetPrivate::Active))
                    return true;
            } else {
                return false;
            }
        } else if (d->flags & (QGalleryTrackerResultSetPrivate::Refresh)) {
            d->update();
        } else {
            return true;
        }
    } while ((msecs -= timer.restart()) > 0);

    return false;
}
Example #15
0
/**
 * Flushes the contents of the \a windowSurface into the screen area of \a widget.
 * \a tlwOffset is the position of the top level widget relative to the window surface.
 * \a region is the region to be updated in \a widget coordinates.
 */
static inline void qt_flush(QWidget *widget, const QRegion &region, QWindowSurface *windowSurface,
                            QWidget *tlw, const QPoint &tlwOffset)
{
    Q_ASSERT(widget);
    Q_ASSERT(!region.isEmpty());
    Q_ASSERT(windowSurface);
    Q_ASSERT(tlw);

#if !defined(QT_NO_PAINT_DEBUG)
    static int flushUpdate = qgetenv("QT_FLUSH_UPDATE").toInt();
    if (flushUpdate > 0)
        QWidgetBackingStore::showYellowThing(widget, region, flushUpdate * 10, false);
#endif

    //The performance hit by doing this should be negligible. However, be aware that
    //using this FPS when you have > 1 windowsurface can give you inaccurate FPS
    static bool fpsDebug = qgetenv("QT_DEBUG_FPS").toInt();
    if (fpsDebug) {
        static QTime time = QTime::currentTime();
        static int frames = 0;

        frames++;

        if(time.elapsed() > 5000) {
            double fps = double(frames * 1000) /time.restart();
            fprintf(stderr,"FPS: %.1f\n",fps);
            frames = 0;
        }
    }
    if (widget != tlw)
        windowSurface->flush(widget, region, tlwOffset + widget->mapTo(tlw, QPoint()));
    else
        windowSurface->flush(widget, region, tlwOffset);
}
Example #16
0
bool MyProcess::runSync(SCRef rc, QByteArray* ro, QObject* rcv, SCRef buf) {
	async = false;
	runCmd = rc;
	runOutput = ro;
	receiver = rcv;
	if (runOutput)
		runOutput->clear();

	setupSignals();
	if (!launchMe(runCmd, buf))
		return false;

	QTime t;
	t.start();

	busy = true; // we have to wait here until we exit

	while (busy) {
		waitForFinished(20); // suspend 20ms to let OS reschedule

		if (t.elapsed() > 200) {
			EM_PROCESS_EVENTS;
			t.restart();
		}
	}
	return !isErrorExit;
}
Example #17
0
void ExportThread::exportItems( const QString& name, ItemList& items, quint32& currentItem, QTime& time )
{
    if( !items.isEmpty() ) {
        QDir dir( m_directory );
        if( dir.exists() ) {
            if( !dir.cd( name ) )
                dir.mkdir( name );
            dir.cd( name );

            QTime rate;
            rate.start();
            quint32 count = 0;
            foreach( TibiaItem* item, items ) {
                if( isCanceled() )
                    break;
                if( exportItem( dir, item ) ) {
                    emit valueChanged( currentItem );
                    currentItem++;

                    if( ( float )( rate.elapsed() / 1000 ) >= 1 ) {
                        emit labelText( tr( "%1\n\nElapsed Time: %2\nTime left: %3" ).arg( m_labelText ).arg( QTime().addMSecs( time.elapsed() ).toString( "hh:mm:ss" ) ).arg( QTime().addMSecs( ( int )( ( ( float )( m_maximum - currentItem ) / count ) * ( float )1000 ) ).toString( "hh:mm:ss" ) ) );
                        //emit rateChanged( count, libraryFile->getCount() - i, time.elapsed() ); // Items/sec, Items remaining
                        rate.restart();
                        count = 0;
                    }

                    count++;
                }
            }
        }
    }
Example #18
0
void proc()
{
    GrammarTree gt;
    QVector<double> p(9);
    p[0] = 5;
    p[1] = 0.5;
    p[2] = 1;
    p[3] = true;
    p[4] = 45;
    p[5] = 30;
    p[6] = 0.3;
    p[7] = 2;
    p[8] = true;

    QTime timer;
    timer.start();
    for(int j = 0; j < 10; j ++)
    {
        QString d ("set arbre "+QString::number(j)+"/");
        QDir di;
        di.mkdir(d);
        for(int i = 0; i < 10; i++)
        {
            timer.restart();
            MeshBase::Mesh m = gt.generation(p);
            qDebug()<<"Génération de l'arbre "<<(j*10+i)<<"en"<<timer.elapsed()<<"ms";
            m.writeObj(d+"treeTest" + QString::number(i) + ".obj");
        }
    }
}
Example #19
0
void NelderMead::run() {
  NMWorker* worker = new NMWorker(liveCrystal);
  if (worker->valid()) {
    int loops = 0;
    int noImprovmentLoops=0;
    QTime rateLimiter;
    double bestEmitedScore=worker->bestScore();
    rateLimiter.start();
    forever {
      loops++;
      noImprovmentLoops++;
      threadLock.lockForRead();
      bool _shouldStop = shouldStop;
      threadLock.unlock();
      if (_shouldStop) {
        break;
      }

      double lastScore = worker->bestScore();
      worker->doOneIteration();
      if (worker->bestScore()<bestEmitedScore && rateLimiter.elapsed()>50) {
        bestEmitedScore = worker->bestScore();
        emit bestSolutionScore(worker->bestScore());
        emit bestSolution(worker->bestSolution(), worker->calcDeviation());
        rateLimiter.restart();
      }
      if (lastScore/worker->bestScore()>1.001) {
        noImprovmentLoops = 0;
      }
      double relativeScoreDifference = (worker->worstScore() - worker->bestScore())/worker->worstScore();
      if ((noImprovmentLoops>75) || (relativeScoreDifference < 1e-4)) {
        break;
      }
    }
  }
Example #20
0
bool QGalleryTrackerTypeResultSet::waitForFinished(int msecs)
{
    Q_D(QGalleryTrackerTypeResultSet);

    QTime timer;
    timer.start();
    do {
        if (QDBusPendingCallWatcher *watcher = d->queryWatcher) {
            d->queryWatcher = 0;

            watcher->waitForFinished();

            d->queryFinished(*watcher);

            delete watcher;

            if (d->state != QGalleryAbstractRequest::Active)
                return true;
        } else {
            return true;
        }
    } while ((msecs -= timer.restart()) > 0);

    return false;
}
    void run(){

        // we should be executed on the main queue
        MU_ASSERT_EQUAL_HEX(QDispatch::currentQueue().native(), dispatch_get_main_queue());

        // assert that we can really get the timer
        MU_ASSERT_EQUAL_HEX(QDispatchTimer::current(), tested_timer);

        // test the timer interval (but only after the second run
        // as the first one will be started immediately
        if(counter > 0) {
            long diff = checked_time.elapsed();
            MU_DESC_ASSERT_LESS_THAN_EQUAL("timer not too late", diff, 3*1000);
            MU_DESC_ASSERT_LESS_THAN_EQUAL("timer not too early", 1*1000, diff);
        }

        checked_time.restart();

        // only pass when the timer fired at least 5 times
        MU_MESSAGE("\t%i", counter);
        if(counter < 5)
            counter++;
        else {
            MU_PASS("");
        }
    }
Example #22
0
void task_attributes::run_impl()
{
  using namespace std;

  size_t counter(0);
  QTime time; time.start();
  shared_ptr<rowset_model> mdl(new rowset_model(0));
  auto rs(m_lr->attributes(get_frame()));
  mdl->m_columns = rs->columns();
  vector<brig::variant> row;

  for (; rs->fetch(row) && counter < brig::PageSize; ++counter)
  {
    vector<string> strs;
    for (const auto& v: row) strs.push_back(brig::string_cast<char>(v));
    mdl->m_rows.push_back(move(strs));

    if (time.elapsed() < BatchInterval) continue;
    progress(QString("rows: %1").arg(counter + 1));
    time.restart();
  }

  if (counter >= brig::PageSize) progress(QString("in excess of %1 rows").arg(brig::PageSize));
  else progress(QString("rows: %1").arg(counter));

  emit signal_rowset(mdl);
}
Example #23
0
void SpecificWorker::compute()
{
	static QTime reloj = QTime::currentTime();
	static int fps=0;
	
	Mat frame, frameRGB;
	grabber.read(frame); 	
	cvtColor( frame, frameRGB, CV_BGR2RGB );
	memcpy( &writeBuffer[0], frameRGB.data, frameRGB.size().area() * 3);
	//qDebug() << "Reading..."; // at" << grabber.get(CV_CAP_PROP_FPS) << "fps";
	//imshow("img", frame);
	QMutexLocker ml(mutex);
	readBuffer.swap( writeBuffer);
	
	if( reloj.elapsed() > 1000)
	{
		qDebug() << "Grabbing at"<< fps << "FPS ";
		fps=0;
		reloj.restart();
	}
	fps++;
	
	str->data = "If you are seeing this, it's mainly coz I'm awesome";
	test_pub.publish(str);
// 	ROS_INFO_STREAM("they see me rollin!");
	ros::spinOnce();
	//if(waitKey(30) >= 0) exit(-1);
	
}
Example #24
0
int work3() {
    int x = 0;
    QApplication a(x,0);
//1396","uid":"359887
    DanmuConnection dc;
    dc.debugFlag = true;
    dc.login("aabbeaabbe","aabbdaabbd", "359887","1396");
    QTime t;
    t.start();
    int count = 0;
     x = 1;
    while(true) {

        if (t.elapsed() >5000)  {
            count+=123123;
            //a = dc.postDanmu(QString ::number(count));
            //   QJsonObject({"action":1,"cmdid":"blockuser","ip":"111.8.57.138","msg":"111","nam
            //   e":"九千万亿电竞女神","type":1,"uid":100305463})

            x = 1-x;
           t.restart();
        }
        QCoreApplication::processEvents();
    }
    return a.exec();

}
Example #25
0
///
/// Set peak value (0.0 .. 1.0)
///
void Fader::setPeak( float fPeak, float &targetPeak, float &persistentPeak, QTime &lastPeakTime )
{
	if( fPeak <  m_fMinPeak )
	{
		fPeak = m_fMinPeak;
	}
	else if( fPeak > m_fMaxPeak )
	{
		fPeak = m_fMaxPeak;
	}

	if( targetPeak != fPeak)
	{
		targetPeak = fPeak;
		if( targetPeak >= persistentPeak )
		{
			persistentPeak = targetPeak;
			lastPeakTime.restart();
		}
		update();
	}

	if( persistentPeak > 0 && lastPeakTime.elapsed() > 1500 )
	{
		persistentPeak = qMax<float>( 0, persistentPeak-0.05 );
		update();
	}
}
Example #26
0
void Dialog::scanMaps(const QString &folderName)
{
    CatchChallenger::DebugClass::redirection=true;

    QTime startTime;
    startTime.restart();

    scanFolderMap(QDir(folderName));
    scanFolderPosition(QDir(folderName));

    qDebug() << startTime.elapsed();

    QString html="<ul>";
    QHash<QString,Map_full>::const_iterator i = other_map.constBegin();
    while (i != other_map.constEnd()) {
        if(i.value().log.size()>0)
        {
            html+="<li>"+i.key();
            html+="<ul><li>"+i.value().log.join("</li><li>")+"</li></ul>";
            html+="</li>";
        }
        ++i;
    }
    html+="</ul>";
    ui->textEdit->setHtml(html);
}
void process_gui_events_if_needed() {
#ifdef QT_VERSION
    if (s_timer.elapsed()>500) {
        qApp->processEvents();
        s_timer.restart();
    }
#endif
}
inline void roiDetector::printFPS( )
{
    static int fps=0;
    static QTime ti;
    if ((++fps % 50) == 0) {
        qDebug() << " VisionComp Cam fps: " << (50000 / ti.restart())/params.numCams;
    }
}
Example #29
0
void BenchWidget::paintEvent(QPaintEvent *)
{
    if (m_done)
        return;

    QPainter p(this);

    m_benchmark->begin(&p, 100);

    PaintingRectAdjuster adjuster;
    adjuster.setNewBenchmark(m_benchmark);
    adjuster.reset(rect());

    for (int i = 0; i < 100; ++i)
        m_benchmark->draw(&p, adjuster.newPaintingRect(), i);

    m_benchmark->end(&p);

    ++m_iteration;

    uint currentElapsed = timer.isNull() ? 0 : timer.elapsed();
    timer.restart();

    m_total += currentElapsed;

    // warm up for at most 5 iterations or half a second
    if (m_iteration >= 5 || m_total >= 500) {
        iterationTimes << currentElapsed;

        if (iterationTimes.size() >= 5) {
            qreal mean = 0;
            qreal stddev = 0;
            uint min = INT_MAX;

            for (int i = 0; i < iterationTimes.size(); ++i) {
                mean += iterationTimes.at(i);
                min = qMin(min, iterationTimes.at(i));
            }

            mean /= qreal(iterationTimes.size());

            for (int i = 0; i < iterationTimes.size(); ++i) {
                qreal delta = iterationTimes.at(i) - mean;
                stddev += delta * delta;
            }

            stddev = qSqrt(stddev / iterationTimes.size());

            stddev = 100 * stddev / mean;
            // do 50 iterations, break earlier if we spend more than 5 seconds or have a low std deviation after 2 seconds
            if (iterationTimes.size() >= 50 || m_total >= 5000 || (m_total >= 2000 && stddev < 4)) {
                m_result = min;
                m_done = true;
                return;
            }
        }
    }
}
Example #30
-1
void MainWindow::on_pushButton_8_clicked()
{
    QStringList times;
    std::string testString="Test string é!";

    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            if(testString!=std::string("test bis"))
            {}
            if(testString==std::string("test bis"))
            {}
            index++;
        }
        times << QString("Condition with != and ==: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            testString+std::string("test bis");
            index++;
        }
        times << QString("concat by +: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            stringreplaceAll(testString,std::string("test bis"),testString);
            index++;
        }
        times << QString("replace format to QString: %1ms").arg(time.elapsed());
    }
    {
        QTime time;
        time.restart();
        quint64 index=0;
        while(index<6553500)
        {
            stringreplaceAll(testString,std::string("test bis"),std::string("test bis"));
            index++;
        }
        times << QString("replace format to format: %1ms").arg(time.elapsed());
    }

    qDebug() << QString("dyna string c++11: \n%1").arg(times.join("\n"));
}