ITK  4.6.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 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 
107  void SetMaximumNumberOfThreads( const ThreadIdType threads );
109 
110 protected:
111  DomainThreader();
112  virtual ~DomainThreader();
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  DomainThreader( const Self & ); // purposely not implemented
150  void operator=( const Self & ); // purposely not implemented
151 
152  void StartThreadingSequence();
153 
156  {
158  };
159 
165  typename DomainPartitionerType::Pointer m_DomainPartitioner;
167  MultiThreader::Pointer m_MultiThreader;
168 };
169 
170 }
171 
172 #ifndef ITK_MANUAL_INSTANTIATION
173 #include "itkDomainThreader.hxx"
174 #endif
175 
176 #endif
virtual void BeforeThreadedExecution()
Light weight base class for most itk classes.
void StartThreadingSequence()
Multi-threaded processing on a domain by processing sub-domains per thread.
void SetMaximumNumberOfThreads(const ThreadIdType threads)
virtual void DetermineNumberOfThreadsUsed()
virtual void AfterThreadedExecution()
AssociateType * m_Associate
static ITK_THREAD_RETURN_TYPE ThreaderCallback(void *arg)
#define ITK_THREAD_RETURN_TYPE
DomainPartitionerType::DomainType DomainType
virtual ~DomainThreader()
TDomainPartitioner DomainPartitionerType
void Execute(AssociateType *enclosingClass, const DomainType &domain)
SmartPointer< Self > Pointer
void operator=(const Self &)
DomainPartitionerType::Pointer m_DomainPartitioner
SmartPointer< const Self > ConstPointer
ThreadIdType m_NumberOfThreadsUsed
ThreadIdType GetMaximumNumberOfThreads() const
MultiThreader::Pointer m_MultiThreader
virtual void ThreadedExecution(const DomainType &subdomain, const ThreadIdType threadId)=0
Base class for most ITK classes.
Definition: itkObject.h:57
MultiThreader * GetMultiThreader() const
unsigned int ThreadIdType
Definition: itkIntTypes.h:159