ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkImageRegistrationMethodv4.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 itkImageRegistrationMethodv4_h
19 #define itkImageRegistrationMethodv4_h
20 
21 #include "itkProcessObject.h"
22 
23 #include "itkCompositeTransform.h"
24 #include "itkDataObjectDecorator.h"
30 #include "itkShrinkImageFilter.h"
31 #include "itkTransform.h"
33 
34 #include <vector>
35 
36 namespace itk
37 {
38 
89 template<typename TFixedImage,
90  typename TMovingImage,
91  typename TOutputTransform = Transform<double, TFixedImage::ImageDimension, TFixedImage::ImageDimension>,
92  typename TVirtualImage = TFixedImage,
93  typename TPointSet = PointSet<unsigned int, TFixedImage::ImageDimension> >
95 :public ProcessObject
96 {
97 public:
103 
105  itkNewMacro( Self );
106 
108  itkStaticConstMacro( ImageDimension, unsigned int, TFixedImage::ImageDimension );
109 
112 
114  typedef TFixedImage FixedImageType;
115  typedef typename FixedImageType::Pointer FixedImagePointer;
116  typedef std::vector<FixedImagePointer> FixedImagesContainerType;
117  typedef TMovingImage MovingImageType;
118  typedef typename MovingImageType::Pointer MovingImagePointer;
119  typedef std::vector<MovingImagePointer> MovingImagesContainerType;
120 
121  typedef TPointSet PointSetType;
122  typedef typename PointSetType::ConstPointer PointSetConstPointer;
123  typedef std::vector<PointSetConstPointer> PointSetsContainerType;
124 
126  typedef TOutputTransform OutputTransformType;
127  typedef typename OutputTransformType::Pointer OutputTransformPointer;
128  typedef typename OutputTransformType::ScalarType RealType;
129  typedef typename OutputTransformType::DerivativeType DerivativeType;
130  typedef typename DerivativeType::ValueType DerivativeValueType;
131 
134 
137 
140 
142 
143  typedef TVirtualImage VirtualImageType;
144  typedef typename VirtualImageType::Pointer VirtualImagePointer;
147 
151 
160 
163 
165 
168 
172  typedef std::vector<TransformParametersAdaptorPointer> TransformParametersAdaptorsContainerType;
173 
177 
180 
183 
185 
187  virtual void SetFixedImage( const FixedImageType *image )
188  {
189  this->SetFixedImage( 0, image );
190  }
191  virtual const FixedImageType * GetFixedImage() const
192  {
193  return this->GetFixedImage( 0 );
194  }
195  virtual void SetFixedImage( SizeValueType, const FixedImageType * );
196  virtual const FixedImageType * GetFixedImage( SizeValueType ) const;
198 
200  virtual void SetMovingImage( const MovingImageType *image )
201  {
202  this->SetMovingImage( 0, image );
203  }
204  virtual const MovingImageType * GetMovingImage() const
205  {
206  return this->GetMovingImage( 0 );
207  }
208  virtual void SetMovingImage( SizeValueType, const MovingImageType * );
209  virtual const MovingImageType * GetMovingImage( SizeValueType ) const;
211 
213  virtual void SetFixedPointSet( const PointSetType *pointSet )
214  {
215  this->SetFixedPointSet( 0, pointSet );
216  }
217  virtual const PointSetType * GetFixedPointSet() const
218  {
219  return this->GetFixedPointSet( 0 );
220  }
221  virtual void SetFixedPointSet( SizeValueType, const PointSetType * );
222  virtual const PointSetType * GetFixedPointSet( SizeValueType ) const;
224 
226  virtual void SetMovingPointSet( const PointSetType *pointSet )
227  {
228  this->SetMovingPointSet( 0, pointSet );
229  }
230  virtual const PointSetType * GetMovingPointSet() const
231  {
232  return this->GetMovingPointSet( 0 );
233  }
234  virtual void SetMovingPointSet( SizeValueType, const PointSetType * );
235  virtual const PointSetType * GetMovingPointSet( SizeValueType ) const;
237 
239  itkSetObjectMacro( Optimizer, OptimizerType );
240  itkGetModifiableObjectMacro( Optimizer, OptimizerType );
242 
252  itkGetConstMacro( OptimizerWeights, OptimizerWeightsType );
254 
256  itkSetObjectMacro( Metric, MetricType );
257  itkGetModifiableObjectMacro( Metric, MetricType );
259 
261  itkSetMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
262  itkGetConstMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
264 
267 
269  itkSetMacro( MetricSamplingPercentagePerLevel, MetricSamplingPercentageArrayType );
270  itkGetConstMacro( MetricSamplingPercentagePerLevel, MetricSamplingPercentageArrayType );
272 
274  itkSetGetDecoratedObjectInputMacro( FixedInitialTransform, InitialTransformType );
275 
277  itkSetGetDecoratedObjectInputMacro( MovingInitialTransform, InitialTransformType );
278 
294  itkSetGetDecoratedObjectInputMacro(InitialTransform, InitialTransformType);
295 
300 
308  void SetNumberOfLevels( const SizeValueType );
309  itkGetConstMacro( NumberOfLevels, SizeValueType );
311 
320  {
321  for( unsigned int level = 0; level < factors.Size(); ++level )
322  {
324  shrinkFactors.Fill( factors[level] );
325  this->SetShrinkFactorsPerDimension( level, shrinkFactors );
326  }
327  }
329 
334  {
335  if( level >= this->m_ShrinkFactorsPerLevel.size() )
336  {
337  itkExceptionMacro( "Requesting level greater than the number of levels." );
338  }
339  return this->m_ShrinkFactorsPerLevel[level];
340  }
342 
347  {
348  if( level >= this->m_ShrinkFactorsPerLevel.size() )
349  {
350  this->m_ShrinkFactorsPerLevel.resize( level + 1 );
351  }
352  this->m_ShrinkFactorsPerLevel[level] = factors;
353  this->Modified();
354  }
356 
362  itkSetMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
363  itkGetConstMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
365 
370  itkSetMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
371  itkGetConstMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
372  itkBooleanMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits );
374 
379 
382  virtual const DecoratedOutputTransformType * GetOutput() const;
384 
386  virtual const DecoratedOutputTransformType * GetTransformOutput() const { return this->GetOutput(); }
387 
389  virtual const OutputTransformType * GetTransform() const;
390 
392  itkGetConstMacro( CurrentLevel, SizeValueType );
393 
395  itkGetConstReferenceMacro( CurrentIteration, SizeValueType );
396 
397  /* Get the current metric value. This is a helper function for reporting observations. */
398  itkGetConstReferenceMacro( CurrentMetricValue, RealType );
399 
401  itkGetConstReferenceMacro( CurrentConvergenceValue, RealType );
402 
404  itkGetConstReferenceMacro( IsConverged, bool );
405 
409  itkSetMacro( InPlace, bool );
410  itkGetConstMacro( InPlace, bool );
411  itkBooleanMacro( InPlace );
413 
419  itkBooleanMacro( InitializeCenterOfLinearOutputTransform );
420  itkSetMacro( InitializeCenterOfLinearOutputTransform, bool );
421  itkGetConstMacro( InitializeCenterOfLinearOutputTransform, bool );
423 
437 
438 #ifdef ITKV3_COMPATIBILITY
439 
454  void StartRegistration(void) { this->Update(); }
455 #endif
456 
457 protected:
459  virtual ~ImageRegistrationMethodv4();
460  virtual void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
461 
463  virtual void GenerateData() ITK_OVERRIDE;
464 
465  virtual void AllocateOutputs();
466 
468  virtual void InitializeRegistrationAtEachLevel( const SizeValueType );
469 
472 
474  virtual void SetMetricSamplePoints();
475 
476  SizeValueType m_CurrentLevel;
477  SizeValueType m_NumberOfLevels;
478  SizeValueType m_CurrentIteration;
482 
488  SizeValueType m_NumberOfFixedObjects;
489  SizeValueType m_NumberOfMovingObjects;
490 
494 
498  SizeValueType m_NumberOfMetrics;
503 
505 
507 
508  //TODO: m_OutputTransform should be removed and replaced with a named input parameter for
509  // the pipeline
511 
512 
513 private:
514  ImageRegistrationMethodv4( const Self & ); //purposely not implemented
515  void operator=( const Self & ); //purposely not implemented
516 
517  bool m_InPlace;
518 
520 
521  // helper function to create the right kind of concrete transform
522  template<typename TTransform>
523  static void MakeOutputTransform(SmartPointer<TTransform> &ptr)
524  {
525  ptr = TTransform::New();
526  }
527 
529  {
531  }
532 
533 };
534 } // end namespace itk
535 
536 #ifndef ITK_MANUAL_INSTANTIATION
537 #include "itkImageRegistrationMethodv4.hxx"
538 #endif
539 
540 #endif
virtual void Update()
Bring this filter up-to-date.
virtual OutputTransformType * GetModifiableTransform()
Transform< RealType, ImageDimension, ImageDimension > InitialTransformType
ImageMetricType::FixedSampledPointSetType MetricSamplePointSetType
Light weight base class for most itk classes.
virtual DecoratedOutputTransformType * GetTransformOutput()
ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
virtual void SetMovingImage(const MovingImageType *image)
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual void SetMovingPointSet(const PointSetType *pointSet)
DerivativeType::ValueType DerivativeValueType
This class takes one ore more ObjectToObject metrics and assigns weights to their derivatives to comp...
virtual const PointSetType * GetFixedPointSet() const
ShrinkFilterType::ShrinkFactorsType ShrinkFactorsPerDimensionContainerType
Computes similarity between two point sets.
TransformParametersAdaptorType::Pointer TransformParametersAdaptorPointer
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
DecoratedInitialTransformType::Pointer DecoratedInitialTransformPointer
CompositeTransformType::Pointer CompositeTransformPointer
ObjectType * GetPointer() const
Base helper class intended for multi-resolution image registration.
Vector< RealType, ImageDimension > VectorType
Base class for all object-to-object similarlity metrics added in ITKv4.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void Fill(const ValueType &)
std::vector< ShrinkFactorsPerDimensionContainerType > m_ShrinkFactorsPerLevel
void SetShrinkFactorsPerLevel(ShrinkFactorsArrayType factors)
static Pointer New()
MetricSamplingPercentageArrayType m_MetricSamplingPercentagePerLevel
ImageToImageMetricv4< FixedImageType, MovingImageType, VirtualImageType, RealType > ImageMetricType
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType) override
Make a DataObject of the correct type to used as the specified output.
void SetMetricSamplingPercentage(const RealType)
virtual void SetFixedPointSet(const PointSetType *pointSet)
virtual void GenerateData() override
MovingImagesContainerType m_MovingSmoothImages
virtual void SetMetricSamplePoints()
static void MakeOutputTransform(SmartPointer< TTransform > &ptr)
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
ShrinkFactorsPerDimensionContainerType GetShrinkFactorsPerDimension(const unsigned int level) const
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual void InitializeRegistrationAtEachLevel(const SizeValueType)
virtual const FixedImageType * GetFixedImage() const
std::vector< TransformParametersAdaptorPointer > TransformParametersAdaptorsContainerType
This class contains a list of transforms and concatenates them by composition.
Decorates any subclass of itkObject with a DataObject API.
static void MakeOutputTransform(SmartPointer< InitialTransformType > &ptr)
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
InitialTransformType::Pointer InitialTransformPointer
Generic representation for an optimization method.
Definition: itkOptimizer.h:38
OptimizerType::ScalesType OptimizerWeightsType
DecoratedOutputTransformType::Pointer DecoratedOutputTransformPointer
void SetOptimizerWeights(OptimizerWeightsType &)
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
ObjectToObjectOptimizerBaseTemplate< RealType > OptimizerType
void SetTransformParametersAdaptorsPerLevel(TransformParametersAdaptorsContainerType &)
OutputTransformType::DerivativeType DerivativeType
virtual void Modified() const
TransformParametersAdaptorsContainerType m_TransformParametersAdaptorsPerLevel
CompositeTransformPointer m_CompositeTransform
virtual void SetFixedImage(const FixedImageType *image)
void SetShrinkFactorsPerDimension(unsigned int level, ShrinkFactorsPerDimensionContainerType factors)
PointSetType::ConstPointer PointSetConstPointer
TransformParametersAdaptorBase< InitialTransformType > TransformParametersAdaptorType
std::vector< MovingImagePointer > MovingImagesContainerType
ObjectToObjectMetricBaseTemplate< RealType > MetricType
MetricSamplingStrategyType m_MetricSamplingStrategy
Base class for templated image classes.
Definition: itkImageBase.h:112
const TransformParametersAdaptorsContainerType & GetTransformParametersAdaptorsPerLevel() const
DataObjectDecorator< InitialTransformType > DecoratedInitialTransformType
virtual const DecoratedOutputTransformType * GetTransformOutput() const
DataObjectDecorator< OutputTransformType > DecoratedOutputTransformType
ShrinkImageFilter< FixedImageType, VirtualImageType > ShrinkFilterType
Reduce the size of an image by an integer factor in each dimension.
SmoothingSigmasArrayType m_SmoothingSigmasPerLevel
SizeValueType Size(void) const
Definition: itkArray.h:124
virtual const PointSetType * GetMovingPointSet() const
std::vector< FixedImagePointer > FixedImagesContainerType
VirtualImageBaseType::ConstPointer VirtualImageBaseConstPointer
Interface method for the current registration framework.
virtual DecoratedOutputTransformType * GetOutput()
PointSetToPointSetMetricv4< PointSetType, PointSetType, RealType > PointSetMetricType
Abstract base for object-to-object optimizers.
CompositeTransform< RealType, ImageDimension > CompositeTransformType
void SetNumberOfLevels(const SizeValueType)
OutputTransformType::ScalarType RealType
std::vector< PointSetConstPointer > PointSetsContainerType
OutputTransformType::Pointer OutputTransformPointer
ObjectToObjectMultiMetricv4< ImageDimension, ImageDimension, VirtualImageType, RealType > MultiMetricType
ImageBase< ImageDimension > VirtualImageBaseType
virtual const MovingImageType * GetMovingImage() const
virtual const OutputTransformType * GetTransform() const
VirtualImageType::Pointer VirtualImagePointer
virtual VirtualImageBaseConstPointer GetCurrentLevelVirtualDomainImage()