ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkDomainThreader.h
Go to the documentation of this file.
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 itkDomainThreader_h
19 #define itkDomainThreader_h
20 
21 #include "itkObject.h"
22 #include "itkMultiThreader.h"
23 
24 namespace itk
25 {
26 
65 template< typename TDomainPartitioner, typename TAssociate >
66 class ITK_TEMPLATE_EXPORT DomainThreader: public Object
67 {
68 public:
71  typedef Object Superclass;
74 
75  typedef TDomainPartitioner DomainPartitionerType;
76  typedef typename DomainPartitionerType::DomainType DomainType;
77 
78  typedef TAssociate AssociateType;
79 
81  itkTypeMacro( DomainThreader, Object );
82 
88  void Execute( AssociateType * enclosingClass, const DomainType & domain );
89 
91  itkSetObjectMacro( DomainPartitioner, DomainPartitionerType );
92  itkGetModifiableObjectMacro(DomainPartitioner, DomainPartitionerType );
94 
97  itkGetConstMacro( NumberOfThreadsUsed, ThreadIdType );
98 
100  MultiThreader * GetMultiThreader() const;
101 
106  ThreadIdType GetMaximumNumberOfThreads() const;
107  void SetMaximumNumberOfThreads( const ThreadIdType threads );
109 
110 protected:
111  DomainThreader();
112  virtual ~DomainThreader() ITK_OVERRIDE;
113 
116  virtual void DetermineNumberOfThreadsUsed();
117 
121  virtual void BeforeThreadedExecution(){}
122 
131  virtual void ThreadedExecution( const DomainType& subdomain,
132  const ThreadIdType threadId ) = 0;
133 
137  virtual void AfterThreadedExecution(){}
138 
139  itkSetObjectMacro( MultiThreader, MultiThreader );
140 
144  static ITK_THREAD_RETURN_TYPE ThreaderCallback( void *arg );
145 
147 
148 private:
149  ITK_DISALLOW_COPY_AND_ASSIGN(DomainThreader);
150 
151  void StartThreadingSequence();
152 
155  {
157  };
158 
164  typename DomainPartitionerType::Pointer m_DomainPartitioner;
166  MultiThreader::Pointer m_MultiThreader;
167 };
168 
169 }
170 
171 #ifndef ITK_MANUAL_INSTANTIATION
172 #include "itkDomainThreader.hxx"
173 #endif
174 
175 #endif
Multi-threaded processing on a domain by processing sub-domains per thread.
virtual void AfterThreadedExecution()
AssociateType * m_Associate
#define ITK_THREAD_RETURN_TYPE
DomainPartitionerType::DomainType DomainType
TDomainPartitioner DomainPartitionerType
SmartPointer< Self > Pointer
DomainPartitionerType::Pointer m_DomainPartitioner
SmartPointer< const Self > ConstPointer
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
ThreadIdType m_NumberOfThreadsUsed
MultiThreader::Pointer m_MultiThreader
Base class for most ITK classes.
Definition: itkObject.h:59