[vtkusers] Re: reading row 3D voxel data
kurt
kurtzhao at yeah.net
Mon Jan 10 13:07:11 EST 2005
Hi Jens,
As far as I know, there is not a conveniet way to do so, correct me if I am wrong.
However, 'coz ITK support many formats 3D images, I use ITK to read the images at first, then convert them to vtkImageData. The code is enclosed.
Please note, what u need to do is adding headers for the *.img (the raw data). the headers supported by ITK are *.mha and *.hdr.
The former u can find details from ITK's documents. but it is fairly simple, something like that:
NDims = 3
DimSize = 256 256 63
ElementType = MET_UCHAR
ElementSpacing = 1.0 1.0 1.0
ElementByteOrderMSB = False
ElementDataFile = 1.img
u can make the *.hdr using MRIcro, u may download it from www.mricro.com.
The former is simpler, but I recommand the later header, it is more convenient to use.
Good luck!
Kurt Zhao
bool MyImage::ImgReader(vtkImageData * vtkImage, const char * ImgFileName)
{
typedef unsigned short SegPixelType;
typedef itk::Image< SegPixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ImageReaderType;
ImageReaderType::Pointer ImageReader = ImageReaderType::New();
ImageReader->SetFileName( ImgFileName );
std::cout<< "Reading the image "<< ImageReader->GetFileName()<<"......"<<std::endl;
try
{
ImageReader->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception Caught !" << std::endl;
std::cerr << excep << std::endl;
}
ImageReader->GetOutput()->ReleaseDataFlagOn();
ImageType *itkImg=ImageReader->GetOutput();
typedef itk::VTKImageExport<ImageType> ImageExportType;
ImageExportType::Pointer itkExporter = ImageExportType::New();
itkExporter->SetInput(itkImg);
vtkImageImport* vtkImporter = vtkImageImport::New();
ConnectPipelines(itkExporter, vtkImporter);
vtkImporter->Update();
vtkImageData *tImage=vtkImporter->GetOutput();
vtkImage->DeepCopy(tImage);
vtkImage->SetSpacing(1,1,1);
// vtkImage->Print(std::cout);
vtkImporter->Delete();
return false;
}
template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
// importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
// importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
importer->SetSpacingCallback(exporter->GetSpacingCallback());
importer->SetOriginCallback(exporter->GetOriginCallback());
importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
importer->SetCallbackUserData(exporter->GetCallbackUserData());
}
Send vtkusers mailing list submissions to
vtkusers at vtk.org
To subscribe or unsubscribe via the World Wide Web, visit
http://www.vtk.org/mailman/listinfo/vtkusers
or, via email, send a message with subject or body 'help' to
vtkusers-request at vtk.org
You can reach the person managing the list at
vtkusers-owner at vtk.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of vtkusers digest..."
Today's Topics:
1. reading row 3D voxel data (Jens Frederich)
2. reading row 3D voxel data (Jens Frederich)
3. reading row 3D voxel data (Jens Frederich)
----------------------------------------------------------------------
Message: 1
Date: Wed, 7 Jan 2004 20:27:09 +0100
From: Jens Frederich < jfrederich at mac.com>
Subject: [vtkusers] reading row 3D voxel data
To: vtk < vtkusers at vtk.org>
Message-ID: < 7C576394-4147-11D8-A56E-000A95A0B65C at mac.com>
Content-Type: text/plain; charset=US-ASCII; format=flowed
Hi all,
what is the best class (way) for reading 3D binary row voxel data. The
data is saved in one file, not many 2D images. I would do volume
rendering, isosurface, contour etc with this data.
With the volume rendering library vgl
(http://www.volumegraphics.com/products/vgl/index.html) is this very
simple. Here a code sample:
VGLSampleGridData* volumeData = new VGLSampleGridData (VGL_TYPE_UINT16);
// load voxel data:
VGLSampleGridIO* importPlugIn = VGLSampleGridIO::create ("raw");
importPlugIn-> setHeaderSkip (40);
imortPlugIn-> setSampleGridSize (VGLSampleGridSize (42,42,42));
importPlugIn-> setSampleGridSize (VGLSampleGridSize (250,250,1));
importPlugIn-> setSampleDataType (VGL_TYPE_UINT16);
importPlugIn-> open ("../data/simdata4.vol");
importPlugIn-> read (volumeData);
importPlugIn-> close ();
delete importPlugIn;
It's very easy. But I search the same on vtk please.
Thanks for help.
Best regards,
Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050110/b53c4e1d/attachment.htm>
More information about the vtkusers
mailing list