[Insight-users] Multithreading Custom Filters

Luis Ibanez luis.ibanez@kitware.com
Tue May 18 16:37:04 EDT 2004


Hi Jayme,

1) There are many examples of filter with
    multiple outputs. Please look at the
    DanielssonDistanceMapImageFilter

http://www.itk.org/Insight/Doxygen/html/classitk_1_1DanielssonDistanceMapImageFilter.html



2) You have to call SetNumberOfRequiredInputs()
    and SetNumberOfRequiredOutput().

    Don't call SetNumberOfInputs() or SetNumberOfOutput(),
    instead simply call SetNthOutput() in order to create
    and connect the output images to the filter.

    You will find this code in the Danielsson filter.


    You don't need to override more methods unless
    your filter requires a behavior different from
    the default, which is OutputRegion == InputRegion.



Regards,


    Luis



---------------------
Jayme Kosior wrote:

> Thank you very much Louis!
> 
> After reading your response, I've read a bit more of the source code and 
> API documentation and now understand better how filters break up the 
> regions using *SplitRequestedRegion().
> 
> *I have a couple of other questions, this time regarding custom filters 
> with multiple outputs. In my case, I have a filter that takes two inputs 
> (one is optional) and produces two outputs. Here are the details:
> 
> Input 1: 4D data set (3D volume over time)
> Input 2: 3D mask volume (optional)
> 
> Output 1: 4D data set
> Output 2: 3D mask - either modifies input 2 or creates a mask
> 
> 
> 1. Are there any examples of multiple output filters in ITK?
> 
> I have looked through the ITK filters source code and the example 
> directory, but I couldn't find any. I'm not sure if I missed it, or if 
> there are none.
> 
> 
> 
> 2. Which methods would I likely need to override?
> 
> I was planning on inheriting from *InPlaceImageFilter *and setting it up 
> similar to *BinaryFunctorImageFilter *(but without the functor object), 
> and modifying it to produce two outputs.
> 
> After reading the Doxygen and some source code, I believe that I would 
> need to do the following:
> - call *ProcessObject::SetNumberOfIutputs( 2 )* in the custom filter's 
> constructor, and *SetNumberOfRequiredInputs( 1 )
> *- call *ProcessObject::SetNumberOfOutputs( 2 )* in the custom filter's 
> constructor, and *SetNumberOfRequiredOutputs( 2 )*
> - Create some additional typedefs for the second output*
> *- And maybe possibly need to override *GenerateOutputRequestedRegion()*
> 
> 
> 
> Thank you very much for your time. The ITK framework itself along with 
> the support is excellent. I look forward to contributing once I get the 
> hang of it. :)
> 
> Jayme
> 
> 
> On May 14, 2004, at 22:19, Luis Ibanez wrote:
> 
> 
>     Hi Jayme,
> 
> 
>     1) Yes, you are right, you must implement the method
>     "ThreadedGenerateData()". You may also take advantage
>     of the methods: BeforeGenerateData() and AfterGenerateDatat()
>     but you are not forced to overload them. They are usually
>     useful for preparing the division of the task in threads,
>     and for consolidating the results once the threads are done.
> 
> 
>     2) The regions to be processed are split at the level of the
>     ImageSource class, in the method SplitRequestedRegion().
>     This method is called from the ThreaderCallback() method in
>     ProcessObject. You will find the code in
> 
>     Insight/Code/Common/itkImageSource.cxx
> 
>     By default it attempts to partition the data among the
>     number of threads that are available.
> 
> 
>     3) You can use the SetNumberOfThreads() methods in order to
>     "request" a certain number of threads. This is just a
>     request and doesn't have to be fulfilled by the run time
>     system.
> 
> 
> 
>     Regards,
> 
> 
>     Luis
> 
> 
>     -------------------
>     Jayme Kosior wrote:
> 
>         Hello.
>         I am starting to experiment with creating my own custom filters
>         and I have a question regarding multithreaded filters in ITK.
>         1. As I understand it, if it is possible to thread the filter's
>         task, then the developer only needs to override the
>         *ThreadedGenerateData()* method and provide the filter's
>         implementation. Then, the *ImageSource* base class takes care of
>         breaking the image up into multiple regions that can be
>         processed in separate threads. Is my understanding correct?
>         If this is how it works, what scheme does the *MultiThreader*
>         class use to decide how to partition the image into regions? For
>         example, does it look at how many processors are on the system?
>         The complexity of the operation? etc.
>         2. There is a method in the base class *ProcessObject* called
>         *SetNumberOfThreads()*. Should developers use this method? Or
>         does the ITK multithreading framework use this method to
>         implement the above scheme.
>         Thank you for time.
>         Jayme
> 
> 
> 
> 
>     _______________________________________________
>     Insight-users mailing list
>     Insight-users@itk.org
>     http://www.itk.org/mailman/listinfo/insight-users
> 






More information about the Insight-users mailing list