[vtkusers] Problem with Image Data Convert
icanfly
freesailing at 163.com
Wed Nov 20 23:06:20 EST 2002
Hi,all VTKUsers
I'm a newcomer of VTK.Now,I have a problem of changing my data to vtkImage Data.
I have read slices from CT DICOM files and reconstructed the data into volume data, the data is stored in a three-dimension array(*pVoxels). I want to render by using vtkContourFilter to generate polygon data. So I have to convert my data into vtkImageData.I'v written some code ,but I don't know wheather it is right. I want to know where should I put my data in the vtkImageData and how can I make my data communicate with vtk data seamlessly,or is there other way to directly manipulate my data in VTK?
Thanks a lot
Xu
List,SEU
-------------------
P.S.
Here are part of my code:
CMyApp* pWinApp=(CMyApp*)AfxGetApp();
vtkImageData *m_pImageData=vtkImageData::new();
CVolume* m_pBone; //CVolume is my defined volume class
m_pBone=pWinApp->mpBone;// Get the bone volume data from the mpBone in CMyApp
int Wid=m_pBone->mWidth;
int Hei=m_pBone->mHeight;
int Thi=m_pBone->mThickness;
int VoxelSize=m_pBone->mVoxelSize;
m_pImageData->SetDimensions(Wid,Hei,Thi);
m_pImageData->SetSpacing(1,1,1);
m_pImageData->SetOrigin(0,0,0);
m_pImageData->SetScalarTypeToUnsignedShort ();
m_pImageData->SetNumberOfScalarComponents(1);
m_pImageData->AllocateScalars();
unsigned short *ptr=(unsigned short*) m_pImageData->GetScalarPointer();
unsigned short *pVoxels=(unsigned short*)m_pBone->mpVoxels;
//the three-dimention array of voxels is referenced by the pointer *mpVoxels.
for(int i=0;i<Wid*Hei*Thi;i++)
{
*ptr++=*pVoxels++;
}
m_pImageData->SetSpacing(1,1,1);
m_pImageData->SetOrigin(0,0,0);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20021121/43a5bd0f/attachment.htm>
More information about the vtkusers
mailing list