[Insight-users] a strange error using itkBSplineDeformableTransform

Chong Zhang chong.zhang at upf.edu
Tue Apr 3 12:08:45 EDT 2007


Dear users,

 

I am using itkBSplineDeformableTransform type deformation (three dimension
and BSpline order is 3) to deform the points on a vtkPolyData type mesh. But
the program crashes when I call the method TransformPoint() at one of the
points. (I pasted the code from itkBSplineDeformableTransform.txx below and
underlined the related lines)

 

template<class TScalarType, unsigned int NDimensions, unsigned int
VSplineOrder>

void 

BSplineDeformableTransform<TScalarType, NDimensions,VSplineOrder>

::TransformPoint( 

  const InputPointType & point, 

  OutputPointType & outputPoint, 

  WeightsType & weights, 

  ParameterIndexArrayType & indices,

  bool& inside ) const

{

 

  unsigned int j;

  IndexType supportIndex;

 

  InputPointType transformedPoint;

  if ( m_BulkTransform )

    {

    transformedPoint = m_BulkTransform->TransformPoint( point );

    }

  else

    {

    transformedPoint = point;

    }

 

  if ( m_CoefficientImage[0] )

    {

 

    ContinuousIndexType index;

    for ( j = 0; j < SpaceDimension; j++ )

      {

      index[j] = ( point[j] - m_GridOrigin[j] ) / m_GridSpacing[j];

      }

 

    // NOTE: if the support region does not lie totally within the grid

    // we assume zero displacement and return the input point

    inside = this->InsideValidRegion( index );

    if ( !inside )

      {

      outputPoint = transformedPoint;

      return;

      }

 

    // Compute interpolation weights

    m_WeightsFunction->Evaluate( index, weights, supportIndex );

 

    // For each dimension, correlate coefficient with weights

    RegionType supportRegion;

    supportRegion.SetSize( m_SupportSize );

    supportRegion.SetIndex( supportIndex );

 

    outputPoint.Fill( NumericTraits<ScalarType>::Zero );

 

    typedef ImageRegionConstIterator<ImageType> IteratorType;

    IteratorType m_Iterator[ SpaceDimension ];

    unsigned long counter = 0;

    const PixelType * basePointer =
m_CoefficientImage[0]->GetBufferPointer();

 

    for ( j = 0; j < SpaceDimension; j++ )

      {

      m_Iterator[j] = IteratorType( m_CoefficientImage[j], supportRegion );

      }

 

    while ( ! m_Iterator[0].IsAtEnd() )

      {

 

      // multiply weigth with coefficient

      for ( j = 0; j < SpaceDimension; j++ )

        {

        outputPoint[j] += static_cast<ScalarType>( 

          weights[counter] * m_Iterator[j].Get());

        }

 

      // populate the indices array

      indices[counter] = &(m_Iterator[0].Value()) - basePointer;

 

      // go to next coefficient in the support region

      ++ counter;

      for ( j = 0; j < SpaceDimension; j++ )

        {

        ++( m_Iterator[j] );

        }

      }

  

    // return results

    for ( j = 0; j < SpaceDimension; j++ )

      {

      outputPoint[j] += transformedPoint[j];

      }

 

    }

    else

    {

 

    itkWarningMacro( << "B-spline coefficients have not been set" );

 

    for ( j = 0; j < SpaceDimension; j++ )

      {

      outputPoint[j] = transformedPoint[j];

      }

 


    }

 

}

 

The ContinuousIndex of the point is (4.80, 11.00, 2.97). And the
m_ValidRegionLast (IndexType) is (11, 11, 11). Therefore, the method
InsideValidRegion() gives true (this is suppose to mean the support region
lies totally within the grid). The size of the supportRegion is known
according to the data dimension and BSpline order, which also determine the
length of weights (in my case is 64). The reason for the crashing is: for
some unkown reason, the while loop has been called more than 64 times, and
this results in the access violation of the weights, which is of size 64. 

 

Is there anyone who knows what is happening there? 

 

Best,

Chong

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070403/2e50202c/attachment-0001.htm


More information about the Insight-users mailing list