[Insight-users] how to write a filter

Bing Jian bjian at cise . ufl . edu
Thu, 13 Nov 2003 09:15:19 -0500 (EST)


Hi,

   I'm trying to study how to write my own ITK-style filters.
I read the Chapter 13 "How to write a filter" in software guide.
But still confused, especially about the region part.

  I started from a very simple one: the output image is just
exactly copied from the input image. Since I want to keep
the image size and other information, I thought I don't need
to override the GenerateOutputInformation(). The only thing
I did is to write the GenerateData() function as follows:

template <class TInputImage, class TOutputImage>
void MyFirstFilter<TInputImage,TOutputImage>
::GenerateData(  )
{
  InputImagePointer  inputPtr = this->GetInput();
  OutputImagePointer outputPtr = this->GetOutput();

  unsigned int total = (outputPtr->GetRequestedRegion()).GetNumberOfPixels();
  std::cout << "total = " << total << std::endl;

  ImageRegionConstIterator<TInputImage>  inputIt(inputPtr,
inputPtr->GetLargestPossibleRegion());  // which region should be used
  ImageRegionIterator<TOutputImage> outputIt(outputPtr,
inputPtr->GetLargestPossibleRegion());  // which region should be used

    unsigned int pos = 0;
    inputIt.GoToBegin();
    outputIt.GoToBegin();
    while(!outputIt.IsAtEnd())
      {
           outputIt.Set(inputIt.Get());  //*
	   ++inputIt;
           ++outputIt;
	   pos ++;
      }
 }

   I am not sure in the definition of iterators what kind of region
should be used. The size of (outputPtr->GetBufferedRegion()) is 0.
Although the size of outputPtr->GetRequestedRegion() and
LargestPossibleRegion are correct, but if I use them, error occured
during the walking of iterator. It turned out that when iterator
passed through the first row, the program crashed. I don't know why?
I thought I must miss something. Can anybody help me out?
   Thanks!


--
Best wishes,
Bing Jian
bjian at cise . ufl . edu