ITK  4.6.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"
29 #include "itkShrinkImageFilter.h"
30 #include "itkTransform.h"
32 
33 #include <vector>
34 
35 namespace itk
36 {
37 
88 template<typename TFixedImage,
89  typename TMovingImage,
90  typename TOutputTransform=Transform<double, TFixedImage::ImageDimension, TFixedImage::ImageDimension >,
91  typename TVirtualImage = TFixedImage>
93 :public ProcessObject
94 {
95 public:
101 
103  itkNewMacro( Self );
104 
106  itkStaticConstMacro( ImageDimension, unsigned int, TFixedImage::ImageDimension );
107 
110 
112  typedef TFixedImage FixedImageType;
113  typedef typename FixedImageType::Pointer FixedImagePointer;
114  typedef std::vector<FixedImagePointer> FixedImagesContainerType;
115  typedef TMovingImage MovingImageType;
116  typedef typename MovingImageType::Pointer MovingImagePointer;
117  typedef std::vector<MovingImagePointer> MovingImagesContainerType;
118 
120  typedef TOutputTransform OutputTransformType;
121  typedef typename OutputTransformType::Pointer OutputTransformPointer;
122  typedef typename OutputTransformType::ScalarType RealType;
123  typedef typename OutputTransformType::DerivativeType DerivativeType;
124  typedef typename DerivativeType::ValueType DerivativeValueType;
125 
128 
131 
134 
135  typedef TVirtualImage VirtualImageType;
136 
139 
148 
149 
152 
154 
157 
161  typedef std::vector<TransformParametersAdaptorPointer> TransformParametersAdaptorsContainerType;
162 
166 
169 
172 
174 
176  virtual void SetFixedImage( const FixedImageType *image )
177  {
178  this->SetFixedImage( 0, image );
179  }
180  virtual const FixedImageType * GetFixedImage() const
181  {
182  return this->GetFixedImage( 0 );
183  }
184  virtual void SetFixedImage( SizeValueType, const FixedImageType * );
185  virtual const FixedImageType * GetFixedImage( SizeValueType ) const;
187 
189  virtual void SetMovingImage( const MovingImageType *image )
190  {
191  this->SetMovingImage( 0, image );
192  }
193  virtual const MovingImageType * GetMovingImage() const
194  {
195  return this->GetMovingImage( 0 );
196  }
197  virtual void SetMovingImage( SizeValueType, const MovingImageType * );
198  virtual const MovingImageType * GetMovingImage( SizeValueType ) const;
200 
202  itkSetObjectMacro( Optimizer, OptimizerType );
203  itkGetModifiableObjectMacro( Optimizer, OptimizerType );
205 
215  itkGetConstMacro( OptimizerWeights, OptimizerWeightsType );
217 
219  itkSetObjectMacro( Metric, MetricType );
220  itkGetModifiableObjectMacro( Metric, MetricType );
222 
224  itkSetMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
225  itkGetConstMacro( MetricSamplingStrategy, MetricSamplingStrategyType );
227 
230 
232  itkSetMacro( MetricSamplingPercentagePerLevel, MetricSamplingPercentageArrayType );
233  itkGetConstMacro( MetricSamplingPercentagePerLevel, MetricSamplingPercentageArrayType );
235 
238 
240  itkSetGetDecoratedObjectInputMacro( MovingInitialTransform, InitialTransformType );
241 
258 
263 
271  void SetNumberOfLevels( const SizeValueType );
272  itkGetConstMacro( NumberOfLevels, SizeValueType );
274 
283  {
284  for( unsigned int level = 0; level < factors.Size(); ++level )
285  {
287  shrinkFactors.Fill( factors[level] );
288  this->SetShrinkFactorsPerDimension( level, shrinkFactors );
289  }
290  }
292 
297  {
298  if( level >= this->m_ShrinkFactorsPerLevel.size() )
299  {
300  itkExceptionMacro( "Requesting level greater than the number of levels." );
301  }
302  return this->m_ShrinkFactorsPerLevel[level];
303  }
305 
310  {
311  if( level >= this->m_ShrinkFactorsPerLevel.size() )
312  {
313  this->m_ShrinkFactorsPerLevel.resize( level + 1 );
314  }
315  this->m_ShrinkFactorsPerLevel[level] = factors;
316  this->Modified();
317  }
319 
325  itkSetMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
326  itkGetConstMacro( SmoothingSigmasPerLevel, SmoothingSigmasArrayType );
328 
333  itkSetMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
334  itkGetConstMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits, bool );
335  itkBooleanMacro( SmoothingSigmasAreSpecifiedInPhysicalUnits );
337 
342 
345  virtual const DecoratedOutputTransformType * GetOutput() const;
347 
349  virtual const DecoratedOutputTransformType * GetTransformOutput() const { return this->GetOutput(); }
350 
352  virtual const OutputTransformType * GetTransform() const;
353 
355  itkGetConstMacro( CurrentLevel, SizeValueType );
356 
358  itkGetConstReferenceMacro( CurrentIteration, SizeValueType );
359 
360  /* Get the current metric value. This is a helper function for reporting observations. */
361  itkGetConstReferenceMacro( CurrentMetricValue, RealType );
362 
364  itkGetConstReferenceMacro( CurrentConvergenceValue, RealType );
365 
367  itkGetConstReferenceMacro( IsConverged, bool );
368 
372  itkSetMacro(InPlace, bool);
373  itkGetConstMacro(InPlace, bool);
374  itkBooleanMacro(InPlace);
376 
377 
378 #ifdef ITKV3_COMPATIBILITY
379 
394  void StartRegistration(void) { this->Update(); }
395 #endif
396 
397 protected:
399  virtual ~ImageRegistrationMethodv4();
400  virtual void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
401 
403  virtual void GenerateData() ITK_OVERRIDE;
404 
405  virtual void AllocateOutputs();
406 
408  virtual void InitializeRegistrationAtEachLevel( const SizeValueType );
409 
411  virtual void SetMetricSamplePoints();
412 
413  SizeValueType m_CurrentLevel;
414  SizeValueType m_NumberOfLevels;
415  SizeValueType m_CurrentIteration;
419 
422  SizeValueType m_NumberOfFixedImages;
423  SizeValueType m_NumberOfMovingImages;
424 
428 
432 
436 
438 
440 
441  //TODO: m_OutputTransform should be removed and replaced with a named input parameter for
442  // the pipeline --- Along with many other fixes
444 
445 
446 private:
447  ImageRegistrationMethodv4( const Self & ); //purposely not implemented
448  void operator=( const Self & ); //purposely not implemented
449 
450  bool m_InPlace;
451 
452  // helper function to create the right kind of concrete transform
453  template<typename TTransform>
454  static void MakeOutputTransform(SmartPointer<TTransform> &ptr)
455  {
456  ptr = TTransform::New();
457  }
458 
460  {
462  }
463 
464 };
465 } // end namespace itk
466 
467 #ifndef ITK_MANUAL_INSTANTIATION
468 #include "itkImageRegistrationMethodv4.hxx"
469 #endif
470 
471 #endif
virtual void Update()
InitialTransformType::Pointer InitialTransformPointer
virtual DecoratedOutputTransformType * GetTransformOutput()
Light weight base class for most itk classes.
OptimizerType::ScalesType OptimizerWeightsType
virtual void SetFixedImage(const FixedImageType *image)
virtual void InitializeRegistrationAtEachLevel(const SizeValueType)
const TransformParametersAdaptorsContainerType & GetTransformParametersAdaptorsPerLevel() const
virtual void SetMovingImage(const MovingImageType *image)
MetricSamplingPercentageArrayType m_MetricSamplingPercentagePerLevel
ShrinkImageFilter< FixedImageType, VirtualImageType > ShrinkFilterType
static void MakeOutputTransform(SmartPointer< TTransform > &ptr)
std::vector< TransformParametersAdaptorPointer > TransformParametersAdaptorsContainerType
This class takes one ore more ObjectToObject metrics and assigns weights to their derivatives to comp...
void SetMetricSamplingPercentage(const RealType)
OutputTransformType::ScalarType RealType
void SetOptimizerWeights(OptimizerWeightsType &)
ObjectToObjectOptimizerBaseTemplate< RealType > OptimizerType
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
ObjectType * GetPointer() const
void SetShrinkFactorsPerDimension(unsigned int level, ShrinkFactorsPerDimensionContainerType factors)
Base helper class intended for multi-resolution image registration.
DecoratedInitialTransformType::Pointer DecoratedInitialTransformPointer
Base class for all object-to-object similarlity metrics added in ITKv4.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
DataObjectDecorator< OutputTransformType > DecoratedOutputTransformType
void Fill(const ValueType &)
DataObjectDecorator< InitialTransformType > DecoratedInitialTransformType
ImageToImageMetricv4< FixedImageType, MovingImageType, VirtualImageType, RealType > ImageMetricType
CompositeTransformType::Pointer CompositeTransformPointer
CompositeTransform< RealType, ImageDimension > CompositeTransformType
std::vector< FixedImagePointer > FixedImagesContainerType
ImageMetricType::FixedSampledPointSetType MetricSamplePointSetType
std::vector< ShrinkFactorsPerDimensionContainerType > m_ShrinkFactorsPerLevel
virtual const FixedImageType * GetFixedImage() const
virtual void GenerateData() ITK_OVERRIDE
static Pointer New()
Transform points and vectors from an input space to an output space.
Definition: itkTransform.h:82
virtual const MovingImageType * GetMovingImage() const
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType) ITK_OVERRIDE
MovingImagesContainerType m_MovingSmoothImages
ObjectToObjectMetricBaseTemplate< RealType > MetricType
itkSetGetDecoratedObjectInputMacro(FixedInitialTransform, InitialTransformType)
This class contains a list of transforms and concatenates them by composition.
virtual OutputTransformType * GetModifiableTransform()
Decorates any subclass of itkObject with a DataObject API.
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
virtual DecoratedOutputTransformType * GetOutput()
virtual void SetMetricSamplePoints()
SmoothingSigmasArrayType m_SmoothingSigmasPerLevel
Generic representation for an optimization method.
Definition: itkOptimizer.h:37
ShrinkFilterType::ShrinkFactorsType ShrinkFactorsPerDimensionContainerType
void SetTransformParametersAdaptorsPerLevel(TransformParametersAdaptorsContainerType &)
void SetShrinkFactorsPerLevel(ShrinkFactorsArrayType factors)
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
static void MakeOutputTransform(SmartPointer< InitialTransformType > &ptr)
virtual const DecoratedOutputTransformType * GetTransformOutput() const
virtual void Modified() const
MetricSamplingStrategyType m_MetricSamplingStrategy
ShrinkFactorsPerDimensionContainerType GetShrinkFactorsPerDimension(const unsigned int level) const
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
TransformParametersAdaptorBase< InitialTransformType > TransformParametersAdaptorType
TransformParametersAdaptorsContainerType m_TransformParametersAdaptorsPerLevel
ObjectToObjectMultiMetricv4< ImageDimension, ImageDimension, VirtualImageType, RealType > MultiMetricType
OutputTransformType::Pointer OutputTransformPointer
Reduce the size of an image by an integer factor in each dimension.
SizeValueType Size(void) const
Definition: itkArray.h:124
CompositeTransformPointer m_CompositeTransform
Interface method for the current registration framework.
void SetNumberOfLevels(const SizeValueType)
TransformParametersAdaptorType::Pointer TransformParametersAdaptorPointer
std::vector< MovingImagePointer > MovingImagesContainerType
Abstract base for object-to-object optimizers.
Transform< RealType, ImageDimension, ImageDimension > InitialTransformType
DerivativeType::ValueType DerivativeValueType
virtual const OutputTransformType * GetTransform() const
DecoratedOutputTransformType::Pointer DecoratedOutputTransformPointer
OutputTransformType::DerivativeType DerivativeType