diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-03 00:09:09 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-16 07:48:20 +0100 |
commit | 545071e998806235442edda5f575ee61e836abe9 (patch) | |
tree | 45579d717361f24c6f4a06354f5836447e691771 | |
parent | 4766be01022d6de50f7b42647299860c2d9909b8 (diff) |
cruft
-rw-r--r-- | compat/mutex.cpp | 10 | ||||
-rw-r--r-- | compat/mutex.hpp | 6 | ||||
-rw-r--r-- | cv/CMakeLists.txt | 2 | ||||
-rw-r--r-- | cv/numeric.hpp | 5 | ||||
-rw-r--r-- | cv/video-property-page.cpp | 3 | ||||
-rw-r--r-- | cv/video-property-page.hpp | 6 | ||||
-rw-r--r-- | options/base-value.cpp | 2 | ||||
-rw-r--r-- | options/base-value.hpp | 4 | ||||
-rw-r--r-- | options/value.hpp | 20 | ||||
-rw-r--r-- | proto-udp/ftnoir_protocol_ftn.cpp | 6 | ||||
-rw-r--r-- | proto-udp/ftnoir_protocol_ftn.h | 5 | ||||
-rw-r--r-- | sdk-paths-sthalik@Clang-windows.cmake | 3 | ||||
-rw-r--r-- | spline/spline-widget.cpp | 5 | ||||
-rw-r--r-- | spline/spline.cpp | 27 | ||||
-rw-r--r-- | tracker-aruco/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tracker-pt/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt.cpp | 2 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.cpp | 12 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.h | 2 | ||||
-rw-r--r-- | tracker-pt/point_tracker.cpp | 22 | ||||
-rw-r--r-- | tracker-pt/pt-api.cpp | 2 | ||||
-rw-r--r-- | tracker-wii/wii_point_extractor.cpp | 4 |
22 files changed, 78 insertions, 74 deletions
diff --git a/compat/mutex.cpp b/compat/mutex.cpp index 55789a22..664677ea 100644 --- a/compat/mutex.cpp +++ b/compat/mutex.cpp @@ -17,17 +17,17 @@ mutex::mutex(RecursionMode m) : inner{m} { } -QMutex* mutex::operator&() const +QMutex* mutex::operator&() const noexcept { - return *this; + return &inner; } -mutex::operator QMutex*() const +mutex::operator QMutex*() const noexcept { return &inner; } -QMutex* mutex::operator->() const +QMutex* mutex::operator->() const noexcept { - return *this; + return &inner; } diff --git a/compat/mutex.hpp b/compat/mutex.hpp index 37e6802b..e142fd0b 100644 --- a/compat/mutex.hpp +++ b/compat/mutex.hpp @@ -17,7 +17,7 @@ public: mutex(const mutex& datum); explicit mutex(RecursionMode m); - QMutex* operator&() const; - operator QMutex*() const; - QMutex* operator->() const; + QMutex* operator&() const noexcept; + explicit operator QMutex*() const noexcept; + QMutex* operator->() const noexcept; }; diff --git a/cv/CMakeLists.txt b/cv/CMakeLists.txt index 1007344c..60350a99 100644 --- a/cv/CMakeLists.txt +++ b/cv/CMakeLists.txt @@ -1,6 +1,6 @@ find_package(OpenCV QUIET) if(OpenCV_FOUND) otr_module(cv STATIC) - target_link_libraries(${self} opencv_core opencv_videoio) + target_link_libraries(${self} opencv_videoio opencv_core) target_include_directories(${self} SYSTEM PRIVATE ${OpenCV_INCLUDE_DIRS}) endif() diff --git a/cv/numeric.hpp b/cv/numeric.hpp index 0edb7f58..7d850cbe 100644 --- a/cv/numeric.hpp +++ b/cv/numeric.hpp @@ -5,9 +5,8 @@ namespace types { using f = double; - namespace constants { - static constexpr inline f eps = f(1e-8); - } + static constexpr inline f eps = f(1e-8); + static constexpr inline f pi = f(M_PI); template<int n> using vec = cv::Vec<f, n>; using vec2 = vec<2>; diff --git a/cv/video-property-page.cpp b/cv/video-property-page.cpp index 1b8b94cf..bae5e8b3 100644 --- a/cv/video-property-page.cpp +++ b/cv/video-property-page.cpp @@ -25,8 +25,6 @@ #include <QDebug> -#include <dshow.h> - bool video_property_page::show_from_capture(cv::VideoCapture& cap, int /*index */) { return cap.set(cv::CAP_PROP_SETTINGS, 0); @@ -165,4 +163,3 @@ bool video_property_page::show_from_capture(cv::VideoCapture&, int idx) bool video_property_page::show(int) { return false; } bool video_property_page::show_from_capture(cv::VideoCapture&, int) { return false; } #endif - diff --git a/cv/video-property-page.hpp b/cv/video-property-page.hpp index 9e6b596f..c2b9525d 100644 --- a/cv/video-property-page.hpp +++ b/cv/video-property-page.hpp @@ -1,11 +1,6 @@ #pragma once #include <QString> - -#ifdef _WIN32 -# include <windows.h> -#endif - #include <opencv2/videoio.hpp> struct video_property_page final @@ -15,3 +10,4 @@ struct video_property_page final static bool show_from_capture(cv::VideoCapture& cap, int index); private: }; + diff --git a/options/base-value.cpp b/options/base-value.cpp index be18bbfd..39453a09 100644 --- a/options/base-value.cpp +++ b/options/base-value.cpp @@ -2,7 +2,7 @@ using namespace options; -value_::value_(bundle const& b, const QString& name) : +value_::value_(bundle const& b, const QString& name) noexcept : b(b), self_name(name) { b->on_value_created(this); diff --git a/options/base-value.hpp b/options/base-value.hpp index 7baff0b3..11d17c00 100644 --- a/options/base-value.hpp +++ b/options/base-value.hpp @@ -31,7 +31,7 @@ class OTR_OPTIONS_EXPORT value_ : public QObject public: QString name() const { return self_name; } - value_(bundle const& b, const QString& name); + value_(bundle const& b, const QString& name) noexcept; ~value_() override; // no C++17 "constexpr inline" for data declarations in MSVC @@ -63,7 +63,7 @@ protected: bundle b; QString self_name; - virtual void store_variant(const QVariant& x) = 0; + virtual void store_variant(const QVariant& x) noexcept = 0; template<typename t> void store_(const t& datum) diff --git a/options/value.hpp b/options/value.hpp index 6714d50d..64234ecf 100644 --- a/options/value.hpp +++ b/options/value.hpp @@ -44,7 +44,7 @@ class value final : public value_ using traits = detail::value_traits<t>; cc_noinline - t get() const + t get() const noexcept { if (self_name.isEmpty() || !b->contains(self_name)) return traits::pass_value(def); @@ -57,7 +57,8 @@ class value final : public value_ return traits::pass_value(traits::value_with_default(traits::value_from_qvariant(variant), def)); } - void store_variant(const QVariant& value) override + cc_noinline + void store_variant(const QVariant& value) noexcept override { if (self_name.isEmpty()) return; @@ -78,7 +79,7 @@ public: emit valueChanged(traits::storage_from_value(get())); } - value<u>& operator=(const t& datum) + value<u>& operator=(const t& datum) noexcept { store_variant(traits::qvariant_from_value(traits::pass_value(datum))); @@ -88,11 +89,12 @@ public: static constexpr inline Qt::ConnectionType DIRECT_CONNTYPE = Qt::DirectConnection; static constexpr inline Qt::ConnectionType SAFE_CONNTYPE = Qt::QueuedConnection; - value(bundle b, const QString& name, t def) : - value_(b, name), def(std::move(def)) + value(bundle b, const QString& name, t def) noexcept : value_(b, name), def(std::move(def)) { } + value(const value<u>& other) noexcept : value{other.b, other.self_name, other.def} {} + t default_value() const { return def; @@ -108,16 +110,16 @@ public: template<typename w> explicit cc_forceinline operator w() const { return to<w>(); } - auto operator->() const + auto operator->() const noexcept { return detail::dereference_wrapper<t>{get()}; } - cc_forceinline t operator()() const { return get(); } - cc_forceinline t operator*() const { return get(); } + cc_forceinline t operator()() const noexcept { return get(); } + cc_forceinline t operator*() const noexcept { return get(); } template<typename w> - w to() const + w to() const noexcept { return static_cast<w>(get()); } diff --git a/proto-udp/ftnoir_protocol_ftn.cpp b/proto-udp/ftnoir_protocol_ftn.cpp index 0eb79954..def3ebb1 100644 --- a/proto-udp/ftnoir_protocol_ftn.cpp +++ b/proto-udp/ftnoir_protocol_ftn.cpp @@ -18,15 +18,19 @@ udp::udp() QObject::connect(s.b.get(), &bundle_::changed, this, &udp::set_dest_address, - Qt::QueuedConnection); + Qt::DirectConnection); } void udp::pose(const double *headpose) { + spinlock_guard l(spl); + outSocket.writeDatagram((const char *) headpose, sizeof(double[6]), dest_ip, dest_port); } void udp::set_dest_address() { + spinlock_guard l(spl); + dest_port = (unsigned short)s.port; dest_ip = QHostAddress((s.ip1.to<unsigned>() & 0xff) << 24 | (s.ip2.to<unsigned>() & 0xff) << 16 | diff --git a/proto-udp/ftnoir_protocol_ftn.h b/proto-udp/ftnoir_protocol_ftn.h index 8bc581bf..a7c90f5b 100644 --- a/proto-udp/ftnoir_protocol_ftn.h +++ b/proto-udp/ftnoir_protocol_ftn.h @@ -11,10 +11,11 @@ #pragma once #include "ui_ftnoir_ftncontrols.h" -#include <QUdpSocket> #include "api/plugin-api.hpp" +#include "compat/spinlock.hpp" #include "options/options.hpp" using namespace options; +#include <QUdpSocket> struct settings : opts { value<int> ip1, ip2, ip3, ip4, port; @@ -41,6 +42,8 @@ private: QUdpSocket outSocket; settings s; + mutable std::atomic_flag spl = ATOMIC_FLAG_INIT; + QHostAddress dest_ip { 127u << 24 | 1u }; unsigned short dest_port = 65535; diff --git a/sdk-paths-sthalik@Clang-windows.cmake b/sdk-paths-sthalik@Clang-windows.cmake index 102917d1..895d68b2 100644 --- a/sdk-paths-sthalik@Clang-windows.cmake +++ b/sdk-paths-sthalik@Clang-windows.cmake @@ -53,8 +53,9 @@ set(_cxxflags -Werror -Werror=inconsistent-missing-destructor-override #-Wno-error=padded - -fdiagnostics-color=always + + -fno-exceptions -fno-rtti # get rid of evil ) set(base-cxxflags "") foreach(k ${_cxxflags}) diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index 7c92094d..bfe8aff1 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -31,7 +31,10 @@ spline_widget::spline_widget(QWidget *parent) : QWidget(parent) spline_widget::~spline_widget() { if (connection) + { QObject::disconnect(connection); + connection = {}; + } } void spline_widget::setConfig(base_spline* spl) @@ -39,7 +42,7 @@ void spline_widget::setConfig(base_spline* spl) if (connection) { QObject::disconnect(connection); - connection = QMetaObject::Connection(); + connection = {}; } config = spl; diff --git a/spline/spline.cpp b/spline/spline.cpp index 5381a28e..50812bad 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -127,7 +127,7 @@ QPointF spline::ensure_in_bounds(const QList<QPointF>& points, int i) int spline::element_count(const QList<QPointF>& points, double max_input) { - const unsigned sz = points.size(); + const unsigned sz = (unsigned)points.size(); for (unsigned k = 0; k < sz; k++) { const QPointF& pt = points[k]; @@ -310,9 +310,6 @@ void spline::save() void spline::invalidate_settings() { - // we're holding the mutex to allow signal disconnection in spline dtor - // before this slot gets called for the next time - { QMutexLocker l(&mtx); validp = false; @@ -373,19 +370,19 @@ void spline::ensure_valid(points_t& list) const std::stable_sort(list.begin(), list.end(), sort_fn); - const int sz = list.size(); + const unsigned sz = (unsigned)list.size(); - QList<QPointF> all_points, tmp; - all_points.reserve(sz); tmp.reserve(sz); + QList<QPointF> tmp_points, all_points; + tmp_points.reserve(sz); all_points.reserve(sz); const double maxx = max_input(); - for (int i = 0; i < sz; i++) + for (unsigned i = 0; i < sz; i++) { QPointF& pt{list[i]}; bool overlap = false; - for (int j = i+1; j < sz; j++) + for (unsigned j = i+1; j < sz; j++) { const QPointF& pt2{list[j]}; const QPointF tmp(pt - pt2); @@ -400,27 +397,27 @@ void spline::ensure_valid(points_t& list) const if (!overlap) { - tmp.append(pt); // all points total + all_points.append(pt); // all points total // points within selected limit, for use in `update_interp_data' if (pt.x() - 1e-4 <= maxx && pt.x() >= 0) - all_points.push_back(pt); + tmp_points.push_back(pt); } } // simply storing to s->points fires bundle::changed leading to a livelock // hence only store if we can't help it - if (tmp.size() < points.size()) + if (all_points.size() < points.size()) { // all points that don't overlap - points = std::move(tmp); + points = std::move(all_points); s->points = points; } - if (all_points.size() < list.size()) + if (tmp_points.size() < list.size()) // points that are within currently-specified bounds - list = std::move(all_points); + list = std::move(tmp_points); last_input_value = {}; activep = false; diff --git a/tracker-aruco/CMakeLists.txt b/tracker-aruco/CMakeLists.txt index 253cdd5f..bfa7a348 100644 --- a/tracker-aruco/CMakeLists.txt +++ b/tracker-aruco/CMakeLists.txt @@ -15,7 +15,7 @@ if(OpenCV_FOUND) maybe_add_static_define() - set(modules "${SDK_ARUCO_LIBPATH}" opencv_core opencv_calib3d opencv_imgproc opencv_videoio) + set(modules "${SDK_ARUCO_LIBPATH}" opencv_calib3d opencv_imgproc opencv_core) get_filename_component(dir "${SDK_ARUCO_LIBPATH}" DIRECTORY) get_filename_component(dir "${dir}" ABSOLUTE) diff --git a/tracker-pt/CMakeLists.txt b/tracker-pt/CMakeLists.txt index 4010b6c1..f12f530b 100644 --- a/tracker-pt/CMakeLists.txt +++ b/tracker-pt/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(OpenCV QUIET) if(OpenCV_FOUND) otr_module(tracker-pt-base STATIC) target_include_directories(${self} SYSTEM PUBLIC ${OpenCV_INCLUDE_DIRS}) - target_link_libraries(${self} opentrack-cv opencv_core opencv_imgproc opencv_videoio) + target_link_libraries(${self} opencv_imgproc opentrack-cv opencv_core) set_property(TARGET ${self} PROPERTY OUTPUT_NAME "pt-base") endif() add_subdirectory(module) diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index f52564f7..c72a7ffa 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -174,7 +174,7 @@ void Tracker_PT::data(double *data) alpha = atan2( R(1,0), R(0,0) ); gamma = atan2( R(2,1), R(2,2) ); - constexpr f rad2deg = f(180/M_PI); + constexpr f rad2deg = f(180/pi); data[Yaw] = rad2deg * alpha; data[Pitch] = -rad2deg * beta; diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index e6364a88..0f7af939 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -182,20 +182,20 @@ void PointExtractor::threshold_image(const cv::Mat& frame_gray, cv::Mat1b& outpu const f radius = (f) threshold_radius_value(frame_gray.cols, frame_gray.rows, threshold_slider_value); float const* const __restrict ptr = hist.ptr<float>(0); - const unsigned area = uround(3 * M_PI * radius*radius); + const unsigned area = uround(3 * pi * radius*radius); const unsigned sz = unsigned(hist.cols * hist.rows); constexpr unsigned min_thres = 64; unsigned thres = min_thres; for (unsigned i = sz-1, cnt = 0; i > 32; i--) { - cnt += ptr[i]; + cnt += (unsigned)ptr[i]; if (cnt >= area) break; thres = i; } if (thres > min_thres) - thres *= .8; + thres = uround(thres * .8); cv::threshold(frame_gray, output, thres, 255, cv::THRESH_BINARY); } @@ -263,12 +263,12 @@ void PointExtractor::extract_points(const pt_frame& frame_, pt_preview& preview_ } } - const double radius = std::sqrt(cnt / M_PI); + const double radius = std::sqrt(cnt / pi); if (radius > region_size_max || radius < region_size_min) continue; blobs.emplace_back(radius, - vec2(rect.width/2., rect.height/2.), + vec2(rect.width/f(2), rect.height/f(2)), std::pow(f(norm), f(1.1))/cnt, rect); @@ -294,7 +294,7 @@ end: for (idx = 0; idx < sz; ++idx) { - blob &b = blobs[idx]; + blob& b = blobs[idx]; cv::Rect rect = b.rect; rect.x -= rect.width / 2; diff --git a/tracker-pt/module/point_extractor.h b/tracker-pt/module/point_extractor.h index 7dd82234..bbe202fa 100644 --- a/tracker-pt/module/point_extractor.h +++ b/tracker-pt/module/point_extractor.h @@ -19,7 +19,7 @@ namespace pt_module { using namespace types; -struct blob +struct blob final { f radius, brightness; vec2 pos; diff --git a/tracker-pt/point_tracker.cpp b/tracker-pt/point_tracker.cpp index b04c8eb1..68e8c286 100644 --- a/tracker-pt/point_tracker.cpp +++ b/tracker-pt/point_tracker.cpp @@ -67,18 +67,19 @@ void PointModel::set_model(const pt_settings& s) void PointModel::get_d_order(const vec2* points, unsigned* d_order, const vec2& d) const { + constexpr unsigned cnt = PointModel::N_POINTS; // fit line to orthographically projected points using t = std::pair<f,unsigned>; - t d_vals[3]; + t d_vals[cnt]; // get sort indices with respect to d scalar product - for (unsigned i = 0; i < PointModel::N_POINTS; ++i) + for (unsigned i = 0; i < cnt; ++i) d_vals[i] = t(d.dot(points[i]), i); std::sort(d_vals, d_vals + 3u, [](const t& a, const t& b) { return a.first < b.first; }); - for (unsigned i = 0; i < PointModel::N_POINTS; ++i) + for (unsigned i = 0; i < cnt; ++i) d_order[i] = d_vals[i].second; } @@ -98,18 +99,19 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vec2* const int diagonal = int(std::sqrt(f(info.res_x*info.res_x + info.res_y*info.res_y))); constexpr int div = 80; const int max_dist = diagonal / div; // 10 pixels for 640x480 + constexpr unsigned sz = PointModel::N_POINTS; // set correspondences by minimum distance to projected model point - bool point_taken[PointModel::N_POINTS]; - for (unsigned i=0; i<PointModel::N_POINTS; ++i) // NOLINT(modernize-loop-convert) + bool point_taken[sz]; + for (unsigned i=0; i < sz; ++i) // NOLINT(modernize-loop-convert) point_taken[i] = false; - for (unsigned i=0; i<PointModel::N_POINTS; ++i) + for (unsigned i=0; i < sz; ++i) { f min_sdist = 0; unsigned min_idx = 0; // find closest point to projected model point i - for (unsigned j=0; j<PointModel::N_POINTS; ++j) + for (unsigned j=0; j < sz; ++j) { vec2 d = p[i]-points[j]; f sdist = d.dot(d); @@ -328,14 +330,14 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order, f foca // CAVEAT don't change to comparison with an epsilon -sh 20160423 if (JJ0 == II0) { rho = sqrt(fabs(2*IJ0)); - theta = -M_PI/4; + 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) ); // avoid branch misprediction - theta += (JJ0 - II0 < 0) * M_PI; + theta += (JJ0 - II0 < 0) * pi; theta *= f(.5); } @@ -378,7 +380,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order, f foca // check for convergence condition const f delta = fabs(epsilon_1 - old_epsilon_1) + fabs(epsilon_2 - old_epsilon_2); - if (delta < constants::eps) + if (delta < eps) break; old_epsilon_1 = epsilon_1; diff --git a/tracker-pt/pt-api.cpp b/tracker-pt/pt-api.cpp index 128dcaea..415f1c13 100644 --- a/tracker-pt/pt-api.cpp +++ b/tracker-pt/pt-api.cpp @@ -10,7 +10,7 @@ double pt_camera_info::get_focal_length(f fov, int res_x, int res_y) const double diag_len = std::sqrt(double(res_x*res_x + res_y*res_y)); const double aspect_x = res_x / diag_len; //const double aspect_y = res_y / diag_len; - const double diag_fov = fov * M_PI/180; + const double diag_fov = fov * pi/180; const double fov_x = 2*std::atan(std::tan(diag_fov*.5) * aspect_x); //const double fov_y = 2*atan(tan(diag_fov*.5) * aspect_y); const double fx = .5 / std::tan(fov_x * .5); diff --git a/tracker-wii/wii_point_extractor.cpp b/tracker-wii/wii_point_extractor.cpp index c5c20c6a..b73925bc 100644 --- a/tracker-wii/wii_point_extractor.cpp +++ b/tracker-wii/wii_point_extractor.cpp @@ -99,8 +99,8 @@ void WIIPointExtractor::draw_bg(cv::Mat& preview_frame, const struct wii_info& w 2); //draw horizon - int pdelta = iround((preview_frame.rows / 4.) * tan(((double)wii.Pitch)* M_PI / 180.)); - int rdelta = iround((preview_frame.cols / 4.) * tan(((double)wii.Roll)* M_PI / 180.)); + int pdelta = iround((preview_frame.rows / 4.) * tan(((double)wii.Pitch)* pi / f(180))); + int rdelta = iround((preview_frame.cols / 4.) * tan(((double)wii.Roll)* pi / f(180))); cv::line(preview_frame, cv::Point(0, preview_frame.rows / 2 + rdelta - pdelta), |