ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDomainThreader.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkDomainThreader_h
00019 #define __itkDomainThreader_h
00020 
00021 #include "itkObject.h"
00022 #include "itkMultiThreader.h"
00023 
00024 namespace itk
00025 {
00026 
00065 template< class TDomainPartitioner, class TAssociate >
00066 class ITK_EXPORT DomainThreader: public Object
00067 {
00068 public:
00070   typedef DomainThreader             Self;
00071   typedef Object                     Superclass;
00072   typedef SmartPointer< Self >       Pointer;
00073   typedef SmartPointer< const Self > ConstPointer;
00074 
00075   typedef TDomainPartitioner                         DomainPartitionerType;
00076   typedef typename DomainPartitionerType::DomainType DomainType;
00077 
00078   typedef TAssociate AssociateType;
00079 
00081   itkTypeMacro( DomainThreader, Object );
00082 
00088   void Execute( AssociateType * enclosingClass, const DomainType & domain );
00089 
00091   itkSetObjectMacro(       DomainPartitioner, DomainPartitionerType );
00092   itkGetConstObjectMacro(  DomainPartitioner, DomainPartitionerType );
00094 
00097   itkGetConstMacro( NumberOfThreadsUsed, ThreadIdType );
00098 
00100   MultiThreader * GetMultiThreader() const;
00101 
00106   ThreadIdType GetMaximumNumberOfThreads() const;
00107   void SetMaximumNumberOfThreads( const ThreadIdType threads );
00109 
00110 protected:
00111   DomainThreader();
00112   virtual ~DomainThreader();
00113 
00116   virtual void DetermineNumberOfThreadsUsed();
00117 
00121   virtual void BeforeThreadedExecution(){}
00122 
00131   virtual void ThreadedExecution( const DomainType& subdomain,
00132                                   const ThreadIdType threadId ) = 0;
00133 
00137   virtual void AfterThreadedExecution(){}
00138 
00139   itkSetObjectMacro( MultiThreader, MultiThreader );
00140 
00144   static ITK_THREAD_RETURN_TYPE ThreaderCallback( void *arg );
00145 
00146   AssociateType * m_Associate;
00147 
00148 private:
00149   DomainThreader( const Self & ); // purposely not implemented
00150   void operator=( const Self & ); // purposely not implemented
00151 
00152   void StartThreadingSequence();
00153 
00155   struct ThreadStruct
00156     {
00157     DomainThreader     * domainThreader;
00158     };
00159 
00164   ThreadIdType                             m_NumberOfThreadsUsed;
00165   typename DomainPartitionerType::Pointer  m_DomainPartitioner;
00166   DomainType                               m_CompleteDomain;
00167   MultiThreader::Pointer                   m_MultiThreader;
00168 };
00169 
00170 }
00171 
00172 #ifndef ITK_MANUAL_INSTANTIATION
00173 #include "itkDomainThreader.hxx"
00174 #endif
00175 
00176 #endif
00177