/usr/include/ITK-4.9/itkEuclideanDistancePointMetric.hxx is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkEuclideanDistancePointMetric_hxx
#define itkEuclideanDistancePointMetric_hxx
#include "itkEuclideanDistancePointMetric.h"
#include "itkImageRegionConstIteratorWithIndex.h"
namespace itk
{
/** Constructor */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::EuclideanDistancePointMetric()
{
m_DistanceMap = ITK_NULLPTR;
// when set to true it will be a bit faster, but it will result in minimizing
// the sum of distances^4 instead of the sum of distances^2
m_ComputeSquaredDistance = false;
}
/** Return the number of values, i.e the number of points in the moving set */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
unsigned int
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::GetNumberOfValues() const
{
MovingPointSetConstPointer movingPointSet = this->GetMovingPointSet();
if ( !movingPointSet )
{
itkExceptionMacro(<< "Moving point set has not been assigned");
}
return movingPointSet->GetPoints()->Size();
}
/** Get the match Measure */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
typename EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >::MeasureType
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::GetValue(const TransformParametersType & parameters) const
{
FixedPointSetConstPointer fixedPointSet = this->GetFixedPointSet();
if ( !fixedPointSet )
{
itkExceptionMacro(<< "Fixed point set has not been assigned");
}
MovingPointSetConstPointer movingPointSet = this->GetMovingPointSet();
if ( !movingPointSet )
{
itkExceptionMacro(<< "Moving point set has not been assigned");
}
MovingPointIterator pointItr = movingPointSet->GetPoints()->Begin();
MovingPointIterator pointEnd = movingPointSet->GetPoints()->End();
MeasureType measure;
measure.set_size( movingPointSet->GetPoints()->Size() );
this->SetTransformParameters(parameters);
unsigned int identifier = 0;
while ( pointItr != pointEnd )
{
typename Superclass::InputPointType inputPoint;
inputPoint.CastFrom( pointItr.Value() );
typename Superclass::OutputPointType transformedPoint =
this->m_Transform->TransformPoint(inputPoint);
double minimumDistance = NumericTraits< double >::max();
bool closestPoint = false;
// Try to use the distance map to solve the closest point
if ( m_DistanceMap )
{
// If the point is inside the distance map
typename DistanceMapType::IndexType index;
if ( m_DistanceMap->TransformPhysicalPointToIndex(transformedPoint, index) )
{
minimumDistance = m_DistanceMap->GetPixel(index);
// In case the provided distance map was signed,
// we correct here the distance to take its absolute value.
if ( minimumDistance < 0.0 )
{
minimumDistance = -minimumDistance;
}
closestPoint = true;
}
}
// if the closestPoint has not been found
if ( !closestPoint )
{
// Go trough the list of fixed point and find the closest distance
FixedPointIterator pointItr2 = fixedPointSet->GetPoints()->Begin();
FixedPointIterator pointEnd2 = fixedPointSet->GetPoints()->End();
while ( pointItr2 != pointEnd2 )
{
double dist = pointItr2.Value().SquaredEuclideanDistanceTo(transformedPoint);
if ( !m_ComputeSquaredDistance )
{
dist = std::sqrt(dist);
}
if ( dist < minimumDistance )
{
minimumDistance = dist;
}
pointItr2++;
}
}
measure.put(identifier, minimumDistance);
++pointItr;
identifier++;
}
return measure;
}
/** Get the Derivative Measure */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
void
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::GetDerivative( const TransformParametersType & itkNotUsed(parameters),
DerivativeType & itkNotUsed(derivative) ) const
{}
/** Get both the match Measure and theDerivative Measure */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
void
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::GetValueAndDerivative(const TransformParametersType & parameters,
MeasureType & value, DerivativeType & derivative) const
{
value = this->GetValue(parameters);
this->GetDerivative(parameters, derivative);
}
/** PrintSelf method */
template< typename TFixedPointSet, typename TMovingPointSet, typename TDistanceMap >
void
EuclideanDistancePointMetric< TFixedPointSet, TMovingPointSet, TDistanceMap >
::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "DistanceMap: " << m_DistanceMap << std::endl;
if ( m_ComputeSquaredDistance )
{
os << indent << "m_ComputeSquaredDistance: True" << std::endl;
}
else
{
os << indent << "m_ComputeSquaredDistance: False" << std::endl;
}
}
} // end namespace itk
#endif
|