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

Luis Ibanez luis.ibanez at kitware.com
Sun Oct 17 07:54:30 EDT 2010


Hi Dan,

Thanks for pointing this out.

You are right,
as long as an Accessor is provided,
the ImageAdaptors should be able
to support Neighborhood iterators.

We may have to verify that all Neighborhood
iterators (and operators) get to the image
values via the Accessor.


Could you please submit this patch
to Gerrit ?

 http://review.source.kitware.com


    Many Thanks


           Luis


------------------------------------------------------------
On Sat, Oct 2, 2010 at 2:43 AM, Dan Mueller <dan.muel at gmail.com> wrote:

> 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(); }
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101017/4c9f47b3/attachment-0001.htm>


More information about the Insight-users mailing list