Reputation: 17
I am working on rendering some volume data via cuda v6.5 sample code - volumeRender. I have some voxel data with different RGB color in another program. I want to render them by outputing them to .raw file format. However, how to output the exact same .raw format as input .raw file in volumeRender is confusing me a lot.
In my knowledgement, a .raw file can contain an array of volume data. I tried to open .raw file, named "Bucky.raw" , in volumrRender, with text editor, but it didn't work. The text was garbled text. So I have no clue of the format of the .raw file.
Next, I tried to read sample code and figure out how the .cpp file read this format. The only information I get was the volume size. It is
unsigned char * width * height * depth
.
Dose that mean each voxel data is represented by only one unsigned char? What does this unsigned char mean? Is it the gray scale of voxel?
I tried to output gray scale of my voxel RGB data, but the result is quite wired like below.
At the top is my voxel data and visualize by PCL. The other is the render result. Obviously, it's the wrong format for the volumeRender program.
I know there are lots of different formats of .raw files, but I think maybe there is only one kind of .raw format just for cuda sample code. Does anyone know how to store .raw format just like "Bucky.raw" format?
Upvotes: 0
Views: 696
Reputation: 45
I created a simple example program in Swift using Xcode that will convert a Goxel model into the .raw format used by the NVIDIA CUDA example programs VolumeRender and VolumeFilter.
Build a model in Goxel, export it as .txt
Then run it through the Goxel2Raw program.
Upvotes: 0
Reputation: 151993
Does that mean each voxel data is represented by only one unsigned char? What does this unsigned char mean? Is it the gray scale of voxel?
Yes, each voxel is represented by one unsigned char
(i.e. VolumeType
), the value (0-255) represents the "transmissivity" of the voxel (i.e. the inverse of the density), with a voxel value of 0 being the lowest transmissivity/highest "density" (creating "darker" areas) and voxel value of 255 being low density (creating "brighter" areas).
The storage order has a rapidly varying dimension in x, then y, then z. The actual dimensions of the volume can be easily discovered in the program as volumeSize.width
(x), volumeSize.height
(y), and volumeSize.depth
(z). x represents the horizontal direction, y the vertical, and z represents the direction into or out of the screen.
Does anyone know how to store .raw format just like "Bucky.raw" format?
Here is a program you can use to experiment with writing different kinds of "Bucky.raw" files. The dimensions will be 32,32,32 which is the default values in the program.
If you compile this program, then run it with a command line parameter of 0-4, you can see different patterns when you run the volumeRender
sample code.
cat buckywriter.cpp
#include <fstream>
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
const int sz = 32;
const int method_max = 4;
int myfunc(int x, int y, int z, int method){
switch (method){
case 0:
return x;
break;
case 1:
return y;
break;
case 2:
return z;
break;
case 3:
return x+y;
break;
case 4:
return (x+y)*2*((z+1)/float(sz));
break;
default:
return x;
break;
}
return 0;
}
int main(int argc, char *argv[]){
int method = 0;
if (argc > 1) method = atoi(argv[1]);
ofstream fout;
string foname("Bucky.raw");
fout.open(foname.c_str());
if (!fout) {std::cout << "file open failed" << std::endl; return 1;}
for (int z = 0; z < sz; z++)
for (int y = 0; y < sz; y++)
for (int x = 0; x < sz; x++)
fout << (unsigned char)(myfunc(x, y, z, method));
if (!fout) {std::cout << "file write failed" << std::endl; return 1;}
fout.close();
return 0;
}
$ g++ buckywriter.cpp -o buckywriter
$ ./buckywriter 3
$ ./volumeRender
This is the graphical output for the above buckywriter 3
case, which creates an increasing transmissivity gradient in x and y:
Upvotes: 2