# Boundary Conditions Have Output Image Type

Cory Quammen
2011-11-08
Added output image template parameter to boundary conditions The boundary conditions were templated only over the type of image for which they provided values. This change adds a template parameter specifying an output image type to which the values retrieved from the boundary condition will be stored. The pixel accessor methods in the boundary conditions now return the pixel type of this output image rather than the pixel type of the input image. This solves some compilation problems when the input and output image types are different in PadImageFilter and its subclasses.

Customized subclasses should compile against the new changes without problems because the output image type is set to be the input image type, so all methods that return pixel values will work. However, it is recommended that the output types of overridden methods should be renamed to OutputPixelType and the template signature of the subclass should be modified to include the output image type.
template< class TInputImage > class BoundaryConditionSubclass : public ImageBoundaryCondition< TInputImage > { ... typedef typename Superclass::PixelType PixelType; typedef typename Superclass::PixelPointerType PixelPointerType;

/** Computes and returns appropriate out-of-bounds values from * neighborhood iterator data. */ virtual PixelType operator()(const OffsetType &, const OffsetType &, const NeighborhoodType *) const;

/** Computes and returns the appropriate pixel value from * neighborhood iterator data, using the functor. */ virtual PixelType operator()( const OffsetType &, const OffsetType &, const NeighborhoodType *, const NeighborhoodAccessorFunctorType &) const;

/** Returns a value for a given pixel at an index. If the index is inside the * bounds of the input image, then the pixel value is obtained from * the input image. Otherwise, the constant value is returned. * * \param index The index of the desired pixel. * \param image The image from which pixel values should be determined. */ PixelType GetPixel( const IndexType & index, const TInputImage * image ) const; ... };
template< class TInputImage, class TOutputImage = TInputImage > class BoundaryConditionSubclass : public ImageBoundaryCondition< TInputImage, TOutputImage > ... typedef typename Superclass::PixelType PixelType; typedef typename Superclass::PixelPointerType PixelPointerType; typedef typename Superclass::OutputPixelType OutputPixelType;

/** Computes and returns appropriate out-of-bounds values from * neighborhood iterator data. */ virtual OutputPixelType operator()(const OffsetType &, const OffsetType &, const NeighborhoodType *) const;

/** Computes and returns the appropriate pixel value from * neighborhood iterator data, using the functor. */ virtual OutputPixelType operator()( const OffsetType &, const OffsetType &, const NeighborhoodType *, const NeighborhoodAccessorFunctorType &) const;

/** Returns a value for a given pixel at an index. If the index is inside the * bounds of the input image, then the pixel value is obtained from * the input image. Otherwise, the constant value is returned. * * \param index The index of the desired pixel. * \param image The image from which pixel values should be determined. */ OutputPixelType GetPixel( const IndexType & index, const TInputImage * image ) const; ... };
I0192e62cc1677fa5d7158101f440d02d5d7e8137
Modules/Core/Common/include/itkConstantBoundaryCondition.h Modules/Core/Common/include/itkConstantBoundaryCondition.hxx Modules/Core/Common/include/itkImageBoundaryCondition.h Modules/Core/Common/include/itkPeriodicBoundaryCondition.h Modules/Core/Common/include/itkPeriodicBoundaryCondition.hxx Modules/Core/Common/include/itkZeroFluxNeumannBoundaryCondition.h Modules/Core/Common/include/itkZeroFluxNeumannBoundaryCondition.hxx Modules/Filtering/ImageGrid/include/itkConstantPadImageFilter.h Modules/Filtering/ImageGrid/include/itkPadImageFilter.h Modules/Filtering/ImageGrid/include/itkWrapPadImageFilter.h Modules/Filtering/ImageGrid/include/itkZeroFluxNeumannPadImageFilter.h Modules/Filtering/ImageGrid/test/itkConstantPadImageTest.cxx Modules/Filtering/ImageGrid/test/itkWrapPadImageTest.cxx Modules/Filtering/ImageGrid/test/itkZeroFluxNeumannPadImageFilterTest.cxx