go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
itkAdvancedImageToImageMetric.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 __itkAdvancedImageToImageMetric_h
19#define __itkAdvancedImageToImageMetric_h
20
21#include "itkImageToImageMetric.h"
22
23#include "itkImageSamplerBase.h"
24#include "itkGradientImageFilter.h"
25#include "itkBSplineInterpolateImageFunction.h"
29#include "itkFixedArray.h"
31#include "vnl/vnl_sparse_matrix.h"
32
33#include "itkImageMaskSpatialObject.h"
34
35// Needed for checking for B-spline for faster implementation
38
39#include "itkPlatformMultiThreader.h"
40
41namespace itk
42{
43
80template< class TFixedImage, class TMovingImage >
82 public ImageToImageMetric< TFixedImage, TMovingImage >
83{
84public:
85
88 typedef ImageToImageMetric< TFixedImage, TMovingImage > Superclass;
90 typedef SmartPointer< const Self > ConstPointer;
91
93 itkTypeMacro( AdvancedImageToImageMetric, ImageToImageMetric );
94
96 itkStaticConstMacro( MovingImageDimension, unsigned int,
97 TMovingImage::ImageDimension );
98 itkStaticConstMacro( FixedImageDimension, unsigned int,
99 TFixedImage::ImageDimension );
100
102 typedef typename Superclass::CoordinateRepresentationType CoordinateRepresentationType;
103 typedef typename Superclass::MovingImageType MovingImageType;
104 typedef typename Superclass::MovingImagePixelType MovingImagePixelType;
105 typedef typename MovingImageType::Pointer MovingImagePointer;
106 typedef typename Superclass::MovingImageConstPointer MovingImageConstPointer;
107 typedef typename Superclass::FixedImageType FixedImageType;
108 typedef typename FixedImageType::Pointer FixedImagePointer;
109 typedef typename Superclass::FixedImageConstPointer FixedImageConstPointer;
110 typedef typename Superclass::FixedImageRegionType FixedImageRegionType;
111 typedef typename Superclass::TransformType TransformType;
112 typedef typename Superclass::TransformPointer TransformPointer;
113 typedef typename Superclass::InputPointType InputPointType;
114 typedef typename Superclass::OutputPointType OutputPointType;
115 typedef typename Superclass::TransformParametersType TransformParametersType;
116 typedef typename Superclass::TransformJacobianType TransformJacobianType;
117 typedef typename Superclass::InterpolatorType InterpolatorType;
118 typedef typename Superclass::InterpolatorPointer InterpolatorPointer;
119 typedef typename Superclass::RealType RealType;
120 typedef typename Superclass::GradientPixelType GradientPixelType;
121 typedef typename Superclass::GradientImageType GradientImageType;
122 typedef typename Superclass::GradientImagePointer GradientImagePointer;
123 typedef typename Superclass::GradientImageFilterType GradientImageFilterType;
124 typedef typename Superclass::GradientImageFilterPointer GradientImageFilterPointer;
125 typedef typename Superclass::FixedImageMaskType FixedImageMaskType;
126 typedef typename Superclass::FixedImageMaskPointer FixedImageMaskPointer;
127 typedef typename Superclass::MovingImageMaskType MovingImageMaskType;
128 typedef typename Superclass::MovingImageMaskPointer MovingImageMaskPointer;
129 typedef typename Superclass::MeasureType MeasureType;
130 typedef typename Superclass::DerivativeType DerivativeType;
131 typedef typename DerivativeType::ValueType DerivativeValueType;
132 typedef typename Superclass::ParametersType ParametersType;
133
134 typedef ImageMaskSpatialObject< itkGetStaticConstMacro( FixedImageDimension ) > FixedImageMaskSpatialObject2Type;
135 typedef ImageMaskSpatialObject< itkGetStaticConstMacro( MovingImageDimension ) > MovingImageMaskSpatialObject2Type;
136
138 typedef typename FixedImageType::PixelType FixedImagePixelType;
139 typedef typename MovingImageType::RegionType MovingImageRegionType;
141
147
155
157 typedef typename TransformType::ScalarType ScalarType;
158 typedef AdvancedTransform<
159 ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType;
161
170
172 typedef typename DerivativeType::ValueType HessianValueType;
173 typedef vnl_sparse_matrix< HessianValueType > HessianType;
174
176 typedef itk::PlatformMultiThreader ThreaderType;
177 typedef typename ThreaderType::WorkUnitInfo ThreadInfoType;
178
183 {
184 this->Superclass::SetTransform( arg );
185 if( this->m_AdvancedTransform != arg )
186 {
187 this->m_AdvancedTransform = arg;
188 this->Modified();
189 }
190 }
191
192
194 const AdvancedTransformType * GetTransform( void ) const override
195 {
196 return this->m_AdvancedTransform.GetPointer();
197 }
198
199
201 itkSetObjectMacro( ImageSampler, ImageSamplerType );
202 virtual ImageSamplerType * GetImageSampler( void ) const
203 {
204 return this->m_ImageSampler.GetPointer();
205 }
206
207
210 itkGetConstMacro( UseImageSampler, bool );
211
215 itkSetMacro( RequiredRatioOfValidSamples, double );
216 itkGetConstMacro( RequiredRatioOfValidSamples, double );
217
220 itkSetObjectMacro( MovingImageLimiter, MovingImageLimiterType );
221 itkGetConstObjectMacro( MovingImageLimiter, MovingImageLimiterType );
222 itkSetObjectMacro( FixedImageLimiter, FixedImageLimiterType );
223 itkGetConstObjectMacro( FixedImageLimiter, FixedImageLimiterType );
224
231 itkSetMacro( MovingLimitRangeRatio, double );
232 itkGetConstMacro( MovingLimitRangeRatio, double );
233 itkSetMacro( FixedLimitRangeRatio, double );
234 itkGetConstMacro( FixedLimitRangeRatio, double );
235
238 itkGetConstMacro( UseFixedImageLimiter, bool );
239 itkGetConstMacro( UseMovingImageLimiter, bool );
240
248 itkSetMacro( UseMovingImageDerivativeScales, bool );
249 itkGetConstMacro( UseMovingImageDerivativeScales, bool );
250
251 itkSetMacro( ScaleGradientWithRespectToMovingImageOrientation, bool );
252 itkGetConstMacro( ScaleGradientWithRespectToMovingImageOrientation, bool );
253
254 itkSetMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
255 itkGetConstReferenceMacro( MovingImageDerivativeScales, MovingImageDerivativeScalesType );
256
265 void Initialize( void ) override;
266
270 virtual void GetSelfHessian( const TransformParametersType & parameters, HessianType & H ) const;
271
273 virtual void SetNumberOfWorkUnits( ThreadIdType numberOfThreads );
274
276 itkSetMacro( UseMetricSingleThreaded, bool );
277 itkGetConstReferenceMacro( UseMetricSingleThreaded, bool );
278 itkBooleanMacro( UseMetricSingleThreaded );
279
281 // \todo: maybe these can be united, check base class.
282 itkSetMacro( UseMultiThread, bool );
283 itkGetConstReferenceMacro( UseMultiThread, bool );
284 itkBooleanMacro( UseMultiThread );
285
292 const TransformParametersType & parameters ) const;
293
294protected:
295
298
301
303 void PrintSelf( std::ostream & os, Indent indent ) const override;
304
308 typedef typename FixedImageType::IndexType FixedImageIndexType;
309 typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
310 typedef typename MovingImageType::IndexType MovingImageIndexType;
311 typedef typename TransformType::InputPointType FixedImagePointType;
312 typedef typename TransformType::OutputPointType MovingImagePointType;
313 typedef typename InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType;
314
316 typedef BSplineInterpolateImageFunction<
318 typedef typename BSplineInterpolatorType::Pointer BSplineInterpolatorPointer;
319 typedef BSplineInterpolateImageFunction<
321 typedef typename BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer;
328 typedef typename BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType;
329 typedef GradientImageFilter<
331 typedef typename CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer;
332
334 typedef typename
336
343
353
355
360
372
376 virtual inline void ThreadedGetValue( ThreadIdType threadID ){}
377
379 virtual inline void AfterThreadedGetValue( MeasureType & value ) const {}
380
382 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueThreaderCallback( void * arg );
383
386
388 virtual inline void ThreadedGetValueAndDerivative(
389 ThreadIdType threadID ){}
390
393 MeasureType & value, DerivativeType & derivative ) const {}
394
396 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueAndDerivativeThreaderCallback( void * arg );
397
400
402 static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION AccumulateDerivativesThreaderCallback( void * arg );
403
408
413 {
414 // To give the threads access to all members.
416 // Used for accumulating derivatives
419 };
421
431 // test per thread struct with padding and alignment
433 {
436 };
437 itkPadStruct( ITK_CACHE_LINE_ALIGNMENT, GetValuePerThreadStruct,
438 PaddedGetValuePerThreadStruct );
439 itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct,
440 AlignedGetValuePerThreadStruct );
441 mutable AlignedGetValuePerThreadStruct * m_GetValuePerThreadVariables;
443
444 // test per thread struct with padding and alignment
446 {
450 };
452 PaddedGetValueAndDerivativePerThreadStruct );
453 itkAlignedTypedef( ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct,
454 AlignedGetValueAndDerivativePerThreadStruct );
455 mutable AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables;
457
459 virtual void InitializeThreadingParameters( void ) const;
460
466 virtual void InitializeImageSampler( void );
467
470 itkSetMacro( UseImageSampler, bool );
471
475 unsigned long wanted, unsigned long found ) const;
476
481 virtual void CheckForBSplineInterpolator( void );
482
492 const MovingImagePointType & mappedPoint,
493 RealType & movingImageValue,
494 MovingImageDerivativeType * gradient ) const;
495
501 const TransformJacobianType & jacobian,
502 const MovingImageDerivativeType & movingImageDerivative,
503 DerivativeType & imageJacobian ) const;
504
511 virtual void CheckForAdvancedTransform( void );
512
514 virtual void CheckForBSplineTransform( void ) const;
515
520 virtual bool TransformPoint(
521 const FixedImagePointType & fixedImagePoint,
522 MovingImagePointType & mappedPoint ) const;
523
531 const FixedImagePointType & fixedImagePoint,
532 TransformJacobianType & jacobian,
533 NonZeroJacobianIndicesType & nzji ) const;
534
536 virtual bool IsInsideMovingMask( const MovingImagePointType & point ) const;
537
540 virtual void InitializeLimiters( void );
541
544 itkSetMacro( UseFixedImageLimiter, bool );
545 itkSetMacro( UseMovingImageLimiter, bool );
546
549
550private:
551
552 AdvancedImageToImageMetric( const Self & ); // purposely not implemented
553 void operator=( const Self & ); // purposely not implemented
554
562
564
565};
566
567} // end namespace itk
568
569#ifndef ITK_MANUAL_INSTANTIATION
570#include "itkAdvancedImageToImageMetric.hxx"
571#endif
572
573#endif // end #ifndef __itkAdvancedImageToImageMetric_h
Deformable transform using a B-spline representation.
This class combines two transforms: an 'initial transform' with a 'current transform'.
An extension of the ITK ImageToImageMetric. It is the intended base class for all elastix metrics.
ReducedDimensionBSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > ReducedBSplineInterpolatorType
MovingImageDerivativeScalesType m_MovingImageDerivativeScales
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, double > BSplineInterpolatorType
itkStaticConstMacro(MovingImageDimension, unsigned int, TMovingImage::ImageDimension)
MovingImageLimiterOutputType m_MovingImageMaxLimit
Superclass::FixedImageConstPointer FixedImageConstPointer
AdvancedCombinationTransform< ScalarType, FixedImageDimension > CombinationTransformType
virtual void CheckForBSplineTransform(void) const
MovingImageLimiterType::Pointer MovingImageLimiterPointer
Superclass::TransformParametersType TransformParametersType
Superclass::MovingImageConstPointer MovingImageConstPointer
virtual void CheckForBSplineInterpolator(void)
virtual bool IsInsideMovingMask(const MovingImagePointType &point) const
FixedImageLimiterType::Pointer FixedImageLimiterPointer
Superclass::FixedImageMaskPointer FixedImageMaskPointer
InterpolatorType::ContinuousIndexType MovingImageContinuousIndexType
Superclass::GradientImageFilterPointer GradientImageFilterPointer
void PrintSelf(std::ostream &os, Indent indent) const override
virtual bool EvaluateTransformJacobian(const FixedImagePointType &fixedImagePoint, TransformJacobianType &jacobian, NonZeroJacobianIndicesType &nzji) const
virtual void InitializeImageSampler(void)
virtual void InitializeThreadingParameters(void) const
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValuePerThreadStruct, AlignedGetValuePerThreadStruct)
virtual bool EvaluateMovingImageValueAndDerivative(const MovingImagePointType &mappedPoint, RealType &movingImageValue, MovingImageDerivativeType *gradient) const
Superclass::GradientImageFilterType GradientImageFilterType
ImageMaskSpatialObject< itkGetStaticConstMacro(MovingImageDimension) > MovingImageMaskSpatialObject2Type
BSplineOrder2TransformType::Pointer BSplineOrder2TransformPointer
AdvancedTransformType::Pointer m_AdvancedTransform
Superclass::TransformJacobianType TransformJacobianType
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 2 > BSplineOrder2TransformType
AlignedGetValueAndDerivativePerThreadStruct * m_GetValueAndDerivativePerThreadVariables
FixedArray< double, Self::MovingImageDimension > MovingImageDerivativeScalesType
Superclass::GradientImagePointer GradientImagePointer
AdvancedTransform< ScalarType, FixedImageDimension, MovingImageDimension > AdvancedTransformType
Superclass::TransformPointer TransformPointer
virtual void AfterThreadedGetValue(MeasureType &value) const
ImageSamplerType::OutputVectorContainerPointer ImageSampleContainerPointer
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 1 > BSplineOrder1TransformType
AdvancedTransformType::NonZeroJacobianIndicesType NonZeroJacobianIndicesType
ImageSamplerBase< FixedImageType > ImageSamplerType
Superclass::CoordinateRepresentationType CoordinateRepresentationType
ImageSamplerType::OutputVectorContainerType ImageSampleContainerType
Superclass::InterpolatorPointer InterpolatorPointer
Superclass::MovingImageMaskPointer MovingImageMaskPointer
void LaunchGetValueThreaderCallback(void) const
virtual void SetTransform(AdvancedTransformType *arg)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueAndDerivativeThreaderCallback(void *arg)
virtual void ThreadedGetValue(ThreadIdType threadID)
TransformType::InputPointType FixedImagePointType
CentralDifferenceGradientFilterPointer m_CentralDifferenceGradientFilter
BSplineInterpolatorFloatType::Pointer BSplineInterpolatorFloatPointer
BSplineInterpolatorFloatPointer m_BSplineInterpolatorFloat
Superclass::MovingImageMaskType MovingImageMaskType
Superclass::GradientPixelType GradientPixelType
void operator=(const Self &)
virtual void ThreadedGetValueAndDerivative(ThreadIdType threadID)
AlignedGetValuePerThreadStruct * m_GetValuePerThreadVariables
ReducedBSplineInterpolatorType::Pointer ReducedBSplineInterpolatorPointer
virtual void CheckNumberOfSamples(unsigned long wanted, unsigned long found) const
BSplineOrder3TransformType::Pointer BSplineOrder3TransformPointer
MovingImageType::IndexType MovingImageIndexType
MovingImageType::RegionType MovingImageRegionType
void LaunchGetValueAndDerivativeThreaderCallback(void) const
virtual void BeforeThreadedGetValueAndDerivative(const TransformParametersType &parameters) const
FixedImageLimiterType::OutputType FixedImageLimiterOutputType
BSplineInterpolatorPointer m_BSplineInterpolator
FixedImageIndexType::IndexValueType FixedImageIndexValueType
ImageToImageMetric< TFixedImage, TMovingImage > Superclass
Superclass::MovingImagePixelType MovingImagePixelType
MovingImageLimiterOutputType m_MovingImageMinLimit
MovingImageLimiterType::OutputType MovingImageLimiterOutputType
BSplineOrder1TransformType::Pointer BSplineOrder1TransformPointer
LinearInterpolatorType::Pointer LinearInterpolatorPointer
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedGetValueAndDerivativePerThreadStruct, AlignedGetValueAndDerivativePerThreadStruct)
virtual ImageSamplerType * GetImageSampler(void) const
GradientImageFilter< MovingImageType, RealType, RealType > CentralDifferenceGradientFilterType
LimiterFunctionBase< RealType, MovingImageDimension > MovingImageLimiterType
ImageMaskSpatialObject< itkGetStaticConstMacro(FixedImageDimension) > FixedImageMaskSpatialObject2Type
BSplineInterpolatorType::CovariantVectorType MovingImageDerivativeType
virtual void CheckForAdvancedTransform(void)
FixedImageLimiterOutputType m_FixedImageMinLimit
Superclass::FixedImageMaskType FixedImageMaskType
AdvancedLinearInterpolateImageFunction< MovingImageType, CoordinateRepresentationType > LinearInterpolatorType
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValuePerThreadStruct, PaddedGetValuePerThreadStruct)
virtual void AfterThreadedGetValueAndDerivative(MeasureType &value, DerivativeType &derivative) const
Superclass::GradientImageType GradientImageType
const AdvancedTransformType * GetTransform(void) const override
CentralDifferenceGradientFilterType::Pointer CentralDifferenceGradientFilterPointer
ReducedBSplineInterpolatorPointer m_ReducedBSplineInterpolator
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION AccumulateDerivativesThreaderCallback(void *arg)
Superclass::InterpolatorType InterpolatorType
virtual void EvaluateTransformJacobianInnerProduct(const TransformJacobianType &jacobian, const MovingImageDerivativeType &movingImageDerivative, DerivativeType &imageJacobian) const
FixedImageLimiterOutputType m_FixedImageMaxLimit
AdvancedImageToImageMetric(const Self &)
TransformType::OutputPointType MovingImagePointType
vnl_sparse_matrix< HessianValueType > HessianType
void Initialize(void) override
itkStaticConstMacro(FixedImageDimension, unsigned int, TFixedImage::ImageDimension)
LimiterFunctionBase< RealType, FixedImageDimension > FixedImageLimiterType
BSplineInterpolatorType::Pointer BSplineInterpolatorPointer
virtual void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
Superclass::FixedImageRegionType FixedImageRegionType
AdvancedTransformType::NumberOfParametersType NumberOfParametersType
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION GetValueThreaderCallback(void *arg)
virtual void InitializeLimiters(void)
AdvancedBSplineDeformableTransform< ScalarType, FixedImageDimension, 3 > BSplineOrder3TransformType
virtual bool TransformPoint(const FixedImagePointType &fixedImagePoint, MovingImagePointType &mappedPoint) const
BSplineInterpolateImageFunction< MovingImageType, CoordinateRepresentationType, float > BSplineInterpolatorFloatType
virtual void GetSelfHessian(const TransformParametersType &parameters, HessianType &H) const
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, GetValueAndDerivativePerThreadStruct, PaddedGetValueAndDerivativePerThreadStruct)
MultiThreaderParameterType m_ThreaderMetricParameters
Linearly interpolate an image at specified positions.
Transform maps points, vectors and covariant vectors from an input space to an output space.
SmartPointer< Self > Pointer
Superclass::NumberOfParametersType NumberOfParametersType
std::vector< unsigned long > NonZeroJacobianIndicesType
This class is a base class for any image sampler.
SmartPointer< Self > Pointer
Base class for all ITK limiter function objects.
SmartPointer< Self > Pointer
Superclass::OutputType OutputType
Evaluates the B-Spline interpolation of an image. Spline order may be from 0 to 5.
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.


Generated on 1667476801 for elastix by doxygen 1.9.4 elastix logo