ITK  6.0.0
Insight Toolkit
itkDomainThreader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 itkDomainThreader_h
19 #define itkDomainThreader_h
20 
21 #include "itkObject.h"
22 #include "itkMultiThreaderBase.h"
23 
24 namespace itk
25 {
26 
65 template <typename TDomainPartitioner, typename TAssociate>
66 class ITK_TEMPLATE_EXPORT DomainThreader : public Object
67 {
68 public:
69  ITK_DISALLOW_COPY_AND_MOVE(DomainThreader);
70 
73  using Superclass = Object;
76 
77  using DomainPartitionerType = TDomainPartitioner;
79 
80  using AssociateType = TAssociate;
81 
83  itkOverrideGetNameOfClassMacro(DomainThreader);
84 
90  void
91  Execute(AssociateType * enclosingClass, const DomainType & completeDomain);
92 
94  itkSetObjectMacro(DomainPartitioner, DomainPartitionerType);
95  itkGetModifiableObjectMacro(DomainPartitioner, DomainPartitionerType);
100  itkGetConstMacro(NumberOfWorkUnitsUsed, ThreadIdType);
101 
104  GetMultiThreader() const;
105 
110  itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
111  itkGetConstMacro(NumberOfWorkUnits, ThreadIdType);
120  {
121  return this->m_MultiThreader->GetMaximumNumberOfThreads();
122  }
123  void
124  SetMaximumNumberOfThreads(const ThreadIdType threads);
127 protected:
128  DomainThreader();
129  ~DomainThreader() override = default;
130 
133  virtual void
134  DetermineNumberOfWorkUnitsUsed();
135 
139  virtual void
141  {}
142 
151  virtual void
152  ThreadedExecution(const DomainType & subdomain, const ThreadIdType threadId) = 0;
153 
157  virtual void
159  {}
160 
161  itkSetObjectMacro(MultiThreader, MultiThreaderBase);
162 
167  ThreaderCallback(void * arg);
168 
169  AssociateType * m_Associate{};
170 
171 private:
172  void
173  StartThreadingSequence();
174 
177  {
179  };
180 
185  ThreadIdType m_NumberOfWorkUnitsUsed{ 0 };
186  ThreadIdType m_NumberOfWorkUnits{};
187  typename DomainPartitionerType::Pointer m_DomainPartitioner{};
188  DomainType m_CompleteDomain{};
189  MultiThreaderBase::Pointer m_MultiThreader{};
190 };
191 
192 } // namespace itk
193 
194 #ifndef ITK_MANUAL_INSTANTIATION
195 # include "itkDomainThreader.hxx"
196 #endif
197 
198 #endif
itk::MultiThreaderBase
A class for performing multithreaded execution.
Definition: itkMultiThreaderBase.h:107
itk::DomainThreader< ThreadedIndexedContainerPartitioner, TJointHistogramMetric >::AssociateType
TJointHistogramMetric AssociateType
Definition: itkDomainThreader.h:80
itk::DomainThreader::GetMaximumNumberOfThreads
ThreadIdType GetMaximumNumberOfThreads() const
Definition: itkDomainThreader.h:119
itk::ThreadedIndexedContainerPartitioner
Partitions an indexed container.
Definition: itkThreadedIndexedContainerPartitioner.h:45
itk::SmartPointer< Self >
itk::ITK_MAX_THREADS
constexpr vcl_size_t ITK_MAX_THREADS
Definition: itkThreadSupport.h:79
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:102
itk::ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
Definition: itkThreadSupport.h:89
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::DomainThreader::ThreadStruct::domainThreader
DomainThreader * domainThreader
Definition: itkDomainThreader.h:178
itk::DomainThreader< ThreadedIndexedContainerPartitioner, TJointHistogramMetric >::DomainType
typename DomainPartitionerType::DomainType DomainType
Definition: itkDomainThreader.h:78
itk::DomainThreader::AfterThreadedExecution
virtual void AfterThreadedExecution()
Definition: itkDomainThreader.h:158
itk::DomainThreader
Multi-threaded processing on a domain by processing sub-domains per thread.
Definition: itkDomainThreader.h:66
itk::DomainThreader::ThreadStruct
Definition: itkDomainThreader.h:176
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itkMultiThreaderBase.h
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ThreadedIndexedContainerPartitioner::DomainType
Superclass::DomainType DomainType
Definition: itkThreadedIndexedContainerPartitioner.h:63
itk::DomainThreader::BeforeThreadedExecution
virtual void BeforeThreadedExecution()
Definition: itkDomainThreader.h:140