From bff654a070f705f7fe28c8af27b2f8d0eaa02433 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Mon, 23 Feb 2015 19:29:17 +0100 Subject: [PATCH] Add screen capture functionality --- idl/gepetto/viewer/graphical-interface.idl | 15 ++++++++ src/graphical-interface.impl.cpp | 41 ++++++++++++++++++++++ src/graphical-interface.impl.hh | 3 ++ 3 files changed, 59 insertions(+) diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl index 90ef3cd..de23ed8 100644 --- a/idl/gepetto/viewer/graphical-interface.idl +++ b/idl/gepetto/viewer/graphical-interface.idl @@ -208,6 +208,21 @@ typedef double Color [4]; /// \param input nodeName : name of the node. /// \param input lightingMode : lighting mode can be "ON" or "OFF". boolean setLightingMode(in string nodeName, in string lightingMode) raises (Error); + + /// Start capturing a window into image files. + /// \param windowId the ID of the window + /// \param filename, extension image files will be + /// '<filename>_<sequence_number>.<extension>' + /// + /// \note To make a movie from the sequence of images, you can run: + /// \code + /// ffmpeg -r 25 -b 1800 -i capture_0_%d.jpeg video.mp4 + /// \endcode + boolean startCapture (in unsigned long windowId, in string filename, + in string extension) raises (Error); + + /// Stop the running capture of a window. + boolean stopCapture (in unsigned long windowId) raises (Error); }; }; }; diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp index 73758f0..1506a3b 100644 --- a/src/graphical-interface.impl.cpp +++ b/src/graphical-interface.impl.cpp @@ -200,6 +200,9 @@ namespace graphics { it != newNodeConfigurations_.end (); it++) { (*it).node->applyConfiguration ( (*it).position, (*it).quat); } + for (WindowManagers_t::iterator it = windowManagers_.begin (); + it!=windowManagers_.end (); ++it) + (*it)->frame (); mtx_.unlock (); newNodeConfigurations_.clear (); } catch (const std::exception& exc) { @@ -803,6 +806,44 @@ namespace graphics { throw Error (exc.what ()); } } + + bool GraphicalInterface::startCapture (const WindowID windowId, const char* filename, + const char* extension) + throw (Error) + { + try { + if (windowId >= 0 || windowId < windowManagers_.size ()) { + windowManagers_[windowId]->startCapture + (std::string (filename), std::string (extension)); + return true; + } + else { + std::cout << "Window ID " << windowId + << " doesn't exist." << std::endl; + return false; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } + + bool GraphicalInterface::stopCapture (const WindowID windowId) + throw (Error) + { + try { + if (windowId >= 0 || windowId < windowManagers_.size ()) { + windowManagers_[windowId]->stopCapture (); + return true; + } + else { + std::cout << "Window ID " << windowId + << " doesn't exist." << std::endl; + return false; + } + } catch (const std::exception& exc) { + throw Error (exc.what ()); + } + } } //end namespace impl } //end namespace corbaServer } //end namespace graphics diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh index b7a6f18..32cbe26 100644 --- a/src/graphical-interface.impl.hh +++ b/src/graphical-interface.impl.hh @@ -133,6 +133,9 @@ public: virtual bool setWireFrameMode(const char* nodeNameCorba, const char* wireFrameModeCorba) throw (Error); virtual bool setLightingMode(const char* nodeNameCorba, const char* lightingModeCorba) throw (Error); + virtual bool startCapture (const WindowID windowId, const char* filename, + const char* extension) throw (Error); + virtual bool stopCapture (const WindowID windowId) throw (Error); }; // end of class } /* namespace impl */ -- GitLab