[vtk-developers] vtkImageReslice performance questions/improvemnts

David Gobbi david.gobbi at gmail.com
Thu Sep 23 19:11:54 EDT 2010


On Thu, Sep 23, 2010 at 4:45 PM, Sean McBride <sean at rogue-research.com> wrote:
> On Thu, 23 Sep 2010 11:06:37 -0600, David Gobbi said:

> For fun, I searched VTK for "i386"... there are 48 occurrences.  Taking
> a look through them, I note the following:
>
> 1) vtkGridTransform.cxx seems to have copy-pasted vtkResliceFloor and
> named it vtkGridFloor.  They were mostly identical, but I suppose
> they've now diverged further after your commit.  This duplication
> suggests that this code should move to vtkMath (or somewhere).
>
>
> 2) I noticed that vtkMath::Floor() has an "#if defined i386" but no
> other special cases.... I wonder if it's worth adding others?

Ugh.  Yeah, if you really look hard you'll find tons of "Floor" and
"Round" definitions in VTK, either as inline functions or as
preprocessor macros.  It is so hard to reach a consensus about the
best way to do these things.

My vtkResliceFloor is no good as a "general purpose" round because it
is not exact.  If a float number is just barely below an integer, it
will be rounded up instead of down (this is true for both the i386 and
the new x86_64 code).  For vtkImageReslice, this property of having it
"stick to the integers" helps to add stability to the results in the
face of roundoff errors in the transformation.  But for other uses in
VTK, this would not be so good.

The vtkMath::Floor() needs to be more exact.  Its i386-trick is more
exact than the one I have in vtkImageReslice.  It could have the
following acceleration in place of floor() for non-i386 systems.

  if (x >= 0)
    {
    return static_cast<int>(x);
    }
  else
    {
    return -static_cast<int>(-x);
    }

Then there is also vtkFastNumericConversion.h, which is used mainly by
vtkFixedPointVolumeRayCastMapper.  So, yeah, lots of round/floor
functions and they dont all have exactly the same roundoff/error
behavior.

But I should definitely unify the code between GridWarp and
ImageReslice.  Thanks for pointing that out.

  David



More information about the vtk-developers mailing list