[Insight-users] "Killing" itk::kdTree ??

Luis Ibanez luis.ibanez at kitware.com
Thu Nov 26 12:46:09 EST 2009


Hi Motes,

You can destroy the instance of the KdTree  (or any other ITK class
that uses smart pointers) by simply assigning NULL to its SmartPointer.

Assuming, of course, that this is the only SmartPointer that points to
that instance.


      Regards,


             Luis


----------------------------------------------------------------------------
On Tue, Nov 24, 2009 at 8:09 PM, motes motes <mort.motes at gmail.com> wrote:
> I have implemented a transform that calls the itk::kdTree in the
> function "TransformPoint":
>
>
> // Transform a point
> template<class TScalarType, unsigned int NDimensions, unsigned int VSplineOrder>
> void
> MyTransform<TScalarType, NDimensions, VSplineOrder>
> ::TransformPoint(
>  const InputPointType & point,
>  OutputPointType & outputPoint,
>  WeightsType & weights,
>  ParameterIndexArrayType & indices,
>  bool & inside ) const
> {
>  unsigned int j;
>  IndexType supportIndex;
>  inside = true;
>  InputPointType transformedPoint;
>
>  if ( m_BulkTransform ) {
>    transformedPoint = m_BulkTransform->TransformPoint( point );
>  } else {
>    transformedPoint = point;
>  }
>
>  outputPoint.Fill( NumericTraits<ScalarType>::Zero );
>  if ( m_CoefficientImage[0] ) {
>      outputPoint.Fill( NumericTraits<ScalarType>::Zero );
>
>
>      NeighborContainerType neighbors;
>
>      // Wraps the call to the kdTree.
>      this->FindNeighbors(point, m_kernel_radius, neighbors);
>
> ...
> ...
>
>
>
>
> Before running the transform the tree is build with elements. Since
> the kdTree is located in the TransformPoint function it gets called
> for all pixels in the input image.
>
> I am currently testing it on 128*128*128 images. But when I try to
> compute the resampled image I get the error:
>
> HEAP CORRUPTION DETECTED:after Normal block(#107261) at 0x020A44E0.
> CRT detected that the application wrote to memory after end of heap
> buffer.
>
> as previously described here on the mailing list. Now the wierd thing
> is that if I insert a limit in the TransformPoint function like:
>
>  if ( m_CoefficientImage[0] ) {
>      outputPoint.Fill( NumericTraits<ScalarType>::Zero );
>
>
>     // Inserting limit
>    if(transform_count < transform_limit) {
>      NeighborContainerType neighbors;
>      this->FindNeighbors(point, m_kernel_radius, neighbors);
>
>      transform_count++;
>
>
>    }
>
>
> it works fine! I have tried with a  transform_limit = 10000 and it
> works fine. But if I raise the limit to 100000 I get the above heap
> error.
>
> Is it possible to "kill" the itk::kdTree if calling it in a loop that
> iterates 100000 times?
> _____________________________________
> 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://www.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-users
>


More information about the Insight-users mailing list