| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkConstantBoundaryCondition.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:34 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkConstantBoundaryCondition_h |
| 18 |
|
#define __itkConstantBoundaryCondition_h |
| 19 |
|
#include "itkNeighborhood.h" |
| 20 |
|
#include "itkNumericTraits.h" |
| 21 |
|
#include "itkImageBoundaryCondition.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
/** \class ConstantBoundaryCondition |
| 27 |
|
* \brief This boundary condition returns a constant value for out-of-bounds |
| 28 |
|
* image pixels. |
| 29 |
|
* |
| 30 |
|
* For example, invoking this function object with a constant value of zero |
| 31 |
|
* (the default) on each out-of-bounds element of a 7x5 iterator that masks a |
| 32 |
|
* region at an image corner |
| 33 |
|
* (iterator is centered on the 2): |
| 34 |
|
* |
| 35 |
|
* * * * * * * * |
| 36 |
|
* * * * * * * * |
| 37 |
|
* * * 1 2 3 4 5 (where * denotes pixels that lie |
| 38 |
|
* * * 3 3 5 5 6 outside of the image boundary) |
| 39 |
|
* * * 4 4 6 7 8 |
| 40 |
|
* |
| 41 |
|
* would produce the following neighborhood of values: |
| 42 |
|
* |
| 43 |
|
* 0 0 0 0 0 0 0 |
| 44 |
|
* 0 0 0 0 0 0 0 |
| 45 |
|
* 0 0 1 2 3 4 5 |
| 46 |
|
* 0 0 3 3 5 5 6 |
| 47 |
|
* 0 0 4 4 6 7 8 |
| 48 |
|
* |
| 49 |
|
* |
| 50 |
|
* \note If you are using an image with Array as the pixel type, you will need |
| 51 |
|
* to set the constant explicitly with an array of the appropriate length. This |
| 52 |
|
* is also true if your image type is a VectorImage. |
| 53 |
|
* |
| 54 |
|
* \sa ImageBoundaryCondition |
| 55 |
|
* |
| 56 |
|
* \ingroup DataRepresentation |
| 57 |
|
* \ingroup ImageObjects |
| 58 |
|
*/ |
| 59 |
|
template<class TImage> |
| 60 |
|
class ITK_EXPORT ConstantBoundaryCondition |
| 61 |
IND |
**: public ImageBoundaryCondition<TImage> |
| 62 |
|
{ |
| 63 |
|
public: |
| 64 |
|
/** Self & superclass typedefs */ |
| 65 |
|
typedef ConstantBoundaryCondition Self; |
| 66 |
TDA |
typedef ImageBoundaryCondition<TImage> Superclass; |
| 67 |
|
|
| 68 |
|
/** Extract information from the image type */ |
| 69 |
|
typedef typename Superclass::PixelType PixelType; |
| 70 |
TDA |
typedef typename Superclass::PixelPointerType PixelPointerType; |
| 71 |
|
typedef typename Superclass::IndexType IndexType; |
| 72 |
TDA |
typedef typename Superclass::OffsetType OffsetType; |
| 73 |
TDA |
typedef typename Superclass::NeighborhoodType NeighborhoodType; |
| 74 |
|
|
| 75 |
|
typedef typename Superclass::NeighborhoodAccessorFunctorType |
| 76 |
IND |
*********************************NeighborhoodAccessorFunctorType; |
| 77 |
|
|
| 78 |
|
/** Save the image dimension. */ |
| 79 |
|
itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension); |
| 80 |
|
|
| 81 |
|
/** Default constructor. */ |
| 82 |
|
ConstantBoundaryCondition() |
| 83 |
|
{ m_Constant = NumericTraits<PixelType>::Zero; } |
| 84 |
|
|
| 85 |
|
/** Computes and returns appropriate out-of-bounds values from |
| 86 |
|
* neighborhood iterator data. */ |
| 87 |
|
virtual PixelType operator()(const OffsetType&, |
| 88 |
|
const OffsetType&, |
| 89 |
|
const NeighborhoodType *) const |
| 90 |
|
{ return m_Constant; } |
| 91 |
|
|
| 92 |
|
/** Computes and returns the appropriate pixel value from |
| 93 |
|
* neighborhood iterator data, using the functor. */ |
| 94 |
|
virtual PixelType operator()( |
| 95 |
|
const OffsetType& , |
| 96 |
|
const OffsetType& , |
| 97 |
|
const NeighborhoodType *, |
| 98 |
|
const NeighborhoodAccessorFunctorType & ) const |
| 99 |
|
{ return m_Constant; } |
| 100 |
|
|
| 101 |
|
/** Set the value of the constant. */ |
| 102 |
|
void SetConstant(const PixelType &c) |
| 103 |
|
{ m_Constant = c; } |
| 104 |
|
|
| 105 |
|
/** Get the value of the constant. */ |
| 106 |
|
const PixelType &GetConstant() const |
| 107 |
|
{ return m_Constant; } |
| 108 |
|
|
| 109 |
|
private: |
| 110 |
|
PixelType m_Constant; |
| 111 |
|
}; |
| 112 |
|
|
| 113 |
|
} // end namespace itk |
| 114 |
|
|
| 115 |
|
#endif |
| 116 |
|
|