Orfeo Toolbox  3.16
otbPointSetToDeformationFieldGenerator.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 __otbPointSetToDeformationFieldGenerator_txx
19 #define __otbPointSetToDeformationFieldGenerator_txx
20 
22 #include "otbMacro.h"
23 
24 namespace otb
25 {
29 template <class TPointSet, class TDeformationField>
32 {
33  this->SetNumberOfRequiredInputs(1);
34  m_MetricThreshold = 0.;
35  m_OutputSize.Fill(100);
36  m_OutputSpacing.Fill(1.);
37  m_OutputOrigin.Fill(0.);
38  m_DefaultValue = 0;
39 // m_NearestPoints = PointSetType::New();
40 }
45 template <class TPointSet, class TDeformationField>
46 void
48 ::SetPointSet(const TPointSet * pointset)
49 {
50  this->itk::ProcessObject::SetNthInput(0, const_cast<PointSetType *>(pointset));
51 }
56 template <class TPointSet, class TDeformationField>
57 const TPointSet *
60 {
61  return static_cast<const PointSetType *>(this->itk::ProcessObject::GetInput(0));
62 }
64 template <class TPointSet, class TDeformationField>
65 void
68 {
69  DeformationFieldPointerType outputPtr = this->GetOutput();
70  typename DeformationFieldType::RegionType largest;
71  largest.SetSize(m_OutputSize);
72  IndexType index;
73  index.Fill(0);
74  largest.SetIndex(index);
75  outputPtr->SetRegions(largest);
76  outputPtr->SetSpacing(m_OutputSpacing);
77  outputPtr->SetOrigin(m_OutputOrigin);
78  // Force the deformation field to have vector pixel of size 2.
79  outputPtr->SetNumberOfComponentsPerPixel(2);
80 }
87 template <class TPointSet, class TDeformationField>
89 ::IndexVectorType
92 {
93  typedef Functor::DistanceComparisonFunctor ComparisonFunctorType;
94  DistanceVectorType distanceVector;
95  IndexVectorType indexVector;
96  IndexVectorType sortVector;
97  unsigned int i = 0;
98  unsigned int j = 0;
99 
100  typedef typename PointSetType::PointsContainer::ConstIterator PointSetIteratorType;
101  typedef typename PointSetType::PointsContainer PointsContainerType;
102  PointSetIteratorType it = this->GetPointSet()->GetPoints()->Begin();
103  for (; it != this->GetPointSet()->GetPoints()->End(); ++it)
104  {
105  PointType p;
106  p[0] = it.Value()[0];
107  p[1] = it.Value()[1];
108  if (vcl_abs(this->GetPointSet()->GetPointData()->GetElement(j)[0]) >= m_MetricThreshold)
109  {
110 
111  distanceVector.push_back(EuclideanDistance(index, p));
112  sortVector.push_back(i);
113  indexVector.push_back(j);
114  ++i;
115  }
116  ++j;
117  }
118 
119  ComparisonFunctorType comp;
120  comp.SetDistanceVector(distanceVector);
121  sort(sortVector.begin(), sortVector.end(), comp);
122 
123  // building output vector
124  unsigned int nbElements = (n < indexVector.size() ? n : indexVector.size());
125  IndexVectorType output;
126  for (i = 0; i < nbElements; ++i)
127  {
128  output.push_back(indexVector[sortVector[i]]);
129  }
130  return output;
131 }
132 
133 template <class TPointSet, class TDeformationField>
134 double
137 {
138  PointType pprime;
139  // our point are expressed in index and not in physical coordinates
140  //this->GetOutput()->TransformIndexToPhysicalPoint(index, pprime);
141  return vcl_sqrt(vcl_pow(index[0] - p[0], 2) + vcl_pow(index[1] - p[1], 2));
142 }
146 template <class TPointSet, class TDeformationField>
147 void
149 ::PrintSelf(std::ostream& os, itk::Indent indent) const
150 {
151  Superclass::PrintSelf(os, indent);
152 }
153 } // End namespace otb
154 #endif

Generated at Sun Feb 3 2013 00:42:04 for Orfeo Toolbox with doxygen 1.8.1.1