如何使用opengl绘制cuda中的点数 [英] How can I plot the points in cuda using opengl

查看:69
本文介绍了如何使用opengl绘制cuda中的点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带点数的csv文件,我需要在cuda中使用opengl在多维数据集中获取值和ploat。我已经绘制了立方体中的点。但我不知道它如何在cuda实施。我需要帮助。



我尝试过:



#include < cstdlib>

#include< ctime>

#include< cmath>

#include< fstream>

#include< iostream>

#include< iomanip>

#include< GL / glut.h>

#include< string>

#include< sstream>

#include< vector>

#include< string>

使用命名空间std;



void display();

double rotate_y = 0;

double rotate_x = 0;

GLfloat xRotated,yRotated,zRotated;

double zoom = 0.5;

< br $>




无效显示(){



glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

glLoadIdentity();

glScalef(缩放,缩放,1.0f);

glTranslatef(0.0,0.0,-10.5);

glRotatef(xRotated,1.0,0.0,0.0);

glRotatef(yRotated,0.0,1.0,0.0);

glRotatef(zRotated,0.0 ,0.0,1.0);







glColor3f(1,1,1);

glBegin(GL_LINE_LOOP);

glVertex3f(0.1,-0.01,-0.01);

glVertex3f(0.1,0.1,-0.01);

glVertex3f(-0.01,0.1,-0.01);

glVertex3f(-0.01,-0.01,-0.01);

glEnd();

glBegin(GL_LINE_LOOP);

glVertex3f(0.1,-0.01,0.1);

glVertex3f(0.1,0.1,0.1);

glVertex3f(-0.01,0.1,0.1);

glVertex3f(-0.01,-0.01,0.1);

glEnd();

glBegin(GL_LINE_LOOP);

glVertex3f(0.1,-0.01,-0.01);

glVertex3f (0.1,0.1,-0.01);

glVertex3f(0.1,0.1,0.1);

glVertex3f(0.1,-0.01,0.1);

glEnd();

glBegin(GL_LINE_LOOP);

glVertex3f(-0.01,-0.01,0.1);

glVertex3f(-0.01 ,0.1,0.1);

glVertex3f(-0.01,0.1,-0.01);

glVertex3f(-0.01,-0.01,-0.01);

glEnd();





浮动f1,f2,f3;



FILE * fp;

fp = fopen(golgi.csv,r);



while(fscanf (fp,%g,%g,%g \ n,& f1,& f2,& f3)== 3)

{

glPo intSize(7);

glColor3f(0,0,1);

glBegin(GL_POINTS);

glVertex3f(f1,f2,f3 );

glEnd();

}

fclose(fp);

glFlush();

glutSwapBuffers();



}







无效动画(无效)

{



yRotated + = 0.70;

xRotated + = 0.03;

display();

}





void reshape(int x,int y)

{

if(y == 0 || x == 0)返回;

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(3.0,(GLdouble)x /(GLdouble)y,0.8,50.0);

glMatrixMode(GL_MODELVIEW );

glViewport(0,0,x,y);



}





void mouse(int button,int state, int x,int y)

{

//右箭头 - 将旋转增加5度

if(state == GLUT_DOWN&& ; button == GLUT_RIGHT_BUTTON)

{

zoom - = 2.5;



}

else if(state == GLUT_DOWN&& button == GLUT_LEFT_BUTTON)

{

zoom + = 2.5;

}



glutPostRedisplay();



}





int main(int argc,char ** argv)

{

glutInit(& argc,argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

glutInitWindowSize(1500,1000);

glutCreateWindow(Awesome Cube);

glEnable(GL_DEPTH_TEST);

glutDisplayFunc(显示);

glutReshapeFunc(重塑);

glutIdleFunc(动画);

glutMouseFunc(鼠标);

glutMainLoop ();

返回0;



}

解决方案

回答这个问题将远远超出快速回答的意图。



您可以查看与CUDA3D游戏引擎编程的OpenGL互操作性 [ ^ ]:

Quote:

在本文中,我将讨论如何在CUDA内核中使用OpenGL纹理和缓冲区。


i have a csv file with points, and i need to take that values and ploat within a cube using opengl in cuda . i already plot the points in the cube. but i dont no how it implement in cuda. i need help.

What I have tried:

# include <cstdlib>
# include <ctime>
# include <cmath>
# include <fstream>
# include <iostream>
# include <iomanip>
# include <GL/glut.h>
# include <string>
# include <sstream>
# include <vector>
# include <string>
using namespace std;

void display();
double rotate_y=0;
double rotate_x=0;
GLfloat xRotated, yRotated, zRotated;
double zoom=0.5;



void display(){

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(zoom, zoom, 1.0f);
glTranslatef(0.0,0.0,-10.5);
glRotatef(xRotated,1.0,0.0,0.0);
glRotatef(yRotated,0.0,1.0,0.0);
glRotatef(zRotated,0.0,0.0,1.0);



glColor3f( 1, 1, 1 );
glBegin(GL_LINE_LOOP);
glVertex3f( 0.1, -0.01, -0.01 );
glVertex3f( 0.1, 0.1, -0.01 );
glVertex3f( -0.01, 0.1, -0.01 );
glVertex3f( -0.01, -0.01, -0.01 );
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.1, -0.01, 0.1 );
glVertex3f( 0.1, 0.1, 0.1 );
glVertex3f( -0.01, 0.1, 0.1 );
glVertex3f( -0.01, -0.01, 0.1 );
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( 0.1, -0.01, -0.01 );
glVertex3f( 0.1, 0.1, -0.01 );
glVertex3f( 0.1, 0.1, 0.1 );
glVertex3f( 0.1, -0.01, 0.1 );
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f( -0.01, -0.01, 0.1 );
glVertex3f( -0.01, 0.1, 0.1 );
glVertex3f( -0.01, 0.1, -0.01 );
glVertex3f( -0.01, -0.01, -0.01 );
glEnd();


float f1, f2, f3;

FILE *fp;
fp = fopen("golgi.csv", "r");

while (fscanf(fp, "%g,%g,%g\n", &f1, &f2, &f3) == 3)
{
glPointSize(7);
glColor3f( 0, 0, 1 );
glBegin(GL_POINTS);
glVertex3f( f1, f2, f3 );
glEnd();
}
fclose(fp);
glFlush();
glutSwapBuffers();

}



void animation(void)
{

yRotated += 0.70;
xRotated += 0.03;
display();
}


void reshape(int x, int y)
{
if (y == 0 || x == 0) return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(3.0,(GLdouble)x/(GLdouble)y,0.8,50.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y);

}


void mouse( int button, int state, int x, int y)
{
//Right arrow - increase rotation by 5 degree
if(state == GLUT_DOWN && button == GLUT_RIGHT_BUTTON)
{
zoom -= 2.5;

}
else if(state == GLUT_DOWN && button == GLUT_LEFT_BUTTON)
{
zoom += 2.5;
}

glutPostRedisplay();

}


int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1500 , 1000);
glutCreateWindow("Awesome Cube");
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(animation);
glutMouseFunc(mouse);
glutMainLoop();
return 0;

}

解决方案

Answering this would be far beyond the intention of "Quick Answer".

You may have a look at OpenGL Interoperability with CUDA3D Game Engine Programming[^]:

Quote:

In this article I will discuss how you can use OpenGL textures and buffers in a CUDA kernel.


这篇关于如何使用opengl绘制cuda中的点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆