diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d3075786da3ac7b8cc95f74bd80933fc8ef49a..7dc1566bc1604d4dc336a159f0698b7fa69d85c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,7 +175,7 @@ check_include_file_cxx("opencv2/cudastereo.hpp" HAVE_OPENCVCUDA) find_program(CPPCHECK_FOUND cppcheck) if (CPPCHECK_FOUND) message(STATUS "Found cppcheck: will perform source checks") - set(CMAKE_CXX_CPPCHECK "cppcheck" "-D__align__(A)" "-DCUDARTAPI" "--enable=warning,performance,style" "--inline-suppr" "--std=c++11" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*nanogui*" "--suppress=*:*json.hpp" "--quiet") + set(CMAKE_CXX_CPPCHECK "cppcheck" "-D__align__(A)" "-DCUDARTAPI" "--enable=warning,performance,style" "--inline-suppr" "--std=c++14" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*nanogui*" "--suppress=*:*json.hpp" "--quiet") endif() # include_directories(${PROJECT_SOURCE_DIR}/common/cpp/include) diff --git a/applications/calibration/src/common.hpp b/applications/calibration/src/common.hpp index 274698b32b51ae9b741b94e25b492ab059637e37..80d31f1452b40069c312a650425598e82f976f33 100644 --- a/applications/calibration/src/common.hpp +++ b/applications/calibration/src/common.hpp @@ -90,7 +90,7 @@ public: */ class CalibrationChessboard : Calibration { public: - CalibrationChessboard(const std::map<std::string, std::string> &opt); + explicit CalibrationChessboard(const std::map<std::string, std::string> &opt); void objectPoints(std::vector<cv::Vec3f> &out); bool findPoints(cv::Mat &in, std::vector<cv::Vec2f> &out); void drawPoints(cv::Mat &img, const std::vector<cv::Vec2f> &points); diff --git a/components/common/cpp/include/ftl/timer.hpp b/components/common/cpp/include/ftl/timer.hpp index dad98a704dd127c23b961bd7429da14253399db3..97776c2c3ee9bcbb62b8d81909d87a7dc43ecd28 100644 --- a/components/common/cpp/include/ftl/timer.hpp +++ b/components/common/cpp/include/ftl/timer.hpp @@ -29,7 +29,9 @@ enum timerlevel_t { * a destructor, for example. */ struct TimerHandle { - const int id = -1; + TimerHandle() : id_(-1) {} + explicit TimerHandle(int i) : id_(i) {} + TimerHandle(const TimerHandle &t) : id_(t.id()) {} /** * Cancel the timer job. If currently executing it will block and wait for @@ -52,7 +54,12 @@ struct TimerHandle { /** * Allow copy assignment. */ - TimerHandle &operator=(const TimerHandle &h) { const_cast<int&>(id) = h.id; return *this; } + TimerHandle &operator=(const TimerHandle &h) { id_ = h.id(); return *this; } + + inline int id() const { return id_; } + + private: + int id_; }; int64_t get_time(); diff --git a/components/common/cpp/src/timer.cpp b/components/common/cpp/src/timer.cpp index d6d8441c65e401a021ceb68dc3fbf0eea0cfc4df..252c51b8360c83756496fd8761ad7e017c394b06 100644 --- a/components/common/cpp/src/timer.cpp +++ b/components/common/cpp/src/timer.cpp @@ -105,12 +105,12 @@ void ftl::timer::setClockAdjustment(int64_t ms) { } const TimerHandle ftl::timer::add(timerlevel_t l, const std::function<bool(int64_t ts)> &f) { - if (l < 0 || l >= kTimerMAXLEVEL) return {-1}; + if (l < 0 || l >= kTimerMAXLEVEL) return {}; UNIQUE_LOCK(mtx, lk); int newid = last_id++; jobs[l].push_back({newid, f, false, false, 0, 0, "NoName"}); - return {newid}; + return TimerHandle(newid); } static void removeJob(int id) { @@ -217,7 +217,7 @@ void ftl::timer::reset() { // ===== TimerHandle =========================================================== void ftl::timer::TimerHandle::cancel() const { - removeJob(id); + removeJob(id()); } void ftl::timer::TimerHandle::pause() const { diff --git a/components/common/cpp/test/timer_unit.cpp b/components/common/cpp/test/timer_unit.cpp index c1d6776299969bb55fe3d9b9c9a91bd3d35430d6..6cdea157e9228b920ce2220c0122c8dcad9cf76e 100644 --- a/components/common/cpp/test/timer_unit.cpp +++ b/components/common/cpp/test/timer_unit.cpp @@ -22,7 +22,7 @@ TEST_CASE( "Timer::add() High Precision Accuracy" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -40,7 +40,7 @@ TEST_CASE( "Timer::add() High Precision Accuracy" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -57,7 +57,7 @@ TEST_CASE( "Timer::add() High Precision Accuracy" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::add(ftl::timer::kTimerHighPrecision, [&didrun](int64_t ts) { didrun[1] = true; @@ -90,7 +90,7 @@ TEST_CASE( "Timer::add() Idle10 job" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -108,7 +108,7 @@ TEST_CASE( "Timer::add() Idle10 job" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -125,7 +125,7 @@ TEST_CASE( "Timer::add() Idle10 job" ) { return false; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -145,7 +145,7 @@ TEST_CASE( "Timer::add() Main job" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -163,7 +163,7 @@ TEST_CASE( "Timer::add() Main job" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -182,7 +182,7 @@ TEST_CASE( "Timer::add() Main job" ) { return true; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::add(ftl::timer::kTimerMain, [&job2](int64_t ts) { job2++; @@ -204,7 +204,7 @@ TEST_CASE( "Timer::add() Main job" ) { return false; }); - REQUIRE( (rc.id >= 0) ); + REQUIRE( (rc.id() >= 0) ); ftl::timer::start(true); REQUIRE( didrun == true ); @@ -224,7 +224,7 @@ TEST_CASE( "TimerHandle::cancel()" ) { }); // Fake Handle - ftl::timer::TimerHandle h = {44}; + ftl::timer::TimerHandle h(44); h.cancel(); ftl::timer::start(true); REQUIRE( didjob ); diff --git a/components/net/cpp/src/peer.cpp b/components/net/cpp/src/peer.cpp index 25059b5473c154d31ea6b31950a3e5e5eff02de8..0335ca67f3a284294b4973c83aea62100d56a5c2 100644 --- a/components/net/cpp/src/peer.cpp +++ b/components/net/cpp/src/peer.cpp @@ -424,50 +424,44 @@ void Peer::data() { //LOG(INFO) << "Pool size: " << ftl::pool.q_size(); int rc=0; - int c=0; - //do { - recv_buf_.reserve_buffer(kMaxMessage); + recv_buf_.reserve_buffer(kMaxMessage); - if (recv_buf_.buffer_capacity() < (kMaxMessage / 10)) { - LOG(WARNING) << "Net buffer at capacity"; - return; - } - - int cap = recv_buf_.buffer_capacity(); - auto buf = recv_buf_.buffer(); - lk.unlock(); + if (recv_buf_.buffer_capacity() < (kMaxMessage / 10)) { + LOG(WARNING) << "Net buffer at capacity"; + return; + } - /*#ifndef WIN32 - int n; - unsigned int m = sizeof(n); - getsockopt(sock_,SOL_SOCKET,SO_RCVBUF,(void *)&n, &m); + int cap = recv_buf_.buffer_capacity(); + auto buf = recv_buf_.buffer(); + lk.unlock(); - int pending; - ioctl(sock_, SIOCINQ, &pending); - if (pending > 100000) LOG(INFO) << "Buffer usage: " << float(pending) / float(n); - #endif*/ - rc = ftl::net::internal::recv(sock_, buf, cap, 0); + /*#ifndef WIN32 + int n; + unsigned int m = sizeof(n); + getsockopt(sock_,SOL_SOCKET,SO_RCVBUF,(void *)&n, &m); - if (rc >= cap-1) { - LOG(WARNING) << "More than buffers worth of data received"; - } - if (cap < (kMaxMessage / 10)) LOG(WARNING) << "NO BUFFER"; - - if (rc == 0) { - close(); - return; - } else if (rc < 0 && c == 0) { - socketError(); - return; - } + int pending; + ioctl(sock_, SIOCINQ, &pending); + if (pending > 100000) LOG(INFO) << "Buffer usage: " << float(pending) / float(n); + #endif*/ + rc = ftl::net::internal::recv(sock_, buf, cap, 0); - //if (rc == -1) break; - ++c; - - lk.lock(); - recv_buf_.buffer_consumed(rc); - //} while (rc > 0); + if (rc >= cap-1) { + LOG(WARNING) << "More than buffers worth of data received"; + } + if (cap < (kMaxMessage / 10)) LOG(WARNING) << "NO BUFFER"; + + if (rc == 0) { + close(); + return; + } else if (rc < 0) { + socketError(); + return; + } + + lk.lock(); + recv_buf_.buffer_consumed(rc); //auto end = std::chrono::high_resolution_clock::now(); //int64_t endts = std::chrono::time_point_cast<std::chrono::milliseconds>(end).time_since_epoch().count(); diff --git a/components/rgbd-sources/include/ftl/rgbd/frame.hpp b/components/rgbd-sources/include/ftl/rgbd/frame.hpp index 5b796a9512efeb8800bbc3c2a8ce4a154a2be296..6574de3bf1db29be30d299fa6fe63c84c5827943 100644 --- a/components/rgbd-sources/include/ftl/rgbd/frame.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/frame.hpp @@ -14,6 +14,7 @@ #include <ftl/cuda_common.hpp> #include <type_traits> +#include <array> namespace ftl { namespace rgbd { @@ -125,7 +126,7 @@ private: ftl::cuda::TextureObjectBase tex; }; - ChannelData data_[Channels::kMax]; + std::array<ChannelData, Channels::kMax> data_; ftl::rgbd::Channels channels_; // Does it have a channel ftl::rgbd::Channels gpu_; // Is the channel on a GPU diff --git a/components/rgbd-sources/src/middlebury_source.cpp b/components/rgbd-sources/src/middlebury_source.cpp index a707bf9fab06a212b4146065b414999d21bc9adb..e82167fdcf6b4e2bfd1a38a00b50e3cdceeb2aef 100644 --- a/components/rgbd-sources/src/middlebury_source.cpp +++ b/components/rgbd-sources/src/middlebury_source.cpp @@ -16,14 +16,13 @@ MiddleburySource::MiddleburySource(ftl::rgbd::Source *host) static bool loadMiddleburyCalib(const std::string &filename, ftl::rgbd::Camera ¶ms, double scaling) { FILE* fp = fopen(filename.c_str(), "r"); - char buff[512]; - float cam0[3][3]; + float cam0[3][3] = {}; float cam1[3][3]; - float doffs; - float baseline; - int width; - int height; + float doffs = 0.0f; + float baseline = 0.0f; + int width = 0; + int height = 0; int ndisp; int isint; int vmin; @@ -31,8 +30,8 @@ static bool loadMiddleburyCalib(const std::string &filename, ftl::rgbd::Camera & float dyavg; float dymax; - if (fp != nullptr) - { + if (fp != nullptr) { + char buff[512]; if (fgets(buff, sizeof(buff), fp) != nullptr) sscanf(buff, "cam0 = [%f %f %f; %f %f %f; %f %f %f]\n", &cam0[0][0], &cam0[0][1], &cam0[0][2], &cam0[1][0], &cam0[1][1], &cam0[1][2], &cam0[2][0], &cam0[2][1], &cam0[2][2]); if (fgets(buff, sizeof(buff), fp) != nullptr) sscanf(buff, "cam1 = [%f %f %f; %f %f %f; %f %f %f]\n", &cam1[0][0], &cam1[0][1], &cam1[0][2], &cam1[1][0], &cam1[1][1], &cam1[1][2], &cam1[2][0], &cam1[2][1], &cam1[2][2]); if (fgets(buff, sizeof(buff), fp) != nullptr) sscanf(buff, "doffs = %f\n", &doffs); @@ -122,7 +121,7 @@ MiddleburySource::MiddleburySource(ftl::rgbd::Source *host, const string &dir) mask_l_ = (mask_l == 0); if (!host_->getConfig()["disparity"].is_object()) { - host_->getConfig()["disparity"] = {{"algorithm","libsgm"}}; + host_->getConfig()["disparity"] = ftl::config::json_t{{"algorithm","libsgm"}}; } disp_ = Disparity::create(host_, "disparity"); diff --git a/components/rgbd-sources/src/middlebury_source.hpp b/components/rgbd-sources/src/middlebury_source.hpp index 21c7d1f1c07d96130be44156fd17666868ab739b..d273d23a66d67c6618c0ac4a2062a780d9a3bddb 100644 --- a/components/rgbd-sources/src/middlebury_source.hpp +++ b/components/rgbd-sources/src/middlebury_source.hpp @@ -15,7 +15,7 @@ class Disparity; class MiddleburySource : public detail::Source { public: - MiddleburySource(ftl::rgbd::Source *); + explicit MiddleburySource(ftl::rgbd::Source *); MiddleburySource(ftl::rgbd::Source *, const std::string &dir); ~MiddleburySource() {}; diff --git a/components/rgbd-sources/src/realsense_source.hpp b/components/rgbd-sources/src/realsense_source.hpp index 4eb182032ffa67cbe121993ed981398a57e0470a..371d305b7d27fc73ad85bba83965f58dcd28c45b 100644 --- a/components/rgbd-sources/src/realsense_source.hpp +++ b/components/rgbd-sources/src/realsense_source.hpp @@ -14,7 +14,7 @@ namespace detail { class RealsenseSource : public ftl::rgbd::detail::Source { public: - RealsenseSource(ftl::rgbd::Source *host); + explicit RealsenseSource(ftl::rgbd::Source *host); ~RealsenseSource(); bool capture(int64_t ts) { timestamp_ = ts; return true; } diff --git a/components/rgbd-sources/src/snapshot_source.hpp b/components/rgbd-sources/src/snapshot_source.hpp index 1200f460cfb0ed68cc7cc1573b66c9135c605404..de1b0df48be79df732f51144226f5c7e6d2f0478 100644 --- a/components/rgbd-sources/src/snapshot_source.hpp +++ b/components/rgbd-sources/src/snapshot_source.hpp @@ -13,7 +13,7 @@ namespace detail { class SnapshotSource : public detail::Source { public: - SnapshotSource(ftl::rgbd::Source *); + explicit SnapshotSource(ftl::rgbd::Source *); SnapshotSource(ftl::rgbd::Source *, ftl::rgbd::Snapshot &snapshot, const std::string &id); ~SnapshotSource() {}; diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp index f52359be76ff3010961a6baada6252d2cd592e25..d33473fc38fbf55670e8b8844ffa5a03487e606d 100644 --- a/components/rgbd-sources/src/source.cpp +++ b/components/rgbd-sources/src/source.cpp @@ -29,7 +29,7 @@ using ftl::rgbd::Channel; Source::Source(ftl::config::json_t &cfg) : Configurable(cfg), pose_(Eigen::Matrix4d::Identity()), net_(nullptr) { impl_ = nullptr; - params_ = {0}; + params_ = {}; stream_ = 0; timestamp_ = 0; reset(); @@ -42,7 +42,7 @@ Source::Source(ftl::config::json_t &cfg) : Configurable(cfg), pose_(Eigen::Matri Source::Source(ftl::config::json_t &cfg, ftl::net::Universe *net) : Configurable(cfg), pose_(Eigen::Matrix4d::Identity()), net_(net) { impl_ = nullptr; - params_ = {0}; + params_ = {}; stream_ = 0; timestamp_ = 0; reset();