Krita Source Code Documentation
Loading...
Searching...
No Matches
KisLegacyCubicSpline< T_point, T > Class Template Reference

#include <kis_cubic_curve_spline.h>

Public Member Functions

begin () const
 
void createSpline (const QList< T_point > &a)
 
end () const
 
getValue (T x) const
 
 KisLegacyCubicSpline ()
 
 KisLegacyCubicSpline (const QList< T_point > &a)
 

Protected Member Functions

int findRegion (T x, T &x0) const
 

Protected Attributes

QList< T > m_a
 
QVector< T > m_b
 
m_begin
 
QVector< T > m_c
 
QVector< T > m_d
 
m_end
 
QVector< T > m_h
 
int m_intervals {0}
 

Detailed Description

template<typename T_point, typename T>
class KisLegacyCubicSpline< T_point, T >

Definition at line 96 of file kis_cubic_curve_spline.h.

Constructor & Destructor Documentation

◆ KisLegacyCubicSpline() [1/2]

template<typename T_point , typename T >
KisLegacyCubicSpline< T_point, T >::KisLegacyCubicSpline ( )
inline

Definition at line 120 of file kis_cubic_curve_spline.h.

120{}

◆ KisLegacyCubicSpline() [2/2]

template<typename T_point , typename T >
KisLegacyCubicSpline< T_point, T >::KisLegacyCubicSpline ( const QList< T_point > & a)
inline

Definition at line 121 of file kis_cubic_curve_spline.h.

121 {
122 createSpline(a);
123 }
void createSpline(const QList< T_point > &a)

References KisLegacyCubicSpline< T_point, T >::createSpline().

Member Function Documentation

◆ begin()

template<typename T_point , typename T >
T KisLegacyCubicSpline< T_point, T >::begin ( ) const
inline

Definition at line 188 of file kis_cubic_curve_spline.h.

188 {
189 return m_begin;
190 }

References KisLegacyCubicSpline< T_point, T >::m_begin.

◆ createSpline()

template<typename T_point , typename T >
void KisLegacyCubicSpline< T_point, T >::createSpline ( const QList< T_point > & a)
inline

Create new spline and precalculate some values for future

- base points of the spline

Definition at line 131 of file kis_cubic_curve_spline.h.

131 {
132 int intervals = m_intervals = a.size() - 1;
133 int i;
134 m_begin = a.first().x();
135 m_end = a.last().x();
136
137 m_a.clear();
138 m_b.resize(intervals);
139 m_c.clear();
140 m_d.resize(intervals);
141 m_h.resize(intervals);
142
143 for (i = 0; i < intervals; i++) {
144 m_h[i] = a[i+1].x() - a[i].x();
145 m_a.append(a[i].y());
146 }
147 m_a.append(a.last().y());
148
149
150 QList<T> tri_b;
151 QList<T> tri_f;
152 QList<T> tri_a; /* equals to @tri_c */
153
154 for (i = 0; i < intervals - 1; i++) {
155 tri_b.append(2.*(m_h[i] + m_h[i+1]));
156
157 tri_f.append(6.*((m_a[i+2] - m_a[i+1]) / m_h[i+1] - (m_a[i+1] - m_a[i]) / m_h[i]));
158 }
159 for (i = 1; i < intervals - 1; i++)
160 tri_a.append(m_h[i]);
161
162 if (intervals > 1) {
163 m_c = KisTridiagonalSystem<T>::calculate(tri_a, tri_b, tri_a, tri_f);
164 }
165 m_c.prepend(0);
166 m_c.append(0);
167
168 for (i = 0; i < intervals; i++)
169 m_d[i] = (m_c[i+1] - m_c[i]) / m_h[i];
170
171 for (i = 0; i < intervals; i++)
172 m_b[i] = -0.5 * (m_c[i] * m_h[i]) - (1 / 6.0) * (m_d[i] * m_h[i] * m_h[i]) + (m_a[i+1] - m_a[i]) / m_h[i];
173 }
static QVector< T > calculate(QList< T > &a, QList< T > &b, QList< T > &c, QList< T > &f)

References KisTridiagonalSystem< T >::calculate(), KisLegacyCubicSpline< T_point, T >::m_a, KisLegacyCubicSpline< T_point, T >::m_b, KisLegacyCubicSpline< T_point, T >::m_begin, KisLegacyCubicSpline< T_point, T >::m_c, KisLegacyCubicSpline< T_point, T >::m_d, KisLegacyCubicSpline< T_point, T >::m_end, KisLegacyCubicSpline< T_point, T >::m_h, and KisLegacyCubicSpline< T_point, T >::m_intervals.

◆ end()

template<typename T_point , typename T >
T KisLegacyCubicSpline< T_point, T >::end ( ) const
inline

Definition at line 192 of file kis_cubic_curve_spline.h.

192 {
193 return m_end;
194 }

References KisLegacyCubicSpline< T_point, T >::m_end.

◆ findRegion()

template<typename T_point , typename T >
int KisLegacyCubicSpline< T_point, T >::findRegion ( T x,
T & x0 ) const
inlineprotected

findRegion - Searches for the region containing @x @x0 - out parameter, containing beginning of the region

Returns
- index of the region

Definition at line 203 of file kis_cubic_curve_spline.h.

203 {
204 int i;
205 x0 = m_begin;
206 for (i = 0; i < m_intervals; i++) {
207 if (x >= x0 && x < x0 + m_h[i])
208 return i;
209 x0 += m_h[i];
210 }
211 if (x >= x0) {
212 x0 -= m_h[m_intervals-1];
213 return m_intervals - 1;
214 }
215
216 qDebug("X value: %f\n", x);
217 qDebug("m_begin: %f\n", m_begin);
218 qDebug("m_end : %f\n", m_end);
219 Q_ASSERT_X(0, "findRegion", "X value is outside regions");
220 /* **never reached** */
221 return -1;
222 }

References KisLegacyCubicSpline< T_point, T >::m_begin, KisLegacyCubicSpline< T_point, T >::m_end, KisLegacyCubicSpline< T_point, T >::m_h, and KisLegacyCubicSpline< T_point, T >::m_intervals.

◆ getValue()

template<typename T_point , typename T >
T KisLegacyCubicSpline< T_point, T >::getValue ( T x) const
inline

Get value of precalculated spline in the point @x

Definition at line 178 of file kis_cubic_curve_spline.h.

178 {
179 T x0;
180 int i = findRegion(x, x0);
181 /* TODO: check for asm equivalent */
182 return m_a[i] +
183 m_b[i] *(x - x0) +
184 0.5 * m_c[i] *(x - x0) *(x - x0) +
185 (1 / 6.0)* m_d[i] *(x - x0) *(x - x0) *(x - x0);
186 }
int findRegion(T x, T &x0) const

References KisLegacyCubicSpline< T_point, T >::findRegion(), KisLegacyCubicSpline< T_point, T >::m_a, KisLegacyCubicSpline< T_point, T >::m_b, KisLegacyCubicSpline< T_point, T >::m_c, and KisLegacyCubicSpline< T_point, T >::m_d.

Member Data Documentation

◆ m_a

template<typename T_point , typename T >
QList<T> KisLegacyCubicSpline< T_point, T >::m_a
protected

s[i](x)=a[i] + b[i] * (x-x[i]) + 1/2 * c[i] * (x-x[i])^2 + 1/6 * d[i] * (x-x[i])^3

h[i]=x[i+1]-x[i]

Definition at line 109 of file kis_cubic_curve_spline.h.

◆ m_b

template<typename T_point , typename T >
QVector<T> KisLegacyCubicSpline< T_point, T >::m_b
protected

Definition at line 110 of file kis_cubic_curve_spline.h.

◆ m_begin

template<typename T_point , typename T >
T KisLegacyCubicSpline< T_point, T >::m_begin
protected

Definition at line 115 of file kis_cubic_curve_spline.h.

◆ m_c

template<typename T_point , typename T >
QVector<T> KisLegacyCubicSpline< T_point, T >::m_c
protected

Definition at line 111 of file kis_cubic_curve_spline.h.

◆ m_d

template<typename T_point , typename T >
QVector<T> KisLegacyCubicSpline< T_point, T >::m_d
protected

Definition at line 112 of file kis_cubic_curve_spline.h.

◆ m_end

template<typename T_point , typename T >
T KisLegacyCubicSpline< T_point, T >::m_end
protected

Definition at line 116 of file kis_cubic_curve_spline.h.

◆ m_h

template<typename T_point , typename T >
QVector<T> KisLegacyCubicSpline< T_point, T >::m_h
protected

Definition at line 114 of file kis_cubic_curve_spline.h.

◆ m_intervals

template<typename T_point , typename T >
int KisLegacyCubicSpline< T_point, T >::m_intervals {0}
protected

Definition at line 117 of file kis_cubic_curve_spline.h.

117{0};

The documentation for this class was generated from the following file: