Newer
Older
#include <nanogui/textbox.h>
#include <nanogui/slider.h>
#include <nanogui/combobox.h>
#include <nanogui/label.h>
#include <nanogui/opengl.h>
#include <nanogui/glutil.h>
#include <nanogui/screen.h>
#include <nanogui/layout.h>
SourceWindow::SourceWindow(ftl::gui::Screen *screen)
: nanogui::Window(screen, ""), screen_(screen) {
setLayout(new nanogui::BoxLayout(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 20, 5));
//if (!screen->root()->get<json_t>("sources")) {
// screen->root()->getConfig()["sources"] = json_t::array();
//}
//src_ = ftl::create<Source>(ctrl->getRoot(), "source", ctrl->getNet());
// tools->setLayout(new BoxLayout(Orientation::Horizontal,
// Alignment::Middle, 0, 6));
auto label = new Label(this, "Select Camera","sans-bold",20);
//auto select = new ComboBox(this, available_);
//select->setCallback([this,select](int ix) {
//src_->set("uri", available_[ix]);
// TODO(Nick) Check camera exists first
// screen_->setActiveCamera(cameras_[available_[ix]]);
// LOG(INFO) << "Change source: " << ix;
//});
auto vscroll = new VScrollPanel(this);
ipanel_ = new Widget(vscroll);
ipanel_->setLayout(new GridLayout(nanogui::Orientation::Horizontal, 2,
nanogui::Alignment::Middle, 0, 5));
//ipanel_ = new ImageView(vscroll, 0);
screen->net()->onConnect([this](ftl::net::Peer *p) {
UNIQUE_LOCK(mutex_, lk);
//select->setItems(available_);
_updateCameras(screen_->net()->findAll<string>("list_streams"));
std::vector<ftl::rgbd::Source*> srcs = ftl::createArray<ftl::rgbd::Source>(screen_->root(), "sources", screen_->net());
for (auto *src : srcs) {
available_.push_back(src->getURI());
}
_updateCameras(screen_->control()->getNet()->findAll<string>("list_streams"));
auto tools = new Widget(this);
tools->setLayout(new BoxLayout(Orientation::Horizontal,
Alignment::Middle, 0, 6));
auto button_rgb = new Button(tools, "RGB");
button_rgb->setTooltip("RGB left image");
button_rgb->setFlags(Button::RadioButton);
button_rgb->setPushed(true);
button_rgb->setChangeCallback([this](bool state) { mode_ = Mode::rgb; });
button_depth->setFlags(Button::RadioButton);
button_depth->setChangeCallback([this](bool state) { mode_ = Mode::depth; });
auto button_stddev = new Button(tools, "SD. 25");
button_stddev->setTooltip("Standard Deviation over 25 frames");
button_stddev->setFlags(Button::RadioButton);
button_stddev->setChangeCallback([this](bool state) { mode_ = Mode::stddev; });
//auto button_pose = new Button(this, "Adjust Pose", ENTYPO_ICON_COMPASS);
//button_pose->setCallback([this]() {
// auto posewin = new PoseWindow(screen_, screen_->control(), src_->getURI());
// posewin->setTheme(theme());
//});
auto button_snapshot = new Button(this, "Snapshot", ENTYPO_ICON_IMAGES);
button_snapshot->setCallback([this] {
std::time_t t=std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
auto writer = ftl::rgbd::SnapshotWriter(std::string(timestamp) + ".tar.gz");
cv::Mat rgb, depth;
if (!writer.addCameraRGBD(
"0", // TODO
rgb,
depth,
this->src_->getPose(),
)) {
LOG(ERROR) << "Snapshot failed";
}
}
catch(std::runtime_error) {
LOG(ERROR) << "Snapshot failed (file error)";
}
});
#endif
//cam.view = imageView;
//imageView->setGridThreshold(20);
//imageView->setSource(src_);
void SourceWindow::_updateCameras(const vector<string> &netcams) {
for (auto s : netcams) {
json_t srcjson;
srcjson["uri"] = s;
screen_->root()->getConfig()["sources"].push_back(srcjson);
std::vector<ftl::rgbd::Source*> srcs = ftl::createArray<ftl::rgbd::Source>(screen_->root(), "sources", screen_->net());
for (auto *src : srcs) {
if (cameras_.find(src->getURI()) == cameras_.end()) {
LOG(INFO) << "Making camera: " << src->getURI();
//LOG(INFO) << "Camera already exists: " << s;
refresh_thumbs_ = true;
if (thumbs_.size() != available_.size()) {
thumbs_.resize(available_.size());
}
}
SourceWindow::~SourceWindow() {
}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
void SourceWindow::draw(NVGcontext *ctx) {
if (refresh_thumbs_) {
UNIQUE_LOCK(mutex_, lk);
//refresh_thumbs_ = false;
for (size_t i=0; i<thumbs_.size(); ++i) {
cv::Mat t;
auto *cam = cameras_[available_[i]];
if (cam) {
if (cam->source()->thumbnail(t)) {
thumbs_[i].update(t);
} else {
refresh_thumbs_ = true;
}
}
if (ipanel_->childCount() < i+1) {
new ftl::gui::ThumbView(ipanel_, screen_, cam);
}
if (thumbs_[i].isValid()) dynamic_cast<nanogui::ImageView*>(ipanel_->childAt(i))->bindImage(thumbs_[i].texture());
}
// TODO(Nick) remove excess image views
center();
}
nanogui::Window::draw(ctx);
}