[Insight-users] Why is itkDataObject::m_Source a WeakPointer?
Miller, James V (Research)
millerjv@crd.ge.com
Fri, 11 Oct 2002 13:58:48 -0400
Okay. The problem is that since the DataObject has a weak pointer
to the last object to the pipeline, and nobody else is holding onto
a handle to the pipeline objects, the pipeline is being destroyed when
you exit your routine. When the pipeline is destroyed, the source of the
output data object is reset to NULL.
Your options are:
1. Return a SmartPointer to the last object in the pipeline instead of
returning a SmartPointer to the output of the last object in the
pipeline. This should force the pipeline not to destroy itself when
you exit your routine.
2. In doing similar things in that past, I usually cache the smart pointers
to all my pipeline elements as ivars in a class. So I have a class that
encapsulates the pipeline with ivars that are smart pointers to every
filter in the pipeline. While this is not truly necessary (you could just
cache the last element of the pipeline), I usually find that once I have
a pipeline constructed, I end up adjusting ivar settings on the elements
in the pipeline.
3. (Somewhere in between 1 and 2), you could return not only the smart
pointer to the output of the last object in the pipeline but also the a
smart pointer to the last process object in the pipeline.
Usually, I do not call Update() on a DataObject. I usually think in terms
of ProcessObjects. So I pass around handles ProcessObjects and call update on
them. Then if I want to cache the output of a process object, I'll get the
output and then disconnect it from the pipeline.
Jim
> -----Original Message-----
> From: Th. Boettger [mailto:t.boettger@dkfz-heidelberg.de]
> Sent: Friday, October 11, 2002 1:04 PM
> To: ITK Mailing List
> Subject: AW: [Insight-users] Why is itkDataObject::m_Source a
> WeakPointer?
>
>
> Well okay. This surely is true.
>
> But how can I avoid the problem described below?
>
>
> > -----Ursprungliche Nachricht-----
> > Von: Miller, James V (Research) [mailto:millerjv@crd.ge.com]
> > Gesendet: Freitag, 11. Oktober 2002 18:54
> > An: 'Th. Boettger'; ITK Mailing List
> > Betreff: RE: [Insight-users] Why is itkDataObject::m_Source a
> > WeakPointer?
> >
> >
> > The source is a WeakPointer because the Source points to the
> > DataObject and
> > the DataObject points to the Source. If they both held
> > SmartPointers to each
> > other, then we would have a cyclic reference loop and neither the
> > Source or the
> > DataObject could ever be deleted.
> >
> >
> >
> > > -----Original Message-----
> > > From: Th. Boettger [mailto:t.boettger@dkfz-heidelberg.de]
> > > Sent: Friday, October 11, 2002 12:25 PM
> > > To: ITK Mailing List
> > > Subject: [Insight-users] Why is itkDataObject::m_Source a
> WeakPointer?
> > >
> > >
> > > Hi all,
> > >
> > > I am trying to construct a filter pipeline in a member
> function and to
> > > return the resulting data object *without* calling Update()
> > > in this method.
> > > When trying to update the returned data object outside, the
> > > source is set to
> > > NULL. The reason is that m_Source member is defined as a weak
> > > pointer, thus
> > > the reference count of the process objects (the source) is
> > > not incremented.
> > >
> > > Why is it a WeakPointer? How can I avoid this problem?
> > >
> > > class itkDataObject
> > > {
> > > ...
> > > mutable WeakPointer<ProcessObject> m_Source;
> > > ...
> > > }
> > >
> > > Thanks in advance!
> > >
> > >
> > >
> > > ---
> > > Dipl.-Inform. Thomas Boettger
> > > Deutsches Krebsforschungszentrum (German Cancer
> > > Research Center)
> > > Div. Medical and Biological Informatics H0100 Tel: (+49)
> > > 6221-42 2328
> > > Im Neuenheimer Feld 280 Fax: (+49)
> > > 6221-42 2345
> > > D-69120 Heidelberg e-mail:
> > > t.boettger@dkfz.de
> > > Germany
> > http://www.dkfz.de/mbi/people/thomasb.shtml
> >
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users@public.kitware.com
> > http://public.kitware.com/mailman/listinfo/insight-users
> >
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>