[Insight-developers] Rounding Test : Redux

Simon Warfield simon.warfield at childrens.harvard.edu
Sun Mar 8 12:38:43 EDT 2009


>
> Folks,
>
> Recall the long discussion regarding rounding. Although we never came
> to consensus, we do have a test that is failing on VS platforms.
>
> itkVNLRoundProfileTest1.cxx fails on these platforms because
> vnl_math_rnd does round-to-even while other platforms do
> round-to-nearest. Regardless of what we decide, having a constantly
> failing test is nbot a good practice. Since we know vnl_math_rnd is
> not platform-independent, I propose removing the pass/fail portion of
> this test. We should keep the test since it still provides useful
> profiling info.
>
> BTW: on gcc systems, rint() also does round-to-even by default. vxl
> uses lround() which does round-to-nearest.
>
> Comments?
>
> Bill
Hi Bill,

  I am interested in resolving the aspect of rounding related to the 
definition of the physical coordinate system.
 
One way ITK uses rounding is to identify the extent of a voxel by 
rounding a continuous index.
This use of rounding defines the extent of a voxel. For example, the 
point that is the origin is in the middle of the voxel at index (0,0,0),
and the extent of that voxel is defined by transforming the physical 
coordinates of the voxel into a continuous index, and then rounding the 
continuous index to identify the integer index (e.g. a continuous index 
of (-0.4, 0.3, 0.2) rounds to (0,0,0).

  If round to even is used for this task, then every second voxel, 
despite having the same physical size, is treated as slightly thinner 
than its neighbors. Using round to nearest ensures that all voxels have 
the same size.  Therefore, I favour round to nearest for this task.

In order for all platforms to have the same definition of the physical 
extent of each voxel, the rounding behaviour needs to be the same
on each platform.

The transformation of physical points into indexes can occur frequently, 
and so should be efficient. I think the efficiency is the second issue 
to consider, after having first defined the nature of the rounding we 
need in physical coordinate to voxel index conversion.
That said, lround() is very efficient on x86/x86_64 platforms, it can be 
even faster than truncation (see discussion at 
http://www.itk.org/Bug/view.php?id=6558 )

If we can't decide on a general purpose implementation of 
vnl_math_round() then we could decide to replace it as the rounding 
function used in the physical space transformations, and use an 
efficient cross-platform round-to-nearest-integer for that task.

-- 
Simon 




More information about the Insight-developers mailing list