[Insight-developers] Templated itk::Math floating point to integer proposal

Tom Vercauteren tom.vercauteren at m4x.org
Mon Jul 27 12:53:40 EDT 2009


Hi all,

Following some discussion on this list, we figured out that the
current itk::Math floating point to integer were somewhat too limited
because they can currently only return "int" intergers. This might be
a problem since the major use of the itk::Math functions is for
conversion of indexes which are currently represented as "long int".

Since it is possible to have 64-bit version of these floating point to
integer functions, it appears that having a templated return type
would be a step towards a better solution.

The only problem with this solution is that we cannot reuse the same
name because:

1) replacing
  int  itk::Math::Round( double x )
by
  template <typename TReturn>
  TReturn itk::Math::Round( double x)
would break backward compatibility

2) Using a default template argument is not an option since this is
not allowed by the standard (see e.g.
http://codeidol.com/cpp/cpp-templates/Future-Directions/Default-Function-Template-Arguments/)


My current approach is to leave the current functions as is and add a
templated version of them. They are prepended by a capital T, e.g.
  template <typename TReturn>
  TReturn itk::Math::TRound( double x)

If anyone has a better proposal, I'll be glad to hear.

The following patch
  http://www.itk.org/Bug/file_download.php?file_id=2383&type=bug
implements that proposal but there are a few things I would like to
get feedback on:

1) I chose to put the new code in a new file (Code/Common/itkMath.h)
and remove the itk::Math code from itkMacro.h. itkMacro.h includes
tkMath.h for backward compatibility

2) I have added a itk::Math::Detail namespace within itk::Math to put
helper functions that should not be used by end-users but need to be
in the header file to be potentially inlined

3) I chose not to directly rely on the functions from vnl_math.h to
ease the process of writting and modifying these functions

4) My helper functions rely on vxl_int_64 and  vxl_int_32 as a hope to
get a portable fixed-width integer within ITK


Also, I am not sure if it's still time to commit something like that.
There is no release schedule for 3.16
  http://www.vtk.org/Wiki/ITK_Release_Schedule
But if we are close to the feature freeze, I'll definitely hold on
before moving on.

Regards,
Tom


More information about the Insight-developers mailing list