[Insight-users] how to iterate over the output of a filter

Alexander Taghva alextaghva at gmail.com
Sun Mar 6 19:31:34 EST 2011


Hello,
I'm having some trouble doing something that seems like it should be simple
to do.  I am writing a composite filter, and I would like to iterate over
the output of one of the component filters.  In my program, it is a
SpatialObjectToImageFilter templated over an ellipse spatial object and
binary image.  I get a seg fault when I try to do it like so.  Thanks for
any help. The key parts of the code are below:

//////////////////////////////////////////////////////////////////////////

// In the header file
  typedef itk::EllipseSpatialObject<3> EllipseType;
  typedef itk::SpatialObjectToImageFilter<EllipseType, BinaryImageType>
EllipseToImageFilterType;
  typedef unsigned char BinaryPixelType;
  typedef itk::Image<BinaryPixelType, 3>               BinaryImageType;
  typedef typename     BinaryImageType::Pointer    BinaryImagePointer;


// in the txx file

  typename Superclass::InputImageConstPointer  inputPtr = this->GetInput();
 // m_EllipseToImageFilter is my SpatialObjectToImageFilter
  BinaryImagePointer  tempBinaryPtr =
m_EllipseToImageFilter->GetOutput();

  typedef itk::ImageRegionConstIterator<TInputImage> InputIterator;
  typedef itk::ImageRegionConstIterator<BinaryImageType>
TempBinaryIterator;

  InputIterator  inputIt(  inputPtr,  inputPtr->GetRequestedRegion() );
  TempBinaryIterator tempBinaryIt( tempBinaryPtr,
tempBinaryPtr->GetRequestedRegion() );

    cout << "Seg fault happens here " << std::endl;
    for( inputIt.GoToBegin(), tempBinaryIt.GoToBegin(); !inputIt.IsAtEnd()
&& !tempBinaryIt.IsAtEnd() ; ++inputIt, ++tempBinaryIt )
  {
            if ( tempBinaryIt.Get() > 0 )
                // do something else;
    }


///////////////////////////////////////////////

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110306/6a00443c/attachment.htm>


More information about the Insight-users mailing list