[Insight-users] Multithreading Custom Filters
Jayme Kosior
jckosior@ucalgary.ca
Mon May 17 06:05:18 EDT 2004
--Apple-Mail-1--911063936
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
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
>
--Apple-Mail-1--911063936
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
charset=US-ASCII
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 <bold>SplitRequestedRegion().
</bold>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 <bold>InPlaceImageFilter </bold>and
setting it up similar to <bold>BinaryFunctorImageFilter </bold>(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 <bold>ProcessObject::SetNumberOfIutputs( 2 )</bold> in the
custom filter's constructor, and <bold>SetNumberOfRequiredInputs( 1 )
</bold>- call <bold>ProcessObject::SetNumberOfOutputs( 2 )</bold> in
the custom filter's constructor, and <bold>SetNumberOfRequiredOutputs(
2 )</bold>
- Create some additional typedefs for the second output<bold>
</bold>- And maybe possibly need to override
<bold>GenerateOutputRequestedRegion()</bold>
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:
<excerpt>
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:
<excerpt>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
</excerpt>
_______________________________________________
Insight-users mailing list
Insight-users@itk.org
http://www.itk.org/mailman/listinfo/insight-users
</excerpt>
--Apple-Mail-1--911063936--
More information about the Insight-users
mailing list