Newer
Older
#include "media_panel.hpp"
#include "screen.hpp"
#include "camera.hpp"
#include <nanogui/layout.h>
#include <nanogui/button.h>
#include <nanogui/popupbutton.h>
#include <nanogui/entypo.h>
#ifdef HAVE_LIBARCHIVE
#include "ftl/rgbd/snapshot.hpp"
#endif
using ftl::gui::MediaPanel;
MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""), screen_(screen) {
setLayout(new BoxLayout(Orientation::Horizontal,
auto size = Vector2i(400, 60);
//setFixedSize(size);
setPosition(Vector2i(screen->width() / 2 - size[0]/2, screen->height() - 30 - size[1]));
auto button = new Button(this, "", ENTYPO_ICON_EDIT);
button->setCallback([this]() {
auto *cam = screen_->activeCamera();
if (cam) cam->showPoseWindow();
});
button = new Button(this, "", ENTYPO_ICON_CONTROLLER_RECORD);
button->setFlags(Button::ToggleButton);
button->setChangeCallback([this,button](bool state) {
if (state){
auto *cam = screen_->activeCamera();
button->setTextColor(nanogui::Color(1.0f,0.1f,0.1f,1.0f));
char timestamp[18];
std::time_t t=std::time(NULL);
std::strftime(timestamp, sizeof(timestamp), "%F-%H%M%S", std::localtime(&t));
writer_ = new ftl::rgbd::SnapshotStreamWriter(std::string(timestamp) + ".tar.gz", 1000 / 25);
writer_->addSource(cam->source());
writer_->start();
} else {
button->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
if (writer_) {
writer_->stop();
delete writer_;
writer_ = nullptr;
}
}
//if (state) ... start
//else ... stop
});
button = new Button(this, "", ENTYPO_ICON_CONTROLLER_STOP);
button->setCallback([this]() {
screen_->setActiveCamera(nullptr);
});
button = new Button(this, "", ENTYPO_ICON_CONTROLLER_PAUS);
button->setCallback([this,button]() {
paused_ = !paused_;
screen_->control()->pause();
if (paused_) {
button->setIcon(ENTYPO_ICON_CONTROLLER_PLAY);
} else {
button->setIcon(ENTYPO_ICON_CONTROLLER_PAUS);
}
});
//button = new Button(this, "", ENTYPO_ICON_CONTROLLER_RECORD);
#ifdef HAVE_LIBARCHIVE
auto button_snapshot = new Button(this, "", ENTYPO_ICON_IMAGES);
ftl::gui::Camera *cam = screen_->activeCamera();
if (!cam) return;
try {
char timestamp[18];
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;
cam->source()->getFrames(rgb, depth);
writer.addSource( cam->source()->getURI(),
cam->source()->parameters(),
cam->source()->getPose());
writer.addRGBD(0, rgb, depth);
}
catch(std::runtime_error) {
LOG(ERROR) << "Snapshot failed (file error)";
}
});
#endif
auto popbutton = new PopupButton(this, "", ENTYPO_ICON_LAYERS);
popbutton->setSide(Popup::Side::Right);
popbutton->setChevronIcon(ENTYPO_ICON_CHEVRON_SMALL_RIGHT);
Popup *popup = popbutton->popup();
popup->setLayout(new GroupLayout());
popup->setTheme(screen->toolbuttheme);
button = new Button(popup, "Left");
button->setFlags(Button::RadioButton);
button->setPushed(true);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanLeft);
}
});
right_button_ = new Button(popup, "Right");
right_button_->setFlags(Button::RadioButton);
right_button_->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanRight);
}
});
depth_button_ = new Button(popup, "Depth");
depth_button_->setFlags(Button::RadioButton);
depth_button_->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanDepth);
}
});
popbutton = new PopupButton(popup, "More");
popbutton->setSide(Popup::Side::Right);
popbutton->setChevronIcon(ENTYPO_ICON_CHEVRON_SMALL_RIGHT);
popup = popbutton->popup();
popup->setLayout(new GroupLayout());
popup->setTheme(screen->toolbuttheme);
popup->setAnchorHeight(150);
button = new Button(popup, "Deviation");
button->setFlags(Button::RadioButton);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanDeviation);
}
});
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
button = new Button(popup, "Normals");
button->setFlags(Button::RadioButton);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanNormals);
}
});
button = new Button(popup, "Flow");
button->setFlags(Button::RadioButton);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanFlow);
}
});
button = new Button(popup, "Confidence");
button->setFlags(Button::RadioButton);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanConfidence);
}
});
button = new Button(popup, "Energy");
button->setFlags(Button::RadioButton);
button->setCallback([this]() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
cam->setChannel(ftl::rgbd::kChanEnergy);
}
});
// Update button enabled status
void MediaPanel::cameraChanged() {
ftl::gui::Camera *cam = screen_->activeCamera();
if (cam) {
if (cam->source()->hasCapabilities(ftl::rgbd::kCapStereo)) {
right_button_->setEnabled(true);
} else {
right_button_->setEnabled(false);
}
}
}