stat_vector_3d.cpp
Go to the documentation of this file.
1 /*
2  * Three dimensional statistic vector for use with the
3  * for ROS Node which interfaces with a wiimote control unit.
4  * Copyright (c) 2016, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  */
15 
16 /*
17  * Initial C++ implementation by
18  * Mark Horn <mark.d.horn@intel.com>
19  *
20  * Revisions:
21  *
22  */
23 
24 #include "wiimote/stat_vector_3d.h"
25 
26 #include "ros/ros.h"
27 
28 #include <numeric>
29 #include <functional>
30 #include <algorithm>
31 #include <math.h>
32 
33 
35 {
36  count_ = 0;
37 }
38 
39 StatVector3d::StatVector3d(int x, int y, int z)
40 {
41  count_ = 0;
42 
43  addData(x, y, z);
44 }
45 
47 {
48  x_.clear();
49  y_.clear();
50  z_.clear();
51 
52  count_ = 0;
53 }
54 
56 {
57  return count_;
58 }
59 
60 void StatVector3d::addData(int x, int y, int z)
61 {
62  ++count_;
63 
64  x_.push_back(x);
65  y_.push_back(y);
66  z_.push_back(z);
67 }
68 
70 {
71  TVectorDouble result;
72 
73  if (x_.size() < 1)
74  {
75  ROS_ERROR("StatVector3d:: Not enough data points for calculations!");
76  ros::Exception("Not enough data points for calculations");
77 
78  return result;
79  }
80 
81  double x_sum = std::accumulate(std::begin(x_), std::end(x_), 0.0);
82  result.push_back(x_sum / x_.size());
83 
84  double y_sum = std::accumulate(std::begin(y_), std::end(y_), 0.0);
85  result.push_back(y_sum / y_.size());
86 
87  double z_sum = std::accumulate(std::begin(z_), std::end(z_), 0.0);
88  result.push_back(z_sum / z_.size());
89 
90  return result;
91 }
92 
94 {
96 
97  std::transform(mean.begin(), mean.end(), mean.begin(),
98  std::bind1st(std::multiplies<double>(), scale));
99 
100  return mean;
101 }
102 
104 {
105  TVectorDouble result;
106 
108 
109  if (x_.size() < 2)
110  {
111  ROS_ERROR("StatVector3d:: Not enough data points for calculations!");
112  ros::Exception("Not enough data points for calculations");
113 
114  return result;
115  }
116 
117  double accum = 0.0;
118  std::for_each(std::begin(x_), std::end(x_), [&](const double d) // NOLINT(build/c++11)
119  {
120  accum += (d - mean.at(0)) * (d - mean.at(0));
121  }); // NOLINT(whitespace/braces)
122 
123  result.push_back(accum / (x_.size()-1));
124 
125  accum = 0.0;
126  std::for_each(std::begin(y_), std::end(y_), [&](const double d) // NOLINT(build/c++11)
127  {
128  accum += (d - mean.at(1)) * (d - mean.at(1));
129  }); // NOLINT(whitespace/braces)
130 
131  result.push_back(accum / (y_.size()-1));
132 
133  accum = 0.0;
134  std::for_each(std::begin(z_), std::end(z_), [&](const double d) // NOLINT(build/c++11)
135  {
136  accum += (d - mean.at(2)) * (d - mean.at(2));
137  }); // NOLINT(whitespace/braces)
138 
139  result.push_back(accum / (z_.size()-1));
140 
141  return result;
142 }
143 
145 {
146  TVectorDouble variance = getVarianceRaw();
147 
148  std::transform(variance.begin(), variance.end(), variance.begin(),
149  std::bind1st(std::multiplies<double>(), scale));
150 
151  return variance;
152 }
153 
155 {
156  TVectorDouble result;
157 
158  TVectorDouble variance = getVarianceRaw();
159 
160  result.push_back(sqrt(variance.at(0)));
161  result.push_back(sqrt(variance.at(1)));
162  result.push_back(sqrt(variance.at(2)));
163 
164  return result;
165 }
166 
168 {
170 
171  std::transform(stddev.begin(), stddev.end(), stddev.begin(),
172  std::bind1st(std::multiplies<double>(), scale));
173 
174  return stddev;
175 }
d
Definition: setup.py:6
void addData(int x, int y, int z)
TVectorDouble getStandardDeviationRaw()
TVectorDouble getMeanScaled(double scale)
TVectorDouble getVarianceRaw()
std::vector< int > x_
std::vector< int > y_
std::vector< int > z_
TVectorDouble getMeanRaw()
TVectorDouble getVarianceScaled(double scale)
#define ROS_ERROR(...)
TVectorDouble getStandardDeviationScaled(double scale)
std::vector< double > TVectorDouble


wiimote
Author(s): Andreas Paepcke, Melonee Wise, Mark Horn
autogenerated on Fri Jun 7 2019 22:01:33