ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 const int dimension = OffsetType::GetOffsetDimension();
40
41 constexpr OffsetType zeroOffset{};
42
43 chainPath.Clear();
44 InPathInputType inPathInput = inPath.StartOfInput();
45 chainPath.SetStart(inPath.EvaluateToIndex(inPathInput));
46
47 for (ChainInputType chainInput = 0;;)
48 {
49 OffsetType offset = inPath.IncrementInput(inPathInput);
50 if (zeroOffset == offset)
51 {
52 break;
53 }
54
55 if (!restrictMovement)
56 {
57 chainPath.InsertStep(chainInput++, offset);
58 }
59 else
60 {
61 for (int d = 0; d < dimension; ++d)
62 {
63 OffsetType tempOffset{};
64 tempOffset[d] = offset[d];
65 chainPath.InsertStep(chainInput++, tempOffset);
66 }
67 }
68 }
69}
70
77template <typename TFourierSeriesPath, typename TChainCodePath>
78void
79MakeFourierSeriesPathTraceChainCode(TFourierSeriesPath & FSPath,
80 const TChainCodePath & chainPath,
81 unsigned int numHarmonics = 8)
82{
83 using IndexType = typename TFourierSeriesPath::IndexType;
84 using OffsetType = typename TFourierSeriesPath::OffsetType;
85 using VectorType = typename TFourierSeriesPath::VectorType;
86
87 using FSInputType = typename TFourierSeriesPath::InputType;
88 using ChainInputType = typename TChainCodePath::InputType;
89
90 const int dimension = OffsetType::GetOffsetDimension();
91 const size_t numSteps = chainPath.NumberOfSteps();
92
93 const double PI = 4.0 * std::atan(1.0);
94
95 FSPath.Clear();
96
97 // Adjust our private copy of numHarmonics if necessary
98 if (numHarmonics <= 1)
99 {
100 numHarmonics = 2;
101 }
102 else if (numHarmonics * 2 > numSteps)
103 {
104 numHarmonics = numSteps / 2;
105 }
106
107 for (unsigned int n = 0; n < numHarmonics; ++n)
108 {
109 IndexType index = chainPath.GetStart();
110 VectorType cosCoefficient{};
111 VectorType sinCoefficient{};
112
113 for (ChainInputType step = 0; step < numSteps; ++step)
114 {
115 index += chainPath.Evaluate(step);
116 const FSInputType theta = 2 * n * PI * (static_cast<double>(step + 1)) / numSteps;
117
118 // turn the current index into a vector
119 VectorType indexVector;
120 for (int d = 0; d < dimension; ++d)
121 {
122 indexVector[d] = index[d];
123 }
124 cosCoefficient += indexVector * (std::cos(theta) / numSteps);
125 sinCoefficient += indexVector * (std::sin(theta) / numSteps);
126 }
127
128 FSPath.AddHarmonic(cosCoefficient, sinCoefficient);
129 }
130}
131} // end namespace itk
132
133#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)