From 7d0c58540103e9182ba584b440b91068df03a49c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik <sthalik@misaki.pl> Date: Fri, 24 Jul 2015 14:08:44 +0200 Subject: standardize on not using "using namespace {cv,std}" --- ftnoir_tracker_pt/point_extractor.cpp | 40 ++++++++++++++++------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'ftnoir_tracker_pt/point_extractor.cpp') diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index e81e3aa0..4791dcc2 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -12,10 +12,6 @@ # include "opentrack/timer.hpp" #endif -using namespace cv; -using namespace std; - - PointExtractor::PointExtractor(){ //if (!AllocConsole()){} //else SetConsoleTitle("debug"); @@ -23,20 +19,20 @@ PointExtractor::PointExtractor(){ //freopen("CON", "w", stderr); } // ---------------------------------------------------------------------------- -std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) +std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) { - const int W = frame.cols; - const int H = frame.rows; + const int W = frame.cols; + const int H = frame.rows; + + // convert to grayscale + cv::Mat frame_gray; + cv::cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - // convert to grayscale - Mat frame_gray; - cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - int min_size = s.min_point_size; int max_size = s.max_point_size; - unsigned int region_size_min = 3.14*min_size*min_size/4.0; - unsigned int region_size_max = 3.14*max_size*max_size/4.0; + unsigned int region_size_min = 3.14*min_size*min_size/4.0; + unsigned int region_size_max = 3.14*max_size*max_size/4.0; // testing indicates threshold difference of 45 from lowest to highest // that's applicable to poor lighting conditions. @@ -144,7 +140,7 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) }; // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) - Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); + cv::Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); const int min = std::max(0, thres - diff/2); const int max = std::min(255, thres + diff/2); @@ -155,8 +151,8 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) // this code is based on OpenCV SimpleBlobDetector for (int i = min; i < max; i += step) { - Mat frame_bin_; - threshold(frame_gray, frame_bin_, i, 255, THRESH_BINARY); + cv::Mat frame_bin_; + cv::threshold(frame_gray, frame_bin_, i, 255, cv::THRESH_BINARY); frame_bin.setTo(170, frame_bin_); std::vector<std::vector<cv::Point>> contours; @@ -211,19 +207,19 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) for (auto& b : simple_blob::merge(blobs)) { auto pos = b.effective_pos(); - Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); + cv::Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); points.push_back(p); } - vector<Mat> channels_; + std::vector<cv::Mat> channels_; cv::split(frame, channels_); // draw output image - Mat frame_bin_ = frame_bin * .5; - vector<Mat> channels; + cv::Mat frame_bin_ = frame_bin * .5; + std::vector<cv::Mat> channels; channels.push_back(channels_[0] + frame_bin_); channels.push_back(channels_[1] - frame_bin_); channels.push_back(channels_[2] - frame_bin_); - merge(channels, frame); + cv::merge(channels, frame); - return points; + return points; } -- cgit v1.2.3 From 24538cf3a3a91481851618791b11be81437563e4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik <sthalik@misaki.pl> Date: Sat, 25 Jul 2015 07:27:03 +0200 Subject: move portability classes to compat library --- CMakeLists.txt | 25 +++---- compat/compat.cpp | 81 ---------------------- compat/compat.h | 37 ---------- facetracknoir/facetracknoir.rc | 4 +- ftnoir_filter_accela/ftnoir_filter_accela.h | 2 +- ftnoir_protocol_ft/ftnoir_protocol_ft.h | 2 +- ftnoir_protocol_sc/scserver.manifest | 26 +++---- ftnoir_protocol_wine/ftnoir_protocol_wine.h | 2 +- .../opentrack-wrapper-wine-main.cxx | 4 +- .../opentrack-wrapper-wine-posix.cxx | 4 +- .../opentrack-wrapper-wine-windows.cxx | 4 +- ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.cpp | 2 +- ftnoir_tracker_ht/ftnoir_tracker_ht.h | 2 +- ftnoir_tracker_pt/camera.cpp | 2 +- ftnoir_tracker_pt/ftnoir_tracker_pt.h | 2 +- ftnoir_tracker_pt/point_extractor.cpp | 2 +- ftnoir_tracker_pt/point_tracker.h | 2 +- opentrack-compat/export.hpp | 13 ++++ opentrack-compat/mingw-version-script.txt | 8 +++ opentrack-compat/posix-version-script.txt | 8 +++ opentrack-compat/qcopyable-mutex.hpp | 37 ++++++++++ opentrack-compat/shm.cpp | 81 ++++++++++++++++++++++ opentrack-compat/shm.h | 37 ++++++++++ opentrack-compat/sleep.hpp | 22 ++++++ opentrack-compat/timer.hpp | 75 ++++++++++++++++++++ opentrack/export.hpp | 13 ---- opentrack/mingw-version-script.txt | 8 --- opentrack/plugin-api.hpp | 4 +- opentrack/pose.hpp | 22 ------ opentrack/posix-version-script.txt | 8 --- opentrack/qcopyable-mutex.hpp | 37 ---------- opentrack/sleep.hpp | 22 ------ opentrack/timer.hpp | 75 -------------------- opentrack/tracker.h | 20 +++++- opentrack/version.cc | 2 +- qfunctionconfigurator/functionconfig.h | 2 +- 37 files changed, 347 insertions(+), 352 deletions(-) delete mode 100644 compat/compat.cpp delete mode 100644 compat/compat.h create mode 100644 opentrack-compat/export.hpp create mode 100644 opentrack-compat/mingw-version-script.txt create mode 100644 opentrack-compat/posix-version-script.txt create mode 100644 opentrack-compat/qcopyable-mutex.hpp create mode 100644 opentrack-compat/shm.cpp create mode 100644 opentrack-compat/shm.h create mode 100644 opentrack-compat/sleep.hpp create mode 100644 opentrack-compat/timer.hpp delete mode 100644 opentrack/export.hpp delete mode 100644 opentrack/mingw-version-script.txt delete mode 100644 opentrack/pose.hpp delete mode 100644 opentrack/posix-version-script.txt delete mode 100644 opentrack/qcopyable-mutex.hpp delete mode 100644 opentrack/sleep.hpp delete mode 100644 opentrack/timer.hpp (limited to 'ftnoir_tracker_pt/point_extractor.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6be4e425..e6a3afc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,10 +112,10 @@ macro(opentrack_library n dir) set(link-mode STATIC) endif() add_library(${n} ${link-mode} ${${n}-all}) - target_link_libraries(${n} opentrack-api ${MY_QT_LIBS}) + target_link_libraries(${n} opentrack-api ${MY_QT_LIBS} opentrack-compat) if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE) SET_TARGET_PROPERTIES(${n} PROPERTIES - LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack/${version-script}-version-script.txt\"" + LINK_FLAGS "${foolib_LINK} ${foolib_GNU-LINK} -Wl,--as-needed -Wl,--version-script=\"${CMAKE_SOURCE_DIR}/opentrack-compat/${version-script}-version-script.txt\"" COMPILE_FLAGS "${foolib_COMPILE} ${foolib_GNU-COMPILE} -fvisibility=hidden -fvisibility-inlines-hidden" ) else() @@ -125,7 +125,9 @@ macro(opentrack_library n dir) endif() set_target_properties(${n} PROPERTIES LINK_FLAGS "${link-flags} ${foolib_LINK}" COMPILE_FLAGS "${foolib_COMPILE}") endif() - install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + if(NOT foolib_STATIC) + install(TARGETS ${n} RUNTIME DESTINATION . LIBRARY DESTINATION .) + endif() endmacro() function(link_with_dinput8 n) @@ -194,13 +196,19 @@ opentrack_qt(opentrack-api) add_library(opentrack-api STATIC ${opentrack-api-all}) opentrack_compat(opentrack-api) target_link_libraries(opentrack-api ${MY_QT_LIBS}) - if(NOT WIN32) target_link_libraries(opentrack-api dl) else() target_link_libraries(opentrack-api winmm) endif() +opentrack_module(opentrack-compat opentrack-compat) +add_library(opentrack-compat STATIC ${opentrack-compat-c}) +opentrack_compat(opentrack-compat) # uh... +if(NOT WIN32 AND NOT APPLE) + target_link_libraries(opentrack-compat rt) +endif() + # ---- # conditional targets @@ -217,7 +225,6 @@ if(WIN32) ENABLE_LANGUAGE(RC) endif(WIN32) -opentrack_module(opentrack-compat compat) opentrack_module(opentrack-xplane-plugin x-plane-plugin) if(SDK_XPLANE) @@ -244,12 +251,6 @@ if(SDK_XPLANE) endif() endif() -add_library(opentrack-compat STATIC ${opentrack-compat-c}) -opentrack_compat(opentrack-compat) # uh... -if(NOT WIN32 AND NOT APPLE) - target_link_libraries(opentrack-compat rt) -endif() - opentrack_module(opentrack-csv csv) add_library(opentrack-csv STATIC ${opentrack-csv-c}) opentrack_compat(opentrack-csv) @@ -377,7 +378,7 @@ if(OpenCV_FOUND) if(SDK_HT AND SDK_HT_FLANDMARK) opentrack_library(opentrack-tracker-ht ftnoir_tracker_ht) - target_link_libraries(opentrack-tracker-ht opentrack-compat ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS}) + target_link_libraries(opentrack-tracker-ht ${SDK_HT} ${SDK_HT_FLANDMARK} ${OpenCV_LIBS}) link_with_dinput8(opentrack-tracker-ht) target_include_directories(opentrack-tracker-ht SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS}) endif() diff --git a/compat/compat.cpp b/compat/compat.cpp deleted file mode 100644 index 9000b453..00000000 --- a/compat/compat.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (c) 2013 Stanisław 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 <cstring> -#include "compat.h" - -#if defined(_WIN32) -PortableLockedShm::PortableLockedShm(const char* shmName, const char* mutexName, int mapSize) -{ - hMutex = CreateMutexA(NULL, false, mutexName); - hMapFile = CreateFileMappingA( - INVALID_HANDLE_VALUE, - NULL, - PAGE_READWRITE, - 0, - mapSize, - shmName); - mem = MapViewOfFile(hMapFile, - FILE_MAP_WRITE, - 0, - 0, - mapSize); -} - -PortableLockedShm::~PortableLockedShm() -{ - UnmapViewOfFile(mem); - CloseHandle(hMapFile); - CloseHandle(hMutex); -} - -void PortableLockedShm::lock() -{ - (void) WaitForSingleObject(hMutex, INFINITE); -} - -void PortableLockedShm::unlock() -{ - (void) ReleaseMutex(hMutex); -} -#else -#pragma GCC diagnostic ignored "-Wunused-result" -PortableLockedShm::PortableLockedShm(const char *shmName, const char* /*mutexName*/, int mapSize) : size(mapSize) -{ - char filename[512] = {0}; - strcpy(filename, "/"); - strcat(filename, shmName); - fd = shm_open(filename, O_RDWR | O_CREAT, 0600); - (void) ftruncate(fd, mapSize); - mem = mmap(NULL, mapSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0); -} - -PortableLockedShm::~PortableLockedShm() -{ - (void) munmap(mem, size); - (void) close(fd); -} - -void PortableLockedShm::lock() -{ - flock(fd, LOCK_EX); -} - -void PortableLockedShm::unlock() -{ - flock(fd, LOCK_UN); -} -#endif - -bool PortableLockedShm::success() -{ -#ifndef _WIN32 - return (void*) mem != (void*) -1; -#else - return (void*) mem != NULL; -#endif -} diff --git a/compat/compat.h b/compat/compat.h deleted file mode 100644 index 17a0d843..00000000 --- a/compat/compat.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (c) 2013 Stanisław 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 - -#if defined(_WIN32) -#include <windows.h> -#else -#include <stdio.h> -#include <string.h> -#include <sys/file.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <limits.h> -#include <unistd.h> -#include <sys/types.h> -#endif - -class PortableLockedShm { -public: - PortableLockedShm(const char *shmName, const char *mutexName, int mapSize); - ~PortableLockedShm(); - void lock(); - void unlock(); - bool success(); - inline void* ptr() { return mem; } -private: - void* mem; -#if defined(_WIN32) - HANDLE hMutex, hMapFile; -#else - int fd, size; -#endif -}; diff --git a/facetracknoir/facetracknoir.rc b/facetracknoir/facetracknoir.rc index 655baa9d..020ffe97 100644 --- a/facetracknoir/facetracknoir.rc +++ b/facetracknoir/facetracknoir.rc @@ -1,2 +1,2 @@ -#include <windows.h> -IDI_ICON1 ICON "facetracknoir.ico" +#include <windows.h> +IDI_ICON1 ICON "facetracknoir.ico" diff --git a/ftnoir_filter_accela/ftnoir_filter_accela.h b/ftnoir_filter_accela/ftnoir_filter_accela.h index 54845bfe..318cf909 100644 --- a/ftnoir_filter_accela/ftnoir_filter_accela.h +++ b/ftnoir_filter_accela/ftnoir_filter_accela.h @@ -14,7 +14,7 @@ #include "opentrack/options.hpp" using namespace options; -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" struct settings_accela : opts { value<int> rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; diff --git a/ftnoir_protocol_ft/ftnoir_protocol_ft.h b/ftnoir_protocol_ft/ftnoir_protocol_ft.h index f80a511b..6010de90 100644 --- a/ftnoir_protocol_ft/ftnoir_protocol_ft.h +++ b/ftnoir_protocol_ft/ftnoir_protocol_ft.h @@ -44,7 +44,7 @@ #include <QString> #include <QMutex> #include <QMutexLocker> -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "opentrack/options.hpp" #include "freetrackclient/fttypes.h" using namespace options; diff --git a/ftnoir_protocol_sc/scserver.manifest b/ftnoir_protocol_sc/scserver.manifest index 60311d6e..d342cfda 100644 --- a/ftnoir_protocol_sc/scserver.manifest +++ b/ftnoir_protocol_sc/scserver.manifest @@ -1,13 +1,13 @@ -<?xml version='1.0' encoding='UTF-8' standalone='yes'?> -<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> - <dependency> - <dependentAssembly> - <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect' version='10.0.61259.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' /> - </dependentAssembly> - </dependency> - <dependency> - <dependentAssembly> - <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> - </dependentAssembly> - </dependency> -</assembly> +<?xml version='1.0' encoding='UTF-8' standalone='yes'?> +<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.FlightSimulator.SimConnect' version='10.0.61259.0' processorArchitecture='x86' publicKeyToken='67c7c14424d61b5b' /> + </dependentAssembly> + </dependency> + <dependency> + <dependentAssembly> + <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' /> + </dependentAssembly> + </dependency> +</assembly> diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine.h b/ftnoir_protocol_wine/ftnoir_protocol_wine.h index 528c4dd3..72897f1f 100644 --- a/ftnoir_protocol_wine/ftnoir_protocol_wine.h +++ b/ftnoir_protocol_wine/ftnoir_protocol_wine.h @@ -9,7 +9,7 @@ #include <QMutexLocker> #include <QFile> #include "opentrack/plugin-api.hpp" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include "ftnoir_protocol_wine/wine-shm.h" class FTNoIR_Protocol : public IProtocol diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx index 026135f0..ffe8938d 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx @@ -6,13 +6,13 @@ #include <cstdio> #include "freetrackclient/fttypes.h" #include "ftnoir_protocol_wine/wine-shm.h" -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" enum Axis { TX = 0, TY, TZ, Yaw, Pitch, Roll }; -#include "compat/compat.h" +#include "opentrack-compat/shm.h" void create_registry_key(void); diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx index 6f43f899..50cce728 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx @@ -3,5 +3,5 @@ #endif #define PortableLockedShm ShmPosix -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx index 6592fbe6..19ee8ffd 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx @@ -3,8 +3,8 @@ #endif #define PortableLockedShm ShmWine -#include "compat/compat.h" -#include "compat/compat.cpp" +#include "opentrack-compat/shm.h" +#include "opentrack-compat/shm.cpp" #include "wine-shm.h" static void write_path(const char* key, const char* subkey) diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp index 05f3e3a4..08ddd3b2 100644 --- a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp +++ b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp @@ -17,7 +17,7 @@ #include <opencv2/highgui/highgui.hpp> #include <opencv2/videoio.hpp> #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp index ad13d716..cc9d2ba1 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.cpp @@ -4,7 +4,7 @@ #include "opentrack/plugin-api.hpp" #include <cmath> #include "opentrack/camera-names.hpp" -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" typedef struct { int width; diff --git a/ftnoir_tracker_ht/ftnoir_tracker_ht.h b/ftnoir_tracker_ht/ftnoir_tracker_ht.h index 32fb6949..16fdbe5c 100644 --- a/ftnoir_tracker_ht/ftnoir_tracker_ht.h +++ b/ftnoir_tracker_ht/ftnoir_tracker_ht.h @@ -10,7 +10,7 @@ #include "headtracker-ftnoir.h" #include "ui_ht-trackercontrols.h" #include "ht_video_widget.h" -#include "compat/compat.h" +#include "opentrack-compat/shm.h" #include <QObject> #include "opentrack/options.hpp" #include "opentrack/plugin-api.hpp" diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 4619f695..9e11b815 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -8,7 +8,7 @@ #include "camera.h" #include <string> #include <QDebug> -#include "opentrack/sleep.hpp" +#include "opentrack-compat/sleep.hpp" void Camera::set_device_index(int index) { diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.h b/ftnoir_tracker_pt/ftnoir_tracker_pt.h index b303a913..3291c7fc 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.h +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.h @@ -14,7 +14,7 @@ #include "point_extractor.h" #include "point_tracker.h" #include "pt_video_widget.h" -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "opentrack/opencv-camera-dialog.hpp" #include <QThread> diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index 4791dcc2..7174d719 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -9,7 +9,7 @@ #include <QDebug> #ifdef DEBUG_EXTRACTION -# include "opentrack/timer.hpp" +# include "opentrack-compat/timer.hpp" #endif PointExtractor::PointExtractor(){ diff --git a/ftnoir_tracker_pt/point_tracker.h b/ftnoir_tracker_pt/point_tracker.h index 7c710704..323eade4 100644 --- a/ftnoir_tracker_pt/point_tracker.h +++ b/ftnoir_tracker_pt/point_tracker.h @@ -15,7 +15,7 @@ # include <memory> #endif #include <vector> -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "ftnoir_tracker_pt_settings.h" #include <QObject> diff --git a/opentrack-compat/export.hpp b/opentrack-compat/export.hpp new file mode 100644 index 00000000..f0983b75 --- /dev/null +++ b/opentrack-compat/export.hpp @@ -0,0 +1,13 @@ +#pragma once + +#ifdef _WIN32 +# define OPENTRACK_LINKAGE __declspec(dllexport) +#else +# define OPENTRACK_LINKAGE +#endif + +#ifndef _MSC_VER +# define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE +#else +# define OPENTRACK_EXPORT OPENTRACK_LINKAGE +#endif \ No newline at end of file diff --git a/opentrack-compat/mingw-version-script.txt b/opentrack-compat/mingw-version-script.txt new file mode 100644 index 00000000..fe20ad37 --- /dev/null +++ b/opentrack-compat/mingw-version-script.txt @@ -0,0 +1,8 @@ +{ + global: + GetDialog?0; + GetConstructor?0; + GetMetadata?0; + local: + *; +}; diff --git a/opentrack-compat/posix-version-script.txt b/opentrack-compat/posix-version-script.txt new file mode 100644 index 00000000..97edb9aa --- /dev/null +++ b/opentrack-compat/posix-version-script.txt @@ -0,0 +1,8 @@ +{ + global: + GetDialog; + GetConstructor; + GetMetadata; + local: + *; +}; \ No newline at end of file diff --git a/opentrack-compat/qcopyable-mutex.hpp b/opentrack-compat/qcopyable-mutex.hpp new file mode 100644 index 00000000..f7f36f93 --- /dev/null +++ b/opentrack-compat/qcopyable-mutex.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <QMutex> + +class MyMutex { +private: + QMutex inner; + +public: + QMutex* operator->() { return &inner; } + QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; } + + MyMutex operator=(const MyMutex& datum) + { + auto mode = + datum->isRecursive() + ? QMutex::Recursive + : QMutex::NonRecursive; + + return MyMutex(mode); + } + + MyMutex(const MyMutex& datum) + { + *this = datum; + } + + MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) : + inner(mode) + { + } + + QMutex* operator&() + { + return &inner; + } +}; diff --git a/opentrack-compat/shm.cpp b/opentrack-compat/shm.cpp new file mode 100644 index 00000000..b18a9933 --- /dev/null +++ b/opentrack-compat/shm.cpp @@ -0,0 +1,81 @@ +/* Copyright (c) 2013 Stanisław 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 <cstring> +#include "shm.h" + +#if defined(_WIN32) +PortableLockedShm::PortableLockedShm(const char* shmName, const char* mutexName, int mapSize) +{ + hMutex = CreateMutexA(NULL, false, mutexName); + hMapFile = CreateFileMappingA( + INVALID_HANDLE_VALUE, + NULL, + PAGE_READWRITE, + 0, + mapSize, + shmName); + mem = MapViewOfFile(hMapFile, + FILE_MAP_WRITE, + 0, + 0, + mapSize); +} + +PortableLockedShm::~PortableLockedShm() +{ + UnmapViewOfFile(mem); + CloseHandle(hMapFile); + CloseHandle(hMutex); +} + +void PortableLockedShm::lock() +{ + (void) WaitForSingleObject(hMutex, INFINITE); +} + +void PortableLockedShm::unlock() +{ + (void) ReleaseMutex(hMutex); +} +#else +#pragma GCC diagnostic ignored "-Wunused-result" +PortableLockedShm::PortableLockedShm(const char *shmName, const char* /*mutexName*/, int mapSize) : size(mapSize) +{ + char filename[512] = {0}; + strcpy(filename, "/"); + strcat(filename, shmName); + fd = shm_open(filename, O_RDWR | O_CREAT, 0600); + (void) ftruncate(fd, mapSize); + mem = mmap(NULL, mapSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (off_t)0); +} + +PortableLockedShm::~PortableLockedShm() +{ + (void) munmap(mem, size); + (void) close(fd); +} + +void PortableLockedShm::lock() +{ + flock(fd, LOCK_EX); +} + +void PortableLockedShm::unlock() +{ + flock(fd, LOCK_UN); +} +#endif + +bool PortableLockedShm::success() +{ +#ifndef _WIN32 + return (void*) mem != (void*) -1; +#else + return (void*) mem != NULL; +#endif +} diff --git a/opentrack-compat/shm.h b/opentrack-compat/shm.h new file mode 100644 index 00000000..17a0d843 --- /dev/null +++ b/opentrack-compat/shm.h @@ -0,0 +1,37 @@ +/* Copyright (c) 2013 Stanisław 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 + +#if defined(_WIN32) +#include <windows.h> +#else +#include <stdio.h> +#include <string.h> +#include <sys/file.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <limits.h> +#include <unistd.h> +#include <sys/types.h> +#endif + +class PortableLockedShm { +public: + PortableLockedShm(const char *shmName, const char *mutexName, int mapSize); + ~PortableLockedShm(); + void lock(); + void unlock(); + bool success(); + inline void* ptr() { return mem; } +private: + void* mem; +#if defined(_WIN32) + HANDLE hMutex, hMapFile; +#else + int fd, size; +#endif +}; diff --git a/opentrack-compat/sleep.hpp b/opentrack-compat/sleep.hpp new file mode 100644 index 00000000..27920842 --- /dev/null +++ b/opentrack-compat/sleep.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace portable +{ +#ifdef _WIN32 + #include <windows.h> + + template<typename = void> + void sleep(unsigned milliseconds) + { + Sleep(milliseconds); + } +#else + #include <unistd.h> + + template<typename = void> + void sleep(unsigned milliseconds) + { + usleep(milliseconds * 1000U); // takes microseconds + } +#endif +} diff --git a/opentrack-compat/timer.hpp b/opentrack-compat/timer.hpp new file mode 100644 index 00000000..fd710499 --- /dev/null +++ b/opentrack-compat/timer.hpp @@ -0,0 +1,75 @@ +/* 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 copyright notice and this permission + * notice appear in all copies. + */ + +#pragma once +#include <ctime> +#if defined (_WIN32) +# include <windows.h> +# ifndef CLOCK_MONOTONIC +# define CLOCK_MONOTONIC -1 +# endif +static inline void opentrack_clock_gettime(int, struct timespec* ts) +{ + static LARGE_INTEGER freq; + + if (!freq.QuadPart) + (void) QueryPerformanceFrequency(&freq); + + LARGE_INTEGER d; + + (void) QueryPerformanceCounter(&d); + + d.QuadPart *= 1000000000L; + d.QuadPart /= freq.QuadPart; + + ts->tv_sec = d.QuadPart / 1000000000L; + ts->tv_nsec = d.QuadPart % 1000000000L; +} +# define clock_gettime opentrack_clock_gettime +#else +# if defined(__MACH__) +# define CLOCK_MONOTONIC 0 +# include <inttypes.h> +# include <mach/mach_time.h> +static inline void clock_gettime(int, struct timespec* ts) +{ + static mach_timebase_info_data_t sTimebaseInfo; + uint64_t state, nsec; + if ( sTimebaseInfo.denom == 0 ) { + (void) mach_timebase_info(&sTimebaseInfo); + } + state = mach_absolute_time(); + nsec = state * sTimebaseInfo.numer / sTimebaseInfo.denom; + ts->tv_sec = nsec / 1000000000L; + ts->tv_nsec = nsec % 1000000000L; +} +# endif +#endif +class Timer { +private: + struct timespec state; + long conv(const struct timespec& cur) + { + return (cur.tv_sec - state.tv_sec) * 1000000000L + (cur.tv_nsec - state.tv_nsec); + } +public: + Timer() { + start(); + } + void start() { + (void) clock_gettime(CLOCK_MONOTONIC, &state); + } + long elapsed() { + struct timespec cur; + (void) clock_gettime(CLOCK_MONOTONIC, &cur); + return conv(cur); + } + long elapsed_ms() { + return elapsed() / 1000000L; + } +}; diff --git a/opentrack/export.hpp b/opentrack/export.hpp deleted file mode 100644 index f0983b75..00000000 --- a/opentrack/export.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#ifdef _WIN32 -# define OPENTRACK_LINKAGE __declspec(dllexport) -#else -# define OPENTRACK_LINKAGE -#endif - -#ifndef _MSC_VER -# define OPENTRACK_EXPORT __attribute__ ((visibility ("default"))) OPENTRACK_LINKAGE -#else -# define OPENTRACK_EXPORT OPENTRACK_LINKAGE -#endif \ No newline at end of file diff --git a/opentrack/mingw-version-script.txt b/opentrack/mingw-version-script.txt deleted file mode 100644 index fe20ad37..00000000 --- a/opentrack/mingw-version-script.txt +++ /dev/null @@ -1,8 +0,0 @@ -{ - global: - GetDialog?0; - GetConstructor?0; - GetMetadata?0; - local: - *; -}; diff --git a/opentrack/plugin-api.hpp b/opentrack/plugin-api.hpp index b0da4950..572b7f31 100644 --- a/opentrack/plugin-api.hpp +++ b/opentrack/plugin-api.hpp @@ -8,7 +8,7 @@ #pragma once -#include "export.hpp" +#include "../opentrack-compat/export.hpp" #include <QString> #include <QWidget> #include <QFrame> @@ -59,7 +59,7 @@ struct IFilter // optional destructor virtual ~IFilter() {} // perform filtering step. - // you have to take care of dt on your own, try "opentrack/timer.hpp" + // you have to take care of dt on your own, try "opentrack-compat/timer.hpp" virtual void filter(const double *input, double *output) = 0; }; diff --git a/opentrack/pose.hpp b/opentrack/pose.hpp deleted file mode 100644 index 93d467a9..00000000 --- a/opentrack/pose.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include <utility> -#include <algorithm> -#include "./plugin-api.hpp" - -class Pose { -private: - static constexpr double pi = 3.141592653; - static constexpr double d2r = pi/180.0; - static constexpr double r2d = 180./pi; - - double axes[6]; -public: - Pose() : axes {0,0,0, 0,0,0} {} - - inline operator double*() { return axes; } - inline operator const double*() const { return axes; } - - inline double& operator()(int i) { return axes[i]; } - inline double operator()(int i) const { return axes[i]; } -}; diff --git a/opentrack/posix-version-script.txt b/opentrack/posix-version-script.txt deleted file mode 100644 index 97edb9aa..00000000 --- a/opentrack/posix-version-script.txt +++ /dev/null @@ -1,8 +0,0 @@ -{ - global: - GetDialog; - GetConstructor; - GetMetadata; - local: - *; -}; \ No newline at end of file diff --git a/opentrack/qcopyable-mutex.hpp b/opentrack/qcopyable-mutex.hpp deleted file mode 100644 index f7f36f93..00000000 --- a/opentrack/qcopyable-mutex.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include <QMutex> - -class MyMutex { -private: - QMutex inner; - -public: - QMutex* operator->() { return &inner; } - QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; } - - MyMutex operator=(const MyMutex& datum) - { - auto mode = - datum->isRecursive() - ? QMutex::Recursive - : QMutex::NonRecursive; - - return MyMutex(mode); - } - - MyMutex(const MyMutex& datum) - { - *this = datum; - } - - MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) : - inner(mode) - { - } - - QMutex* operator&() - { - return &inner; - } -}; diff --git a/opentrack/sleep.hpp b/opentrack/sleep.hpp deleted file mode 100644 index 27920842..00000000 --- a/opentrack/sleep.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -namespace portable -{ -#ifdef _WIN32 - #include <windows.h> - - template<typename = void> - void sleep(unsigned milliseconds) - { - Sleep(milliseconds); - } -#else - #include <unistd.h> - - template<typename = void> - void sleep(unsigned milliseconds) - { - usleep(milliseconds * 1000U); // takes microseconds - } -#endif -} diff --git a/opentrack/timer.hpp b/opentrack/timer.hpp deleted file mode 100644 index fd710499..00000000 --- a/opentrack/timer.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* 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 copyright notice and this permission - * notice appear in all copies. - */ - -#pragma once -#include <ctime> -#if defined (_WIN32) -# include <windows.h> -# ifndef CLOCK_MONOTONIC -# define CLOCK_MONOTONIC -1 -# endif -static inline void opentrack_clock_gettime(int, struct timespec* ts) -{ - static LARGE_INTEGER freq; - - if (!freq.QuadPart) - (void) QueryPerformanceFrequency(&freq); - - LARGE_INTEGER d; - - (void) QueryPerformanceCounter(&d); - - d.QuadPart *= 1000000000L; - d.QuadPart /= freq.QuadPart; - - ts->tv_sec = d.QuadPart / 1000000000L; - ts->tv_nsec = d.QuadPart % 1000000000L; -} -# define clock_gettime opentrack_clock_gettime -#else -# if defined(__MACH__) -# define CLOCK_MONOTONIC 0 -# include <inttypes.h> -# include <mach/mach_time.h> -static inline void clock_gettime(int, struct timespec* ts) -{ - static mach_timebase_info_data_t sTimebaseInfo; - uint64_t state, nsec; - if ( sTimebaseInfo.denom == 0 ) { - (void) mach_timebase_info(&sTimebaseInfo); - } - state = mach_absolute_time(); - nsec = state * sTimebaseInfo.numer / sTimebaseInfo.denom; - ts->tv_sec = nsec / 1000000000L; - ts->tv_nsec = nsec % 1000000000L; -} -# endif -#endif -class Timer { -private: - struct timespec state; - long conv(const struct timespec& cur) - { - return (cur.tv_sec - state.tv_sec) * 1000000000L + (cur.tv_nsec - state.tv_nsec); - } -public: - Timer() { - start(); - } - void start() { - (void) clock_gettime(CLOCK_MONOTONIC, &state); - } - long elapsed() { - struct timespec cur; - (void) clock_gettime(CLOCK_MONOTONIC, &cur); - return conv(cur); - } - long elapsed_ms() { - return elapsed() / 1000000L; - } -}; diff --git a/opentrack/tracker.h b/opentrack/tracker.h index 453357c4..c5c39797 100644 --- a/opentrack/tracker.h +++ b/opentrack/tracker.h @@ -10,10 +10,9 @@ #include <vector> -#include "timer.hpp" +#include "opentrack-compat/timer.hpp" #include "plugin-support.hpp" #include "mappings.hpp" -#include "pose.hpp" #include "simple-mat.hpp" #include "selected-libraries.hpp" @@ -24,6 +23,23 @@ #include <QMutex> #include <QThread> +class Pose { +private: + static constexpr double pi = 3.141592653; + static constexpr double d2r = pi/180.0; + static constexpr double r2d = 180./pi; + + double axes[6]; +public: + Pose() : axes {0,0,0, 0,0,0} {} + + inline operator double*() { return axes; } + inline operator const double*() const { return axes; } + + inline double& operator()(int i) { return axes[i]; } + inline double operator()(int i) const { return axes[i]; } +}; + class Tracker : private QThread { Q_OBJECT private: diff --git a/opentrack/version.cc b/opentrack/version.cc index 026ad057..13bc5dc5 100644 --- a/opentrack/version.cc +++ b/opentrack/version.cc @@ -1,4 +1,4 @@ -#include "opentrack/export.hpp" +#include "opentrack-compat/export.hpp" #ifdef __cplusplus extern "C" diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h index 7ead2c5d..a8b46597 100644 --- a/qfunctionconfigurator/functionconfig.h +++ b/qfunctionconfigurator/functionconfig.h @@ -14,7 +14,7 @@ #include <QSettings> #include <QMutex> #include <vector> -#include "opentrack/qcopyable-mutex.hpp" +#include "opentrack-compat/qcopyable-mutex.hpp" class Map { private: -- cgit v1.2.3