diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-21 20:44:33 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-21 20:52:20 +0200 |
commit | a815d8dfe1b452e0cab9b588a9d4ec4650a5bdda (patch) | |
tree | 12dbf31a6dde154f6fa8bee0669584c217c3fad6 | |
parent | 757252abb8043909dcd8f1e9dc8c51016f01ee63 (diff) | |
parent | fe3bc42f80bb8cef37dea68539e8a1fd9752baa8 (diff) |
Merge branch 'unstable' into trackhattrackhat-1.1p2
* unstable:
cmake: update toolchain file
shortcuts: fix osx/linux keystrokes persisting
cmake: fix copy-paste comment
cmake: add toolchain file for OSX
cmake: add osx policy to make it shutup
x-plane: ignore diagnostic
osx: nix warning
gitattributes: more text extensions to eol=lf
cmake: timestamp logic simplify/fix
cmake: no timestamp for tag builds
all: update copyright where appropriate
all: comments only
cmake: regen before making tarball
cmake: fix dropbox share invocation
tracker: initialize newpose
pt: use previous pose on NaN result from POSIT
accela: also don't poison ewma state with nans
cmake: fix tarball invocation
accela: elide NaN output values
qfc: elide NaN values
pt: reformat more
pt: reformat posit
pt: refactor auto threshold somewhat
pt: rename ill-chosen name
pt: switch min/max point size to reals
cmake: upload tarball to Dropbox but only if I'm the user
cmake: add tarball timestamp so it gets rebuilt
cmake: don't regen version if none changed
cmake: fix git describe --dirty
cmake: retab git module
fix tarball target
cmake: mark dirty tree
cmake: regen tarball even if exists
cmake: generate version.cc
tracker: check for NaN values
accela: don't check NaNs in filter, wrong place
cmake: drop -ffast-math, allow for NaN check
shortcuts: actually print screen binding works
shortcuts: alias right modifier keys to left modifier keys
shortcuts: allow for binding scroll lock and pause/break
accela: also filter out NaNs on tracking start
allow for filter immediate center
36 files changed, 610 insertions, 402 deletions
diff --git a/.gitattributes b/.gitattributes index 5f7a58f5..d681ede5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,5 @@ *.txt text=auto eol=lf *.ui text=auto eol=lf *.qrc text=auto eol=lf +*.cc text=auto eol=lf +*.md text=auto eol=lf diff --git a/CMakeLists.txt b/CMakeLists.txt index b48ac0cf..a7c64144 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ endif() if(POLICY CMP0028) cmake_policy(SET CMP0028 OLD) endif() +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) +endif() include(CMakeParseArguments) @@ -14,10 +17,36 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/) include(GetGitRevisionDescription) find_package(Git QUIET) if(GIT_FOUND) - git_describe(OPENTRACK__COMMIT --tags --always) + git_describe(OPENTRACK_COMMIT --tags --always --dirty) + git_describe(OPENTRACK_TAG_EXACT --tag --exact) +endif() + +file(WRITE ${CMAKE_BINARY_DIR}/opentrack-version.h "#define OPENTRACK_VERSION \"${OPENTRACK_COMMIT}\"") + +## start crapola + +set(version-string " +#include \"opentrack-compat/export.hpp\" + +#ifdef __cplusplus +extern \"C\" +#endif +OPENTRACK_EXPORT +const char* opentrack_version; + +const char* opentrack_version = \"${OPENTRACK_COMMIT}\"; +") + +set(crapola-ver) +if(EXISTS ${CMAKE_BINARY_DIR}/version.cc) + file(READ ${CMAKE_BINARY_DIR}/version.cc crapola-ver) endif() -file(WRITE ${CMAKE_BINARY_DIR}/opentrack-version.h "#define OPENTRACK_VERSION \"${OPENTRACK__COMMIT}\"") +if(NOT (crapola-ver STREQUAL version-string)) + file(WRITE ${CMAKE_BINARY_DIR}/version.cc "${version-string}") +endif() + +## end crapola SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) @@ -177,11 +206,7 @@ if(NOT WIN32) set(SDK_WINE_NO_WRAPPER FALSE CACHE BOOL "disable Wine wrapper -- use Wine only for X-Plane") endif() -# ---- - -# misc - -# ---- +# --- tarball string(TIMESTAMP filename-date "%Y%m%d") set(filename-ostype ${CMAKE_SYSTEM_NAME}) @@ -191,12 +216,23 @@ if(filename-hash_0) endif() string(REPLACE "refs/heads/" "" filename-branch_1 "${filename-branch_0}") string(REPLACE "/" "-" filename-branch "${filename-branch_1}") -set(filename_0 "${OPENTRACK__COMMIT}") -set(filename "${CMAKE_BINARY_DIR}/${filename_0}.zip") +set(filename_0 "${OPENTRACK_COMMIT}") +set(filename_1) +if (NOT OPENTRACK_TAG_EXACT STREQUAL OPENTRACK_COMMIT) + string(TIMESTAMP filename_1 "-%Y%m%d%H%M%S") +endif() +set(filename "${CMAKE_BINARY_DIR}/${filename_0}${filename_1}.zip") + +add_custom_target(tarball-real) +add_custom_target(tarball-real2) +add_custom_command(TARGET tarball-real COMMAND cmake -P ${CMAKE_SOURCE_DIR}/cmake/tarball.cmake) -add_custom_command(OUTPUT ${filename} COMMAND env sh "${CMAKE_SOURCE_DIR}/make-tar.sh" "${CMAKE_INSTALL_PREFIX}" "${filename}") -add_custom_target(tarball DEPENDS ${filename}) +add_custom_command(TARGET tarball-real2 COMMAND /usr/bin/env sh + "${CMAKE_SOURCE_DIR}/make-tar.sh" "${CMAKE_INSTALL_PREFIX}" + "${filename}" "${CMAKE_BINARY_DIR}") +add_custom_target(tarball DEPENDS tarball-real) +# -- end tarball opentrack_module(opentrack-api opentrack) opentrack_qt(opentrack-api) @@ -278,11 +314,8 @@ opentrack_compat(opentrack-spline-widget) target_include_directories(opentrack-spline-widget PUBLIC qfunctionconfigurator/) target_link_libraries(opentrack-spline-widget ${MY_QT_LIBS}) -add_library(opentrack-version STATIC opentrack/version.cc) +add_library(opentrack-version STATIC ${CMAKE_BINARY_DIR}/version.cc) opentrack_compat(opentrack-version) -set_target_properties(opentrack-version PROPERTIES - COMPILE_DEFINITIONS - "OPENTRACK_VERSION=\"${OPENTRACK__COMMIT}\"") opentrack_library(opentrack-filter-accela ftnoir_filter_accela STATIC TRUE) target_link_libraries(opentrack-filter-accela opentrack-spline-widget) @@ -463,6 +496,6 @@ if(APPLE) \"${CMAKE_SOURCE_DIR}/macosx\" \"${CMAKE_INSTALL_PREFIX}\" \"${CMAKE_BINARY_DIR}\" - \"${OPENTRACK__COMMIT}\") + \"${OPENTRACK_COMMIT}\") ") endif() diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index e16d8c37..e4ac79c0 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -31,7 +31,7 @@ # http://www.boost.org/LICENSE_1_0.txt) if(__get_git_revision_description) - return() + return() endif() set(__get_git_revision_description YES) @@ -40,84 +40,83 @@ set(__get_git_revision_description YES) get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories - set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") - get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) - if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) - # We have reached the root directory, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - endwhile() - set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") - if(NOT EXISTS "${GIT_DATA}") - file(MAKE_DIRECTORY "${GIT_DATA}") - endif() + set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() - if(NOT EXISTS "${GIT_DIR}/HEAD") - return() - endif() - set(HEAD_FILE "${GIT_DATA}/HEAD") - configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) - configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" - "${GIT_DATA}/grabRef.cmake" - @ONLY) - include("${GIT_DATA}/grabRef.cmake") + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") - set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) - set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) endfunction() function(git_describe _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - get_git_head_revision(refspec hash) - if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) - return() - endif() - if(NOT hash) - set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) - return() - endif() + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + #get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + #if(NOT hash) + # set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + # return() + #endif() - # TODO sanitize - #if((${ARGN}" MATCHES "&&") OR - # (ARGN MATCHES "||") OR - # (ARGN MATCHES "\\;")) - # message("Please report the following error to the project!") - # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") - #endif() + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() - #message(STATUS "Arguments to execute_process: ${ARGN}") + #message(STATUS "Arguments to execute_process: ${ARGN}") - execute_process(COMMAND - "${GIT_EXECUTABLE}" - describe - ${hash} - ${ARGN} - WORKING_DIRECTORY - "${CMAKE_SOURCE_DIR}" - RESULT_VARIABLE - res - OUTPUT_VARIABLE - out - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT res EQUAL 0) - set(out "${out}-${res}-NOTFOUND") - endif() + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() - set(${_var} "${out}" PARENT_SCOPE) + set(${_var} "${out}" PARENT_SCOPE) endfunction() function(git_get_exact_tag _var) - git_describe(out ${ARGN}) - set(${_var} "${out}" PARENT_SCOPE) + git_describe(out ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) endfunction() diff --git a/cmake/apple.cmake b/cmake/apple.cmake new file mode 100644 index 00000000..054e1ae5 --- /dev/null +++ b/cmake/apple.cmake @@ -0,0 +1,24 @@ +SET(CMAKE_SYSTEM_NAME Darwin) +SET(CMAKE_SYSTEM_VERSION 1) + +SET(CMAKE_C_COMPILER ${c}cc) +SET(CMAKE_CXX_COMPILER ${c}c++) +set(CMAKE_LINKER ${c}c++) + +set(CMAKE_OSX_ARCHITECTURES x86_64) +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.8) +# change this +set(CMAKE_OSX_SYSROOT /var/root/MacOSX10.8.sdk) + +set(fpu "-fno-math-errno -funsafe-math-optimizations -fno-signed-zeros") +set(cpu "-O3 -DNDEBUG -flto ${fpu}") +set(cxx "-std=c++11 -stdlib=libc++") + +set(CFLAGS-OVERRIDE "" CACHE STRING "") + +set(CMAKE_C_FLAGS_RELEASE "${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${cxx}" CACHE STRING "" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) +set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) +set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) +set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "" FORCE) diff --git a/cmake/mingw-w64-debug.cmake b/cmake/mingw-w64-debug.cmake deleted file mode 100644 index 7a371e5d..00000000 --- a/cmake/mingw-w64-debug.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# this file only serves as toolchain file when specified so explicitly -# when building the software. from repository's root directory: -# mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=$(pwd)/../cmake/mingw-w64.cmake -# -sh 20140922 - -SET(CMAKE_SYSTEM_NAME Windows) -SET(CMAKE_SYSTEM_VERSION 1) - -# specify the cross compiler -set(c i686-w64-mingw32-) - -SET(CMAKE_C_COMPILER ${c}gcc) -SET(CMAKE_CXX_COMPILER ${c}g++) -set(CMAKE_RC_COMPILER ${c}windres) -set(CMAKE_LINKER ${c}ld) -set(CMAKE_AR ${c}gcc-ar CACHE STRING "" FORCE) -set(CMAKE_NM ${c}gcc-nm CACHE STRING "" FORCE) -set(CMAKE_RANLIB ${c}gcc-ranlib CACHE STRING "" FORCE) - -SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) - -# search for programs in the host directories -SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -# don't poison with system compile-time data -SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -set(cpu "-O2 -march=i686 -mtune=corei7-avx -ffast-math -mfpmath=both -msse -msse2 -mno-sse3 -mno-avx") -set(rice "-ggdb") - -set(CFLAGS-OVERRIDE "" CACHE STRING "") - -set(CMAKE_C_FLAGS_RELEASE "${rice} ${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) -set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} CACHE STRING "" FORCE) -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${cpu} ${CFLAGS-OVERRIDE}" CACHE STRING "" FORCE) -set(CMAKE_EXE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) -set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} CACHE STRING "" FORCE) -set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "" FORCE) diff --git a/cmake/mingw-w64.cmake b/cmake/mingw-w64.cmake index f8ee1d41..1f60993a 100644 --- a/cmake/mingw-w64.cmake +++ b/cmake/mingw-w64.cmake @@ -26,7 +26,8 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # oldest CPU supported here is Northwood-based Pentium 4. -sh 20150811 -set(cpu "-O3 -march=pentium4 -mtune=corei7-avx -ffast-math -mfpmath=both -msse -msse2 -mno-sse3") +set(fpu "-ffast-math -fno-finite-math-only -mfpmath=both") +set(cpu "-O3 -march=pentium4 -mtune=corei7-avx ${fpu} -msse -msse2 -mno-sse3") set(CFLAGS-OVERRIDE "" CACHE STRING "") diff --git a/cmake/tarball.cmake b/cmake/tarball.cmake new file mode 100644 index 00000000..5761e24a --- /dev/null +++ b/cmake/tarball.cmake @@ -0,0 +1,8 @@ +execute_process(COMMAND cmake ${CMAKE_BINARY_DIR} RESULT_VARIABLE ret) +if(NOT ret EQUAL 0) + message(FATAL_ERROR "can't regen") +endif() +execute_process(COMMAND cmake --build ${CMAKE_BINARY_DIR} --target tarball-real2) +if(NOT ret EQUAL 0) + message(FATAL_ERROR "can't make tarball") +endif() diff --git a/facetracknoir/main.cpp b/facetracknoir/main.cpp index 8425299b..4e56b3df 100644 --- a/facetracknoir/main.cpp +++ b/facetracknoir/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) // qt5 designer-made controls look like shit on 'doze -sh 20140921 // also our OSX look leaves a lot to be desired -sh 20150726 { - const QStringList preferred { "fusion", "windowsvista", "jazzbands'-marijuana", "macintosh", "windowsxp" }; + const QStringList preferred { "fusion", "windowsvista", "macintosh", "windowsxp" }; for (const auto& style_name : preferred) { QStyle* s = QStyleFactory::create(style_name); diff --git a/facetracknoir/settings.ui b/facetracknoir/settings.ui index 5a32daf6..5ab857db 100644 --- a/facetracknoir/settings.ui +++ b/facetracknoir/settings.ui @@ -300,19 +300,6 @@ </property> </widget> </item> - <item row="0" column="1"> - <widget class="QSpinBox" name="mindiam_spin"> - <property name="toolTip"> - <string>Minimum point diameter</string> - </property> - <property name="suffix"> - <string> px</string> - </property> - <property name="maximum"> - <number>1024</number> - </property> - </widget> - </item> <item row="0" column="2"> <widget class="QLabel" name="label_22"> <property name="text"> @@ -324,15 +311,28 @@ </widget> </item> <item row="0" column="3"> - <widget class="QSpinBox" name="maxdiam_spin"> + <widget class="QDoubleSpinBox" name="maxdiam_spin"> <property name="toolTip"> <string>Maximum point diameter</string> </property> <property name="suffix"> <string> px</string> </property> - <property name="maximum"> - <number>1024</number> + <property name="decimals"> + <number>1</number> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QDoubleSpinBox" name="mindiam_spin"> + <property name="toolTip"> + <string>Minimum point diameter</string> + </property> + <property name="suffix"> + <string> px</string> + </property> + <property name="decimals"> + <number>1</number> </property> </widget> </item> diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.cpp b/ftnoir_filter_accela/ftnoir_filter_accela.cpp index 46c35958..51e79ec2 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.cpp +++ b/ftnoir_filter_accela/ftnoir_filter_accela.cpp @@ -58,15 +58,32 @@ FTNoIR_Filter::FTNoIR_Filter() : first_run(true) } } +static inline bool nanp(double value) +{ + return std::isnan(value) || std::isinf(value); +} + +static inline double elide_nan(double value, double def) +{ + if (nanp(value)) + { + if (nanp(def)) + return 0; + return def; + } + return value; +} + void FTNoIR_Filter::filter(const double* input, double *output) { if (first_run) { for (int i = 0; i < 6; i++) { - output[i] = input[i]; - last_output[i] = input[i]; - smoothed_input[i] = input[i]; + const double f = nanp(input[i]) ? 0 : input[i]; + output[i] = f; + last_output[i] = f; + smoothed_input[i] = f; } first_run = false; t.start(); @@ -88,9 +105,7 @@ void FTNoIR_Filter::filter(const double* input, double *output) { Map& m = i >= 3 ? rot : trans; - const bool drop = std::isnan(input[i]) || std::isinf(input[i]); - const double f = drop ? last_output[i] : input[i]; - smoothed_input[i] = smoothed_input[i] * (1.-alpha) + f * alpha; + smoothed_input[i] = smoothed_input[i] * (1.-alpha) + elide_nan(input[i], smoothed_input[i]) * alpha; const double in = smoothed_input[i]; @@ -106,6 +121,6 @@ void FTNoIR_Filter::filter(const double* input, double *output) : result >= in; const double ret = done ? in : result; - last_output[i] = output[i] = ret; + last_output[i] = output[i] = elide_nan(ret, last_output[i]); } } diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 360ca7f3..6e36525b 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -36,7 +36,8 @@ class FTNoIR_Filter : public IFilter { public: FTNoIR_Filter(); - void filter(const double* input, double *output); + void filter(const double* input, double *output) override; + void center() override { first_run = true; } Map rot, trans; private: settings_accela s; diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp index d77df027..702a92d4 100644 --- a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp +++ b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp @@ -114,7 +114,7 @@ void FTNoIR_Protocol::pose(const double *headpose ) { // FSUIPC checks for already open connections and returns FSUIPC_ERR_OPEN in that case // the connection scope is global for the process. this is why above code doesn't // leak resources or have logic errors. see: http://www.purebasic.fr/english/viewtopic.php?t=31112 - FSUIPC_Close(); //timeout (1 second) so assume FS closed + FSUIPC_Close(); } } } diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 5d7ab778..0c6cb486 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -1,9 +1,13 @@ -/* Copyright (c) 2015 Stanislaw Halik <sthalik@misaki.pl> - * Copyright (c) 2015 Wim Vriend - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. +/* Homepage http://facetracknoir.sourceforge.net/home/default.htm * + * * + * ISC License (ISC) * + * * + * Copyright (c) 2015, Wim Vriend + * Copyright (c) 2014, Stanislaw Halik <sthalik@misaki.pl> + * * + * Permission to use, copy, modify, and/or distribute this software for any * + * purpose with or without fee is hereby granted, provided that the above * + * copyright notice and this permission notice appear in all copies. * */ #include "ftnoir_protocol_sc.h" #include "opentrack/plugin-api.hpp" @@ -80,7 +84,7 @@ public: # define PREFIX "" #else # define PREFIX "lib" -#endif +#endif QString path = QCoreApplication::applicationDirPath() + "/" PREFIX "opentrack-proto-simconnect.dll"; QByteArray name = QFile::encodeName(path); actx.lpSource = name.constData(); @@ -113,11 +117,11 @@ private: }; bool FTNoIR_Protocol::correct() -{ - if (!SCClientLib.isLoaded()) +{ + if (!SCClientLib.isLoaded()) { ActivationContext ctx(142 + static_cast<int>(s.sxs_manifest)); - + if (ctx.is_ok()) { SCClientLib.setFileName("SimConnect.dll"); @@ -171,7 +175,7 @@ void FTNoIR_Protocol::handle() void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *self_) { FTNoIR_Protocol& self = *reinterpret_cast<FTNoIR_Protocol*>(self_); - + switch(pData->dwID) { default: diff --git a/ftnoir_tracker_aruco/trans_calib.cpp b/ftnoir_tracker_aruco/trans_calib.cpp index 176cf24c..b5148efd 100644 --- a/ftnoir_tracker_aruco/trans_calib.cpp +++ b/ftnoir_tracker_aruco/trans_calib.cpp @@ -7,7 +7,6 @@ #include "trans_calib.h" -//----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { reset(); diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 7b70d4eb..9a5f11c4 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -1,4 +1,5 @@ /* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2014-2015 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,8 +20,8 @@ Tracker_PT::Tracker_PT() : mutex(QMutex::Recursive), commands(0), - video_widget(NULL), - video_frame(NULL), + video_widget(NULL), + video_frame(NULL), ever_success(false) { connect(s.b.get(), SIGNAL(saving()), this, SLOT(apply_settings())); @@ -28,8 +29,8 @@ Tracker_PT::Tracker_PT() Tracker_PT::~Tracker_PT() { - set_command(ABORT); - wait(); + set_command(ABORT); + wait(); delete video_widget; video_widget = NULL; if (video_frame->layout()) delete video_frame->layout(); @@ -39,13 +40,13 @@ Tracker_PT::~Tracker_PT() void Tracker_PT::set_command(Command command) { //QMutexLocker lock(&mutex); - commands |= command; + commands |= command; } void Tracker_PT::reset_command(Command command) { //QMutexLocker lock(&mutex); - commands &= ~command; + commands &= ~command; } bool Tracker_PT::get_focal_length(float& ret) @@ -78,16 +79,21 @@ bool Tracker_PT::get_focal_length(float& ret) return false; } +static inline bool nanp(double value) +{ + return std::isnan(value) || std::isinf(value); +} + void Tracker_PT::run() { #ifdef PT_PERF_LOG - QFile log_file(QCoreApplication::applicationDirPath() + "/PointTrackerPerformance.txt"); - if (!log_file.open(QIODevice::WriteOnly | QIODevice::Text)) return; - QTextStream log_stream(&log_file); + QFile log_file(QCoreApplication::applicationDirPath() + "/PointTrackerPerformance.txt"); + if (!log_file.open(QIODevice::WriteOnly | QIODevice::Text)) return; + QTextStream log_stream(&log_file); #endif apply_settings(); - + while((commands & ABORT) == 0) { const double dt = time.elapsed() * 1e-9; @@ -109,22 +115,46 @@ void Tracker_PT::run() // blobs are sorted in order of circularity if (points.size() > PointModel::N_POINTS) points.resize(PointModel::N_POINTS); - + bool success = points.size() == PointModel::N_POINTS; - - ever_success |= success; float fx; if (!get_focal_length(fx)) continue; + + Affine X_CM_ = pose(); if (success) { point_tracker.track(points, PointModel(s), fx, s.dynamic_pose, s.init_phase_timeout); } + Affine X_CM = pose(); + + { + int j = 0; + + for (int i = 0; i < 3; i++) + { + if (nanp(X_CM.t(i))) + goto nannan; + for (; j < 3; j++) + if (nanp(X_CM.R(i, j))) + { +nannan: success = false; + X_CM = X_CM_; + { + QMutexLocker lock(&mutex); + point_tracker.reset(X_CM_); + } + goto nannannan; + } + } + } + +nannannan: ever_success |= success; + { - Affine X_CM = pose(); Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below if (X_MH.t[0] == 0 && X_MH.t[1] == 0 && X_MH.t[2] == 0) { @@ -145,7 +175,7 @@ void Tracker_PT::run() cv::Vec2f p_(p[0] / p[2] * fx, p[1] / p[2] * fx); // projected to screen points.push_back(p_); } - + for (unsigned i = 0; i < points.size(); i++) { auto& p = points[i]; @@ -164,7 +194,7 @@ void Tracker_PT::run() color, 4); } - + video_widget->update_image(frame); } #ifdef PT_PERF_LOG @@ -233,26 +263,26 @@ void Tracker_PT::data(double *data) if (ever_success) { Affine X_CM = pose(); - + Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); Affine X_GH = X_CM * X_MH; - + cv::Matx33f R = X_GH.R; cv::Vec3f t = X_GH.t; - + // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame // -z -> x, y -> z, x -> -y cv::Matx33f R_EG(0, 0,-1, -1, 0, 0, 0, 1, 0); R = R_EG * R * R_EG.t(); - + // extract rotation angles float alpha, beta, gamma; beta = atan2( -R(2,0), sqrt(R(2,1)*R(2,1) + R(2,2)*R(2,2)) ); alpha = atan2( R(1,0), R(0,0)); gamma = atan2( R(2,1), R(2,2)); - + // extract rotation angles data[Yaw] = rad2deg * alpha; data[Pitch] = -rad2deg * beta; diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h index 0bfc05f7..78626468 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h @@ -1,4 +1,5 @@ /* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2014-2015 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -13,9 +14,8 @@ using namespace options; struct settings_pt : opts { - value<int> threshold, - min_point_size, - max_point_size; + value<int> threshold; + value<double> min_point_size, max_point_size; value<int> t_MH_x, t_MH_y, t_MH_z; value<int> fov, camera_mode; diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index 0ac2fc32..ec37dd00 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -1,4 +1,5 @@ /* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2014-2015 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -28,21 +29,21 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) cv::Mat frame_gray; cv::cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - const int region_size_min = s.min_point_size; - const int region_size_max = s.max_point_size; + const double region_size_min = s.min_point_size; + const double region_size_max = s.max_point_size; - struct simple_blob + struct blob { double radius; cv::Vec2d pos; double confid; bool taken; double area; - simple_blob(double radius, const cv::Vec2d& pos, double confid, double area) : radius(radius), pos(pos), confid(confid), taken(false), area(area) + blob(double radius, const cv::Vec2d& pos, double confid, double area) : radius(radius), pos(pos), confid(confid), taken(false), area(area) { //qDebug() << "radius" << radius << "pos" << pos[0] << pos[1] << "confid" << confid; } - bool inside(const simple_blob& other) + bool inside(const blob& other) { cv::Vec2d tmp = pos - other.pos; return sqrt(tmp.dot(tmp)) < radius; @@ -52,7 +53,7 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) cv::Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); - std::vector<simple_blob> blobs; + std::vector<blob> blobs; std::vector<std::vector<cv::Point>> contours; const int thres = s.threshold; @@ -76,8 +77,8 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) const int sz = hist.rows*hist.cols; int val = 0; int cnt = 0; - constexpr int min_pixels = 2000; - const int pixels_to_include = std::max(0, static_cast<int>(min_pixels * (1. - s.threshold / 100.))); + constexpr int min_pixels = 250; + const auto pixels_to_include = std::max<int>(0, min_pixels * s.threshold/100.); for (int i = sz-1; i >= 0; i--) { cnt += hist.at<float>(i); @@ -87,8 +88,8 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) break; } } - val *= .95; - //qDebug() << "cnt" << cnt << "val" << val; + val *= 240./256.; + //qDebug() << "val" << val; cv::Mat frame_bin_; cv::threshold(frame_gray, frame_bin_, val, 255, CV_THRESH_BINARY); @@ -148,13 +149,13 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) cv::putText(frame, buf, cv::Point(pos[0]+30, pos[1]+20), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 0, 255), 1); } - blobs.push_back(simple_blob(radius, pos, confid, area)); + blobs.push_back(blob(radius, pos, confid, area)); } // clear old points points.clear(); - using b = const simple_blob; + using b = const blob; std::sort(blobs.begin(), blobs.end(), [](b& b1, b& b2) {return b1.confid > b2.confid;}); for (auto& b : blobs) diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index cedf1979..924b75de 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -15,19 +15,18 @@ const float PI = 3.14159265358979323846f; -// ---------------------------------------------------------------------------- static void get_row(const cv::Matx33f& m, int i, cv::Vec3f& v) { - v[0] = m(i,0); - v[1] = m(i,1); - v[2] = m(i,2); + v[0] = m(i,0); + v[1] = m(i,1); + v[2] = m(i,2); } static void set_row(cv::Matx33f& m, int i, const cv::Vec3f& v) { - m(i,0) = v[0]; - m(i,1) = v[1]; - m(i,2) = v[2]; + m(i,0) = v[0]; + m(i,1) = v[1]; + m(i,2) = v[2]; } static bool d_vals_sort(const std::pair<float,int> a, const std::pair<float,int> b) @@ -67,31 +66,31 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const std:: // set correspondences by minimum distance to projected model point bool point_taken[PointModel::N_POINTS]; for (int i=0; i<PointModel::N_POINTS; ++i) - point_taken[i] = false; + point_taken[i] = false; for (int i=0; i<PointModel::N_POINTS; ++i) { - float min_sdist = 0; - int min_idx = 0; - // find closest point to projected model point i - for (int j=0; j<PointModel::N_POINTS; ++j) + float min_sdist = 0; + int min_idx = 0; + // find closest point to projected model point i + for (int j=0; j<PointModel::N_POINTS; ++j) + { + cv::Vec2f d = p.points[i]-points[j]; + float sdist = d.dot(d); + if (sdist < min_sdist || j==0) { - cv::Vec2f d = p.points[i]-points[j]; - float sdist = d.dot(d); - if (sdist < min_sdist || j==0) - { - min_idx = j; - min_sdist = sdist; - } + min_idx = j; + min_sdist = sdist; } - // if one point is closest to more than one model point, fallback - if (point_taken[min_idx]) - { - init_phase = true; - return find_correspondences(points, model); - } - point_taken[min_idx] = true; - p.points[i] = points[min_idx]; + } + // if one point is closest to more than one model point, fallback + if (point_taken[min_idx]) + { + init_phase = true; + return find_correspondences(points, model); + } + point_taken[min_idx] = true; + p.points[i] = points[min_idx]; } return p; } @@ -100,19 +99,19 @@ void PointTracker::track(const std::vector<cv::Vec2f>& points, const PointModel& { PointOrder order; - if (t.elapsed_ms() > init_phase_timeout) - { - t.start(); - init_phase = true; - } + if (t.elapsed_ms() > init_phase_timeout) + { + t.start(); + init_phase = true; + } if (!dynamic_pose || init_phase) order = find_correspondences(points, model); - else - order = find_correspondences_previous(points, model, f); - + else + order = find_correspondences_previous(points, model, f); + POSIT(model, order, f); - init_phase = false; + init_phase = false; t.start(); } @@ -142,127 +141,127 @@ PointTracker::PointOrder PointTracker::find_correspondences(const std::vector<cv int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float focal_length) { - // POSIT algorithm for coplanar points as presented in - // [Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis: "Iterative Pose Estimation Using Coplanar Feature Points"] - // we use the same notation as in the paper here - - // The expected rotation used for resolving the ambiguity in POSIT: - // In every iteration step the rotation closer to R_expected is taken - cv::Matx33f R_expected = cv::Matx33f::eye(); - - // initial pose = last (predicted) pose - cv::Vec3f k; - get_row(R_expected, 2, k); - float Z0 = 1000.f; - - float old_epsilon_1 = 0; - float old_epsilon_2 = 0; - float epsilon_1 = 1; - float epsilon_2 = 1; - - cv::Vec3f I0, J0; - cv::Vec2f I0_coeff, J0_coeff; - - cv::Vec3f I_1, J_1, I_2, J_2; - cv::Matx33f R_1, R_2; - cv::Matx33f* R_current; - - const int MAX_ITER = 100; - const float EPS_THRESHOLD = 1e-4; - - const cv::Vec2f* order = order_.points; - - int i=1; - for (; i<MAX_ITER; ++i) - { - epsilon_1 = k.dot(model.M01)/Z0; - epsilon_2 = k.dot(model.M02)/Z0; - - // vector of scalar products <I0, M0i> and <J0, M0i> - cv::Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], - order[2][0]*(1.0 + epsilon_2) - order[0][0]); - cv::Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], - order[2][1]*(1.0 + epsilon_2) - order[0][1]); - - // construct projection of I, J onto M0i plane: I0 and J0 - I0_coeff = model.P * I0_M0i; - J0_coeff = model.P * J0_M0i; - I0 = I0_coeff[0]*model.M01 + I0_coeff[1]*model.M02; - J0 = J0_coeff[0]*model.M01 + J0_coeff[1]*model.M02; - - // calculate u component of I, J - float II0 = I0.dot(I0); - float IJ0 = I0.dot(J0); - float JJ0 = J0.dot(J0); - float rho, theta; - if (JJ0 == II0) { - rho = std::sqrt(std::abs(2*IJ0)); - theta = -PI/4; - if (IJ0<0) theta *= -1; - } - else { - rho = sqrt(sqrt( (JJ0-II0)*(JJ0-II0) + 4*IJ0*IJ0 )); - theta = atan( -2*IJ0 / (JJ0-II0) ); - if (JJ0 - II0 < 0) theta += PI; - theta /= 2; - } - - // construct the two solutions - I_1 = I0 + rho*cos(theta)*model.u; - I_2 = I0 - rho*cos(theta)*model.u; - - J_1 = J0 + rho*sin(theta)*model.u; - J_2 = J0 - rho*sin(theta)*model.u; - - float norm_const = 1.0/cv::norm(I_1); // all have the same norm - - // create rotation matrices - I_1 *= norm_const; J_1 *= norm_const; - I_2 *= norm_const; J_2 *= norm_const; - - set_row(R_1, 0, I_1); - set_row(R_1, 1, J_1); - set_row(R_1, 2, I_1.cross(J_1)); - - set_row(R_2, 0, I_2); - set_row(R_2, 1, J_2); - set_row(R_2, 2, I_2.cross(J_2)); - - // the single translation solution - Z0 = norm_const * focal_length; - - // pick the rotation solution closer to the expected one - // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_2.t()); - - if (R_1_deviation < R_2_deviation) - R_current = &R_1; - else - R_current = &R_2; - - get_row(*R_current, 2, k); - - // check for convergence condition - if (std::abs(epsilon_1 - old_epsilon_1) + std::abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) - break; - old_epsilon_1 = epsilon_1; - old_epsilon_2 = epsilon_2; - } - - // apply results - X_CM.R = *R_current; - X_CM.t[0] = order[0][0] * Z0/focal_length; - X_CM.t[1] = order[0][1] * Z0/focal_length; - X_CM.t[2] = Z0; - - //qDebug() << "iter:" << i; - - return i; + // POSIT algorithm for coplanar points as presented in + // [Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis: "Iterative Pose Estimation Using Coplanar Feature Points"] + // we use the same notation as in the paper here + + // The expected rotation used for resolving the ambiguity in POSIT: + // In every iteration step the rotation closer to R_expected is taken + cv::Matx33f R_expected = cv::Matx33f::eye(); + + // initial pose = last (predicted) pose + cv::Vec3f k; + get_row(R_expected, 2, k); + float Z0 = 1000.f; + + float old_epsilon_1 = 0; + float old_epsilon_2 = 0; + float epsilon_1 = 1; + float epsilon_2 = 1; + + cv::Vec3f I0, J0; + cv::Vec2f I0_coeff, J0_coeff; + + cv::Vec3f I_1, J_1, I_2, J_2; + cv::Matx33f R_1, R_2; + cv::Matx33f* R_current; + + const int MAX_ITER = 100; + const float EPS_THRESHOLD = 1e-4; + + const cv::Vec2f* order = order_.points; + + int i=1; + for (; i<MAX_ITER; ++i) + { + epsilon_1 = k.dot(model.M01)/Z0; + epsilon_2 = k.dot(model.M02)/Z0; + + // vector of scalar products <I0, M0i> and <J0, M0i> + cv::Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], + order[2][0]*(1.0 + epsilon_2) - order[0][0]); + cv::Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], + order[2][1]*(1.0 + epsilon_2) - order[0][1]); + + // construct projection of I, J onto M0i plane: I0 and J0 + I0_coeff = model.P * I0_M0i; + J0_coeff = model.P * J0_M0i; + I0 = I0_coeff[0]*model.M01 + I0_coeff[1]*model.M02; + J0 = J0_coeff[0]*model.M01 + J0_coeff[1]*model.M02; + + // calculate u component of I, J + float II0 = I0.dot(I0); + float IJ0 = I0.dot(J0); + float JJ0 = J0.dot(J0); + float rho, theta; + if (JJ0 == II0) { + rho = std::sqrt(std::abs(2*IJ0)); + theta = -PI/4; + if (IJ0<0) theta *= -1; + } + else { + rho = sqrt(sqrt( (JJ0-II0)*(JJ0-II0) + 4*IJ0*IJ0 )); + theta = atan( -2*IJ0 / (JJ0-II0) ); + if (JJ0 - II0 < 0) theta += PI; + theta /= 2; + } + + // construct the two solutions + I_1 = I0 + rho*cos(theta)*model.u; + I_2 = I0 - rho*cos(theta)*model.u; + + J_1 = J0 + rho*sin(theta)*model.u; + J_2 = J0 - rho*sin(theta)*model.u; + + float norm_const = 1.0/cv::norm(I_1); // all have the same norm + + // create rotation matrices + I_1 *= norm_const; J_1 *= norm_const; + I_2 *= norm_const; J_2 *= norm_const; + + set_row(R_1, 0, I_1); + set_row(R_1, 1, J_1); + set_row(R_1, 2, I_1.cross(J_1)); + + set_row(R_2, 0, I_2); + set_row(R_2, 1, J_2); + set_row(R_2, 2, I_2.cross(J_2)); + + // the single translation solution + Z0 = norm_const * focal_length; + + // pick the rotation solution closer to the expected one + // in simple metric d(A,B) = || I - A * B^T || + float R_1_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_1.t()); + float R_2_deviation = cv::norm(cv::Matx33f::eye() - R_expected * R_2.t()); + + if (R_1_deviation < R_2_deviation) + R_current = &R_1; + else + R_current = &R_2; + + get_row(*R_current, 2, k); + + // check for convergence condition + if (std::abs(epsilon_1 - old_epsilon_1) + std::abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) + break; + old_epsilon_1 = epsilon_1; + old_epsilon_2 = epsilon_2; + } + + // apply results + X_CM.R = *R_current; + X_CM.t[0] = order[0][0] * Z0/focal_length; + X_CM.t[1] = order[0][1] * Z0/focal_length; + X_CM.t[2] = Z0; + + //qDebug() << "iter:" << i; + + return i; } cv::Vec2f PointTracker::project(const cv::Vec3f& v_M, float f) { - cv::Vec3f v_C = X_CM * v_M; - return cv::Vec2f(f*v_C[0]/v_C[2], f*v_C[1]/v_C[2]); + cv::Vec3f v_C = X_CM * v_M; + return cv::Vec2f(f*v_C[0]/v_C[2], f*v_C[1]/v_C[2]); } diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index df938237..f4268486 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -122,6 +122,10 @@ public: void track(const std::vector<cv::Vec2f>& projected_points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout); Affine pose() const { return X_CM; } cv::Vec2f project(const cv::Vec3f& v_M, float f); + void reset(const Affine& pose) + { + X_CM = pose; + } private: // the points in model order struct PointOrder diff --git a/ftnoir_tracker_pt/pt_video_widget.cpp b/ftnoir_tracker_pt/pt_video_widget.cpp index 9f2b90f6..cbb7c268 100644 --- a/ftnoir_tracker_pt/pt_video_widget.cpp +++ b/ftnoir_tracker_pt/pt_video_widget.cpp @@ -1,4 +1,5 @@ /* Copyright (c) 2012 Patrick Ruoff + * Copyright (c) 2015 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/make-tar.sh b/make-tar.sh index cd5abc56..3e119d12 100644 --- a/make-tar.sh +++ b/make-tar.sh @@ -2,14 +2,24 @@ prefix="$1" filename="$2" +bin="$3" + +cmake --build "$bin" --target install || exit 1 if : && cd $(dirname -- "${prefix}") && zip -9r "${filename}" $(basename "${prefix}") then - ls -lh -- "${filename}" - case "$(uname -s)" in - CYGWIN_*) ls -lh -- "$(cygpath -w -- "$filename")";; + case "$USER,$(uname -s)" in + # for the script see https://github.com/andreafabrizi/Dropbox-Uploader + sthalik,CYGWIN_*) + dropbox_uploader.sh -p upload "$filename" / + bn="$(basename -- "$filename")" + l="$(dropbox_uploader.sh -q share /"$bn")" + test -n "$l" && echo -n "$l" | putclip + echo $l + echo -ne '\a' ;; + *) ls -lh -- "${filename}" ;; esac else rm -fv -- "${filename}" diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp index 65735740..ef3b325f 100644 --- a/opentrack-compat/process-list.hpp +++ b/opentrack-compat/process-list.hpp @@ -1,3 +1,10 @@ +/* Copyright (c) 2015 Stanislaw Halik <sthalik@misaki.pl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + #pragma once #include <QDebug> diff --git a/opentrack-compat/shm.cpp b/opentrack-compat/shm.cpp index b18a9933..029a4c95 100644 --- a/opentrack-compat/shm.cpp +++ b/opentrack-compat/shm.cpp @@ -43,10 +43,13 @@ void PortableLockedShm::unlock() (void) ReleaseMutex(hMutex); } #else + +#include <limits.h> + #pragma GCC diagnostic ignored "-Wunused-result" PortableLockedShm::PortableLockedShm(const char *shmName, const char* /*mutexName*/, int mapSize) : size(mapSize) { - char filename[512] = {0}; + char filename[PATH_MAX+2] = {0}; strcpy(filename, "/"); strcat(filename, shmName); fd = shm_open(filename, O_RDWR | O_CREAT, 0600); diff --git a/opentrack-compat/sleep.hpp b/opentrack-compat/sleep.hpp index 27920842..e7c70285 100644 --- a/opentrack-compat/sleep.hpp +++ b/opentrack-compat/sleep.hpp @@ -3,7 +3,7 @@ namespace portable { #ifdef _WIN32 - #include <windows.h> +# include <windows.h> template<typename = void> void sleep(unsigned milliseconds) diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp index 732dbb3d..a57077ab 100644 --- a/opentrack/plugin-api.hpp +++ b/opentrack/plugin-api.hpp @@ -61,6 +61,8 @@ struct IFilter // perform filtering step. // you have to take care of dt on your own, try "opentrack-compat/timer.hpp" virtual void filter(const double *input, double *output) = 0; + // optionally reset the filter when centering + virtual void center() {} }; struct IFilterDialog : public BaseDialog diff --git a/opentrack/shortcuts.cpp b/opentrack/shortcuts.cpp index ba2b7c8e..91480d16 100644 --- a/opentrack/shortcuts.cpp +++ b/opentrack/shortcuts.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2014, Stanislaw Halik <sthalik@misaki.pl> +/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl> * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, @@ -96,9 +96,9 @@ void KeybindingWorker::run() { case DIK_RALT: break; default: - k.shift = !!(keystate[DIK_LSHIFT] & 0x80); - k.alt = !!(keystate[DIK_LALT] & 0x80); - k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80); + k.shift = !!(keystate[DIK_LSHIFT] & 0x80) || !!(keystate[DIK_RSHIFT] & 0x80); + k.alt = !!(keystate[DIK_LALT] & 0x80) || !!(keystate[DIK_RALT] & 0x80); + k.ctrl = !!(keystate[DIK_LCONTROL] & 0x80) || !!(keystate[DIK_RCONTROL] & 0x80); k.keycode = i; receiver(k); break; @@ -120,6 +120,8 @@ void Shortcuts::bind_keyboard_shortcut(K &key, key_opts& k) else { key->setShortcut(QKeySequence::UnknownKey); key->setEnabled(false); + std::shared_ptr<QxtGlobalShortcut> ptr = K(); + key.swap(ptr); } if (k.keycode != "") diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp index 8a9a0511..1bc28b87 100644 --- a/opentrack/tracker.cpp +++ b/opentrack/tracker.cpp @@ -24,6 +24,7 @@ Tracker::Tracker(main_settings& s, Mappings &m, SelectedLibraries &libs) : s(s), m(m), + newpose {0,0,0, 0,0,0}, centerp(s.center_at_startup), enabledp(true), zero_(false), @@ -62,6 +63,44 @@ void Tracker::t_compensate(const rmat& rmat, const double* xyz, double* output, output[0] = -ret(1); } +static inline bool nanp(double value) +{ + return std::isnan(value) || std::isinf(value); +} + +static inline double elide_nan(double value, double def) +{ + if (nanp(value)) + { + if (nanp(def)) + return 0; + return def; + } + return value; +} + +static bool is_nan(const dmat<3,3>& r, const dmat<3, 1>& t) +{ + for (int i = 0; i < 3; i++) + for (int j = 0; j < 3; j++) + if (nanp(r(i, j))) + return true; + + for (int i = 0; i < 3; i++) + if (nanp(t(i))) + return true; + + return false; +} + +static bool is_nan(const Pose& value) +{ + for (int i = 0; i < 6; i++) + if (nanp(value(i))) + return true; + return false; +} + void Tracker::logic() { bool inverts[6] = { @@ -72,12 +111,12 @@ void Tracker::logic() m(4).opts.invert, m(5).opts.invert, }; - + static constexpr double pi = 3.141592653; static constexpr double r2d = 180. / pi; - + Pose value, raw; - + for (int i = 0; i < 6; i++) { auto& axis = m(i); @@ -89,6 +128,9 @@ void Tracker::logic() raw(i) = newpose[i]; } + if (is_nan(raw)) + raw = last_raw; + const double off[] = { (double)-s.camera_yaw, (double)-s.camera_pitch, @@ -97,12 +139,13 @@ void Tracker::logic() const rmat cam = rmat::euler_to_rmat(off); rmat r = rmat::euler_to_rmat(&value[Yaw]); dmat<3, 1> t(value(0), value(1), value(2)); - + r = cam * r; - + bool can_center = false; - - if (centerp) + const bool nan = is_nan(r, t); + + if (centerp && !nan) { for (int i = 0; i < 6; i++) if (fabs(newpose[i]) != 0) @@ -111,15 +154,17 @@ void Tracker::logic() break; } } - + if (can_center) { + if (libs.pFilter) + libs.pFilter->center(); centerp = false; for (int i = 0; i < 3; i++) t_b[i] = t(i); r_b = r; } - + { double tmp[3] = { t(0) - t_b[0], t(1) - t_b[1], t(2) - t_b[2] }; t_compensate(cam, tmp, tmp, false); @@ -141,32 +186,54 @@ void Tracker::logic() value(i+3) = euler(i) * r2d; } } - + + bool nan_ = false; + // we're checking NaNs after every block of numeric ops + if (is_nan(value)) + { + nan_ = true; + } + else { Pose tmp = value; - + if (libs.pFilter) libs.pFilter->filter(tmp, value); - } - for (int i = 0; i < 6; i++) - value(i) = map(value(i), m(i)); - - if (s.tcomp_p) - t_compensate(rmat::euler_to_rmat(&value[Yaw]), - value, - value, - s.tcomp_tz); + for (int i = 0; i < 6; i++) + value(i) = map(value(i), m(i)); - for (int i = 0; i < 6; i++) - value[i] *= inverts[i] ? -1. : 1.; + if (s.tcomp_p) + t_compensate(rmat::euler_to_rmat(&value[Yaw]), + value, + value, + s.tcomp_tz); - if (zero_) for (int i = 0; i < 6; i++) - value(i) = 0; + value[i] *= inverts[i] ? -1. : 1.; + + if (zero_) + for (int i = 0; i < 6; i++) + value(i) = 0; + + if (is_nan(value)) + nan_ = true; + } + + if (nan_) + { + value = last_mapped; + + // for widget last value display + for (int i = 0; i < 6; i++) + (void) map(value(i), m(i)); + } libs.pProtocol->pose(value); + last_mapped = value; + last_raw = raw; + QMutexLocker foo(&mtx); output_pose = value; raw_6dof = raw; @@ -174,7 +241,7 @@ void Tracker::logic() void Tracker::run() { const int sleep_ms = 3; - + #if defined(_WIN32) (void) timeBeginPeriod(1); #endif @@ -182,14 +249,14 @@ void Tracker::run() { while (!should_quit) { t.start(); - + double tmp[6] {0,0,0, 0,0,0}; libs.pTracker->data(tmp); if (enabledp) for (int i = 0; i < 6; i++) - newpose[i] = tmp[i]; - + newpose[i] = elide_nan(tmp[i], newpose[i]); + logic(); long q = sleep_ms * 1000L - t.elapsed()/1000L; diff --git a/opentrack/tracker.h b/opentrack/tracker.h index c5c39797..b0e89455 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -48,7 +48,7 @@ private: Mappings& m; Timer t; - Pose output_pose, raw_6dof; + Pose output_pose, raw_6dof, last_mapped, last_raw; double newpose[6]; volatile bool centerp; diff --git a/opentrack/version.cc b/opentrack/version.cc deleted file mode 100644 index 9e75a336..00000000 --- a/opentrack/version.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "opentrack-compat/export.hpp" - -#ifdef __cplusplus -extern "C" -#endif -OPENTRACK_EXPORT -const char* opentrack_version; - -const char* opentrack_version = OPENTRACK_VERSION; diff --git a/opentrack/win32-shortcuts.cpp b/opentrack/win32-shortcuts.cpp index bd51ae88..96232631 100644 --- a/opentrack/win32-shortcuts.cpp +++ b/opentrack/win32-shortcuts.cpp @@ -1,3 +1,11 @@ +/* Copyright (c) 2015, Stanislaw Halik <sthalik@misaki.pl> + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ + #if defined(_WIN32) # ifndef DIRECTINPUT_VERSION # define DIRECTINPUT_VERSION 0x800 @@ -109,6 +117,9 @@ QList<win_key> windows_key_sequences = win_key(DIK_RETURN, Qt::Key::Key_Return), win_key(DIK_INSERT, Qt::Key::Key_Insert), win_key(DIK_SPACE, Qt::Key::Key_Space), + win_key(DIK_SYSRQ, Qt::Key::Key_Print), + win_key(DIK_SCROLL, Qt::Key::Key_ScrollLock), + win_key(DIK_PAUSE, Qt::Key::Key_Pause), }); bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods) diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp index 33f9beee..cac8121c 100644 --- a/qfunctionconfigurator/functionconfig.cpp +++ b/qfunctionconfigurator/functionconfig.cpp @@ -1,3 +1,11 @@ +/* Copyright (c) 2012-2015, Stanislaw Halik <sthalik@misaki.pl> + + * Permission to use, copy, modify, and/or distribute this + * software for any purpose with or without fee is hereby granted, + * provided that the above copyright notice and this permission + * notice appear in all copies. + */ + #include <QMutexLocker> #include <QCoreApplication> #include <QPointF> @@ -67,6 +75,18 @@ static bool sortFn(const QPointF& one, const QPointF& two) { return one.x() < two.x(); } +static inline bool nanp(double value) +{ + return std::isnan(value) || std::isinf(value); +} + +static inline double elide_nan(double value) +{ + if (nanp(value)) + return -1; + return value; +} + void Map::reload() { if (cur.input.size()) { @@ -124,7 +144,7 @@ void Map::reload() { (-p0_y + 3. * p1_y - 3. * p2_y + p3_y) * t3); if (x >= 0 && x < sz) - data[x] = y; + data[x] = elide_nan(y); } } diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h index 31aebdf6..6d76d0de 100644 --- a/qfunctionconfigurator/functionconfig.h +++ b/qfunctionconfigurator/functionconfig.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014, Stanislaw Halik <sthalik@misaki.pl> +/* Copyright (c) 2012-2015, Stanislaw Halik <sthalik@misaki.pl> * Permission to use, copy, modify, and/or distribute this * software for any purpose with or without fee is hereby granted, diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp index e62049db..bcb895ec 100644 --- a/qfunctionconfigurator/qfunctionconfigurator.cpp +++ b/qfunctionconfigurator/qfunctionconfigurator.cpp @@ -1,3 +1,10 @@ +/* Copyright (c) 2012-2015 Stanislaw Halik <sthalik@misaki.pl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + #include "opentrack/options.hpp" using namespace options; #include "qfunctionconfigurator/qfunctionconfigurator.h" diff --git a/qfunctionconfigurator/qfunctionconfigurator.h b/qfunctionconfigurator/qfunctionconfigurator.h index 8957c898..667886cd 100644 --- a/qfunctionconfigurator/qfunctionconfigurator.h +++ b/qfunctionconfigurator/qfunctionconfigurator.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011-2014 Stanislaw Halik <sthalik@misaki.pl> +/* Copyright (c) 2012-2015 Stanislaw Halik <sthalik@misaki.pl> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/qxt-mini/plat/qxtglobalshortcut_mac.cpp b/qxt-mini/plat/qxtglobalshortcut_mac.cpp index fbf86a94..1181b293 100644 --- a/qxt-mini/plat/qxtglobalshortcut_mac.cpp +++ b/qxt-mini/plat/qxtglobalshortcut_mac.cpp @@ -29,6 +29,9 @@ ** <http://libqxt.org> <foundation@libqxt.org> *****************************************************************************/ +#pragma GCC diagnostic ignored "-Wfour-char-constants" +#pragma GCC diagnostic ignored "-Wunused-parameter" + #include "qxtglobalshortcut_p.h" #include <QMap> #include <QHash> diff --git a/x-plane-plugin/plugin.c b/x-plane-plugin/plugin.c index 999f6e15..c091f74d 100644 --- a/x-plane-plugin/plugin.c +++ b/x-plane-plugin/plugin.c @@ -16,6 +16,8 @@ #define PLUGIN_API #endif +#pragma GCC diagnostic ignored "-Wunused-parameter" + /* using Wine name to ease things */ #define WINE_SHM_NAME "facetracknoir-wine-shm" #define WINE_MTX_NAME "facetracknoir-wine-mtx" |