[Insight-users] Problem of itk ExtractImageFilter

ask ITK askitk at gmail.com
Thu Feb 9 04:50:39 EST 2006


Hi all,

    I come along with an interesting situation when using the itk
ExtractImageFilter.

A function written similarly from the example in IO section of ITK folder:

============================================================
void ApplicationCore::extractSlice( VolumePtr input, void * output,
int dimension, int slice_index)
{
	ExtractSliceFilterType::Pointer filter = ExtractSliceFilterType::New();
	VolumeType::RegionType inputRegion = input->GetLargestPossibleRegion();
	
	// supress the dimension
	// and set the slice #
	VolumeType::SizeType size = inputRegion.GetSize();
	VolumeType::IndexType start = inputRegion.GetIndex();

	size[dimension] = 0;
	start[dimension] = slice_index;
	
	VolumeType::RegionType desiredRegion;
	desiredRegion.SetSize(  size  );
	desiredRegion.SetIndex( start );
	filter->SetExtractionRegion( desiredRegion );
	filter->SetInput( input );

	ImagePtr *tempoutput = (ImagePtr*)output;
	*tempoutput = filter->GetOutput();

	// !!!!!!!!!! really dummy code to trigger ITK pipeline !!!!!!!!!
                // ==============================================
	itkvtkConnectorPtr itkvtkconnector = itkvtkConnectorType::New();
	itkvtkconnector->SetInput( *tempoutput );
	itkvtkconnector->Update();
                // ==============================================
}


// I call this function by the following code:
void * pimg = &Image_Vol[choice]->m_Image;
extractSlice( Image_Vol[choice]->m_Volume, pimg,2, 0);

printf("Dimension : x = %d y = %d z = %d\n",
Image_Vol[choice]->m_Image->GetLargestPossibleRegion().GetSize()[0],Image_Vol[choice]->m_Image->GetLargestPossibleRegion().GetSize()[1],Image_Vol[choice]->m_Image->GetLargestPossibleRegion().GetSize()[2]);
==========================================================

Everyone should know usage of void* pointer to get the result when
writting function in this way.....
But an interesting fact is, if I miss the dummy code I written above:
(strictly speaking, if I miss the itkvtkconnector->Update(); )
Then the m_Image I received is nothing!!!!
But will the call of the itkvtkconnector->Update();
it works properly!

Anybody knows the reason???
Now I temporary solve this problem with the above dummy code


More information about the Insight-users mailing list