/usr/include/OTB-5.8/otbPointSetToDisplacementFieldGenerator.txx is in libotb-dev 5.8.0+dfsg-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | /*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbPointSetToDisplacementFieldGenerator_txx
#define otbPointSetToDisplacementFieldGenerator_txx
#include "otbPointSetToDisplacementFieldGenerator.h"
#include "otbMacro.h"
namespace otb
{
/**
* Constructor
*/
template <class TPointSet, class TDisplacementField>
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::PointSetToDisplacementFieldGenerator()
{
this->SetNumberOfRequiredInputs(1);
m_MetricThreshold = 0.;
m_OutputSize.Fill(100);
m_OutputSpacing.Fill(1.);
m_OutputOrigin.Fill(0.);
m_DefaultValue = 0;
// m_NearestPoints = PointSetType::New();
}
/**
* Set the pointset containing the disparity.
* \param pointset The pointset containing the disparity.
*/
template <class TPointSet, class TDisplacementField>
void
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::SetPointSet(const TPointSet * pointset)
{
this->itk::ProcessObject::SetNthInput(0, const_cast<PointSetType *>(pointset));
}
/**
* Get the pointset containing the disparity.
* \return The pointset containing the disparity.
*/
template <class TPointSet, class TDisplacementField>
const TPointSet *
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::GetPointSet(void)
{
return static_cast<const PointSetType *>(this->itk::ProcessObject::GetInput(0));
}
/** Generate output information */
template <class TPointSet, class TDisplacementField>
void
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::GenerateOutputInformation(void)
{
DisplacementFieldPointerType outputPtr = this->GetOutput();
typename DisplacementFieldType::RegionType largest;
largest.SetSize(m_OutputSize);
IndexType index;
index.Fill(0);
largest.SetIndex(index);
outputPtr->SetRegions(largest);
outputPtr->SetSpacing(m_OutputSpacing);
outputPtr->SetOrigin(m_OutputOrigin);
// Force the displacement field to have vector pixel of size 2.
outputPtr->SetNumberOfComponentsPerPixel(2);
}
/**
* Generate the n nearest point in point set
* \param index The index of the pixel to compute.
* \param n The number of nearest point to seek.
* \return A vector containing the index of the nearest point from nearest to most far.
*/
template <class TPointSet, class TDisplacementField>
typename PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::IndexVectorType
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::GenerateNearestValidPointsPointSet(IndexType index, unsigned int n)
{
typedef Functor::DistanceComparisonFunctor ComparisonFunctorType;
DistanceVectorType distanceVector;
IndexVectorType indexVector;
IndexVectorType sortVector;
unsigned int i = 0;
unsigned int j = 0;
typedef typename PointSetType::PointsContainer::ConstIterator PointSetIteratorType;
PointSetIteratorType it = this->GetPointSet()->GetPoints()->Begin();
for (; it != this->GetPointSet()->GetPoints()->End(); ++it)
{
PointType p;
p[0] = it.Value()[0];
p[1] = it.Value()[1];
if (vcl_abs(this->GetPointSet()->GetPointData()->GetElement(j)[0]) >= m_MetricThreshold)
{
distanceVector.push_back(EuclideanDistanceMetric(index, p));
sortVector.push_back(i);
indexVector.push_back(j);
++i;
}
++j;
}
ComparisonFunctorType comp;
comp.SetDistanceVector(distanceVector);
sort(sortVector.begin(), sortVector.end(), comp);
// building output vector
unsigned int nbElements = (n < indexVector.size() ? n : indexVector.size());
IndexVectorType output;
for (i = 0; i < nbElements; ++i)
{
output.push_back(indexVector[sortVector[i]]);
}
return output;
}
template <class TPointSet, class TDisplacementField>
double
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::EuclideanDistanceMetric(IndexType index, PointType p)
{
PointType pprime;
// our point are expressed in index and not in physical coordinates
//this->GetOutput()->TransformIndexToPhysicalPoint(index, pprime);
return vcl_sqrt(vcl_pow(index[0] - p[0], 2) + vcl_pow(index[1] - p[1], 2));
}
/**
* PrintSelf Method
*/
template <class TPointSet, class TDisplacementField>
void
PointSetToDisplacementFieldGenerator<TPointSet, TDisplacementField>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
|