18 #ifndef itkPathFunctions_h
19 #define itkPathFunctions_h
31 template<
typename TChainCodePath,
typename TPathInput >
33 const TPathInput & inPath,
34 bool restrictMovement =
false)
36 using OffsetType =
typename TChainCodePath::OffsetType;
37 using ChainInputType =
typename TChainCodePath::InputType;
38 using InPathInputType =
typename TPathInput::InputType;
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)
83 using OffsetType =
typename TFourierSeriesPath::OffsetType;
87 using FSInputType =
typename TFourierSeriesPath::InputType;
88 using ChainInputType =
typename TChainCodePath::InputType;
95 int dimension = OffsetType::GetOffsetDimension();
96 size_t 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)
ImageBaseType::IndexType IndexType
void MakeChainCodeTracePath(TChainCodePath &chainPath, const TPathInput &inPath, bool restrictMovement=false)
ImageBaseType::SpacingType VectorType