[Insight-users] Problem for reading vtk images
Luis Ibanez
luis.ibanez at kitware.com
Wed Oct 31 09:52:40 EDT 2007
Hi Alex,
Thanks for the additional details.
Now it makes sense.
What is the content of the VTK file that you
are not being able to read with your current code:
>>> itk::ImageIOBase::Pointer imageIO =
>>> itk::ImageIOFactory::CreateImageIO ( entree,
>>> itk::ImageIOFactory::ReadMode );
You may find the answer to your problem in the CanReadFile() method
of the VTKImageIO class. Lines 124-147:
bool VTKImageIO::CanReadFile(const char* filename)
{
std::ifstream file;
char buffer[256];
std::string fname(filename);
if ( fname.find(".vtk") >= fname.length() )
{
return false;
}
if ( ! this->OpenVTKFileForReading(file, filename) )
{
return false;
}
// Check to see if its a vtk structured points file
file.getline(buffer,255);
file.getline(buffer,255);
file.getline(buffer,255);
file.getline(buffer,255);
fname = buffer;
if ( fname.find("STRUCTURED_POINTS") < fname.length() ||
fname.find("structured_points") < fname.length() )
{
return true;
}
else
{
return false;
}
}
This method is currently returning "false" in your case,
which means that your file is failing one (or several
of the tests above).
Regards,
Luis
-----------------------
Alexandre Abadie wrote:
> Hi Luis,
>
> Thanks for the reply.
> I already had a look using ImageFileReader for opening my datas but I am
> trying to extend my program for using 4D or 3D datas. I have to typedef
> ImageType with the dimension (3 or 4) before opening the data when using
> ImageFileReader (and I don't know the dimension before :-) ). With the
> ImageIO object, there's a method called "GetNumberOfDimensions()" that
> gives me the dimensions of the data I am trying to open. Then I develop
> a template method for processing my data (both 3D or 4D).
>
> My code compiles for the moment and works with 3D datas (except with vtk
> datas in itk3.4). I didn't have a look for the moment if my program
> works with 4D datas.
>
> What can you advice to me ?
>
> Thanks,
>
> Alex
>
> Luis Ibanez a écrit :
>
>>
>>
>> Hi Alex,
>>
>>
>> Why are you using the ImageIO classes directly ?
>>
>>
>> You *should not* need to access them at all.
>>
>>
>> You can read image by simply using the ImageFileReader:
>>
>>
>>
>> typedef itk::ImageFileReader< ImageType > ReaderType;
>>
>> ReaderType::Pointer reader = ReaderType::New();
>>
>> reader->SetFileName("myImage.vtk");
>>
>> try
>> {
>> reader->Update();
>> }
>> catch( itk::ExceptionObject & excp )
>> {
>> std::cerr << excp << std::endl;
>> return EXIT_FAILURE;
>> }
>>
>>
>>
>>
>> The ImageFileReader will deal with the ImageIOFactories for you.
>>
>>
>>
>> Please give us more details about what you are doing,
>>
>>
>> Thanks
>>
>>
>>
>> Luis
>>
>>
>>
>> ----------------------
>> Alexandre Abadie wrote:
>>
>>> Hi itk users,
>>>
>>> I am currently using the itkImageIOFactory class for reading the data
>>> formats supported by itk. This works very well with versions 3.0 and
>>> 3.2 but I recently made an update to 3.4 and now I can't read vtk
>>> data. I tested with NIFTI and Mha data and it always works.
>>> Here is how I am proceeding :
>>> itk::ImageIOBase::Pointer imageIO =
>>> itk::ImageIOFactory::CreateImageIO ( entree,
>>> itk::ImageIOFactory::ReadMode );
>>> This return a null pointer when I am trying to load a vtk data with
>>> itk 3.4.
>>>
>>> Any suggestion ?
>>>
>>> Thanks in advance.
>>>
>>> Alex
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>
More information about the Insight-users
mailing list