[Insight-users] Operator for VariableLengthVector

Karthik Krishnan karthik.krishnan at kitware.com
Fri Dec 14 08:45:49 EST 2007


On 12/14/07, Emmanuel Christophe <emmanuel.christophe at gmail.com> wrote:
>
> 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 ) ?


That should read
  static_cast< ValueType >( static_cast< RealValueType >(m_Data[i]) /
static_cast< RealValueType >(s) );

Math operations should as far as possible be performed in the highest
available precision, (definitely when you run a chance of an under/overflow)
and hence they use NumericTraits::RealType.   static_cast is a compile time
cast and is the fastest cast possible (as fast as C style casts). Sure it
adds a line or two more of machine code... but its not much of a concern.

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


Yes

Thanks
-- 
Karthik Krishnan
R&D Engineer,
Kitware Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071214/f14d62e4/attachment.html


More information about the Insight-users mailing list