0.4.1
Loading...
Searching...
No Matches
QuadraticBsplines.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
10
11#include <cmath>
12#include <array>
13
14#include "util/Logger.hpp"
15
16std::array<double, 3> NAV::BsplineKF::quadraticBsplines(const double& ti, const double& splineSpacing)
17{
18 std::array<double, 3> qBsplines{ 0.0, 0.0, 0.0 }; // Stacked B-spline, which consists of three single B-splines
19 std::array<double, 4> knots{}; // Knot vector for a single quadratic B-spline
20
21 for (size_t splineIterator = 0; splineIterator < 3; splineIterator++)
22 {
23 if (ti >= 2.0 * splineSpacing)
24 {
25 knots.at(3) = ti - std::fmod(ti, splineSpacing) + splineSpacing * static_cast<double>(splineIterator + 1); // t_k+1
26 knots.at(2) = knots.at(3) - splineSpacing; // t_k
27 knots.at(1) = knots.at(3) - 2.0 * splineSpacing; // t_k-1
28 knots.at(0) = knots.at(3) - 3.0 * splineSpacing; // t_k-2
29 }
30 else if ((ti >= splineSpacing) && (ti < 2.0 * splineSpacing))
31 {
32 switch (splineIterator)
33 {
34 case 0:
35 knots = { 0.0, 0.0, 1.0 * splineSpacing, 2.0 * splineSpacing };
36 break;
37 case 1:
38 knots = { 0.0, 1.0 * splineSpacing, 2.0 * splineSpacing, 3.0 * splineSpacing };
39 break;
40 case 2:
41 knots = { 1.0 * splineSpacing, 2.0 * splineSpacing, 3.0 * splineSpacing, 4.0 * splineSpacing };
42 break;
43
44 default:
45 break;
46 }
47 }
48 else if (ti < 1.0 * splineSpacing)
49 {
50 switch (splineIterator)
51 {
52 case 0:
53 knots = { 0.0, 0.0, 0.0, 1.0 * splineSpacing };
54 break;
55 case 1:
56 knots = { 0.0, 0.0, 1.0 * splineSpacing, 2.0 * splineSpacing };
57 break;
58 case 2:
59 knots = { 0.0, 1.0 * splineSpacing, 2.0 * splineSpacing, 3.0 * splineSpacing };
60 break;
61
62 default:
63 break;
64 }
65 }
66
67 LOG_DATA("ti = {}, B-spline '{}', knots = {}, {}, {}, {}", ti, splineIterator, knots.at(0), knots.at(1), knots.at(2), knots.at(3));
68
69 // B-spline of degree 0
70 std::array<double, 3> N0{};
71 if ((knots.at(0) <= ti) && (ti < knots.at(1)))
72 {
73 N0.at(0) = 1.0;
74 }
75 else if ((knots.at(1) <= ti) && (ti < knots.at(2)))
76 {
77 N0.at(1) = 1.0;
78 }
79 else if ((knots.at(2) <= ti) && (ti < knots.at(3)))
80 {
81 N0.at(2) = 1.0;
82 }
83
84 // B-spline of degree 1
85 std::array<double, 2> N1{};
86 double N11_factor1{};
87 double N11_factor2{};
88 double N12_factor1{};
89 double N12_factor2{};
90
91 if ((knots.at(0) <= ti) && (ti < knots.at(2)))
92 {
93 if (knots.at(1) - knots.at(0) != 0.0)
94 {
95 N11_factor1 = (ti - knots.at(0)) / (knots.at(1) - knots.at(0));
96 }
97 if (knots.at(2) - knots.at(1) != 0.0)
98 {
99 N11_factor2 = (knots.at(2) - ti) / (knots.at(2) - knots.at(1));
100 }
101 N1.at(0) = N11_factor1 * N0.at(0) + N11_factor2 * N0.at(1);
102 }
103 if ((knots.at(1) <= ti) && (ti < knots.at(3)))
104 {
105 if (knots.at(2) - knots.at(1) != 0.0)
106 {
107 N12_factor1 = (ti - knots.at(1)) / (knots.at(2) - knots.at(1));
108 }
109 if (knots.at(3) - knots.at(2) != 0.0)
110 {
111 N12_factor2 = (knots.at(3) - ti) / (knots.at(3) - knots.at(2));
112 }
113 N1.at(1) = N12_factor1 * N0.at(1) + N12_factor2 * N0.at(2);
114 }
115
116 // B-spline of degree 2 (i.e. quadratic)
117 double N2_factor1{};
118 double N2_factor2{};
119
120 if (knots.at(2) - knots.at(0) != 0.0)
121 {
122 N2_factor1 = (ti - knots.at(0)) / (knots.at(2) - knots.at(0));
123 }
124 if (knots.at(3) - knots.at(1) != 0.0)
125 {
126 N2_factor2 = (knots.at(3) - ti) / (knots.at(3) - knots.at(1));
127 }
128 qBsplines.at(splineIterator) = N2_factor1 * N1.at(0) + N2_factor2 * N1.at(1);
129 }
130
131 return qBsplines;
132}
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Constructs four overlapping qaudratic B-splines.
std::array< double, 3 > quadraticBsplines(const double &ti, const double &splineSpacing=1.0)
Set the points/knots of the four B-splines.