Filter.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef FILTER_H
25 #define FILTER_H
26 
33 #include "Alvar.h"
34 #include <algorithm>
35 #include <deque>
36 #include <vector>
37 #include <cmath>
38 
39 namespace alvar {
40 
80 protected:
81  double value;
82 public:
84  Filter();
86  double get() const { return value; }
88  operator double () { return get(); }
90  virtual double next(double y) = 0;
92  virtual void reset() = 0;
93 };
94 
107 protected:
108  unsigned int count;
109  unsigned int window_size;
110  std::deque<double> buffer;
111  void push_to_buffer(double y);
112 public:
113  FilterAverage(int size=3) { setWindowSize(size); }
114  void setWindowSize(int size) { window_size=size; count=0; }
115  int getWindowSize() { return window_size; }
116  int getCurrentSize() { return (int) buffer.size(); }
117  double operator= (double _value) { return next(_value); }
118  virtual double next(double y);
119  virtual void reset();
120  double deviation() const;
121 };
122 
134  std::vector<double> sort_buffer;
135 public:
136  FilterMedian(int size=3) { setWindowSize(size); }
137  void setWindowSize(int size) {
139  sort_buffer.resize(size);
140  }
141  double operator= (double _value) { return next(_value); }
142  virtual double next(double y);
143 };
144 
160 protected:
161  double alpha;
162  bool breset;
163 public:
164  FilterRunningAverage(double _alpha=0.5) { breset=true; setAlpha(_alpha); }
165  void setAlpha(double _alpha) { alpha=std::max(std::min(_alpha,1.0),0.0); }
166  double getAlpha() { return alpha; }
167  double operator= (double _value) { return next(_value); }
168  virtual double next(double y);
169  virtual void reset();
170 };
171 
188 protected:
189  double gamma;
190  double slope;
191 public:
192  FilterDoubleExponentialSmoothing(double _alpha=0.5, double _gamma=1.0) : FilterRunningAverage(_alpha) {
193  setGamma(_gamma);
194  }
195  void setGamma(double _gamma) { gamma=std::max(std::min(_gamma,1.0),0.0); }
196  double getGamma() { return gamma; }
197  double operator= (double _value) { return next(_value); }
198  virtual double next(double y);
199 };
200 
205 template <class F>
207 protected:
208  double *tmp;
209  std::vector<F> arr;
210 public:
211  FilterArray(int size) {
212  tmp = NULL;
213  SetSize(size);
214  }
216  delete [] tmp;
217  }
218  size_t GetSize() {
219  return arr.size();
220  }
221  void SetSize(size_t size) {
222  if (tmp) delete [] tmp;
223  tmp = new double[size];
224  arr.resize(size);
225  }
226  F &operator[](size_t i) {
227  return arr[i];
228  }
229  const double *as_double_array(size_t start_i=0) {
230  for (size_t i=0; i<arr.size(); i++) {
231  tmp[i] = arr[i];
232  }
233  return &(tmp[start_i]);
234  }
235 };
236 
237 } // namespace alvar
238 
239 #endif
Main ALVAR namespace.
Definition: Alvar.h:174
unsigned int count
Definition: Filter.h:108
void setWindowSize(int size)
Definition: Filter.h:137
void SetSize(size_t size)
Definition: Filter.h:221
FilterDoubleExponentialSmoothing provides an weighted running average filter
Definition: Filter.h:187
const double * as_double_array(size_t start_i=0)
Definition: Filter.h:229
std::vector< double > sort_buffer
Definition: Filter.h:134
TFSIMD_FORCE_INLINE const tfScalar & y() const
FilterDoubleExponentialSmoothing(double _alpha=0.5, double _gamma=1.0)
Definition: Filter.h:192
F & operator[](size_t i)
Definition: Filter.h:226
std::vector< F > arr
Definition: Filter.h:209
Filter is pure virtual class describing the basic virtual interface for all filters ...
Definition: Filter.h:79
FilterMedian(int size=3)
Definition: Filter.h:136
void setAlpha(double _alpha)
Definition: Filter.h:165
double * tmp
Definition: Filter.h:208
FilterRunningAverage provides an weighted running average filter
Definition: Filter.h:159
FilterArray(int size)
Definition: Filter.h:211
double value
Definition: Filter.h:81
Class for handling an array of filtered values.
Definition: Filter.h:206
FilterAverage provides an average filter
Definition: Filter.h:106
#define ALVAR_EXPORT
Definition: Alvar.h:168
FilterMedian provides an median filter
Definition: Filter.h:133
void setWindowSize(int size)
Definition: Filter.h:114
FilterRunningAverage(double _alpha=0.5)
Definition: Filter.h:164
std::deque< double > buffer
Definition: Filter.h:110
int getCurrentSize()
Definition: Filter.h:116
size_t GetSize()
Definition: Filter.h:218
unsigned int window_size
Definition: Filter.h:109
FilterAverage(int size=3)
Definition: Filter.h:113
This file defines library export definitions, version numbers and build information.


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04