Beispiel #1
0
void drawFrameProcCPU(int w, int h, int texOut)
{
    LOGD("Processing on CPU");
    int64_t t;

    // let's modify pixels in FBO texture in C++ code (on CPU)
    static cv::Mat m;
    m.create(h, w, CV_8UC4);

    // read
    t = getTimeMs();
    // expecting FBO to be bound
    glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data);
    LOGD("glReadPixels() costs %d ms", getTimeInterval(t));

   // modify
    t = getTimeMs();
    cv::Laplacian(m, m, CV_8U);
    m *= 10;
    LOGD("Laplacian() costs %d ms", getTimeInterval(t));

    // write back
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texOut);
    t = getTimeMs();
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m.data);
    LOGD("glTexSubImage2D() costs %d ms", getTimeInterval(t));
}
Beispiel #2
0
void procOCL_I2I(int texIn, int texOut, int w, int h)
{
    if(!haveOpenCL) return;

    LOGD("procOCL_I2I(%d, %d, %d, %d)", texIn, texOut, w, h);
    cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY,  GL_TEXTURE_2D, 0, texIn);
    cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, texOut);
    std::vector < cl::Memory > images;
    images.push_back(imgIn);
    images.push_back(imgOut);

    int64_t t = getTimeMs();
    theQueue.enqueueAcquireGLObjects(&images);
    theQueue.finish();
    LOGD("enqueueAcquireGLObjects() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    cl::Kernel Laplacian(theProgI2I, "Laplacian"); //TODO: may be done once
    Laplacian.setArg(0, imgIn);
    Laplacian.setArg(1, imgOut);
    theQueue.finish();
    LOGD("Kernel() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    theQueue.enqueueNDRangeKernel(Laplacian, cl::NullRange, cl::NDRange(w, h), cl::NullRange);
    theQueue.finish();
    LOGD("enqueueNDRangeKernel() costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    theQueue.enqueueReleaseGLObjects(&images);
    theQueue.finish();
    LOGD("enqueueReleaseGLObjects() costs %d ms", getTimeInterval(t));
}
Beispiel #3
0
void procOCL_OCV(int tex, int w, int h)
{
    int64_t t = getTimeMs();
    cl::ImageGL imgIn (theContext, CL_MEM_READ_ONLY,  GL_TEXTURE_2D, 0, tex);
    std::vector < cl::Memory > images(1, imgIn);
    theQueue.enqueueAcquireGLObjects(&images);
    theQueue.finish();
    cv::UMat uIn, uOut, uTmp;
    cv::ocl::convertFromImage(imgIn(), uIn);
    LOGD("loading texture data to OpenCV UMat costs %d ms", getTimeInterval(t));
    theQueue.enqueueReleaseGLObjects(&images);

    t = getTimeMs();
    //cv::blur(uIn, uOut, cv::Size(5, 5));
    cv::Laplacian(uIn, uTmp, CV_8U);
    cv:multiply(uTmp, 10, uOut);
    cv::ocl::finish();
    LOGD("OpenCV processing costs %d ms", getTimeInterval(t));

    t = getTimeMs();
    cl::ImageGL imgOut(theContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, tex);
    images.clear();
    images.push_back(imgOut);
    theQueue.enqueueAcquireGLObjects(&images);
    cl_mem clBuffer = (cl_mem)uOut.handle(cv::ACCESS_READ);
    cl_command_queue q = (cl_command_queue)cv::ocl::Queue::getDefault().ptr();
    size_t offset = 0;
    size_t origin[3] = { 0, 0, 0 };
    size_t region[3] = { w, h, 1 };
    CV_Assert(clEnqueueCopyBufferToImage (q, clBuffer, imgOut(), offset, origin, region, 0, NULL, NULL) == CL_SUCCESS);
    theQueue.enqueueReleaseGLObjects(&images);
    cv::ocl::finish();
    LOGD("uploading results to texture costs %d ms", getTimeInterval(t));
}
Beispiel #4
0
void main()
{
	init();
	
	pthread_t threads[THREADS_AMOUNT];
	int threadArguments[THREADS_AMOUNT];

	struct timeval begin, end;
	int i;

	gettimeofday(&begin, NULL);
	for (i = 0; i<THREADS_AMOUNT; i++)
	{
		threadArguments[i] = i;
		pthread_create(&threads[i], NULL, multiplication, (void *)&threadArguments[i]);
	}
	
	for (i = 0; i<THREADS_AMOUNT; i++)
	{
		pthread_join(threads[i], NULL);
	}
	gettimeofday(&end, NULL);

	printf("complicatedTest: %ims\r\n", getTimeInterval(begin, end));
}
/**
 * @brief 
 * Use Euler Advection Scheme to Solve the PDE.
 */
int ConvectionSolve2d(structMesh *mesh, physics *phy, double** c, double finalTime){
    double time, CFL, dt;
    double **rhs = Matrix_create(mesh->ndim1, mesh->ndim2);
    
    time      = 0.0;
    CFL       = 0.1;
    
    // calculate time interval - dt
    dt = getTimeInterval(mesh, phy, CFL);

    double start, stop;
    start = MPI_Wtime();
    
    while (time < finalTime) {
        
        // increase local time
        if (time+dt > finalTime) {
            dt   = finalTime - time;
            time = finalTime;
        }else{
            time += dt;
        }
        
        TimeEvolution(mesh, phy, c, time, dt, rhs);
    }

    stop = MPI_Wtime();
    printf("Time Usaged: %f\n", (stop-start)*1000.0 );
    
    Matrix_free(rhs);
    return 0;
}
Beispiel #6
0
void Livininabox(){
   double time;
   time = getTimeInterval();
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   if(time >  0.0   && time < 16.17)     KnockKnock(time);
   if(time > 16.04  && time < 27.07)     drawExplosion(time - 16.04);
   if(time > 16.17  && time < 27.07)     JumpOut(time - 16.17);
   if(time > 27.07  && time < 52.23)     RunForLife(time - 27.07);
   if(time > 52.23  && time < 66.50)     Credits(time);
   if(time > 66.50  && time < 118.06)    Greetings(time - 66.50);
   if(time > 118.06 && time < 134.00)    ProceduralScenes(time - 118.06);
   if(time > 134.00 && time < 162.94)    FractalMe(time - 134.00);
   if(time > 162.94 && time < 196.94)    CubeTunnel(time - 162.94);
   if(time > 196.94 && time < 221.26)    Trap(time - 196.94);
   if(time > 221.26 && time < 226.86)    HangingFruite(time - 221.26);
   if(time > 226.86 && time < 248.49)    WatchOutForTheLetters(time - 226.86);
   if(time > 248.49 && time < 271.87)    OpenTheDoor(time - 248.49);
   if(time > 271.87 && time < 276.85)    Headbreak(time);
   if(time > 276.85 && time < 283.33)    Matatas(time);
   if(time > 283.33 && time < 300.00)    Cube(time - 283.33);
   if(time > 300.00 && time < 307.00)    End();

   if(time > 307.00) cg_isrunning = 0;
}
Beispiel #7
0
//
//  Get new values and update plot
//
void MainWindow::onDrawPlot()
{
    //qDebug() << "MainWindow::OnDrawPlot() - ThreadId: " << QThread::currentThreadId();

    int nrOfValues = m_kldatabase->getNrOfValues(getTimeInterval());
    x1->resize(nrOfValues);
    y1->resize(nrOfValues);
    y2->resize(nrOfValues);
    y3->resize(nrOfValues);
    y4->resize(nrOfValues);

    int count = m_kldatabase->getValues(getTimeInterval(), x1, y1, y2, y3, y4);

    if(count == 0)
        return;

    double y1Min = getMinValue(y1);
    double y1Max = getMaxValue(y1);
    double y2Min = getMinValue(y2);
    double y2Max = getMaxValue(y2);
    double y3Min = getMinValue(y3);
    double y3Max = getMaxValue(y3);
    double y4Min = getMinValue(y4);
    double y4Max = getMaxValue(y4);

    double minTemperature = y1Min <= y3Min ? y1Min : y3Min;
    double maxTemperature = y1Max >= y3Max ? y1Max : y3Max;
    double minHumidity    = y2Min <= y4Min ? y2Min : y4Min;
    double maxHumidity    = y2Max >= y4Max ? y2Max : y4Max;

    minTemperature = (minTemperature / 5.0 - 1.0) * 5.0;
    maxTemperature = (maxTemperature / 5.0 + 1.0) * 5.0;
    minHumidity    = (minHumidity / 5.0 - 1.0) * 5.0;
    maxHumidity    = (maxHumidity / 5.0 + 1.0) * 5.0;

    //update UI
    // get created graphs
    QCPGraph *graph1 = ui->customPlot->graph(0);
    QCPGraph *graph2 = ui->customPlot->graph(1);
    QCPGraph *graph3 = ui->customPlot->graph(2);
    QCPGraph *graph4 = ui->customPlot->graph(3);

    //.. and update the values
    graph1->setData(*x1, *y1);
    graph2->setData(*x1, *y2);
    graph3->setData(*x1, *y3);
    graph4->setData(*x1, *y4);

    // calculate tick below lowest x axis value and above highest x axis value
    long minTick = ((long)(((*x1)[0] - TIME_BASIS) / getTickSpacing()) * getTickSpacing()) + TIME_BASIS ;
    long maxTick = ((long)(((*x1)[count-1] - TIME_BASIS) / getTickSpacing() + 1 ) * getTickSpacing()) + TIME_BASIS;

    // generete and set ticks for x axis
    QVector<double> xAxisTicks(0);
    int i =0;
    long actualTick = minTick;
    while ( actualTick <= maxTick){
        actualTick =  minTick + i * getTickSpacing();
        xAxisTicks.append(actualTick);
        i = i + 1;
    }
    ui->customPlot->xAxis->setTickVector(xAxisTicks);

    //reconfigure axis
    ui->customPlot->xAxis->setRange((*x1)[0], (*x1)[count-1]);

    ui->customPlot->yAxis->setRange(minTemperature, maxTemperature);
    ui->customPlot->yAxis2->setRange(minHumidity, maxHumidity);

    //redraw
    ui->customPlot->replot();
}