[Insight-users] weird thing happen when I try to write template function

Luis Ibanez luis.ibanez at kitware.com
Sat Feb 21 10:56:16 EST 2009


Hi Baoyun,

Your function has a misleading argument name.

It should probably be:


 > template <class TInputFilter>
 > void IsotropicResample( TInputFilter* inputFilter )
 > {


instead of the current:


 > template <class TInputImage>
 > void IsotropicResample( TInputImage* inputimage )
 > {


Also, the OutputImageType, you should get it as
a trait from the InputFilter type, instead of
composing it on your own.

You should do:

 > typedef typename TInputFilter::OutputImageType OutputImageType;

Instead of the current:

 > const unsigned int Dimension=3;
 > typedef   short   OutputPixelType;
 > typedef itk::Image< OutputPixelType,   Dimension >   OutputImageType;



However,
these are not the reasons why your program fails at run time.


The problem is that you missed to pass the input filename
to the reader.


You should do this in the main() before you invoke your
templated function.


Something like

main()
 > {
 >   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
 >   ReaderType::Pointer reader = ReaderType::New();

     reader->SetFileName("myInputImageFile.mhd"); //  <<<<< THIS

 >    IsotropicResample <ReaderType> (reader );
 > }
 >



    Regards,


        Luis


----------------
Baoyun Li wrote:
> Dear All:
>  
> I am trying to write some template function.
>  
> Here is  my function, it just passed ReaderType::Pointer from the main 
> program
>  
>  
> template <class TInputImage>
> void IsotropicResample( TInputImage* inputimage )
> {
>  
>     const unsigned int Dimension=3;
>     typedef   short   OutputPixelType;
>     typedef itk::Image< OutputPixelType,   Dimension >   OutputImageType;
>  
>    typedef itk::ImageFileWriter< OutputImageType >  WriterType;
>  
>    WriterType::Pointer writer = WriterType::New();
>  
>    writer->SetFileName("../data/test.hdr");
>    writer->SetInput( inputimage->GetOutput() );
>   
>   try
>      {
>      writer->Update();
>      }
>    catch( itk::ExceptionObject & excep )
>      {
>      std::cerr << "Exception caught !" << std::endl;
>      std::cerr << excep << std::endl;
>      }
> ;
> 
> };
>  
> ////// in the main function, we call the function as following
>  
> main()
> {
>   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>   ReaderType::Pointer reader = ReaderType::New();
>    IsotropicResample <ReaderType> (reader );
> }
>  
> When I run the program through command line, everything is ok, I got the 
> test.hdr as output.
>  
> But when I debug program, the program catch error and goes to the catch 
> branch.
>  
> warning RTTI symbol not found,
> FileReader<itk::Image<short, 3u>, itk::DefaultConvertPixelTraits<short> >'
>  
>   try
>      {
>      writer->Update();
>      }
>    catch( itk::ExceptionObject & excep )
>      {
>      std::cerr << "Exception caught !" << std::endl;
>      std::cerr << excep << std::endl;
>      }
>  
> However, the result is still there?
>  
> Can sombody teach me how to solve this problem??
>  
> Thanks
>  
> Baoyun
> 
>  
> 


More information about the Insight-users mailing list