AW: [Insight-users] How to watch IterationEvent()

jiang jiang at TI.Uni-Trier.DE
Wed, 7 Jan 2004 16:09:22 +0100


Hi Luis,
I'm sorry I make you confused, since I simplify my code in last email. In
fact, I define another class to handel the segmentation, named as L class.
And I define one pointer of L class. It is "ls".
The signal defination and slot function are in the QtUIView class. It
derives from QtUIForm class, and QtUIForm  derives from QDialog, which is
the UI form. The type of "this" in the signal Qt connection line is
QtUIView.
In fact, in SLOT IterateUpdate()
 void IterateUpdate()
 {
 	std::cerr << "Iteration Number:"<<filter->GetElapsedIterations() <<
std::endl;
 }
filter->GetElapsedIterations() should be ls->GetIterateNumber(). And in L
class
int L::GetIterateNumber()
{
	return filter->GetElapsedIterations();
}
All operations about filter are performed in L class, except
m_Filter=ls->GetLSFilter(); and
m_Filter->AddObserver( itk::IterationEvent(), signalAdaptor1.GetCommand() );
which are signal definition part in QtUIView class.

I'm sure filter is legal in L class. It is the pointer of
ThresholdSegmentationLevelSetImageFilterType. It can perform the
segmentation in L class.

I hope my explanation is clear. Thank you for your help. Could you point out
why the IterationEvent can not be watched? The slot function IterateUpdate()
can not be called. And in L class, filter->Update()will cause the program
collapse when it is running, but filter->Modified() will not.


Chunyan

-----Ursprungliche Nachricht-----
Von: Luis Ibanez [mailto:luis.ibanez at kitware.com]
Gesendet: Mittwoch, 7. Januar 2004 15:20
An: jiang
Cc: ITK
Betreff: Re: [Insight-users] How to watch IterationEvent()



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
>