5 #include <itkTranslationTransform.h> 13 template <
typename TInputImageType>
23 m_SearchAngleRadius = 5;
24 m_SearchScaleRadius = 0.1;
26 m_AffineDirection = 1;
29 template <
typename TInputImageType>
34 switch (m_BlockTransformType)
37 return AgregatorType::TRANSLATION;
40 return AgregatorType::RIGID;
43 case Directional_Affine:
45 return AgregatorType::AFFINE;
49 template <
typename TInputImageType>
56 switch(m_BlockTransformType)
60 typedef itk::TranslationTransform <double, InputImageType::ImageDimension> itkTransformType;
61 typename itkTransformType::Pointer tr = itkTransformType::New();
70 if (InputImageType::ImageDimension == 3)
73 typename itkTransformType::Pointer tr = itkTransformType::New();
75 tr->SetCenter(blockCenter);
80 std::cerr <<
"Only Rigid 3D transforms handled right now." << std::endl;
87 typename itkTransformType::Pointer tr = itkTransformType::New();
89 tr->SetCenter(blockCenter);
95 case Directional_Affine:
99 typename itkTransformType::Pointer tr = itkTransformType::New();
102 typename itkTransformType::HomogeneousMatrixType geometry;
104 geometry.SetIdentity();
105 for (
unsigned int i = 0;i < 3;++i)
106 for (
unsigned int j = 0;j < 3;++j)
107 geometry(i,j) = this->GetReferenceImage()->GetDirection()(i,j) * this->GetReferenceImage()->GetSpacing()[j];
109 for (
unsigned int j = 0;j < 3;++j)
110 geometry(j,TInputImageType::ImageDimension) = blockCenter[j];
112 tr->SetUniqueDirection(m_AffineDirection);
113 tr->SetGeometry(geometry,
false);
123 template <
typename TInputImageType>
128 switch (m_BlockTransformType)
132 typedef itk::TranslationTransform <double, InputImageType::ImageDimension> itkTransformType;
133 itkTransformType *tr = dynamic_cast <itkTransformType *> (this->GetBlockTransformPointer(block).GetPointer());
140 typedef itk::MatrixOffsetTransformBase <double, InputImageType::ImageDimension> itkTransformType;
141 itkTransformType *tr = dynamic_cast <itkTransformType *> (this->GetBlockTransformPointer(block).GetPointer());
148 template <
typename TInputImageType>
157 LocalOptimizerType::ScalesType tmpScales(this->GetBlockTransformPointer(0)->GetNumberOfParameters());
158 LocalOptimizerType::ScalesType lowerBounds(this->GetBlockTransformPointer(0)->GetNumberOfParameters());
159 LocalOptimizerType::ScalesType upperBounds(this->GetBlockTransformPointer(0)->GetNumberOfParameters());
160 typename InputImageType::SpacingType fixedSpacing = this->GetReferenceImage()->GetSpacing();
162 switch (m_BlockTransformType)
166 for (
unsigned int i = 0;i < InputImageType::ImageDimension;++i)
168 tmpScales[i] = 1.0 / fixedSpacing[i];
170 lowerBounds[i] = - m_TranslateMax * fixedSpacing[i];
171 upperBounds[i] = m_TranslateMax * fixedSpacing[i];
179 for (
unsigned int i = 0;i < InputImageType::ImageDimension;++i)
181 tmpScales[i] = this->GetSearchRadius() * 180.0 / (m_SearchAngleRadius * M_PI);
182 lowerBounds[i] = - m_AngleMax * M_PI / 180.0;
183 upperBounds[i] = m_AngleMax * M_PI / 180.0;
185 tmpScales[i+InputImageType::ImageDimension] = 1.0 / fixedSpacing[i];
187 lowerBounds[i+InputImageType::ImageDimension] = - m_TranslateMax * fixedSpacing[i];
188 upperBounds[i+InputImageType::ImageDimension] = m_TranslateMax * fixedSpacing[i];
197 for (
unsigned int i = 0;i < InputImageType::ImageDimension;++i)
200 tmpScales[i] = this->GetSearchRadius() * 180.0 / (m_SearchAngleRadius * M_PI);
201 lowerBounds[i] = - m_AngleMax * M_PI / 180.0;
202 upperBounds[i] = m_AngleMax * M_PI / 180.0;
205 tmpScales[InputImageType::ImageDimension + i] = 1.0 / fixedSpacing[i];
207 lowerBounds[InputImageType::ImageDimension + i] = - m_TranslateMax * fixedSpacing[i];
208 upperBounds[InputImageType::ImageDimension + i] = m_TranslateMax * fixedSpacing[i];
211 tmpScales[2 * InputImageType::ImageDimension + i] = this->GetSearchRadius() / m_SearchScaleRadius;
213 lowerBounds[2 * InputImageType::ImageDimension + i] = - std::log (m_ScaleMax);
214 upperBounds[2 * InputImageType::ImageDimension + i] = std::log (m_ScaleMax);
217 tmpScales[3 * InputImageType::ImageDimension + i] = this->GetSearchRadius() * 180.0 / (m_SearchAngleRadius * M_PI);
219 lowerBounds[3 * InputImageType::ImageDimension + i] = - m_AngleMax * M_PI / 180.0;
220 upperBounds[3 * InputImageType::ImageDimension + i] = m_AngleMax * M_PI / 180.0;
226 case Directional_Affine:
232 lowerBounds[0] = - m_TranslateMax;
233 upperBounds[0] = m_TranslateMax;
239 LocalOptimizerType * tmpOpt = dynamic_cast <LocalOptimizerType *> (optimizer.GetPointer());
240 tmpOpt->SetScales(tmpScales);
241 tmpOpt->SetLowerBounds(lowerBounds);
242 tmpOpt->SetUpperBounds(upperBounds);
AgregatorType::TRANSFORM_TYPE GetAgregatorInputTransformType()
Superclass::BaseInputTransformPointer BaseInputTransformPointer
Superclass::MetricPointer MetricPointer
Superclass::PointType PointType
Superclass::OptimizerPointer OptimizerPointer
virtual void BlockMatchingSetup(MetricPointer &metric, unsigned int block)
virtual BaseInputTransformPointer GetNewBlockTransform(PointType &blockCenter)
virtual void TransformDependantOptimizerSetup(OptimizerPointer &optimizer)