no more direct calls to form()

pull/3471/head
kallaballa 2 years ago
parent f0711a82b0
commit 6c42a8752f
  1. 25
      src/common/viz2d.cpp
  2. 17
      src/common/viz2d.hpp
  3. 30
      src/optflow/optflow-demo.cpp

@ -612,22 +612,41 @@ bool Viz2D::isStretching() {
return stretch_;
}
nanogui::Window* Viz2D::makeWindow(int x, int y, const string &title) {
return form()->add_window(nanogui::Vector2i(x, y), title);
Viz2DWindow* Viz2D::makeWindow(int x, int y, const string &title) {
this->makeCurrent();
auto* win = new kb::viz2d::Viz2DWindow(this, x, y, title);
this->form()->set_window(win);
return win;
}
nanogui::Label* Viz2D::makeGroup(const string &label) {
return form()->add_group(label);
}
nanogui::detail::FormWidget<bool>* Viz2D::makeFormVariable(const string &name, bool &v, const string &tooltip, bool visible) {
nanogui::detail::FormWidget<bool>* Viz2D::makeFormVariable(const string &name, bool &v, const string &tooltip, bool visible, bool enabled) {
auto var = form()->add_variable(name, v);
var->set_enabled(enabled);
var->set_visible(visible);
if (!tooltip.empty())
var->set_tooltip(tooltip);
return var;
}
nanogui::ColorPicker* Viz2D::makeColorPicker(const string& label, nanogui::Color& color, const string& tooltip, std::function<void(const nanogui::Color)> fn, bool visible, bool enabled) {
auto* colorPicker = form()->add_variable(label, color);
colorPicker->set_enabled(enabled);
colorPicker->set_visible(visible);
if (!tooltip.empty())
colorPicker->set_tooltip(tooltip);
if(fn)
colorPicker->set_final_callback(fn);
return colorPicker;
}
nanogui::Button* Viz2D::makeButton(const string& caption, std::function<void()> fn) {
return this->form()->add_button(caption, fn);
}
bool Viz2D::isAccelerated() {
return cv::ocl::useOpenCL();
}

@ -134,11 +134,12 @@ public:
bool display();
nanogui::FormHelper* form();
nanogui::Window* makeWindow(int x, int y, const string& title);
Viz2DWindow* makeWindow(int x, int y, const string& title);
nanogui::Label* makeGroup(const string& label);
nanogui::detail::FormWidget<bool>* makeFormVariable(const string &name, bool &v, const string &tooltip = "", bool visible = true);
template<typename T> nanogui::detail::FormWidget<T>* makeFormVariable(const string &name, T &v, const T &min, const T &max, bool spinnable, const string &unit, const string tooltip, bool visible = true) {
nanogui::detail::FormWidget<bool>* makeFormVariable(const string &name, bool &v, const string &tooltip = "", bool visible = true, bool enabled = true);
template<typename T> nanogui::detail::FormWidget<T>* 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 = form()->add_variable(name, v);
var->set_enabled(enabled);
var->set_visible(visible);
var->set_spinnable(spinnable);
var->set_min_value(min);
@ -149,6 +150,16 @@ public:
var->set_tooltip(tooltip);
return var;
}
nanogui::ColorPicker* makeColorPicker(const string& label, nanogui::Color& color, const string& tooltip = "", std::function<void(const nanogui::Color)> fn = nullptr, bool visible = true, bool enabled = true);
template<typename T> nanogui::ComboBox* makeComboBox(const string &label, T& e, const std::vector<string>& items) {
auto* var = form()->add_variable("Mode", e, true);
var->set_items(items);
return var;
}
nanogui::Button* makeButton(const string& caption, std::function<void()> fn);
private:
virtual bool keyboard_event(int key, int scancode, int action, int modifiers) override;
void setMousePosition(int x, int y);

@ -260,17 +260,13 @@ kb::viz2d::Viz2DWindow* menuWindow;
void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> v2dMenu) {
v2d->makeCurrent();
effectWindow = new kb::viz2d::Viz2DWindow(v2d, 5, 30, "Effects");
v2d->form()->set_window(effectWindow);
effectWindow = v2d->makeWindow(5, 30, "Effects");
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");
v2d->makeGroup("Background");
v2d->form()->add_variable("Mode", background_mode, true)->set_items({"Grey", "Color", "Value", "None"});
v2d->makeComboBox("Mode",background_mode, {"Grey", "Color", "Value", "None"});
v2d->makeGroup("Points");
v2d->makeFormVariable("Max. Points", max_points, 10, 1000000, true, "", "The theoretical maximum number of points to track which is scaled by the density of detected points and therefor is usually much smaller");
v2d->makeFormVariable("Point Loss", point_loss, 0.0f, 100.0f, true, "%", "How many of the tracked points to lose intentionally");
@ -278,9 +274,7 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> v2dMenu)
v2d->makeGroup("Optical flow");
v2d->makeFormVariable("Max. Stroke Size", max_stroke, 1, 100, true, "px", "The theoretical maximum size of the drawing stroke which is scaled by the area of the convex hull of tracked points and therefor is usually much smaller");
auto* color = v2d->form()->add_variable("Color", effect_color);
color->set_tooltip("The primary effect color");
color->set_final_callback([](const nanogui::Color &c) {
v2d->makeColorPicker("Color", effect_color, "The primary effect color",[](const nanogui::Color &c) {
effect_color[0] = c[0];
effect_color[1] = c[1];
effect_color[2] = c[2];
@ -293,10 +287,8 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> v2dMenu)
kernel_size = std::max(int(k % 2 == 0 ? k + 1 : k), 1);
});
auto* thresh = v2d->makeFormVariable("Threshold", bloom_thresh, 1, 255, true, "", "The lightness selection threshold");
auto* gain = v2d->makeFormVariable("Gain", bloom_gain, 0.1f, 20.0f, true, "", "Intensity of the effect defined by gain");
thresh->set_enabled(false);
gain->set_enabled(false);
auto* thresh = v2d->makeFormVariable("Threshold", bloom_thresh, 1, 255, true, "", "The lightness selection threshold", true, false);
auto* gain = v2d->makeFormVariable("Gain", bloom_gain, 0.1f, 20.0f, true, "", "Intensity of the effect defined by gain", true, false);
enableBloom->set_callback([&,thresh, gain](const bool& b) {
if(b) {
thresh->set_enabled(true);
@ -307,9 +299,8 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> v2dMenu)
}
use_bloom = b;
});
settingsWindow = new kb::viz2d::Viz2DWindow(v2d, 220, 320, "Settings");
v2d->form()->set_window(settingsWindow);
settingsWindow = v2d->makeWindow(220, 320, "Settings");
v2d->makeGroup("Hardware Acceleration");
v2d->makeFormVariable("Enable", use_acceleration, "Enable or disable libva and OpenCL acceleration");
@ -317,21 +308,18 @@ void setup_gui(cv::Ptr<kb::viz2d::Viz2D> v2d, cv::Ptr<kb::viz2d::Viz2D> v2dMenu)
v2d->makeFormVariable("Threshold", scene_change_thresh, 0.1f, 1.0f, true, "", "Peak threshold. Lowering it makes detection more sensitive");
v2d->makeFormVariable("Threshold Diff", scene_change_thresh_diff, 0.1f, 1.0f, true, "", "Difference of peak thresholds. Lowering it makes detection more sensitive");
v2dMenu->makeCurrent();
menuWindow = new kb::viz2d::Viz2DWindow(v2dMenu, 0, 0, "Display");
v2dMenu->form()->set_window(menuWindow);
menuWindow = v2dMenu->makeWindow(0, 0, "Display");
v2dMenu->makeGroup("Display");
v2dMenu->makeFormVariable("Show FPS", show_fps, "Enable or disable the On-screen FPS display");
v2dMenu->makeFormVariable("Stetch", stretch, "Stretch the frame buffer to the window size")->set_callback([=](const bool &s) {
v2d->setStretching(s);
});
v2dMenu->form()->add_button("Fullscreen", [=]() {
v2dMenu->makeButton("Fullscreen", [=]() {
v2d->setFullscreen(!v2d->isFullscreen());
});
v2dMenu->form()->add_button("Offscreen", [=]() {
v2dMenu->makeButton("Offscreen", [=]() {
v2d->setOffscreen(!v2d->isOffscreen());
});

Loading…
Cancel
Save