diff --git a/CMakeLists.txt b/CMakeLists.txt index 65b3fb9c01a1db2aaf46f59ae9fdfd67024fcfce..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,portability,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/applications/groupview/src/main.cpp b/applications/groupview/src/main.cpp index 99820d759b6c2ef6be37e34e6efea157295c0104..6b32221ef1a13ad05f9e5bb915c1186eca0aa52c 100644 --- a/applications/groupview/src/main.cpp +++ b/applications/groupview/src/main.cpp @@ -110,11 +110,12 @@ void modeLeftRight(ftl::Configurable *root) { }); int idx = 0; - int key; Mat show; while (ftl::running) { + int key; + while (!new_frames) { for (auto src : sources) { src->grab(30); } key = cv::waitKey(10); diff --git a/applications/gui/src/camera.cpp b/applications/gui/src/camera.cpp index dd8bc936a6e06ac7a15e2951a053eeadb783b43f..fe7b115c779989468644014675b020e1a0ed7d52 100644 --- a/applications/gui/src/camera.cpp +++ b/applications/gui/src/camera.cpp @@ -18,7 +18,7 @@ private: float n_; // total number of samples public: - StatisticsImage(cv::Size size); + explicit StatisticsImage(cv::Size size); StatisticsImage(cv::Size size, float max_f); /* @brief reset all statistics to 0 diff --git a/applications/gui/src/camera.hpp b/applications/gui/src/camera.hpp index 605560cc0cae859678e25dbf2070d777a72e9112..0d6e99b6d08d5cd5f71dfc20a94d0f35e26518b0 100644 --- a/applications/gui/src/camera.hpp +++ b/applications/gui/src/camera.hpp @@ -19,6 +19,8 @@ class Camera { Camera(ftl::gui::Screen *screen, ftl::rgbd::Source *src); ~Camera(); + Camera(const Camera &)=delete; + ftl::rgbd::Source *source(); int width() { return (src_) ? src_->parameters().width : 0; } diff --git a/applications/gui/src/media_panel.hpp b/applications/gui/src/media_panel.hpp index d7f9aa9938ee51418629ee42781e738b535c38d0..9e9154d860483a6bf6c88b8da856a4a89862de2f 100644 --- a/applications/gui/src/media_panel.hpp +++ b/applications/gui/src/media_panel.hpp @@ -15,7 +15,7 @@ class Screen; class MediaPanel : public nanogui::Window { public: - MediaPanel(ftl::gui::Screen *); + explicit MediaPanel(ftl::gui::Screen *); ~MediaPanel(); void cameraChanged(); diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp index 56624ce61d9524c43e6dffe00948e807528ae595..22382626d15ffe037020fd8545772cbd506905e8 100644 --- a/applications/gui/src/screen.cpp +++ b/applications/gui/src/screen.cpp @@ -51,15 +51,15 @@ namespace { })"; } -ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl::ctrl::Master *controller) : nanogui::Screen(Eigen::Vector2i(1024, 768), "FT-Lab Remote Presence") { +ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl::ctrl::Master *controller) : + nanogui::Screen(Eigen::Vector2i(1024, 768), "FT-Lab Remote Presence"), + status_("FT-Lab Remote Presence System") { using namespace nanogui; net_ = pnet; ctrl_ = controller; root_ = proot; camera_ = nullptr; - status_ = "FT-Lab Remote Presence System"; - setSize(Vector2i(1280,720)); toolbuttheme = new Theme(*theme()); diff --git a/applications/gui/src/src_window.hpp b/applications/gui/src/src_window.hpp index 7f28279c7fa3cd83bdb62a074e55d4d549799f73..b2fe8a9e0957f3345a719a0c37bac46bf473089c 100644 --- a/applications/gui/src/src_window.hpp +++ b/applications/gui/src/src_window.hpp @@ -22,7 +22,7 @@ class Camera; class SourceWindow : public nanogui::Window { public: - SourceWindow(ftl::gui::Screen *screen); + explicit SourceWindow(ftl::gui::Screen *screen); ~SourceWindow(); const std::vector<ftl::gui::Camera*> &getCameras(); diff --git a/applications/reconstruct/include/ftl/cuda_matrix_util.hpp b/applications/reconstruct/include/ftl/cuda_matrix_util.hpp index e8d803e6fdf7b7c62d52d456ddce288bf554b233..4dd1db7fa8a58c84a40f9d93abd8cc0a492b2792 100644 --- a/applications/reconstruct/include/ftl/cuda_matrix_util.hpp +++ b/applications/reconstruct/include/ftl/cuda_matrix_util.hpp @@ -1606,6 +1606,7 @@ inline __device__ __host__ matNxM<2, 2> matNxM<2, 2>::getInverse() const // To Matrix from floatNxN template<> +// cppcheck-suppress syntaxError template<> inline __device__ __host__ matNxM<1, 1>::matNxM(const float& other) { diff --git a/applications/reconstruct/src/dibr.cu b/applications/reconstruct/src/dibr.cu index fade3634314698772c46b126218765862d1adbaf..66428ce3086e42b6a3e81c667ae126314d910c98 100644 --- a/applications/reconstruct/src/dibr.cu +++ b/applications/reconstruct/src/dibr.cu @@ -158,8 +158,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp const int upsample = min(UPSAMPLE_MAX, int((r) * params.camera.fx / camPos.z)); // Not on screen so stop now... - if (screenPos.x + upsample < 0 || screenPos.y + upsample < 0 || - screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return; + if (screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return; // TODO:(Nick) Check depth buffer and don't do anything if already hidden? @@ -181,7 +180,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp // and depth remains within the bounds. // How to find min and max depths? - float ld = nearest.z; + //float ld = nearest.z; // TODO: (Nick) Estimate depth using points plane, but needs better normals. //float t; @@ -241,7 +240,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp }*/ //nearest = params.camera.kinectDepthToSkeleton(screenPos.x+u,screenPos.y+v,d); // ld + (d - ld)*0.8f - ld = d; + //ld = d; } //} } @@ -287,8 +286,7 @@ __global__ void OLD_dibr_visibility_kernel(TextureObject<int> depth, int cam, Sp const int upsample = min(UPSAMPLE_MAX, int((4.0f*r) * params.camera.fx / camPos.z)); // Not on screen so stop now... - if (screenPos.x + upsample < 0 || screenPos.y + upsample < 0 || - screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return; + if (screenPos.x - upsample >= depth.width() || screenPos.y - upsample >= depth.height()) return; // TODO:(Nick) Check depth buffer and don't do anything if already hidden? @@ -575,7 +573,7 @@ __global__ void dibr_attribute_contrib_kernel( const ftl::voxhash::DepthCameraCUDA &camera = c_cameras[cam]; const int tid = (threadIdx.x + threadIdx.y * blockDim.x); - const int warp = tid / WARP_SIZE; + //const int warp = tid / WARP_SIZE; const int x = (blockIdx.x*blockDim.x + threadIdx.x) / WARP_SIZE; const int y = blockIdx.y*blockDim.y + threadIdx.y; @@ -592,8 +590,7 @@ __global__ void dibr_attribute_contrib_kernel( const int upsample = 8; //min(UPSAMPLE_MAX, int((5.0f*r) * params.camera.fx / camPos.z)); // Not on screen so stop now... - if (screenPos.x < 0 || screenPos.y < 0 || - screenPos.x >= depth_in.width() || screenPos.y >= depth_in.height()) return; + if (screenPos.x >= depth_in.width() || screenPos.y >= depth_in.height()) return; // Is this point near the actual surface and therefore a contributor? const float d = ((float)depth_in.tex2D((int)screenPos.x, (int)screenPos.y)/1000.0f); @@ -722,7 +719,7 @@ void ftl::cuda::dibr(const TextureObject<int> &depth_out, cudaSafeCall(cudaDeviceSynchronize()); #endif - int i=3; + //int i=3; bool noSplatting = params.m_flags & ftl::render::kNoSplatting; diff --git a/components/codecs/src/nvpipe_encoder.cpp b/components/codecs/src/nvpipe_encoder.cpp index cbae706ef8d5729615d4084ca8c024fc69333ea2..e03dc7073349a97bb7e090ce5b9a563b8ea2117a 100644 --- a/components/codecs/src/nvpipe_encoder.cpp +++ b/components/codecs/src/nvpipe_encoder.cpp @@ -30,8 +30,6 @@ void NvPipeEncoder::reset() { /* Check preset resolution is not better than actual resolution. */ definition_t NvPipeEncoder::_verifiedDefinition(definition_t def, const cv::Mat &in) { - bool is_float = in.type() == CV_32F; - int height = ftl::codecs::getHeight(def); // FIXME: Make sure this can't go forever diff --git a/components/common/cpp/CMakeLists.txt b/components/common/cpp/CMakeLists.txt index 8759e81039afede246d4f7e783531da98a1bc473..de0f7707c504447a16967625c2f01ab76e1218bb 100644 --- a/components/common/cpp/CMakeLists.txt +++ b/components/common/cpp/CMakeLists.txt @@ -21,7 +21,7 @@ target_include_directories(ftlcommon PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> PRIVATE src) -target_link_libraries(ftlcommon Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${PCL_LIBRARIES} ${URIPARSER_LIBRARIES}) +target_link_libraries(ftlcommon Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${PCL_LIBRARIES} ${URIPARSER_LIBRARIES} ${CUDA_LIBRARIES}) add_subdirectory(test) diff --git a/components/common/cpp/include/ftl/cuda_common.hpp b/components/common/cpp/include/ftl/cuda_common.hpp index 09a1dd062ad62bd3e8c0c7384a201a8565573517..70a6a4ad6d4dc0def715979f9eaf348e621d103e 100644 --- a/components/common/cpp/include/ftl/cuda_common.hpp +++ b/components/common/cpp/include/ftl/cuda_common.hpp @@ -22,6 +22,12 @@ namespace ftl { namespace cuda { +bool initialise(); + +bool hasCompute(int major, int minor); + +int deviceCount(); + /** * Represent a CUDA texture object. Instances of this class can be used on both * host and device. A texture object base cannot be constructed directly, it @@ -142,6 +148,7 @@ TextureObject<T>::TextureObject(const cv::cuda::GpuMat &d) { resDesc.res.pitch2D.height = d.rows; cudaTextureDesc texDesc; + // cppcheck-suppress memsetClassFloat memset(&texDesc, 0, sizeof(texDesc)); texDesc.readMode = cudaReadModeElementType; @@ -175,6 +182,7 @@ TextureObject<T>::TextureObject(const cv::cuda::PtrStepSz<T> &d) { resDesc.res.pitch2D.height = d.rows; cudaTextureDesc texDesc; + // cppcheck-suppress memsetClassFloat memset(&texDesc, 0, sizeof(texDesc)); texDesc.readMode = cudaReadModeElementType; @@ -207,6 +215,7 @@ TextureObject<T>::TextureObject(T *ptr, int pitch, int width, int height) { resDesc.res.pitch2D.height = height; cudaTextureDesc texDesc; + // cppcheck-suppress memsetClassFloat memset(&texDesc, 0, sizeof(texDesc)); texDesc.readMode = cudaReadModeElementType; @@ -240,6 +249,7 @@ TextureObject<T>::TextureObject(size_t width, size_t height) { resDesc.res.pitch2D.height = height; cudaTextureDesc texDesc; + // cppcheck-suppress memsetClassFloat memset(&texDesc, 0, sizeof(texDesc)); texDesc.readMode = cudaReadModeElementType; cudaCreateTextureObject(&tex, &resDesc, &texDesc, NULL); 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/configuration.cpp b/components/common/cpp/src/configuration.cpp index ef33ab93a1c93dc5c74ef6787cb47bceab49f71e..8a3849e8ee8799119f3d15700dc277e1dece7654 100644 --- a/components/common/cpp/src/configuration.cpp +++ b/components/common/cpp/src/configuration.cpp @@ -20,6 +20,7 @@ #include <ftl/uri.hpp> #include <ftl/threads.hpp> #include <ftl/timer.hpp> +#include <ftl/cuda_common.hpp> #include <fstream> #include <string> @@ -457,7 +458,7 @@ Configurable *ftl::config::configure(ftl::config::json_t &cfg) { loguru::g_preamble_uptime = false; loguru::g_preamble_thread = false; int argc = 1; - const char *argv[] = {"d",0}; + const char *argv[]{"d",0}; loguru::init(argc, const_cast<char**>(argv), "--verbosity"); config_index.clear(); @@ -519,6 +520,9 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r // Some global settings ftl::timer::setInterval(1000 / rootcfg->value("fps",20)); + // Check CUDA + ftl::cuda::initialise(); + int pool_size = rootcfg->value("thread_pool_factor", 2.0f)*std::thread::hardware_concurrency(); if (pool_size != ftl::pool.size()) ftl::pool.resize(pool_size); diff --git a/components/common/cpp/src/cuda_common.cpp b/components/common/cpp/src/cuda_common.cpp index 15fa9c94963bb073647f609176f3f022a084d4a0..b29c1df08ba14d61a17d8b7afce290b353c25ce6 100644 --- a/components/common/cpp/src/cuda_common.cpp +++ b/components/common/cpp/src/cuda_common.cpp @@ -2,6 +2,40 @@ using ftl::cuda::TextureObjectBase; +static int dev_count = 0; +static std::vector<cudaDeviceProp> properties; + +bool ftl::cuda::initialise() { + // Do an initial CUDA check + cudaSafeCall(cudaGetDeviceCount(&dev_count)); + CHECK_GE(dev_count, 1) << "No CUDA devices found"; + + LOG(INFO) << "CUDA Devices (" << dev_count << "):"; + + properties.resize(dev_count); + for (int i=0; i<dev_count; i++) { + cudaSafeCall(cudaGetDeviceProperties(&properties[i], i)); + LOG(INFO) << " - " << properties[i].name; + } + + return true; +} + +bool ftl::cuda::hasCompute(int major, int minor) { + int dev = -1; + cudaSafeCall(cudaGetDevice(&dev)); + + if (dev > 0) { + return properties[dev].major > major || + (properties[dev].major == major && properties[dev].minor >= minor); + } + return false; +} + +int ftl::cuda::deviceCount() { + return dev_count; +} + TextureObjectBase::~TextureObjectBase() { free(); } diff --git a/components/common/cpp/src/timer.cpp b/components/common/cpp/src/timer.cpp index d6d8441c65e401a021ceb68dc3fbf0eea0cfc4df..328006ab82041d9613ab9ef7847d74727e3aa7f2 100644 --- a/components/common/cpp/src/timer.cpp +++ b/components/common/cpp/src/timer.cpp @@ -30,9 +30,10 @@ struct TimerJob { int id; function<bool(int64_t)> job; volatile bool active; - bool paused; - int multiplier; - int countdown; + // TODO: (Nick) Implement richer forms of timer + //bool paused; + //int multiplier; + //int countdown; std::string name; }; @@ -105,12 +106,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}; + jobs[l].push_back({newid, f, false, "NoName"}); + return TimerHandle(newid); } static void removeJob(int id) { @@ -217,7 +218,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/src/uri.cpp b/components/common/cpp/src/uri.cpp index 0db7a4af505f28bd162d81eed763241ed6f5ff9d..90fb33522c1c2d701fac47b0a6d43a5a6afee3a7 100644 --- a/components/common/cpp/src/uri.cpp +++ b/components/common/cpp/src/uri.cpp @@ -41,8 +41,9 @@ void URI::_parse(uri_t puri) { // NOTE: Non-standard additions to allow for Unix style relative file names. if (suri[0] == '.') { char cwdbuf[1024]; - getcwd(cwdbuf, 1024); - suri = string("file://") + string(cwdbuf) + suri.substr(1); + if (getcwd(cwdbuf, 1024)) { + suri = string("file://") + string(cwdbuf) + suri.substr(1); + } } else if (suri[0] == '~') { #ifdef WIN32 suri = string("file://") + string(std::getenv("HOMEDRIVE")) + string(std::getenv("HOMEPATH")) + suri.substr(1); diff --git a/components/common/cpp/test/CMakeLists.txt b/components/common/cpp/test/CMakeLists.txt index 2ef8e4338ae4e5bb3b39f4eaf8c88ec343fb1b95..f9c1773b92718fc79eb1e26c1d63c7668f12fa53 100644 --- a/components/common/cpp/test/CMakeLists.txt +++ b/components/common/cpp/test/CMakeLists.txt @@ -7,12 +7,13 @@ add_executable(configurable_unit ../src/configuration.cpp ../src/loguru.cpp ../src/ctpl_stl.cpp + ../src/cuda_common.cpp ./configurable_unit.cpp ) target_include_directories(configurable_unit PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include") target_link_libraries(configurable_unit ${URIPARSER_LIBRARIES} - Threads::Threads ${OS_LIBS}) + Threads::Threads ${OS_LIBS} ${OpenCV_LIBS} ${CUDA_LIBRARIES}) ### URI ######################################################################## add_executable(uri_unit 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/calibrate.cpp b/components/rgbd-sources/src/calibrate.cpp index df7fac455b68d8ee326957053ae99da946aa941f..934ca1dcd221ed725c06cba5b6c921b279456d26 100644 --- a/components/rgbd-sources/src/calibrate.cpp +++ b/components/rgbd-sources/src/calibrate.cpp @@ -150,8 +150,6 @@ bool Calibrate::_loadCalibration(cv::Size img_size, std::pair<Mat, Mat> &map1, s } void Calibrate::updateCalibration(const ftl::rgbd::Camera &p) { - std::pair<Mat, Mat> map1, map2; - Q_.at<double>(3, 2) = 1.0 / p.baseline; Q_.at<double>(2, 3) = p.fx; Q_.at<double>(0, 3) = p.cx; 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.cpp b/components/rgbd-sources/src/snapshot.cpp index 8ce89fa080392eb755278f42d92c60a7b0fa0f1e..7a80ee677c6275f2446d0f2b404e3bc778745d08 100644 --- a/components/rgbd-sources/src/snapshot.cpp +++ b/components/rgbd-sources/src/snapshot.cpp @@ -169,7 +169,7 @@ bool SnapshotWriter::addRGBD(size_t source, const cv::Mat &rgb, const cv::Mat &d void SnapshotWriter::writeIndex() { FileStorage fs(".yml", FileStorage::WRITE + FileStorage::MEMORY); - vector<string> channels = {"time", "rgb_left", "depth_left"}; + vector<string> channels{"time", "rgb_left", "depth_left"}; fs << "sources" << sources_; fs << "params" <<params_; 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(); diff --git a/components/rgbd-sources/test/channel_unit.cpp b/components/rgbd-sources/test/channel_unit.cpp index eb88777bd4a8c564c9a57d5fd99b53cdc164d67c..25171678540f1970088d84e1e842865a4249455e 100644 --- a/components/rgbd-sources/test/channel_unit.cpp +++ b/components/rgbd-sources/test/channel_unit.cpp @@ -26,7 +26,7 @@ TEST_CASE("Channel or-ing", "") { cs |= Channel::Right; - REQUIRE( cs.count() == 2 ); + REQUIRE( (cs.count() == 2) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Depth) ); } @@ -36,7 +36,7 @@ TEST_CASE("Channel or-ing", "") { cs = Channel::Right | Channel::Flow | Channel::Left; - REQUIRE( cs.count() == 3 ); + REQUIRE( (cs.count() == 3) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Flow) ); REQUIRE( cs.has(Channel::Left) ); @@ -45,7 +45,7 @@ TEST_CASE("Channel or-ing", "") { SECTION("Combine multiple channels at init") { Channels cs = Channel::Right | Channel::Flow | Channel::Left; - REQUIRE( cs.count() == 3 ); + REQUIRE( (cs.count() == 3) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Flow) ); REQUIRE( cs.has(Channel::Left) ); @@ -58,7 +58,7 @@ TEST_CASE("Channel adding", "") { cs += Channel::Right; - REQUIRE( cs.count() == 2 ); + REQUIRE( (cs.count() == 2) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Depth) ); } @@ -68,7 +68,7 @@ TEST_CASE("Channel adding", "") { cs = Channel::Right + Channel::Flow + Channel::Left; - REQUIRE( cs.count() == 3 ); + REQUIRE( (cs.count() == 3) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Flow) ); REQUIRE( cs.has(Channel::Left) ); @@ -81,7 +81,7 @@ TEST_CASE("Channel subtracting", "") { cs -= Channel::Flow; - REQUIRE( cs.count() == 2 ); + REQUIRE( (cs.count() == 2) ); REQUIRE( cs.has(Channel::Right) ); REQUIRE( cs.has(Channel::Left) ); } diff --git a/components/rgbd-sources/test/frame_unit.cpp b/components/rgbd-sources/test/frame_unit.cpp index 9f3c5b33eb450087959bb560f6c7ea15732a0581..1d1648b2139440f08c62379bffc6f2dec356112d 100644 --- a/components/rgbd-sources/test/frame_unit.cpp +++ b/components/rgbd-sources/test/frame_unit.cpp @@ -32,7 +32,7 @@ TEST_CASE("Frame::get()", "") { bool hadexception = false; try { - auto &m = f.get<cv::Mat>(Channel::Colour); + f.get<cv::Mat>(Channel::Colour); } catch (ftl::exception &e) { hadexception = true; } @@ -45,7 +45,7 @@ TEST_CASE("Frame::get()", "") { bool hadexception = false; try { - auto &m = f.get<cv::cuda::GpuMat>(Channel::Colour); + f.get<cv::cuda::GpuMat>(Channel::Colour); } catch (ftl::exception &e) { hadexception = true; } @@ -138,7 +138,7 @@ TEST_CASE("Frame::createTexture()", "") { bool hadexception = false; try { - auto &t = f.createTexture<float>(Channel::Depth); + f.createTexture<float>(Channel::Depth); } catch (ftl::exception &e) { hadexception = true; } @@ -169,7 +169,7 @@ TEST_CASE("Frame::createTexture()", "") { try { f.create<cv::Mat>(Channel::Depth, Format<uchar4>(100,100)); - auto &t = f.createTexture<float>(Channel::Depth); + f.createTexture<float>(Channel::Depth); } catch (ftl::exception &e) { hadexception = true; } @@ -228,7 +228,7 @@ TEST_CASE("Frame::getTexture()", "") { bool hadexception = false; try { - auto &t = f.getTexture<float>(Channel::Depth); + f.getTexture<float>(Channel::Depth); } catch (ftl::exception &e) { hadexception = true; } @@ -242,7 +242,7 @@ TEST_CASE("Frame::getTexture()", "") { try { f.createTexture<uchar4>(Channel::Depth, Format<uchar4>(100,100)); - auto &t = f.getTexture<float>(Channel::Depth); + f.getTexture<float>(Channel::Depth); } catch (ftl::exception &e) { hadexception = true; } diff --git a/components/rgbd-sources/test/source_unit.cpp b/components/rgbd-sources/test/source_unit.cpp index 4b14bee1887c956a2b646009b82d779e663b97d7..dca38be2ffb6e06b8be416c8de71a7a799c77867 100644 --- a/components/rgbd-sources/test/source_unit.cpp +++ b/components/rgbd-sources/test/source_unit.cpp @@ -14,7 +14,7 @@ class Snapshot {}; class SnapshotReader { public: - SnapshotReader(const std::string &) {} + explicit SnapshotReader(const std::string &) {} Snapshot readArchive() { return Snapshot(); }; }; @@ -22,7 +22,7 @@ namespace detail { class ImageSource : public ftl::rgbd::detail::Source { public: - ImageSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { + explicit ImageSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { last_type = "image"; } ImageSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) { @@ -37,7 +37,7 @@ class ImageSource : public ftl::rgbd::detail::Source { class StereoVideoSource : public ftl::rgbd::detail::Source { public: - StereoVideoSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { + explicit StereoVideoSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { last_type = "video"; } StereoVideoSource(ftl::rgbd::Source *host, const std::string &f) : ftl::rgbd::detail::Source(host) { @@ -52,7 +52,7 @@ class StereoVideoSource : public ftl::rgbd::detail::Source { class NetSource : public ftl::rgbd::detail::Source { public: - NetSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { + explicit NetSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { last_type = "net"; } @@ -76,7 +76,7 @@ class SnapshotSource : public ftl::rgbd::detail::Source { class RealsenseSource : public ftl::rgbd::detail::Source { public: - RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { + explicit RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { last_type = "realsense"; } @@ -122,11 +122,11 @@ using ftl::rgbd::Source; using ftl::config::json_t; TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { - json_t global = {{"$id","ftl://test"}}; + json_t global = json_t{{"$id","ftl://test"}}; ftl::config::configure(global); SECTION("with valid image file uri") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/1"}, {"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"} }; @@ -139,7 +139,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } SECTION("with valid video file uri") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/2"}, {"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/video.mp4"} }; @@ -152,7 +152,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } SECTION("with valid net uri") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/2"}, {"uri","ftl://utu.fi/dummy"} }; @@ -165,7 +165,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } SECTION("with an invalid uri") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/2"}, {"uri","not a uri"} }; @@ -177,7 +177,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } SECTION("with an invalid file uri") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/2"}, {"uri","file:///not/a/file"} }; @@ -189,7 +189,7 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } SECTION("with a missing file") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/2"}, {"uri","file:///data/image2.png"} }; @@ -202,11 +202,11 @@ TEST_CASE("ftl::create<Source>(cfg)", "[rgbd]") { } TEST_CASE("Source::set(uri)", "[rgbd]") { - json_t global = {{"$id","ftl://test"}}; + json_t global = json_t{{"$id","ftl://test"}}; ftl::config::configure(global); SECTION("change to different valid URI type") { - json_t cfg = { + json_t cfg = json_t{ {"$id","ftl://test/1"}, {"uri","file://" FTL_SOURCE_DIRECTORY "/components/rgbd-sources/test/data/image.png"} };