| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkLandmarkBasedTransformInitializer.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 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 |
|
|
| 18 |
|
#ifndef __itkLandmarkBasedTransformInitializer_h |
| 19 |
|
#define __itkLandmarkBasedTransformInitializer_h |
| 20 |
|
|
| 21 |
|
#include "itkObject.h" |
| 22 |
|
#include "itkObjectFactory.h" |
| 23 |
|
#include "itkVersorRigid3DTransform.h" |
| 24 |
|
#include "itkRigid2DTransform.h" |
| 25 |
|
#include <vector> |
| 26 |
|
#include <iostream> |
| 27 |
|
|
| 28 |
|
namespace itk |
| 29 |
|
{ |
| 30 |
|
|
| 31 |
|
/** \brief LandmarkBasedTransformInitializer is a helper class intended to |
| 32 |
|
* The class computes the transform that aligns the fixed and moving images |
| 33 |
|
* given a set of landmarks. The class is templated over the Transform type. |
| 34 |
|
* The transform computed gives the best fit transform that maps the fixed |
| 35 |
|
* and moving images in a least squares sense. The indices are taken to |
| 36 |
|
* correspond, so point 1 in the first set will get mapped close to point |
| 37 |
|
* 1 in the second set, etc. An equal number of fixed and moving landmarks |
| 38 |
|
* need to be specified using SetFixedLandmarks() SetMovingLandmarks(). |
| 39 |
|
* Any number of landmarks may be specified. |
| 40 |
|
* Call InitializeTransform() to initialize the transform. |
| 41 |
|
* |
| 42 |
|
* Currently, the following transforms are supported by the class: |
| 43 |
|
* VersorRigid3DTransform |
| 44 |
|
* Rigid2DTansform |
| 45 |
|
* |
| 46 |
|
* The class is based in part on Hybrid/vtkLandmarkTransform originally |
| 47 |
|
* implemented in python by David G. Gobbi. |
| 48 |
|
* |
| 49 |
|
* The solution is based on |
| 50 |
|
* Berthold K. P. Horn (1987), "Closed-form solution of absolute orientation |
| 51 |
|
* using unit quaternions," |
| 52 |
|
* http://people.csail.mit.edu/bkph/papers/Absolute_Orientation.pdf |
| 53 |
|
* |
| 54 |
|
* |
| 55 |
|
* \ingroup Transforms |
| 56 |
|
*/ |
| 57 |
|
template < class TTransform, |
| 58 |
|
class TFixedImage, |
| 59 |
|
class TMovingImage > |
| 60 |
MCM |
class ITK_EXPORT LandmarkBasedTransformInitializer : |
| 61 |
IND |
************public Object |
| 62 |
|
{ |
| 63 |
|
public: |
| 64 |
|
/** Standard class typedefs. */ |
| 65 |
|
typedef LandmarkBasedTransformInitializer Self; |
| 66 |
TDA |
typedef Object Superclass; |
| 67 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 68 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 69 |
|
|
| 70 |
|
/** New macro for creation of through a Smart Pointer. */ |
| 71 |
|
itkNewMacro( Self ); |
| 72 |
|
|
| 73 |
|
/** Run-time type information (and related methods). */ |
| 74 |
|
itkTypeMacro( LandmarkBasedTransformInitializer, Object ); |
| 75 |
|
|
| 76 |
|
/** Type of the transform to initialize */ |
| 77 |
|
typedef TTransform TransformType; |
| 78 |
|
typedef typename TransformType::Pointer TransformPointer; |
| 79 |
|
|
| 80 |
|
/** Dimension of parameters. */ |
| 81 |
LEN |
itkStaticConstMacro(InputSpaceDimension, unsigned int, TransformType::InputSpaceDimension); |
| 82 |
LEN |
itkStaticConstMacro(OutputSpaceDimension, unsigned int, TransformType::OutputSpaceDimension); |
| 83 |
|
|
| 84 |
|
/** Set the transform to be initialized */ |
| 85 |
|
itkSetObjectMacro( Transform, TransformType ); |
| 86 |
|
|
| 87 |
|
/** Image Types to use in the initialization of the transform */ |
| 88 |
|
typedef TFixedImage FixedImageType; |
| 89 |
|
typedef TMovingImage MovingImageType; |
| 90 |
|
|
| 91 |
|
typedef typename FixedImageType::ConstPointer FixedImagePointer; |
| 92 |
|
typedef typename MovingImageType::ConstPointer MovingImagePointer; |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
/** \deprecated |
| 96 |
|
* Set the fixed image. |
| 97 |
|
* The method really doesn't do anything. The goal of this class is to compute |
| 98 |
|
* the optimal transform, for the templated TransformType between the fixed |
| 99 |
|
* and moving image grid, given a set of landmarks. Nothing is done with the |
| 100 |
|
* images themselves. The method will therefore be deprecated and removed */ |
| 101 |
|
void SetFixedImage( const FixedImageType * image ) |
| 102 |
|
{ |
| 103 |
|
this->m_FixedImage = image; |
| 104 |
|
itkLegacyBody( SetFixedImage, 2.2 ); |
| 105 |
|
} |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
/** \deprecated |
| 109 |
|
* Set the moving image. |
| 110 |
|
* The method really doesn't do anything. The goal of this class is to compute |
| 111 |
|
* the optimal transform, for the templated TransformType between the fixed |
| 112 |
|
* and moving image grid, given a set of landmarks. Nothing is done with the |
| 113 |
|
* images themselves. The method will therefore be deprecated and removed. */ |
| 114 |
|
void SetMovingImage( const MovingImageType * image ) |
| 115 |
|
{ |
| 116 |
|
this->m_MovingImage = image; |
| 117 |
|
itkLegacyBody( SetMovingImage, 2.2 ); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
/** Determine the image dimension. */ |
| 122 |
LEN |
itkStaticConstMacro(ImageDimension, unsigned int, FixedImageType::ImageDimension ); |
| 123 |
|
|
| 124 |
|
/** Convenience typedefs */ |
| 125 |
|
typedef typename TransformType::InputPointType InputPointType; |
| 126 |
TDA |
typedef typename TransformType::OutputVectorType OutputVectorType; |
| 127 |
LEN,TDA |
typedef Point< double, itkGetStaticConstMacro(ImageDimension) > LandmarkPointType; |
| 128 |
TDA |
typedef std::vector< LandmarkPointType > LandmarkPointContainer; |
| 129 |
|
typedef typename |
| 130 |
LEN,TDA,IND |
**********LandmarkPointContainer::const_iterator PointsContainerConstIterator; |
| 131 |
TDA |
typedef typename TransformType::ParametersType ParametersType; |
| 132 |
TDA |
typedef typename ParametersType::ValueType ParameterValueType; |
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
/** Set the Fixed landmark point containers */ |
| 137 |
|
void SetFixedLandmarks(LandmarkPointContainer & fixedLandmarks) |
| 138 |
|
{ |
| 139 |
|
this->m_FixedLandmarks = fixedLandmarks; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
/** Set the Moving landmark point containers */ |
| 143 |
|
void SetMovingLandmarks(LandmarkPointContainer & movingLandmarks) |
| 144 |
|
{ |
| 145 |
|
this->m_MovingLandmarks = movingLandmarks; |
| 146 |
|
} |
| 147 |
|
|
| 148 |
|
|
| 149 |
|
/** Supported Transform typedefs */ |
| 150 |
|
typedef VersorRigid3DTransform< ParameterValueType > |
| 151 |
IND |
****************************************VersorRigid3DTransformType; |
| 152 |
TDA |
typedef Rigid2DTransform< ParameterValueType > Rigid2DTransformType; |
| 153 |
|
|
| 154 |
|
/** Initialize the transform from the landmarks */ |
| 155 |
SEM |
virtual void InitializeTransform() ; |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
protected: |
| 159 |
|
LandmarkBasedTransformInitializer(); |
| 160 |
|
~LandmarkBasedTransformInitializer(){}; |
| 161 |
|
|
| 162 |
|
void PrintSelf(std::ostream &os, Indent indent) const; |
| 163 |
|
|
| 164 |
|
// Supported Transform types |
| 165 |
|
typedef enum{ |
| 166 |
|
VersorRigid3Dtransform=1, |
| 167 |
|
Rigid2Dtransfrom, |
| 168 |
|
Else |
| 169 |
IND |
**}InputTransformType; |
| 170 |
|
|
| 171 |
|
private: |
| 172 |
|
LandmarkBasedTransformInitializer(const Self&); //purposely not implemented |
| 173 |
|
void operator=(const Self&); //purposely not implemented |
| 174 |
|
|
| 175 |
|
FixedImagePointer m_FixedImage; |
| 176 |
|
MovingImagePointer m_MovingImage; |
| 177 |
|
|
| 178 |
|
LandmarkPointContainer m_FixedLandmarks; |
| 179 |
|
LandmarkPointContainer m_MovingLandmarks; |
| 180 |
|
|
| 181 |
|
TransformPointer m_Transform; |
| 182 |
|
|
| 183 |
|
}; //class LandmarkBasedTransformInitializer |
| 184 |
|
|
| 185 |
|
|
| 186 |
|
} // namespace itk |
| 187 |
|
|
| 188 |
|
|
| 189 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 190 |
|
#include "itkLandmarkBasedTransformInitializer.txx" |
| 191 |
|
#endif |
| 192 |
|
|
| 193 |
|
#endif /* __itkLandmarkBasedTransformInitializer_h */ |
| 194 |
|
|