Skip to content

Commit

Permalink
Add look_at() viz interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 28, 2023
1 parent aadb17a commit b347618
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mola_kernel/include/mola_kernel/interfaces/VizInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include <mrpt/gui/CDisplayWindowGUI.h> // nanogui
#include <mrpt/math/TPoint3D.h>

#include <future>
#include <memory>
Expand Down Expand Up @@ -46,7 +47,10 @@ class VizInterface
const std::string& viewportName = "main",
const std::string& parentWindow = "main") = 0;

protected:
virtual std::future<bool> update_viewport_look_at(
const mrpt::math::TPoint3Df& lookAt,
const std::string& viewportName = "main",
const std::string& parentWindow = "main") = 0;
};

} // namespace mola
5 changes: 5 additions & 0 deletions mola_viz/include/mola_viz/MolaViz.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class MolaViz : public ExecutableBase, public VizInterface
const std::string& viewportName = "main",
const std::string& parentWindow = DEFAULT_WINDOW_NAME) override;

std::future<bool> update_viewport_look_at(
const mrpt::math::TPoint3Df& lookAt,
const std::string& viewportName = "main",
const std::string& parentWindow = DEFAULT_WINDOW_NAME) override;

/** @} */

/** @name mola-viz GUI update handlers registry
Expand Down
29 changes: 29 additions & 0 deletions mola_viz/src/MolaViz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,35 @@ std::future<bool> MolaViz::update_3d_object(
return task->get_future();
}

std::future<bool> MolaViz::update_viewport_look_at(
const mrpt::math::TPoint3Df& lookAt, const std::string& viewportName,
const std::string& parentWindow)
{
using return_type = bool;

auto task = std::make_shared<std::packaged_task<return_type()>>(
[this, lookAt, viewportName, parentWindow]() {
MRPT_LOG_DEBUG_STREAM(
"update_viewport_look_at() lookAt=" << lookAt.asString());

ASSERT_(windows_.count(parentWindow));
auto topWin = windows_.at(parentWindow);
ASSERT_(topWin);

// No need to acquire the mutex, since this task will be run
// in the proper moment in the proper thread:
ASSERT_(topWin->background_scene);
topWin->camera().setCameraPointing(lookAt.x, lookAt.y, lookAt.z);

return true;
});

auto lck = mrpt::lockHelper(guiThreadPendingTasksMtx_);
guiThreadPendingTasks_.emplace_back([=]() { (*task)(); });
guiThreadMustReLayoutTheseWindows_.insert(parentWindow);
return task->get_future();
}

#if 0
// Visualize GT:
if (1)
Expand Down

0 comments on commit b347618

Please sign in to comment.