Finally, I find out one solution![Insight-users] How to watch IterationEvent()

Luis Ibanez luis.ibanez at kitware.com
Thu, 08 Jan 2004 11:35:54 -0500


Hi Chuyan,

Thanks for letting us know that you found
the solution to your problem.

As you now know, it is important to have
connected all the Observer classes before
you run the filter by calling Update().

There are still some unclear issues on your
email. For example the fact the program
works fine when you commment out a "cout"...

This is a bad, very bad sign !

I'm affraid that you may still have some
pointer/memory issues in your program.
Please try not to use it for image guided
surgery any time soon...

You should probably try any of the tools
that help you find inapropriate memory and
pointer usage. E.g. Purify (windows) or
Valgrind (Unix).


Regards,


   Luis


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

> Hi Luis,
> Good news! I tried many many times. At last, one solution works actually. It
> is that put the definition of event watch code just before filter->Update().
> Any other place doesn't work. It looks very strange, but it works. I don't
> know why.
> Another explanation that why the program will break, if I put one simple
> sentence to try/catch block of filter->Update(), then it will break, just
> like:
>  try
>     {
>     m_thresholdSegmentation->Update();
>     std::cout<<"print something"<<std::endl;
>     }
>   catch( itk::ExceptionObject & excep )
>     {
>     std::cerr << "Exception caught !" << std::endl;
>     std::cerr << excep << std::endl;
>     return;
>     }
> If I comment that std::cout line, then the program will work without any
> problem. But for watching IterationEvent, only when I put the following code
> above the try/catch block:
> 
>   typedef itk::QtSignalAdaptor SignalAdaptorType;
>   SignalAdaptorType signalAdaptor1;
> 
>   // Connect the adaptor as an observer of a Filter's event
>   filter->AddObserver( itk::IterationEvent(),
>  signalAdaptor1.GetCommand() );
> 
>   // Connect the adaptor's Signal to the Qt Widget Slot
>   QObject::connect( &signalAdaptor1, SIGNAL(Signal()), this,
> SLOT(IterateUpate()) );
> 
> Thank you for your kind help during these days. I learn many things from you
> about ITK, also about programming.
> 
> 
> Cheers,
> 
> Chunyan
> 
> -----Ursprungliche Nachricht-----
> Von: Luis Ibanez [mailto:luis.ibanez at kitware.com]
> Gesendet: Mittwoch, 7. Januar 2004 18:16
> An: jiang
> Cc: ITK
> Betreff: Re: AW: AW: [Insight-users] How to watch IterationEvent()
> 
> 
> 
> 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
> 
> 
> 
>