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

jiang jiang at TI.Uni-Trier.DE
Wed, 7 Jan 2004 17:37:28 +0100


Hi Luis,
Firstly I would like to answer your two argues:
A) I have set try/catch block around Update(), but no exception is shown.
The application breaks directly.
B) I debug it and find out that the program stops at filter->Update(). The
error message is:
"Unhandled exception in SeeThrough.exe(QT-MT230NC.DLL):0xC0000005: Access
Violation."
And filter is defined by
ThresholdSegmentationLevelSetImageFilterType::Pointer filter;
It should be SmartPointer. filter->GetElapsedIterations() can work when the
program doesn't collapse.

I have a look in the code of
itkThresholdSegmentationLevelSetImageFilterTest.cxx. It defines a class
RMSCommand to watch the IterationEvent. Should I also define such a class?

Thank you for your quick and clear answer.

Best regards,

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



Hi Chuyan,

The IterationEvent can be watched without problem
from the ThresholdSegmentationLevelSetImageFilter.

You can easily verify the correct beahvior of
this filter in its test:

   Insight/Testing/Code/Algorithms
    itkThresholdSegmentationLevelSetImageFilterTest.cxx

This test is printing out messages for both the
IterationEvent() and the ProgressEvent().


If your program is "collapsing", that's a clear
indication that there is something wrong about
the organization of your code.

I would suggest you to start tracing the causes
of the crash:


A) Have you tried setting a try/catch block
    around the Update() call of the filter ?

    It may be possible that the filter is
    throwing an exception during the call to
    Update().


B) Have you ran the program in a debugger
    and traced the place where it crashes ?


I still think that there is something inapropriate
in the pointer you are using for calling
GetElapsedIterations().
Is this variable a SmartPointer ?



Regards,


    Luis


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

> 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
>>
>
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>