<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:12pt"><div><span></span></div><div> 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 </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 </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>
</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 <ImageType> 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->SetFileName(fileName.toAscii().data());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        
        </span>reader->Update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>this->displayImage(ConvertITKImageToVtkImage(reader->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> int *dim= image->GetDimensions(); </div><div> double *spacing = image->GetSpacing(); </div><div> double *origin = image->GetOrigin(); </div><div> </div><div> float Cx = (dim[0] * spacing[0])/2. + origin[0];</div><div> float Cy = (dim[1] * spacing[1])/2. + origin[1];</div><div> camera->ParallelProjectionOn();</div><div> camera->SetFocalPoint(Cx,Cy,0); </div><div>
camera->SetPosition(Cx,Cy,1);</div><div> //</div><div> // // to flip de image</div><div> // camera->SetViewUp (0, 1, 0); </div><div> // </div><div> // set actor properties</div><div> actor->SetInput(image);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>actor->InterpolateOff(); </div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>renderer->AddActor(actor);</div><div> renderer->SetActiveCamera(camera);</div><div> renderer->ResetCamera();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget->SetRenderWindow(renderWindow);</div><div><br></div><div> // window interactor style for display images </div><div><span
class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer<vtkInteractorStyleImage> style =<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer<vtkInteractorStyleImage>::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->GetInteractor()->SetInteractorStyle(style);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget->update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>this->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 <vtkImageData> 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->GetExporter()->SetInput(image); </div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>connector->GetImporter()->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<vtkImageFlip> flipYFilter = vtkSmartPointer<vtkImageFlip>::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">
        </span>flipYFilter->SetFilteredAxis(1); // flip Y axis</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>flipYFilter->SetInput(connector->GetImporter()->GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>flipYFilter->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<vtkImageData>::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkImageFromItkImage->DeepCopy(flipYFilter->GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkImageFromItkImage->SetScalarTypeToUnsignedChar();</div><div><span class="yiv121940224Apple-tab-span" style="white-space:
pre; ">        </span>vtkImageFromItkImage->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 </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> </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 <ImageType> 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->SetFileName(fileName.toAscii().data());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>reader->Update();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkSmartPointer <vtkImageData> 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->GetExporter()->SetInput( reader->GetOutput() ); </div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>connector->GetImporter()->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<vtkImageFlip> flipYFilter = vtkSmartPointer<vtkImageFlip>::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter->SetFilteredAxis(1); // flip Y axis</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter->SetInput(connector->GetImporter()->GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>flipYFilter->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<vtkImageData>::New();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage->DeepCopy(flipYFilter->GetOutput());</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage->SetScalarTypeToUnsignedChar();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">                </span>vtkImageFromItkImage->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> int *dim= image->GetDimensions(); </div><div> double *spacing = image->GetSpacing(); </div><div> double *origin = image->GetOrigin(); </div><div> </div><div> float Cx = (dim[0] * spacing[0])/2. + origin[0];</div><div> float Cy = (dim[1] * spacing[1])/2. + origin[1];</div><div> camera->ParallelProjectionOn();</div><div> camera->SetFocalPoint(Cx,Cy,0); </div><div> camera->SetPosition(Cx,Cy,1);</div><div> //</div><div> // // to flip de image</div><div> // camera->SetViewUp (0, 1, 0); </div><div> // </div><div> // set actor properties</div><div>
actor->SetInput(image);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>actor->InterpolateOff(); </div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>renderer->AddActor(actor);</div><div> renderer->SetActiveCamera(camera);</div><div> renderer->ResetCamera();</div><div><br></div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget->SetRenderWindow(renderWindow);</div><div><br></div><div> // window interactor style for display images </div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer<vtkInteractorStyleImage> style =<span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>vtkSmartPointer<vtkInteractorStyleImage>::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->GetInteractor()->SetInteractorStyle(style);</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>qvtkWidget->update();</div><div><span class="yiv121940224Apple-tab-span" style="white-space: pre; ">        </span>this->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>