diff --git a/src/common/detail/clvacontext.cpp b/src/common/detail/clvacontext.cpp index 8c54aaadc..dd2344b49 100644 --- a/src/common/detail/clvacontext.cpp +++ b/src/common/detail/clvacontext.cpp @@ -11,25 +11,25 @@ namespace cv { namespace viz { namespace detail { -CLVAContext::CLVAContext(FrameBufferContext &clglContext) : +CLVAContext::CLVAContext(FrameBufferContext& clglContext) : clglContext_(clglContext) { } void CLVAContext::setVideoFrameSize(const cv::Size& sz) { - if(videoFrameSize_ != cv::Size(0,0)) + if (videoFrameSize_ != cv::Size(0, 0)) assert(videoFrameSize_ == sz || "Input and output video sizes don't match"); videoFrameSize_ = sz; } cv::Size CLVAContext::getVideoFrameSize() { - assert(videoFrameSize_ == cv::Size(0,0) || "Video frame size not initialized"); + assert(videoFrameSize_ == cv::Size(0, 0) || "Video frame size not initialized"); return videoFrameSize_; } bool CLVAContext::capture(std::function fn) { { - if(!context_ .empty()) { + if (!context_.empty()) { #ifndef __EMSCRIPTEN__ CLExecScope_t scope(context_); #endif diff --git a/src/common/detail/clvacontext.hpp b/src/common/detail/clvacontext.hpp index f60358f54..e43e5518f 100644 --- a/src/common/detail/clvacontext.hpp +++ b/src/common/detail/clvacontext.hpp @@ -16,7 +16,7 @@ namespace detail { class CLVAContext { friend class cv::viz::Viz2D; CLExecContext_t context_; - FrameBufferContext &clglContext_; + FrameBufferContext& clglContext_; cv::UMat frameBuffer_; cv::UMat videoFrame_; cv::UMat rgbBuffer_; @@ -24,7 +24,7 @@ class CLVAContext { cv::Size videoFrameSize_; CLExecContext_t getCLExecContext(); public: - CLVAContext(FrameBufferContext &fbContext); + CLVAContext(FrameBufferContext& fbContext); cv::Size getVideoFrameSize(); void setVideoFrameSize(const cv::Size& sz); bool capture(std::function fn); diff --git a/src/common/detail/framebuffercontext.cpp b/src/common/detail/framebuffercontext.cpp index f46f4add4..d70f3944c 100644 --- a/src/common/detail/framebuffercontext.cpp +++ b/src/common/detail/framebuffercontext.cpp @@ -19,7 +19,7 @@ FrameBufferContext::FrameBufferContext(const cv::Size& frameBufferSize) : glewExperimental = true; glewInit(); try { - if(is_cl_gl_sharing_supported()) + if (is_cl_gl_sharing_supported()) cv::ogl::ocl::initializeContextFromGL(); else clglSharing_ = false; @@ -39,13 +39,17 @@ FrameBufferContext::FrameBufferContext(const cv::Size& frameBufferSize) : GL_CHECK(glBindTexture(GL_TEXTURE_2D, textureID_)); texture_ = new cv::ogl::Texture2D(frameBufferSize_, cv::ogl::Texture2D::RGBA, textureID_); GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); - GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frameBufferSize_.width, frameBufferSize_.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0)); + GL_CHECK( + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, frameBufferSize_.width, frameBufferSize_.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0)); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID_)); - GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, frameBufferSize_.width, frameBufferSize_.height)); - GL_CHECK(glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_)); + GL_CHECK( + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, frameBufferSize_.width, frameBufferSize_.height)); + GL_CHECK( + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_)); - GL_CHECK(glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0)); + GL_CHECK( + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0)); assert(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); #ifndef __EMSCRIPTEN__ context_ = CLExecContext_t::getCurrent(); @@ -55,8 +59,8 @@ FrameBufferContext::FrameBufferContext(const cv::Size& frameBufferSize) : FrameBufferContext::~FrameBufferContext() { end(); glDeleteTextures(1, &textureID_); - glDeleteRenderbuffers( 1, &renderBufferID_); - glDeleteFramebuffers( 1, &frameBufferID_); + glDeleteRenderbuffers(1, &renderBufferID_); + glDeleteFramebuffers(1, &frameBufferID_); } cv::Size FrameBufferContext::getSize() { @@ -82,25 +86,24 @@ CLExecContext_t& FrameBufferContext::getCLExecContext() { } #endif -void FrameBufferContext::blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize, bool stretch) { +void FrameBufferContext::blitFrameBufferToScreen(const cv::Rect& viewport, + const cv::Size& windowSize, bool stretch) { GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, frameBufferID_)); GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0)); GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); - GL_CHECK(glBlitFramebuffer( - viewport.x, viewport.y, viewport.x + viewport.width, viewport.y + viewport.height, - stretch ? 0 : windowSize.width - frameBufferSize_.width, - stretch ? 0 : windowSize.height - frameBufferSize_.height, - stretch ? windowSize.width : frameBufferSize_.width, - stretch ? windowSize.height : frameBufferSize_.height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); + GL_CHECK( + glBlitFramebuffer( viewport.x, viewport.y, viewport.x + viewport.width, viewport.y + viewport.height, stretch ? 0 : windowSize.width - frameBufferSize_.width, stretch ? 0 : windowSize.height - frameBufferSize_.height, stretch ? windowSize.width : frameBufferSize_.width, stretch ? windowSize.height : frameBufferSize_.height, GL_COLOR_BUFFER_BIT, GL_NEAREST)); } void FrameBufferContext::begin() { GL_CHECK(glGetIntegerv( GL_VIEWPORT, viewport_ )); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID_)); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, renderBufferID_)); - GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_)); + GL_CHECK( + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBufferID_)); GL_CHECK(glBindTexture(GL_TEXTURE_2D, textureID_)); - GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0)); + GL_CHECK( + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID_, 0)); assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE); } @@ -123,25 +126,16 @@ void FrameBufferContext::download(cv::UMat& m) { void FrameBufferContext::upload(const cv::UMat& m) { cv::Mat tmp = m.getMat(cv::ACCESS_READ); assert(tmp.data != nullptr); - GL_CHECK(glTexSubImage2D( - GL_TEXTURE_2D, - 0, - 0, - 0, - tmp.cols, - tmp.rows, - GL_RGBA, - GL_UNSIGNED_BYTE, - tmp.data) - ); + GL_CHECK( + glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tmp.cols, tmp.rows, GL_RGBA, GL_UNSIGNED_BYTE, tmp.data)); tmp.release(); } -void FrameBufferContext::acquireFromGL(cv::UMat &m) { - if(clglSharing_) { +void FrameBufferContext::acquireFromGL(cv::UMat& m) { + if (clglSharing_) { GL_CHECK(cv::ogl::convertFromGLTexture2D(getTexture2D(), m)); } else { - if(m.empty()) + if (m.empty()) m.create(getSize(), CV_8UC4); download(m); GL_CHECK(glFlush()); @@ -151,13 +145,13 @@ void FrameBufferContext::acquireFromGL(cv::UMat &m) { cv::flip(m, m, 0); } -void FrameBufferContext::releaseToGL(cv::UMat &m) { +void FrameBufferContext::releaseToGL(cv::UMat& m) { //FIXME cv::flip(m, m, 0); - if(clglSharing_) { + if (clglSharing_) { GL_CHECK(cv::ogl::convertToGLTexture2D(m, getTexture2D())); } else { - if(m.empty()) + if (m.empty()) m.create(getSize(), CV_8UC4); upload(m); GL_CHECK(glFlush()); diff --git a/src/common/detail/framebuffercontext.hpp b/src/common/detail/framebuffercontext.hpp index 5709c3deb..ce43475a2 100644 --- a/src/common/detail/framebuffercontext.hpp +++ b/src/common/detail/framebuffercontext.hpp @@ -50,13 +50,15 @@ class FrameBufferContext { #ifndef __EMSCRIPTEN__ CLExecContext_t& getCLExecContext(); #endif - void blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize, bool stretch = false); + void blitFrameBufferToScreen(const cv::Rect& viewport, const cv::Size& windowSize, + bool stretch = false); public: class FrameBufferScope { FrameBufferContext& ctx_; cv::UMat& m_; public: - FrameBufferScope(FrameBufferContext& ctx, cv::UMat& m) : ctx_(ctx), m_(m) { + FrameBufferScope(FrameBufferContext& ctx, cv::UMat& m) : + ctx_(ctx), m_(m) { ctx_.acquireFromGL(m_); } @@ -68,7 +70,8 @@ public: class GLScope { FrameBufferContext& ctx_; public: - GLScope(FrameBufferContext& ctx) : ctx_(ctx) { + GLScope(FrameBufferContext& ctx) : + ctx_(ctx) { ctx_.begin(); } @@ -86,8 +89,8 @@ protected: void end(); void download(cv::UMat& m); void upload(const cv::UMat& m); - void acquireFromGL(cv::UMat &m); - void releaseToGL(cv::UMat &m); + void acquireFromGL(cv::UMat& m); + void releaseToGL(cv::UMat& m); cv::UMat frameBuffer_; cv::ogl::Texture2D* texture_ = nullptr; }; diff --git a/src/common/detail/nanovgcontext.cpp b/src/common/detail/nanovgcontext.cpp index 41a10c7e3..15b584db5 100644 --- a/src/common/detail/nanovgcontext.cpp +++ b/src/common/detail/nanovgcontext.cpp @@ -10,7 +10,7 @@ namespace cv { namespace viz { namespace detail { -NanoVGContext::NanoVGContext(Viz2D &v2d, NVGcontext *context, FrameBufferContext &fbContext) : +NanoVGContext::NanoVGContext(Viz2D& v2d, NVGcontext* context, FrameBufferContext& fbContext) : v2d_(v2d), context_(context), clglContext_(fbContext) { //FIXME workaround for first frame color glitch cv::UMat tmp; @@ -23,8 +23,7 @@ void NanoVGContext::render(std::function fn) { #endif FrameBufferContext::GLScope glScope(clglContext_); NanoVGContext::Scope nvgScope(*this); - cv::viz::nvg::detail::NVG::setCurrentContext(context_), - fn(clglContext_.getSize()); + cv::viz::nvg::detail::NVG::setCurrentContext(context_), fn(clglContext_.getSize()); } void push() { diff --git a/src/common/detail/nanovgcontext.hpp b/src/common/detail/nanovgcontext.hpp index 3962370b6..808a2a7db 100644 --- a/src/common/detail/nanovgcontext.hpp +++ b/src/common/detail/nanovgcontext.hpp @@ -23,13 +23,14 @@ namespace viz { namespace detail { class NanoVGContext { Viz2D& v2d_; - NVGcontext *context_; - FrameBufferContext &clglContext_; + NVGcontext* context_; + FrameBufferContext& clglContext_; public: class Scope { NanoVGContext& ctx_; public: - Scope(NanoVGContext& ctx) : ctx_(ctx) { + Scope(NanoVGContext& ctx) : + ctx_(ctx) { ctx_.begin(); } @@ -37,7 +38,7 @@ public: ctx_.end(); } }; - NanoVGContext(Viz2D& v2d, NVGcontext *context, FrameBufferContext &fbContext); + NanoVGContext(Viz2D& v2d, NVGcontext* context, FrameBufferContext& fbContext); void render(std::function fn); private: void begin(); diff --git a/src/common/dialog.cpp b/src/common/dialog.cpp index 9bd0af961..d17a5a292 100644 --- a/src/common/dialog.cpp +++ b/src/common/dialog.cpp @@ -10,11 +10,13 @@ namespace cv { namespace viz { +std::function Dialog::viz2DWin_Xcomparator([](Dialog* lhs, Dialog* rhs) { + return lhs->position()[0] < rhs->position()[0]; +}); +std::set Dialog::all_windows_xsorted_( + viz2DWin_Xcomparator); -std::function Dialog::viz2DWin_Xcomparator([](Dialog* lhs, Dialog* rhs){ return lhs->position()[0] < rhs->position()[0]; }); -std::set Dialog::all_windows_xsorted_(viz2DWin_Xcomparator); - -Dialog::Dialog(nanogui::Screen *screen, int x, int y, const string &title) : +Dialog::Dialog(nanogui::Screen* screen, int x, int y, const string& title) : Window(screen, title), screen_(screen), lastDragPos_(x, y) { all_windows_xsorted_.insert(this); oldLayout_ = new nanogui::AdvancedGridLayout( { 10, 0, 10, 0 }, { }); @@ -34,7 +36,7 @@ Dialog::Dialog(nanogui::Screen *screen, int x, int y, const string &title) : this->minBtn_->set_visible(true); this->maxBtn_->set_visible(false); - for (auto *child : this->children()) { + for (auto* child : this->children()) { child->set_visible(true); } @@ -48,7 +50,7 @@ Dialog::Dialog(nanogui::Screen *screen, int x, int y, const string &title) : this->minBtn_->set_visible(false); this->maxBtn_->set_visible(true); - for (auto *child : this->children()) { + for (auto* child : this->children()) { child->set_visible(false); } this->set_size( { 0, 0 }); @@ -61,18 +63,18 @@ Dialog::Dialog(nanogui::Screen *screen, int x, int y, const string &title) : this->maximizedPos_ = this->position(); for (Dialog* win : all_windows_xsorted_) { - if(win != this && win->isMinimized()) { + if (win != this && win->isMinimized()) { x = win->position()[0]; gap = lastX + x; - if(gap >= w) { - this->set_position({lastX, screen_->height() - this->height()}); + if (gap >= w) { + this->set_position( { lastX, screen_->height() - this->height() }); break; } lastX = x + win->width() + 1; } } - if(gap < w) { - this->set_position({lastX, screen_->height() - this->height()}); + if (gap < w) { + this->set_position( { lastX, screen_->height() - this->height() }); } this->minimized_ = true; }); @@ -86,19 +88,26 @@ bool Dialog::isMinimized() { return minimized_; } -bool Dialog::mouse_drag_event(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int mods) { +bool Dialog::mouse_drag_event(const nanogui::Vector2i& p, const nanogui::Vector2i& rel, int button, + int mods) { if (m_drag && (button & (1 << GLFW_MOUSE_BUTTON_1)) != 0) { - if(maxBtn_->visible()) { - for (auto *win : all_windows_xsorted_) { + if (maxBtn_->visible()) { + for (auto* win : all_windows_xsorted_) { if (win != this) { if (win->contains(this->position()) - || win->contains( { this->position()[0] + this->size()[0], this->position()[1] + this->size()[1] }) - || win->contains( { this->position()[0], this->position()[1] + this->size()[1] }) - || win->contains( { this->position()[0] + this->size()[0], this->position()[1] }) + || win->contains( + { this->position()[0] + this->size()[0], this->position()[1] + + this->size()[1] }) || win->contains( { + this->position()[0], this->position()[1] + this->size()[1] }) + || win->contains( + { this->position()[0] + this->size()[0], this->position()[1] }) || this->contains(win->position()) - || this->contains( { win->position()[0] + win->size()[0], win->position()[1] + win->size()[1] }) - || this->contains( { win->position()[0], win->position()[1] + win->size()[1] }) - || this->contains( { win->position()[0] + win->size()[0], win->position()[1] })) { + || this->contains( + { win->position()[0] + win->size()[0], win->position()[1] + + win->size()[1] }) || this->contains( { + win->position()[0], win->position()[1] + win->size()[1] }) + || this->contains( { win->position()[0] + win->size()[0], + win->position()[1] })) { this->set_position(lastDragPos_); return true; } diff --git a/src/common/dialog.hpp b/src/common/dialog.hpp index 8632f77b5..55ca3b8a2 100644 --- a/src/common/dialog.hpp +++ b/src/common/dialog.hpp @@ -16,7 +16,7 @@ namespace viz { using std::string; -class Dialog : public nanogui::Window { +class Dialog: public nanogui::Window { private: static std::function viz2DWin_Xcomparator; static std::set all_windows_xsorted_; @@ -32,7 +32,8 @@ public: Dialog(nanogui::Screen* screen, int x, int y, const string& title); virtual ~Dialog(); bool isMinimized(); - bool mouse_drag_event(const nanogui::Vector2i &p, const nanogui::Vector2i &rel, int button, int mods) override; + bool mouse_drag_event(const nanogui::Vector2i& p, const nanogui::Vector2i& rel, int button, + int mods) override; }; } /* namespace viz2d */ diff --git a/src/common/formhelper.cpp b/src/common/formhelper.cpp index 078c5cb45..70bc4a1b4 100644 --- a/src/common/formhelper.cpp +++ b/src/common/formhelper.cpp @@ -8,23 +8,25 @@ namespace cv { namespace viz { -FormHelper::FormHelper(nanogui::Screen* screen) : nanogui::FormHelper(screen) { +FormHelper::FormHelper(nanogui::Screen* screen) : + nanogui::FormHelper(screen) { } FormHelper::~FormHelper() { } -Dialog* FormHelper::makeWindow(int x, int y, const string &title) { +Dialog* FormHelper::makeWindow(int x, int y, const string& title) { auto* win = new cv::viz::Dialog(m_screen, x, y, title); this->set_window(win); return win; } -nanogui::Label* FormHelper::makeGroup(const string &label) { +nanogui::Label* FormHelper::makeGroup(const string& label) { return add_group(label); } -nanogui::detail::FormWidget* FormHelper::makeFormVariable(const string &name, bool &v, const string &tooltip, bool visible, bool enabled) { +nanogui::detail::FormWidget* FormHelper::makeFormVariable(const string& name, bool& v, + const string& tooltip, bool visible, bool enabled) { auto var = add_variable(name, v); var->set_enabled(enabled); var->set_visible(visible); @@ -33,13 +35,15 @@ nanogui::detail::FormWidget* FormHelper::makeFormVariable(const string &na return var; } -nanogui::ColorPicker* FormHelper::makeColorPicker(const string& label, nanogui::Color& color, const string& tooltip, std::function fn, bool visible, bool enabled) { +nanogui::ColorPicker* FormHelper::makeColorPicker(const string& label, nanogui::Color& color, + const string& tooltip, std::function fn, bool visible, + bool enabled) { auto* colorPicker = add_variable(label, color); colorPicker->set_enabled(enabled); colorPicker->set_visible(visible); if (!tooltip.empty()) - colorPicker->set_tooltip(tooltip); - if(fn) + colorPicker->set_tooltip(tooltip); + if (fn) colorPicker->set_final_callback(fn); return colorPicker; diff --git a/src/common/formhelper.hpp b/src/common/formhelper.hpp index 44fe53cd7..1a54a2093 100644 --- a/src/common/formhelper.hpp +++ b/src/common/formhelper.hpp @@ -3,7 +3,6 @@ // of this distribution and at http://opencv.org/license.html. // Copyright Amir Hassan (kallaballa) - #ifndef SRC_COMMON_FORMHELPER_HPP_ #define SRC_COMMON_FORMHELPER_HPP_ #include "dialog.hpp" @@ -13,7 +12,6 @@ #include - namespace cv { namespace viz { using std::string; @@ -24,8 +22,11 @@ public: Dialog* makeWindow(int x, int y, const string& title); nanogui::Label* makeGroup(const string& label); - nanogui::detail::FormWidget* makeFormVariable(const string &name, bool &v, const string &tooltip = "", bool visible = true, bool enabled = true); - template nanogui::detail::FormWidget* makeFormVariable(const string &name, T &v, const T &min, const T &max, bool spinnable, const string &unit, const string tooltip, bool visible = true, bool enabled = true) { + nanogui::detail::FormWidget* makeFormVariable(const string& name, bool& v, + const string& tooltip = "", bool visible = true, bool enabled = true); + template nanogui::detail::FormWidget* makeFormVariable(const string& name, T& v, + const T& min, const T& max, bool spinnable, const string& unit, const string tooltip, + bool visible = true, bool enabled = true) { auto var = this->add_variable(name, v); var->set_enabled(enabled); var->set_visible(visible); @@ -39,8 +40,11 @@ public: return var; } - nanogui::ColorPicker* makeColorPicker(const string& label, nanogui::Color& color, const string& tooltip = "", std::function fn = nullptr, bool visible = true, bool enabled = true); - template nanogui::ComboBox* makeComboBox(const string &label, T& e, const std::vector& items) { + nanogui::ColorPicker* makeColorPicker(const string& label, nanogui::Color& color, + const string& tooltip = "", std::function fn = nullptr, + bool visible = true, bool enabled = true); + template nanogui::ComboBox* makeComboBox(const string& label, T& e, + const std::vector& items) { auto* var = this->add_variable(label, e, true); var->set_items(items); return var; diff --git a/src/common/nvg.cpp b/src/common/nvg.cpp index 6093005a8..41db25d98 100644 --- a/src/common/nvg.cpp +++ b/src/common/nvg.cpp @@ -14,7 +14,7 @@ class NVG; NVG* NVG::nvg_instance_ = nullptr; void NVG::setCurrentContext(NVGcontext* ctx) { - if(nvg_instance_ != nullptr) + if (nvg_instance_ != nullptr) delete nvg_instance_; nvg_instance_ = new NVG(ctx); } @@ -84,11 +84,13 @@ float NVG::textBounds(float x, float y, const char* string, const char* end, flo return nvgTextBounds(getContext(), x, y, string, end, bounds); } -void NVG::textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds) { +void NVG::textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, + float* bounds) { nvgTextBoxBounds(getContext(), x, y, breakRowWidth, string, end, bounds); } -int NVG::textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions) { +int NVG::textGlyphPositions(float x, float y, const char* string, const char* end, + GlyphPosition* positions, int maxPositions) { return nvgTextGlyphPositions(getContext(), x, y, string, end, positions, maxPositions); } @@ -96,8 +98,9 @@ void NVG::textMetrics(float* ascender, float* descender, float* lineh) { nvgTextMetrics(getContext(), ascender, descender, lineh); } -int NVG::textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows) { - return nvgTextBreakLines(getContext(),string, end, breakRowWidth, rows, maxRows); +int NVG::textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, + int maxRows) { + return nvgTextBreakLines(getContext(), string, end, breakRowWidth, rows, maxRows); } void NVG::save() { @@ -117,7 +120,7 @@ void NVG::shapeAntiAlias(int enabled) { } void NVG::strokeColor(const cv::Scalar& bgra) { - nvgStrokeColor(getContext(), nvgRGBA(bgra[2],bgra[1],bgra[0],bgra[3])); + nvgStrokeColor(getContext(), nvgRGBA(bgra[2], bgra[1], bgra[0], bgra[3])); } void NVG::strokePaint(Paint paint) { @@ -126,7 +129,7 @@ void NVG::strokePaint(Paint paint) { } void NVG::fillColor(const cv::Scalar& bgra) { - nvgFillColor(getContext(), nvgRGBA(bgra[2],bgra[1],bgra[0],bgra[3])); + nvgFillColor(getContext(), nvgRGBA(bgra[2], bgra[1], bgra[0], bgra[3])); } void NVG::fillPaint(Paint paint) { @@ -278,8 +281,10 @@ void NVG::roundedRect(float x, float y, float w, float h, float r) { nvgRoundedRect(getContext(), x, y, w, h, r); } -void NVG::roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft) { - nvgRoundedRectVarying(getContext(), x, y, w, h, radTopLeft, radTopRight, radBottomRight, radBottomLeft); +void NVG::roundedRectVarying(float x, float y, float w, float h, float radTopLeft, + float radTopRight, float radBottomRight, float radBottomLeft) { + nvgRoundedRectVarying(getContext(), x, y, w, h, radTopLeft, radTopRight, radBottomRight, + radBottomLeft); } void NVG::ellipse(float cx, float cy, float rx, float ry) { @@ -298,22 +303,32 @@ void NVG::stroke() { nvgStroke(getContext()); } -Paint NVG::linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol) { - NVGpaint np = nvgLinearGradient(getContext(), sx, sy, ex, ey, nvgRGBA(icol[2],icol[1],icol[0],icol[3]), nvgRGBA(ocol[2],ocol[1],ocol[0],ocol[3])); +Paint NVG::linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, + const cv::Scalar& ocol) { + NVGpaint np = nvgLinearGradient(getContext(), sx, sy, ex, ey, + nvgRGBA(icol[2], icol[1], icol[0], icol[3]), + nvgRGBA(ocol[2], ocol[1], ocol[0], ocol[3])); return Paint(np); } -Paint NVG::boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol) { - NVGpaint np = nvgBoxGradient(getContext(), x, y, w, h, r, f, nvgRGBA(icol[2],icol[1],icol[0],icol[3]), nvgRGBA(ocol[2],ocol[1],ocol[0],ocol[3])); +Paint NVG::boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, + const cv::Scalar& ocol) { + NVGpaint np = nvgBoxGradient(getContext(), x, y, w, h, r, f, + nvgRGBA(icol[2], icol[1], icol[0], icol[3]), + nvgRGBA(ocol[2], ocol[1], ocol[0], ocol[3])); return Paint(np); } -Paint NVG::radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, const cv::Scalar& ocol) { - NVGpaint np = nvgRadialGradient(getContext(), cx, cy, inr, outr, nvgRGBA(icol[2],icol[1],icol[0],icol[3]), nvgRGBA(ocol[2],ocol[1],ocol[0],ocol[3])); +Paint NVG::radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, + const cv::Scalar& ocol) { + NVGpaint np = nvgRadialGradient(getContext(), cx, cy, inr, outr, + nvgRGBA(icol[2], icol[1], icol[0], icol[3]), + nvgRGBA(ocol[2], ocol[1], ocol[0], ocol[3])); return Paint(np); } -Paint NVG::imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha) { +Paint NVG::imagePattern(float ox, float oy, float ex, float ey, float angle, int image, + float alpha) { NVGpaint np = nvgImagePattern(getContext(), ox, oy, ex, ey, angle, image, alpha); return Paint(np); } @@ -332,7 +347,7 @@ void NVG::resetScissor() { } int createFont(const char* name, const char* filename) { - return detail::NVG::getCurrentContext()->createFont(name,filename); + return detail::NVG::getCurrentContext()->createFont(name, filename); } int createFontMem(const char* name, unsigned char* data, int ndata, int freeData) { @@ -390,20 +405,25 @@ float textBounds(float x, float y, const char* string, const char* end, float* b return detail::NVG::getCurrentContext()->textBounds(x, y, string, end, bounds); } -void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds) { +void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, + float* bounds) { detail::NVG::getCurrentContext()->textBoxBounds(x, y, breakRowWidth, string, end, bounds); } -int textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions) { - return detail::NVG::getCurrentContext()->textGlyphPositions(x, y, string, end, positions, maxPositions); +int textGlyphPositions(float x, float y, const char* string, const char* end, + GlyphPosition* positions, int maxPositions) { + return detail::NVG::getCurrentContext()->textGlyphPositions(x, y, string, end, positions, + maxPositions); } void textMetrics(float* ascender, float* descender, float* lineh) { detail::NVG::getCurrentContext()->textMetrics(ascender, descender, lineh); } -int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows) { - return detail::NVG::getCurrentContext()->textBreakLines(string, end, breakRowWidth, rows, maxRows); +int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, + int maxRows) { + return detail::NVG::getCurrentContext()->textBreakLines(string, end, breakRowWidth, rows, + maxRows); } void save() { @@ -581,8 +601,10 @@ void roundedRect(float x, float y, float w, float h, float r) { detail::NVG::getCurrentContext()->roundedRect(x, y, w, h, r); } -void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft) { - detail::NVG::getCurrentContext()->roundedRectVarying(x, y, w, h, radTopLeft, radTopRight, radBottomRight, radBottomLeft); +void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, + float radBottomRight, float radBottomLeft) { + detail::NVG::getCurrentContext()->roundedRectVarying(x, y, w, h, radTopLeft, radTopRight, + radBottomRight, radBottomLeft); } void ellipse(float cx, float cy, float rx, float ry) { @@ -601,15 +623,18 @@ void stroke() { detail::NVG::getCurrentContext()->stroke(); } -Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol) { +Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, + const cv::Scalar& ocol) { return detail::NVG::getCurrentContext()->linearGradient(sx, sy, ex, ey, icol, ocol); } -Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol) { +Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, + const cv::Scalar& ocol) { return detail::NVG::getCurrentContext()->boxGradient(x, y, w, h, r, f, icol, ocol); } -Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, const cv::Scalar& ocol) { +Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, + const cv::Scalar& ocol) { return detail::NVG::getCurrentContext()->radialGradient(cx, cy, inr, outr, icol, ocol); } diff --git a/src/common/nvg.hpp b/src/common/nvg.hpp index 9042a8768..eeacbf5a7 100644 --- a/src/common/nvg.hpp +++ b/src/common/nvg.hpp @@ -19,10 +19,10 @@ namespace cv { namespace viz { namespace nvg { -struct TextRow : public NVGtextRow { +struct TextRow: public NVGtextRow { }; -struct GlyphPosition : public NVGglyphPosition { +struct GlyphPosition: public NVGglyphPosition { }; struct Paint { @@ -33,8 +33,10 @@ struct Paint { memcpy(this->extent, np.extent, sizeof(this->extent)); this->radius = np.radius; this->feather = np.feather; - this->innerColor = cv::Scalar(np.innerColor.rgba[2] * 255, np.innerColor.rgba[1] * 255, np.innerColor.rgba[0] * 255, np.innerColor.rgba[3] * 255); - this->outerColor = cv::Scalar(np.outerColor.rgba[2] * 255, np.outerColor.rgba[1] * 255, np.outerColor.rgba[0] * 255, np.outerColor.rgba[3] * 255); + this->innerColor = cv::Scalar(np.innerColor.rgba[2] * 255, np.innerColor.rgba[1] * 255, + np.innerColor.rgba[0] * 255, np.innerColor.rgba[3] * 255); + this->outerColor = cv::Scalar(np.outerColor.rgba[2] * 255, np.outerColor.rgba[1] * 255, + np.outerColor.rgba[0] * 255, np.outerColor.rgba[3] * 255); this->image = np.image; } @@ -44,8 +46,10 @@ struct Paint { memcpy(np.extent, this->extent, sizeof(this->extent)); np.radius = this->radius; np.feather = this->feather; - np.innerColor = nvgRGBA(this->innerColor[2], this->innerColor[1], this->innerColor[0], this->innerColor[3]); - np.outerColor = nvgRGBA(this->outerColor[2], this->outerColor[1], this->outerColor[0], this->outerColor[3]); + np.innerColor = nvgRGBA(this->innerColor[2], this->innerColor[1], this->innerColor[0], + this->innerColor[3]); + np.outerColor = nvgRGBA(this->outerColor[2], this->outerColor[1], this->outerColor[0], + this->outerColor[3]); np.image = this->image; return np; } @@ -67,7 +71,8 @@ class NVG { NVGcontext* ctx_ = nullptr; public: - NVG(NVGcontext* ctx) : ctx_(ctx) { + NVG(NVGcontext* ctx) : + ctx_(ctx) { } static void setCurrentContext(NVGcontext* ctx); @@ -79,87 +84,94 @@ public: } public: -int createFont(const char* name, const char* filename); -int createFontMem(const char* name, unsigned char* data, int ndata, int freeData); -int findFont(const char* name); -int addFallbackFontId(int baseFont, int fallbackFont); -int addFallbackFont(const char* baseFont, const char* fallbackFont); -void fontSize(float size); -void fontBlur(float blur); -void textLetterSpacing(float spacing); -void textLineHeight(float lineHeight); -void textAlign(int align); -void fontFaceId(int font); -void fontFace(const char* font); -float text(float x, float y, const char* string, const char* end); -void textBox(float x, float y, float breakRowWidth, const char* string, const char* end); -float textBounds(float x, float y, const char* string, const char* end, float* bounds); -void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds); -int textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions); -void textMetrics(float* ascender, float* descender, float* lineh); -int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows); + int createFont(const char* name, const char* filename); + int createFontMem(const char* name, unsigned char* data, int ndata, int freeData); + int findFont(const char* name); + int addFallbackFontId(int baseFont, int fallbackFont); + int addFallbackFont(const char* baseFont, const char* fallbackFont); + void fontSize(float size); + void fontBlur(float blur); + void textLetterSpacing(float spacing); + void textLineHeight(float lineHeight); + void textAlign(int align); + void fontFaceId(int font); + void fontFace(const char* font); + float text(float x, float y, const char* string, const char* end); + void textBox(float x, float y, float breakRowWidth, const char* string, const char* end); + float textBounds(float x, float y, const char* string, const char* end, float* bounds); + void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, + float* bounds); + int textGlyphPositions(float x, float y, const char* string, const char* end, + GlyphPosition* positions, int maxPositions); + void textMetrics(float* ascender, float* descender, float* lineh); + int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, + int maxRows); -void save(); -void restore(); -void reset(); + void save(); + void restore(); + void reset(); -void shapeAntiAlias(int enabled); -void strokeColor(const cv::Scalar& bgra); -void strokePaint(Paint paint); -void fillColor(const cv::Scalar& bgra); -void fillPaint(Paint paint); -void miterLimit(float limit); -void strokeWidth(float size); -void lineCap(int cap); -void lineJoin(int join); -void globalAlpha(float alpha); + void shapeAntiAlias(int enabled); + void strokeColor(const cv::Scalar& bgra); + void strokePaint(Paint paint); + void fillColor(const cv::Scalar& bgra); + void fillPaint(Paint paint); + void miterLimit(float limit); + void strokeWidth(float size); + void lineCap(int cap); + void lineJoin(int join); + void globalAlpha(float alpha); -void resetTransform(); -void transform(float a, float b, float c, float d, float e, float f); -void translate(float x, float y); -void rotate(float angle); -void skewX(float angle); -void skewY(float angle); -void scale(float x, float y); -void currentTransform(float* xform); -void transformIdentity(float* dst); -void transformTranslate(float* dst, float tx, float ty); -void transformScale(float* dst, float sx, float sy); -void transformRotate(float* dst, float a); -void transformSkewX(float* dst, float a); -void transformSkewY(float* dst, float a); -void transformMultiply(float* dst, const float* src); -void transformPremultiply(float* dst, const float* src); -int transformInverse(float* dst, const float* src); -void transformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy); + void resetTransform(); + void transform(float a, float b, float c, float d, float e, float f); + void translate(float x, float y); + void rotate(float angle); + void skewX(float angle); + void skewY(float angle); + void scale(float x, float y); + void currentTransform(float* xform); + void transformIdentity(float* dst); + void transformTranslate(float* dst, float tx, float ty); + void transformScale(float* dst, float sx, float sy); + void transformRotate(float* dst, float a); + void transformSkewX(float* dst, float a); + void transformSkewY(float* dst, float a); + void transformMultiply(float* dst, const float* src); + void transformPremultiply(float* dst, const float* src); + int transformInverse(float* dst, const float* src); + void transformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy); -float degToRad(float deg); -float radToDeg(float rad); + float degToRad(float deg); + float radToDeg(float rad); -void beginPath(); -void moveTo(float x, float y); -void lineTo(float x, float y); -void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y); -void quadTo(float cx, float cy, float x, float y); -void arcTo(float x1, float y1, float x2, float y2, float radius); -void closePath(); -void pathWinding(int dir); -void arc(float cx, float cy, float r, float a0, float a1, int dir); -void rect(float x, float y, float w, float h); -void roundedRect(float x, float y, float w, float h, float r); -void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft); -void ellipse(float cx, float cy, float rx, float ry); -void circle(float cx, float cy, float r); -void fill(); -void stroke(); + void beginPath(); + void moveTo(float x, float y); + void lineTo(float x, float y); + void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y); + void quadTo(float cx, float cy, float x, float y); + void arcTo(float x1, float y1, float x2, float y2, float radius); + void closePath(); + void pathWinding(int dir); + void arc(float cx, float cy, float r, float a0, float a1, int dir); + void rect(float x, float y, float w, float h); + void roundedRect(float x, float y, float w, float h, float r); + void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, + float radBottomRight, float radBottomLeft); + void ellipse(float cx, float cy, float rx, float ry); + void circle(float cx, float cy, float r); + void fill(); + void stroke(); -Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol); -Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol); -Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, const cv::Scalar& ocol); -Paint imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha); -void scissor(float x, float y, float w, float h); -void intersectScissor(float x, float y, float w, float h); -void resetScissor(); + Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, + const cv::Scalar& ocol); + Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, + const cv::Scalar& ocol); + Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, + const cv::Scalar& ocol); + Paint imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha); + void scissor(float x, float y, float w, float h); + void intersectScissor(float x, float y, float w, float h); + void resetScissor(); }; } // namespace detail @@ -178,10 +190,13 @@ void fontFace(const char* font); float text(float x, float y, const char* string, const char* end); void textBox(float x, float y, float breakRowWidth, const char* string, const char* end); float textBounds(float x, float y, const char* string, const char* end, float* bounds); -void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds); -int textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions); +void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, + float* bounds); +int textGlyphPositions(float x, float y, const char* string, const char* end, + GlyphPosition* positions, int maxPositions); void textMetrics(float* ascender, float* descender, float* lineh); -int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows); +int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, + int maxRows); void save(); void restore(); @@ -231,15 +246,19 @@ void pathWinding(int dir); void arc(float cx, float cy, float r, float a0, float a1, int dir); void rect(float x, float y, float w, float h); void roundedRect(float x, float y, float w, float h, float r); -void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft); +void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, + float radBottomRight, float radBottomLeft); void ellipse(float cx, float cy, float rx, float ry); void circle(float cx, float cy, float r); void fill(); void stroke(); -Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol); -Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol); -Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, const cv::Scalar& ocol); +Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, + const cv::Scalar& ocol); +Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, + const cv::Scalar& ocol); +Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, + const cv::Scalar& ocol); Paint imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha); void scissor(float x, float y, float w, float h); void intersectScissor(float x, float y, float w, float h); @@ -248,6 +267,4 @@ void resetScissor(); } } - - #endif /* SRC_COMMON_NVG_HPP_ */ diff --git a/src/common/sink.cpp b/src/common/sink.cpp index 61b2fb5e4..7b0e74d8e 100644 --- a/src/common/sink.cpp +++ b/src/common/sink.cpp @@ -8,7 +8,8 @@ namespace cv { namespace viz { -Sink::Sink(std::function consumer) : consumer_(consumer) { +Sink::Sink(std::function consumer) : + consumer_(consumer) { } Sink::Sink() { @@ -18,7 +19,7 @@ Sink::~Sink() { } bool Sink::isReady() { - if(consumer_) + if (consumer_) return true; else return false; diff --git a/src/common/source.cpp b/src/common/source.cpp index 0bf0da8f2..44db0aed4 100644 --- a/src/common/source.cpp +++ b/src/common/source.cpp @@ -8,17 +8,19 @@ namespace cv { namespace viz { -Source::Source(std::function generator, float fps) : generator_(generator), fps_(fps) { +Source::Source(std::function generator, float fps) : + generator_(generator), fps_(fps) { } -Source::Source() : fps_(0) { +Source::Source() : + fps_(0) { } Source::~Source() { } bool Source::isReady() { - if(generator_) + if (generator_) return true; else return false; diff --git a/src/common/util.cpp b/src/common/util.cpp index faabcdf86..105dc2e56 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -35,10 +35,10 @@ std::string get_cl_info() { #ifndef __EMSCRIPTEN__ std::vector plt_info; cv::ocl::getPlatfomsInfo(plt_info); - const cv::ocl::Device &defaultDevice = cv::ocl::Device::getDefault(); + const cv::ocl::Device& defaultDevice = cv::ocl::Device::getDefault(); cv::ocl::Device current; ss << endl; - for (const auto &info : plt_info) { + for (const auto& info : plt_info) { for (int i = 0; i < info.deviceNumber(); ++i) { ss << "\t"; info.getDevice(current, i); @@ -47,8 +47,12 @@ std::string get_cl_info() { else ss << " "; ss << info.version() << " = " << info.name() << endl; - ss << "\t\t GL sharing: " << (current.isExtensionSupported("cl_khr_gl_sharing") ? "true" : "false") << endl; - ss << "\t\t VAAPI media sharing: " << (current.isExtensionSupported("cl_intel_va_api_media_sharing") ? "true" : "false") << endl; + ss << "\t\t GL sharing: " + << (current.isExtensionSupported("cl_khr_gl_sharing") ? "true" : "false") + << endl; + ss << "\t\t VAAPI media sharing: " + << (current.isExtensionSupported("cl_intel_va_api_media_sharing") ? + "true" : "false") << endl; } } #endif @@ -65,14 +69,14 @@ bool is_intel_va_supported() { std::vector plt_info; cv::ocl::getPlatfomsInfo(plt_info); cv::ocl::Device current; - for (const auto &info : plt_info) { + for (const auto& info : plt_info) { for (int i = 0; i < info.deviceNumber(); ++i) { info.getDevice(current, i); return current.isExtensionSupported("cl_intel_va_api_media_sharing"); } } } catch (std::exception& ex) { - cerr << "Intel VAAPI query failed: " << ex. what() << endl; + cerr << "Intel VAAPI query failed: " << ex.what() << endl; } catch (...) { cerr << "Intel VAAPI query failed" << endl; } @@ -90,14 +94,14 @@ bool is_cl_gl_sharing_supported() { std::vector plt_info; cv::ocl::getPlatfomsInfo(plt_info); cv::ocl::Device current; - for (const auto &info : plt_info) { + for (const auto& info : plt_info) { for (int i = 0; i < info.deviceNumber(); ++i) { info.getDevice(current, i); return current.isExtensionSupported("cl_khr_gl_sharing"); } } } catch (std::exception& ex) { - cerr << "CL-GL sharing query failed: " << ex. what() << endl; + cerr << "CL-GL sharing query failed: " << ex.what() << endl; } catch (...) { cerr << "CL-GL sharing query failed" << endl; } @@ -139,7 +143,7 @@ static void install_signal_handlers() { * @return true if the program should keep on running */ bool keep_running() { - if(!signal_handlers_installed) { + if (!signal_handlers_installed) { install_signal_handlers(); } return !finish_requested; @@ -170,7 +174,7 @@ void update_fps(cv::Ptr v2d, bool graphically) { } if (graphically) { - v2d->nvg([&](const cv::Size &size) { + v2d->nvg([&](const cv::Size& size) { using namespace cv; string text = "FPS: " + std::to_string(fps); nvg::beginPath(); @@ -201,22 +205,29 @@ void update_fps(cv::Ptr v2d, bool graphically) { * @param vaDeviceIndex * @return */ -Sink make_va_sink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize, const int vaDeviceIndex) { - cv::Ptr writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, frameSize, { cv::VIDEOWRITER_PROP_HW_DEVICE, vaDeviceIndex, cv::VIDEOWRITER_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, cv::VIDEOWRITER_PROP_HW_ACCELERATION_USE_OPENCL, 1 }); - - return Sink([=](const cv::UMat& frame){ +Sink make_va_sink(const string& outputFilename, const int fourcc, const float fps, + const cv::Size& frameSize, const int vaDeviceIndex) { + cv::Ptr writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG, + cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, frameSize, { + cv::VIDEOWRITER_PROP_HW_DEVICE, vaDeviceIndex, + cv::VIDEOWRITER_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, + cv::VIDEOWRITER_PROP_HW_ACCELERATION_USE_OPENCL, 1 }); + + return Sink([=](const cv::UMat& frame) { (*writer) << frame; return writer->isOpened(); }); } -Source make_va_source(const string &inputFilename, const int vaDeviceIndex) { - cv::Ptr capture = new cv::VideoCapture(inputFilename, cv::CAP_FFMPEG, { cv::CAP_PROP_HW_DEVICE, vaDeviceIndex, cv::CAP_PROP_HW_ACCELERATION, cv::VIDEO_ACCELERATION_VAAPI, cv::CAP_PROP_HW_ACCELERATION_USE_OPENCL, 1 }); +Source make_va_source(const string& inputFilename, const int vaDeviceIndex) { + cv::Ptr capture = new cv::VideoCapture(inputFilename, cv::CAP_FFMPEG, { + cv::CAP_PROP_HW_DEVICE, vaDeviceIndex, cv::CAP_PROP_HW_ACCELERATION, + cv::VIDEO_ACCELERATION_VAAPI, cv::CAP_PROP_HW_ACCELERATION_USE_OPENCL, 1 }); float fps = capture->get(cv::CAP_PROP_FPS); float w = capture->get(cv::CAP_PROP_FRAME_WIDTH); float h = capture->get(cv::CAP_PROP_FRAME_HEIGHT); - return Source([=](cv::UMat& frame){ + return Source([=](cv::UMat& frame) { (*capture) >> frame; return !frame.empty(); }, fps); @@ -235,21 +246,23 @@ Source make_va_source(const string &inputFilename, const int vaDeviceIndex) { #endif #ifndef __EMSCRIPTEN__ -Sink make_writer_sink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize) { - if(is_intel_va_supported()) { +Sink make_writer_sink(const string& outputFilename, const int fourcc, const float fps, + const cv::Size& frameSize) { + if (is_intel_va_supported()) { return make_va_sink(outputFilename, fourcc, fps, frameSize, 0); } - cv::Ptr writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG, cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, frameSize); + cv::Ptr writer = new cv::VideoWriter(outputFilename, cv::CAP_FFMPEG, + cv::VideoWriter::fourcc('V', 'P', '9', '0'), fps, frameSize); - return Sink([=](const cv::UMat& frame){ + return Sink([=](const cv::UMat& frame) { (*writer) << frame; return writer->isOpened(); }); } -Source make_capture_source(const string &inputFilename) { - if(is_intel_va_supported()) { +Source make_capture_source(const string& inputFilename) { + if (is_intel_va_supported()) { return make_va_source(inputFilename, 0); } @@ -258,7 +271,7 @@ Source make_capture_source(const string &inputFilename) { float w = capture->get(cv::CAP_PROP_FRAME_WIDTH); float h = capture->get(cv::CAP_PROP_FRAME_HEIGHT); - return Source([=](cv::UMat& frame){ + return Source([=](cv::UMat& frame) { (*capture) >> frame; return !frame.empty(); }, fps); diff --git a/src/common/util.hpp b/src/common/util.hpp index 0b7bf0488..5e3d2b126 100644 --- a/src/common/util.hpp +++ b/src/common/util.hpp @@ -32,10 +32,12 @@ void print_system_info(); void update_fps(cv::Ptr viz2d, bool graphical); #ifndef __EMSCRIPTEN__ -Sink make_va_sink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize, const int vaDeviceIndex); -Source make_va_source(const string &inputFilename, const int vaDeviceIndex); -Sink make_writer_sink(const string &outputFilename, const int fourcc, const float fps, const cv::Size &frameSize); -Source make_capture_source(const string &inputFilename); +Sink make_va_sink(const string& outputFilename, const int fourcc, const float fps, + const cv::Size& frameSize, const int vaDeviceIndex); +Source make_va_source(const string& inputFilename, const int vaDeviceIndex); +Sink make_writer_sink(const string& outputFilename, const int fourcc, const float fps, + const cv::Size& frameSize); +Source make_capture_source(const string& inputFilename); #else Source make_capture_source(int width, int height); #endif diff --git a/src/common/viz2d.cpp b/src/common/viz2d.cpp index 7df3d4575..386d45778 100644 --- a/src/common/viz2d.cpp +++ b/src/common/viz2d.cpp @@ -15,57 +15,64 @@ namespace cv { namespace viz { namespace detail { -void gl_check_error(const std::filesystem::path &file, unsigned int line, const char *expression) { +void gl_check_error(const std::filesystem::path& file, unsigned int line, const char* expression) { int errorCode = glGetError(); if (errorCode != 0) { - std::cerr << "GL failed in " << file.filename() << " (" << line << ") : " << "\nExpression:\n " << expression << "\nError code:\n " << errorCode << "\n " << std::endl; + std::cerr << "GL failed in " << file.filename() << " (" << line << ") : " + << "\nExpression:\n " << expression << "\nError code:\n " << errorCode + << "\n " << std::endl; assert(false); } } -void error_callback(int error, const char *description) { +void error_callback(int error, const char* description) { fprintf(stderr, "GLFW Error: %s\n", description); } } -template void find_widgets(nanogui::Widget* parent, std::vector& widgets) { +template void find_widgets(nanogui::Widget* parent, std::vector& widgets) { T w; - for(auto* child: parent->children()) { + for (auto* child : parent->children()) { find_widgets(child, widgets); - if((w = dynamic_cast(child)) != nullptr) { + if ((w = dynamic_cast(child)) != nullptr) { widgets.push_back(w); } } } -bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i &p) { +bool contains_absolute(nanogui::Widget* w, const nanogui::Vector2i& p) { nanogui::Vector2i d = p - w->absolute_position(); - return d.x() >= 0 && d.y() >= 0 && - d.x() < w->size().x() && d.y() < w->size().y(); + return d.x() >= 0 && d.y() >= 0 && d.x() < w->size().x() && d.y() < w->size().y(); } cv::Scalar color_convert(const cv::Scalar& src, cv::ColorConversionCodes code) { - cv::Mat tmpIn(1,1,CV_8UC3); - cv::Mat tmpOut(1,1,CV_8UC3); + cv::Mat tmpIn(1, 1, CV_8UC3); + cv::Mat tmpOut(1, 1, CV_8UC3); - tmpIn.at(0,0) = cv::Vec3b(src[0], src[1], src[2]); + tmpIn.at(0, 0) = cv::Vec3b(src[0], src[1], src[2]); cvtColor(tmpIn, tmpOut, code); - const cv::Vec3b& vdst = tmpOut.at(0,0); - cv::Scalar dst(vdst[0],vdst[1],vdst[2], src[3]); + const cv::Vec3b& vdst = tmpOut.at(0, 0); + cv::Scalar dst(vdst[0], vdst[1], vdst[2], src[3]); return dst; } -Viz2D::Viz2D(const cv::Size &size, const cv::Size& frameBufferSize, bool offscreen, const string &title, int major, int minor, int samples, bool debug) : - initialSize_(size), frameBufferSize_(frameBufferSize), viewport_(0, 0, frameBufferSize.width, frameBufferSize.height), scale_(1), mousePos_(0,0), offscreen_(offscreen), stretch_(false), title_(title), major_(major), minor_(minor), samples_(samples), debug_(debug) { - assert(frameBufferSize_.width >= initialSize_.width && frameBufferSize_.height >= initialSize_.height); +Viz2D::Viz2D(const cv::Size& size, const cv::Size& frameBufferSize, bool offscreen, + const string& title, int major, int minor, int samples, bool debug) : + initialSize_(size), frameBufferSize_(frameBufferSize), viewport_(0, 0, + frameBufferSize.width, frameBufferSize.height), scale_(1), mousePos_(0, 0), offscreen_( + offscreen), stretch_(false), title_(title), major_(major), minor_(minor), samples_( + samples), debug_(debug) { + assert( + frameBufferSize_.width >= initialSize_.width + && frameBufferSize_.height >= initialSize_.height); initializeWindowing(); } Viz2D::~Viz2D() { //don't delete form_. it is autmatically cleaned up by the base class (nanogui::Screen) - if(screen_) + if (screen_) delete screen_; if (writer_) delete writer_; @@ -80,7 +87,7 @@ Viz2D::~Viz2D() { } bool Viz2D::initializeWindowing() { - if(glfwInit() != GLFW_TRUE) + if (glfwInit() != GLFW_TRUE) return false; glfwSetErrorCallback(cv::viz::error_callback); @@ -129,7 +136,8 @@ bool Viz2D::initializeWindowing() { */ glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE); - glfwWindow_ = glfwCreateWindow(initialSize_.width, initialSize_.height, title_.c_str(), nullptr, nullptr); + glfwWindow_ = glfwCreateWindow(initialSize_.width, initialSize_.height, title_.c_str(), nullptr, + nullptr); if (glfwWindow_ == NULL) { return false; } @@ -143,51 +151,54 @@ bool Viz2D::initializeWindowing() { glfwSetWindowUserPointer(getGLFWWindow(), this); - glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, double x, double y) { + glfwSetCursorPosCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) { Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); v2d->screen().cursor_pos_callback_event(x, y); auto cursor = v2d->getMousePosition(); auto diff = cursor - cv::Vec2f(x, y); - if(v2d->isMouseDrag()) { + if (v2d->isMouseDrag()) { v2d->pan(diff[0], -diff[1]); } v2d->setMousePosition(x, y); } ); - glfwSetMouseButtonCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, int button, int action, int modifiers) { - Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - v2d->screen().mouse_button_callback_event(button, action, modifiers); - if (button == GLFW_MOUSE_BUTTON_RIGHT) { - v2d->setMouseDrag(action == GLFW_PRESS); - } - } + glfwSetMouseButtonCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int button, int action, int modifiers) { + Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + v2d->screen().mouse_button_callback_event(button, action, modifiers); + if (button == GLFW_MOUSE_BUTTON_RIGHT) { + v2d->setMouseDrag(action == GLFW_PRESS); + } + } ); - glfwSetKeyCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, int key, int scancode, int action, int mods) { - Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - v2d->screen().key_callback_event(key, scancode, action, mods); - } + glfwSetKeyCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int key, int scancode, int action, int mods) { + Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + v2d->screen().key_callback_event(key, scancode, action, mods); + } ); - glfwSetCharCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, unsigned int codepoint) { + glfwSetCharCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, unsigned int codepoint) { Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); v2d->screen().char_callback_event(codepoint); } ); - glfwSetDropCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, int count, const char **filenames) { - Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); - v2d->screen().drop_callback_event(count, filenames); - } + glfwSetDropCallback(getGLFWWindow(), + [](GLFWwindow* glfwWin, int count, const char** filenames) { + Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); + v2d->screen().drop_callback_event(count, filenames); + } ); - glfwSetScrollCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, double x, double y) { + glfwSetScrollCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, double x, double y) { Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); std::vector widgets; find_widgets(&v2d->screen(), widgets); - for(auto* w : widgets) { + for (auto* w : widgets) { auto mousePos = nanogui::Vector2i(v2d->getMousePosition()[0] / v2d->getXPixelRatio(), v2d->getMousePosition()[1] / v2d->getYPixelRatio()); - if(contains_absolute(w, mousePos)) { - v2d->screen().scroll_callback_event(x, y); - return; - } - } + if(contains_absolute(w, mousePos)) { + v2d->screen().scroll_callback_event(x, y); + return; + } +} v2d->zoom(y < 0 ? 1.1 : 0.9); } @@ -199,11 +210,10 @@ bool Viz2D::initializeWindowing() { // } // ); - glfwSetFramebufferSizeCallback(getGLFWWindow(), [](GLFWwindow *glfwWin, int width, int height) { + glfwSetFramebufferSizeCallback(getGLFWWindow(), [](GLFWwindow* glfwWin, int width, int height) { Viz2D* v2d = reinterpret_cast(glfwGetWindowUserPointer(glfwWin)); v2d->screen().resize_callback_event(width, height); - } - ); + }); clglContext_ = new detail::FrameBufferContext(this->getFrameBufferSize()); clvaContext_ = new detail::CLVAContext(*clglContext_); @@ -219,12 +229,13 @@ FormHelper& Viz2D::form() { return *form_; } -void Viz2D::setKeyboardEventCallback(std::function fn) { +void Viz2D::setKeyboardEventCallback( + std::function fn) { keyEventCb_ = fn; } bool Viz2D::keyboard_event(int key, int scancode, int action, int modifiers) { - if(keyEventCb_) + if (keyEventCb_) return keyEventCb_(key, scancode, action, modifiers); if (screen().keyboard_event(key, scancode, action, modifiers)) @@ -285,36 +296,36 @@ void Viz2D::nanogui(std::function fn) { fn(form()); } -void Viz2D::setSource(const Source &src) { +void Viz2D::setSource(const Source& src) { if (!clva().hasContext()) clva().copyContext(); source_ = src; } bool Viz2D::capture() { - return this->capture([&](cv::UMat &videoFrame) { - if(source_.isReady()) + return this->capture([&](cv::UMat& videoFrame) { + if (source_.isReady()) source_().second.copyTo(videoFrame); }); } bool Viz2D::capture(std::function fn) { - return clva().capture(fn); + return clva().capture(fn); } bool Viz2D::isSourceReady() { return source_.isReady(); } -void Viz2D::setSink(const Sink &sink) { +void Viz2D::setSink(const Sink& sink) { if (!clva().hasContext()) clva().copyContext(); sink_ = sink; } void Viz2D::write() { - this->write([&](const cv::UMat &videoFrame) { - if(sink_.isReady()) + this->write([&](const cv::UMat& videoFrame) { + if (sink_.isReady()) sink_(videoFrame); }); } @@ -335,18 +346,18 @@ void Viz2D::makeNoneCurrent() { glfwMakeContextCurrent(nullptr); } -void Viz2D::clear(const cv::Scalar &rgba) { - const float &r = rgba[0] / 255.0f; - const float &g = rgba[1] / 255.0f; - const float &b = rgba[2] / 255.0f; - const float &a = rgba[3] / 255.0f; +void Viz2D::clear(const cv::Scalar& rgba) { + const float& r = rgba[0] / 255.0f; + const float& g = rgba[1] / 255.0f; + const float& b = rgba[2] / 255.0f; + const float& a = rgba[3] / 255.0f; GL_CHECK(glClearColor(r, g, b, a)); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT)); } void Viz2D::showGui(bool s) { auto children = screen().children(); - for(auto* child : children) { + for (auto* child : children) { child->set_visible(s); } } @@ -365,7 +376,7 @@ void Viz2D::pan(int x, int y) { } void Viz2D::zoom(float factor) { - if(scale_ == 1 && viewport_.x == 0 && viewport_.y == 0 && factor > 1) + if (scale_ == 1 && viewport_.x == 0 && viewport_.y == 0 && factor > 1) return; double oldScale = scale_; @@ -373,19 +384,23 @@ void Viz2D::zoom(float factor) { double origH = getFrameBufferSize().height; scale_ *= factor; - if(scale_ <= 0.025) { + if (scale_ <= 0.025) { scale_ = 0.025; return; - } else if(scale_ > 1) { + } else if (scale_ > 1) { scale_ = 1; viewport_.width = origW; viewport_.height = origH; - if(factor > 1) { - viewport_.x += log10(((viewport_.x * (1.0 - factor)) / viewport_.width) * 9 + 1.0) * viewport_.width; - viewport_.y += log10(((viewport_.y * (1.0 - factor)) / viewport_.height) * 9 + 1.0) * viewport_.height; + if (factor > 1) { + viewport_.x += log10(((viewport_.x * (1.0 - factor)) / viewport_.width) * 9 + 1.0) + * viewport_.width; + viewport_.y += log10(((viewport_.y * (1.0 - factor)) / viewport_.height) * 9 + 1.0) + * viewport_.height; } else { - viewport_.x += log10(((-viewport_.x * (1.0 - factor)) / viewport_.width) * 9 + 1.0) * viewport_.width; - viewport_.y += log10(((-viewport_.y * (1.0 - factor)) / viewport_.height) * 9 + 1.0) * viewport_.height; + viewport_.x += log10(((-viewport_.x * (1.0 - factor)) / viewport_.width) * 9 + 1.0) + * viewport_.width; + viewport_.y += log10(((-viewport_.y * (1.0 - factor)) / viewport_.height) * 9 + 1.0) + * viewport_.height; } return; } @@ -399,20 +414,22 @@ void Viz2D::zoom(float factor) { float delta_x; float delta_y; - if(factor < 1.0) { - offset = cv::Vec2f(viewport_.x, viewport_.y) - cv::Vec2f(mousePos_[0], origH - mousePos_[1]); + if (factor < 1.0) { + offset = cv::Vec2f(viewport_.x, viewport_.y) + - cv::Vec2f(mousePos_[0], origH - mousePos_[1]); delta_x = offset[0] / oldW; delta_y = offset[1] / oldH; } else { - offset = cv::Vec2f(viewport_.x - (viewport_.width / 2.0), viewport_.y - (viewport_.height / 2.0)) - cv::Vec2f(viewport_.x, viewport_.y); + offset = cv::Vec2f(viewport_.x - (viewport_.width / 2.0), + viewport_.y - (viewport_.height / 2.0)) - cv::Vec2f(viewport_.x, viewport_.y); delta_x = offset[0] / oldW; delta_y = offset[1] / oldH; } float x_offset; float y_offset; - x_offset = delta_x * (viewport_.width - oldW); - y_offset = delta_y * (viewport_.height - oldH); + x_offset = delta_x * (viewport_.width - oldW); + y_offset = delta_y * (viewport_.height - oldH); if (factor < 1.0) { viewport_.x += x_offset; @@ -435,7 +452,7 @@ cv::Vec2f Viz2D::getMousePosition() { } void Viz2D::setMousePosition(int x, int y) { - mousePos_ = {float(x), float(y)}; + mousePos_ = { float(x), float(y) }; } float Viz2D::getScale() { @@ -490,7 +507,7 @@ float Viz2D::getYPixelRatio() { #endif } -void Viz2D::setWindowSize(const cv::Size &sz) { +void Viz2D::setWindowSize(const cv::Size& sz) { makeCurrent(); screen().set_size(nanogui::Vector2i(sz.width / getXPixelRatio(), sz.height / getYPixelRatio())); } @@ -503,12 +520,14 @@ bool Viz2D::isFullscreen() { void Viz2D::setFullscreen(bool f) { makeCurrent(); auto monitor = glfwGetPrimaryMonitor(); - const GLFWvidmode *mode = glfwGetVideoMode(monitor); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); if (f) { - glfwSetWindowMonitor(getGLFWWindow(), monitor, 0, 0, mode->width, mode->height, mode->refreshRate); + glfwSetWindowMonitor(getGLFWWindow(), monitor, 0, 0, mode->width, mode->height, + mode->refreshRate); setWindowSize(getNativeFrameBufferSize()); } else { - glfwSetWindowMonitor(getGLFWWindow(), nullptr, 0, 0, getInitialSize().width, getInitialSize().height, 0); + glfwSetWindowMonitor(getGLFWWindow(), nullptr, 0, 0, getInitialSize().width, + getInitialSize().height, 0); setWindowSize(getInitialSize()); } } @@ -559,7 +578,7 @@ void Viz2D::setDefaultKeyboardEventCallback() { return true; } else if (key == GLFW_KEY_TAB && action == GLFW_PRESS) { auto children = screen().children(); - for(auto* child : children) { + for (auto* child : children) { child->set_visible(!child->visible()); } diff --git a/src/common/viz2d.hpp b/src/common/viz2d.hpp index ee4b1a78c..5d5cb5540 100644 --- a/src/common/viz2d.hpp +++ b/src/common/viz2d.hpp @@ -11,7 +11,6 @@ #include "dialog.hpp" #include "formhelper.hpp" - #include #include #include @@ -37,13 +36,13 @@ class FrameBufferContext; class CLVAContext; class NanoVGContext; -void gl_check_error(const std::filesystem::path &file, unsigned int line, const char *expression); +void gl_check_error(const std::filesystem::path& file, unsigned int line, const char* expression); #define GL_CHECK(expr) \ expr; \ cv::viz::gl_check_error(__FILE__, __LINE__, #expr); -void error_callback(int error, const char *description); +void error_callback(int error, const char* description); } cv::Scalar color_convert(const cv::Scalar& src, cv::ColorConversionCodes code); @@ -78,7 +77,7 @@ class Viz2D { cv::VideoWriter* writer_ = nullptr; FormHelper* form_ = nullptr; bool closed_ = false; - cv::Size videoFrameSize_ = cv::Size(0,0); + cv::Size videoFrameSize_ = cv::Size(0, 0); int vaCaptureDeviceIndex_ = 0; int vaWriterDeviceIndex_ = 0; bool mouseDrag_ = false; @@ -87,7 +86,8 @@ class Viz2D { Sink sink_; std::function keyEventCb_; public: - Viz2D(const cv::Size &initialSize, const cv::Size& frameBufferSize, bool offscreen, const string &title, int major = 4, int minor = 6, int samples = 0, bool debug = false); + Viz2D(const cv::Size& initialSize, const cv::Size& frameBufferSize, bool offscreen, + const string& title, int major = 4, int minor = 6, int samples = 0, bool debug = false); virtual ~Viz2D(); bool initializeWindowing(); void makeCurrent(); @@ -100,7 +100,7 @@ public: void nvg(std::function fn); void nanogui(std::function); - void clear(const cv::Scalar& rgba = cv::Scalar(0,0,0,255)); + void clear(const cv::Scalar& rgba = cv::Scalar(0, 0, 0, 255)); bool capture(); bool capture(std::function fn); @@ -146,7 +146,8 @@ public: bool display(); void setDefaultKeyboardEventCallback(); - void setKeyboardEventCallback(std::function fn); + void setKeyboardEventCallback( + std::function fn); private: bool keyboard_event(int key, int scancode, int action, int modifiers); void setMousePosition(int x, int y);