[Insight-users] Operator for VariableLengthVector

Emmanuel Christophe emmanuel.christophe at gmail.com
Fri Dec 14 03:41:47 EST 2007


Hi,

I don't know what is ITK policy for this, but I wouldn't have done it
exactly this way:
 - always converting to double can be costly in term of processing
time (especially when this is done on each pixel)
 - as the ITK user is programming in C++ he should expect the division
to be an integer division if both numerator and denominator are int
and the division to be a real division if at least one of the
numerator or denominator is real.

Given these points why not just cast on the result: static_cast<
ValueType > (m_Data[i] /  s ) ?

The same modifications should also be applied to the operator* and *= I think.

Regards,
Emmanuel


2007/12/13, Karthik Krishnan <karthik.krishnan at kitware.com>:
> Thanks for the report. Fixed in CVS
>
> /cvsroot/Insight/Insight/Code/Common/itkVariableLengthVector.h,v
>  <--  itkVariableLengthVector.h
> new revision: 1.12; previous revision: 1.11
>
>
> --
> Karthik Krishnan
> R&D Engineer,
> Kitware Inc.
>
>
>
> On 12/13/07, Emmanuel Christophe <emmanuel.christophe at gmail.com > wrote:
> >
> > Hi,
> >
> > I noticed that the operator / for VariableLengthVector (in
> > itkVariableLengthVector.h)  is defined as (as well as most operator):
> >
> >   template< class T > inline Self operator/( T s ) const
> >     {
> >     Self result( m_NumElements );
> >     for( ElementIdentifier i=0; i< m_NumElements; i++ )
> >       {
> >       result[i] = m_Data[i] / (static_cast< ValueType >( s ));
> >       }
> >     return result;
> >     }
> >
> > Wouldn't it make more sense to apply the cast after the operation, as:
> > result[i] = static_cast< ValueType >( m_Data[i] /  s );
> >
> > In the situation where the VariableLengthVector is templated on int
> > and s on double, the result would be closer to what is expected by the
> > user.
> >
> > Regards,
> > Emmanuel
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>


More information about the Insight-users mailing list