Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_SensorFilter.cpp
Go to the documentation of this file.
1 /************************************************************************************
2 
3 PublicHeader: OVR.h
4 Filename : OVR_SensorFilter.cpp
5 Content : Basic filtering of sensor this->Data
6 Created : March 7, 2013
7 Authors : Steve LaValle, Anna Yershova, Max Katsev
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 *************************************************************************************/
27 
28 #include "OVR_SensorFilter.h"
29 
30 namespace OVR {
31 
32 template <typename T>
34 {
35  Vector3<T> result;
36  T* slice = (T*) OVR_ALLOC(this->ElemCount * sizeof(T));
37 
38  for (int coord = 0; coord < 3; coord++)
39  {
40  for (int i = 0; i < this->ElemCount; i++)
41  slice[i] = this->Data[i][coord];
42  result[coord] = Alg::Median(ArrayAdaptor(slice, this->ElemCount));
43  }
44 
45  OVR_FREE(slice);
46  return result;
47 }
48 
49 // Only the diagonal of the covariance matrix.
50 template <typename T>
52 {
53  Vector3<T> mean = this->Mean();
54  Vector3<T> total;
55  for (int i = 0; i < this->ElemCount; i++)
56  {
57  total.x += (this->Data[i].x - mean.x) * (this->Data[i].x - mean.x);
58  total.y += (this->Data[i].y - mean.y) * (this->Data[i].y - mean.y);
59  total.z += (this->Data[i].z - mean.z) * (this->Data[i].z - mean.z);
60  }
61  return total / (float) this->ElemCount;
62 }
63 
64 template <typename T>
66 {
67  Vector3<T> mean = this->Mean();
68  Matrix3<T> total;
69  for (int i = 0; i < this->ElemCount; i++)
70  {
71  total.M[0][0] += (this->Data[i].x - mean.x) * (this->Data[i].x - mean.x);
72  total.M[1][0] += (this->Data[i].y - mean.y) * (this->Data[i].x - mean.x);
73  total.M[2][0] += (this->Data[i].z - mean.z) * (this->Data[i].x - mean.x);
74  total.M[1][1] += (this->Data[i].y - mean.y) * (this->Data[i].y - mean.y);
75  total.M[2][1] += (this->Data[i].z - mean.z) * (this->Data[i].y - mean.y);
76  total.M[2][2] += (this->Data[i].z - mean.z) * (this->Data[i].z - mean.z);
77  }
78  total.M[0][1] = total.M[1][0];
79  total.M[0][2] = total.M[2][0];
80  total.M[1][2] = total.M[2][1];
81  for (int i = 0; i < 3; i++)
82  for (int j = 0; j < 3; j++)
83  total.M[i][j] /= (float) this->ElemCount;
84  return total;
85 }
86 
87 template <typename T>
89 {
90  Matrix3<T> cov = this->Covariance();
91  Vector3<T> pearson;
92  pearson.x = cov.M[0][1]/(sqrt(cov.M[0][0])*sqrt(cov.M[1][1]));
93  pearson.y = cov.M[1][2]/(sqrt(cov.M[1][1])*sqrt(cov.M[2][2]));
94  pearson.z = cov.M[2][0]/(sqrt(cov.M[2][2])*sqrt(cov.M[0][0]));
95 
96  return pearson;
97 }
98 
99 } //namespace OVR
T M[3][3]
Definition: OVR_Math.h:1866
Vector3< T > Median() const
Matrix3< T > Covariance() const
Vector3< T > PearsonCoefficient() const
Vector3< T > Variance() const
Array::ValueType & Median(Array &arr)
Definition: OVR_Alg.h:443
#define OVR_ALLOC(s)
#define OVR_FREE(p)