21 #ifndef otbDisparityMapEstimationMethod_hxx
22 #define otbDisparityMapEstimationMethod_hxx
25 #include "itkImageRegistrationMethod.h"
37 template <
typename TFixedImage,
typename TMovingImage,
class TPo
intSet>
40 this->SetNumberOfRequiredInputs(3);
43 this->SetReleaseDataBeforeUpdateFlag(
false);
44 m_Transform =
nullptr;
45 m_Interpolator =
nullptr;
47 m_Optimizer =
nullptr;
51 m_InitialTransformParameters.Fill(0.0f);
56 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
64 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
67 this->itk::ProcessObject::SetNthInput(0,
const_cast<PointSetType*
>(pointset));
74 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
77 return static_cast<const PointSetType*
>(this->itk::ProcessObject::GetInput(0));
84 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
87 this->itk::ProcessObject::SetNthInput(1,
const_cast<FixedImageType*
>(image));
94 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
97 return static_cast<const FixedImageType*
>(this->itk::ProcessObject::GetInput(1));
104 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
107 this->itk::ProcessObject::SetNthInput(2,
const_cast<MovingImageType*
>(image));
114 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
117 return static_cast<const MovingImageType*
>(this->itk::ProcessObject::GetInput(2));
123 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
134 typedef typename PointSetType::PointsContainer PointsContainer;
135 typedef typename PointsContainer::ConstIterator PointsIterator;
136 typedef itk::ImageRegistrationMethod<FixedImageType, MovingImageType> RegistrationType;
141 typename PointsContainer::ConstPointer points = pointSet->GetPoints();
144 PointsIterator pointIterator = points->Begin();
145 PointsIterator end = points->End();
146 unsigned int dataId = 0;
151 while (pointIterator != end)
153 typename PointSetType::PointType p = pointIterator.Value();
156 typename FixedExtractType::Pointer fixedExtractor = FixedExtractType::New();
157 typename MovingExtractType::Pointer movingExtractor = MovingExtractType::New();
158 fixedExtractor->SetInput(fixed);
159 movingExtractor->SetInput(moving);
162 fixedExtractor->SetStartX(
static_cast<unsigned long>(p[0] - m_ExploSize[0]));
163 fixedExtractor->SetStartY(
static_cast<unsigned long>(p[1] - m_ExploSize[1]));
164 fixedExtractor->SetSizeX(
static_cast<unsigned long>(2 * m_ExploSize[0] + 1));
165 fixedExtractor->SetSizeY(
static_cast<unsigned long>(2 * m_ExploSize[1] + 1));
167 otbMsgDevMacro(<<
"Fixed region: origin(" << p[0] - m_ExploSize[0] <<
", " << p[1] - m_ExploSize[1] <<
") size(" << 2 * m_ExploSize[0] + 1 <<
", "
168 << 2 * m_ExploSize[1] + 1 <<
")");
170 movingExtractor->SetStartX(
static_cast<unsigned long>(p[0] - m_WinSize[0]));
171 movingExtractor->SetStartY(
static_cast<unsigned long>(p[1] - m_WinSize[1]));
172 movingExtractor->SetSizeX(
static_cast<unsigned long>(2 * m_WinSize[0] + 1));
173 movingExtractor->SetSizeY(
static_cast<unsigned long>(2 * m_WinSize[1] + 1));
174 otbMsgDevMacro(<<
"Moving region: origin(" << p[0] - m_WinSize[0] <<
", " << p[1] - m_WinSize[1] <<
") size(" << 2 * m_WinSize[0] + 1 <<
", "
175 << 2 * m_WinSize[1] + 1 <<
")");
177 fixedExtractor->Update();
178 movingExtractor->Update();
205 typename RegistrationType::Pointer registration = RegistrationType::New();
208 registration->SetOptimizer(m_Optimizer);
209 registration->SetTransform(m_Transform);
210 registration->SetInterpolator(m_Interpolator);
211 registration->SetMetric(m_Metric);
212 registration->SetFixedImage(fixedExtractor->GetOutput());
213 registration->SetMovingImage(movingExtractor->GetOutput());
216 registration->SetInitialTransformParameters(m_InitialTransformParameters);
217 m_Interpolator->SetInputImage(movingExtractor->GetOutput());
220 registration->Update();
223 ParametersType finalParameters = registration->GetLastTransformParameters();
224 double value = m_Optimizer->GetValue(registration->GetLastTransformParameters());
227 typename FixedImageType::PointType inputPoint, outputPoint;
228 typename FixedImageType::IndexType inputIndex;
231 inputIndex[0] =
static_cast<unsigned int>(p[0]);
232 inputIndex[1] =
static_cast<unsigned int>(p[1]);
234 fixed->TransformIndexToPhysicalPoint(inputIndex, inputPoint);
236 m_Transform->SetParameters(finalParameters);
237 outputPoint = m_Transform->TransformPoint(inputPoint);
241 otbMsgDevMacro(<<
"Displacement: (" << outputPoint[0] - inputPoint[0] <<
", " << outputPoint[1] - inputPoint[1] <<
")");
247 data[1] = outputPoint[0] - inputPoint[0];
248 data[2] = outputPoint[1] - inputPoint[1];
250 for (
unsigned int i = 0; i < finalParameters.GetSize(); ++i)
252 data[i + 3] = finalParameters[i];
256 output->SetPoint(dataId, p);
257 output->SetPointData(dataId, data);
263 template <
class TFixedImage,
class TMovingImage,
class TPo
intSet>
266 Superclass::PrintSelf(os, indent);
267 os << indent <<
"Window size: " << m_WinSize << std::endl;
268 os << indent <<
"Exploration size: " << m_ExploSize << std::endl;