From 53dd12a66884540b87fe428383e2f79d0f5e32ba Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Fri, 1 Jun 2012 13:24:04 -0700 Subject: Implement an integrating VelocityTracker strategy. This algorithm better tolerates certain kinds of errors in the touch input than the least squares strategy but it may underestimate the velocity of accelerating movements. This algorithm is mainly of interest as a baseline for testing and comparison with the least squares algorithm, which remains the default. Bug: 6413587 Change-Id: I8ddb50084e44875e234717907e5b06d03f59788c --- include/androidfw/VelocityTracker.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'include') diff --git a/include/androidfw/VelocityTracker.h b/include/androidfw/VelocityTracker.h index 1d44f13..e600c5a 100644 --- a/include/androidfw/VelocityTracker.h +++ b/include/androidfw/VelocityTracker.h @@ -172,6 +172,39 @@ private: Movement mMovements[HISTORY_SIZE]; }; + +/* + * Velocity tracker algorithm that uses an IIR filter. + */ +class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy { +public: + IntegratingVelocityTrackerStrategy(); + ~IntegratingVelocityTrackerStrategy(); + + virtual void clear(); + virtual void clearPointers(BitSet32 idBits); + virtual void addMovement(nsecs_t eventTime, BitSet32 idBits, + const VelocityTracker::Position* positions); + virtual bool getEstimator(uint32_t id, VelocityTracker::Estimator* outEstimator) const; + +private: + // Current state estimate for a particular pointer. + struct State { + nsecs_t updateTime; + bool first; + + float xpos, xvel; + float ypos, yvel; + }; + + BitSet32 mPointerIdBits; + State mPointerState[MAX_POINTER_ID + 1]; + + static void initState(State& state, nsecs_t eventTime, float xpos, float ypos); + static void updateState(State& state, nsecs_t eventTime, float xpos, float ypos); + static void populateEstimator(const State& state, VelocityTracker::Estimator* outEstimator); +}; + } // namespace android #endif // _ANDROIDFW_VELOCITY_TRACKER_H -- cgit v1.1