21 #ifndef otbKeyPointSetsMatchingFilter_hxx
22 #define otbKeyPointSetsMatchingFilter_hxx
29 template <
class TPo
intSet,
class TDistance>
32 this->SetNumberOfRequiredInputs(2);
33 m_UseBackMatching =
false;
34 m_DistanceThreshold = 0.6;
36 m_DistanceCalculator = DistanceType::New();
39 template <
class TPo
intSet,
class TDistance>
42 return static_cast<const PointSetType*
>(this->itk::ProcessObject::GetInput(0));
45 template <
class TPo
intSet,
class TDistance>
48 this->itk::ProcessObject::SetNthInput(0,
const_cast<PointSetType*
>(pointset));
51 template <
class TPo
intSet,
class TDistance>
54 return static_cast<const PointSetType*
>(this->itk::ProcessObject::GetInput(1));
57 template <
class TPo
intSet,
class TDistance>
60 this->itk::ProcessObject::SetNthInput(1,
const_cast<PointSetType*
>(pointset));
63 template <
class TPo
intSet,
class TDistance>
73 if (ps1->GetNumberOfPoints() == 0 || ps2->GetNumberOfPoints() == 0)
75 itkExceptionMacro(<<
"Empty input pointset !");
86 while (pdIt != ps1->GetPointData()->End() && pIt != ps1->GetPoints()->End())
89 bool matchFound =
false;
90 unsigned int currentIndex = pIt.Index();
102 if (searchResult1.second < m_DistanceThreshold)
105 dataMatch = ps2->GetPointData()->GetElement(searchResult1.first);
106 pointMatch = ps2->GetPoints()->GetElement(searchResult1.first);
109 if (m_UseBackMatching)
115 if (currentIndex == searchResult2.first)
130 landmark->SetPoint1(point);
131 landmark->SetPointData1(data);
132 landmark->SetPoint2(pointMatch);
133 landmark->SetPointData2(dataMatch);
134 landmark->SetLandmarkData(searchResult1.second);
137 landmarks->PushBack(landmark);
144 template <
class TPo
intSet,
class TDistance>
156 unsigned int nearestIndex = 0;
157 double d1 = m_DistanceCalculator->Evaluate(data1, pdIt.Value());
159 double d2 = m_DistanceCalculator->Evaluate(data1, pdIt.Value());
167 double nearestDistance = std::min(d1, d2);
168 double secondNearestDistance = std::max(d1, d2);
169 double distanceValue;
172 while (pdIt != pointset->GetPointData()->End())
175 distanceValue = m_DistanceCalculator->Evaluate(data1, pdIt.Value());
180 if (distanceValue < nearestDistance)
182 secondNearestDistance = nearestDistance;
183 nearestDistance = distanceValue;
184 nearestIndex = pdIt.Index();
187 else if (distanceValue < secondNearestDistance)
189 secondNearestDistance = distanceValue;
195 result.first = nearestIndex;
196 if (secondNearestDistance == 0)
202 result.second = nearestDistance / secondNearestDistance;
209 template <
class TPo
intSet,
class TDistance>
212 Superclass::PrintSelf(os, indent);