[Insight-developers] Using Math::Floor in interpolation code?

Tom Vercauteren tom.vercauteren at gmail.com
Mon Jul 20 10:13:43 EDT 2009


Hi All,

I saw that several interpolators use the following piece of code:

  // The following "if" block is equivalent to the following line without
  // having to call floor.
  //    baseIndex[dim] = (long) vcl_floor(index[dim] );
  if (index[dim] >= 0.0)
    {
    baseIndex[dim] = (long) index[dim];
    }
  else
    {
    long tIndex = (long) index[dim];
    if (double(tIndex) != index[dim])
      {
      tIndex--;
      }
    baseIndex[dim] = tIndex;
    }


Anyone against changing this to a more efficient and cleaner call to
Math::Floor?

  baseIndex[dim] = Math::Floor( index[dim] );


I guess the initial reason for not using vcl_floor was for
performance. Math::Floor should be faster that both vcl_floor and the
above code.

The attached patch implements this proposal, on my setup, the
experimental build turns out green except for one test that has been
failing for some time when consistent centered pixels is turned on.
http://www.cdash.org/CDash/buildSummary.php?buildid=382493

Regards,
Tom

P.S.: As for the other itk::Math:: routines, the limitations are that
itk::Math::Floor is only guaranteed to work for arguments less than
INT_MAX/2. Also it expects the FPU rounding mode to be the default
one.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itk-InterpolateFloor-2009-07-20.patch
Type: text/x-patch
Size: 16286 bytes
Desc: not available
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090720/e013a7c4/attachment.bin>


More information about the Insight-developers mailing list