[Insight-developers] itk::VariableLengthVector (and probably other similer classes) allows boundless recursion in operators

Williams, Norman K norman-k-williams at uiowa.edu
Wed Feb 26 15:12:42 EST 2014


That does work.

I'm concerned that this doesn't generate any error and warning and then goes into boundless recursion at runtime:

itk::VariableLengthVector<double> a(3);
a[0] = 1; a[1] = 2; a[2] = 3;
a = a * a;

There are two operator* in VariableLengthVector: a member function and a template function. The template function should be prevented from instantiating in this case.


From: Bradley Lowekamp <blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>>
Date: Monday, February 24, 2014 4:13 PM
To: Mushly McMushmaster <norman-k-williams at uiowa.edu<mailto:norman-k-williams at uiowa.edu>>
Cc: ITK <insight-developers at itk.org<mailto:insight-developers at itk.org>>
Subject: Re: [Insight-developers] itk::VariableLengthVector (and probably other similer classes) allows boundless recursion in operators

Kent,

I bet if you tried a ScalarImage as a template argument it would work as expected.

If disallow the case where:


template< typename TValueType, typename T >
inline
VariableLengthVector< TValueType >
operator*(const T & scalar, const VariableLengthVector< TValueType > & v)

{ return v * scalar; }

T is also of type variable length vector. Perhaps this would work:


template< typename TValueType, typename TValueType2 >
inline
VariableLengthVector< TValueType >
operator*(const VariableLengthVector< TValueType2 > & v, const VariableLengthVector< TValueType > & v); // Intentionally not implemented



On Feb 24, 2014, at 2:26 PM, Williams, Norman K <norman-k-williams at uiowa.edu<mailto:norman-k-williams at uiowa.edu>> wrote:

Logged as a bug; I'd write a patch if I can figure out how to do the C++ template metaprogramming magic.

I ran into this when I needed to multiply an itk::VectorImage by a scalar constant.  Using the MultiplyImageFilter, the SetConstant (and SetConstant1 and SetConstant2) methods only accept InputImage1PixelType as a constant.

So, because I was deep into abstruse code, my naïve solution was to instantiate an itk::VariableLengthVector as the constant to pass to SetConstant, where each element was the scalar constant.

This is, upon further reflection, absurd, because A * B for vectors doesn't even make sense in matrix math, and there's no operator for pairwise multiplication of vector elements.

But what I found out running my program is that itk::VariableLengthVector will instantiate an operator * with boundless recursion.

There are two problems: not disallowing boundless recursion, and not supporting scalar constants for vector Images in itk::BinaryFunctorImageFilter.

https://issues.itk.org/jira/browse/SIMPLEITK-498



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________
_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20140226/1709abe9/attachment.html>


More information about the Insight-developers mailing list