-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStreamingAverager.cpp
44 lines (38 loc) · 1.15 KB
/
StreamingAverager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdafx.h"
#include "Version.h"
#include "StreamingAverager.h"
#include "Util.h"
namespace ark {
StreamingAverager::StreamingAverager(int frequency, float rejectionDistance) :
sampleFrequency(frequency), rejectionThreshold(rejectionDistance * rejectionDistance)
{
ASSERT(frequency > 0, "Sampling frequency must be at least 1");
}
Vec3f StreamingAverager::addDataPoint(Vec3f pt)
{
if (util::norm(pt - getCurrentAverage()) > rejectionThreshold)
{
addEmptyPoint();
}
else {
if (dataPoints.size() >= sampleFrequency)
{
currentValue -= dataPoints.front();
dataPoints.pop_front();
}
dataPoints.push_back(pt);
currentValue += pt;
}
return getCurrentAverage();
}
void StreamingAverager::addEmptyPoint()
{
if (dataPoints.empty()) return;
currentValue -= dataPoints.front();;
dataPoints.pop_front();
}
Vec3f StreamingAverager::getCurrentAverage()
{
return dataPoints.empty() ? 0 : currentValue / (int)dataPoints.size();
}
}