Skip to content
Snippets Groups Projects
Commit 2ddd3b45 authored by Sebastian Hahta's avatar Sebastian Hahta
Browse files

code cleanup (debug messages, etc)

parent dea2720d
No related branches found
No related tags found
2 merge requests!139feature/vr,!138OpenVR support
Pipeline #15739 passed
......@@ -152,13 +152,13 @@ ftl::gui::Camera::Camera(ftl::gui::Screen *screen, ftl::rgbd::Source *src) : scr
UNIQUE_LOCK(mutex_, lk);
im1_.create(channel1.size(), channel1.type());
im2_.create(channel2.size(), channel2.type());
cv::swap(channel1, im1_);
cv::swap(channel2, im2_);
cv::imshow("1", im1_);
cv::imshow("2", im2_);
cv::waitKey(1);
//cv::flip(rgb_,rgb_,0);
//cv::flip(depth_,depth_,0);
//cv::swap(channel1, im1_);
//cv::swap(channel2, im2_);
// OpenGL (0,0) bottom left
cv::flip(channel1, im1_, 0);
cv::flip(channel2, im2_, 0);
});
}
......@@ -250,6 +250,7 @@ bool ftl::gui::Camera::setVR(bool on) {
}
else {
vr_mode_ = false;
setChannel(Channel::Left); // reset to left channel
}
return vr_mode_;
......@@ -331,6 +332,7 @@ bool ftl::gui::Camera::thumbnail(cv::Mat &thumb) {
src_->grab(1,9);
if (im1_.empty()) return false;
cv::resize(im1_, thumb, cv::Size(320,180));
cv::flip(thumb, thumb, 0);
return true;
}
......@@ -353,7 +355,8 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
//Eigen::Matrix4d eye_r = ConvertSteamVRMatrixToMatrix4(
// vr::VRSystem()->GetEyeToHeadTransform(vr::Eye_Right));
//LOG(INFO) << ConvertSteamVRMatrixToMatrix4(vr::VRSystem()->GetProjectionMatrix(vr::Eye_Left, 0.01, 10.0));
//LOG(INFO) << "\n" << ConvertSteamVRMatrixToMatrix4(vr::VRSystem()->GetProjectionMatrix(vr::Eye_Left, 0.1, 100.0));
// assumes eye_l(3, 0) = -eye_r(3, 0)
// => baseline = abs(2*eye_l(3, 0))
......@@ -368,18 +371,15 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
LOG(INFO) << "Baseline updated, new value: " << baseline_;*/
}
//LOG(INFO) << ConvertSteamVRMatrixToMatrix4(vr::VRSystem()->GetProjectionMatrix(vr::Eye_Left, 0.01, 10.0));
auto pose = ConvertSteamVRMatrixToMatrix4( rTrackedDevicePose_[vr::k_unTrackedDeviceIndex_Hmd].mDeviceToAbsoluteTracking );
//LOG(INFO) << "\n" << pose;
pose = pose.inverse();
pose = pose.inverse();
Eigen::Translation3d trans(eye_);
Eigen::Affine3d t(trans);
Eigen::Matrix4d viewPose = t.matrix() * pose;
//LOG(INFO) << "\n" << ConvertSteamVRMatrixToMatrix4(vr::VRSystem()->GetProjectionMatrix(vr::Eye_Left, 0.1, 100.0));
if (src_->hasCapabilities(ftl::rgbd::kCapMovable)) src_->setPose(viewPose);
} else {
......
......@@ -85,6 +85,7 @@ class Camera {
ftl::codecs::Channels channels_;
cv::Mat im1_; // first channel (left)
cv::Mat im2_; // second channel ("right")
MUTEX mutex_;
#ifdef HAVE_OPENVR
......
......@@ -113,11 +113,11 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
});
*/
#ifdef HAVE_OPENVR
if (this->screen_->hasVR()) {
auto button_vr = new Button(this, "VR");
button_vr->setFlags(Button::ToggleButton);
button_vr->setChangeCallback([this, button_vr](bool state) {
LOG(INFO) << screen_->useVR();
if (!screen_->useVR()) {
if (screen_->switchVR(true) == true) {
button_vr->setTextColor(nanogui::Color(0.5f,0.5f,1.0f,1.0f));
......@@ -128,11 +128,11 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""),
if (screen_->switchVR(false) == false) {
button_vr->setTextColor(nanogui::Color(1.0f,1.0f,1.0f,1.0f));
this->button_channels_->setEnabled(true);
// reset channel?
}
}
});
}
#endif
button_channels_ = new PopupButton(this, "", ENTYPO_ICON_LAYERS);
button_channels_->setSide(Popup::Side::Right);
......
......@@ -287,18 +287,15 @@ bool ftl::gui::Screen::switchVR(bool on) {
if (useVR() == on) { return on; }
if (on && (HMD_ == nullptr) && !initVR()) {
LOG(INFO) << "init failed";
return false;
}
if (on) {
LOG(INFO) << "set on";
activeCamera()->setVR(true);
} else {
LOG(INFO) << "set off";
activeCamera()->setVR(false);
}
LOG(INFO) << "useVR() " << useVR();
return useVR();
}
#endif
......@@ -399,69 +396,38 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) {
if (camera_) {
imageSize = {camera_->width(), camera_->height()};
camera_->captureFrame();
leftEye_ = camera_->getLeft().texture();
mImageID = camera_->captureFrame().texture();
leftEye_ = mImageID;
rightEye_ = camera_->getRight().texture();
bool show_lr = show_two_images_ &&
(camera_->getChannel() != ftl::codecs::Channel::Left) &&
camera_->getRight().isValid();
if (camera_->getChannel() != ftl::codecs::Channel::Left) { mImageID = rightEye_; }
#ifdef HAVE_OPENVR
if (useVR() && (imageSize[0] > 0) &&
camera_->getLeft().isValid() && camera_->getRight().isValid() &&
(camera_->getChannel() == ftl::codecs::Channel::Right)) {
if (useVR() && imageSize[0] > 0 && camera_->getLeft().isValid() && camera_->getRight().isValid()) {
vr::Texture_t leftEyeTexture = {(void*)(uintptr_t)camera_->getLeft().texture(), vr::TextureType_OpenGL, vr::ColorSpace_Gamma};
vr::Texture_t leftEyeTexture = {(void*)(uintptr_t)leftEye_, vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
vr::VRCompositor()->Submit(vr::Eye_Left, &leftEyeTexture );
glBindTexture(GL_TEXTURE_2D, rightEye_);
vr::Texture_t rightEyeTexture = {(void*)(uintptr_t)camera_->getRight().texture(), vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
vr::Texture_t rightEyeTexture = {(void*)(uintptr_t)rightEye_, vr::TextureType_OpenGL, vr::ColorSpace_Gamma };
vr::VRCompositor()->Submit(vr::Eye_Right, &rightEyeTexture );
mImageID = leftEye_;
}
#endif
if (mImageID < std::numeric_limits<unsigned int>::max() && imageSize[0] > 0) {
//glEnable(GL_SCISSOR_TEST);
//float r = screen->pixelRatio();
/* glScissor(positionInScreen.x() * r,
(screenSize.y() - positionInScreen.y() - size().y()) * r,
size().x() * r, size().y() * r);*/
if (show_lr) {
auto mScale = (screenSize.cwiseQuotient(Vector2f(imageSize[0] *2, imageSize[1])).minCoeff());
Vector2f scaleFactor = mScale * Vector2f(imageSize[0] *2, imageSize[1]).cwiseQuotient(screenSize);
Vector2f positionInScreen(0.0f, 0.0f);
auto mOffset = (screenSize - (screenSize.cwiseProduct(scaleFactor))) / 2;
Vector2f positionAfterOffset = positionInScreen + mOffset;
Vector2f imagePosition = positionAfterOffset.cwiseQuotient(screenSize);
scaleFactor = Vector2f(scaleFactor[0] / 2, scaleFactor[1]);
imagePosition[1] += 0.25;
mShader.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, leftEye_);
mShader.setUniform("image", 0);
mShader.setUniform("scaleFactor", scaleFactor);
mShader.setUniform("position", imagePosition);
mShader.drawIndexed(GL_TRIANGLES, 0, 2);
glBindTexture(GL_TEXTURE_2D, rightEye_);
mShader.setUniform("image", 0);
mShader.setUniform("scaleFactor", scaleFactor);
mShader.setUniform("position", Vector2f(imagePosition[0] + 0.5, imagePosition[1] + 0));
mShader.drawIndexed(GL_TRIANGLES, 0, 2);
} else {
auto mScale = (screenSize.cwiseQuotient(imageSize).minCoeff());
Vector2f scaleFactor = mScale * imageSize.cwiseQuotient(screenSize);
Vector2f positionInScreen(0.0f, 0.0f);
auto mOffset = (screenSize - (screenSize.cwiseProduct(scaleFactor))) / 2;
Vector2f positionAfterOffset = positionInScreen + mOffset;
Vector2f imagePosition = positionAfterOffset.cwiseQuotient(screenSize);
mImageID = (camera_->getChannel() == ftl::codecs::Channel::Left) ? leftEye_ : rightEye_;
//glEnable(GL_SCISSOR_TEST);
//float r = screen->pixelRatio();
/* glScissor(positionInScreen.x() * r,
(screenSize.y() - positionInScreen.y() - size().y()) * r,
size().x() * r, size().y() * r);*/
mShader.bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mImageID);
......@@ -469,7 +435,6 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) {
mShader.setUniform("scaleFactor", scaleFactor);
mShader.setUniform("position", imagePosition);
mShader.drawIndexed(GL_TRIANGLES, 0, 2);
}
//glDisable(GL_SCISSOR_TEST);
}
}
......
......@@ -13,9 +13,9 @@
* Parameters are provided by IVRSystem::GetProjectionRaw and
* IVRSystem::GetRecommendedRenderTargetSize.
*
* | tanx1 = x1 / fx
* | tanx2 = x2 / fy
* | x1 + x2 = size_x
* tanx1 = x1 / fx (1)
* tanx2 = x2 / fy (2)
* x1 + x2 = size_x (3)
*
* :. fx = size_x / (-tanx1 + tanx2)
*
......@@ -28,6 +28,9 @@ Eigen::Matrix3d getCameraMatrix(const double tanx1,
const double size_x,
const double size_y);
/*
* @brief Same as above, but uses given IVRSystem and eye.
*/
Eigen::Matrix3d getCameraMatrix(vr::IVRSystem *vr, const vr::Hmd_Eye &eye);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment