<div dir="ltr">David, I am getting this error on your code:<div><div><br></div><div>error: ‘class vtkImageViewer2’ has no member named ‘SetInputData’</div><div> imageViewer->SetInputData(connector->GetOutput());</div>
</div><div><br></div><div><br></div><div style>Am I using and old or bad compiled version of vtk?</div><div style><br></div><div style>Regards,</div><div style>Manuel.</div><div><br></div></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Mon, May 20, 2013 at 11:06 AM, Manuel Corrales <span dir="ltr"><<a href="mailto:manuelcorrales@gmail.com" target="_blank">manuelcorrales@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Thanks David. Sorry about the example. I will attach a working example as soon as I can. About the sample code you sent, my problem is when the code is the other way around. I mean, reading the file and the connector in the function and then rendering the viewer in the main method. It maybe a Qt widget issue, but I am not sure.<div>
<br></div><div>Thanks for your response!</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, May 20, 2013 at 10:55 AM, David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Fri, May 17, 2013 at 3:43 PM, Manuel Corrales<br>
<<a href="mailto:manuelcorrales@gmail.com" target="_blank">manuelcorrales@gmail.com</a>> wrote:<br>
> Hello all. I have a simple code that reads an image using ITK, then it<br>
> convert it to VTK and after that I display the image in a QVTKWidget. The<br>
> code is this and works fine:<br>
><br>
> typedef itk::Image< double, 2 > ImageType;<br>
> typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;<br>
> typedef itk::ImageFileReader<ImageType> ReaderType;<br>
><br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> reader->SetFileName(file.c_str());<br>
> reader->Update();<br>
><br>
> ConnectorType::Pointer connector = ConnectorType::New();<br>
> connector->SetInput(reader->GetOutput());<br>
> connector->Update();<br>
> ImageReader *myReader = new ImageReader();<br>
> vtkSmartPointer<vtkImageViewer2> vtkImageViewer =<br>
> vtkSmartPointer<vtkImageViewer2>::New();<br>
> vtkImageViewer->SetInput(connector->GetOutput());<br>
> vtkImageViewer->SetRenderWindow(this->qvtkWidget->GetRenderWindow());<br>
> vtkImageViewer->Render();<br>
><br>
><br>
> Now if I change this code and create a separate function to perform the<br>
> connection from ITK to VTK, I get a segfault:<br>
><br>
> ImageReader *myReader = new ImageReader();<br>
> vtkSmartPointer<vtkImageViewer2> vtkImageViewer =<br>
> myReader->renderITKReaderInVTK(file);<br>
> vtkImageViewer->SetRenderWindow(this->qvtkWidget->GetRenderWindow());<br>
> vtkImageViewer->Render();<br>
><br>
> and the called function:<br>
><br>
> vtkSmartPointer<vtkImageViewer2><br>
> ImageReader::renderITKReaderInVTK(std::string fileName) {<br>
> typedef itk::Image< double, 2 > ImageType;<br>
> typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;<br>
> typedef itk::ImageFileReader<ImageType> ReaderType;<br>
><br>
> ReaderType::Pointer reader = ReaderType::New();<br>
> qDebug() << "Setting reader file name";<br>
> reader->SetFileName(fileName.c_str());<br>
> qDebug() << "Updating reader";<br>
> reader->Update();<br>
><br>
> ConnectorType::Pointer connector = ConnectorType::New();<br>
> qDebug() << "Setting input to connector";<br>
> connector->SetInput(reader->GetOutput());<br>
> qDebug() << "Updating connector";<br>
> connector->Update();<br>
><br>
> vtkSmartPointer<vtkImageViewer2> vtkImageViewer =<br>
> vtkSmartPointer<vtkImageViewer2>::New();<br>
> qDebug() << "Setting connector outupt -> imageViewer input";<br>
> vtkImageViewer->SetInput(connector->GetOutput());<br>
> qDebug() << "Image viewer set up ready";<br>
> return vtkImageViewer;<br>
> }<br>
><br>
> Any ideas why the same code (I think) works if it is all together but fail<br>
> when it's in a different function?<br>
><br>
> Thanks in advance!<br>
> Regards,<br>
> Manuel.<br>
<br>
<br>
</div></div>It is much easier for us if you provide a compilable example of the<br>
error. I tried the following, but it seems to work fine. If you can<br>
provide something like this that segfaults, I'm sure someone can help<br>
you out.<br>
<br>
#include <vtkVersion.h><br>
#include <vtkSmartPointer.h><br>
#include <vtkRenderWindow.h><br>
#include <vtkRenderWindowInteractor.h><br>
#include <vtkRenderer.h><br>
#include <vtkImageViewer2.h><br>
<br>
#include "itkImage.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageToVTKImageFilter.h"<br>
<br>
vtkSmartPointer<vtkImageViewer2> CreateImageViewer();<br>
<br>
int main(int, char *[])<br>
{<br>
<div><br>
typedef itk::Image< double, 2 > ImageType;<br>
typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;<br>
typedef itk::ImageFileReader<ImageType> ReaderType;<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
</div> reader->SetFileName("test.png");<br>
<div> reader->Update();<br>
<br>
ConnectorType::Pointer connector = ConnectorType::New();<br>
connector->SetInput(reader->GetOutput());<br>
connector->Update();<br>
<br>
</div> vtkSmartPointer<vtkImageViewer2> imageViewer = CreateImageViewer();<br>
imageViewer->SetInputData(connector->GetOutput());<br>
imageViewer->Render();<br>
<br>
return EXIT_SUCCESS;<br>
}<br>
<br>
vtkSmartPointer<vtkImageViewer2> CreateImageViewer()<br>
{<br>
vtkSmartPointer<vtkImageViewer2> imageViewer =<br>
vtkSmartPointer<vtkImageViewer2>::New();<br>
return imageViewer;<br>
}<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>