Skip to content
Snippets Groups Projects
Commit 44f9b1f5 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add some cursor checks and a reset

parent 938846e1
Branches
No related tags found
1 merge request!329Add pose adjustment and toolbar
Pipeline #28936 passed
...@@ -428,7 +428,11 @@ bool Camera::hasFrame() { ...@@ -428,7 +428,11 @@ bool Camera::hasFrame() {
} }
Eigen::Matrix4d Camera::cursor() const { Eigen::Matrix4d Camera::cursor() const {
return nanogui::lookAt(cursor_pos_, cursor_target_, cursor_normal_).cast<double>(); if (cursor_normal_.norm() > 0.0f) return nanogui::lookAt(cursor_pos_, cursor_target_, cursor_normal_).cast<double>();
Eigen::Matrix4d ident;
ident.setIdentity();
return ident;
} }
void Camera::drawOverlay(NVGcontext *ctx, const nanogui::Vector2f &s, const nanogui::Vector2f &is, const Eigen::Vector2f &offset) { void Camera::drawOverlay(NVGcontext *ctx, const nanogui::Vector2f &s, const nanogui::Vector2f &is, const Eigen::Vector2f &offset) {
...@@ -573,6 +577,14 @@ void Camera::setCursor(int x, int y) { ...@@ -573,6 +577,14 @@ void Camera::setCursor(int x, int y) {
void Camera::setOriginToCursor() { void Camera::setOriginToCursor() {
using ftl::calibration::transform::inverse; using ftl::calibration::transform::inverse;
// Check for valid cursor
if (cursor_normal_.norm() == 0.0f) return;
float cursor_length = (cursor_target_ - cursor_pos_).norm();
float cursor_dist = cursor_pos_.norm();
if (cursor_length < 0.01f || cursor_length > 5.0f) return;
if (cursor_dist > 10.0f) return;
if (movable_) { if (movable_) {
auto *rend = io->feed()->getRenderer(frame_id_); auto *rend = io->feed()->getRenderer(frame_id_);
if (rend) { if (rend) {
...@@ -596,4 +608,37 @@ void Camera::setOriginToCursor() { ...@@ -596,4 +608,37 @@ void Camera::setOriginToCursor() {
} }
} }
} }
cursor_target_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
cursor_pos_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
cursor_normal_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
}
void Camera::resetOrigin() {
cursor_target_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
cursor_pos_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
cursor_normal_ = Eigen::Vector3f(0.0f,0.0f,0.0f);
if (movable_) {
auto *rend = io->feed()->getRenderer(frame_id_);
if (rend) {
auto *filter = rend->filter();
if (filter) {
cv::Mat cur;
cv::eigen2cv(cursor(), cur);
auto fss = filter->getLatestFrameSets();
for (auto &fs : fss) {
if (fs->frameset() == frame_id_.frameset()) continue;
for (auto &f : fs->frames) {
auto response = f.response();
auto &rgbdf = response.cast<ftl::rgbd::Frame>();
auto &calib = rgbdf.setCalibration();
calib = f.cast<ftl::rgbd::Frame>().getCalibration();
calib.origin = cur;
}
};
}
}
}
} }
...@@ -81,6 +81,7 @@ public: ...@@ -81,6 +81,7 @@ public:
const Eigen::Vector3f getCursorPosition() const { return cursor_pos_; } const Eigen::Vector3f getCursorPosition() const { return cursor_pos_; }
void setOriginToCursor(); void setOriginToCursor();
void resetOrigin();
private: private:
int frame_idx = -1; int frame_idx = -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment