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

Baoyun Li baoyun_li123 at yahoo.com
Sat Feb 21 18:41:46 EST 2009



Hi, Luis:

Thanks for your reply. I am sorry for my missleading letter.

I did not give the whole main() in the letter. Actually, my code can be run and got propoer output. The only thing is it shows  "warning RTTI symbol not found  FileReader<itk::Image<short, 3u>, itk::DefaultConvertPixelTraits<short> >, and the program catch exception when I use KDE to debug it. Also the content of smart pointer can not be displayed when debuging. If I run it as comman line,  nothing wrong.

1, you suggest not to compose the outputtype but got it as a trait from the inputfiler. But I want to do many things in the template fucntion. Such as isotropic resampling, is it possible for me to get many kinds of filters such as resampling filtering, recursive Gaussian filtering all from the template inputfilter.

2, I am actually want to do muti-scale active contour sementation. So  I dont want to make the main program too long. Thus I want to have template function, but I try to avoid claim so many filters in my main program. Do you have any suggestions? I know ITK has mutiresolutionregistration filtering, is there anything similar for level set?

Thanks and best regards

Baoyun


 

________________________________
From: Luis Ibanez <luis.ibanez at kitware.com>
To: Baoyun Li <baoyun_li123 at yahoo.com>
Cc: insight-users at itk.org
Sent: Saturday, February 21, 2009 7:56:16 AM
Subject: Re: weird thing happen when I try to write template function


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
> 
>  



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090221/bbb21f4a/attachment.htm>


More information about the Insight-users mailing list