[Insight-users] Problem with itk-vtk in MFC

Luis Ibanez luis.ibanez at kitware.com
Sun Nov 27 07:42:48 EST 2005


Hi Wang,


Please read the ImageIO section of
the ITK Software Guide:

  http://www.itk.org/ItkSoftwareGuide.pdf


In particular, you shoul add a try/catch
block and an Update() to your reader.

If any exception is thrown, you should
print out the message returned by the
exception. This message will give you
hints on the source of the error.


The code should look like



imageReader2D_1->SetFileName( strFile );

   try
    {
    imageReader2D_1->Update
    }
   catch( itk::ExceptionObject & excp )
    {
    std::cerr << excp << std::endl;
    }



Please see the ItkSoftwareGuide.pdf for details.



  Regards,



     Luis


-----------------
Wang Minyou wrote:
> Hi everyone,
> 
> I'm a freshman using itk. I have some problem with itk-vtk in MFC. I 
> wrote a Win32 Project in VC6. I want to use itk to readin a pic and view 
> it with vtk. Here is a portion of codes.
> 
> *********************************
> CString strFile="";
> 
> char szFilter[]="bmp文件(*.bmp)|*.bmp|All files(*.*)|*.*||";
> CFileDialog 
> dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter,this);
> dlg.m_ofn.lpstrInitialDir=".";
> 
> if(dlg.DoModal()==IDOK)
> {
>     strFile=dlg.GetPathName();
> }
> 
> imageReader2D_1->SetFileName( strFile );
> 
> typedef itk::ImageToVTKImageFilter<ImageType2D> ConnectorType2D;
> ConnectorType2D::Pointer connector=ConnectorType2D::New();
> vtkImageViewer* viewer=vtkImageViewer::New();
> vtkRenderWindowInteractor* 
> ImgRenderWindowInteractor=vtkRenderWindowInteractor::New();
> 
> connector->SetInput(imageReader2D_1->GetOutput());
> 
> HWND hwnd = this->GetSafeHwnd();
> 
> viewer->SetParentId(hwnd);
> viewer->SetPosition(0,0);
> viewer->SetSize(512,512);
> viewer->SetupInteractor(ImgRenderWindowInteractor);
>     
> viewer->SetInput(connector->GetOutput());
> viewer->Render();
> 
> viewer->SetColorWindow(255);
> viewer->SetColorLevel(128);
> ImgRenderWindowInteractor->Start();
> **************************
> 
> There is no problem when compiling and linking, but when running it 
> results in a "Runtime Error". Using Debug, I found it occurs when 
> running "viewer->Render();". Does anyone can give some informations 
> about where the wrong lie. Thank you in advance!
> 
> _________________________________________________________________
> 与联机的朋友进行交流,请使用 MSN Messenger:  http://messenger.msn.com/cn 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 



More information about the Insight-users mailing list