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{
67class ITKPolynomials_EXPORT MultivariateLegendrePolynomial
68{
69public:
71
72 using DoubleArrayType = std::vector<double>;
73 using ULongArrayType = std::vector<unsigned long>;
74 using LongArrayType = std::vector<long>;
75
78
82
86
88 MultivariateLegendrePolynomial(unsigned int dimension, unsigned int degree, const DomainSizeType & domainSize);
89
92
99
101 [[nodiscard]] unsigned int
103 {
104 return m_Dimension;
105 }
106
108 [[nodiscard]] unsigned int
109 GetDegree() const
110 {
111 return m_Degree;
112 }
113
120 [[nodiscard]] unsigned int
122 {
124 }
125
127 [[nodiscard]] const DomainSizeType &
129 {
130 return m_DomainSize;
131 }
132
139 {
140 public:
141 CoefficientVectorSizeMismatch(const size_t given, const size_t required)
142 : m_Required{ required }
143 , m_Given{ given }
144 {}
145
147 size_t m_Given;
148 };
149
154 void
156
157 void
158 SetCoefficients(const ParametersType & coefficients);
159
161 [[nodiscard]] const CoefficientArrayType &
163
166 double
168 {
169 if (m_Dimension == 2)
170 {
171 if (index[1] != m_PrevY)
172 {
173 // normalized y [-1, 1]
174 const double norm_y = m_NormFactor[1] * static_cast<double>(index[1] - 1);
175 this->CalculateXCoef(norm_y, m_CoefficientArray);
176 m_PrevY = index[1];
177 }
178
179 // normalized x [-1, 1]
180 const double norm_x = m_NormFactor[0] * static_cast<double>(index[0] - 1);
181
182 return LegendreSum(norm_x, m_Degree, m_CachedXCoef);
183 }
184 if (m_Dimension == 3)
185 {
186 if (index[2] != m_PrevZ)
187 {
188 // normalized z [-1, 1]
189 const double norm_z = m_NormFactor[2] * static_cast<double>(index[2] - 1);
190 this->CalculateYCoef(norm_z, m_CoefficientArray);
191 m_PrevZ = index[2];
192 }
193
194 if (index[1] != m_PrevY)
195 {
196 // normalized y [-1, 1]
197 const double norm_y = m_NormFactor[1] * static_cast<double>(index[1] - 1);
198 this->CalculateXCoef(norm_y, m_CachedYCoef);
199 m_PrevY = index[1];
200 }
201
202 // normalized x [-1, 1]
203 const double norm_x = m_NormFactor[0] * static_cast<double>(index[0] - 1);
204 return this->LegendreSum(norm_x, m_Degree, m_CachedXCoef);
205 }
206 return 0;
207 }
208
210 unsigned int
211 GetNumberOfCoefficients(unsigned int dimension, unsigned int degree);
212
221 {
222 public:
232
233 void
235 {
236 m_IsAtEnd = false;
237 for (unsigned int dim = 0; dim < m_Dimension; ++dim)
238 {
239 m_Index[dim] = 0;
240 }
241 }
242
243 [[nodiscard]] bool
244 IsAtEnd() const
245 {
246 return m_IsAtEnd;
247 }
248
251 {
252 for (unsigned int dim = 0; dim < m_Dimension; ++dim)
253 {
254 if (m_Index[dim] < static_cast<int>(m_DomainSize[dim] - 1))
255 {
256 m_Index[dim] += 1;
257 return *this;
258 }
259
260 if (dim == m_Dimension - 1)
261 {
262 m_IsAtEnd = true;
263 break;
264 }
265 else
266 {
267 m_Index[dim] = 0;
268 }
269 }
270 return *this;
271 }
272
273 double
275 {
277 }
278
279 private:
281 unsigned int m_Dimension;
284 bool m_IsAtEnd{ false };
285 }; // end of class Iterator
286
287 void
288 Print(std::ostream & os) const;
289
290protected:
291 void
292 PrintSelf(std::ostream & os, Indent indent) const;
293
294 double
295 LegendreSum(const double x, int n, const CoefficientArrayType & coef, int offset = 0);
296
297 void
298 CalculateXCoef(double norm_y, const CoefficientArrayType & coef);
299
300 void
301 CalculateYCoef(double norm_z, const CoefficientArrayType & coef);
302
303private:
305 unsigned int m_Dimension{};
306 unsigned int m_Degree{};
308
313
317}; // end of class
318
319ITKPolynomials_EXPORT std::ostream &
320 operator<<(std::ostream & os, const MultivariateLegendrePolynomial & poly);
321} // end of namespace itk
322#endif
Array class with size defined at construction time.
Definition itkArray.h:48
Control indentation during Print() invocation.
Definition itkIndent.h:51
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
MultivariateLegendrePolynomial(MultivariateLegendrePolynomial &&)=default
void SetCoefficients(const ParametersType &coefficients)
const CoefficientArrayType & GetCoefficients() const
Gets Legendre polynomials' coefficients.
void CalculateXCoef(double norm_y, const CoefficientArrayType &coef)
MultivariateLegendrePolynomial & operator=(MultivariateLegendrePolynomial &&)=default
MultivariateLegendrePolynomial & operator=(const MultivariateLegendrePolynomial &)=default
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)
MultivariateLegendrePolynomial(const MultivariateLegendrePolynomial &)=default
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, AnatomicalOrientation::CoordinateEnum value)
long IndexValueType
Definition itkIntTypes.h:93