From 7d0c58540103e9182ba584b440b91068df03a49c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 24 Jul 2015 14:08:44 +0200 Subject: standardize on not using "using namespace {cv,std}" --- ftnoir_tracker_pt/camera.cpp | 10 ++-- ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 17 +++---- ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp | 2 - ftnoir_tracker_pt/point_extractor.cpp | 40 +++++++--------- ftnoir_tracker_pt/point_tracker.cpp | 65 ++++++++++++-------------- ftnoir_tracker_pt/pt_video_widget.cpp | 3 -- ftnoir_tracker_pt/trans_calib.cpp | 17 +++---- 7 files changed, 67 insertions(+), 87 deletions(-) (limited to 'ftnoir_tracker_pt') diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 2989c1fe..4619f695 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -10,8 +10,6 @@ #include #include "opentrack/sleep.hpp" -using namespace cv; - void Camera::set_device_index(int index) { if (desired_index != index) @@ -74,7 +72,7 @@ void CVCamera::start() { if (cap) delete cap; - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); _set_res(); _set_fps(); // extract camera info @@ -103,11 +101,11 @@ void CVCamera::stop() active = false; } -bool CVCamera::_get_frame(Mat* frame) +bool CVCamera::_get_frame(cv::Mat* frame) { if (cap && cap->isOpened()) { - Mat img; + cv::Mat img; for (int i = 0; i < 100 && !cap->read(img); i++) ;; @@ -142,5 +140,5 @@ void CVCamera::_set_device_index() cap->release(); delete cap; } - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); } diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 07370f84..d3b43503 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -13,9 +13,6 @@ #include #include "opentrack/camera-names.hpp" -using namespace std; -using namespace cv; - //#define PT_PERF_LOG //log performance //----------------------------------------------------------------------------- @@ -101,7 +98,7 @@ void Tracker_PT::run() { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below + 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 Affine X_GH = X_CM * X_MH; cv::Vec3f p = X_GH.t; // head (center?) position in global space float fx = get_focal_length(); @@ -171,17 +168,17 @@ void Tracker_PT::data(double *data) { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); + 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; - Matx33f R = X_GH.R; - Vec3f t = X_GH.t; + 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 - Matx33f R_EG(0, 0,-1, - -1, 0, 0, - 0, 1, 0); + cv::Matx33f R_EG(0, 0,-1, + -1, 0, 0, + 0, 1, 0); R = R_EG * R * R_EG.t(); // extract rotation angles diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp index 9fdab441..07ee4f1b 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp @@ -14,8 +14,6 @@ #include "opentrack/camera-names.hpp" #include -using namespace std; - //----------------------------------------------------------------------------- TrackerDialog_PT::TrackerDialog_PT() : tracker(NULL), 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 PointExtractor::extract_points(Mat& frame) +std::vector 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 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 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> contours; @@ -211,19 +207,19 @@ std::vector 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 channels_; + std::vector channels_; cv::split(frame, channels_); // draw output image - Mat frame_bin_ = frame_bin * .5; - vector channels; + cv::Mat frame_bin_ = frame_bin * .5; + std::vector 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; } diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index b4283d37..d7adc09c 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -13,46 +13,43 @@ #include -using namespace cv; -using namespace std; - const float PI = 3.14159265358979323846f; // ---------------------------------------------------------------------------- -static void get_row(const Matx33f& m, int i, Vec3f& v) +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); } -static void set_row(Matx33f& m, int i, const Vec3f& v) +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]; } -static bool d_vals_sort(const pair a, const pair b) +static bool d_vals_sort(const std::pair a, const std::pair b) { return a.first < b.first; } void PointModel::get_d_order(const std::vector& points, int d_order[], cv::Vec2f d) const { - // fit line to orthographically projected points - vector< pair > d_vals; + // fit line to orthographically projected points + std::vector> d_vals; // get sort indices with respect to d scalar product - for (unsigned i = 0; i(d.dot(points[i]), i)); + for (unsigned i = 0; i(d.dot(points[i]), i)); std::sort(d_vals.begin(), d_vals.end(), d_vals_sort ); - for (unsigned i = 0; i& points, const PointModel& model, float f) +PointTracker::PointOrder PointTracker::find_correspondences_previous(const std::vector& points, const PointModel& model, float f) { PointTracker::PointOrder p; - p.points[0] = project(Vec3f(0,0,0), f); + p.points[0] = project(cv::Vec3f(0,0,0), f); p.points[1] = project(model.M01, f); p.points[2] = project(model.M02, f); @@ -79,7 +76,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto // find closest point to projected model point i for (int j=0; j& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) +void PointTracker::track(const std::vector& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) { PointOrder order; @@ -129,9 +126,9 @@ PointTracker::PointOrder PointTracker::find_correspondences(const std::vector { - Vec2f{0,0}, - Vec2f(model.M01[0], model.M01[1]), - Vec2f(model.M02[0], model.M02[1]) + cv::Vec2f{0,0}, + cv::Vec2f(model.M01[0], model.M01[1]), + cv::Vec2f(model.M02[0], model.M02[1]) }, model_d_order, d); @@ -151,10 +148,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // The expected rotation used for resolving the ambiguity in POSIT: // In every iteration step the rotation closer to R_expected is taken - Matx33f R_expected = Matx33f::eye(); + cv::Matx33f R_expected = cv::Matx33f::eye(); // initial pose = last (predicted) pose - Vec3f k; + cv::Vec3f k; get_row(R_expected, 2, k); float Z0 = 1000.f; @@ -163,17 +160,17 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float epsilon_1 = 1; float epsilon_2 = 1; - Vec3f I0, J0; - Vec2f I0_coeff, J0_coeff; + cv::Vec3f I0, J0; + cv::Vec2f I0_coeff, J0_coeff; - Vec3f I_1, J_1, I_2, J_2; - Matx33f R_1, R_2; - Matx33f* R_current; + 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; + const cv::Vec2f* order = order_.points; int i=1; for (; i and - Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], - order[2][0]*(1.0 + epsilon_2) - order[0][0]); - Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], - order[2][1]*(1.0 + epsilon_2) - order[0][1]); + 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; @@ -236,8 +233,8 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // pick the rotation solution closer to the expected one // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = norm(Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = norm(Matx33f::eye() - R_expected * R_2.t()); + float R_1_deviation = norm(cv::Matx33f::eye() - R_expected * R_1.t()); + float R_2_deviation = norm(cv::Matx33f::eye() - R_expected * R_2.t()); if (R_1_deviation < R_2_deviation) R_current = &R_1; @@ -259,7 +256,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float X_CM.t[1] = order[0][1] * Z0/focal_length; X_CM.t[2] = Z0; - //qDebug() << "iter:" << i; + //qDebug() << "iter:" << i; return i; } diff --git a/ftnoir_tracker_pt/pt_video_widget.cpp b/ftnoir_tracker_pt/pt_video_widget.cpp index 15fc5a86..9f2b90f6 100644 --- a/ftnoir_tracker_pt/pt_video_widget.cpp +++ b/ftnoir_tracker_pt/pt_video_widget.cpp @@ -9,9 +9,6 @@ #include "pt_video_widget.h" -using namespace cv; -using namespace std; - void PTVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_pt/trans_calib.cpp b/ftnoir_tracker_pt/trans_calib.cpp index 2994eb48..a1a4b641 100644 --- a/ftnoir_tracker_pt/trans_calib.cpp +++ b/ftnoir_tracker_pt/trans_calib.cpp @@ -7,9 +7,6 @@ #include "trans_calib.h" -using namespace cv; - -//----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { reset(); @@ -17,13 +14,13 @@ TranslationCalibrator::TranslationCalibrator() void TranslationCalibrator::reset() { - P = Matx66f::zeros(); - y = Vec6f(0,0,0, 0,0,0); + P = cv::Matx66f::zeros(); + y = cv::Vec6f(0,0,0, 0,0,0); } -void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) +void TranslationCalibrator::update(const cv::Matx33f& R_CM_k, const cv::Vec3f& t_CM_k) { - Matx H_k_T = Matx::zeros(); + cv::Matx H_k_T = cv::Matx::zeros(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { H_k_T(i,j) = R_CM_k(j,i); @@ -37,8 +34,8 @@ void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) y += H_k_T * t_CM_k; } -Vec3f TranslationCalibrator::get_estimate() +cv::Vec3f TranslationCalibrator::get_estimate() { - Vec6f x = P.inv() * y; - return Vec3f(-x[0], -x[1], -x[2]); + cv::Vec6f x = P.inv() * y; + return cv::Vec3f(-x[0], -x[1], -x[2]); } -- cgit v1.2.3 From b6a13399604b6069054faf6f3d4c481f949473d4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Jul 2015 05:26:39 +0200 Subject: fix integral/float confusion --- ftnoir_tracker_pt/point_tracker.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ftnoir_tracker_pt') diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index d7adc09c..cedf1979 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -196,7 +196,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float JJ0 = J0.dot(J0); float rho, theta; if (JJ0 == II0) { - rho = sqrt(abs(2*IJ0)); + rho = std::sqrt(std::abs(2*IJ0)); theta = -PI/4; if (IJ0<0) theta *= -1; } @@ -214,7 +214,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float J_1 = J0 + rho*sin(theta)*model.u; J_2 = J0 - rho*sin(theta)*model.u; - float norm_const = 1.0/norm(I_1); // all have the same norm + 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; @@ -233,8 +233,8 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // pick the rotation solution closer to the expected one // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = norm(cv::Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = norm(cv::Matx33f::eye() - R_expected * R_2.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; @@ -244,7 +244,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float get_row(*R_current, 2, k); // check for convergence condition - if (abs(epsilon_1 - old_epsilon_1) + abs(epsilon_2 - old_epsilon_2) < EPS_THRESHOLD) + 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; -- cgit v1.2.3 From 24538cf3a3a91481851618791b11be81437563e4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik 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') 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 - - * 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 -#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 - - * 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 -#else -#include -#include -#include -#include -#include -#include -#include -#include -#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 -IDI_ICON1 ICON "facetracknoir.ico" +#include +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 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 #include #include -#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 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + 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 #include #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 #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 #include #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 #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 #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 #include -#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 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 #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 #endif #include -#include "opentrack/timer.hpp" +#include "opentrack-compat/timer.hpp" #include "ftnoir_tracker_pt_settings.h" #include 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 + +class MyMutex { +private: + QMutex inner; + +public: + QMutex* operator->() { return &inner; } + QMutex* operator->() const { return &const_cast(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 + + * 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 +#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 + + * 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 +#else +#include +#include +#include +#include +#include +#include +#include +#include +#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 + + template + void sleep(unsigned milliseconds) + { + Sleep(milliseconds); + } +#else + #include + + template + 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 + + * 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 +#if defined (_WIN32) +# include +# 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 +# include +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 #include #include @@ -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 -#include -#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 - -class MyMutex { -private: - QMutex inner; - -public: - QMutex* operator->() { return &inner; } - QMutex* operator->() const { return &const_cast(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 - - template - void sleep(unsigned milliseconds) - { - Sleep(milliseconds); - } -#else - #include - - template - 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 - - * 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 -#if defined (_WIN32) -# include -# 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 -# include -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 -#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 #include +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 #include #include -#include "opentrack/qcopyable-mutex.hpp" +#include "opentrack-compat/qcopyable-mutex.hpp" class Map { private: -- cgit v1.2.3