Permalink
Browse files

Use interpolated windows and osx functions

  • Loading branch information...
Izzatbek committed Apr 1, 2016
1 parent 39db5e8 commit 10ac7531c373bcaccd58b1ea5916e00862b524e1
@@ -42,4 +42,5 @@ qrc_*.cpp

apps/consoleExample/consoleExample
apps/glutExample/glutExample
apps/qtExample/qtExample
apps/qtExample/qtExample
tests/interpolation/interpolation
@@ -6,7 +6,7 @@

TEMPLATE = subdirs

ALL_APPS = pointing apps
ALL_APPS = pointing apps tests
for(dir, ALL_APPS) {
exists($$dir) {
SUBDIRS += $$dir
@@ -189,8 +189,10 @@ namespace pointing {

double result = -1 ;
if (hiddev->theDevice) result = 1.0 / hidGetReportInterval(hiddev->theDevice->device) ;
if (result>0) return result ;
double estimated = estimatedUpdateFrequency();
if (result == 125. && estimated > 0.)
return estimated;
if (result>0) return result ;
if (estimated > 0.)
return estimated;
if (defval) return *defval ;
@@ -272,10 +272,9 @@ namespace pointing
URI uri;
uri.scheme = "interp";
uri.path = directory;
std::stringstream q ;
URI::addQueryArg(uri.query, "f", curAcc);
if (expanded || normalize)
q << "normalize=" << normalize;
uri.query = q.str() ;
URI::addQueryArg(uri.query, "normalize", normalize);
return uri;
}

@@ -35,6 +35,7 @@
#include <pointing/transferfunctions/Interpolation.h>

#include <pointing/transferfunctions/Composition.h>
#include <pointing/utils/FileUtils.h>

#ifdef __APPLE__
#include <pointing/transferfunctions/osx/osxSystemPointerAcceleration.h>
@@ -51,6 +52,10 @@
#define DEFAULT_INPUT_CPI 400.
#define DEFAULT_OUTPUT_PPI 96.

#define DEFAULT_OSX_SETTING 0.6875
#define DEFAULT_WINDOWS_SLIDER 0
#define DEFAULT_WINDOWS_EPP true

#include <stdexcept>
#include <iostream>
#include <sstream>
@@ -124,24 +129,21 @@ namespace pointing {

TransferFunction*
TransferFunction::create(URI &uri,
PointingDevice* input, DisplayDevice* output) {
// uri.debug(std::cerr) ;
PointingDevice* input, DisplayDevice* output) {

if (uri.scheme=="system") {
#ifdef __APPLE__
osxSystemPointerAcceleration sysAcc ;
double setting = sysAcc.get(uri.opaque.c_str()) ;
if (!uri.query.empty()) {
URI::getQueryArg(uri.query, "setting", &setting) ;
sysAcc.set(setting, uri.opaque.c_str()) ;
setting = sysAcc.get(uri.opaque.c_str()) ;
// std::cerr << "Setting: " << setting << std::endl ;
URI::getQueryArg(uri.query, "setting", &setting) ;
sysAcc.set(setting, uri.opaque.c_str()) ;
setting = sysAcc.get(uri.opaque.c_str()) ;
}
uri.scheme = "osx" ;
std::stringstream q ;
q << "setting=" << setting ;
uri.query = q.str() ;
// std::cerr << uri.asString() << std::endl ;
#endif

#ifdef __linux__
@@ -203,6 +205,31 @@ namespace pointing {
return new XorgFunction(uri, input, output) ;
#endif

// Replace with the corresponding interpolated tfs
if (uri.scheme == "osx" || uri.scheme == "windows")
{
std::string modulePath = moduleHeadersPath();
std::string subDir;
if (uri.scheme == "osx")
{
double setting = DEFAULT_OSX_SETTING;
URI::getQueryArg(uri.query, "setting", &setting);
URI::addQueryArg(uri.query, "f", setting);
subDir = "/pointing-echomouse/darwin-15";
}
else
{
int slider = DEFAULT_WINDOWS_SLIDER;
int epp = DEFAULT_WINDOWS_EPP;
URI::getQueryArg(uri.query, "slider", &slider);
URI::addQueryArg(uri.query, "f", slider);
URI::getQueryArg(uri.query, "epp", &epp);
subDir = "/pointing-echomouse/windows" + std::string(epp ? "/epp" : "/no-epp");
}
uri.path = modulePath + subDir;
uri.scheme = "interp";
}

if (uri.scheme=="interp")
return new Interpolation(uri, input, output) ;

@@ -67,7 +67,7 @@ namespace pointing {

/**
* @brief Static method to instantiate an object of a sub-class.
* @param function_uri URI caracterizing the type and details of an object
* @param function_uri URI defining the type and details of an object
* @param input Input device associated with this transfer function.
* @param output Output device associated with this transfer function
* @return Pointer to the initialized transfer function.
72 pointing/utils/FileUtils.cpp 100644 → 100755
@@ -26,6 +26,19 @@
#include <sys/stat.h>
#include <fcntl.h>

#if defined(__APPLE__) || defined(__linux__)
#include <dlfcn.h>
#define SLASH '/'
#endif

#ifdef _WIN32
#include <windows.h>
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define SLASH '\\'
#endif

#define PATH_LENGTH 256

namespace pointing {

bool
@@ -75,4 +88,63 @@ namespace pointing {
#endif
}

bool pointingDirExists(const char *path)
{
const char pointingDir[] = "/pointing";
char tmp[PATH_LENGTH];
sprintf(tmp, "%s%s", path, pointingDir);
struct stat sb;
return stat(tmp, &sb) == 0 && S_ISDIR(sb.st_mode);
}

bool getModulePath(char *path)
{
#ifdef _WIN32
HMODULE hm = NULL;

if (!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
(LPCSTR) &moduleHeadersPath,
&hm))
{
int ret = GetLastError();
fprintf(stderr, "GetModuleHandle returned %d\n", ret);
return false;
}
GetModuleFileNameA(hm, path, PATH_LENGTH);
return true;
#else
Dl_info info;
if (dladdr((void *)moduleHeadersPath, &info))
{
strcpy(path, info.dli_fname);
return true;
}
return false;
#endif
}

std::string moduleHeadersPath()
{
char path[PATH_LENGTH];
if (getModulePath(path))
{
for (int i = 0; i < 5; i++) // Check 5 levels max
{
char *lastSlash = strrchr(path, SLASH);
if (!lastSlash)
break;

sprintf(lastSlash, "%s", "/include");
if (pointingDirExists(path))
return std::string(path);

// Cut the path (go to path/..)
*lastSlash = 0;
if (pointingDirExists(path))
return std::string(path);
}
}
return "";
}
}
@@ -17,6 +17,7 @@
#define FileUtils_h

#include <stdint.h>
#include <string>

namespace pointing {

@@ -26,6 +27,7 @@ namespace pointing {

void readFromFile(const char *filename, char *data, unsigned int size) ;

std::string moduleHeadersPath();
}

#endif
@@ -0,0 +1,138 @@
#ifndef INTERPOLATION_TEST_H
#define INTERPOLATION_TEST_H

#include <QObject>
#include <QtTest/QtTest>
#include <pointing/transferfunctions/Interpolation.h>
#include <pointing/utils/FileUtils.h>

using namespace pointing;
using namespace std;

class InterpolationTest : public QObject
{
Q_OBJECT
Interpolation *func;

private slots:

// At the beginning
void initTestCase()
{
URI uri("interp:");
func = new Interpolation(uri, 0, 0);
}

// Each time a function is called
void init()
{

}

void ZeroPoints()
{
int dxP, dyP;
func->clearState();
func->applyi(0, 0, &dxP, &dyP);
QCOMPARE(dxP, 0);
QCOMPARE(dyP, 0);
}

void OutOfBoundPoints()
{
func->loadTableStr("max-counts: 1\n"
"0: 0\n"
"1: 0.2\n");
int dxP, dyP;
func->applyi(6, 0, &dxP, &dyP);
QCOMPARE(dxP, 1);
func->applyi(4, 0, &dxP, &dyP);
QCOMPARE(dxP, 1);
func->applyi(100, 0, &dxP, &dyP);
QCOMPARE(dxP, 20);
}

void InterpolateBetween2()
{
func->loadTableStr("max-counts: 3\n"
"0: 0\n"
"1: 2\n"
"3: 6\n");
int dxP, dyP;
func->applyi(2, 0, &dxP, &dyP);
QCOMPARE(dxP, 4);
}

void InterpolateFromFar()
{
func->loadTableStr("max-counts: 11\n"
"0: 0\n"
"1: 1\n"
"5: 10\n"
"11: 22\n");
int dxP, dyP;
func->applyi(2, 0, &dxP, &dyP);
QCOMPARE(dxP, 3);
func->clearState();
func->applyi(9, 0, &dxP, &dyP);
QCOMPARE(dxP, 18);
}

void NegativeValues()
{
func->loadTableStr("max-counts: 1\n"
"0: 0\n"
"1: 0.2\n");
int dxP, dyP;
// This should give 0.2 which is floored to 0 not to 1
func->applyi(-1, 0, &dxP, &dyP);
QCOMPARE(dxP, 0);
}

void replacedOSXURI()
{
TransferFunction *f = TransferFunction::create("osx:?setting=1.5", 0, 0);
URI uri = f->getURI();
QCOMPARE(uri.scheme, std::string("interp"));
double setting = 0.;
URI::getQueryArg(uri.query, "f", &setting);
QCOMPARE(setting, 1.5);
delete f;
}

void replacedWindowsURI()
{
TransferFunction *f = TransferFunction::create("windows:", 0, 0);
URI uri = f->getURI();
QCOMPARE(uri.scheme, std::string("interp"));
int slider = -1;
URI::getQueryArg(uri.query, "f", &slider);
QCOMPARE(slider, 0);
std::string modulePath = moduleHeadersPath();
QCOMPARE(uri.path, modulePath + "/pointing-echomouse/windows/epp");
delete f;
}

void replacedWindowsWithArgsURI()
{
TransferFunction *f = TransferFunction::create("windows:?epp=false&slider=3", 0, 0);
URI uri = f->getURI();
QCOMPARE(uri.scheme, std::string("interp"));
int slider = -1;
URI::getQueryArg(uri.query, "f", &slider);
QCOMPARE(slider, 3);
std::string modulePath = moduleHeadersPath();
QCOMPARE(uri.path, modulePath + "/pointing-echomouse/windows/no-epp");
delete f;
}

// At the end
void cleanupTestCase()
{
delete func;
}
};

#endif // INTERPOLATION_TEST_H

QTEST_MAIN(InterpolationTest)
@@ -0,0 +1,18 @@
# test/basic/interpolation/interpolation.pro --
#
# Initial software
# Authors: Izzat Mukhanov
# Copyright © INRIA

TEMPLATE = app
CONFIG += warn_on link_prl
CONFIG -= app_bundle

QT += testlib

TARGET = interpolation

POINTING = ../..
include($$POINTING/pointing/pointing.pri)

HEADERS += interpolation.h
@@ -0,0 +1,9 @@
# tests/tests.pro --
#
# Initial software
# Authors: Izzatbek Mukhanov
# Copyright © Inria

TEMPLATE = subdirs

SUBDIRS += interpolation

0 comments on commit 10ac753

Please sign in to comment.