[Insight-users] How to watch IterationEvent()
jiang
jiang at TI.Uni-Trier.DE
Wed, 7 Jan 2004 11:38:32 +0100
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