[Insight-users] Problem for reading vtk images
Luis Ibanez
luis.ibanez at kitware.com
Wed Oct 31 11:34:21 EDT 2007
Hi Alex,
CVS has all the answers :-)
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkVTKImageIO.cxx?rev=1.42&root=Insight&view=log
The "STRUCTURED POINTS" has been there for reading (Read method)
since cvs version 1.9 of this file, This is February 25 2002:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkVTKImageIO.cxx?r1=1.8&r2=1.9&root=Insight
The "STRUCTURED POINTS" has been there for writing (Write method)
since cvs version 1.5: December 21 2001:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkVTKImageIO.cxx?r1=1.4&r2=1.5&root=Insight
In the ITK 3.2 version, they are both there:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkVTKImageIO.cxx?annotate=1.39&root=Insight
In the ITK 3.4 version, they are still there:
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkVTKImageIO.cxx?annotate=1.42&root=Insight
Which probably lead to conclude that it is unlikely that
the .vtk file that you have, was created from ITK.
Your vtk file was probably generated from another source.
Regards,
Luis
----------------------
Alexandre Abadie wrote:
> I think the error comes from the vtk format I am trying to read. I
> produce it with an old program version (which was linked this itk3.2)
> and when I looked in the file (open with simple text editor vim), I
> couldn't find "STRUCTURED POINTS".
>
> With the new version, the file is completely different, but it works !
>
> Why are the 2 vtk formats different ?
>
> Thanks a lot.
>
>
> Luis Ibanez a écrit :
>
>>
>> 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
>>>>>
>>>
>> _______________________________________________
>> 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