No subject


Mon Aug 10 18:29:21 EDT 2009


approach. The only issue I still have is about the backward<br>
compatibility policy. The rounding functions need some helper<br>
functions. It would be better if those helper functions were not<br>
subject to any backward compatibility requirement. Here are three<br>
possibilities I can think of:<br>
<br>
<br>
1) All namespace approach<br>
---------------------------------------<br>
Advantage: seems clearer to me<br>
Drawback: No control on the access to th helper functions in Math::Detail<b=
r>
<div class=3D"im"><br>
namespace Math<br>
 =A0{<br>
 =A0const double p =3D 3.14;<br>
<br>
</div> =A0namespace Detail<br>
 =A0 =A0{<br>
 =A0 =A0// Things here are excluded from the backward-compatibility policy<=
br>
 =A0 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0 =A0inline TReturn RoundHelper(TInput x, TReturn * =3D 0) { [snip] }<br=
>
 =A0 =A0}<br>
<br>
 =A0// The second argument is fro msvc 6 compatibility<br>
 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0inline TReturn Round(TInput x, TReturn * =3D 0)<br>
 =A0 =A0{<br>
 =A0 =A0return Detail::RoundHelper&lt;TReturn&gt;(x);<br>
 =A0 =A0}<br>
 =A0}<br>
<br>
<br>
<br>
2) All class approach<br>
--------------------------------<br>
Advantage: Helper functions not accessible to the users<br>
Drawback: Somehow confusing for me to have a class with only static<br>
members and functions (Also potential compiler optimization loss??)<br>
<br>
class Math<br>
{<br>
public:<br>
 =A0static const double pi;<br>
<br>
 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0static inline TReturn Round(TInput x, TReturn * =3D 0)<br>
 =A0 =A0{<br>
 =A0 =A0return RoundHelper&lt;TReturn&gt;(x);<br>
 =A0 =A0}<br>
<br>
private:<br>
 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0static inline TReturn RoundHelper(TInput x, TReturn * =3D 0) { [snip] }=
<br>
};<br>
<br>
const double Math::pi =3D 3.14;<br>
<br>
<br>
<br>
3) Mixed namespace-class approach<br>
-----------------------------------------------------<br>
Advantage: Helper functions not accessible to the users, constants are<br>
defined next to their declaration<br>
Drawback: More complex code due to template friend functions<br>
<div class=3D"im"><br>
namespace Math<br>
 =A0{<br>
 =A0const double p =3D 3.14;<br>
<br>
</div> =A0// Forward declarations<br>
 =A0class MathDetail;<br>
 =A0template&lt;typename TReturn, typename TInput&gt;<br>
 =A0TReturn =A0Round(TInput, TReturn *);<br>
<br>
 =A0class MathDetail<br>
 =A0{<br>
 =A0public:<br>
 =A0 =A0template&lt;typename TReturn, typename TInput&gt;<br>
 =A0 =A0friend inline TReturn Round(TInput x, TReturn * =3D 0);<br>
<br>
 =A0private:<br>
 =A0 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0 =A0static inline TReturn RoundHelper(TInput x, TReturn * =3D 0) { [sni=
p] }<br>
 =A0}<br>
<br>
 =A0template &lt;typename TReturn, typename TInput&gt;<br>
 =A0inline TReturn Round(TInput x, TReturn * =3D 0)<br>
 =A0 =A0{<br>
 =A0 =A0return MathDetail::RoundHelper&lt;TReturn&gt;(x);<br>
 =A0 =A0}<br>
 =A0}<br>
<br>
<br>
It seems to me we should wait until after the release to implement any<br>
of these option. What do you think?<br>
<br>
Cheers,<br>
<font color=3D"#888888">Tom<br>
</font><div><div></div><div class=3D"h5"><br>
<br>
On Sat, Aug 8, 2009 at 16:18, Bradley Lowekamp&lt;<a href=3D"mailto:bloweka=
mp at mail.nih.gov">blowekamp at mail.nih.gov</a>&gt; wrote:<br>
&gt; Currently we have two things we would like to put into itk::Math, weat=
her it<br>
&gt; be a namespace or a class. The first is the rounding methods and the s=
econd<br>
&gt; is the numeric constants. For the numeric constants consider these two=
<br>
&gt; different possibilities:<br>
&gt;<br>
&gt;<br>
&gt; math.h:<br>
&gt; class Math<br>
&gt; {<br>
&gt; =A0 =A0 =A0 =A0static const double p;<br>
&gt; }<br>
&gt;<br>
&gt; math.cxx:<br>
&gt; const double p =3D 3.14;<br>
&gt;<br>
&gt; Where as with a namespace, we don&#39;t need the static qualifier and =
I believe<br>
&gt; the following will not have the linking issues, and is valid c++:<br>
&gt;<br>
&gt; math.h:<br>
&gt; namespace Math {<br>
&gt; =A0 =A0 =A0 =A0const double p =3D 3.14;<br>
&gt; };<br>
&gt;<br>
&gt;<br>
&gt; With the namespace implementation we can always get optimizations, but=
 there<br>
&gt; will be multiple addresses in different compilation files. I don&#39;t=
 believe<br>
&gt; that that latter is really a negative though.<br>
&gt;<br>
&gt;<br>
&gt; Brad<br>
&gt;<br>
&gt;<br>
&gt; On Aug 6, 2009, at 11:21 AM, Tom Vercauteren wrote:<br>
&gt;<br>
&gt;&gt; Hi Brad,<br>
&gt;&gt;<br>
&gt;&gt; Moving these mathematical constants to a more visible place sounds=
<br>
&gt;&gt; good to me. However, handling floating point constants in c++ is a=
<br>
&gt;&gt; pain. For example, the following code is not standard and won&#39;=
t be<br>
&gt;&gt; usable on several systems (mac gcc 4.0 at least):<br>
&gt;&gt;<br>
&gt;&gt; class No_Good {<br>
&gt;&gt; =A0static double const d =3D 1.0;<br>
&gt;&gt; };<br>
&gt;&gt;<br>
&gt;&gt; I guess that&#39;s why boost chose to implement these constants as=
<br>
&gt;&gt; template functions:<br>
&gt;&gt;<br>
&gt;&gt; <a href=3D"http://www.boost.org/doc/libs/1_39_0/libs/math/doc/sf_a=
nd_dist/html/math_toolkit/toolkit/internals1/constants.html" target=3D"_bla=
nk">http://www.boost.org/doc/libs/1_39_0/libs/math/doc/sf_and_dist/html/mat=
h_toolkit/toolkit/internals1/constants.html</a><br>

&gt;&gt;<br>
&gt;&gt; The other option is to decouple the definition and declaration as =
done<br>
&gt;&gt; in vnl =A0(with some ugly macro):<br>
&gt;&gt;<br>
&gt;&gt; class Now_Better<br>
&gt;&gt; {<br>
&gt;&gt; =A0 static double const d;<br>
&gt;&gt; };<br>
&gt;&gt;<br>
&gt;&gt; double const Now_Better::d =3D 1.0;<br>
&gt;&gt;<br>
&gt;&gt; More information can be found here:<br>
&gt;&gt;<br>
&gt;&gt; <a href=3D"http://stackoverflow.com/questions/370283/why-cant-i-ha=
ve-a-non-integral-static-const-member-in-a-class" target=3D"_blank">http://=
stackoverflow.com/questions/370283/why-cant-i-have-a-non-integral-static-co=
nst-member-in-a-class</a><br>

&gt;&gt;<br>
&gt;&gt; No matter the implementation, I would definitely vote for replacin=
g<br>
&gt;&gt; the current hard-coded values by a common thing such as vnl_math::=
pi,<br>
&gt;&gt; itk::Math::pi, or =A0itk::Math::pi&lt;double&gt;().<br>
&gt;&gt;<br>
&gt;&gt; My two cents,<br>
&gt;&gt; Tom<br>
&gt;&gt;<br>
&gt;&gt; On Thu, Aug 6, 2009 at 16:40, Bradley Lowekamp&lt;<a href=3D"mailt=
o:blowekamp at mail.nih.gov">blowekamp at mail.nih.gov</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Hello,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =A0 =A0 =A0 I was looking at:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; BasicFilters/itkBilateralImageFilter.txx: =A0rangeGaussianDeno=
m =3D<br>
&gt;&gt;&gt; m_RangeSigma*vcl_sqrt(2.0*3.1415927);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; It took me a little bit to figure out that we most likely shou=
ld be using<br>
&gt;&gt;&gt; vnl_math::pi, along with their &quot;e and all that&quot;. I d=
o wonder if these<br>
&gt;&gt;&gt; constants were in itk::Math and in doxygen if it would help wi=
th<br>
&gt;&gt;&gt; increased<br>
&gt;&gt;&gt; usage.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; So I began greping in the &quot;Code&quot; directory and came =
up with the<br>
&gt;&gt;&gt; following:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; grep -r 3.1415 *<br>
&gt;&gt;&gt; BasicFilters/itkBilateralImageFilter.txx: =A0rangeGaussianDeno=
m =3D<br>
&gt;&gt;&gt; m_RangeSigma*vcl_sqrt(2.0*3.1415927);<br>
&gt;&gt;&gt; BasicFilters/itkVectorGradientMagnitudeImageFilter.txx: =A0con=
st double dpi<br>
&gt;&gt;&gt; =3D<br>
&gt;&gt;&gt; 3.14159265358979323846;<br>
&gt;&gt;&gt; Common/itkGaussianDerivativeSpatialFunction.txx: =A0 =A0prefix=
Denom *=3D<br>
&gt;&gt;&gt; 2*vcl_pow( 2 * 3.1415927, VImageDimension / 2.0);<br>
&gt;&gt;&gt; Common/itkMersenneTwisterRandomVariateGenerator.h: =A0double p=
hi =3D 2.0 *<br>
&gt;&gt;&gt; 3.14159265358979323846264338328<br>
&gt;&gt;&gt; Numerics/itkCumulativeGaussianOptimizer.cxx: =A0m_ComputedAmpl=
itude =3D =A0sum<br>
&gt;&gt;&gt; /<br>
&gt;&gt;&gt; (m_ComputedStandardDeviation * vcl_sqrt(2*3.14159265));<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; grep -r 0.707 *<br>
&gt;&gt;&gt; BasicFilters/itkBSplineResampleImageFilterBase.txx: =A0 =A0 =
=A0m_G[0] =A0=3D<br>
&gt;&gt;&gt; =A00.707107;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; grep -r 1.414 *<br>
&gt;&gt;&gt; Numerics/Statistics/itkGaussianDistribution.cxx: =A0 =A0dq =A0=
=3D 0.5e+0 *<br>
&gt;&gt;&gt; vnl_erfc(<br>
&gt;&gt;&gt; dx / 1.414213562373095e+0 ) - dp;<br>
&gt;&gt;&gt; Review/Statistics/itkGaussianDistribution.cxx: =A0 =A0dq =A0=
=3D 0.5e+0 *<br>
&gt;&gt;&gt; vnl_erfc(<br>
&gt;&gt;&gt; dx / 1.414213562373095e+0 ) - dp;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; grep -r vnl_math:: * | wc<br>
&gt;&gt;&gt; =A0 =A0 69 =A0 =A0 571 =A0 =A07652<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Well I guess that is almost 90% usage of the numeric constants=
, so its<br>
&gt;&gt;&gt; not<br>
&gt;&gt;&gt; bad at all.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;ll work on a patch tonight, and likely commit something =
tomorrow if no<br>
&gt;&gt;&gt; one<br>
&gt;&gt;&gt; sees a problem with this.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Brad<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Powered by <a href=3D"http://www.kitware.com" target=3D"_blank=
">www.kitware.com</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Visit other Kitware open-source projects at<br>
&gt;&gt;&gt; <a href=3D"http://www.kitware.com/opensource/opensource.html" =
target=3D"_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt;&gt;&gt; <a href=3D"http://www.itk.org/Wiki/ITK_FAQ" target=3D"_blank">=
http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Follow this link to subscribe/unsubscribe:<br>
&gt;&gt;&gt; <a href=3D"http://www.itk.org/mailman/listinfo/insight-develop=
ers" target=3D"_blank">http://www.itk.org/mailman/listinfo/insight-develope=
rs</a><br>
&gt;&gt;&gt;<br>
&gt;<br>
&gt;<br>
_______________________________________________<br>
Powered by <a href=3D"http://www.kitware.com" target=3D"_blank">www.kitware=
.com</a><br>
<br>
Visit other Kitware open-source projects at <a href=3D"http://www.kitware.c=
om/opensource/opensource.html" target=3D"_blank">http://www.kitware.com/ope=
nsource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href=3D"http://w=
ww.itk.org/Wiki/ITK_FAQ" target=3D"_blank">http://www.itk.org/Wiki/ITK_FAQ<=
/a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href=3D"http://www.itk.org/mailman/listinfo/insight-developers" target=
=3D"_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
</div></div></blockquote></div><br>

--0015175ce1427ee5460470de04c3--


More information about the Insight-developers mailing list