18 #ifndef __itkPathFunctions_h
19 #define __itkPathFunctions_h
31 template<
class TChainCodePath,
class TPathInput >
33 const TPathInput & inPath,
34 bool restrictMovement =
false)
36 typedef typename TChainCodePath::OffsetType OffsetType;
37 typedef typename TChainCodePath::InputType ChainInputType;
38 typedef typename TChainCodePath::OutputType ChainOutputType;
39 typedef typename TPathInput::InputType InPathInputType;
40 typedef typename TPathInput::OutputType InPathOutputType;
42 OffsetType offset, tempOffset, zeroOffset;
43 InPathInputType inPathInput;
44 int dimension = OffsetType::GetOffsetDimension();
49 inPathInput = inPath.StartOfInput();
50 chainPath.SetStart( inPath.EvaluateToIndex(inPathInput) );
52 for ( ChainInputType chainInput = 0;; )
54 offset = inPath.IncrementInput(inPathInput);
55 if ( zeroOffset == offset ) {
break; }
57 if ( !restrictMovement )
59 chainPath.InsertStep(chainInput++, offset);
63 for (
int d = 0; d < dimension; d++ )
66 tempOffset[d] = offset[d];
67 chainPath.InsertStep(chainInput++, tempOffset);
79 template<
class TFourierSeriesPath,
class TChainCodePath >
81 const TChainCodePath & chainPath,
82 unsigned int numHarmonics = 8)
84 typedef typename TFourierSeriesPath::IndexType IndexType;
85 typedef typename TFourierSeriesPath::OffsetType OffsetType;
86 typedef typename TFourierSeriesPath::VectorType VectorType;
89 typedef typename TFourierSeriesPath::InputType FSInputType;
90 typedef typename TFourierSeriesPath::OutputType FSOutputType;
91 typedef typename TChainCodePath::InputType ChainInputType;
92 typedef typename TChainCodePath::OutputType ChainOutputType;
95 VectorType indexVector;
96 VectorType cosCoefficient;
97 VectorType sinCoefficient;
99 int dimension = OffsetType::GetOffsetDimension();
100 unsigned numSteps = chainPath.NumberOfSteps();
102 const double PI = 4.0 * vcl_atan(1.0);
107 if ( numHarmonics <= 1 )
111 else if ( numHarmonics * 2 > numSteps )
113 numHarmonics = numSteps / 2;
116 for (
unsigned n = 0; n < numHarmonics; n++ )
118 index = chainPath.GetStart();
119 cosCoefficient.Fill(0.0);
120 sinCoefficient.Fill(0.0);
122 for ( ChainInputType step = 0; step < numSteps; step++ )
124 index += chainPath.Evaluate(step);
125 theta = 2 * n * PI * ( double(step + 1) ) / numSteps;
128 for (
int d = 0; d < dimension; d++ )
130 indexVector[d] = index[d];
132 cosCoefficient += indexVector * ( vcl_cos(theta) / numSteps );
133 sinCoefficient += indexVector * ( vcl_sin(theta) / numSteps );
136 FSPath.AddHarmonic(cosCoefficient, sinCoefficient);