[Insight-users] Trying to derive single OutputWindow class from itkOutputWindow, vtkOutputWindow

Luis Ibanez luis . ibanez at kitware . com
Thu, 20 Nov 2003 15:25:04 -0500


Hi Parag,

It seems that you choose to use multiple inheritance
in one of those cases where it will not work too well.

Since these two classes are so similar, doing multiple
inheritance from them is prone to a good number of
ambiguous situations.

What you may do intead is to create the following three
classes:

A) itkOutputWindowDelegator
B) vtkOutputwindowDelegator
C) fltkOutputWindow

class (A) deriving from itkOutputWindow
class (B) deriving from vtkOutputWindow

Both of these two classes should have a pointer
to a Fl_Text_Output, and implement the code for
writing to this text output (that they don't own).

Then you write a (C) as a class that
has a Fl_Text_Output, and classes (A) and (B)
as member variables.  In the constructor of (C)
you pass the Fl_Text_Output pointer to (A) and
(B), so they are in capacity of writing to this
widget.

Finally in your class (C), implement methdos:

vtkOutputWindow * GetVTKOutputWindow()
itkOutputWindow * GetITKOutputWinodw()

each one of which returs a pointer to the
internally owned OutputWindows (itk and vtk
respectively).

Then, to use your class, you do:


myWindow = aks::fltkOutputWindow::New();

itk::OutputWindow::SetInstance(
           myWindow->GetITKOutputWindow());

vtkOutputWindow::SetInstance(
           myWindow->GetVTKOutputWindow());




The intuition behind this is that multiple-inheritance
can always be replaced with containment.


Hope that helps,


  Luis


----------------------------------------------

Parag Chandra wrote:
> Hi,
> 
>  
> 
> I want to create a single class derived from itk::OutputWindow and 
> vtkOutputWindow to use as a receptacle for all the messages my 
> application (and ITK/VTK) might generate. Right now I have two classes, 
> ITKDevNullWindow and VTKDevNullWindow, and at the beginning of my 
> program I use
> 
>  
> 
>     
> itk::OutputWindow::SetInstance(aks::ITKDevNullWindow::New().GetPointer());
> 
>     vtkOutputWindow::SetInstance(aks::VTKDevNullWindow::New());
> 
>  
> 
> to redirect messages. This works fine in the case of redirecting to 
> /dev/null, but now I want to redirect the messages to a single FLTK 
> output window, so now I need to derive my OutputWindow from 
> Fl_TextOutput, vtkOutputWindow, and itk::OutputWindow. As a first step, 
> I have tried to create a DevNullOutput derived from both 
> itk::OutputWindow and vtkOutputWindow, like this:
> 
>  
> 
> class DevNullOutput : public itk::OutputWindow, public vtkOutputWindow
> 
> {
> 
> public:
> 
>     typedef DevNullOutput Self;
> 
>     typedef itk::SmartPointer<Self>  Pointer;
> 
>     itkNewMacro(Self);
> 
>     itkTypeMacro(DevNullOutput, OutputWindow);
> 
>     vtkTypeRevisionMacro(DevNullOutput, vtkOutputWindow);
> 
>     virtual void DisplayText(const char*) {}
> 
>  
> 
> protected:
> 
>     DevNullOutput() {}
> 
>     virtual ~DevNullOutput() {}
> 
> };
> 
>  
> 
> But VC++6 gives me 2 errors saying that DevNullOutput::new is ambiguous 
> and DevNullOutput::delete is ambiguous. I resolved the first one by 
> expanding out itkNewMacro to be:
> 
>  
> 
> static Pointer New(void)
> 
> {
> 
>         Pointer smartPtr;
> 
>         Self *rawPtr = ::itk::new Self;
> 
>         smartPtr = rawPtr;
> 
>         static_cast<itk::OutputWindow*>(rawPtr)->UnRegister();
> 
>         return smartPtr;
> 
> }
> 
>  
> 
> but the second one remains. How can I disambiguate this symbol, and why 
> is it even getting confused about these two operators that, as far as I 
> can tell, aren?t even overridden by ITK or VTK? Also, is this whole idea 
> an exercise in futility? I haven?t ever tried to use multiple 
> inheritance before. Thanks for any advice you can offer.
> 
>  
> 
> Best regards,
> 
> Parag Chandra
>