refactoring, renaming and commenting

pull/3471/head
kallaballa 2 years ago
parent ba3df1feb7
commit fe9ea26171
  1. 31
      src/common/viz2d.cpp
  2. 13
      src/common/viz2d.hpp
  3. 4
      src/font/font-demo.cpp
  4. 6
      src/nanovg/nanovg-demo.cpp
  5. 31
      src/optflow/optflow-demo.cpp
  6. 2
      src/pedestrian/pedestrian-demo.cpp

@ -20,7 +20,7 @@ void error_callback(int error, const char *description) {
}
}
cv::Scalar convert(const cv::Scalar& src, cv::ColorConversionCodes code) {
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);
@ -32,8 +32,8 @@ cv::Scalar convert(const cv::Scalar& src, cv::ColorConversionCodes code) {
}
Viz2D::Viz2D(const cv::Size &size, const cv::Size& frameBufferSize, bool offscreen, const string &title, int major, int minor, int samples, bool debug) :
size_(size), frameBufferSize_(frameBufferSize), offscreen_(offscreen), title_(title), major_(major), minor_(minor), samples_(samples), debug_(debug) {
assert(frameBufferSize_.width >= size_.width && frameBufferSize_.height >= size_.height);
initialSize_(size), frameBufferSize_(frameBufferSize), offscreen_(offscreen), title_(title), major_(major), minor_(minor), samples_(samples), debug_(debug) {
assert(frameBufferSize_.width >= initialSize_.width && frameBufferSize_.height >= initialSize_.height);
initialize();
}
@ -91,7 +91,7 @@ void Viz2D::initialize() {
*/
// glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE);
glfwWindow_ = glfwCreateWindow(size_.width, size_.height, title_.c_str(), nullptr, nullptr);
glfwWindow_ = glfwCreateWindow(initialSize_.width, initialSize_.height, title_.c_str(), nullptr, nullptr);
if (glfwWindow_ == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
@ -101,7 +101,7 @@ void Viz2D::initialize() {
screen().initialize(getGLFWWindow(), false);
form_ = new nanogui::FormHelper(this);
this->setSize(size_);
this->setWindowSize(initialSize_);
glfwSetWindowUserPointer(getGLFWWindow(), this);
@ -275,12 +275,16 @@ cv::Size Viz2D::getFrameBufferSize() {
return frameBufferSize_;
}
cv::Size Viz2D::getSize() {
cv::Size Viz2D::getWindowSize() {
int w, h;
glfwGetWindowSize(getGLFWWindow(), &w, &h);
return {w, h};
}
cv::Size Viz2D::getInitialSize() {
return initialSize_;
}
float Viz2D::getXPixelRatio() {
#if defined(EMSCRIPTEN)
return emscripten_get_device_pixel_ratio();
@ -301,8 +305,8 @@ float Viz2D::getYPixelRatio() {
#endif
}
void Viz2D::setSize(const cv::Size &sz) {
screen().set_size(nanogui::Vector2i(sz.width / getXPixelRatio(), sz.height / getYPixelRatio()));
void Viz2D::setWindowSize(const cv::Size &sz) {
set_size(nanogui::Vector2i(sz.width / getXPixelRatio(), sz.height / getYPixelRatio()));
}
bool Viz2D::isFullscreen() {
@ -314,10 +318,11 @@ void Viz2D::setFullscreen(bool f) {
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
if (f) {
glfwSetWindowMonitor(getGLFWWindow(), monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
setWindowSize(getNativeFrameBufferSize());
} else {
glfwSetWindowMonitor(getGLFWWindow(), nullptr, 0, 0, getNativeFrameBufferSize().width, getNativeFrameBufferSize().height, mode->refreshRate);
glfwSetWindowMonitor(getGLFWWindow(), nullptr, 0, 0, getInitialSize().width, getInitialSize().height, 0);
// setWindowSize(getInitialSize());
}
setSize(size_);
}
bool Viz2D::isResizable() {
@ -333,10 +338,10 @@ bool Viz2D::isVisible() {
}
void Viz2D::setVisible(bool v) {
screen().perform_layout();
glfwWindowHint(GLFW_VISIBLE, v ? GLFW_TRUE : GLFW_FALSE);
screen().set_visible(v);
setSize(size_);
// setSize(size_);
screen().perform_layout();
}
bool Viz2D::isOffscreen() {
@ -374,7 +379,7 @@ bool Viz2D::display() {
if (!offscreen_) {
glfwPollEvents();
screen().draw_contents();
clglContext_->blitFrameBufferToScreen(getSize());
clglContext_->blitFrameBufferToScreen(getWindowSize());
screen().draw_widgets();
glfwSwapBuffers(glfwWindow_);
result = !glfwWindowShouldClose(glfwWindow_);

@ -28,14 +28,14 @@ void gl_check_error(const std::filesystem::path &file, unsigned int line, const
void error_callback(int error, const char *description);
}
cv::Scalar convert(const cv::Scalar& src, cv::ColorConversionCodes code);
cv::Scalar color_convert(const cv::Scalar& src, cv::ColorConversionCodes code);
using namespace kb::viz2d::detail;
class NVG;
class Viz2D: private nanogui::Screen {
cv::Size size_;
class Viz2D: public nanogui::Screen {
const cv::Size initialSize_;
cv::Size frameBufferSize_;
bool offscreen_;
string title_;
@ -53,7 +53,7 @@ class Viz2D: private nanogui::Screen {
bool closed_ = false;
cv::Size videoFrameSize_ = cv::Size(0,0);
public:
Viz2D(const cv::Size &size, 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();
void initialize();
@ -68,8 +68,9 @@ public:
cv::VideoWriter& makeVAWriter(const string& outputFilename, const int fourcc, const float fps, const cv::Size& frameSize, const int vaDeviceIndex);
cv::VideoCapture& makeVACapture(const string& intputFilename, const int vaDeviceIndex);
void setSize(const cv::Size& sz);
cv::Size getSize();
void setWindowSize(const cv::Size& sz);
cv::Size getWindowSize();
cv::Size getInitialSize();
void setVideoFrameSize(const cv::Size& sz);
cv::Size getVideoFrameSize();
cv::Size getFrameBufferSize();

@ -74,7 +74,7 @@ int main(int argc, char **argv) {
for(int i = 0; i < numStars; ++i) {
nvg::beginPath();
nvg::strokeWidth(rng.uniform(0.5f, MAX_STAR_SIZE));
nvg::strokeColor(convert(cv::Scalar(0, rng.uniform(MIN_STAR_LIGHTNESS, 1.0f) * 255, 255, rng.uniform(MIN_STAR_ALPHA, 255)), cv::COLOR_HLS2BGR));
nvg::strokeColor(color_convert(cv::Scalar(0, rng.uniform(MIN_STAR_LIGHTNESS, 1.0f) * 255, 255, rng.uniform(MIN_STAR_ALPHA, 255)), cv::COLOR_HLS2BGR));
nvg::circle(rng.uniform(0, WIDTH) , rng.uniform(0, HEIGHT), MAX_STAR_SIZE);
nvg::stroke();
}
@ -97,7 +97,7 @@ int main(int argc, char **argv) {
nvg::beginPath();
nvg::fontSize(FONT_SIZE);
nvg::fontFace("libertine");
nvg::fillColor(convert(cv::Scalar(0.15 * 180.0, 128, 255, 255), cv::COLOR_HLS2BGR));
nvg::fillColor(color_convert(cv::Scalar(0.15 * 180.0, 128, 255, 255), cv::COLOR_HLS2BGR));
nvg::textAlign(NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
/** only draw lines that are visible **/

@ -40,8 +40,8 @@ void drawColorwheel(float x, float y, float w, float h, float hue) {
bx = cx + cosf(a1) * (r0 + r1) * 0.5f;
by = cy + sinf(a1) * (r0 + r1) * 0.5f;
paint = nvg::linearGradient(ax, ay, bx, by,
kb::viz2d::convert(cv::Scalar((a0 / (CV_PI * 2.0)) * 180.0, 0.55 * 255.0, 255.0, 255.0), cv::COLOR_HLS2BGR),
kb::viz2d::convert(cv::Scalar((a1 / (CV_PI * 2.0)) * 180.0, 0.55 * 255, 255, 255), cv::COLOR_HLS2BGR));
kb::viz2d::color_convert(cv::Scalar((a0 / (CV_PI * 2.0)) * 180.0, 0.55 * 255.0, 255.0, 255.0), cv::COLOR_HLS2BGR),
kb::viz2d::color_convert(cv::Scalar((a1 / (CV_PI * 2.0)) * 180.0, 0.55 * 255, 255, 255), cv::COLOR_HLS2BGR));
nvg::fillPaint(paint);
nvg::fill();
}
@ -84,7 +84,7 @@ void drawColorwheel(float x, float y, float w, float h, float hue) {
nvg::lineTo(ax, ay);
nvg::lineTo(bx, by);
nvg::closePath();
paint = nvg::linearGradient(r, 0, ax, ay, kb::viz2d::convert(cv::Scalar(hue, 128, 255, 255), cv::COLOR_HLS2BGR_FULL), cv::Scalar(255, 255, 255, 255));
paint = nvg::linearGradient(r, 0, ax, ay, kb::viz2d::color_convert(cv::Scalar(hue, 128, 255, 255), cv::COLOR_HLS2BGR_FULL), cv::Scalar(255, 255, 255, 255));
nvg::fillPaint(paint);
nvg::fill();
paint = nvg::linearGradient((r + ax) * 0.5f, (0 + ay) * 0.5f, bx, by, cv::Scalar(0, 0, 0, 0), cv::Scalar(0, 0, 0, 255));

@ -1,11 +1,9 @@
#define CL_TARGET_OPENCL_VERSION 120
#include "../common/viz2d.hpp"
#include "../common/nvg.hpp"
#include "../common/util.hpp"
#include <cmath>
#include <vector>
#include <string>
@ -228,7 +226,24 @@ void composite_layers(const cv::UMat background, const cv::UMat foreground, cons
}
void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d) {
v2d->makeWindow(5, 30, "Effects");
auto* effectWindow = v2d->makeWindow(5, 30, "Effects");
// nanogui::Button* btn = v2d->form()->add_button("Expand", [=]() {
// for(auto* child : effectWindow->children()) {
// child->set_visible(true);
// }
// btn->set_visible(false);
// v2d->perform_layout();
// });
effectWindow->button_panel()->add<nanogui::Button>("_")->set_callback([=](){
effectWindow->set_visible(false);
for(auto* child : effectWindow->children()) {
child->set_visible(false);
}
// btn->set_visible(true);
v2d->perform_layout();
});
v2d->makeGroup("Foreground");
v2d->makeFormVariable("Scale", fg_scale, 0.1f, 4.0f, true, "", "Generate the foreground at this scale");
v2d->makeFormVariable("Loss", fg_loss, 0.1f, 99.9f, true, "%", "On every frame the foreground loses on brightness");
@ -263,7 +278,15 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d) {
v2d->makeFormVariable("Threshold", bloom_thresh, 1, 255, true, "", "The lightness selection threshold");
v2d->makeFormVariable("Gain", bloom_gain, 0.1f, 20.0f, true, "", "Intensity of the effect defined by gain");
v2d->makeWindow(240, 30, "Settings");
auto* settingsWindow = v2d->makeWindow(240, 30, "Settings");
// settingsWindow->button_panel()->add<nanogui::Button>("_")->set_callback([=](){
// settingsWindow->set_visible(false);
// nanogui::Button* btn = lbl->add<nanogui::Button>("Settings");
// btn->set_callback([=](){
// settingsWindow->set_visible(true);
// });
// v2d->perform_layout();
// });
v2d->makeGroup("Acceleration");
v2d->makeFormVariable("Use OpenCL", use_opencl, "Enable or disable OpenCL acceleration");

@ -180,7 +180,7 @@ int main(int argc, char **argv) {
v2d->clear();
nvg::beginPath();
nvg::strokeWidth(std::fmax(2.0, WIDTH / 960.0));
nvg::strokeColor(kb::viz2d::convert(cv::Scalar(0, 127, 255, 200), cv::COLOR_HLS2BGR));
nvg::strokeColor(kb::viz2d::color_convert(cv::Scalar(0, 127, 255, 200), cv::COLOR_HLS2BGR));
for (size_t i = 0; i < maxLocations.size(); i++) {
nvg::rect(maxLocations[i].x * WIDTH_FACTOR, maxLocations[i].y * HEIGHT_FACTOR, maxLocations[i].width * WIDTH_FACTOR, maxLocations[i].height * HEIGHT_FACTOR);
}

Loading…
Cancel
Save