Orfeo Toolbox  3.16
otbBSplinesInterpolateDeformationFieldGenerator.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbBSplinesInterpolateDeformationFieldGenerator_txx
19 #define __otbBSplinesInterpolateDeformationFieldGenerator_txx
20 
22 // Disabling deprecation warning if on visual
23 #ifdef _MSC_VER
24 #pragma warning(push)
25 #pragma warning(disable:4996)
26 #endif
28 // Enabling remaining deprecation warning
29 #ifdef _MSC_VER
30 #pragma warning(pop)
31 #endif
32 #include "otbMacro.h"
33 #include "otbImage.h"
34 #include "itkImageRegionIterator.h"
35 
36 namespace otb
37 {
39 template <class TPointSet, class TDeformationField>
40 void
43 {
44  DeformationFieldPointerType outputPtr = this->GetOutput();
47  typedef itk::DeformationFieldSource<ImageType> DeformationFieldSourceType;
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;
55 
56  typename LandmarkContainerType::Pointer sourceLandmarks = LandmarkContainerType::New();
57  typename LandmarkContainerType::Pointer targetLandmarks = LandmarkContainerType::New();
58  LandmarkPointType sourcePoint;
59  LandmarkPointType targetPoint;
60 
61  PointsIterator pointIterator = this->GetPointSet()->GetPoints()->Begin();
62  PointsIterator end = this->GetPointSet()->GetPoints()->End();
63  unsigned int pointId = 0;
64 
65  PointDataIterator pointDataIterator = this->GetPointSet()->GetPointData()->Begin();
66 
67  while (pointIterator != end)
68  {
69  typename PointDataContainer::Element valueAndDeformations = pointDataIterator.Value();
70 
71  if (vcl_abs(valueAndDeformations[0]) >= this->GetMetricThreshold())
72  {
73  typename PointSetType::PointType p = pointIterator.Value(); // access the point
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);
82  ++pointId;
83  }
84  ++pointIterator;
85  ++pointDataIterator;
86  }
87 
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());
94 
95  deformer->Update();
96  outputPtr->Allocate();
97  PixelType defaultPixel;
98  defaultPixel.SetSize(2);
99  defaultPixel.Fill(this->GetDefaultValue());
100  outputPtr->FillBuffer(defaultPixel);
101  typedef itk::ImageRegionIterator<ImageType> ImageIteratorType;
102  typedef itk::ImageRegionIterator<DeformationFieldType> OutputIteratorType;
103 
104  ImageIteratorType inIt(deformer->GetOutput(), outputPtr->GetRequestedRegion());
105  OutputIteratorType outIt(outputPtr, outputPtr->GetRequestedRegion());
106  int i = 0;
107  // Casting otb::Image<itt::Vector<ValueType, 2>, 2> to otb::VectorImage<ValueType, 2>
108  for (inIt.GoToBegin(), outIt.GoToBegin(); (!inIt.IsAtEnd()) && (!outIt.IsAtEnd()); ++inIt, ++outIt, ++i)
109  {
110  typename ImageType::PixelType inPixel;
111  inPixel = inIt.Get();
112  PixelType outPixel;
113  outPixel.SetSize(2);
114  outPixel[0] = -inPixel[0];
115  outPixel[1] = -inPixel[1];
116  outIt.Set(outPixel);
117  }
118 }
122 template <class TPointSet, class TDeformationField>
123 void
125 ::PrintSelf(std::ostream& os, itk::Indent indent) const
126 {
127  Superclass::PrintSelf(os, indent);
128 }
129 } // End namespace otb
130 #endif

Generated at Sun Feb 3 2013 00:18:48 for Orfeo Toolbox with doxygen 1.8.1.1