[Insight-users] a strange error using itkBSplineDeformableTransform

Luis Ibanez luis.ibanez at kitware.com
Sat Apr 7 20:23:36 EDT 2007


Hi Chong,

Could you please provide the source code of the
program from which you are calling this Transform ?

We would like to try to reproduce what you are
observing.

Please send it as a minimal piece of code that
we could actually compile and run, and still
observe this problem.


    Thanks


      Luis


------------------
Chong Zhang wrote:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list