<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19258"></HEAD>
<BODY
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space">
<DIV dir=ltr align=left><SPAN class=171181116-23082012><FONT size=2
face=Verdana>Yes, thanks. It works when I explicitly pass the template
parameter. But in my case I don't want to have to do that because I'm modifying
CentralDifferenceImageFunction::Evaluate* methods, which doesn't seem like a
good method to change if not absolutely necessary.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=171181116-23082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=171181116-23082012><FONT size=2
face=Verdana>-M</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> Bradley Lowekamp
[mailto:blowekamp@mail.nih.gov] <BR><B>Sent:</B> Thursday, August 23, 2012
8:22 AM<BR><B>To:</B> M Stauffer -V-<BR><B>Cc:</B>
Insight-developers@itk.org<BR><B>Subject:</B> Re: [Insight-developers]
Overloading methods<BR></FONT><BR></DIV>
<DIV></DIV>Hello,
<DIV><BR></DIV>
<DIV>The reason you methods is not working is because C++ can't deduce the
template parameters from the argument types passed to the function. That is to
say since T is only used for the return type, and not as an argument to the
function, so you should explicitly specify it as a template parameters.
Something like this should work:</DIV>
<DIV><BR></DIV>
<DIV>r = this->EnableIfTest<OutputType>( 3 );</DIV>
<DIV><BR></DIV>
<DIV>Brad</DIV>
<DIV>
<DIV><BR></DIV>
<DIV><BR>
<DIV>
<DIV>On Aug 22, 2012, at 4:08 PM, M Stauffer -V- wrote:</DIV><BR
class=Apple-interchange-newline>
<BLOCKQUOTE type="cite">
<META name=GENERATOR content="MSHTML 8.00.6001.19258">
<DIV
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space">
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana>Great, thanks Brad.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana>I can reproduce what you explain below, but it's not working
when I rely on only the return parameter type for the template parameter
deduction. That is, the following won't compile</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana>template< typename T ><BR>typename EnableIfC<
IsSame< T, ScalarDerivativeType >::Value, T
>::Type<BR>EnableIfTest(int val)<BR>{<BR> std::cout <<
"Output == ScalarDerivativeType. val " << val << "\n" <<
std::endl;<BR> T o;<BR> o.Fill(1);<BR> return
o;<BR>}<BR></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana>(and similarly with DisableIfC...)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana>In implementation:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=656050320-22082012><FONT size=2
face=Verdana> OutputType r;<BR></FONT></SPAN><SPAN
class=656050320-22082012><FONT size=2 face=Verdana> r =
this->EnableIfTest(3);<BR></FONT></SPAN></DIV>
<DIV><SPAN class=656050320-22082012><FONT size=2 face=Verdana>I think I'll
skip this for now because I have a working implementation and the extra
overhead it has, because it requires a nested function call, is only a
few %.</FONT></SPAN></DIV>
<DIV><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV><SPAN class=656050320-22082012><FONT size=2 face=Verdana>I'll put up a
patch soon and hopefully you could take a look at it, Brad. I'll let you
know.</FONT></SPAN></DIV>
<DIV><SPAN class=656050320-22082012><FONT size=2
face=Verdana></FONT></SPAN> </DIV>
<DIV><SPAN class=656050320-22082012><FONT size=2
face=Verdana>-M</FONT></SPAN></DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><FONT size=2 face=Verdana></FONT> </DIV>
<DIV><BR></DIV>
<BLOCKQUOTE
style="Z-INDEX: auto; POSITION: static; BORDER-LEFT: rgb(0,0,0) 2px solid; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> Bradley Lowekamp
[mailto:blowekamp@mail.nih.gov] <BR><B>Sent:</B> Tuesday, August 21, 2012
3:37 PM<BR><B>To:</B> Michael Stauffer<BR><B>Cc:</B> <A
href="mailto:Insight-developers@itk.org">Insight-developers@itk.org</A><BR><B>Subject:</B>
Re: [Insight-developers] Overloading methods<BR></FONT><BR></DIV>
<DIV></DIV>Hello Michael,
<DIV><BR></DIV>
<DIV>Here is the declaration of one of the GetComponent methods:</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>template< typename T></DIV>
<DIV> typename EnableIfC<</DIV>
<DIV> IsSame<T, typename
NumericTraits<T>::ValueType>::Value,</DIV>
<DIV> T >::Type</DIV>
<DIV> GetComponent(const T pix,</DIV>
<DIV> unsigned int
itkNotUsed( idx ) ) const;</DIV></DIV>
<DIV><BR></DIV>
<DIV>This uses the EnableIf idom to answer lets look at a simplification
of function:</DIV>
<DIV><BR></DIV>
<DIV>
<DIV>template< typename T> T GetComponent(const T
pix, unsigned int idx ) const;</DIV></DIV>
<DIV><BR></DIV>
<DIV>So I just simplified it some. So for function C++ has the ability to
implicitly deduce the template parameters from the arguments passed to a
function. So if you did the following:</DIV>
<DIV><BR></DIV>
<DIV>int i;</DIV>
<DIV>GetComponent( i, 10 )</DIV>
<DIV><BR></DIV>
<DIV>C++ can deduce the template parameter T, based on the function
argument i being of type int.</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>There are a couple C++ tricks to overloading functions that
should be considered before the EnableIf idiom should be considered. Using
the EnableIf idom is really a last resort when simpler more understandable
techniques can not be used.</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>Brad</DIV>
<DIV><BR>
<DIV>
<DIV>On Aug 17, 2012, at 6:17 PM, Michael Stauffer wrote:</DIV>
<BLOCKQUOTE type="cite">
<DIV>I'm using the new EnableIfC and DisableIfC routines, to try and
optimize itkCentralDifferenceImageFunction::Evaluate* methods by
specializing for scalar and vector pixel types. I have it working using
my own SFINAE method I pulled off the web. But this, requires calling
templated subfunctions, which cost about 2% in
overhead.<BR><BR></DIV></BLOCKQUOTE>
<BLOCKQUOTE type="cite">
<DIV><BR>Looking at itkEnableIf.h and its usage in
PatchBasedDenoisingImageFilter, I was hoping to be able to call the
specialized Evalute* methods directly.<BR><BR><BR>The method
PatchBasedDenoisingImageFilter::GetComponent is are template-specialized
to use one of two versions depending on whether the pixel is scalar or
not. The method is templated.<BR>But in
PatchBasedDenoisingImageFilter::ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(),
GetComponent is called without any template parameters. How does this
work? I must be missing something.<BR><BR><BR><BR><BR>template
<BR>void<BR>PatchBasedDenoisingImageFilter<BR>::ComputeSignedEuclideanDifferenceAndWeightedSquaredNorm(const
PixelType& a, const PixelType& b,<BR>const RealArrayType&
weight,<BR>bool itkNotUsed(useCachedComputations),<BR>SizeValueType
itkNotUsed(cacheIndex),<BR>EigenValuesCacheType&
itkNotUsed(eigenValsCache),<BR>EigenVectorsCacheType&
itkNotUsed(eigenVecsCache),<BR>RealType& diff, RealArrayType&
norm)<BR>{<BR>for (unsigned int pc = 0; pc < m_NumPixelComponents;
++pc)<BR>{<BR>RealValueType tmpDiff = GetComponent(b, pc) -
GetComponent(a, pc);<BR>RealValueType tmpWeight =
weight[pc];<BR>SetComponent(diff, pc, tmpDiff);<BR>norm[pc] = tmpWeight
* tmpWeight * tmpDiff *
tmpDiff;<BR>}<BR>}<BR><BR></DIV></BLOCKQUOTE></DIV><BR>
<DIV>
<DIV
style="WORD-WRAP: break-word; FONT-SIZE: 12px; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"><SPAN
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto"
class=Apple-style-span>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>========================================================</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Bradley Lowekamp<SPAN
class=Apple-converted-space> </SPAN><SPAN
class=Apple-converted-space> </SPAN></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Medical Science and Computing for</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Office of High Performance Computing and
Communications</FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>National Library of Medicine<SPAN
class=Apple-converted-space> </SPAN></FONT></DIV>
<DIV style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica><A
href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</A></FONT></DIV><BR
class=Apple-interchange-newline></SPAN></DIV><BR
class=Apple-interchange-newline></DIV><BR></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV><BR>
<DIV><SPAN
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: medium Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px"
class=Apple-style-span><SPAN
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto"
class=Apple-style-span>
<DIV
style="WORD-WRAP: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space"><SPAN
style="WIDOWS: 2; TEXT-TRANSFORM: none; TEXT-INDENT: 0px; BORDER-COLLAPSE: separate; FONT: 12px Helvetica; WHITE-SPACE: normal; ORPHANS: 2; LETTER-SPACING: normal; COLOR: rgb(0,0,0); WORD-SPACING: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto"
class=Apple-style-span>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>========================================================</FONT></P>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Bradley Lowekamp<SPAN
class=Apple-converted-space> </SPAN><SPAN
class=Apple-converted-space> </SPAN></FONT></P>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Medical Science and Computing for</FONT></P>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>Office of High Performance Computing and
Communications</FONT></P>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica>National Library of Medicine<SPAN
class=Apple-converted-space> </SPAN></FONT></P>
<P style="MARGIN: 0px"><FONT style="FONT: 12px Helvetica" size=3
face=Helvetica><A
href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</A></FONT></P><BR
class=Apple-interchange-newline></SPAN></DIV></SPAN></SPAN><BR
class=Apple-interchange-newline></DIV><BR></DIV></DIV></BLOCKQUOTE></BODY></HTML>