| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkLaplacianOperator.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 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 _itkLaplacianOperator_txx |
| 18 |
DEF |
#define _itkLaplacianOperator_txx |
| 19 |
|
#include "itkLaplacianOperator.h" |
| 20 |
|
|
| 21 |
|
namespace itk |
| 22 |
|
{ |
| 23 |
|
|
| 24 |
|
template<class TPixel, unsigned int VDimension, class TAllocator> |
| 25 |
|
void |
| 26 |
|
LaplacianOperator<TPixel, VDimension, TAllocator> |
| 27 |
|
::SetDerivativeScalings( const double *s ) |
| 28 |
|
{ |
| 29 |
|
for (unsigned int i = 0; i < VDimension; ++i) |
| 30 |
|
{ |
| 31 |
|
m_DerivativeScalings[i] = s[i]; |
| 32 |
|
} |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
//Create the operator |
| 37 |
|
template <class TPixel, unsigned int VDimension, class TAllocator> |
| 38 |
|
void |
| 39 |
|
LaplacianOperator<TPixel, VDimension, TAllocator> |
| 40 |
|
::CreateOperator() |
| 41 |
|
{ |
| 42 |
|
CoefficientVector coefficients; |
| 43 |
|
|
| 44 |
|
coefficients = this->GenerateCoefficients(); |
| 45 |
|
|
| 46 |
|
this->Fill(coefficients); |
| 47 |
|
|
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
//This function fills the coefficients into the corresponding neighborhodd. |
| 51 |
|
template <class TPixel, unsigned int VDimension, class TAllocator> |
| 52 |
|
void |
| 53 |
|
LaplacianOperator <TPixel, VDimension, TAllocator> |
| 54 |
|
::Fill(const CoefficientVector &coeff) |
| 55 |
|
{ |
| 56 |
|
|
| 57 |
|
typename Superclass::CoefficientVector::const_iterator it; |
| 58 |
|
|
| 59 |
|
std::slice* temp_slice; |
| 60 |
|
temp_slice = new std::slice(0, coeff.size(),1); |
| 61 |
|
|
| 62 |
|
typename Self::SliceIteratorType data(this, *temp_slice); |
| 63 |
|
delete temp_slice; |
| 64 |
|
|
| 65 |
|
it = coeff.begin(); |
| 66 |
|
|
| 67 |
|
// Copy the coefficients into the neighborhood |
| 68 |
|
for (data = data.Begin(); data < data.End(); ++data, ++it) |
| 69 |
|
{ |
| 70 |
|
*data = *it; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
} |
| 74 |
|
|
| 75 |
|
template <class TPixel, unsigned int VDimension, class TAllocator> |
| 76 |
|
typename LaplacianOperator<TPixel, VDimension, TAllocator> |
| 77 |
|
::CoefficientVector |
| 78 |
|
LaplacianOperator<TPixel, VDimension, TAllocator> |
| 79 |
|
::GenerateCoefficients() |
| 80 |
|
{ |
| 81 |
|
unsigned int i, w; |
| 82 |
|
|
| 83 |
|
// Here we set the radius to 1's, here the |
| 84 |
|
// operator is 3x3 for 2D, 3x3x3 for 3D. |
| 85 |
|
SizeType r; |
| 86 |
|
r.Fill(1); |
| 87 |
|
this->SetRadius(r); |
| 88 |
|
|
| 89 |
|
// Create a vector of the correct size to hold the coefficients. |
| 90 |
|
w = this->Size(); |
| 91 |
|
CoefficientVector coeffP(w); |
| 92 |
|
|
| 93 |
|
//Set the coefficients |
| 94 |
|
double sum = 0.0; |
| 95 |
|
double hsq; |
| 96 |
|
long stride; |
| 97 |
SEM |
for (i = 0 ; i < 2 * VDimension; i+=2) |
| 98 |
|
{ |
| 99 |
|
stride = static_cast<long>( this->GetStride(i/2) ); |
| 100 |
|
|
| 101 |
|
hsq = m_DerivativeScalings[ i / 2]*m_DerivativeScalings[ i / 2]; |
| 102 |
|
coeffP[w/2 - stride] = coeffP[w/2 + stride] = hsq; |
| 103 |
|
sum += 2.0*hsq; |
| 104 |
|
} |
| 105 |
|
coeffP[w/2] = - sum; |
| 106 |
|
|
| 107 |
|
return coeffP; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
} // namespace itk |
| 111 |
|
|
| 112 |
|
#endif |
| 113 |
|
|