[Insight-developers] Warning in itkScalarConnectedComponentImageFilter

Luis Ibanez luis.ibanez at kitware.com
Fri Jul 3 12:46:09 EDT 2009


Hi Kevin,

You may need a small change to make this coder truly generic.


The code:

TInput absDifference = static_cast<TInput>( vnl_math_abs( a-b ) );

Where

                     a and b are of type "TInput"

Will produce incorrect result for any "unsigned" integer type
(unsigned char, int, long).

For example:

  unsigned int k = 100;
  unsigned int p = 10;

  std::cout << p - k << std::endl;

produces:

            4294967206

instead of the "-90" that one would
expect at first sight.


The generic code should be of the form:

   typedef itk::NumericTraits<TInput>::RealType InputRealType;

   TInput absDifference = static_cast<TInput>(
         vnl_math_abs(  static_cast<InputRealType>( a ) -
                                static_cast<InputRealType>( b )  ) );


BTW: If you commit the code, please make sure that you will
         monitor the Dashboard in the following hours, as well
         as the Nightlies that will show up tomorrow.


    Regards,


           Luis


-------------------------------------------------------------------
On Fri, Jul 3, 2009 at 12:20 PM, Kevin H. Hobbs <hobbsk at ohiou.edu> wrote:

> When the itkScalarConnectedComponentImageFilter is instantiated with an
> int pixel type gcc produces a warning like the first one on the farsight
> dashboard here:
>
> http://www.cdash.org/CDash/viewBuildError.php?type=1&buildid=369974
>
> The line in question is :
>
> return (vnl_math_abs(a-b) <= m_Threshold);
>
> Stephen Aylward suggested on the farsight developers list here:
>
>
> http://www.kitware.com/cgi-bin/mailman/private/farsight-developers/2009-June/000113.html
>
> that this should be something like :
>
> TInput absDifference = static_cast<TInput>( vnl_math_abs( a-b ) );
> if( absDifference <= m_Threshold )
>  {
>  return true;
>  }
> else
>  {
>  return false;
>  }
>
> May I make this change?
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-developers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20090703/4283901e/attachment.htm>


More information about the Insight-developers mailing list