oculus1

diff libovr/Src/OVR_SensorFilter.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/OVR_SensorFilter.h	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,99 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   OVR.h
     1.7 +Filename    :   OVR_SensorFilter.h
     1.8 +Content     :   Basic filtering of sensor data
     1.9 +Created     :   March 7, 2013
    1.10 +Authors     :   Steve LaValle, Anna Yershova
    1.11 +
    1.12 +Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
    1.13 +
    1.14 +Use of this software is subject to the terms of the Oculus license
    1.15 +agreement provided at the time of installation or download, or which
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +*************************************************************************************/
    1.19 +
    1.20 +#ifndef OVR_SensorFilter_h
    1.21 +#define OVR_SensorFilter_h
    1.22 +
    1.23 +#include "Kernel/OVR_Math.h"
    1.24 +
    1.25 +
    1.26 +namespace OVR {
    1.27 +
    1.28 +// This class maintains a sliding window of sensor data taken over time and implements
    1.29 +// various simple filters, most of which are linear functions of the data history.
    1.30 +class SensorFilter
    1.31 +{
    1.32 +    enum
    1.33 +    {
    1.34 +        MaxFilterSize     = 100,
    1.35 +        DefaultFilterSize = 20
    1.36 +    };
    1.37 +
    1.38 +private:
    1.39 +    int         LastIdx;                    // The index of the last element that was added to the array
    1.40 +    int         Size;                       // The window size (number of elements)
    1.41 +    Vector3f    Elements[MaxFilterSize]; 
    1.42 +
    1.43 +public:
    1.44 +    // Create a new filter with default size
    1.45 +    SensorFilter() 
    1.46 +    {
    1.47 +        LastIdx = -1;
    1.48 +        Size = DefaultFilterSize;
    1.49 +    };
    1.50 +
    1.51 +    // Create a new filter with size i
    1.52 +    SensorFilter(int i) 
    1.53 +    {
    1.54 +        OVR_ASSERT(i <= MaxFilterSize);
    1.55 +        LastIdx = -1;
    1.56 +        Size = i;
    1.57 +    };
    1.58 +
    1.59 +
    1.60 +    // Create a new element to the filter
    1.61 +    void AddElement (const Vector3f &e) 
    1.62 +    {
    1.63 +        if (LastIdx == Size - 1) 
    1.64 +            LastIdx = 0;
    1.65 +        else                            
    1.66 +            LastIdx++;
    1.67 +
    1.68 +        Elements[LastIdx] = e;
    1.69 +    };
    1.70 +
    1.71 +    // Get element i.  0 is the most recent, 1 is one step ago, 2 is two steps ago, ...
    1.72 +    Vector3f GetPrev(int i) const
    1.73 +    {
    1.74 +		OVR_ASSERT(i >= 0); // 
    1.75 +        int idx = (LastIdx - i);
    1.76 +        if (idx < 0) // Fix the wraparound case
    1.77 +            idx += Size;
    1.78 +		OVR_ASSERT(idx >= 0); // Multiple wraparounds not allowed
    1.79 +        return Elements[idx];
    1.80 +    };
    1.81 +
    1.82 +    // Simple statistics
    1.83 +    Vector3f Total() const;
    1.84 +    Vector3f Mean() const;
    1.85 +    Vector3f Median() const;
    1.86 +    Vector3f Variance() const; // The diagonal of covariance matrix
    1.87 +    Matrix4f Covariance() const;
    1.88 +    Vector3f PearsonCoefficient() const;
    1.89 +
    1.90 +    // A popular family of smoothing filters and smoothed derivatives
    1.91 +    Vector3f SavitzkyGolaySmooth8() const;
    1.92 +    Vector3f SavitzkyGolayDerivative4() const;
    1.93 +    Vector3f SavitzkyGolayDerivative5() const;
    1.94 +    Vector3f SavitzkyGolayDerivative12() const; 
    1.95 +    Vector3f SavitzkyGolayDerivativeN(int n) const;
    1.96 +
    1.97 +    ~SensorFilter() {};
    1.98 +};
    1.99 +
   1.100 +} //namespace OVR
   1.101 +
   1.102 +#endif // OVR_SensorFilter_h