openni2_timer_filter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Author: Julius Kammerl (jkammerl@willowgarage.com)
30  */
31 
33 #include <algorithm>
34 
35 
36 namespace openni2_wrapper
37 {
38 
40  filter_len_(filter_len)
41 {
42 }
43 
45 {
46 }
47 
48 void OpenNI2TimerFilter::addSample(double sample)
49 {
50  buffer_.push_back(sample);
51  if (buffer_.size()>filter_len_)
52  buffer_.pop_front();
53 }
54 
56 {
57  if (buffer_.size()>0)
58  {
59  std::deque<double> sort_buffer = buffer_;
60 
61  std::sort(sort_buffer.begin(), sort_buffer.end());
62 
63  return sort_buffer[sort_buffer.size()/2];
64  } else
65  return 0.0;
66 }
67 
69 {
70  if (buffer_.size() > 0)
71  {
72  double sum = 0;
73 
74  std::deque<double>::const_iterator it = buffer_.begin();
75  std::deque<double>::const_iterator it_end = buffer_.end();
76 
77  while (it != it_end)
78  {
79  sum += *(it++);
80  }
81 
82  return sum / static_cast<double>(buffer_.size());
83  } else
84  return 0.0;
85 }
86 
87 
89 {
90  buffer_.clear();
91 }
92 
93 
94 } //namespace openni2_wrapper


openni2_camera
Author(s): Julius Kammerl
autogenerated on Fri Jun 7 2019 22:05:43