From 3ce5684dec769b6db13d01bf96f93791b82ec105 Mon Sep 17 00:00:00 2001 From: Sebastian Hahta <joseha@utu.fi> Date: Fri, 7 Jun 2019 16:27:01 +0300 Subject: [PATCH] fix snapshot build; add snapshot button to GUI --- applications/gui/src/src_window.cpp | 37 +++++++++++++++++-- components/common/cpp/include/ftl/config.h.in | 1 + components/rgbd-sources/CMakeLists.txt | 8 ++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/applications/gui/src/src_window.cpp b/applications/gui/src/src_window.cpp index 008933886..f3e84b511 100644 --- a/applications/gui/src/src_window.cpp +++ b/applications/gui/src/src_window.cpp @@ -8,6 +8,10 @@ #include <nanogui/screen.h> #include <nanogui/layout.h> +#ifdef HAVE_LIBARCHIVE +#include "ftl/snapshot.hpp" +#endif + using ftl::gui::SourceWindow; using ftl::rgbd::RGBDSource; using std::string; @@ -175,11 +179,36 @@ SourceWindow::SourceWindow(nanogui::Widget *parent, ftl::ctrl::Master *ctrl) image_->setDepth(state); }); +#ifdef HAVE_LIBARCHIVE + auto snapshot = new Button(tools, "Snapshot"); + snapshot->setCallback([this] { + try { + char timestamp[18]; + std::time_t t=std::time(NULL); + std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t)); + auto writer = ftl::rgbd::SnapshotWriter(std::string(timestamp) + ".tar.gz"); + cv::Mat rgb, depth; + this->src_->getRGBD(rgb, depth); + if (!writer.addCameraRGBD( + "0", // TODO + rgb, + depth, + this->src_->getPose(), + this->src_->getParameters() + )) { + LOG(ERROR) << "Snapshot failed"; + } + } + catch(std::runtime_error) { + LOG(ERROR) << "Snapshot failed (file error)"; + } + }); +#endif - auto imageView = new VirtualCameraView(this); - //cam.view = imageView; - imageView->setGridThreshold(20); - imageView->setSource(src_); + auto imageView = new VirtualCameraView(this); + //cam.view = imageView; + imageView->setGridThreshold(20); + imageView->setSource(src_); image_ = imageView; } diff --git a/components/common/cpp/include/ftl/config.h.in b/components/common/cpp/include/ftl/config.h.in index 296da9eec..67dc859e6 100644 --- a/components/common/cpp/include/ftl/config.h.in +++ b/components/common/cpp/include/ftl/config.h.in @@ -20,6 +20,7 @@ #cmakedefine HAVE_RENDER #cmakedefine HAVE_LIBSGM #cmakedefine HAVE_NANOGUI +#cmakedefine HAVE_LIBARCHIVE extern const char *FTL_VERSION_LONG; extern const char *FTL_VERSION; diff --git a/components/rgbd-sources/CMakeLists.txt b/components/rgbd-sources/CMakeLists.txt index fe8281440..d1326ec16 100644 --- a/components/rgbd-sources/CMakeLists.txt +++ b/components/rgbd-sources/CMakeLists.txt @@ -12,12 +12,12 @@ set(RGBDSRC src/algorithms/opencv_bm.cpp ) -if (LIBARCHIVE_FOUND) +if (LibArchive_FOUND) list(APPEND RGBDSRC - "src/snapshot.cpp" - "src/snapshot_source.cpp" + src/snapshot.cpp + src/snapshot_source.cpp ) -endif (LIBARCHIVE_FOUND) +endif (LibArchive_FOUND) if (LIBSGM_FOUND) list(APPEND RGBDSRC "src/algorithms/fixstars_sgm.cpp") -- GitLab