[Insight-users] ITK and type casting

Hendrik Belitz hbelitz at darkon.info
Fri Mar 30 07:02:57 EST 2007


Hi Urlek,

You cannot call methods of derived classes from a pointer to the base class if these methods were not also defined in the base class.
In your specific case, I would instantiate an FileReaderType object (or SeriesReaderType respectively) first, call all parametrizing methods (like SetFileNames) and afterwards assign the Reader object to the generic SourceType::Pointer:


typedef itk::ImageSource< InputImageType > SourceType;
typedef itk::ImageFileReader< InputImageType > FileReaderType;


SourceType::Pointer firstPipelineNode;

if ( instantiateFileReader )
{
  FileReaderType::Pointer reader = FileReaderType::New();
  reader->SetFileName( "foo.bar" );
  /* Call more reader methods here */
  firstPipelineNode = reader; 
} 
else
{
  /* Do the same here for ImageSeriesReader*/
}



Hope this helps,
 Hendrik

>
>Hi,
>
>   I have a problem with casting that seem to defy all my understanding
>about it (which, I admit, is not very deep). 
>
>   I would like to use an itk::ImageSource as the beginning of the pipeline
>but instantaniate it as either an ImageFileReader or ImageSeriesReader,
>which is to be decided at the run-time. But I somehow can not use sub-class
>member functions (ImageFileReader or ImageSeriesReader) if I define the
>source to be ImageSource!
>
>For Example:
>
>  typedef itk::ImageSource< InputImageType >  SourceType;
>  typedef itk::ImageFileReader< InputImageType >  FileReaderType;
>
>  SourceType::Pointer reader = SeriesReaderType::New();
>
>How do I now call reader's SetFileNames(), which is member of
>SeriesReaderType but not SourceType?
>
>-- 
>View this message in context: 
>http://www.nabble.com/ITK-and-type-casting-tf3491684.html#a9751546
>Sent from the ITK - Users mailing list archive at Nabble.com.
>
>_______________________________________________
>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