[vtk-developers] vtkMath inline choices...

Will Schroeder will.schroeder at kitware.com
Mon Jan 31 15:12:58 EST 2011


It's been a long time but I remember using templating magic in particular
C++ numeric_limits which has some support for NaN...does it make sense to
use something along these lines? ITK uses numeric traits pretty extensively,
but I'm not sure whether it would fit into the VTK world.

W

On Mon, Jan 31, 2011 at 1:51 PM, David Gobbi <david.gobbi at gmail.com> wrote:

> I think it is best if all code that uses isnan() is explicit about the
> data type, rather than using an overloaded isnan().
>
> The reason is as follows: when I see any float/double function
> being applied to an integer, including functions like sin(), cos(),
> rint(), etcetera, my immediate thought is "something is wrong
> here".  And I don't want to have to search for a header file and
> look at the isnan() definition to convince myself that the code is,
> in fact, correct.  I'd rather have the code in vtkLookupTable.cxx
> (or in any other class that uses isnan) be sufficiently explicit
> that I don't have to look elsewhere.
>
> That's just my 2 cents.
>
>  - David
>
>
> On Mon, Jan 31, 2011 at 11:17 AM, Moreland, Kenneth <kmorel at sandia.gov>
> wrote:
> > Since we are talking about inlining vtkMath::IsNaN anyway, why not just
> > provide overloaded inlined functions for integer types that always return
> > false?  That way the compiler removes the check for you without having to
> > write any type-dependent case code.
> >
> > -Ken
> >
> >
> > On 1/30/11 11:24 AM, "David Gobbi" <david.gobbi at gmail.com> wrote:
> >
> > Hi Ken,
> >
> > The main issue with performance and IsNan() is more about how it is used
> > than about whether it is inlined.  My guess is that Sean saw a
> performance
> > hit because IsNan() was used inside vtkLookupTable, which has some of the
> > hottest loops in all of VTK.  The IsNan() check was applied to all
> > datatypes, even though it is not relevant for integer data.
> >
> > I've patched vtkLookupTable so that it overloads vtkLinearLookup() and
> the
> > IsNan check is only done on float and double.  The new code gives me a
> 40%
> > speedup in color mapping a 16-bit image to RGBA.  The patch can be seen
> > here: http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=1c348fcb.  I merged
> it
> > directly into master.
> >
> > There is also a function in vtkScalarsToColorsPainter that applies
> IsNan()
> > regardless of scalar type.  It could benefit from a similar patch.
> >
> >  - David
> >
> >
> >
> >    ****      Kenneth Moreland
> >     ***      Sandia National Laboratories
> > ***********
> > *** *** ***  email: kmorel at sandia.gov
> > **  ***  **  phone: (505) 844-8919
> >     ***      web:   http://www.cs.unm.edu/~kmorel
> >
> >
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>


-- 
William J. Schroeder, PhD
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
will.schroeder at kitware.com
http://www.kitware.com
(518) 881-4902
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110131/bdf55d8a/attachment.html>


More information about the vtk-developers mailing list