[Insight-developers] itkImageIOBase parent/child question

Wilson Chang wmcst6+@pitt.edu
Wed, 31 Oct 2001 17:09:14 -0500


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