[vtkusers] Adding image writer to the pipeline gets itk reader fails
Marcos
fotosentido at gmail.com
Wed Aug 13 06:56:10 EDT 2014
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/20140813/e2825341/attachment.html>
More information about the vtkusers
mailing list