Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSpeedSmoother Class Reference

#include <kis_speed_smoother.h>

Classes

struct  Private
 

Public Member Functions

void clear ()
 
qreal getNextSpeed (const QPointF &pt, ulong timestamp)
 
 KisSpeedSmoother ()
 
qreal lastSpeed () const
 
void updateSettings ()
 
 ~KisSpeedSmoother ()
 

Private Member Functions

qreal getNextSpeedImpl (const QPointF &pt, qreal time)
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 15 of file kis_speed_smoother.h.

Constructor & Destructor Documentation

◆ KisSpeedSmoother()

KisSpeedSmoother::KisSpeedSmoother ( )

Definition at line 66 of file kis_speed_smoother.cpp.

68{
70}
const QScopedPointer< Private > m_d
#define MAX_SMOOTH_HISTORY

References updateSettings().

◆ ~KisSpeedSmoother()

KisSpeedSmoother::~KisSpeedSmoother ( )

Definition at line 72 of file kis_speed_smoother.cpp.

73{
74}

Member Function Documentation

◆ clear()

void KisSpeedSmoother::clear ( )

Definition at line 90 of file kis_speed_smoother.cpp.

91{
92 m_d->timer.restart();
93 m_d->distances.clear();
94 m_d->distances.push_back(Private::DistancePoint(0.0, 0.0));
95 m_d->lastPoint = QPointF();
96 m_d->lastSpeed = 0.0;
97}

References m_d.

◆ getNextSpeed()

qreal KisSpeedSmoother::getNextSpeed ( const QPointF & pt,
ulong timestamp )

Definition at line 81 of file kis_speed_smoother.cpp.

82{
83 const qreal time = m_d->useTimestamps ?
84 qreal(timestamp) :
85 qreal(m_d->timer.nsecsElapsed()) / 1000000;
86
87 return getNextSpeedImpl(pt, time);
88}
qreal getNextSpeedImpl(const QPointF &pt, qreal time)

References getNextSpeedImpl(), and m_d.

◆ getNextSpeedImpl()

qreal KisSpeedSmoother::getNextSpeedImpl ( const QPointF & pt,
qreal time )
private

Mind you, we don't care about the specific timestamps of the tablet events! They are not reliable. Instead, we are trying to estimate the sample rate of the tablet itself using the filtered mean accumulator. It works in an assumption that all the tablets generate events at a fixed sample rate.

Definition at line 107 of file kis_speed_smoother.cpp.

108{
109 const qreal dist = kisDistance(pt, m_d->lastPoint);
110
111 if (m_d->lastPoint.isNull()) {
112 m_d->lastPoint = pt;
113 m_d->lastTime = time;
114 m_d->lastSpeed = 0.0;
115 return 0.0;
116 }
117
118 const qreal timeDiff = time - m_d->lastTime;
119
120 m_d->timeDiffsMean.addValue(timeDiff);
121 const qreal avgTimeDiff = m_d->timeDiffsMean.filteredMean();
122
123 m_d->lastPoint = pt;
124 m_d->lastTime = time;
125
126 m_d->distances.push_back(Private::DistancePoint(dist, time));
127
128 Private::DistanceBuffer::const_reverse_iterator it = m_d->distances.rbegin();
129 Private::DistanceBuffer::const_reverse_iterator end = m_d->distances.rend();
130
131 qreal totalDistance = 0;
132 qreal totalTime = 0.0;
133 int itemsSearched = 0;
134
135 for (; it != end; ++it) {
136 itemsSearched++;
137 totalDistance += it->distance;
138
147 totalTime += avgTimeDiff;
148
149 if (itemsSearched > m_d->numSmoothingSamples &&
150 totalDistance > MIN_TRACKING_DISTANCE) {
151
152 break;
153 }
154 }
155
156 if (totalTime > 0 && totalDistance > MIN_TRACKING_DISTANCE) {
157 m_d->lastSpeed = totalDistance / totalTime;
158 }
159
160 return m_d->lastSpeed;
161}
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:190
#define MIN_TRACKING_DISTANCE

References kisDistance(), m_d, and MIN_TRACKING_DISTANCE.

◆ lastSpeed()

qreal KisSpeedSmoother::lastSpeed ( ) const

Definition at line 76 of file kis_speed_smoother.cpp.

77{
78 return m_d->lastSpeed;
79}

References m_d.

◆ updateSettings()

void KisSpeedSmoother::updateSettings ( )

Definition at line 99 of file kis_speed_smoother.cpp.

100{
101
102 KisConfig cfg(true);
103 m_d->useTimestamps = cfg.readEntry("useTimestampsForBrushSpeed", false);
104 m_d->numSmoothingSamples = cfg.readEntry("speedValueSmoothing", 3);
105}

References m_d, and KisConfig::readEntry().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisSpeedSmoother::m_d
private

Definition at line 31 of file kis_speed_smoother.h.


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