[vtkusers] How to display 3D RGB data with VTK?

Saifeng Liu liusaifeng at gmail.com
Mon May 18 04:09:17 EDT 2009


Hi,
I have developed a program to display 3D ultrasound raw data, and everything
goes well. Now I want to extend my work by displaying some 3D RGB raw data,
but I failed.

I have found somebody's suggestion on the mailing list, the suggestion is
that, first quantizing the color to a small set of colors ,and then build a
lookup table for it. I have tried this, but it does not work. Maybe I did it
in a wrong way.

now I have a 3D RGB raw data, and there are 3 components( the r,g,b value; 8
bit ) in each scalar, and I have successfully created a vtkImageData, and I
want to display a single slice of this image data. I choose to use
vtkReslice to display the sagittal, coronal and axial slices; and I choose
to use vtkImagePlaneWidget to display these slices together. They all work
perfectly with grey scale raw data.

So how to build up a lookup table for rgb data? or how to quantizing my data
to a small set of colors?
Besides, can we display the data directly without building a lookup table,
since the value itself is RGB value already?

Thank you very much for your help.

Saifeng,

How I create the vtkImageData, and read in some binary data.
//***********************************
vtkImageData* id = vtkImageData::New();
  id->SetDimensions(256,256,256);
  id->SetSpacing(1,1,1);
  id->SetScalarTypeToUnsignedChar();
  id->SetNumberOfScalarComponents(3);// the r,g,b value.
  id->SetOrigin(0.0,0.0,0.0);
  id->AllocateScalars();

//Then I fill in the image data with my raw data.
ifstream infile("/home/Rawdata/rgbcube.raw",ios::in|ios::binary);
int size=256*256*256*3;
unsigned char *buf=new unsigned char [size];
infile.read((char *)buf,size);
infile.close();

//fill in imagedata;
unsigned char *ptr = (unsigned char *) id->GetScalarPointer();
int i;
for(i=0;i<size;i++)
{
 *ptr=buf[i];
  ptr++;
}
cout<<"imagedata filled"<<endl;
//then set up a vtkreslice
-- 
Saifeng Liu
Department of Biomedical Engineering
Huazhong University of Science and Technology,
Wuhan, China
Tel:86-15827367525(mobile), 86-27-87442691
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090518/b0507f86/attachment.htm>


More information about the vtkusers mailing list