1 /*=========================================================================
2  *
3  *  Copyright Insight Software Consortium
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *         http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkThreadedDomainPartitioner_h
19 #define itkThreadedDomainPartitioner_h
20 
21 #include "itkIntTypes.h"
22 #include "itkMultiThreaderBase.h"
23 #include "itkObject.h"
24 
25 namespace itk
26 {
27 
28 /** \class ThreadedDomainPartitioner
29  *  \brief Virtual base class for partitioning a domain into subsets to be
30  *  processed per thread when parallel processing.
31  *
32  * \tparam TDomain The type of the domain to be partitioned.
33  *
34  * \c PartitionDomain is a method to split the domain into
35  * non-overlapping pieces for threading. It must be overridden by derived
36  * classes to provide the particular functionality required for
37  * \c TDomain type.
38  *
39  * Subclasses of this class are typically used as template arguments to a DomainThreader.
40  *
41  * \sa DomainThreader
42  *
43  * \ingroup DataProcessing
44  * \ingroup ITKCommon
45  */
46 template <typename TDomain >
47 class ITK_TEMPLATE_EXPORT ThreadedDomainPartitioner : public Object
48 {
49 public:
50   ITK_DISALLOW_COPY_AND_ASSIGN(ThreadedDomainPartitioner);
51 
52   /** Standard class type aliases. */
53   using Self = ThreadedDomainPartitioner;
54   using Superclass = Object;
55   using Pointer = SmartPointer<Self>;
56   using ConstPointer = SmartPointer<const Self>;
57 
58   /** Run-time type information (and related methods). */
59   itkTypeMacro(ThreadedDomainPartitioner, Object);
60 
61   /** Type of the input object that's split for threading */
62   using DomainType = TDomain;
63 
64   /** Split the domain \c completeDomain into up to \c requestedTotal
65    * non-overlapping subdomains, setting subdomain number \c threadId as
66    * \c subDomain and returning the total number of subdomains actually available.
67    *
68    * Subdomains may represent an image region, or a index range for a parameter
69    * array, etc, depending on the type of object over which this class is
70    * templated.
71    *
72    * This method should be called repeatedly for each value of \c threadId, from 0 up
73    * to the return value (which is always less than or equal to \c requestedTotal).
74    */
75   virtual
76   ThreadIdType PartitionDomain(const ThreadIdType threadId,
77                            const ThreadIdType requestedTotal,
78                            const DomainType& completeDomain,
79                            DomainType& subDomain) const = 0;
80 
81 protected:
82   ThreadedDomainPartitioner()= default;
83   ~ThreadedDomainPartitioner() override = default;
84 };
85 
86 } // end namespace itk
87 
88 #endif
89