How can I run a C code on GPU using openGL?
I have this code in C and want it to run on GPU using openGL. I am just beginning to learn openGL.
My main concern is how to shift the code from running on CPU to GPU. Any help is appreciated.
void projectvolumeontoimagea (Volume* vol, CB_Image* cbi, float scale)
{
int i, j, k, p;
float* img = (float*) vol->img;
double wip[3];
double *xip, *yip, *zip;
double acc1[3],acc2[3],acc3[3];
/* Rescale image (destructive rescaling) /
for (i = 0; i < cbi->dim[0]cbi->dim[1]; i++) {
cbi->img *= scale;
}
xip = (double) malloc (3vol->dim[0]sizeof(double));
yip = (double) malloc (3vol->dim[1]sizeof(double));
zip = (double) malloc (3vol->dim[2]*sizeof(double));
/* Precompute stuff here /
for (i = 0; i < vol->dim[0]; i++) {
double a = (double) (vol->offset[0] + i * vol->pix_spacing[0]);
xip[i3+0] = a * cbi->matrix[0];
xip[i3+1] = a * cbi->matrix[4];
xip[i3+2] = a * cbi->matrix[8];
}
for (j = 0; j < vol->dim[1]; j++) {
double a = (double) (vol->offset[1] + j * vol->pixspacing[1]);
yip[j*3+0] = a * cbi->matrix[1];
yip[j*3+1] = a * cbi->matrix[5];
yip[j*3+2] = a * cbi->matrix[9];
}
for (k = 0; k < vol->dim[2]; k++) {
double a = (double) (vol->offset[2 ] + k * vol->pixspacing[2]);
zip[k3+0] = a * cbi->matrix[2];
zip[k3+1] = a * cbi->matrix[6];
zip[k3+2] = a * cbi->matrix[10];
}
wip[0] = cbi->matrix[3];
wip[1] = cbi->matrix[7];
wip[2] = cbi->matrix[11];
/ Main loop /
p = 0;
for (k = 0; k < vol->dim[2]; k++) {
rawvec3_add3 (acc1, wip, &zip[3k]);
for (j = 0; j < vol->dim[1]; j++) {
rawvec3add3 (acc2, acc1, &yip[3*j]);
for (i = 0; i < vol->dim[0]; i++) {
rawvec3add3 (acc3, acc2, &xip[3*i]);
acc3[0] = cbi->ic[0] + acc3[0] / acc3[2];
acc3[1] = cbi->ic[1] + acc3[1] / acc3[2];
img[p++] += getpixelvalue (cbi, acc3[0], acc3[1]);
}
}
}
}
void
rawvec3_add3 (double* v1, const double* v2, const double* v3)
{
int i;
for (i = 0; i < 3; i++) {
v1 = v2 + v3;
}
}
float getpixelvalue (CB_Image* cbi, double r, double c)
{
int rr, cc;
rr = roundint (r);
if (rr < 0 || rr >= cbi->dim[0]) return 0.0;
cc = roundint (c);
if (cc < 0 || cc >= cbi->dim[1]) return 0.0;
return cbi->img[rr*cbi-> dim[0] + cc];
}
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).