oculus1

view libovr/Src/OVR_SensorFilter.h @ 18:1b107de821c1

fixed the test to work with non-pow2 textures
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 26 Sep 2013 10:33:08 +0300
parents
children
line source
1 /************************************************************************************
3 PublicHeader: OVR.h
4 Filename : OVR_SensorFilter.h
5 Content : Basic filtering of sensor data
6 Created : March 7, 2013
7 Authors : Steve LaValle, Anna Yershova
9 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
11 Use of this software is subject to the terms of the Oculus license
12 agreement provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 *************************************************************************************/
17 #ifndef OVR_SensorFilter_h
18 #define OVR_SensorFilter_h
20 #include "Kernel/OVR_Math.h"
23 namespace OVR {
25 // This class maintains a sliding window of sensor data taken over time and implements
26 // various simple filters, most of which are linear functions of the data history.
27 class SensorFilter
28 {
29 enum
30 {
31 MaxFilterSize = 100,
32 DefaultFilterSize = 20
33 };
35 private:
36 int LastIdx; // The index of the last element that was added to the array
37 int Size; // The window size (number of elements)
38 Vector3f Elements[MaxFilterSize];
40 public:
41 // Create a new filter with default size
42 SensorFilter()
43 {
44 LastIdx = -1;
45 Size = DefaultFilterSize;
46 };
48 // Create a new filter with size i
49 SensorFilter(int i)
50 {
51 OVR_ASSERT(i <= MaxFilterSize);
52 LastIdx = -1;
53 Size = i;
54 };
57 // Create a new element to the filter
58 void AddElement (const Vector3f &e)
59 {
60 if (LastIdx == Size - 1)
61 LastIdx = 0;
62 else
63 LastIdx++;
65 Elements[LastIdx] = e;
66 };
68 // Get element i. 0 is the most recent, 1 is one step ago, 2 is two steps ago, ...
69 Vector3f GetPrev(int i) const
70 {
71 OVR_ASSERT(i >= 0); //
72 int idx = (LastIdx - i);
73 if (idx < 0) // Fix the wraparound case
74 idx += Size;
75 OVR_ASSERT(idx >= 0); // Multiple wraparounds not allowed
76 return Elements[idx];
77 };
79 // Simple statistics
80 Vector3f Total() const;
81 Vector3f Mean() const;
82 Vector3f Median() const;
83 Vector3f Variance() const; // The diagonal of covariance matrix
84 Matrix4f Covariance() const;
85 Vector3f PearsonCoefficient() const;
87 // A popular family of smoothing filters and smoothed derivatives
88 Vector3f SavitzkyGolaySmooth8() const;
89 Vector3f SavitzkyGolayDerivative4() const;
90 Vector3f SavitzkyGolayDerivative5() const;
91 Vector3f SavitzkyGolayDerivative12() const;
92 Vector3f SavitzkyGolayDerivativeN(int n) const;
94 ~SensorFilter() {};
95 };
97 } //namespace OVR
99 #endif // OVR_SensorFilter_h