| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkFourierSeriesPath.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:36 $ |
| 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 |
|
|
| 18 |
|
|
| 19 |
DEF |
#ifndef _itkFourierSeriesPath_txx |
| 20 |
DEF |
#define _itkFourierSeriesPath_txx |
| 21 |
|
|
| 22 |
|
#include "itkFourierSeriesPath.h" |
| 23 |
|
#include <math.h> |
| 24 |
|
|
| 25 |
|
// not all versions of math.h seem to define M_PI: |
| 26 |
|
#ifndef M_PI |
| 27 |
|
#define M_PI 3.14159265358979323846 |
| 28 |
|
#endif |
| 29 |
|
|
| 30 |
|
|
| 31 |
EML |
|
| 32 |
|
namespace itk |
| 33 |
|
{ |
| 34 |
|
|
| 35 |
|
template<unsigned int VDimension> |
| 36 |
|
typename FourierSeriesPath<VDimension>::OutputType |
| 37 |
|
FourierSeriesPath<VDimension> |
| 38 |
|
::Evaluate( const InputType & input ) const |
| 39 |
|
{ |
| 40 |
|
InputType theta; |
| 41 |
|
OutputType output; |
| 42 |
|
int numHarmonics; |
| 43 |
|
|
| 44 |
|
numHarmonics = m_CosCoefficients->Size(); |
| 45 |
|
output.Fill(0); |
| 46 |
|
|
| 47 |
|
if( numHarmonics > 0 ) { output += m_CosCoefficients->ElementAt(0); } |
| 48 |
|
|
| 49 |
|
for(int n=1; n<numHarmonics; n++) |
| 50 |
|
{ |
| 51 |
|
// input defined over [0,1] maps to theta defined over [0,2pi * n] |
| 52 |
|
theta = M_PI*2.0*n*input; |
| 53 |
|
output += ( m_CosCoefficients->ElementAt(n) * cos(theta) + |
| 54 |
IND |
****************m_SinCoefficients->ElementAt(n) * sin(theta) ) * 2.0; |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
return output; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
|
| 61 |
EML |
|
| 62 |
|
template<unsigned int VDimension> |
| 63 |
|
typename FourierSeriesPath<VDimension>::VectorType |
| 64 |
|
FourierSeriesPath<VDimension> |
| 65 |
|
::EvaluateDerivative(const InputType & input) const |
| 66 |
|
{ |
| 67 |
|
InputType theta; |
| 68 |
|
VectorType output; |
| 69 |
|
int numHarmonics; |
| 70 |
|
|
| 71 |
|
numHarmonics = m_CosCoefficients->Size(); |
| 72 |
|
output.Fill(0); |
| 73 |
|
|
| 74 |
|
for(int n=1; n<numHarmonics; n++) |
| 75 |
|
{ |
| 76 |
|
// input defined over [0,1] maps to theta defined over [0,2pi * n] |
| 77 |
|
theta = M_PI*2.0*n*input; |
| 78 |
|
output += ( m_SinCoefficients->ElementAt(n) * cos(theta) - |
| 79 |
IND |
****************m_CosCoefficients->ElementAt(n) * sin(theta) ) * (2.0 * n); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
return output; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
|
|
| 86 |
EML |
|
| 87 |
|
template<unsigned int VDimension> |
| 88 |
|
void |
| 89 |
|
FourierSeriesPath<VDimension> |
| 90 |
|
::AddHarmonic( const VectorType & CosCoefficients, |
| 91 |
|
const VectorType & SinCoefficients ) |
| 92 |
|
{ |
| 93 |
|
unsigned int numHarmonics = m_CosCoefficients->Size(); |
| 94 |
|
|
| 95 |
|
m_CosCoefficients->InsertElement(numHarmonics, CosCoefficients); |
| 96 |
|
m_SinCoefficients->InsertElement(numHarmonics, SinCoefficients); |
| 97 |
|
this->Modified(); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
EML |
|
| 102 |
|
/** |
| 103 |
|
* Constructor |
| 104 |
|
*/ |
| 105 |
|
template <unsigned int VDimension> |
| 106 |
|
FourierSeriesPath<VDimension> |
| 107 |
|
::FourierSeriesPath() |
| 108 |
|
{ |
| 109 |
|
this->SetDefaultInputStepSize( 1.0/50.0 ); |
| 110 |
|
m_CosCoefficients = CoefficientsType::New(); |
| 111 |
|
m_SinCoefficients = CoefficientsType::New(); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
EML |
|
| 116 |
|
/** |
| 117 |
|
* Standard "PrintSelf" method |
| 118 |
|
*/ |
| 119 |
|
template <unsigned int VDimension> |
| 120 |
|
void |
| 121 |
|
FourierSeriesPath<VDimension> |
| 122 |
|
::PrintSelf( std::ostream& os, Indent indent) const |
| 123 |
|
{ |
| 124 |
|
Superclass::PrintSelf( os, indent ); |
| 125 |
|
os << indent << "Cos Coefficients: " << m_CosCoefficients << std::endl; |
| 126 |
|
os << indent << "Sin Coefficients: " << m_SinCoefficients << std::endl; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
|
| 130 |
EML |
|
| 131 |
|
} // end namespaceitk |
| 132 |
|
|
| 133 |
|
#endif |
| 134 |
|
|