[Insight-users] Should image adaptor support neighborhood iterators?

Dan Mueller dan.muel at gmail.com
Sat Oct 2 02:43:34 EDT 2010


Hi all,

I receive compilation errors when using ConstNeighborhoodIterator on
an ImageAdaptor. Should I create a bug report? Is my fix below
appropriate?

Details: ITK 3.20, CMake 2.6.4, Visual Studio 2008, Windows XP.

== CMakeLists.txt ==
PROJECT(itkTest)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
INCLUDE_DIRECTORIES(
  BEFORE
  ${SOURCE_PATH}
  ${TESTING_PATH}
  )
ADD_EXECUTABLE(Main main.cxx)
TARGET_LINK_LIBRARIES(Main ${ITK_LIBRARIES})

== main.cxx ==
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#define _SCL_SECURE_NO_WARNINGS

#include "itkImage.h"
#include "itkImageAdaptor.h"
#include "itkConstNeighborhoodIterator.h"

int main(int argc, char * argv [])
{
  try
    {
    // Typedefs
    const unsigned int Dimension = 2;
    typedef float PixelType;
    typedef itk::Image< PixelType, Dimension > ImageType;
    typedef itk::DefaultPixelAccessor< PixelType > DefaultPixelAccessorType;
    typedef itk::ImageAdaptor<ImageType, DefaultPixelAccessorType > AdaptorType;
    typedef itk::ConstNeighborhoodIterator< AdaptorType > IteratorType;

    // Create image
    ImageType::Pointer image = ImageType::New();
    ImageType::RegionType::SizeType size; size.Fill(64);
    ImageType::RegionType region(size);
    image->SetRegions(region);
    image->Allocate();
    image->FillBuffer(128);

    // Create adaptor around image
    AdaptorType::Pointer adaptedImage = AdaptorType::New();
    adaptedImage->SetImage(image);

    // Create neighborhood iterator
    IteratorType::SizeType radius; radius.Fill(2);
    IteratorType it( radius, adaptedImage,
adaptedImage->GetLargestPossibleRegion() );
    for (it.GoToBegin(); !it.IsAtEnd(); ++it)
      {
      PixelType pixel0 = it.GetPixel(0);
      PixelType pixel1 = it.GetPixel(1);
      PixelType pixel2 = it.GetPixel(2);
      }

    return EXIT_SUCCESS;
    }
  catch (itk::ExceptionObject & err)
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
    }
}

== Selected compilation errors ==
2>Compiling...
2>main.cxx
2>c:\insighttoolkit-3.20.0\code\common\itkConstNeighborhoodIterator.h(89)
: error C2039: 'NeighborhoodAccessorFunctorType' : is not a member of
'itk::ImageAdaptor<TImage,TAccessor>'
2>        with
2>        [
2>            TImage=ImageType,
2>            TAccessor=DefaultPixelAccessorType
2>        ]
2>        ..\main.cxx(36) : see reference to class template
instantiation 'itk::ConstNeighborhoodIterator<TImage>' being compiled
2>        with
2>        [
2>            TImage=AdaptorType
2>        ]
2>c:\insighttoolkit-3.20.0\code\common\itkConstNeighborhoodIterator.h(90)
: error C2602: 'itk::ConstNeighborhoodIterator<TImage>::NeighborhoodAccessorFunctorType'
is not a member of a base class of
'itk::ConstNeighborhoodIterator<TImage>'
2>        with
2>        [
2>            TImage=AdaptorType
2>        ]
2>        c:\insighttoolkit-3.20.0\code\common\itkConstNeighborhoodIterator.h(90)
: see declaration of
'itk::ConstNeighborhoodIterator<TImage>::NeighborhoodAccessorFunctorType'
2>        with
2>        [
2>            TImage=AdaptorType
2>        ]

== Proposed fix: ImageAdaptor.h.patch ==
C:\Temp\itkTest>diff --text itkImageAdaptor.h itkImageAdaptor.h.new
89a90,93
>
>   /** Typedef for the functor used to access a neighborhood of pixel
>    * pointers. */
>   typedef NeighborhoodAccessorFunctor< Self >  NeighborhoodAccessorFunctorType;
283c287,295
<
---
>
>   /** Return the NeighborhoodAccessor functor */
>   NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
>     { return NeighborhoodAccessorFunctorType(); }
>
>   /** Return the NeighborhoodAccessor functor */
>   const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
>     { return NeighborhoodAccessorFunctorType(); }
>


More information about the Insight-users mailing list