| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkImageFunction.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:38 $ |
| 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 |
DEF |
#ifndef _itkImageFunction_h |
| 18 |
DEF |
#define _itkImageFunction_h |
| 19 |
|
|
| 20 |
|
#include "itkFunctionBase.h" |
| 21 |
|
#include "itkPoint.h" |
| 22 |
|
#include "itkIndex.h" |
| 23 |
|
#include "itkContinuousIndex.h" |
| 24 |
|
#include "itkImageBase.h" |
| 25 |
|
|
| 26 |
|
namespace itk |
| 27 |
|
{ |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
/** \class ImageFunction |
| 31 |
|
* \brief Evaluates a function of an image at specified position. |
| 32 |
|
* |
| 33 |
|
* ImageFunction is a baseclass for all objects that evaluates |
| 34 |
|
* a function of an image at index, continuous index or point. |
| 35 |
|
* This class is templated over the input image type, the type |
| 36 |
|
* of the function output and the coordinate representation type |
| 37 |
|
* (e.g. float or double). |
| 38 |
|
* |
| 39 |
|
* The input image is set via method SetInputImage(). |
| 40 |
|
* Methods Evaluate, EvaluateAtIndex and EvaluateAtContinuousIndex |
| 41 |
|
* respectively evaluates the function at an geometric point, |
| 42 |
|
* image index and continuous image index. |
| 43 |
|
* |
| 44 |
|
* \warning Image BufferedRegion information is cached during |
| 45 |
|
* in SetInputImage( image ). If the image BufferedRegion has changed |
| 46 |
|
* one must call SetInputImage( image ) again to update the cache |
| 47 |
|
* to the current values. |
| 48 |
|
* |
| 49 |
|
* \sa Point |
| 50 |
|
* \sa Index |
| 51 |
|
* \sa ContinuousIndex |
| 52 |
|
* |
| 53 |
|
* \ingroup ImageFunctions |
| 54 |
|
*/ |
| 55 |
|
template < |
| 56 |
|
class TInputImage, |
| 57 |
|
class TOutput, |
| 58 |
|
class TCoordRep = float |
| 59 |
|
> |
| 60 |
|
class ITK_EXPORT ImageFunction : |
| 61 |
IND |
****public FunctionBase< Point<TCoordRep, |
| 62 |
LEN |
::itk::GetImageDimension<TInputImage>::ImageDimension>, |
| 63 |
IND |
***********************TOutput > |
| 64 |
|
{ |
| 65 |
|
public: |
| 66 |
|
/** Dimension underlying input image. */ |
| 67 |
|
itkStaticConstMacro(ImageDimension, unsigned int, |
| 68 |
|
TInputImage::ImageDimension); |
| 69 |
|
|
| 70 |
|
/** Standard class typedefs. */ |
| 71 |
|
typedef ImageFunction Self; |
| 72 |
|
typedef FunctionBase< Point<TCoordRep, |
| 73 |
|
itkGetStaticConstMacro(ImageDimension)>, |
| 74 |
TDA,IND |
************************TOutput > Superclass; |
| 75 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 76 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 77 |
|
|
| 78 |
|
/** Run-time type information (and related methods). */ |
| 79 |
|
itkTypeMacro(ImageFunction, FunctionBase); |
| 80 |
|
|
| 81 |
|
/** InputImageType typedef support. */ |
| 82 |
|
typedef TInputImage InputImageType; |
| 83 |
|
|
| 84 |
|
/** InputPixel typedef support */ |
| 85 |
|
typedef typename InputImageType::PixelType InputPixelType; |
| 86 |
|
|
| 87 |
|
/** InputImagePointer typedef support */ |
| 88 |
|
typedef typename InputImageType::ConstPointer InputImageConstPointer; |
| 89 |
|
|
| 90 |
|
/** OutputType typedef support. */ |
| 91 |
|
typedef TOutput OutputType; |
| 92 |
|
|
| 93 |
|
/** CoordRepType typedef support. */ |
| 94 |
|
typedef TCoordRep CoordRepType; |
| 95 |
|
|
| 96 |
|
/** Index Type. */ |
| 97 |
|
typedef typename InputImageType::IndexType IndexType; |
| 98 |
|
|
| 99 |
|
/** ContinuousIndex Type. */ |
| 100 |
|
typedef ContinuousIndex<TCoordRep,itkGetStaticConstMacro(ImageDimension)> |
| 101 |
IND |
**********ContinuousIndexType; |
| 102 |
|
|
| 103 |
|
/** Point Type. */ |
| 104 |
|
typedef Point<TCoordRep,itkGetStaticConstMacro(ImageDimension)> PointType; |
| 105 |
|
|
| 106 |
|
/** Set the input image. |
| 107 |
|
* \warning this method caches BufferedRegion information. |
| 108 |
|
* If the BufferedRegion has changed, user must call |
| 109 |
|
* SetInputImage again to update cached values. */ |
| 110 |
|
virtual void SetInputImage( const InputImageType * ptr ); |
| 111 |
|
|
| 112 |
|
/** Get the input image. */ |
| 113 |
|
const InputImageType * GetInputImage() const |
| 114 |
|
{ return m_Image.GetPointer(); } |
| 115 |
|
|
| 116 |
|
/** Evaluate the function at specified Point position. |
| 117 |
|
* Subclasses must provide this method. */ |
| 118 |
|
virtual TOutput Evaluate( const PointType& point ) const = 0; |
| 119 |
|
|
| 120 |
|
/** Evaluate the function at specified Index position. |
| 121 |
|
* Subclasses must provide this method. */ |
| 122 |
|
virtual TOutput EvaluateAtIndex( const IndexType & index ) const = 0; |
| 123 |
|
|
| 124 |
|
/** Evaluate the function at specified ContinousIndex position. |
| 125 |
|
* Subclasses must provide this method. */ |
| 126 |
|
virtual TOutput EvaluateAtContinuousIndex( |
| 127 |
|
const ContinuousIndexType & index ) const = 0; |
| 128 |
|
|
| 129 |
|
/** Check if an index is inside the image buffer. |
| 130 |
|
* \warning For efficiency, no validity checking of |
| 131 |
|
* the input image is done. */ |
| 132 |
|
virtual bool IsInsideBuffer( const IndexType & index ) const |
| 133 |
|
{ |
| 134 |
IND |
******for ( unsigned int j = 0; j < ImageDimension; j++ ) |
| 135 |
|
{ |
| 136 |
|
if ( index[j] < m_StartIndex[j] ) { return false; }; |
| 137 |
|
if ( index[j] > m_EndIndex[j] ) { return false; }; |
| 138 |
IND |
********} |
| 139 |
IND |
******return true; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
/** Check if a continuous index is inside the image buffer. |
| 143 |
|
* \warning For efficiency, no validity checking of |
| 144 |
|
* the input image is done. */ |
| 145 |
|
virtual bool IsInsideBuffer( const ContinuousIndexType & index ) const |
| 146 |
|
{ |
| 147 |
IND |
******for ( unsigned int j = 0; j < ImageDimension; j++ ) |
| 148 |
|
{ |
| 149 |
|
if ( index[j] < m_StartContinuousIndex[j] ) { return false; }; |
| 150 |
|
if ( index[j] > m_EndContinuousIndex[j] ) { return false; }; |
| 151 |
IND |
********} |
| 152 |
IND |
******return true; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
/** Check if a point is inside the image buffer. |
| 156 |
|
* \warning For efficiency, no validity checking of |
| 157 |
|
* the input image pointer is done. */ |
| 158 |
|
virtual bool IsInsideBuffer( const PointType & point ) const |
| 159 |
|
{ |
| 160 |
|
ContinuousIndexType index; |
| 161 |
|
m_Image->TransformPhysicalPointToContinuousIndex( point, index ); |
| 162 |
|
return this->IsInsideBuffer( index ); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
/** Convert point to nearest index. */ |
| 166 |
|
void ConvertPointToNearestIndex( const PointType & point, |
| 167 |
|
IndexType & index ) const |
| 168 |
|
{ |
| 169 |
|
ContinuousIndexType cindex; |
| 170 |
|
m_Image->TransformPhysicalPointToContinuousIndex( point, cindex ); |
| 171 |
|
this->ConvertContinuousIndexToNearestIndex( cindex, index ); |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
/** Convert continuous index to nearest index. */ |
| 175 |
|
void ConvertContinuousIndexToNearestIndex( const ContinuousIndexType & cindex, |
| 176 |
|
IndexType & index ) const |
| 177 |
|
{ |
| 178 |
|
typedef typename IndexType::IndexValueType ValueType; |
| 179 |
|
for ( unsigned int j = 0; j < ImageDimension; j++ ) |
| 180 |
|
{ index[j] = static_cast<ValueType>( vnl_math_rnd( cindex[j] ) ); } |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
itkGetConstReferenceMacro(StartIndex, IndexType); |
| 184 |
|
itkGetConstReferenceMacro(EndIndex, IndexType); |
| 185 |
|
|
| 186 |
|
itkGetConstReferenceMacro(StartContinuousIndex, ContinuousIndexType); |
| 187 |
|
itkGetConstReferenceMacro(EndContinuousIndex, ContinuousIndexType); |
| 188 |
|
|
| 189 |
|
protected: |
| 190 |
|
ImageFunction(); |
| 191 |
|
~ImageFunction() {} |
| 192 |
|
void PrintSelf(std::ostream& os, Indent indent) const; |
| 193 |
|
|
| 194 |
|
/** Const pointer to the input image. */ |
| 195 |
|
InputImageConstPointer m_Image; |
| 196 |
|
|
| 197 |
|
/** Cache some values for testing if indices are inside buffered region. */ |
| 198 |
|
IndexType m_StartIndex; |
| 199 |
|
IndexType m_EndIndex; |
| 200 |
|
ContinuousIndexType m_StartContinuousIndex; |
| 201 |
|
ContinuousIndexType m_EndContinuousIndex; |
| 202 |
|
|
| 203 |
|
private: |
| 204 |
|
ImageFunction(const Self&); //purposely not implemented |
| 205 |
|
void operator=(const Self&); //purposely not implemented |
| 206 |
|
|
| 207 |
|
}; |
| 208 |
|
|
| 209 |
|
} // namespace itk |
| 210 |
|
|
| 211 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 212 |
|
#include "itkImageFunction.txx" |
| 213 |
|
#endif |
| 214 |
|
|
| 215 |
|
#endif |
| 216 |
|
|