go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkComputeDisplacementDistribution.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright UMC Utrecht and contributors
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 __itkComputeDisplacementDistribution_h
19 #define __itkComputeDisplacementDistribution_h
20 
22 
23 #include "itkImageGridSampler.h"
26 #include "itkImageFullSampler.h"
27 #include "itkMultiThreader.h"
28 
29 namespace itk
30 {
45 template< class TFixedImage, class TTransform >
48 {
49 public:
50 
55  typedef SmartPointer< const Self > ConstPointer;
56 
58  itkNewMacro( Self );
59 
61  itkTypeMacro( ComputeDisplacementDistribution,
63 
65  typedef TFixedImage FixedImageType;
66  typedef typename FixedImageType::PixelType FixedImagePixelType;
67  typedef TTransform TransformType;
68  typedef typename TransformType::Pointer TransformPointer;
69  typedef typename FixedImageType::RegionType FixedImageRegionType;
73 
77  itkStaticConstMacro( FixedImageDimension, unsigned int,
78  TFixedImage::ImageDimension );
79  typedef SpatialObject< itkGetStaticConstMacro( FixedImageDimension ) > FixedImageMaskType;
80  typedef typename FixedImageMaskType::Pointer FixedImageMaskPointer;
81  typedef typename FixedImageMaskType::ConstPointer FixedImageMaskConstPointer;
82  typedef typename TransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType;
83 
85  itkSetConstObjectMacro( FixedImage, FixedImageType );
86 
88  itkSetObjectMacro( Transform, TransformType );
89 
91  itkSetObjectMacro( FixedImageMask, FixedImageMaskType );
92  itkSetConstObjectMacro( FixedImageMask, FixedImageMaskType );
93  itkGetConstObjectMacro( FixedImageMask, FixedImageMaskType );
94 
96  itkSetMacro( NumberOfJacobianMeasurements, SizeValueType );
97 
99  void SetFixedImageRegion( const FixedImageRegionType & region )
100  {
101  if( region != this->m_FixedImageRegion )
102  {
103  this->m_FixedImageRegion = region;
104  }
105  }
106 
107 
109  itkGetConstReferenceMacro( FixedImageRegion, FixedImageRegionType );
110 
112  virtual void Compute( const ParametersType & mu,
113  double & jacg, double & maxJJ, std::string method );
114 
116  virtual void ComputeSingleThreaded( const ParametersType & mu,
117  double & jacg, double & maxJJ, std::string method );
118 
119  virtual void ComputeUsingSearchDirection( const ParametersType & mu,
120  double & jacg, double & maxJJ, std::string methods );
121 
123  void SetNumberOfThreads( ThreadIdType numberOfThreads )
124  {
125  this->m_Threader->SetNumberOfThreads( numberOfThreads );
126  }
127 
128 
129  virtual void BeforeThreadedCompute( const ParametersType & mu );
130 
131  virtual void AfterThreadedCompute( double & jacg, double & maxJJ );
132 
133 protected:
134 
137 
139  typedef itk::MultiThreader ThreaderType;
140  typedef ThreaderType::ThreadInfoStruct ThreadInfoType;
141 
142  typename FixedImageType::ConstPointer m_FixedImage;
143  FixedImageRegionType m_FixedImageRegion;
144  FixedImageMaskConstPointer m_FixedImageMask;
145  TransformPointer m_Transform;
148  DerivativeType m_ExactGradient;
149  SizeValueType m_NumberOfParameters;
150  ThreaderType::Pointer m_Threader;
151 
152  typedef typename FixedImageType::IndexType FixedImageIndexType;
153  typedef typename FixedImageType::PointType FixedImagePointType;
154  typedef typename TransformType::JacobianType JacobianType;
155  typedef typename JacobianType::ValueType JacobianValueType;
156 
160 
163 
166 
169  typedef typename ImageGridSamplerType
171  typedef typename ImageSampleContainerType::Pointer ImageSampleContainerPointer;
172 
174  typedef JacobianType TransformJacobianType;
175  typedef typename TransformType::ScalarType CoordinateRepresentationType;
176  typedef typename TransformType::NumberOfParametersType NumberOfParametersType;
177 
179  // \todo: note that this is an exact copy of itk::ComputeJacobianTerms
180  // in the future it would be better to refactoring this part of the code
182  ImageSampleContainerPointer & sampleContainer );
183 
185  void LaunchComputeThreaderCallback( void ) const;
186 
188  static ITK_THREAD_RETURN_TYPE ComputeThreaderCallback( void * arg );
189 
191  virtual inline void ThreadedCompute( ThreadIdType threadID );
192 
194  virtual void InitializeThreadingParameters( void );
195 
200  {
201  // To give the threads access to all member variables and functions.
202  Self * st_Self;
203  };
205 
207  {
208  // Used for accumulating derivatives
209  double st_MaxJJ;
213  };
214  itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct,
215  PaddedComputePerThreadStruct );
216  itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct,
217  AlignedComputePerThreadStruct );
218  mutable AlignedComputePerThreadStruct * m_ComputePerThreadVariables;
220 
221  SizeValueType m_NumberOfPixelsCounted;
223  ScalesType m_Scales;
224  ImageSampleContainerPointer m_SampleContainer;
225 
226 private:
227 
228  ComputeDisplacementDistribution( const Self & ); // purposely not implemented
229  void operator=( const Self & ); // purposely not implemented
230 
231 };
232 
233 } // end namespace itk
234 
235 #ifndef ITK_MANUAL_INSTANTIATION
236 #include "itkComputeDisplacementDistribution.hxx"
237 #endif
238 
239 #endif // end #ifndef __itkComputeDisplacementDistribution_h
virtual void ComputeSingleThreaded(const ParametersType &mu, double &jacg, double &maxJJ, std::string method)
ScaledSingleValuedNonLinearOptimizer Superclass
virtual void InitializeThreadingParameters(void)
static ITK_THREAD_RETURN_TYPE ComputeThreaderCallback(void *arg)
virtual void Compute(const ParametersType &mu, double &jacg, double &maxJJ, std::string method)
void LaunchComputeThreaderCallback(void) const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct)
virtual void AfterThreadedCompute(double &jacg, double &maxJJ)
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct)
Samples all voxels in the InputImageRegion.
ImageRandomSamplerBase< FixedImageType > ImageRandomSamplerBaseType
itkStaticConstMacro(FixedImageDimension, unsigned int, TFixedImage::ImageDimension)
virtual void SampleFixedImageForJacobianTerms(ImageSampleContainerPointer &sampleContainer)
ScaledSingleValuedCostFunction::Pointer m_CostFunction
This class is a base class for any image sampler.
TransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
ImageGridSamplerType ::ImageSampleContainerType ImageSampleContainerType
virtual void BeforeThreadedCompute(const ParametersType &mu)
ImageFullSampler< FixedImageType > ImageFullSamplerType
Superclass::ImageSampleContainerType ImageSampleContainerType
virtual void ComputeUsingSearchDirection(const ParametersType &mu, double &jacg, double &maxJJ, std::string methods)
void SetFixedImageRegion(const FixedImageRegionType &region)
FixedImageMaskType::ConstPointer FixedImageMaskConstPointer
virtual void ThreadedCompute(ThreadIdType threadID)
ImageSampleContainerType::Pointer ImageSampleContainerPointer
ImageRandomSamplerBaseType::Pointer ImageRandomSamplerBasePointer
This is a helper class for the automatic parameter estimation of the ASGD optimizer.
AlignedComputePerThreadStruct * m_ComputePerThreadVariables
void SetNumberOfThreads(ThreadIdType numberOfThreads)
SpatialObject< itkGetStaticConstMacro(FixedImageDimension) > FixedImageMaskType
ImageSamplerBase< FixedImageType > ImageSamplerBaseType
ImageGridSampler< FixedImageType > ImageGridSamplerType
This class is a base class for any image sampler that randomly picks samples.
Samples image voxels on a regular grid.
TransformType::NumberOfParametersType NumberOfParametersType


Generated on OURCE_DATE_EPOCH for elastix by doxygen 1.8.13 elastix logo