ITK  6.0.0
Insight Toolkit
itkPathFunctions.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkPathFunctions_h
19#define itkPathFunctions_h
20
21#include "itkChainCodePath.h"
23#include <cmath>
24
25namespace itk
26{
31template <typename TChainCodePath, typename TPathInput>
32void
33MakeChainCodeTracePath(TChainCodePath & chainPath, const TPathInput & inPath, bool restrictMovement = false)
34{
35 using OffsetType = typename TChainCodePath::OffsetType;
36 using ChainInputType = typename TChainCodePath::InputType;
37 using InPathInputType = typename TPathInput::InputType;
38
39 OffsetType offset, tempOffset, zeroOffset;
40 InPathInputType inPathInput;
41 int dimension = OffsetType::GetOffsetDimension();
42
43 zeroOffset.Fill(0);
44
45 chainPath.Clear();
46 inPathInput = inPath.StartOfInput();
47 chainPath.SetStart(inPath.EvaluateToIndex(inPathInput));
48
49 for (ChainInputType chainInput = 0;;)
50 {
51 offset = inPath.IncrementInput(inPathInput);
52 if (zeroOffset == offset)
53 {
54 break;
55 }
56
57 if (!restrictMovement)
58 {
59 chainPath.InsertStep(chainInput++, offset);
60 }
61 else
62 {
63 for (int d = 0; d < dimension; ++d)
64 {
65 tempOffset.Fill(0);
66 tempOffset[d] = offset[d];
67 chainPath.InsertStep(chainInput++, tempOffset);
68 }
69 }
70 }
71}
72
79template <typename TFourierSeriesPath, typename TChainCodePath>
80void
81MakeFourierSeriesPathTraceChainCode(TFourierSeriesPath & FSPath,
82 const TChainCodePath & chainPath,
83 unsigned int numHarmonics = 8)
84{
86 using OffsetType = typename TFourierSeriesPath::OffsetType;
90 using FSInputType = typename TFourierSeriesPath::InputType;
91 using ChainInputType = typename TChainCodePath::InputType;
92
93 IndexType index;
94 VectorType indexVector;
95 VectorType cosCoefficient;
96 VectorType sinCoefficient;
97 FSInputType theta;
98 int dimension = OffsetType::GetOffsetDimension();
99 size_t numSteps = chainPath.NumberOfSteps();
100
101 const double PI = 4.0 * std::atan(1.0);
102
103 FSPath.Clear();
104
105 // Adjust our private copy of numHarmonics if necessary
106 if (numHarmonics <= 1)
107 {
108 numHarmonics = 2;
109 }
110 else if (numHarmonics * 2 > numSteps)
111 {
112 numHarmonics = numSteps / 2;
113 }
114
115 for (unsigned int n = 0; n < numHarmonics; ++n)
116 {
117 index = chainPath.GetStart();
118 cosCoefficient.Fill(0.0);
119 sinCoefficient.Fill(0.0);
120
121 for (ChainInputType step = 0; step < numSteps; ++step)
122 {
123 index += chainPath.Evaluate(step);
124 theta = 2 * n * PI * (static_cast<double>(step + 1)) / numSteps;
125
126 // turn the current index into a vector
127 for (int d = 0; d < dimension; ++d)
128 {
129 indexVector[d] = index[d];
130 }
131 cosCoefficient += indexVector * (std::cos(theta) / numSteps);
132 sinCoefficient += indexVector * (std::sin(theta) / numSteps);
133 }
134
135 FSPath.AddHarmonic(cosCoefficient, sinCoefficient);
136 }
137}
138} // end namespace itk
139
140#endif
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
void MakeFourierSeriesPathTraceChainCode(TFourierSeriesPath &FSPath, const TChainCodePath &chainPath, unsigned int numHarmonics=8)
void MakeChainCodeTracePath(TChainCodePath &chainPath, const TPathInput &inPath, bool restrictMovement=false)