<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif; ">
<div>That does work.</div>
<div><br>
</div>
<div>I'm concerned that this doesn't generate any error and warning and then goes into boundless recursion at runtime:</div>
<div><br>
</div>
<div>itk::VariableLengthVector<double> a(3);</div>
<div>a[0] = 1; a[1] = 2; a[2] = 3;</div>
<div>a = a * a;</div>
<div><br>
</div>
<div>There are two operator* in VariableLengthVector: a member function and a template function. The template function should be prevented from instantiating in this case.</div>
<div><br>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Bradley Lowekamp <<a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a>><br>
<span style="font-weight:bold">Date: </span>Monday, February 24, 2014 4:13 PM<br>
<span style="font-weight:bold">To: </span>Mushly McMushmaster <<a href="mailto:norman-k-williams@uiowa.edu">norman-k-williams@uiowa.edu</a>><br>
<span style="font-weight:bold">Cc: </span>ITK <<a href="mailto:insight-developers@itk.org">insight-developers@itk.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [Insight-developers] itk::VariableLengthVector (and probably other similer classes) allows boundless recursion in operators<br>
</div>
<div><br>
</div>
<div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Kent,
<div><br>
</div>
<div>I bet if you tried a ScalarImage as a template argument it would work as expected.</div>
<div><br>
</div>
<div>If disallow the case where:</div>
<div><br>
</div>
<div>
<p style="margin: 16px 0px 0px; padding: 0px; font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; line-height: 17px; background-color: rgb(255, 255, 255);">
template< typename TValueType, typename T ><br>
inline<br>
VariableLengthVector< TValueType ><br>
operator*(const T & scalar, const VariableLengthVector< TValueType > & v)</p>
<span style="font-size: 13px; line-height: 17px; background-color: rgb(255, 255, 255); font-family: Arial, FreeSans, Helvetica, sans-serif; ">{ return v * scalar; }</span></div>
<div><span style="font-size: 13px; line-height: 17px; background-color: rgb(255, 255, 255); font-family: Arial, FreeSans, Helvetica, sans-serif; "><br>
</span></div>
<div><font face="Arial,FreeSans,Helvetica,sans-serif" size="2"><span style="line-height: 17px;">T is also of type variable length vector. Perhaps this would work:</span></font></div>
<div><font face="Arial,FreeSans,Helvetica,sans-serif" size="2"><span style="line-height: 17px;"><br>
</span></font></div>
<div>
<p style="margin: 16px 0px 0px; padding: 0px; font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; line-height: 17px; background-color: rgb(255, 255, 255); position: static; z-index: auto;">
template< typename TValueType, typename TValueType2 ><br>
inline<br>
VariableLengthVector< TValueType ><br>
operator*(const VariableLengthVector< TValueType2 > & v, const VariableLengthVector< TValueType > & v); // Intentionally not implemented</p>
</div>
<div><span style="font-size: 13px; line-height: 17px; background-color: rgb(255, 255, 255); font-family: Arial, FreeSans, Helvetica, sans-serif; "><br>
</span></div>
<div><br>
</div>
<div><br>
<div>
<div>On Feb 24, 2014, at 2:26 PM, Williams, Norman K <<a href="mailto:norman-k-williams@uiowa.edu">norman-k-williams@uiowa.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; font-size: 14px; font-family: Calibri, sans-serif;">
<div>Logged as a bug; I'd write a patch if I can figure out how to do the C++ template metaprogramming magic.</div>
<div><br>
</div>
<div>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. </div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>But what I found out running my program is that itk::VariableLengthVector will instantiate an operator * with boundless recursion.</div>
<div><br>
</div>
<div>There are two problems: not disallowing boundless recursion, and not supporting scalar constants for vector Images in itk::BinaryFunctorImageFilter.</div>
<div><br>
</div>
<div><a href="https://issues.itk.org/jira/browse/SIMPLEITK-498">https://issues.itk.org/jira/browse/SIMPLEITK-498</a></div>
<div><br>
</div>
<br>
<br>
<hr>
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.
<hr>
</div>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://kitware.com/products/protraining.php">http://kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-developers">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</span><br>
<br>
<hr>
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.
<hr>
</body>
</html>