18 #ifndef __itkPathFunctions_h
19 #define __itkPathFunctions_h
31 template<
typename TChainCodePath,
typename TPathInput >
33 const TPathInput & inPath,
34 bool restrictMovement =
false)
36 typedef typename TChainCodePath::OffsetType OffsetType;
37 typedef typename TChainCodePath::InputType ChainInputType;
38 typedef typename TPathInput::InputType InPathInputType;
40 OffsetType offset, tempOffset, zeroOffset;
41 InPathInputType inPathInput;
42 int dimension = OffsetType::GetOffsetDimension();
47 inPathInput = inPath.StartOfInput();
48 chainPath.SetStart( inPath.EvaluateToIndex(inPathInput) );
50 for ( ChainInputType chainInput = 0;; )
52 offset = inPath.IncrementInput(inPathInput);
53 if ( zeroOffset == offset ) {
break; }
55 if ( !restrictMovement )
57 chainPath.InsertStep(chainInput++, offset);
61 for (
int d = 0; d < dimension; d++ )
64 tempOffset[d] = offset[d];
65 chainPath.InsertStep(chainInput++, tempOffset);
77 template<
typename TFourierSeriesPath,
typename TChainCodePath >
79 const TChainCodePath & chainPath,
80 unsigned int numHarmonics = 8)
82 typedef typename TFourierSeriesPath::IndexType IndexType;
83 typedef typename TFourierSeriesPath::OffsetType OffsetType;
84 typedef typename TFourierSeriesPath::VectorType VectorType;
87 typedef typename TFourierSeriesPath::InputType FSInputType;
88 typedef typename TChainCodePath::InputType ChainInputType;
91 VectorType indexVector;
92 VectorType cosCoefficient;
93 VectorType sinCoefficient;
95 int dimension = OffsetType::GetOffsetDimension();
96 unsigned numSteps = chainPath.NumberOfSteps();
98 const double PI = 4.0 * std::atan(1.0);
103 if ( numHarmonics <= 1 )
107 else if ( numHarmonics * 2 > numSteps )
109 numHarmonics = numSteps / 2;
112 for (
unsigned n = 0; n < numHarmonics; n++ )
114 index = chainPath.GetStart();
115 cosCoefficient.Fill(0.0);
116 sinCoefficient.Fill(0.0);
118 for ( ChainInputType step = 0; step < numSteps; step++ )
120 index += chainPath.Evaluate(step);
121 theta = 2 * n * PI * ( double(step + 1) ) / numSteps;
124 for (
int d = 0; d < dimension; d++ )
126 indexVector[d] = index[d];
128 cosCoefficient += indexVector * ( std::cos(theta) / numSteps );
129 sinCoefficient += indexVector * ( std::sin(theta) / numSteps );
132 FSPath.AddHarmonic(cosCoefficient, sinCoefficient);
void MakeFourierSeriesPathTraceChainCode(TFourierSeriesPath &FSPath, const TChainCodePath &chainPath, unsigned int numHarmonics=8)
void MakeChainCodeTracePath(TChainCodePath &chainPath, const TPathInput &inPath, bool restrictMovement=false)