[Insight-developers] itkImageIOBase parent/child question

Bill Hoffman bill.hoffman@kitware.com
Fri, 02 Nov 2001 09:04:17 -0400


There are two ways to do this:

1. use dynamic_cast :

itk::ImageFileReader<myImage>::Pointer reader 
    = itk::ImageFileReader<myImage>::New();
  reader->DebugOn();
  reader->SetFileName(av[1]);
  try{
  reader->Update();
}
catch (itk::ImageFileReaderException& e)
  {
  std::cerr << "exception in file reader \n"  << e.GetDescription();
  return -1;
  }
  
itk::ImageIOBase::Pointer reader = reader->GetImageIO();
itk::VOLImageIO* volio = dynamic_cast<itk::VOLImageIO*>(reader.GetPointer());
if(volio)
{
// access VOLImageIO methods now...
}


2. Set the IO object directly on the reader:


itk::VOLImageIO::Pointer volio = itk::VOLImageIO::New();
reader->SetImageIO(volio);
reader->SetFileName(...);
...
volio->privatestuff....



-Bill

At 08:03 AM 11/2/2001 -0500, Miller, James V (CRD) wrote:
>When you need the distance to the imaging device, scan rate, etc. You'll have to dynamic_cast<> the
>ImageIOBase to the appropriate subclass.  That is the only way you'll be able to get access to
>members that only exist in the subclass. 
>
>Of course, this means that you'll need to know the suite of readers that could have the information
>that you are requesting.
>
>
>-----Original Message-----
>From: Wilson Chang [mailto:wmcst6+@pitt.edu]
>Sent: Wednesday, October 31, 2001 5:09 PM
>To: insight-developers@public.kitware.com
>Subject: [Insight-developers] itkImageIOBase parent/child question
>
>
>I was wondering if someone knew of a solution to a problem that I have been
>having.  Here is the scenerio:
>
>class Parent
>{
>}
>
>class Child1 : public Parent
>{
>private:
>  int m_Child1data;
>}
>
>class Child2 : public Parent
>{
>private:
>  float m_Child2data;
>}
>
>
>}main()
>{
>    Parent foo;
>//some code that makes the foo of type Child1.
>// foo must be of type Parent to be generic across all possible children
>type
>...
>}//main()
>
>
>    My question is, how can I go about getting access to members of a child,
>when all the code really knows about is the parent?  i.e. how would I go
>about getting m_Child1data if all the program knew about was the Parent
>class?  Putting a "itkGetMacro(Child1Data, int)" in the Child1 class doesn't
>work.  Any Ideas?
>
>    The situation that I am running into involves file readers.  All of the
>file readers inherit from ImageIOBase.  For example, I am working on the
>itkVOLImageIO class.  I have some information loaded from the image file
>pertaining to the image (i.e. patient information, distance the image is
>away from the imaging device, scan rate...).  This information does not have
>a place to be stored in the ImageIOBase class.  However, this information is
>important for processing the image later downstream.  When a generic file
>reader is created to load up the file:
> itk::ImageFileReader<myImage>::Pointer reader =
>itk::ImageFileReader<myImage>::New();
>but now I need access to information besides the pixel values, such as the
>distance the image is away from the imaging device, scan rate, etc.  How can
>I go about getting access to the information?
>
>Wilson Chang
>
>Univ of Pittsburgh MD/PhD program
>School of Engineering-Bioengineering
>School of Medicine
>
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers
>_______________________________________________
>Insight-developers mailing list
>Insight-developers@public.kitware.com
>http://public.kitware.com/mailman/listinfo/insight-developers