ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMultivariateLegendrePolynomial.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 itkMultivariateLegendrePolynomial_h
19#define itkMultivariateLegendrePolynomial_h
20
21#include "itkIntTypes.h"
22#include "itkIndent.h"
23#include <vector>
24#include "itkArray.h"
25#include "ITKPolynomialsExport.h"
26
27namespace itk
28{
68
69class ITKPolynomials_EXPORT MultivariateLegendrePolynomial
70{
71public:
73
74 using DoubleArrayType = std::vector<double>;
75 using ULongArrayType = std::vector<unsigned long>;
76 using LongArrayType = std::vector<long>;
77
80
84
88
90 MultivariateLegendrePolynomial(unsigned int dimension, unsigned int degree, const DomainSizeType & domainSize);
91
94
96 unsigned int
98 {
99 return m_Dimension;
100 }
101
103 unsigned int
104 GetDegree() const
105 {
106 return m_Degree;
107 }
108
115 unsigned int
117 {
119 }
120
122 const DomainSizeType &
124 {
125 return m_DomainSize;
126 }
127
134 {
135 public:
136 CoefficientVectorSizeMismatch(const size_t given, const size_t required)
137 : m_Required{ required }
138 , m_Given{ given }
139 {}
140
142 size_t m_Given;
143 };
144
149 void
151
152 void
153 SetCoefficients(const ParametersType & coefficients);
154
158
161 double
163 {
164 if (m_Dimension == 2)
165 {
166 if (index[1] != m_PrevY)
167 {
168 // normalized y [-1, 1]
169 const double norm_y = m_NormFactor[1] * static_cast<double>(index[1] - 1);
170 this->CalculateXCoef(norm_y, m_CoefficientArray);
171 m_PrevY = index[1];
172 }
174
175 // normalized x [-1, 1]
176 const double norm_x = m_NormFactor[0] * static_cast<double>(index[0] - 1);
177
178 return LegendreSum(norm_x, m_Degree, m_CachedXCoef);
179 }
180 if (m_Dimension == 3)
181 {
182 if (index[2] != m_PrevZ)
183 {
184 // normalized z [-1, 1]
185 const double norm_z = m_NormFactor[2] * static_cast<double>(index[2] - 1);
186 this->CalculateYCoef(norm_z, m_CoefficientArray);
187 m_PrevZ = index[2];
188 }
189
190 if (index[1] != m_PrevY)
191 {
192 // normalized y [-1, 1]
193 const double norm_y = m_NormFactor[1] * static_cast<double>(index[1] - 1);
194 this->CalculateXCoef(norm_y, m_CachedYCoef);
195 m_PrevY = index[1];
196 }
197
198 // normalized x [-1, 1]
199 const double norm_x = m_NormFactor[0] * static_cast<double>(index[0] - 1);
200 return this->LegendreSum(norm_x, m_Degree, m_CachedXCoef);
201 }
202 return 0;
203 }
204
206 unsigned int
207 GetNumberOfCoefficients(unsigned int dimension, unsigned int degree);
208
217 {
218 public:
228
229 void
231 {
232 m_IsAtEnd = false;
233 for (unsigned int dim = 0; dim < m_Dimension; ++dim)
234 {
235 m_Index[dim] = 0;
236 }
237 }
238
239 bool
240 IsAtEnd() const
241 {
242 return m_IsAtEnd;
243 }
244
247 {
248 for (unsigned int dim = 0; dim < m_Dimension; ++dim)
249 {
250 if (m_Index[dim] < static_cast<int>(m_DomainSize[dim] - 1))
251 {
252 m_Index[dim] += 1;
253 return *this;
254 }
255
256 if (dim == m_Dimension - 1)
257 {
258 m_IsAtEnd = true;
259 break;
260 }
261 else
262 {
263 m_Index[dim] = 0;
264 }
265 }
266 return *this;
267 }
268
269 double
271 {
273 }
274
275 private:
277 unsigned int m_Dimension;
280 bool m_IsAtEnd{ false };
281 }; // end of class Iterator
282
283 void
284 Print(std::ostream & os) const;
285
286protected:
287 void
288 PrintSelf(std::ostream & os, Indent indent) const;
289
290 double
291 LegendreSum(const double x, int n, const CoefficientArrayType & coef, int offset = 0);
292
293 void
294 CalculateXCoef(double norm_y, const CoefficientArrayType & coef);
295
296 void
297 CalculateYCoef(double norm_z, const CoefficientArrayType & coef);
298
299private:
301 unsigned int m_Dimension{};
302 unsigned int m_Degree{};
304
309
313}; // end of class
314
315ITKPolynomials_EXPORT std::ostream &
316 operator<<(std::ostream & os, const MultivariateLegendrePolynomial & poly);
317} // end of namespace itk
318#endif
Array class with size defined at construction time.
Definition itkArray.h:48
Control indentation during Print() invocation.
Definition itkIndent.h:50
CoefficientVectorSizeMismatch(const vcl_size_t given, const vcl_size_t required)
Iterator which only supports forward iteration and Begin(), IsAtEnd(), and Get() method which work ju...
2D and 3D multivariate Legendre Polynomial
void Print(std::ostream &os) const
void SetCoefficients(const ParametersType &coefficients)
const CoefficientArrayType & GetCoefficients() const
Gets Legendre polynomials' coefficients.
void CalculateXCoef(double norm_y, const CoefficientArrayType &coef)
void PrintSelf(std::ostream &os, Indent indent) const
unsigned int GetNumberOfCoefficients(unsigned int dimension, unsigned int degree)
void CalculateYCoef(double norm_z, const CoefficientArrayType &coef)
void SetCoefficients(const CoefficientArrayType &coefficients)
Sets the Legendre polynomials' parameters.
MultivariateLegendrePolynomial(unsigned int dimension, unsigned int degree, const DomainSizeType &domainSize)
double LegendreSum(const double x, int n, const CoefficientArrayType &coef, int offset=0)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
long IndexValueType
Definition itkIntTypes.h:93