[Insight-users] An error under VC6, maybe I use itkImage uncorrectly

Luis Ibanez luis . ibanez at kitware . com
Thu, 21 Aug 2003 18:27:45 -0400


Hi Zhaocg,


Your code looks fine.

Could you please add a try/catch block around the Update()
method ?

It is likely that the filter is missing something.

Please add code like the following:


   try
   {
   filter->Update();
   }
   catch( itk::ExceptionObject & exi )
    {
    std::cerr << "ITK exception " << std::endl;
    std::cerr << exi << std::endl;
    }
   catch( std::exception & ex )
    {
    std::cerr << "STD exception " << std::endl;
    std::cerr << ex.what() << std::endl;
    }
   catch( ... )
    {
    std::cerr << "Other exception " << std::endl;
    }


Let us know what you get after catching the exception.


----

Also, (this may be unrelated to the problem you are facing),
but anyways, you may want to use the ImageImportFilter.

You will find a description of this filter in the software
guide.

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

Section 4.1.7, pdf-page 70.

This filter allows you to import a buffer into an itk::Image.


--------


Regards,


    Luis



---------------
Zhaocg wrote:
> Hi Luis,
> 
>     The code bellow cause a runtime error:
> 
>     typedef itk::Image<float, 2>                                                                                                       CITKFloatImageType;
>     typedef itk::GradientMagnitudeImageFilter<CITKFloatImageType, CITKFloatImageType>        CITKGradMagFilterType;
>  
>      CITKFloatImageType::IndexType idx;
>      CITKFloatImageType::SizeType  size;
>      CITKFloatImageType::RegionType rgn;
>      
>     idx.SetElement(0, 0);
>     idx.SetElement(1, 0);
>     
>     size.SetElement(0, sz.cx); // sz = {512, 512}
>     size.SetElement(1, sz.cy);
>     
>     rgn.SetIndex(idx);
>     rgn.SetSize(size);
> 
>     g_itkpImage = CITKFloatImageType::New();
>     g_itkpImage -> SetLargestPossibleRegion(rgn);
>     g_itkpImage -> SetBufferedRegion(rgn);
>     g_itkpImage -> SetRequestedRegion(rgn);
>     g_itkpImage -> Allocate();
> 
>     itk::ImageRegionIterator<CITKFloatImageType> It(g_itkpImage, rgn);
>     It.GoToBegin();
>  
>    while(!It.IsAtEnd()){
>         It.Set((float)(pImg[i++]));    ////pImg is a 1-D array
>         ++It;
>     }
> 
>    g_itkpGradMagFilter = CITKGradMagFilterType::New();
>    g_itkpGradMagFilter -> SetInput(g_itkpImage);
>    g_itkpGradMagFilter -> Update();  ///////////////////////// this sentence cause an runtime error /////////////////////////
> 
> 
> I traced into the source code further and found that this runtime error (Microsoft C++ exception) was caused by the line bellow:
> 
> imgData = dynamic_cast<const ImageBase<VImageDimension>*>(data);  //// itk version 1.2,  itkImageBase.txx, line 173 
> 
> How to clear it? Thanks!
> 
> Zhao
> 
> 
> 
>     
> "{"‚n±ê왨¥Šx%ŠËHžÈ †Û¬z»"¶J+‚m§ÿðí’Šàþf¢–f§þX¬¶)ߣø§²(!¶ërs==