[Insight-users] Walking off the end of an array.

Mike Jackson mike.jackson at bluequartz.net
Sat Jun 6 10:23:40 EDT 2009


Yep. I followed the hierarchy all way back to the vnl_vector class and
so change my code a bit:

when I print the value of the "size" of the array I get 2. So I tried
the following code and it seemed to let me set the value without
asserting during execution.


metricParams(200) = 0.0;
metricParams.put(200, 0.0);

I made sure I was building with a debug build but I still do not get
an assert or error or anything that I would assume I would get when
running the code. Dunno.

Mike

On Sat, Jun 6, 2009 at 9:54 AM, Luis Ibanez<luis.ibanez at kitware.com> wrote:
>
> Hi Mike,
>
> The type used by the Metric for the array of transform parameters
> is ultimately an itk::Array<double>.
>
> You will find it in:
>
> Insight/Code/Common/itkTransformBase.h  line  49
>
>   /** Type of the input parameters. */
>   typedef  Array< double >           ParametersType;
>
>
> The code of the itkArray itself does not have assertions,
> nor error checking when accessing the elements with
> the operator[].
>
> The itkArray derives from the vnl_vector, which indeed
> has some of these assertions, but they are in the
>
>    operator()   method,
>
> not in the
>
>     operator[]  method.
>
> Therefore, you will have error checking if you use
>
>     metricParams(3) = 56;
>
> but not if you use
>
>     metricParams[3] = 56;
>
>
> --
>
>
>    Regards,
>
>
>         Luis
>
>
> -------------------------------------------------------------------------------------------------------------
> On Sat, Jun 6, 2009 at 9:33 AM, Mike Jackson <mike.jackson at bluequartz.net>
> wrote:
>>
>> While running some code I kept getting some asserts from the HDF5
>> library that I am using when my program exited. Turns out that I had
>> something like this in my own code:
>>
>>
>>
>> namespace R3D
>> {
>>  namespace Detail
>>  {
>>    const unsigned int Dimension = 2;
>>  }
>> }
>>
>> typedef   unsigned char  PixelType;
>> typedef itk::Image<PixelType, R3D::Detail::Dimension>
>>  ImageType;
>> typedef itk::MeanSquaresImageToImageMetric<  ImageType, ImageType >
>>  MetricType;
>> MetricType::TransformParametersType metricParams(R3D::Detail::Dimension);
>>
>>
>> metricParams[0] = scale;
>> metricParams[1] = 0.0;
>> metricParams[2] = 0.0;
>> metricParams[3] = 0.0;
>>
>> Turns out there are only 2 parameters for the metricParams array and
>> so I guess I was walking off the end of then array and assigning data
>> to memory locations in the HDF5 library area.
>>
>> Turns out I was using the non-boundary checking version of those
>> calls. I should have been doing something like:
>> metricParams(2) = 0.0;
>> metricParams.put(2, 0.0);
>>
>> So I tried those fully expecting an assert to happen by my code
>> completes successfully now. I compiled ITK in debug mode along with my
>> code. Is there something else that needs to be done in order to enable
>> these asserts or boundary checking? I am still new to ITK and so I
>> would like to have the safety net.
>>
>> Thanks
>> Mike Jackson


More information about the Insight-users mailing list