[vtkusers] Adding image writer to the pipeline gets itk reader fails

Marcos fotosentido at gmail.com
Fri Aug 15 07:28:03 EDT 2014


The problem is in the file. I don't know why it works with that file
without that line. Really weird.

I just don't get it.

I will try with other files.



2014-08-15 13:03 GMT+02:00 Marcos <fotosentido at gmail.com>:

> Well, now I don't understand at all.
>
> The problem with itk ImageFileReader doesn't occur when I add the writer
> to the pipeline... it's when I create the vtkJPEGWriter!!!!
>
> The line:
> vtkJPEGWriter* writer = vtkJPEGWriter::New();
>
> is the problem.
>
> Why?? It has nothing to do with the reading of the file!! It doesn't
> execute, it's in another function I don't use at that moment!
>
> I comment that line -and all the next with that object- I can read the
> file.
>
> I just add that line: itkImageFileReader fails!!!
>
> I'm just wasting a lot of time with this.
>
>
>
> 2014-08-13 12:56 GMT+02:00 Marcos <fotosentido at gmail.com>:
>
> Hi,
>>
>> I wonder if somebody could help me, I'm stuck with this. Sorry if this
>> was asked before, I didn't find anything similar.
>>
>> I got a simple pipeline working, starting with a itk::ImageFileReader who
>> connects to a vtkImageImport, passing through a vtkImageViewer and ending
>> in a QVTKWidget.
>>
>> Great. I see an image in my QVTKWidget.
>>
>> Now, writing to a file. Let's say a JPEG file.
>>
>> I tried with a vtkWindowToImageFilter and a vtkJPEGWriter.
>>
>> And that's where the weird things take place: the itk::ImageFileReader
>> fails trying to read the file; a segmentation fault in the Update() method.
>>
>> Why? It's the same file, and the new code is added after.
>>
>> I guess it is related to the pipeline, but I don't get how the end of
>> pipeline affects the beginning. Well, I know the Update method from the
>> first object could update the whole pipeline.
>>
>> So I tried isolating the last part in a method, which is called from a
>> menu option: in my application, I "open" the file. I see a image in my
>> viewer. Then, later, I choose to export the image I see to a file. It's not
>> until that moment that I create the vtkWindowToImageFilter and
>> vtkJPEGWriter objects.
>>
>> But itk::ImageFileReader fails again. If I comment the last lines, it
>> works again.
>>
>> Here is the code, simplified (reader is a global variable: when I call
>> connectVTKWidget, it has called successfully (before I added the writing
>> part) the Update method and I can see a image in the widget):
>>
>> void DCMBase::connectVTKWidget(QVTKWidget* widget)
>> {
>>     typedef itk::Image< signed short, 2 > TipoImagen;
>>     typedef itk::ImageFileReader< TipoImagen > Tiporeader;
>>     Tiporeader::Pointer reader;
>>
>>     typedef itk::VTKImageExport< TipoImagen > TipoImagenExport;
>>     TipoImagenExport::Pointer exporter = TipoImagenExport::New();
>>     exporter->SetInput(reader->GetOutput());
>>
>>     vtkImageImport *imageImport = vtkImageImport::New();
>>     this->ConnectPipelines(exporter, imageImport);
>>
>>     vtkImageViewer* imageViewer = vtkImageViewer::New();
>>     imageViewer->SetInputConnection(imageImport->GetOutputPort());
>>     widget->SetRenderWindow(imageViewer->GetRenderWindow());
>>
>>     // with this, itk::ImageFileReader fails!
>>     vtkWindowToImageFilter* filtroAImagen = vtkWindowToImageFilter::New();
>>     filtroAImagen->SetInput(widget->GetRenderWindow());
>>     vtkJPEGWriter* writer = vtkJPEGWriter::New();
>>     writer->SetFileName("myfile.jpg");
>>     //    writer->SetInputConnection(alg->GetOutputPort());
>>
>>     try
>>     {
>>         writer->Update();
>>     }
>>     catch (itk::ExceptionObject& e)
>>     {
>>         std::cerr << "Excepción en escritura:" <<std::endl;
>>         std::cerr << e << std::endl;
>>     }
>>
>>     imageViewer->Render();
>> }
>>
>>
>>
>> Am I missing something? Thanks in advance.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140815/a2d02d11/attachment.html>


More information about the vtkusers mailing list