[Insight-developers] Harmless (?) valgrind errors on
DeformableRegistration7
Kris Thielemans
kris.thielemans at csc.mrc.ac.uk
Mon Oct 3 07:17:35 EDT 2005
Hi
I've run valgrind --tool=memcheck on the executable for
Examples/Registration/DeformableRegistration7.cxx that I make on my debian
system (ITK 2.2, unfortunately using gcc 2.95.4, but I don't think it
matters).
I get errors like this:
==28336==
==28336== Use of uninitialised value of size 8
==28336== at 0x833B35E: vnl_vector<double>::operator=(vnl_vector<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Utilities/vxl/core/vnl/vnl_v
ector.txx:391)
==28336== by 0x813CC8D: itk::Array<double>::operator=(itk::Array<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Common/itkArray.txx:167
)
==28336== by 0x813D67B: itk::ImageRegistrationMethod<itk::Image<float,
3>, itk::Image<float, 3> >::ImageRegistrationMethod(void)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Algorithms/itkImageRegi
strationMethod.txx:44)
==28336== by 0x818EDFC: itk::ImageRegistrationMethod<itk::Image<float,
3>, itk::Image<float, 3> >::New(void)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Algorithms/itkImageRegi
strationMethod.h:73)
==28336==
==28336== Use of uninitialised value of size 8
==28336== at 0x833B35E: vnl_vector<double>::operator=(vnl_vector<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Utilities/vxl/core/vnl/vnl_v
ector.txx:391)
==28336== by 0x813CC8D: itk::Array<double>::operator=(itk::Array<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Common/itkArray.txx:167
)
==28336== by 0x813D6BC: itk::ImageRegistrationMethod<itk::Image<float,
3>, itk::Image<float, 3> >::ImageRegistrationMethod(void)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Algorithms/itkImageRegi
strationMethod.txx:45)
==28336== by 0x818EDFC: itk::ImageRegistrationMethod<itk::Image<float,
3>, itk::Image<float, 3> >::New(void)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Algorithms/itkImageRegi
strationMethod.h:73)
Intial Parameters =
<snip>
==28336==
==28336== Use of uninitialised value of size 8
==28336== at 0x833B35E: vnl_vector<double>::operator=(vnl_vector<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Utilities/vxl/core/vnl/vnl_v
ector.txx:391)
==28336== by 0x813CC8D: itk::Array<double>::operator=(itk::Array<double>
const &)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Common/itkArray.txx:167
)
==28336== by 0x817D409:
itk::MeanSquaresImageToImageMetric<itk::Image<float, 3>, itk::Image<float,
3> >::GetValueAndDerivative(itk::Array<double> const &, double &,
itk::Array<double> &) const
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Algorithms/itkMeanSquar
esImageToImageMetric.txx:292)
==28336== by 0x819783B: itk::LBFGSBOptimizer::StartOptimization(void)
(/data/home/kris/devel/ITK/InsightToolkit-2.2.0/Code/Numerics/itkLBFGSBOptim
izer.cxx:287)
The first 2 come from the following lines in itkImageRegistrationMethod.txx:
m_InitialTransformParameters = ParametersType(1);
m_LastTransformParameters = ParametersType(1);
I suppose this is because the constructor of ParametersType==Array<double>
does not initialise the values. So, probably the code is really ok, but
having a valgrind error feels a bit strange.
If these members really have to be initialised with an array of length 1 (I
can't see why, but what do I know?) then I believe one solution would be to
rewrite the constructor
template < typename TFixedImage, typename TMovingImage >
ImageRegistrationMethod<TFixedImage,TMovingImage>
::ImageRegistrationMethod()
: m_InitialTransformParameters (1),
m_LastTransformParameters(1)
{
//etc
}
which is generally considered cleaner practice anyway.
The last error comes from a similar line
derivative = DerivativeType( ParametersDimension );
This is not in a constructor, so the above trick doesn't work. However, as
that line is followed by
derivative.Fill( NumericTraits<ITK_TYPENAME
DerivativeType::ValueType>::Zero );
I believe it would be best to replace both lines with
derivative = DerivativeType( ParametersDimensio,
NumericTraits<ITK_TYPENAME
DerivativeType::ValueType>::Zero );
(and similar for the lines in the constructor above).
It seems all a consequence of the fact that Array doesn't have a resize().
So, probably there are countless of these around.
All the best
Kris Thielemans
Hammersmith Imanet, part of GE Healthcare
United Kingdom
More information about the Insight-developers
mailing list