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

Luis Ibanez luis.ibanez at kitware.com
Mon Mar 15 15:10:38 EDT 2010


HI Brad,

The method:

                         operator=(T)

is defined in the superclass of the itk::Array<T> class
which is the class

                        vnl_vector<T>

The definition of this method can be found in

Insight/Utilities/vxl/core/vnl/vnl_vector.h:  line 188:

  vnl_vector<T>& operator=(T const&v) { fill(v); return *this; }


Note that this is an operator that takes a type "T" as input,
and therefore it is a bit different from the constructor that
takes an unsigned int as input.


    Luis


-----------------------------------------------------------
On Mon, Mar 15, 2010 at 3:06 PM, Bradley Lowekamp
<blowekamp at mail.nih.gov> wrote:
> Luis,
>
> On Mar 15, 2010, at 2:32 PM, Luis Ibanez wrote:
>> a1 = 60;   // assigns the value 60 to all the elements.
>>
>
> I did not try this, but I don't know what operator or function this would call. There is no Array::operator=(TValueType&), so it may still call the nasty conversion constructor... I am curious now...
>
>
> Brad
>
>
>
>>
>> ---
>>
>> 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