<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:12pt"><div><span></span></div><div>&nbsp;hi all</div><div><br></div><div><div style="font-size: 12pt; font-family: sans-serif; ">I'm trying to send itkimage pointer to a function then convert it to vtkimagedata but after that i&nbsp;</div><div style="font-size: 12pt; font-family: sans-serif; ">have run time exception during display them . but if i use the same code of conversion in the function i use to open this image all things are going good . actually i want to ask what's the different between this code&nbsp;</div><div style="font-size: 12pt; font-family: sans-serif; "><br></div><div><div>void ImageWidget::openWithITK()</div><div>{</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());</div><div>&nbsp;
 &nbsp;&nbsp;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>if (!fileName.isEmpty()) {</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>// read the image</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>typedef itk::ImageFileReader &lt;ImageType&gt; ReaderType;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>ReaderType::Pointer reader = ReaderType::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>reader-&gt;SetFileName(fileName.toAscii().data());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        
        </span>reader-&gt;Update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>this-&gt;displayImage(ConvertITKImageToVtkImage(reader-&gt;GetOutput()));</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>}</div><div>}</div><div>void ImageWidget::displayImage(vtkImageData *image)</div><div>{</div><div>&nbsp; &nbsp; int *dim= image-&gt;GetDimensions(); &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; double *spacing = image-&gt;GetSpacing();&nbsp;</div><div>&nbsp; &nbsp; double *origin = image-&gt;GetOrigin(); &nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; float Cx = (dim[0] * spacing[0])/2. + origin[0];</div><div>&nbsp; &nbsp; float Cy = (dim[1] * spacing[1])/2. + origin[1];</div><div>&nbsp; &nbsp; camera-&gt;ParallelProjectionOn();</div><div>&nbsp; &nbsp; camera-&gt;SetFocalPoint(Cx,Cy,0); &nbsp; &nbsp;</div><div>&nbsp; &nbsp;
 camera-&gt;SetPosition(Cx,Cy,1);</div><div>&nbsp; &nbsp; //</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;// to flip de image</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;camera-&gt;SetViewUp (0, 1, 0); &nbsp;</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;</div><div>&nbsp; &nbsp; // set actor properties</div><div>&nbsp; &nbsp; actor-&gt;SetInput(image);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>actor-&gt;InterpolateOff(); &nbsp; &nbsp;</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>renderer-&gt;AddActor(actor);</div><div>&nbsp; &nbsp; renderer-&gt;SetActiveCamera(camera);</div><div>&nbsp; &nbsp; renderer-&gt;ResetCamera();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;SetRenderWindow(renderWindow);</div><div><br></div><div>&nbsp; &nbsp; // window interactor style for display images&nbsp;</div><div><span
 class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer&lt;vtkInteractorStyleImage&gt; style =<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer&lt;vtkInteractorStyleImage&gt;::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>// set interactor style to the qvtkWidget Interactor</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;GetInteractor()-&gt;SetInteractorStyle(style);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>this-&gt;update();</div><div>}</div><div><br></div><div>vtkImageData* ImageWidget::ConvertITKImageToVtkImage(ImageType * image)</div><div>{</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">
        </span>vtkSmartPointer &lt;vtkImageData&gt; vtkImageFromItkImage;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkConnectorType::Pointer connector = vtkConnectorType::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>connector-&gt;GetExporter()-&gt;SetInput(image);&nbsp;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>connector-&gt;GetImporter()-&gt;Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>// flip image in Y axis<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                                </span></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer&lt;vtkImageFlip&gt; flipYFilter = vtkSmartPointer&lt;vtkImageFlip&gt;::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">
        </span>flipYFilter-&gt;SetFilteredAxis(1); // flip Y axis</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>flipYFilter-&gt;SetInput(connector-&gt;GetImporter()-&gt;GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>flipYFilter-&gt;Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>// create vtk image</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkImageFromItkImage = vtkSmartPointer&lt;vtkImageData&gt;::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkImageFromItkImage-&gt;DeepCopy(flipYFilter-&gt;GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkImageFromItkImage-&gt;SetScalarTypeToUnsignedChar();</div><div><span class="yiv121940224Apple-tab-span" style="white-space:
 pre; ">        </span>vtkImageFromItkImage-&gt;Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>//reader = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>flipYFilter = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>connector = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>return vtkImageFromItkImage;<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span></div><div>}</div><div><br></div><div>and that code&nbsp;</div><div><br></div><div><div>void ImageWidget::openWithITK()</div><div>{</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());</div><div>&nbsp; &nbsp;&nbsp;</div><div><span class="yiv121940224Apple-tab-span"
 style="white-space: pre; ">        </span>if (!fileName.isEmpty()) {</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>// read the image</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>typedef itk::ImageFileReader &lt;ImageType&gt; ReaderType;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>ReaderType::Pointer reader = ReaderType::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        
        </span>reader-&gt;SetFileName(fileName.toAscii().data());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>reader-&gt;Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkSmartPointer &lt;vtkImageData&gt; vtkImageFromItkImage;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkConnectorType::Pointer connector = vtkConnectorType::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>connector-&gt;GetExporter()-&gt;SetInput( reader-&gt;GetOutput()&nbsp;);&nbsp;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>connector-&gt;GetImporter()-&gt;Update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>// flip image in Y
 axis<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                                </span></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkSmartPointer&lt;vtkImageFlip&gt; flipYFilter = vtkSmartPointer&lt;vtkImageFlip&gt;::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter-&gt;SetFilteredAxis(1); // flip Y axis</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter-&gt;SetInput(connector-&gt;GetImporter()-&gt;GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter-&gt;Update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>// create vtk image</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        
        </span>vtkImageFromItkImage = vtkSmartPointer&lt;vtkImageData&gt;::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage-&gt;DeepCopy(flipYFilter-&gt;GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage-&gt;SetScalarTypeToUnsignedChar();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage-&gt;Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>//reader = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>connector = NULL;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>}</div><div>}</div><div>void
 ImageWidget::displayImage(vtkImageData *image)</div><div>{</div><div>&nbsp; &nbsp; int *dim= image-&gt;GetDimensions(); &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; double *spacing = image-&gt;GetSpacing();&nbsp;</div><div>&nbsp; &nbsp; double *origin = image-&gt;GetOrigin(); &nbsp;</div><div>&nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; float Cx = (dim[0] * spacing[0])/2. + origin[0];</div><div>&nbsp; &nbsp; float Cy = (dim[1] * spacing[1])/2. + origin[1];</div><div>&nbsp; &nbsp; camera-&gt;ParallelProjectionOn();</div><div>&nbsp; &nbsp; camera-&gt;SetFocalPoint(Cx,Cy,0); &nbsp; &nbsp;</div><div>&nbsp; &nbsp; camera-&gt;SetPosition(Cx,Cy,1);</div><div>&nbsp; &nbsp; //</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;// to flip de image</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;camera-&gt;SetViewUp (0, 1, 0); &nbsp;</div><div>&nbsp; &nbsp; // &nbsp; &nbsp;</div><div>&nbsp; &nbsp; // set actor properties</div><div>&nbsp; &nbsp;
 actor-&gt;SetInput(image);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>actor-&gt;InterpolateOff(); &nbsp; &nbsp;</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>renderer-&gt;AddActor(actor);</div><div>&nbsp; &nbsp; renderer-&gt;SetActiveCamera(camera);</div><div>&nbsp; &nbsp; renderer-&gt;ResetCamera();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;SetRenderWindow(renderWindow);</div><div><br></div><div>&nbsp; &nbsp; // window interactor style for display images&nbsp;</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer&lt;vtkInteractorStyleImage&gt; style =<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer&lt;vtkInteractorStyleImage&gt;::New();</div><div><span class="yiv121940224Apple-tab-span"
 style="white-space: pre; ">        </span>// set interactor style to the qvtkWidget Interactor</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;GetInteractor()-&gt;SetInteractorStyle(style);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget-&gt;update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>this-&gt;update();</div><div>}</div><br class="yiv121940224Apple-interchange-newline"></div><div>the second works good but the first give me run time error at display function.</div><div><br></div><div><div style="font-size: 12pt; font-family: sans-serif; ">keep Blessed</div><div style="font-size: 12pt; font-family: sans-serif; "><br></div><div style="font-size: 12pt; font-family: sans-serif; ">Regards</div><div style="font-size: 12pt; font-family: sans-serif; "><br></div><div style="font-size: 12pt; font-family: sans-serif;
 ">Alaa</div></div></div></div><div><br></div></div></body></html>