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

Luis Ibanez luis.ibanez at kitware.com
Sat Jun 6 09:54:24 EDT 2009


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
> _____________________________________
> 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-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090606/4af5f0c5/attachment.htm>


More information about the Insight-users mailing list