| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkCentralDifferenceImageFunction.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:33 $ |
| 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 _itkCentralDifferenceImageFunction_txx |
| 18 |
DEF |
#define _itkCentralDifferenceImageFunction_txx |
| 19 |
|
#include "itkCentralDifferenceImageFunction.h" |
| 20 |
|
|
| 21 |
|
namespace itk |
| 22 |
|
{ |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
/** |
| 26 |
|
* Constructor |
| 27 |
|
*/ |
| 28 |
|
template <class TInputImage, class TCoordRep> |
| 29 |
|
CentralDifferenceImageFunction<TInputImage,TCoordRep> |
| 30 |
|
::CentralDifferenceImageFunction() |
| 31 |
|
{ |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
/** |
| 36 |
|
* |
| 37 |
|
*/ |
| 38 |
|
template <class TInputImage, class TCoordRep> |
| 39 |
|
void |
| 40 |
|
CentralDifferenceImageFunction<TInputImage,TCoordRep> |
| 41 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 42 |
|
{ |
| 43 |
|
this->Superclass::PrintSelf(os,indent); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
/** |
| 48 |
|
* |
| 49 |
|
*/ |
| 50 |
|
template <class TInputImage, class TCoordRep> |
| 51 |
|
typename CentralDifferenceImageFunction<TInputImage,TCoordRep>::OutputType |
| 52 |
|
CentralDifferenceImageFunction<TInputImage,TCoordRep> |
| 53 |
|
::EvaluateAtIndex( const IndexType& index ) const |
| 54 |
|
{ |
| 55 |
|
|
| 56 |
|
OutputType derivative; |
| 57 |
|
derivative.Fill( 0.0 ); |
| 58 |
|
|
| 59 |
|
IndexType neighIndex = index; |
| 60 |
|
|
| 61 |
|
const typename InputImageType::SizeType& size = |
| 62 |
IND |
****this->GetInputImage()->GetBufferedRegion().GetSize(); |
| 63 |
|
const typename InputImageType::IndexType& start = |
| 64 |
IND |
****this->GetInputImage()->GetBufferedRegion().GetIndex(); |
| 65 |
|
|
| 66 |
|
for ( unsigned int dim = 0; dim < TInputImage::ImageDimension; dim++ ) |
| 67 |
|
{ |
| 68 |
|
// bounds checking |
| 69 |
|
if( index[dim] < static_cast<long>(start[dim]) + 1 || |
| 70 |
IND |
********index[dim] > (start[dim] + static_cast<long>(size[dim]) - 2 ) ) |
| 71 |
|
{ |
| 72 |
|
derivative[dim] = 0.0; |
| 73 |
|
continue; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
// compute derivative |
| 77 |
|
neighIndex[dim] += 1; |
| 78 |
|
derivative[dim] = this->GetInputImage()->GetPixel( neighIndex ); |
| 79 |
|
|
| 80 |
|
neighIndex[dim] -= 2; |
| 81 |
|
derivative[dim] -= this->GetInputImage()->GetPixel( neighIndex ); |
| 82 |
|
|
| 83 |
|
derivative[dim] *= 0.5 / this->GetInputImage()->GetSpacing()[dim]; |
| 84 |
|
neighIndex[dim] += 1; |
| 85 |
IND |
**} |
| 86 |
|
|
| 87 |
|
return ( derivative ); |
| 88 |
|
|
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
} // namespace itk |
| 93 |
|
|
| 94 |
|
#endif |
| 95 |
|
|