[Insight-users] How to watch IterationEvent()

Luis Ibanez luis.ibanez at kitware.com
Wed, 07 Jan 2004 09:19:49 -0500


Hi Chuyan,

In your code you are connecting the Signal() of
the QtSignalAdaptor to the Slot "IterateUpdate()"
of the Qt object "this", and in the IterateUpdate()
method you use the "filter" pointer to call
GetElapsedIterations()...

Could you please tell us:

    A) Where did you defined the pointer "filter"

    B) Where did you assigned a value to the
       pointer "filter"

    C) What is the type of "this" in the signal
       Qt connection line


Chances are that the 'filter' pointer in IterateUpdate()
is invalid (it may be null or it may be associated to a
destroyed object).

You should try the following things in IterateUpdate()
before the GetElapsedIterations() call:

   1) print out the value of the "filter"  pointer.
      std::cout << filter << std::endl;

   2) print out the content of filter
      filter->Print( std::cout );

   3) print out the reference count of filter
      std::cout << filter->GetReferenceCount() << std::endl;


It seem that you may want to reconsider your design and
do the exercise of drawing a couple of UML collaboration
diagrams in order to better organize your code.


Regards,


   Luis



------------------------
jiang wrote:

> Hi, ITK users,
> I use itk::ThresholdSegmentationLevelSetImageFilter to do segmentation as
> the example application ThresholdSegmentationLevelSetFltkGui.
> I use Qt as user interface. Learning from example QtITK, I use the following
> code to watch IterationEvent().
> 
> 	ThresholdSegmentationLevelSetImageFilterType::Pointer m_Filter;
> 	m_Filter=ls->GetLSFilter();
>       typedef itk::QtSignalAdaptor SignalAdaptorType;
>   	SignalAdaptorType signalAdaptor1;
> 
> 	// Connect the adaptor as an observer of a Filter's event
> 	m_Filter->AddObserver( itk::IterationEvent(),
>  signalAdaptor1.GetCommand() );
> 
> 	// Connect the adaptor's Signal to the Qt Widget Slot
> 	QObject::connect( &signalAdaptor1, SIGNAL(Signal()), this,
> SLOT(IterateUpate()) );
> 
> In the segmentation function
> void Segment()
> {
> /*Set some parameters for filter*/
>     ...
>   try
>     {
>     filter->Update();
>     }
>   catch( itk::ExceptionObject & excep )
>     {
>     std::cerr << "Exception caught !" << std::endl;
>     std::cerr << excep << std::endl;
>     return;
>     }
> }
> 
> In SLOT IterateUpdate()
> void IterateUpdate()
> {
> 	std::cerr << "Iteration Number:"<<filter->GetElapsedIterations() <<
> std::endl;
> }
> 
> When I run it, the application will collapse at filter->Update(). When I
> change filter->Update() to filter->Modified(), the application will no
> collapse. But the filter runs iteratively only once, not as
> filter->SetMaximumIterations( 100 ). And the SLOT IterateUpdate() can not be
> called. Is there something wrong in signal setting? How can I watch
> IterationEvent?
> 
> 
> Thank you very much!
> 
> 
> Chunyan
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>