| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkNeighborhoodOperator.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:42 $ |
| 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 __itkNeighborhoodOperator_h |
| 18 |
|
#define __itkNeighborhoodOperator_h |
| 19 |
|
|
| 20 |
|
#include "itkNeighborhood.h" |
| 21 |
|
#include "itkExceptionObject.h" |
| 22 |
|
#include "itkNumericTraits.h" |
| 23 |
|
#include <vector> |
| 24 |
|
|
| 25 |
|
namespace itk { |
| 26 |
|
/** \class NeighborhoodOperator |
| 27 |
|
* \brief Virtual class that defines a common interface to all |
| 28 |
|
* neighborhood operator subtypes. |
| 29 |
|
* |
| 30 |
|
* A NeighborhoodOperator is a set of pixel values that can be applied to a |
| 31 |
|
* Neighborhood to perform a user-defined operation (i.e. convolution kernel, |
| 32 |
|
* morphological structuring element). A NeighborhoodOperator is itself a |
| 33 |
|
* specialized Neighborhood, with functionality to generate its coefficients |
| 34 |
|
* according to user-defined parameters. Because the operator is a subclass |
| 35 |
|
* of Neighborhood, it is a valid operand in any of the operations |
| 36 |
|
* defined on the Neighborhood object (convolution, inner product, etc.). |
| 37 |
|
* |
| 38 |
|
* NeighborhoodOperator is a pure virtual object that must be |
| 39 |
|
* subclassed to be used. A user's subclass must implement two methods: |
| 40 |
|
* |
| 41 |
|
* (1) GenerateScalarCoefficients -- the algorithm that computes the scalar |
| 42 |
|
* coefficients of the operator. |
| 43 |
|
* |
| 44 |
|
* (2) ScalarFill -- the algorithm that places the scalar coefficients into |
| 45 |
|
* the memory buffer of the operator (arranges them spatially in the |
| 46 |
|
* neighborhood). |
| 47 |
|
* |
| 48 |
|
* NeighborhoodOperator supports the concept of a "directional operator." |
| 49 |
|
* A directional operator is defined in this context to be an operator |
| 50 |
|
* that is applied along a single dimension. Examples of this type of |
| 51 |
|
* operator are directional derivatives and the individual, directional |
| 52 |
|
* components of separable processes such as Gaussian smoothing. |
| 53 |
|
* |
| 54 |
|
* How a NeighborhoodOperator is applied to data is up to the user who |
| 55 |
|
* defines it. One possible use of an operator would be to take its |
| 56 |
|
* inner product with a neighborhood of values to produce |
| 57 |
|
* a scalar result. This process effects convolution when applied to |
| 58 |
|
* successive neighborhoods across a region of interest in an image. |
| 59 |
|
* |
| 60 |
|
* \ingroup Operators |
| 61 |
|
*/ |
| 62 |
|
template< class TPixel, unsigned int VDimension, |
| 63 |
|
class TAllocator = NeighborhoodAllocator<TPixel> > |
| 64 |
|
class ITK_EXPORT NeighborhoodOperator |
| 65 |
IND |
**: public Neighborhood<TPixel, VDimension, TAllocator> |
| 66 |
|
{ |
| 67 |
|
public: |
| 68 |
|
/** Standard class typedefs. */ |
| 69 |
|
typedef NeighborhoodOperator Self; |
| 70 |
TDA |
typedef Neighborhood<TPixel, VDimension, TAllocator> Superclass; |
| 71 |
|
|
| 72 |
|
/** Size object typedef support */ |
| 73 |
|
typedef typename Superclass::SizeType SizeType; |
| 74 |
|
|
| 75 |
|
/** External support for pixel type */ |
| 76 |
|
typedef TPixel PixelType; |
| 77 |
|
|
| 78 |
|
/** Slice iterator typedef support */ |
| 79 |
|
typedef SliceIterator<TPixel, Self> SliceIteratorType; |
| 80 |
|
|
| 81 |
|
/** Constructor. */ |
| 82 |
|
NeighborhoodOperator() |
| 83 |
|
{ m_Direction = 0; } |
| 84 |
|
|
| 85 |
|
/** Copy constructor */ |
| 86 |
|
NeighborhoodOperator(const Self &orig) |
| 87 |
IND |
****: Neighborhood<TPixel, VDimension, TAllocator>(orig) |
| 88 |
|
{ m_Direction = orig.m_Direction; } |
| 89 |
|
|
| 90 |
IND |
*/** Assignment operator. */ |
| 91 |
|
Self &operator=( const Self &orig ) |
| 92 |
|
{ |
| 93 |
IND |
******Superclass::operator=(orig); |
| 94 |
IND |
******m_Direction = orig.m_Direction; |
| 95 |
IND |
******return *this; |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
/** Sets the dimensional direction of a directional operator. */ |
| 99 |
|
void SetDirection(const unsigned long &direction) |
| 100 |
|
{ m_Direction = direction; } |
| 101 |
|
|
| 102 |
|
/** Returns the direction (dimension number) of a directional operator. */ |
| 103 |
|
unsigned long GetDirection() const |
| 104 |
|
{ return m_Direction; } |
| 105 |
|
|
| 106 |
|
/** Creates the operator with length only in the specified direction. |
| 107 |
|
* The radius of the operator will be 0 except along the axis on which |
| 108 |
|
* the operator will work. |
| 109 |
LEN |
* \sa CreateToRadius \sa FillCenteredDirectional \sa SetDirection() \sa GetDirection() */ |
| 110 |
|
virtual void CreateDirectional(); |
| 111 |
|
|
| 112 |
|
/** Creates the operator with a specified radius. The spatial location of |
| 113 |
|
* the coefficients within the operator is defined by the subclass |
| 114 |
|
* implementation of the Fill method. |
| 115 |
|
* \sa CreateDirectional \sa Fill */ |
| 116 |
|
virtual void CreateToRadius(const SizeType &); |
| 117 |
|
|
| 118 |
|
/** Creates the operator with a specified radius ("square", same length |
| 119 |
|
* on each side). The spatial location of the coefficients within the |
| 120 |
|
* operator is defined by the subclass implementation of the Fill method. |
| 121 |
|
* \sa CreateDirectional \sa Fill */ |
| 122 |
|
virtual void CreateToRadius(const unsigned long); |
| 123 |
|
|
| 124 |
|
/** Reverses the direction of all axes of the operator by reversing the order |
| 125 |
IND |
***** of the coefficients. */ |
| 126 |
|
virtual void FlipAxes(); |
| 127 |
|
|
| 128 |
|
/** Prints some debugging information. */ |
| 129 |
|
virtual void PrintSelf(std::ostream& os, Indent i) const |
| 130 |
|
{ |
| 131 |
IND |
******os << i << "NeighborhoodOperator { this=" << this |
| 132 |
|
<< " Direction = " << m_Direction << " }" << std::endl; |
| 133 |
|
Superclass::PrintSelf( os, i.GetNextIndent() ); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
typedef typename NumericTraits< TPixel >::RealType PixelRealType; |
| 137 |
|
|
| 138 |
LEN |
/** Multiplies all of the coefficients of the kernel by a single scalar value. */ |
| 139 |
|
void ScaleCoefficients( PixelRealType ); |
| 140 |
|
|
| 141 |
|
protected: |
| 142 |
|
/** Typedef support for coefficient vector type. Necessary |
| 143 |
|
* to fix bug in the microsoft VC++ compiler. */ |
| 144 |
|
typedef std::vector<double> CoefficientVector; |
| 145 |
|
|
| 146 |
|
/** A subclass-specific algorithm that computes the coefficients |
| 147 |
|
* of the operator. */ |
| 148 |
|
virtual CoefficientVector GenerateCoefficients() = 0; |
| 149 |
|
|
| 150 |
|
/** A subclass-specific algorithm that positions the coefficients |
| 151 |
|
* spatially in the operator. */ |
| 152 |
|
virtual void Fill(const CoefficientVector &) = 0; |
| 153 |
|
|
| 154 |
|
/** A pre-defined Fill function that can be called by a subclass |
| 155 |
|
* Fill function to center coefficients along the axis specified |
| 156 |
|
* by the SetDirection method. Useful for creating directional |
| 157 |
|
* operators, or centering coefficients in an N-dimensional |
| 158 |
|
* neighborhood. */ |
| 159 |
|
virtual void FillCenteredDirectional(const CoefficientVector &); |
| 160 |
|
|
| 161 |
|
/** Initializes all the coefficients in the neighborhood to zero values */ |
| 162 |
|
void InitializeToZero() |
| 163 |
IND |
**{ |
| 164 |
|
for (unsigned int i = 0; i< this->Size(); ++i) |
| 165 |
|
{ this->operator[](i) = NumericTraits<PixelType>::Zero; } |
| 166 |
IND |
**} |
| 167 |
|
|
| 168 |
|
private: |
| 169 |
|
/** Direction (dimension number) of the derivative. */ |
| 170 |
|
unsigned long m_Direction; |
| 171 |
|
}; |
| 172 |
|
|
| 173 |
|
} // namespace itk |
| 174 |
|
|
| 175 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 176 |
|
#include "itkNeighborhoodOperator.txx" |
| 177 |
|
#endif |
| 178 |
|
|
| 179 |
|
#endif |
| 180 |
|
|
| 181 |
EOF |
|