[Insight-developers] itk::Array has an implicit conversion from unsigned int????

Luis Ibanez luis.ibanez at kitware.com
Mon Mar 15 14:32:31 EDT 2010


Kent, Brad,

Yes, this can indeed be a misleading behavior

  itk::Array<double>   a1(60);   // allocates 60 elements

while

  a1 = 60;   // assigns the value 60 to all the elements.


---

I'm running a Linux Experimental build with Brad's suggested
change, and if it comes out green, will commit it to the repository.

We will have to track the effect in other platforms...


       Thanks


           Luis


-------------------------------------------------------------------------------------
On Wed, Mar 10, 2010 at 2:55 PM, Bradley Lowekamp
<blowekamp at mail.nih.gov> wrote:
> I ran int to this before!
> I believe I encountered it utilizing the new ITK Statistics, when trying to
> set the size of perhaps a histogram. It expected an array but I used a
> integer which got converted into some high dimension itk::Array.
> Initializing a histogram with 256 dimension with zero bins in each
> dimension. Needless to say it caused my program to crash, and after a fair
> amount of time I tracked it down. Since I have been using the following:
> Index: itkArray.h
> ===================================================================
> RCS file: /cvsroot/Insight/Insight/Code/Common/itkArray.h,v
> retrieving revision 1.47
> diff -r1.47 itkArray.h
> 60c60
> <   Array(unsigned int dimension);
> ---
>>   explicit Array(unsigned int dimension);
>
> I didn't audit other array types to ensure that this insidious  implicit
> constructor isn't else where. But I have been building ITK with it for a
> while and the explicit qualifier does not cause any problems else where.
> Brad
>
> On Mar 10, 2010, at 1:40 PM, kent williams wrote:
>
> I ran into this today.  I thought I was dealing with a drop-in replacement
> ITK class, but the old class defined a method/member variable like this:
>
> itkSetMacro( MaximumNumberOfIterations, unsigned int);
>
> and the new class did this:
>
> itkSetMacro( MaximumNumberOfIterations, itk::Array<unsigned int>);
>
> The unexpected thing was that this:
>
> x->SetMaximumNumberOfIterations(50);
>
> compiled without complaint.
>
> When I debugged it, it turns out the second case is equivalent to
>
> itk::Array<unsigned int> anonymousTemp(50);
> x->SetMaximumNumberOfIterations(anonymousTemp);
>
> My reaction when I discovered this was WTF? (or What the Frumious
> Bandersnatch).
>
> Where is the implicit conversion from unsigned int to itk::Array, and is
> this even a desirable thing?
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.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
>
> ========================================================
>
> Bradley Lowekamp
>
> Lockheed Martin Contractor for
>
> Office of High Performance Computing and Communications
>
> National Library of Medicine
>
> blowekamp at mail.nih.gov
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://kitware.com/products/protraining.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
>
>


More information about the Insight-developers mailing list