• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <map>
6 #include <memory>
7 #include <gtest/gtest.h>  // for FRIEND_TEST
8 
9 #include "include/filter_interpreter.h"
10 #include "include/finger_metrics.h"
11 #include "include/gestures.h"
12 #include "include/prop_registry.h"
13 #include "include/tracer.h"
14 
15 #ifndef GESTURES_BOX_FILTER_INTERPRETER_H_
16 #define GESTURES_BOX_FILTER_INTERPRETER_H_
17 
18 namespace gestures {
19 
20 // This filter interpreter applies simple "box" algorithm to fingers as they
21 // pass through the filter. The purpose is to filter noisy input.
22 // The algorithm is: For each axis:
23 // - For each input point, compare X distance to previous output point for
24 //   the finger.
25 // - If the X distance is under box_width_ / 2, report the old location.
26 // - Report the new point shifted box_width_ / 2 toward the previous
27 //   output point.
28 // - Apply box_height_ to Y distance.
29 //
30 // The way to think about this is that there is a box around the previous
31 // output point with a width and height of box_width_. If a new point is
32 // within that box, report the old location (don't move the box). If the new
33 // point is outside, shift the box over to include the new point, then report
34 // the new center of the box.
35 
36 class BoxFilterInterpreter : public FilterInterpreter, public PropertyDelegate {
37   FRIEND_TEST(BoxFilterInterpreterTest, SimpleTest);
38  public:
39   // Takes ownership of |next|:
40   BoxFilterInterpreter(PropRegistry* prop_reg, Interpreter* next,
41                        Tracer* tracer);
~BoxFilterInterpreter()42   virtual ~BoxFilterInterpreter() {}
43 
44  protected:
45   virtual void SyncInterpretImpl(HardwareState* hwstate, stime_t* timeout);
46 
47  private:
48   std::map<short, FingerState> previous_output_;
49 
50   DoubleProperty box_width_;
51   DoubleProperty box_height_;
52 };
53 
54 }  // namespace gestures
55 
56 #endif  // GESTURES_BOX_FILTER_INTERPRETER_H_
57