예제 #1
0
파일: main.cpp 프로젝트: duxing/GPUFinal
void raytrace()
{
	uint* imagedata;
	cutilSafeCall(cudaGLMapBufferObject((void**)&imagedata, pbo));

	float3 A, B, C;
	camera.getImagePlane(A, B, C);
	dev_camera d_cam(camera.getPosition(), A, B, C, aperture, focal);
	dev_light d_light(light.getPosition(), light.getColor(), 4096);
	//need to change here.
	float3 minAABB, maxAABB;
	world.getAABB(minAABB, maxAABB);
	sceneInfo scene(world.getNumTriangles(), world.getNumSpheres(), world.getNumBoxes(), minAABB, maxAABB);
	//TODO: add control for clear buffer here.
	//change here for the many object case
	raytraceImage(imagedata, dev_lastframe_ptr, dev_num_layers, r_width, r_height, moved, d_cam, d_light, scene);
	//for showing the real frame rate
	cudaMemcpy(&frame_num, dev_num_layers, sizeof(float), cudaMemcpyDeviceToHost);
	frame_num++;
	cudaMemcpy(dev_num_layers, &frame_num, sizeof(int), cudaMemcpyHostToDevice);
	cutilSafeCall(cudaGLUnmapBufferObject(pbo));

	//download texture from pbo
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
	glBindTexture(GL_TEXTURE_2D, framebuffer);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r_width, r_height, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

	CUT_CHECK_ERROR_GL();
}
예제 #2
0
void KnotsViewer::draw_fitting_error_colorbar(QPainter *painter)
{
    const int barwidth = 20;
    const int barheight = 200;
    painter->save();
    painter->translate(0.8*width(), 0.7*height());
    painter->save();
    int h1, s1, v1;
    int h2, s2, v2;
    int color[3];
    color[0] =250;
    color[1] = 0;
    color[2] = 250;
    QColor d_light(color[0], color[1], color[2]);

    color[0] = 0;
    color[1] = 127;
    color[2] = 0;
    QColor d_dark(color[0], color[1], color[2]);
    d_light.getHsv( &h1, &s1, &v1 );
    d_dark.getHsv( &h2, &s2, &v2 );
    QRect rect(0, -100, barwidth, barheight);
    painter->setClipRect( rect );//设置裁剪,默认用裁剪后的替代原先的。
    painter->setClipping( true );

    painter->fillRect( rect, d_dark );//用d_dark来填充rect

    int sectionSize = 4;

    int numIntervals;
    numIntervals = rect.height() / sectionSize;

    for ( int i = 0; i < numIntervals; i++ )
    {
        QRect colorsection;
        colorsection.setRect( rect.x(), rect.y() + i * sectionSize,
                              rect.width(), sectionSize );

        const double ratio = i / static_cast<double>( numIntervals );
        QColor c;
        c.setHsv( h1 + qRound( ratio * ( h2 - h1 ) ),
                  s1 + qRound( ratio * ( s2 - s1 ) ),
                  v1 + qRound( ratio * ( v2 - v1 ) ) );

        painter->fillRect( colorsection, c );
    }
    painter->restore();
    sectionSize = 8;
    painter->translate(barwidth, 0);
    QFont font("Times", 10);
    painter->setPen(Qt::black);
    painter->setFont(font);
    double err_step = max_err / sectionSize;
    for ( int i = 0; i <= sectionSize; i++ )
    {
        QString str = QString::number(i*err_step);
        painter->drawText(5, barheight/2-barheight/8*i, str);
    }
    painter->restore();

}
예제 #3
0
void KnotsViewer::draw_curvature_colorbar(QPainter *painter)
{
    const int barwidth = 20;
    const int barheight = 200;
    painter->save();
    painter->translate(0.8*width(), 0.7*height());
    painter->save();
    int h1, s1, v1;
    int h2, s2, v2;
    int color[3];
    color[0] = 250;
    color[1] = 0;
    color[2] = 0;
    QColor d_light(color[0], color[1], color[2]);

    color[0] = 0;
    color[1] = 0;
    color[2] = 255;
    QColor d_dark(color[0], color[1], color[2]);
    d_light.getHsv( &h1, &s1, &v1 );
    d_dark.getHsv( &h2, &s2, &v2 );
    QRect rect(0, -100, barwidth, barheight);
    painter->setClipRect( rect );
    painter->setClipping( true );

    painter->fillRect( rect, d_dark );

    int sectionSize = 4;

    int numIntervals;
    numIntervals = rect.height() / sectionSize;

    for ( int i = 0; i < numIntervals; i++ )
    {
        QRect colorsection;
        colorsection.setRect( rect.x(), rect.y() + i * sectionSize,
                              rect.width(), sectionSize );

        const double ratio = i / static_cast<double>( numIntervals );
        QColor c;
        c.setHsv( h1 + qRound( ratio * ( h2 - h1 ) ),
                  s1 + qRound( ratio * ( s2 - s1 ) ),
                  v1 + qRound( ratio * ( v2 - v1 ) ) );
        /*int color[3];
        c.getRgb(&color[0], &color[1], &color[2]);*/
        painter->fillRect( colorsection, c );
    }
    painter->restore();
    sectionSize = 8;
    painter->translate(barwidth, 0);
    QFont font("Times", 10);
    painter->setPen(Qt::black);
    painter->setFont(font);
    double max_curve=surfacedata->get_max_meancurvature();
    double min_curve=surfacedata->get_min_meancurvature();
    double cur_step = (max_curve-min_curve)/ sectionSize;
    for ( int i = 0; i <= sectionSize; i++ )
    {
        QString str = QString::number(i*cur_step+min_curve);
        painter->drawText(5, barheight/2-barheight/8*i, str);
    }
    painter->restore();
}