18 #ifndef __otbBSplinesInterpolateDeformationFieldGenerator_txx
19 #define __otbBSplinesInterpolateDeformationFieldGenerator_txx
25 #pragma warning(disable:4996)
39 template <
class TPo
intSet,
class TDeformationField>
48 typedef typename DeformationFieldSourceType::LandmarkContainerPointer LandmarkContainerPointer;
49 typedef typename DeformationFieldSourceType::LandmarkContainer LandmarkContainerType;
50 typedef typename DeformationFieldSourceType::LandmarkPointType LandmarkPointType;
51 typedef typename PointSetType::PointsContainer PointsContainer;
52 typedef typename PointsContainer::ConstIterator PointsIterator;
53 typedef typename PointSetType::PointDataContainer PointDataContainer;
54 typedef typename PointDataContainer::ConstIterator PointDataIterator;
56 typename LandmarkContainerType::Pointer sourceLandmarks = LandmarkContainerType::New();
57 typename LandmarkContainerType::Pointer targetLandmarks = LandmarkContainerType::New();
58 LandmarkPointType sourcePoint;
59 LandmarkPointType targetPoint;
61 PointsIterator pointIterator = this->GetPointSet()->GetPoints()->Begin();
62 PointsIterator end = this->GetPointSet()->GetPoints()->End();
63 unsigned int pointId = 0;
65 PointDataIterator pointDataIterator = this->GetPointSet()->GetPointData()->Begin();
67 while (pointIterator != end)
69 typename PointDataContainer::Element valueAndDeformations = pointDataIterator.Value();
71 if (vcl_abs(valueAndDeformations[0]) >= this->GetMetricThreshold())
73 typename PointSetType::PointType p = pointIterator.Value();
74 sourcePoint[0] = p[0];
75 sourcePoint[1] = p[1];
76 targetPoint[0] = p[0] - valueAndDeformations[1];
77 targetPoint[1] = p[1] - valueAndDeformations[2];
79 <<
"Adding landmark " << pointId <<
", source point: " << sourcePoint <<
", targetpoint: " << targetPoint);
80 sourceLandmarks->InsertElement(pointId, sourcePoint);
81 targetLandmarks->InsertElement(pointId, targetPoint);
88 typename DeformationFieldSourceType::Pointer deformer = DeformationFieldSourceType::New();
89 deformer->SetOutputSpacing(this->GetOutputSpacing());
90 deformer->SetOutputOrigin(this->GetOutputOrigin());
91 deformer->SetOutputRegion(outputPtr->GetRequestedRegion());
92 deformer->SetSourceLandmarks(sourceLandmarks.GetPointer());
93 deformer->SetTargetLandmarks(targetLandmarks.GetPointer());
96 outputPtr->Allocate();
98 defaultPixel.SetSize(2);
99 defaultPixel.Fill(this->GetDefaultValue());
100 outputPtr->FillBuffer(defaultPixel);
104 ImageIteratorType inIt(deformer->GetOutput(), outputPtr->GetRequestedRegion());
105 OutputIteratorType outIt(outputPtr, outputPtr->GetRequestedRegion());
108 for (inIt.GoToBegin(), outIt.GoToBegin(); (!inIt.IsAtEnd()) && (!outIt.IsAtEnd()); ++inIt, ++outIt, ++i)
110 typename ImageType::PixelType inPixel;
111 inPixel = inIt.
Get();
114 outPixel[0] = -inPixel[0];
115 outPixel[1] = -inPixel[1];
122 template <
class TPo
intSet,
class TDeformationField>
127 Superclass::PrintSelf(os, indent);