From ad0a0319ed39955636dfcbdb50699e71279975db Mon Sep 17 00:00:00 2001 From: kallaballa Date: Fri, 7 Apr 2023 17:22:08 +0200 Subject: [PATCH] refactoring, renaming and commenting --- src/beauty/beauty-demo.cpp | 2 +- src/common/detail/nanovgcontext.cpp | 2 +- src/common/dialog.hpp | 22 ++- src/common/formhelper.cpp | 2 +- src/common/formhelper.hpp | 66 ++++++- src/common/nvg.cpp | 2 +- src/common/nvg.hpp | 263 +++++++++++++++++++++++++++- src/common/sink.hpp | 25 +++ src/common/source.cpp | 2 +- src/common/source.hpp | 33 ++++ src/common/util.cpp | 47 +---- src/common/util.hpp | 64 ++++++- src/common/viz2d.hpp | 7 +- src/font/font-demo.cpp | 4 +- src/optflow/optflow-demo.cpp | 8 +- src/shader/shader-demo.cpp | 2 +- 16 files changed, 486 insertions(+), 65 deletions(-) diff --git a/src/beauty/beauty-demo.cpp b/src/beauty/beauty-demo.cpp index c4a07247d..78e082b58 100644 --- a/src/beauty/beauty-demo.cpp +++ b/src/beauty/beauty-demo.cpp @@ -183,7 +183,7 @@ void adjust_saturation(const cv::UMat &srcBGR, cv::UMat &dstBGR, float factor) { void setup_gui(cv::Ptr v2d) { v2d->nanogui([&](cv::viz::FormHelper& form){ - form.makeWindow(5, 30, "Effect"); + form.makeDialog(5, 30, "Effect"); form.makeGroup("Display"); form.makeFormVariable("Side by side", side_by_side, "Enable or disable side by side view"); diff --git a/src/common/detail/nanovgcontext.cpp b/src/common/detail/nanovgcontext.cpp index 15b584db5..237dd4dbd 100644 --- a/src/common/detail/nanovgcontext.cpp +++ b/src/common/detail/nanovgcontext.cpp @@ -23,7 +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::initializeContext(context_), fn(clglContext_.getSize()); } void push() { diff --git a/src/common/dialog.hpp b/src/common/dialog.hpp index 55ca3b8a2..14b318559 100644 --- a/src/common/dialog.hpp +++ b/src/common/dialog.hpp @@ -16,6 +16,10 @@ namespace viz { using std::string; +/*! + * A class for light-weight dialog (a dialog renderered inside a window) derived from nanogui::Window. + * It keeps track of which dialogs are presented and which are lowered and is responsible for layout of lowered dialog-bars. + */ class Dialog: public nanogui::Window { private: static std::function viz2DWin_Xcomparator; @@ -28,12 +32,26 @@ private: nanogui::ref oldLayout_; nanogui::ref newLayout_; bool minimized_ = false; + bool mouse_drag_event(const nanogui::Vector2i& p, const nanogui::Vector2i& rel, int button, + int mods) override; public: + /*! + * Creates a Dialog. + * @param screen The parent nanogui screen + * @param x The x position of the dialog + * @param y The y position of the dialog + * @param title The title of the dialog + */ Dialog(nanogui::Screen* screen, int x, int y, const string& title); + /*! + * Default destructor + */ virtual ~Dialog(); + /*! + * Checks if a dialog is minimized. + * @return true if the dialog is minimized. + */ bool isMinimized(); - 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 70bc4a1b4..01e0bda9e 100644 --- a/src/common/formhelper.cpp +++ b/src/common/formhelper.cpp @@ -15,7 +15,7 @@ FormHelper::FormHelper(nanogui::Screen* screen) : FormHelper::~FormHelper() { } -Dialog* FormHelper::makeWindow(int x, int y, const string& title) { +Dialog* FormHelper::makeDialog(int x, int y, const string& title) { auto* win = new cv::viz::Dialog(m_screen, x, y, title); this->set_window(win); return win; diff --git a/src/common/formhelper.hpp b/src/common/formhelper.hpp index 1a54a2093..de968cfb2 100644 --- a/src/common/formhelper.hpp +++ b/src/common/formhelper.hpp @@ -15,15 +15,61 @@ namespace cv { namespace viz { using std::string; + +/*! + * Ansub-class of nanogui::FormHelper adding convenience calls not unlike highgui offers. + */ class FormHelper: public nanogui::FormHelper { public: + /*! + * Creates a FormHelper. + * @param screen The parent nanogui::screen. + */ FormHelper(nanogui::Screen* screen); + /*! + * Default destructor. + */ virtual ~FormHelper(); - - Dialog* makeWindow(int x, int y, const string& title); + /*! + * Creates a dialog held by this form helper. + * @param x The x position. + * @param y The y position. + * @param title The title. + * @return A pointer to the newly created Dialog. + */ + Dialog* makeDialog(int x, int y, const string& title); + /*! + * Create a grouping label. + * @param label The label text. + * @return A pointer to the newly created Label. + */ nanogui::Label* makeGroup(const string& label); + /*! + * Make a boolean form widget. + * @param name The widget name. + * @param v The state of the widget. + * @param tooltip The tooltip. + * @param visible The initial visibility. + * @param enabled Indicates if the widget is initially enabled. + * @return A pointer to the newly created boolean form widget. + */ nanogui::detail::FormWidget* makeFormVariable(const string& name, bool& v, const string& tooltip = "", bool visible = true, bool enabled = true); + + /*! + * Creates a form widget and deduces the type of widget by template parameter T. + * @tparam T The underlying type of the form widget. + * @param name The name of the widget. + * @param v The current value. + * @param min The minimum value. + * @param max The maximum value. + * @param spinnable Indicates if the widget is spinnable. + * @param unit A string denoting a unit.. + * @param tooltip The tooltip. + * @param visible The initial visibility. + * @param enabled Indicates if the widget is initially enabled. + * @return A pointer to the newly created form widget representing type T. + */ 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) { @@ -40,6 +86,16 @@ public: return var; } + /*! + * Creates a color picker widget + * @param label The label of the widget + * @param color The initial color + * @param tooltip The widget tooltip + * @param fn Custom color selection callback + * @param visible Indicates if the widget is initially visible + * @param enabled Indicates if the widget is initially enabled + * @return A pointer to the newly created ColorPicker + */ nanogui::ColorPicker* makeColorPicker(const string& label, nanogui::Color& color, const string& tooltip = "", std::function fn = nullptr, bool visible = true, bool enabled = true); @@ -50,6 +106,12 @@ public: return var; } + /*! + * Create a Button Widget. + * @param caption The caption + * @param fn Button press callback + * @return A pointer to the newly created Button + */ nanogui::Button* makeButton(const string& caption, std::function fn); }; diff --git a/src/common/nvg.cpp b/src/common/nvg.cpp index 41db25d98..ce5a0d9b9 100644 --- a/src/common/nvg.cpp +++ b/src/common/nvg.cpp @@ -13,7 +13,7 @@ class NVG; NVG* NVG::nvg_instance_ = nullptr; -void NVG::setCurrentContext(NVGcontext* ctx) { +void NVG::initializeContext(NVGcontext* ctx) { if (nvg_instance_ != nullptr) delete nvg_instance_; nvg_instance_ = new NVG(ctx); diff --git a/src/common/nvg.hpp b/src/common/nvg.hpp index eeacbf5a7..255bb95b8 100644 --- a/src/common/nvg.hpp +++ b/src/common/nvg.hpp @@ -17,14 +17,26 @@ namespace cv { namespace viz { +/*! + * In general please refere to https://github.com/memononen/nanovg/blob/master/src/nanovg.h for reference. + */ namespace nvg { +/*! + * Equivalent of a NVGtextRow. + */ struct TextRow: public NVGtextRow { }; +/*! + * Equivalent of a NVGglyphPosition. + */ struct GlyphPosition: public NVGglyphPosition { }; +/*! + * Equivalent of a NVGPaint. Converts back and forth between the two representations (Paint/NVGPaint). + */ struct Paint { Paint() { } @@ -64,26 +76,38 @@ struct Paint { }; namespace detail { - +/*! + * Internal NanoVG singleton that wraps all NanoVG functions. + */ class NVG { +private: friend class Viz2D; static NVG* nvg_instance_; NVGcontext* ctx_ = nullptr; - -public: NVG(NVGcontext* ctx) : ctx_(ctx) { } - - static void setCurrentContext(NVGcontext* ctx); +public: + /*! + * Initialize the current NVG object; + * @param ctx The NVGcontext to create the NVG object from. + */ + static void initializeContext(NVGcontext* ctx); + /*! + * Get the current NVGcontext. + * @return The current NVGcontext context. + */ static NVG* getCurrentContext(); + /*! + * Get the underlying NVGcontext. + * @return The underlying NVGcontext. + */ NVGcontext* getContext() { assert(ctx_ != nullptr); return ctx_; } 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); @@ -175,93 +199,316 @@ public: }; } // namespace detail +/*! + * A forward to nvgCreateFont. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int createFont(const char* name, const char* filename); +/*! + * A forward to nvgCreateFontMem. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int createFontMem(const char* name, unsigned char* data, int ndata, int freeData); +/*! + * A forward to nvgFindFont. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int findFont(const char* name); +/*! + * A forward to nvgAddFallbackFontId. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int addFallbackFontId(int baseFont, int fallbackFont); +/*! + * A forward to nvgAddFallbackFont. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int addFallbackFont(const char* baseFont, const char* fallbackFont); +/*! + * A forward to nvgFontSize. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fontSize(float size); +/*! + * A forward to nvgFontBlur. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fontBlur(float blur); +/*! + * A forward to nvgTextLetterSpacing. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textLetterSpacing(float spacing); +/*! + * A forward to nvgTextLineHeight. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textLineHeight(float lineHeight); +/*! + * A forward to nvgTextAlign. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textAlign(int align); +/*! + * A forward to nvgFontFaceId. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fontFaceId(int font); +/*! + * A forward to nvgFontFace. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fontFace(const char* font); +/*! + * A forward to nvgText. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ float text(float x, float y, const char* string, const char* end); +/*! + * A forward to nvgTextBox. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textBox(float x, float y, float breakRowWidth, const char* string, const char* end); +/*! + * A forward to nvgTextBounds. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ float textBounds(float x, float y, const char* string, const char* end, float* bounds); +/*! + * A forward to nvgTextBoxBounds. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textBoxBounds(float x, float y, float breakRowWidth, const char* string, const char* end, float* bounds); +/*! + * A forward to nvgTextGlyphPositions. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int textGlyphPositions(float x, float y, const char* string, const char* end, GlyphPosition* positions, int maxPositions); +/*! + * A forward to nvgTextMetrics. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void textMetrics(float* ascender, float* descender, float* lineh); +/*! + * A forward to nvgTextBreakLines. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int textBreakLines(const char* string, const char* end, float breakRowWidth, TextRow* rows, int maxRows); - +/*! + * A forward to nvgSave. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void save(); +/*! + * A forward to nvgRestore. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void restore(); +/*! + * A forward to nvgReset. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void reset(); - +/*! + * A forward to nvgShapeAntiAlias. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void shapeAntiAlias(int enabled); +/*! + * A forward to nvgStrokeColor. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void strokeColor(const cv::Scalar& bgra); +/*! + * A forward to nvgStrokePaint. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void strokePaint(Paint paint); +/*! + * A forward to nvgFillColor. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fillColor(const cv::Scalar& color); +/*! + * A forward to nvgFillPaint. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fillPaint(Paint paint); +/*! + * A forward to nvgMiterLimit. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void miterLimit(float limit); +/*! + * A forward to nvgStrokeWidth. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void strokeWidth(float size); +/*! + * A forward to nvgLineCap. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void lineCap(int cap); +/*! + * A forward to nvgLineJoin. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void lineJoin(int join); +/*! + * A forward to nvgGlobalAlpha. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void globalAlpha(float alpha); +/*! + * A forward to nvgResetTransform. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void resetTransform(); +/*! + * A forward to nvgTransform. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transform(float a, float b, float c, float d, float e, float f); +/*! + * A forward to nvgTranslate. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void translate(float x, float y); +/*! + * A forward to nvgRotate. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void rotate(float angle); +/*! + * A forward to nvgSkewX. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void skewX(float angle); +/*! + * A forward to nvgSkewY. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void skewY(float angle); +/*! + * A forward to nvgScale. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void scale(float x, float y); +/*! + * A forward to nvgCurrentTransform. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void currentTransform(float* xform); +/*! + * A forward to nvgTransformIdentity. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformIdentity(float* dst); +/*! + * A forward to nvgTransformTranslate. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformTranslate(float* dst, float tx, float ty); +/*! + * A forward to nvgTransformScale. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformScale(float* dst, float sx, float sy); +/*! + * A forward to nvgTransformRotate. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformRotate(float* dst, float a); +/*! + * A forward to nvgTransformSkewX. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformSkewX(float* dst, float a); +/*! + * A forward to nvgTransformSkewY. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformSkewY(float* dst, float a); +/*! + * A forward to nvgTransformMultiply. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformMultiply(float* dst, const float* src); +/*! + * A forward to nvgTransformPremultiply. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformPremultiply(float* dst, const float* src); +/*! + * A forward to nvgTransformInverse. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ int transformInverse(float* dst, const float* src); +/*! + * A forward to nvgTransformPoint. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void transformPoint(float* dstx, float* dsty, const float* xform, float srcx, float srcy); +/*! + * A forward to nvgDegToRad. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ float degToRad(float deg); +/*! + * A forward to nvgRadToDeg. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ float radToDeg(float rad); +/*! + * A forward to nvgBeginPath. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void beginPath(); +/*! + * A forward to nvgMoveTo. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void moveTo(float x, float y); +/*! + * A forward to nvgLineTo. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void lineTo(float x, float y); +/*! + * A forward to nvgBezierTo. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void bezierTo(float c1x, float c1y, float c2x, float c2y, float x, float y); +/*! + * A forward to nvgQuadTo. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void quadTo(float cx, float cy, float x, float y); +/*! + * A forward to nvgArcTo. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void arcTo(float x1, float y1, float x2, float y2, float radius); +/*! + * A forward to nvgClosePath. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void closePath(); +/*! + * A forward to nvgPathWinding. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void pathWinding(int dir); +/*! + * A forward to nvgArc. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void arc(float cx, float cy, float r, float a0, float a1, int dir); +/*! + * A forward to nvgRect. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void rect(float x, float y, float w, float h); +/*! + * A forward to nvgRoundedRect. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void roundedRect(float x, float y, float w, float h, float r); +/*! + * A forward to nvgRoundedRectVarying. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void roundedRectVarying(float x, float y, float w, float h, float radTopLeft, float radTopRight, float radBottomRight, float radBottomLeft); +/*! + * A forward to nvgEllipse. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void ellipse(float cx, float cy, float rx, float ry); +/*! + * A forward to nvgCircle. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void circle(float cx, float cy, float r); +/*! + * A forward to nvgFill. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void fill(); +/*! + * A forward to nvgStroke. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void stroke(); +/*! + * A forward to nvgLinearGradient. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ Paint linearGradient(float sx, float sy, float ex, float ey, const cv::Scalar& icol, const cv::Scalar& ocol); +/*! + * A forward to nvgBoxGradient. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ Paint boxGradient(float x, float y, float w, float h, float r, float f, const cv::Scalar& icol, const cv::Scalar& ocol); +/*! + * A forward to nvgRadialGradient. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ Paint radialGradient(float cx, float cy, float inr, float outr, const cv::Scalar& icol, const cv::Scalar& ocol); +/*! + * A forward to nvgImagePattern. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ Paint imagePattern(float ox, float oy, float ex, float ey, float angle, int image, float alpha); +/*! + * A forward to nvgScissor. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void scissor(float x, float y, float w, float h); +/*! + * A forward to nvgIntersectScissor. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void intersectScissor(float x, float y, float w, float h); +/*! + * A forward to nvgRresetScissor. See https://github.com/memononen/nanovg/blob/master/src/nanovg.h + */ void resetScissor(); } } diff --git a/src/common/sink.hpp b/src/common/sink.hpp index dc59cd905..01ce69398 100644 --- a/src/common/sink.hpp +++ b/src/common/sink.hpp @@ -12,15 +12,40 @@ namespace cv { namespace viz { +/*! + * A Sink object represents a way to write data produced by Viz2D (e.g. a video-file). + */ class Sink { bool open_ = true; std::function consumer_; public: + /*! + * Consturcts the Sink object from a consumer functor. + * @param consumer A function object that consumes a UMat frame (e.g. writes it to a video file). + */ Sink(std::function consumer); + /*! + * Constucts a null Sink that is never open or ready + */ Sink(); + /*! + * Default destructor + */ virtual ~Sink(); + /*! + * Signals if the sink is ready to consume data. + * @return true if the sink is ready. + */ bool isReady(); + /*! + * Determines if the sink is open. + * @return true if the sink is open. + */ bool isOpen(); + /*! + * The sink operator. It accepts a UMat frame to pass to the consumer + * @param frame The frame to pass to the consumer. (e.g. VideoWriter) + */ void operator()(const cv::UMat& frame); }; diff --git a/src/common/source.cpp b/src/common/source.cpp index 44db0aed4..98fe62229 100644 --- a/src/common/source.cpp +++ b/src/common/source.cpp @@ -13,7 +13,7 @@ Source::Source(std::function generator, float fps) : } Source::Source() : - fps_(0) { + open_(false), fps_(0) { } Source::~Source() { diff --git a/src/common/source.hpp b/src/common/source.hpp index f67427ca8..c3ff46494 100644 --- a/src/common/source.hpp +++ b/src/common/source.hpp @@ -12,6 +12,10 @@ namespace cv { namespace viz { +/*! + * A Source object represents a way to provide data to Viz2D by using + * a generator functor. + */ class Source { bool open_ = true; std::function generator_; @@ -19,12 +23,41 @@ class Source { uint64_t count_ = 0; float fps_; public: + /*! + * Constructs the Source object from a generator functor. + * @param generator A function object that accepts a reference to a UMat frame + * that it manipulates. This is ultimatively used to provide video data to #Viz2D + * @param fps The fps the Source object provides data with. + */ Source(std::function generator, float fps); + /*! + * Constructs a null Source that is never open or ready. + */ Source(); + /*! + * Default destructor. + */ virtual ~Source(); + /*! + * Signals if the source is ready to provide data. + * @return true if the source is ready. + */ bool isReady(); + /*! + * Determines if the source is open. + * @return true if the source is open. + */ bool isOpen(); + /*! + * Returns the fps the underlying generator provides data with. + * @return The fps of the Source object. + */ float fps(); + /*! + * The source operator. It returns the frame count and the frame generated + * (e.g. by VideoCapture)in a pair. + * @return A pair containing the frame count and the frame generated. + */ std::pair operator()(); }; diff --git a/src/common/util.cpp b/src/common/util.cpp index d147534cf..2067731d7 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -19,17 +19,10 @@ namespace cv { namespace viz { -/*! - * Returns the OpenGL Version information. - * @return a string object with the OpenGL version information - */ std::string get_gl_info() { return reinterpret_cast(glGetString(GL_VERSION)); } -/*! - * Returns the OpenCL Version information. - * @return a string object with the OpenCL version information - */ + std::string get_cl_info() { std::stringstream ss; #ifndef __EMSCRIPTEN__ @@ -59,10 +52,6 @@ std::string get_cl_info() { return ss.str(); } -/*! - * Determines if Intel VAAPI is supported - * @return true if it is supported - */ bool is_intel_va_supported() { #ifndef __EMSCRIPTEN__ try { @@ -84,10 +73,6 @@ bool is_intel_va_supported() { return false; } -/*! - * Determines if cl_khr_gl_sharing is supported - * @return true if it is supported - */ bool is_cl_gl_sharing_supported() { #ifndef __EMSCRIPTEN__ try { @@ -109,15 +94,18 @@ bool is_cl_gl_sharing_supported() { return false; } -/*! - * Pretty prints system information. - */ void print_system_info() { cerr << "OpenGL Version: " << get_gl_info() << endl; cerr << "OpenCL Platforms: " << get_cl_info() << endl; } +/*! + * Internal variable that signals that finishing all operation is requested + */ static bool finish_requested = false; +/*! + * Internal variable that tracks if signal handlers have already been installed + */ static bool signal_handlers_installed = false; /*! @@ -136,12 +124,6 @@ static void install_signal_handlers() { signal(SIGTERM, request_finish); } -/*! - * Tells the application if it's alright to keep on running. - * Note: If you use this mechanism signal handlers are installed - * using #install_signal_handlers() - * @return true if the program should keep on running - */ bool keep_running() { if (!signal_handlers_installed) { install_signal_handlers(); @@ -149,11 +131,6 @@ bool keep_running() { return !finish_requested; } -/*! - * Little helper program to keep track of FPS and optionally display it using NanoVG - * @param v2d The Viz2D object to operate on - * @param graphically if this parameter is true the FPS drawn on display - */ void update_fps(cv::Ptr v2d, bool graphically) { static uint64_t cnt = 0; static cv::TickMeter tick; @@ -196,15 +173,7 @@ void update_fps(cv::Ptr v2d, bool graphically) { } #ifndef __EMSCRIPTEN__ -/*! - * - * @param outputFilename - * @param fourcc - * @param fps - * @param frameSize - * @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, diff --git a/src/common/util.hpp b/src/common/util.hpp index 5e3d2b126..049cd80bd 100644 --- a/src/common/util.hpp +++ b/src/common/util.hpp @@ -23,20 +23,82 @@ namespace cv { namespace viz { using std::string; class Viz2D; +/*! + * Returns the OpenGL Version information. + * @return a string object with the OpenGL version information + */ std::string get_gl_info(); +/*! + * Returns the OpenCL Version information. + * @return a string object with the OpenCL version information + */ std::string get_cl_info(); +/*! + * Determines if Intel VAAPI is supported + * @return true if it is supported + */ bool is_intel_va_supported(); +/*! + * Determines if cl_khr_gl_sharing is supported + * @return true if it is supported + */ bool is_cl_gl_sharing_supported(); -bool keep_running(); +/*! + * Pretty prints system information. + */ void print_system_info(); +/*! + * Tells the application if it's alright to keep on running. + * Note: If you use this mechanism signal handlers are installed + * using #install_signal_handlers() + * @return true if the program should keep on running + */ +bool keep_running(); +/*! + * Little helper program to keep track of FPS and optionally display it using NanoVG + * @param v2d The Viz2D object to operate on + * @param graphically if this parameter is true the FPS drawn on display + */ void update_fps(cv::Ptr viz2d, bool graphical); #ifndef __EMSCRIPTEN__ +/*! + * Creates an Intel VAAPI enabled VideoWriter sink object to use in conjunction with #Viz2D::setSink(). + * Usually you would call #make_writer_sink() and let it automatically decide if VAAPI is available. + * @param outputFilename The filename to write the video to. + * @param fourcc The fourcc code of the codec to use. + * @param fps The fps of the target video. + * @param frameSize The frame size of the target video. + * @param vaDeviceIndex The VAAPI device index to use. + * @return A VAAPI enabled sink object. + */ Sink make_va_sink(const string& outputFilename, const int fourcc, const float fps, const cv::Size& frameSize, const int vaDeviceIndex); +/*! + * Creates an Intel VAAPI enabled VideoCapture source object to use in conjunction with #Viz2D::setSource(). + * Usually you would call #make_capture_source() and let it automatically decide if VAAPI is available. + * @param inputFilename The file to read from. + * @param vaDeviceIndex The VAAPI device index to use. + * @return A VAAPI enabled source object. + */ Source make_va_source(const string& inputFilename, const int vaDeviceIndex); +/*! + * Creates a VideoWriter sink object to use in conjunction with #Viz2D::setSink(). + * This function automatically determines if Intel VAAPI is available and enables it if so. + * @param outputFilename The filename to write the video to. + * @param fourcc The fourcc code of the codec to use. + * @param fps The fps of the target video. + * @param frameSize The frame size of the target video. + * @return A (optionally VAAPI enabled) VideoWriter sink object. + */ Sink make_writer_sink(const string& outputFilename, const int fourcc, const float fps, const cv::Size& frameSize); +/*! + * Creates a VideoCapture source object to use in conjunction with #Viz2D::setSource(). + * This function automatically determines if Intel VAAPI is available and enables it if so. + * @param inputFilename The file to read from. + * @return A (optionally VAAPI enabled) VideoCapture enabled source object. + */ Source make_capture_source(const string& inputFilename); #else Source make_capture_source(int width, int height); diff --git a/src/common/viz2d.hpp b/src/common/viz2d.hpp index 5d5cb5540..dabb62996 100644 --- a/src/common/viz2d.hpp +++ b/src/common/viz2d.hpp @@ -28,8 +28,13 @@ using std::cout; using std::cerr; using std::endl; using std::string; - +/*! + * OpenCV namespace + */ namespace cv { +/*! + * Visualization namespace + */ namespace viz { namespace detail { class FrameBufferContext; diff --git a/src/font/font-demo.cpp b/src/font/font-demo.cpp index 958220117..9329abebb 100644 --- a/src/font/font-demo.cpp +++ b/src/font/font-demo.cpp @@ -53,7 +53,7 @@ bool update_perspective = true; void setup_gui(cv::Ptr v2d) { v2d->nanogui([&](cv::viz::FormHelper& form){ - form.makeWindow(5, 30, "Effect"); + form.makeDialog(5, 30, "Effect"); form.makeGroup("Text Crawl"); form.makeFormVariable("Font Size", font_size, 1.0f, 100.0f, true, "pt", "Font size of the text crawl"); form.makeFormVariable("Warp Ratio", warp_ratio, 0.1f, 1.0f, true, "", "The ratio of start width to end width of a crawling line")->set_callback([&](const float &w) { @@ -91,7 +91,7 @@ void setup_gui(cv::Ptr v2d) { star_alpha = a; }); - form.makeWindow(8, 16, "Display"); + form.makeDialog(8, 16, "Display"); form.makeGroup("Display"); form.makeFormVariable("Show FPS", show_fps, "Enable or disable the On-screen FPS display"); diff --git a/src/optflow/optflow-demo.cpp b/src/optflow/optflow-demo.cpp index e709b8ca9..3e3d1fab4 100644 --- a/src/optflow/optflow-demo.cpp +++ b/src/optflow/optflow-demo.cpp @@ -308,7 +308,7 @@ void composite_layers(cv::UMat& background, const cv::UMat& foreground, const cv void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) { v2d->nanogui([&](cv::viz::FormHelper& form){ - form.makeWindow(5, 30, "Effects"); + form.makeDialog(5, 30, "Effects"); form.makeGroup("Foreground"); form.makeFormVariable("Scale", fg_scale, 0.1f, 4.0f, true, "", "Generate the foreground at this scale"); @@ -330,7 +330,7 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) { }); form.makeFormVariable("Alpha", alpha, 0.0f, 1.0f, true, "", "The opacity of the effect"); - form.makeWindow(220, 30, "Post Processing"); + form.makeDialog(220, 30, "Post Processing"); auto* postPocMode = form.makeComboBox("Mode",post_proc_mode, {"Glow", "Bloom", "None"}); auto* kernelSize = form.makeFormVariable("Kernel Size", GLOW_KERNEL_SIZE, 1, 63, true, "", "Intensity of glow defined by kernel size"); kernelSize->set_callback([=](const int& k) { @@ -371,7 +371,7 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) { postPocMode->set_selected_index(m); }); - form.makeWindow(220, 175, "Settings"); + form.makeDialog(220, 175, "Settings"); form.makeGroup("Scene Change Detection"); form.makeFormVariable("Threshold", scene_change_thresh, 0.1f, 1.0f, true, "", "Peak threshold. Lowering it makes detection more sensitive"); @@ -379,7 +379,7 @@ void setup_gui(cv::Ptr v2d, cv::Ptr v2dMenu) { }); v2dMenu->nanogui([&](cv::viz::FormHelper& form){ - form.makeWindow(8, 16, "Display"); + form.makeDialog(8, 16, "Display"); form.makeGroup("Display"); form.makeFormVariable("Show FPS", show_fps, "Enable or disable the On-screen FPS display"); diff --git a/src/shader/shader-demo.cpp b/src/shader/shader-demo.cpp index fe000e0b1..b53505cb9 100644 --- a/src/shader/shader-demo.cpp +++ b/src/shader/shader-demo.cpp @@ -326,7 +326,7 @@ cv::Ptr v2d = new cv::viz::Viz2D(cv::Size(WIDTH, HEIGHT), cv::Si void setup_gui(cv::Ptr v2d) { v2d->nanogui([](cv::viz::FormHelper& form){ - form.makeWindow(5, 30, "Fractal"); + form.makeDialog(5, 30, "Fractal"); form.makeGroup("Navigation"); form.makeFormVariable("Iterations", max_iterations, 3, 1000000, true, "", "How deeply to calculate the fractal.");