Orfeo Toolbox  3.16
itkOptImageToImageMetric.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkOptImageToImageMetric.h,v $
5  Language: C++
6  Date: $Date: 2010-03-05 16:15:37 $
7  Version: $Revision: 1.34 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkOptImageToImageMetric_h
18 #define __itkOptImageToImageMetric_h
19 
21 #include "itkImageBase.h"
22 #include "itkTransform.h"
24 #include "itkExceptionObject.h"
26 #include "itkSpatialObject.h"
29 #include "itkCovariantVector.h"
30 
31 #include "itkMultiThreader.h"
32 
34 
35 namespace itk
36 {
37 
57 template <class TFixedImage, class TMovingImage>
58 class ITK_EXPORT ImageToImageMetric
59 : public SingleValuedCostFunction
60 {
61 public:
67 
70 
73 
75  typedef TMovingImage MovingImageType;
76  typedef typename TMovingImage::PixelType MovingImagePixelType;
77  typedef typename MovingImageType::ConstPointer MovingImageConstPointer;
78 
80  typedef TFixedImage FixedImageType;
81  typedef typename TFixedImage::PixelType FixedImagePixelType;
82  typedef typename FixedImageType::ConstPointer FixedImageConstPointer;
83  typedef typename FixedImageType::RegionType FixedImageRegionType;
84 
86  itkStaticConstMacro(MovingImageDimension,
87  unsigned int,
88  TMovingImage::ImageDimension);
89  itkStaticConstMacro(FixedImageDimension,
90  unsigned int,
91  TFixedImage::ImageDimension);
92 
95  itkGetStaticConstMacro(MovingImageDimension),
96  itkGetStaticConstMacro(FixedImageDimension)>
98 
104 
106  typedef typename FixedImageType::IndexType FixedImageIndexType;
107  typedef typename FixedImageIndexType::IndexValueType FixedImageIndexValueType;
108  typedef typename MovingImageType::IndexType MovingImageIndexType;
111 
112  typedef std::vector<FixedImageIndexType> FixedImageIndexContainer;
113 
118 
122  typedef CovariantVector<RealType,
123  itkGetStaticConstMacro(MovingImageDimension)>
125  typedef Image<GradientPixelType,
126  itkGetStaticConstMacro(MovingImageDimension)>
133 
134 
136 
137 
144 
151 
152 
155 
158 
161 
163  itkSetConstObjectMacro( FixedImage, FixedImageType );
164 
166  itkGetConstObjectMacro( FixedImage, FixedImageType );
167 
169  itkSetConstObjectMacro( MovingImage, MovingImageType );
170 
172  itkGetConstObjectMacro( MovingImage, MovingImageType );
173 
175  itkSetObjectMacro( Transform, TransformType );
176 
178  itkGetConstObjectMacro( Transform, TransformType );
179 
181  itkSetObjectMacro( Interpolator, InterpolatorType );
182 
184  itkGetConstObjectMacro( Interpolator, InterpolatorType );
185 
187  unsigned long GetNumberOfMovingImageSamples( void )
188  {
189  return this->GetNumberOfPixelsCounted();
190  }
191  itkGetConstReferenceMacro( NumberOfPixelsCounted, unsigned long );
192 
194  void SetFixedImageRegion( const FixedImageRegionType reg );
195 
197  itkGetConstReferenceMacro( FixedImageRegion, FixedImageRegionType );
198 
200  itkSetObjectMacro( MovingImageMask, MovingImageMaskType );
201  itkSetConstObjectMacro( MovingImageMask, MovingImageMaskType );
202  itkGetConstObjectMacro( MovingImageMask, MovingImageMaskType );
203 
205  itkSetObjectMacro( FixedImageMask, FixedImageMaskType );
206  itkSetConstObjectMacro( FixedImageMask, FixedImageMaskType );
207  itkGetConstObjectMacro( FixedImageMask, FixedImageMaskType );
208 
211  void SetFixedImageIndexes( const FixedImageIndexContainer & indexes );
212  void SetUseFixedImageIndexes( bool useIndex );
213  itkGetConstReferenceMacro( UseFixedImageIndexes, bool );
214 
216  void SetNumberOfThreads( unsigned int numberOfThreads );
217  itkGetConstReferenceMacro( NumberOfThreads, unsigned int );
218 
220  itkSetMacro( ComputeGradient, bool );
221  itkGetConstReferenceMacro( ComputeGradient, bool );
222  itkBooleanMacro(ComputeGradient );
223 
225  virtual void ComputeGradient( void );
226 
228  itkGetConstObjectMacro( GradientImage, GradientImageType );
229 
231  void SetTransformParameters( const ParametersType & parameters ) const;
232 
234  unsigned int GetNumberOfParameters( void ) const
235  {
236  return m_Transform->GetNumberOfParameters();
237  }
238 
241  virtual void Initialize( void ) throw ( ExceptionObject );
242 
244  virtual void MultiThreadingInitialize( void ) throw ( ExceptionObject );
245 
248  virtual void SetNumberOfFixedImageSamples( unsigned long numSamples );
249  itkGetConstReferenceMacro( NumberOfFixedImageSamples, unsigned long );
250 
253  void SetNumberOfSpatialSamples( unsigned long num )
254  {
255  this->SetNumberOfFixedImageSamples( num );
256  }
257  unsigned long GetNumberOfSpatialSamples( void )
258  {
259  return this->GetNumberOfFixedImageSamples();
260  }
261 
264  void SetFixedImageSamplesIntensityThreshold( const FixedImagePixelType & thresh );
265  itkGetConstReferenceMacro( FixedImageSamplesIntensityThreshold, FixedImagePixelType );
266 
267  void SetUseFixedImageSamplesIntensityThreshold( bool useThresh );
268  itkGetConstReferenceMacro( UseFixedImageSamplesIntensityThreshold, bool );
269 
273  void SetUseAllPixels( bool useAllPixels );
274  void UseAllPixelsOn( void )
275  {
276  this->SetUseAllPixels( true );
277  }
278  void UseAllPixelsOff( void )
279  {
280  this->SetUseAllPixels( false );
281  }
282  itkGetConstReferenceMacro( UseAllPixels, bool );
283 
288  void SetUseSequentialSampling( bool sequentialSampling );
289  itkGetConstReferenceMacro( UseSequentialSampling, bool );
290 
300  void ReinitializeSeed();
301  void ReinitializeSeed( int seed );
302 
319  itkSetMacro(UseCachingOfBSplineWeights,bool);
320  itkGetConstReferenceMacro(UseCachingOfBSplineWeights,bool);
321  itkBooleanMacro(UseCachingOfBSplineWeights);
322 
325  itkGetConstObjectMacro( Threader, MultiThreaderType );
326  const TransformPointer* GetThreaderTransform()
327  {
328  return m_ThreaderTransform;
329  }
330 
331 protected:
333  virtual ~ImageToImageMetric();
334 
335  void PrintSelf(std::ostream& os, Indent indent) const;
336 
340 
342  {
343  public:
345  {
346  point.Fill(0.0);
347  value = 0;
348  valueIndex = 0;
349  }
350  ~FixedImageSamplePoint() {};
351 
352  public:
353  FixedImagePointType point;
354  double value;
355  unsigned int valueIndex;
356  };
358 
361 
364 
366  typedef std::vector<FixedImageSamplePoint> FixedImageSampleContainer;
367 
369  virtual void SampleFixedImageRegion( FixedImageSampleContainer & samples) const;
370 
371  virtual void SampleFixedImageIndexes( FixedImageSampleContainer &
372  samples) const;
373 
375  virtual void SampleFullFixedImageRegion( FixedImageSampleContainer &
376  samples) const;
377 
380 
381  unsigned long m_NumberOfParameters;
383 
385  //m_NumberOfPixelsCounted must be mutable because the const
386  //thread consolidation functions merge each threads valus
387  //onto this accumulator variable.
388  mutable unsigned long m_NumberOfPixelsCounted;
389 
390  FixedImageConstPointer m_FixedImage;
391  MovingImageConstPointer m_MovingImage;
392 
394  TransformPointer m_Transform;
398 
399  InterpolatorPointer m_Interpolator;
400 
401  bool m_ComputeGradient;
402  GradientImagePointer m_GradientImage;
403 
406 
407  unsigned int m_NumberOfThreads;
408 
411 
413 
415 
424 
427  unsigned long m_NumBSplineWeights;
428 
429  itkStaticConstMacro(DeformationSplineOrder, unsigned int, 3 );
430 
433  itkGetStaticConstMacro(DeformationSplineOrder) > BSplineTransformType;
434 
438 
443 
444  typedef std::vector<MovingImagePointType> MovingImagePointArrayType;
445  typedef std::vector<bool> BooleanArrayType;
446  typedef FixedArray< unsigned long,
448  ::ImageDimension > BSplineParametersOffsetType;
461  typedef CovariantVector< double,
462  itkGetStaticConstMacro(MovingImageDimension) >
464 
465 
467 
472 
474 
475  // Variables needed for optionally caching values when using a BSpline transform.
479 
482 
483  virtual void PreComputeTransformValues( void );
484 
487  virtual void TransformPoint( unsigned int sampleNumber,
488  MovingImagePointType& mappedPoint,
489  bool& sampleWithinSupportRegion,
490  double& movingImageValue,
491  unsigned int threadID ) const;
492 
493  virtual void TransformPointWithDerivatives( unsigned int sampleNumber,
494  MovingImagePointType& mappedPoint,
495  bool& sampleWithinSupportRegion,
496  double& movingImageValue,
497  ImageDerivativesType & gradient,
498  unsigned int threadID ) const;
499 
504 
507 
509  virtual void ComputeImageDerivatives( const MovingImagePointType & mappedPoint,
510  ImageDerivativesType & gradient,
511  unsigned int threadID ) const;
512 
513 
519  {
521  };
522 
525  mutable unsigned int * m_ThreaderNumberOfMovingImageSamples;
528 
529  void GetValueMultiThreadedPreProcessInitiate( void ) const;
530  void GetValueMultiThreadedInitiate( void ) const;
531  void GetValueMultiThreadedPostProcessInitiate( void ) const;
532  static ITK_THREAD_RETURN_TYPE GetValueMultiThreadedPreProcess( void * arg );
533  static ITK_THREAD_RETURN_TYPE GetValueMultiThreaded( void * arg );
534  static ITK_THREAD_RETURN_TYPE GetValueMultiThreadedPostProcess( void * arg );
535 
536  virtual inline void GetValueThread( unsigned int threadID ) const;
537  virtual inline void GetValueThreadPreProcess(
538  unsigned int itkNotUsed(threadID),
539  bool itkNotUsed(withinSampleThread) ) const
540  { };
541  virtual inline bool GetValueThreadProcessSample(
542  unsigned int itkNotUsed(threadID),
543  unsigned long itkNotUsed(fixedImageSample),
544  const MovingImagePointType & itkNotUsed(mappedPoint),
545  double itkNotUsed(movingImageValue)) const
546  { return false; };
547  virtual inline void GetValueThreadPostProcess(
548  unsigned int itkNotUsed(threadID),
549  bool itkNotUsed(withinSampleThread) ) const
550  { };
551 
552  void GetValueAndDerivativeMultiThreadedPreProcessInitiate( void ) const;
553  void GetValueAndDerivativeMultiThreadedInitiate( void ) const;
554  void GetValueAndDerivativeMultiThreadedPostProcessInitiate( void ) const;
555  static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeMultiThreadedPreProcess( void * arg );
556  static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeMultiThreaded(void * arg);
557  static ITK_THREAD_RETURN_TYPE GetValueAndDerivativeMultiThreadedPostProcess(void * arg);
558 
559  virtual inline void GetValueAndDerivativeThread(unsigned int threadID) const;
560  virtual inline void GetValueAndDerivativeThreadPreProcess(
561  unsigned int itkNotUsed(threadID),
562  bool itkNotUsed(withinSampleThread)) const
563  { };
564  virtual inline bool GetValueAndDerivativeThreadProcessSample(
565  unsigned int itkNotUsed(threadID),
566  unsigned long itkNotUsed(fixedImageSample),
567  const MovingImagePointType & itkNotUsed(mappedPoint),
568  double itkNotUsed(movingImageValue),
569  const ImageDerivativesType & itkNotUsed(movingImageGradientValue) ) const
570  { return false; }
571  virtual inline void GetValueAndDerivativeThreadPostProcess(
572  unsigned int itkNotUsed(threadID),
573  bool itkNotUsed(withinSampleThread) ) const
574  { };
575 
579  virtual void SynchronizeTransforms() const;
580 
581 private:
582  ImageToImageMetric(const Self&); //purposely not implemented
583  void operator=(const Self&); //purposely not implemented
584 
585  FixedImageRegionType m_FixedImageRegion;
586 
587 };
588 
589 } // end namespace itk
590 
591 #ifndef ITK_MANUAL_INSTANTIATION
593 #endif
594 
595 #endif

Generated at Sat May 18 2013 23:58:05 for Orfeo Toolbox with doxygen 1.8.3.1