[Insight-users] reusing Filters
Miller, James V (Research)
millerjv at crd.ge.com
Thu Apr 21 09:42:40 EDT 2005
Samuel,
>From the callstack, you can see that the pipeline is throwing an exception.
If you put your call to Update() in a try/catch block, you can print
out the exception
try
{
thresholdFilter->Update();
}
catch (itk::ExceptionObject &e)
{
std::cout << e;
}
You will probably see that the pipeline is throwing an "InvalidRequestedRegion"
exception, indicating the RequestedRegion is at least partially outside
the LargestPossibleRegion.
This can happen when an input is swapped on a filter, and the new input
has a different size. The first time Update() is called on a filter,
the pipeline sets the RequestedRegion to the LargestPossibleRegion
(unless a RequestedRegion was not explictly set by the user). Subsequent
calls to Update() try to generate the RequestedRegion from the previous
call. In swapping the input to the filter, a new LargestPossibleRegion
can result and that input may not be able to satisfy the previous
RequestedRegion.
There are (at least) 3 ways to solve this problem.
1) As you discovered, you can simply create new filters for each pipeline
execution on new data.
2) Whenever you switch the input to the pipeline with one that is a different
size, call UpdateLargestPossibleRegion() instead of calling Update(). This forces
the pipeline to use the LargestPossibleRegion as the RequestedRegion instead of
using any caches RequestedRegion.
3) Explictly set the RequestedRegion on the output of the pipeline whenever
you change the input to one that is a different size. This requires that
you know how big the output of the pipeline will be, so you need to understand
what each filter in the pipeline is doing. This is least appealing option. To use
this option will write code like
thresholdFilter->GetOutput()->SetRequestedRegion( someRegion );
thresholdFilter->Update();
Option #2 is the easiest to do. You can either call UpdateLargestPossibleRegion()
whenever you change inputs to an image that is a different size or you can simply
call UpdateLargestPossibleRegion() whenever you change the inputs.
Jim
-----Original Message-----
From: insight-users-bounces at itk.org
[mailto:insight-users-bounces at itk.org]On Behalf Of marquis2 at etu.unige.ch
Sent: Thursday, April 21, 2005 6:35 AM
To: insight-users at itk.org
Subject: [Insight-users] reusing Filters
hi,
is it ok to reuse a filter many times or does it have to be instanciated once
per use ? the docs suggests the first but I have a SIGABRT with a
BinnaryThresholdImageFilter< ImageType, ImageType >
(with ImageType = short, 2) for every _second_ image I want to filter:
Program received signal SIGABRT, Aborted.
[Switching to Thread 16384 (LWP 12578)]
0x4096cb71 in kill () from /lib/i686/libc.so.6
(gdb) bt
#0 0x4096cb71 in kill () from /lib/i686/libc.so.6
#1 0x4080bcf1 in pthread_kill () from /lib/i686/libpthread.so.0
#2 0x4080c00b in raise () from /lib/i686/libpthread.so.0
#3 0x4096c904 in raise () from /lib/i686/libc.so.6
#4 0x4096de8c in abort () from /lib/i686/libc.so.6
#5 0x40910305 in __cxxabiv1::__terminate(void (*)()) () from
/usr/lib/libstdc++.so.5
#6 0x40910342 in std::terminate() () from /usr/lib/libstdc++.so.5
#7 0x409104c2 in __cxa_throw () from /usr/lib/libstdc++.so.5
#8 0x081c9fe2 in itk::DataObject::PropagateRequestedRegion() ()
#9 0x081d964a in itk::ProcessObject::PropagateRequestedRegion(itk::DataObject*)
()
#10 0x081c9e7f in itk::DataObject::PropagateRequestedRegion() ()
#11 0x081c9cb5 in itk::DataObject::Update() ()
code is:
thresholdFilter->SetInput(image);
thresholdFilter->SetLowerThreshold( threshold );
thresholdFilter->SetUpperThreshold( itk::NumericTraits< PixelType >::max());
thresholdFilter->SetOutsideValue( 0 ) ;
thresholdFilter->SetInsideValue( white );
thresholdFilter->Update();
is there other "cleaning"
I should make between each use so that it does not crash on the second?
My code works fine with ::New() before each use.
TIA for any help!
Samuel
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list