Commit 230fb1f2 authored by Rob Schonberger's avatar Rob Schonberger Committed by Commit Bot

Add 1 util method, test it. Add a Model abstract class with inline docs.

This CL could be split in two.

First, adds a method to Stroke for the biggest touch-major of that
stroke, and the corresponding unit test.

More importantly: Adds an abstract class for what a checked in model
looks like. All the configuration is accessible from the model when
instantiated, and no implementation is added. All the fields in
configuration are documented, and an explicit constructor for the
configuration is added since this counts as a complex struct.

Bug: 1009290
Change-Id: I7eeca918540e80a34133230c6d0a67c6b58c2af5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864490Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Rob Schonberger <robsc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706743}
parent e044af60
......@@ -122,6 +122,8 @@ if (use_ozone) {
"evdev/touch_filter/horizontally_aligned_touch_noise_filter.h",
"evdev/touch_filter/low_pressure_filter.cc",
"evdev/touch_filter/low_pressure_filter.h",
"evdev/touch_filter/neural_stylus_palm_detection_filter_model.cc",
"evdev/touch_filter/neural_stylus_palm_detection_filter_model.h",
"evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc",
"evdev/touch_filter/neural_stylus_palm_detection_filter_util.h",
"evdev/touch_filter/open_palm_detection_filter.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h"
namespace ui {
NeuralStylusPalmDetectionFilterModelConfig::
NeuralStylusPalmDetectionFilterModelConfig() = default;
NeuralStylusPalmDetectionFilterModelConfig::
NeuralStylusPalmDetectionFilterModelConfig(
const NeuralStylusPalmDetectionFilterModelConfig& other) = default;
} // namespace ui
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_
#include <cstdint>
#include <vector>
#include "base/time/time.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
namespace ui {
struct EVENTS_OZONE_EVDEV_EXPORT NeuralStylusPalmDetectionFilterModelConfig {
// Explicit constructor to make chromium style happy.
NeuralStylusPalmDetectionFilterModelConfig();
NeuralStylusPalmDetectionFilterModelConfig(
const NeuralStylusPalmDetectionFilterModelConfig& other);
// Number of nearest neighbors to use in vector construction.
uint32_t nearest_neighbor_count = 0;
// Number of biggest nearby neighbors to use in vector construction.
uint32_t biggest_near_neighbor_count = 0;
// Maximum distance of neighbor centroid, in millimeters.
float max_neighbor_distance_in_mm = 0.0f;
base::TimeDelta max_dead_neighbor_time =
base::TimeDelta::FromMilliseconds(0.0);
// Minimum count of samples in a stroke for neural comparison.
uint32_t min_sample_count = 0;
// Maximum sample count.
uint32_t max_sample_count = 0;
uint32_t max_sequence_start_count_for_inference = 0;
bool include_sequence_count_in_strokes = false;
// If this number is positive, short strokes with a touch major greater than
// or equal to this should be marked as a palm. If 0 or less, has no effect.
float heuristic_palm_touch_limit = 0.0f;
// If this number is positive, short strokes with any touch having an area
// greater than or equal to this should be marked as a palm. If <= 0, has no
// effect
float heuristic_palm_area_limit = 0.0f;
};
// An abstract model utilized by NueralStylusPalmDetectionFilter.
class EVENTS_OZONE_EVDEV_EXPORT NeuralStylusPalmDetectionFilterModel {
public:
virtual ~NeuralStylusPalmDetectionFilterModel() {}
// Actually execute inference on floating point input. If the length of
// features is not correct, return Nan. The return value is assumed to be the
// input of a sigmoid. i.e. any value greater than 0 implies a positive
// result.
virtual float Inference(const std::vector<float>& features) const = 0;
virtual NeuralStylusPalmDetectionFilterModelConfig& config() const = 0;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_MODEL_H_
......@@ -116,6 +116,14 @@ void Stroke::SetTrackingId(int tracking_id) {
tracking_id_ = tracking_id;
}
float Stroke::MaxMajorRadius() const {
float maximum = 0.0;
for (const auto& sample : samples_) {
maximum = std::max(maximum, sample.major_radius);
}
return maximum;
}
float Stroke::BiggestSize() const {
float biggest = 0;
for (const auto& sample : samples_) {
......
......@@ -59,10 +59,13 @@ class EVENTS_OZONE_EVDEV_EXPORT Stroke {
void AddSample(const Sample& sample);
gfx::PointF GetCentroid() const;
float BiggestSize() const;
// If no elements in stroke, returns 0.0;
float MaxMajorRadius() const;
void SetTrackingId(int tracking_id);
const std::deque<Sample>& samples() const;
uint64_t samples_seen() const;
int tracking_id() const;
private:
std::deque<Sample> samples_;
int tracking_id_ = 0;
......
......@@ -176,4 +176,22 @@ TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeBiggestSizeTest) {
}
}
TEST_F(NeuralStylusPalmDetectionFilterUtilTest, StrokeGetMaxMajorTest) {
Stroke stroke(3);
EXPECT_FLOAT_EQ(0, stroke.MaxMajorRadius());
base::TimeTicks t =
base::TimeTicks::UnixEpoch() + base::TimeDelta::FromSeconds(30);
const DistilledDevInfo nocturne_distilled =
DistilledDevInfo::Create(nocturne_touchscreen_);
for (int i = 1; i < 50; ++i) {
touch_.major = i;
touch_.minor = i - 1;
Sample s(touch_, t, nocturne_distilled);
t += base::TimeDelta::FromMilliseconds(8);
EXPECT_EQ(static_cast<uint64_t>(i - 1), stroke.samples_seen());
stroke.AddSample(s);
EXPECT_FLOAT_EQ(i, stroke.MaxMajorRadius());
}
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment