AW: AW: [Insight-users] How to watch IterationEvent()
Luis Ibanez
luis.ibanez at kitware.com
Wed, 07 Jan 2004 12:15:58 -0500
Hi Chuyan,
It seems that in (1) you proved that there is
no ITK exception being thrown from the filter.
However, in (2) you found that there is an
access violation Exception being thrown.
You will catch this exception is you use
catch( std::exception & excp )
instead of
catch( itk::ExceptionObject & excp )
In any case,
The exception that is being thrown is due to an
illegal access to a region of memory. It means
that you have a pointer accessing memory that
has not been allocated for it.
Usual suspectes are:
1) Still the pointer to the filter...
- Did you tried filter->Print( std::cout );
in IterateUpdate(). I still think that your
"filter" pointer there has something to prove...
2) The input image of the ThresholdSegmentation
filter.
- Have you verified that a valid image is
being passed as input to this filter ?
the simplest test is to use an ImageFileWriter
connect the image as input to the writer and
dump the image to a file. Then view the file
with the ImageViewer application in InsightApplications,
or with any other viewer you may have.
3) The input image for the FeatureImage of the
ThresholdSegmentation filter.
Are you providing an input for the FeatureImage ?
If no : You must provide one.
If yes: Check the validity of the image by
writing it to a file, as in (2).
You don't need to define any RMSCommand, the Command
contained in the QtSlotAdaptor is all what you need.
It doesn't seem that your crash has anything to do with
the Iteration update, since the exception is thrown from
the Update method and not from the IterationUpdate() method.
If you are debugging with VisualStudio you can setup the
debugger for stopping when an exception is thrown and
showing you the real lines of code involved.
Are you attempting to refresh a visualization at every
iteration of the filter ?
That would be another interesting place to search for
suspects...
Regards,
Luis
-----------------
jiang wrote:
> 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
>>
>
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>