Merge "Fix touch coordinate calibration"

main
Satoshi Kataoka 2013-04-09 08:53:24 +00:00 committed by Android (Google) Code Review
commit f31553bc09
10 changed files with 51 additions and 32 deletions

View File

@ -129,7 +129,7 @@ bool ProximityInfo::hasSpaceProximity(const int x, const int y) const {
} }
float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG( float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG(
const int keyId, const int x, const int y) const { const int keyId, const int x, const int y, const float verticalScale) const {
const bool correctTouchPosition = hasTouchPositionCorrectionData(); const bool correctTouchPosition = hasTouchPositionCorrectionData();
const float centerX = static_cast<float>(correctTouchPosition ? getSweetSpotCenterXAt(keyId) const float centerX = static_cast<float>(correctTouchPosition ? getSweetSpotCenterXAt(keyId)
: getKeyCenterXOfKeyIdG(keyId)); : getKeyCenterXOfKeyIdG(keyId));
@ -138,7 +138,7 @@ float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloatG(
if (correctTouchPosition) { if (correctTouchPosition) {
const float sweetSpotCenterY = static_cast<float>(getSweetSpotCenterYAt(keyId)); const float sweetSpotCenterY = static_cast<float>(getSweetSpotCenterYAt(keyId));
const float gapY = sweetSpotCenterY - visualKeyCenterY; const float gapY = sweetSpotCenterY - visualKeyCenterY;
centerY = visualKeyCenterY + gapY * ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE_G; centerY = visualKeyCenterY + gapY * verticalScale;
} else { } else {
centerY = visualKeyCenterY; centerY = visualKeyCenterY;
} }

View File

@ -39,7 +39,8 @@ class ProximityInfo {
bool hasSpaceProximity(const int x, const int y) const; bool hasSpaceProximity(const int x, const int y) const;
int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const; int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const;
float getNormalizedSquaredDistanceFromCenterFloatG( float getNormalizedSquaredDistanceFromCenterFloatG(
const int keyId, const int x, const int y) const; const int keyId, const int x, const int y,
const float verticalScale) const;
bool sameAsTyped(const unsigned short *word, int length) const; bool sameAsTyped(const unsigned short *word, int length) const;
int getCodePointOf(const int keyIndex) const; int getCodePointOf(const int keyIndex) const;
bool hasSweetSpotData(const int keyIndex) const { bool hasSweetSpotData(const int keyIndex) const {

View File

@ -20,7 +20,8 @@
namespace latinime { namespace latinime {
const float ProximityInfoParams::NOT_A_DISTANCE_FLOAT = -1.0f; const float ProximityInfoParams::NOT_A_DISTANCE_FLOAT = -1.0f;
const int ProximityInfoParams::MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE = 5; const int ProximityInfoParams::MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE = 5;
const float ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE_G = 1.1f; const float ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE = 1.0f;
const float ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE_G = 0.5f;
/* Per method constants */ /* Per method constants */
// Used by ProximityInfoStateUtils::initGeometricDistanceInfos() // Used by ProximityInfoStateUtils::initGeometricDistanceInfos()

View File

@ -25,6 +25,7 @@ class ProximityInfoParams {
public: public:
static const float NOT_A_DISTANCE_FLOAT; static const float NOT_A_DISTANCE_FLOAT;
static const int MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE; static const int MIN_DOUBLE_LETTER_BEELINE_SPEED_PERCENTILE;
static const float VERTICAL_SWEET_SPOT_SCALE;
static const float VERTICAL_SWEET_SPOT_SCALE_G; static const float VERTICAL_SWEET_SPOT_SCALE_G;
// Used by ProximityInfoStateUtils::initGeometricDistanceInfos() // Used by ProximityInfoStateUtils::initGeometricDistanceInfos()

View File

@ -28,6 +28,7 @@
namespace latinime { namespace latinime {
// TODO: Remove the dependency of "isGeometric"
void ProximityInfoState::initInputParams(const int pointerId, const float maxPointToKeyLength, void ProximityInfoState::initInputParams(const int pointerId, const float maxPointToKeyLength,
const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize, const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize,
const int *const xCoordinates, const int *const yCoordinates, const int *const times, const int *const xCoordinates, const int *const yCoordinates, const int *const times,
@ -94,12 +95,17 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
pushTouchPointStartIndex, lastSavedInputSize); pushTouchPointStartIndex, lastSavedInputSize);
} }
// TODO: Remove the dependency of "isGeometric"
const float verticalSweetSpotScale = isGeometric
? ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE_G
: ProximityInfoParams::VERTICAL_SWEET_SPOT_SCALE;
if (xCoordinates && yCoordinates) { if (xCoordinates && yCoordinates) {
mSampledInputSize = ProximityInfoStateUtils::updateTouchPoints(mProximityInfo, mSampledInputSize = ProximityInfoStateUtils::updateTouchPoints(mProximityInfo,
mMaxPointToKeyLength, mInputProximities, xCoordinates, yCoordinates, times, mMaxPointToKeyLength, mInputProximities, xCoordinates, yCoordinates, times,
pointerIds, inputSize, isGeometric, pointerId, pushTouchPointStartIndex, pointerIds, verticalSweetSpotScale, inputSize, isGeometric, pointerId,
&mSampledInputXs, &mSampledInputYs, &mSampledTimes, &mSampledLengthCache, pushTouchPointStartIndex, &mSampledInputXs, &mSampledInputYs, &mSampledTimes,
&mSampledInputIndice); &mSampledLengthCache, &mSampledInputIndice);
} }
if (mSampledInputSize > 0 && isGeometric) { if (mSampledInputSize > 0 && isGeometric) {
@ -115,8 +121,8 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
if (mSampledInputSize > 0) { if (mSampledInputSize > 0) {
ProximityInfoStateUtils::initGeometricDistanceInfos(mProximityInfo, mSampledInputSize, ProximityInfoStateUtils::initGeometricDistanceInfos(mProximityInfo, mSampledInputSize,
lastSavedInputSize, &mSampledInputXs, &mSampledInputYs, &mSampledNearKeySets, lastSavedInputSize, verticalSweetSpotScale, &mSampledInputXs, &mSampledInputYs,
&mSampledDistanceCache_G); &mSampledNearKeySets, &mSampledDistanceCache_G);
if (isGeometric) { if (isGeometric) {
// updates probabilities of skipping or mapping each key for all points. // updates probabilities of skipping or mapping each key for all points.
ProximityInfoStateUtils::updateAlignPointProbabilities( ProximityInfoStateUtils::updateAlignPointProbabilities(

View File

@ -42,8 +42,8 @@ namespace latinime {
const ProximityInfo *const proximityInfo, const int maxPointToKeyLength, const ProximityInfo *const proximityInfo, const int maxPointToKeyLength,
const int *const inputProximities, const int *const inputXCoordinates, const int *const inputProximities, const int *const inputXCoordinates,
const int *const inputYCoordinates, const int *const times, const int *const pointerIds, const int *const inputYCoordinates, const int *const times, const int *const pointerIds,
const int inputSize, const bool isGeometric, const int pointerId, const float verticalSweetSpotScale, const int inputSize, const bool isGeometric,
const int pushTouchPointStartIndex, std::vector<int> *sampledInputXs, const int pointerId, const int pushTouchPointStartIndex, std::vector<int> *sampledInputXs,
std::vector<int> *sampledInputYs, std::vector<int> *sampledInputTimes, std::vector<int> *sampledInputYs, std::vector<int> *sampledInputTimes,
std::vector<int> *sampledLengthCache, std::vector<int> *sampledInputIndice) { std::vector<int> *sampledLengthCache, std::vector<int> *sampledInputIndice) {
if (DEBUG_SAMPLING_POINTS) { if (DEBUG_SAMPLING_POINTS) {
@ -112,10 +112,10 @@ namespace latinime {
} }
if (pushTouchPoint(proximityInfo, maxPointToKeyLength, i, c, x, y, time, if (pushTouchPoint(proximityInfo, maxPointToKeyLength, i, c, x, y, time,
isGeometric /* doSampling */, i == lastInputIndex, sumAngle, verticalSweetSpotScale, isGeometric /* doSampling */, i == lastInputIndex,
currentNearKeysDistances, prevNearKeysDistances, prevPrevNearKeysDistances, sumAngle, currentNearKeysDistances, prevNearKeysDistances,
sampledInputXs, sampledInputYs, sampledInputTimes, sampledLengthCache, prevPrevNearKeysDistances, sampledInputXs, sampledInputYs, sampledInputTimes,
sampledInputIndice)) { sampledLengthCache, sampledInputIndice)) {
// Previous point information was popped. // Previous point information was popped.
NearKeysDistanceMap *tmp = prevNearKeysDistances; NearKeysDistanceMap *tmp = prevNearKeysDistances;
prevNearKeysDistances = currentNearKeysDistances; prevNearKeysDistances = currentNearKeysDistances;
@ -222,7 +222,8 @@ namespace latinime {
/* static */ void ProximityInfoStateUtils::initGeometricDistanceInfos( /* static */ void ProximityInfoStateUtils::initGeometricDistanceInfos(
const ProximityInfo *const proximityInfo, const int sampledInputSize, const ProximityInfo *const proximityInfo, const int sampledInputSize,
const int lastSavedInputSize, const std::vector<int> *const sampledInputXs, const int lastSavedInputSize, const float verticalSweetSpotScale,
const std::vector<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs, const std::vector<int> *const sampledInputYs,
std::vector<NearKeycodesSet> *SampledNearKeySets, std::vector<NearKeycodesSet> *SampledNearKeySets,
std::vector<float> *SampledDistanceCache_G) { std::vector<float> *SampledDistanceCache_G) {
@ -236,7 +237,8 @@ namespace latinime {
const int x = (*sampledInputXs)[i]; const int x = (*sampledInputXs)[i];
const int y = (*sampledInputYs)[i]; const int y = (*sampledInputYs)[i];
const float normalizedSquaredDistance = const float normalizedSquaredDistance =
proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y); proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(
k, x, y, verticalSweetSpotScale);
(*SampledDistanceCache_G)[index] = normalizedSquaredDistance; (*SampledDistanceCache_G)[index] = normalizedSquaredDistance;
if (normalizedSquaredDistance if (normalizedSquaredDistance
< ProximityInfoParams::NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) { < ProximityInfoParams::NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) {
@ -354,12 +356,14 @@ namespace latinime {
// the given point and the nearest key position. // the given point and the nearest key position.
/* static */ float ProximityInfoStateUtils::updateNearKeysDistances( /* static */ float ProximityInfoStateUtils::updateNearKeysDistances(
const ProximityInfo *const proximityInfo, const float maxPointToKeyLength, const int x, const ProximityInfo *const proximityInfo, const float maxPointToKeyLength, const int x,
const int y, NearKeysDistanceMap *const currentNearKeysDistances) { const int y, const float verticalSweetspotScale,
NearKeysDistanceMap *const currentNearKeysDistances) {
currentNearKeysDistances->clear(); currentNearKeysDistances->clear();
const int keyCount = proximityInfo->getKeyCount(); const int keyCount = proximityInfo->getKeyCount();
float nearestKeyDistance = maxPointToKeyLength; float nearestKeyDistance = maxPointToKeyLength;
for (int k = 0; k < keyCount; ++k) { for (int k = 0; k < keyCount; ++k) {
const float dist = proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y); const float dist = proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(k, x, y,
verticalSweetspotScale);
if (dist < ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_DISTANCE) { if (dist < ProximityInfoParams::NEAR_KEY_THRESHOLD_FOR_DISTANCE) {
currentNearKeysDistances->insert(std::pair<int, float>(k, dist)); currentNearKeysDistances->insert(std::pair<int, float>(k, dist));
} }
@ -439,7 +443,8 @@ namespace latinime {
// Returning if previous point is popped or not. // Returning if previous point is popped or not.
/* static */ bool ProximityInfoStateUtils::pushTouchPoint(const ProximityInfo *const proximityInfo, /* static */ bool ProximityInfoStateUtils::pushTouchPoint(const ProximityInfo *const proximityInfo,
const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x, int y, const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x, int y,
const int time, const bool doSampling, const bool isLastPoint, const float sumAngle, const int time, const float verticalSweetSpotScale, const bool doSampling,
const bool isLastPoint, const float sumAngle,
NearKeysDistanceMap *const currentNearKeysDistances, NearKeysDistanceMap *const currentNearKeysDistances,
const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances,
@ -451,8 +456,8 @@ namespace latinime {
size_t size = sampledInputXs->size(); size_t size = sampledInputXs->size();
bool popped = false; bool popped = false;
if (nodeCodePoint < 0 && doSampling) { if (nodeCodePoint < 0 && doSampling) {
const float nearest = updateNearKeysDistances( const float nearest = updateNearKeysDistances(proximityInfo, maxPointToKeyLength, x, y,
proximityInfo, maxPointToKeyLength, x, y, currentNearKeysDistances); verticalSweetSpotScale, currentNearKeysDistances);
const float score = getPointScore(mostCommonKeyWidth, x, y, time, isLastPoint, nearest, const float score = getPointScore(mostCommonKeyWidth, x, y, time, isLastPoint, nearest,
sumAngle, currentNearKeysDistances, prevNearKeysDistances, sumAngle, currentNearKeysDistances, prevNearKeysDistances,
prevPrevNearKeysDistances, sampledInputXs, sampledInputYs); prevPrevNearKeysDistances, sampledInputXs, sampledInputYs);

View File

@ -38,7 +38,8 @@ class ProximityInfoStateUtils {
static int updateTouchPoints(const ProximityInfo *const proximityInfo, static int updateTouchPoints(const ProximityInfo *const proximityInfo,
const int maxPointToKeyLength, const int *const inputProximities, const int maxPointToKeyLength, const int *const inputProximities,
const int *const inputXCoordinates, const int *const inputYCoordinates, const int *const inputXCoordinates, const int *const inputYCoordinates,
const int *const times, const int *const pointerIds, const int inputSize, const int *const times, const int *const pointerIds,
const float verticalSweetSpotScale, const int inputSize,
const bool isGeometric, const int pointerId, const int pushTouchPointStartIndex, const bool isGeometric, const int pointerId, const int pushTouchPointStartIndex,
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs, std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs,
std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache, std::vector<int> *sampledInputTimes, std::vector<int> *sampledLengthCache,
@ -84,6 +85,7 @@ class ProximityInfoStateUtils {
const int inputIndex, const int keyId); const int inputIndex, const int keyId);
static void initGeometricDistanceInfos(const ProximityInfo *const proximityInfo, static void initGeometricDistanceInfos(const ProximityInfo *const proximityInfo,
const int sampledInputSize, const int lastSavedInputSize, const int sampledInputSize, const int lastSavedInputSize,
const float verticalSweetSpotScale,
const std::vector<int> *const sampledInputXs, const std::vector<int> *const sampledInputXs,
const std::vector<int> *const sampledInputYs, const std::vector<int> *const sampledInputYs,
std::vector<NearKeycodesSet> *SampledNearKeySets, std::vector<NearKeycodesSet> *SampledNearKeySets,
@ -118,6 +120,7 @@ class ProximityInfoStateUtils {
static float updateNearKeysDistances(const ProximityInfo *const proximityInfo, static float updateNearKeysDistances(const ProximityInfo *const proximityInfo,
const float maxPointToKeyLength, const int x, const int y, const float maxPointToKeyLength, const int x, const int y,
const float verticalSweetSpotScale,
NearKeysDistanceMap *const currentNearKeysDistances); NearKeysDistanceMap *const currentNearKeysDistances);
static bool isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances, static bool isPrevLocalMin(const NearKeysDistanceMap *const currentNearKeysDistances,
const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances,
@ -130,7 +133,8 @@ class ProximityInfoStateUtils {
std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs); std::vector<int> *sampledInputXs, std::vector<int> *sampledInputYs);
static bool pushTouchPoint(const ProximityInfo *const proximityInfo, static bool pushTouchPoint(const ProximityInfo *const proximityInfo,
const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x, const int maxPointToKeyLength, const int inputIndex, const int nodeCodePoint, int x,
int y, const int time, const bool doSampling, const bool isLastPoint, int y, const int time, const float verticalSweetSpotScale,
const bool doSampling, const bool isLastPoint,
const float sumAngle, NearKeysDistanceMap *const currentNearKeysDistances, const float sumAngle, NearKeysDistanceMap *const currentNearKeysDistances,
const NearKeysDistanceMap *const prevNearKeysDistances, const NearKeysDistanceMap *const prevNearKeysDistances,
const NearKeysDistanceMap *const prevPrevNearKeysDistances, const NearKeysDistanceMap *const prevPrevNearKeysDistances,

View File

@ -48,13 +48,6 @@
namespace latinime { namespace latinime {
// Naming convention
// - Distance: "Weighted" edit distance -- used both for spatial and language.
// - Compound Distance: Spatial Distance + Language Distance -- used for pruning and scoring
// - Cost: delta/diff for Distance -- used both for spatial and language
// - Length: "Non-weighted" -- used only for spatial
// - Probability: "Non-weighted" -- used only for language
// This struct is purely a bucket to return values. No instances of this struct should be kept. // This struct is purely a bucket to return values. No instances of this struct should be kept.
struct DicNode_InputStateG { struct DicNode_InputStateG {
bool mNeedsToUpdateInputStateG; bool mNeedsToUpdateInputStateG;

View File

@ -426,7 +426,6 @@ void Suggest::processDicNodeAsOmission(
weightChildNode(traverseSession, childDicNode); weightChildNode(traverseSession, childDicNode);
if (!TRAVERSAL->isPossibleOmissionChildNode(traverseSession, dicNode, childDicNode)) { if (!TRAVERSAL->isPossibleOmissionChildNode(traverseSession, dicNode, childDicNode)) {
DicNode::managedDelete(childDicNode);
continue; continue;
} }
processExpandedDicNode(traverseSession, childDicNode); processExpandedDicNode(traverseSession, childDicNode);

View File

@ -23,6 +23,15 @@
namespace latinime { namespace latinime {
// Naming convention
// - Distance: "Weighted" edit distance -- used both for spatial and language.
// - Compound Distance: Spatial Distance + Language Distance -- used for pruning and scoring
// - Cost: delta/diff for Distance -- used both for spatial and language
// - Length: "Non-weighted" -- used only for spatial
// - Probability: "Non-weighted" -- used only for language
// - Score: Final calibrated score based on the compound distance, which is sent to java as the
// priority of a suggested word
class DicNode; class DicNode;
class DicTraverseSession; class DicTraverseSession;
class ProximityInfo; class ProximityInfo;