Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 114 additions & 101 deletions apps/lidar_odometry_step_1/lidar_odometry_gui.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions apps/lidar_odometry_step_1/lidar_odometry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct LidarOdometryParams

// Optional GUI observer, called by the producer only at safe trajectory boundaries.
std::function<void(const std::vector<WorkerData>&, bool)> publish_trajectory;
std::function<void(const Eigen::Vector3d&)> publish_processing_head; // completed worker, never the predicted tail

// filter points
double filter_threshold_xy_inner = 0.3; // filtering points during load
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,8 @@ static bool compute_step_2_impl(
spdlog::stopwatch stopwatch_worker;
if (initialize_lidar_odometry(worker_data, params, ts_failure, loProgress, pause, debugMsg, lookup_stats))
{
if (params.publish_processing_head && !worker_data.empty() && !worker_data.front().intermediate_trajectory.empty())
params.publish_processing_head(worker_data.front().intermediate_trajectory.front().translation());
if (params.publish_trajectory)
params.publish_trajectory(worker_data, true);
for (int i = 0; i < worker_data.size(); i++)
Expand Down Expand Up @@ -2677,6 +2679,9 @@ static bool compute_step_2_impl(

HDMAP_ZONE_END(update_rgd_after);

if (params.publish_processing_head && !worker_data[i].intermediate_trajectory.empty())
params.publish_processing_head(worker_data[i].intermediate_trajectory.back().translation());

if (i > 1)
{
double translation = (worker_data[i - 1].intermediate_trajectory[0].translation() -
Expand Down
214 changes: 214 additions & 0 deletions apps/lidar_odometry_step_1/trajectory_follow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#pragma once

#include <RaylibWidgets/OrbitCamera.h>
#include <raymath.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <limits>
#include <optional>

namespace step1_render
{
// Pick once on double click, using the same matrices and logical viewport as the displayed frame.
// This searches projected pose positions, without rebuilding geometry or reading back GPU buffers.
template<class Workers>
std::optional<Vector3> nearestProjectedTrajectoryPoint(
const Workers& workers, const Matrix& view, const Matrix& projection, Vector2 cursor, float width, float height)
{
if (width <= 0 || height <= 0 || !std::isfinite(cursor.x) || !std::isfinite(cursor.y))
return std::nullopt;
const Matrix m = MatrixMultiply(view, projection);
float bestDistance = std::numeric_limits<float>::infinity();
float bestDepth = std::numeric_limits<float>::infinity();
std::optional<Vector3> result;
for (const auto& worker : workers)
for (const auto& pose : worker.intermediate_trajectory)
{
const auto p = pose.translation().template cast<float>().eval();
const float w = m.m3 * p.x() + m.m7 * p.y() + m.m11 * p.z() + m.m15;
if (!p.allFinite() || !std::isfinite(w) || w <= 1e-6f)
continue;
const float x = (m.m0 * p.x() + m.m4 * p.y() + m.m8 * p.z() + m.m12) / w;
const float y = (m.m1 * p.x() + m.m5 * p.y() + m.m9 * p.z() + m.m13) / w;
const float z = (m.m2 * p.x() + m.m6 * p.y() + m.m10 * p.z() + m.m14) / w;
if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) || std::fabs(x) > 1 || std::fabs(y) > 1 || std::fabs(z) > 1)
continue;
const float dx = (x * 0.5f + 0.5f) * width - cursor.x;
const float dy = (0.5f - y * 0.5f) * height - cursor.y;
const float distance = dx * dx + dy * dy;
if (distance < bestDistance || (distance == bestDistance && z < bestDepth))
{
bestDistance = distance;
bestDepth = z;
result = Vector3{ p.x(), p.y(), p.z() };
}
}
return result;
}

// Only an explicit point selection detaches the pivot from the processing head.
class TrajectoryFollow
{
public:
float idleSeconds = 5.f;

void reset(double now)
{
observed = wasProcessing = suspended = transitioning = recentering = automaticReturn = requested = false;
selected.reset();
lastNavigation = now;
}

void explore(Vector3 point, double now)
{
if (!finite(point))
return;
selected = point;
suspended = transitioning = recentering = true;
automaticReturn = requested = false;
lastNavigation = now;
}

void returnToHead()
{
requested = true;
}

bool exploring() const
{
return suspended;
}

void update(
raylib_widgets::OrbitCamera& camera,
const std::optional<Vector3>& head,
bool processing,
bool interacting,
bool focused,
double now,
float dt)
{
if (observed && state(camera) != previous)
{
lastNavigation = now;
// Pan changes the framing, while orbit and zoom keep the same pivot.
if (camera.euler.translate.x + camera.euler.rotationCenter.x != previous[2] + previous[5] ||
camera.euler.translate.y + camera.euler.rotationCenter.y != previous[3] + previous[6])
recentering = false;
if (camera.isOrtho && (camera.orthoShiftX != previous[17] || camera.orthoShiftY != previous[18]))
{
// Step 1's ortho view uses the Euler transform, not updateOrtho()'s lookAt.
const float dx = camera.orthoShiftX - previous[17], dy = camera.orthoShiftY - previous[18];
const float angle = (camera.euler.rotateX + camera.euler.rotateY) * DEG2RAD;
camera.euler.translate.x += std::cos(angle) * dx + std::sin(angle) * dy;
camera.euler.translate.y -= -std::sin(angle) * dx + std::cos(angle) * dy;
camera.eulerTransitionActive = false;
recentering = false;
}
}
// Stop an automatic return when SLAM ends; explicit exploration/return may finish.
if (wasProcessing && !processing && automaticReturn)
transitioning = recentering = automaticReturn = false;
wasProcessing = processing;
camera.updateEulerTransition(dt);

if (!processing || interacting || !focused)
lastNavigation = now;
if (requested && head && finite(*head))
{
suspended = automaticReturn = false;
transitioning = recentering = true;
selected.reset();
camera.eulerTransitionActive = false;
}
else if (processing && suspended && now - lastNavigation >= idleSeconds && head && finite(*head))
{
suspended = false;
transitioning = recentering = automaticReturn = true;
selected.reset();
camera.eulerTransitionActive = false;
}
requested = false;

const auto target = suspended ? selected : head;
if (focused && target && finite(*target) && (transitioning || (processing && !suspended)))
{
const float alpha = -std::expm1(-std::clamp(dt, 0.f, 0.1f) / (transitioning ? 0.15f : 0.35f));
auto& e = camera.euler;
const Vector3 oldCenter = e.rotationCenter;
e.rotationCenter = Vector3Lerp(oldCenter, *target, alpha);
const Vector3 delta = Vector3Subtract(e.rotationCenter, oldCenter);
e.translate = Vector3Subtract(e.translate, delta); // preserve pan and zoom while the pivot moves
const float dx = recentering ? -(e.translate.x + e.rotationCenter.x) * alpha : 0;
const float dy = recentering ? -(e.translate.y + e.rotationCenter.y) * alpha : 0;
e.translate.x += dx;
e.translate.y += dy;
if (camera.eulerTransitionActive)
{
// Preserve camera-menu orientation transitions while following a moving head.
camera.eulerGoal.rotationCenter = e.rotationCenter;
camera.eulerGoal.translate = Vector3Subtract(camera.eulerGoal.translate, delta);
camera.eulerGoal.translate.x += dx;
camera.eulerGoal.translate.y += dy;
}
else
camera.eulerGoal = e;
float error = Vector3Distance(e.rotationCenter, *target);
if (recentering)
error =
std::max({ error, std::fabs(e.translate.x + e.rotationCenter.x), std::fabs(e.translate.y + e.rotationCenter.y) });
if (error < 0.01f)
transitioning = recentering = automaticReturn = false;
}
previous = state(camera);
observed = true;
}

private:
static bool finite(Vector3 point)
{
return std::isfinite(point.x) && std::isfinite(point.y) && std::isfinite(point.z);
}

static std::array<float, 22> state(const raylib_widgets::OrbitCamera& camera)
{
const auto& e = camera.euler;
const auto& g = camera.eulerGoal;
return { e.rotateX,
e.rotateY,
e.translate.x,
e.translate.y,
e.translate.z,
e.rotationCenter.x,
e.rotationCenter.y,
e.rotationCenter.z,
g.rotateX,
g.rotateY,
g.translate.x,
g.translate.y,
g.translate.z,
g.rotationCenter.x,
g.rotationCenter.y,
g.rotationCenter.z,
camera.orthoZoom,
camera.orthoShiftX,
camera.orthoShiftY,
camera.orthoZCenterH,
static_cast<float>(camera.isOrtho),
static_cast<float>(camera.lockZ) };
}

std::array<float, 22> previous{};
std::optional<Vector3> selected;
double lastNavigation = 0;
bool observed = false;
bool wasProcessing = false;
bool suspended = false;
bool transitioning = false;
bool recentering = false;
bool automaticReturn = false;
bool requested = false;
};
} // namespace step1_render
4 changes: 2 additions & 2 deletions raylib_widgets/include/RaylibWidgets/ShortcutsTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace raylib_widgets
};

// Renders `entries` as a bordered, scrollable two-column table (Shortcut |
// Description) inside the current ImGui window.
void ShowShortcutsTable(const std::vector<ShortcutEntry>& entries);
// Description) inside the current ImGui window, with the requested height.
void ShowShortcutsTable(const std::vector<ShortcutEntry>& entries, float height = 200.f);

} // namespace raylib_widgets
78 changes: 41 additions & 37 deletions raylib_widgets/src/AppShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <imgui_internal.h> // ImGui::DockBuilder*

#include <algorithm>

#ifdef _WIN32
// NOGDI/NOUSER: windows.h's wingdi.h/winuser.h #define (or, for CloseWindow/
// ShowCursor, directly declare) identifiers that collide with raylib.h's own
Expand Down Expand Up @@ -103,49 +105,51 @@ namespace raylib_widgets
return;

static bool show_about = false;
const ImVec2 workSize = ImGui::GetMainViewport()->WorkSize;
const ImVec2 maximum(workSize.x * 0.95f, workSize.y * 0.95f);
ImGui::SetNextWindowSize(ImVec2(std::min(1000.f, maximum.x), std::min(760.f, maximum.y)), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(std::min(540.f, maximum.x), std::min(480.f, maximum.y)), maximum);

if (ImGui::Begin(
"Info",
&open,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse))
if (ImGui::Begin("Info", &open, ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse))
{
bool firstLine = true;
for (const auto& line : infoLines)
if (ImGui::BeginTabBar("InfoTabs"))
{
if (line.empty())
ImGui::NewLine();
else if (line.rfind("https://", 0) == 0)
ImGuiHyperlink(line.c_str());
else
ImGui::TextUnformatted(line.c_str());

if (firstLine)
if (ImGui::BeginTabItem("Controls", nullptr, ImGuiTabItemFlags_NoPushId))
{
ImGui::SameLine(
ImGui::GetWindowWidth() - ImGui::CalcTextSize("ImGui").x - ImGui::GetStyle().ItemSpacing.x * 2 -
ImGui::GetStyle().FramePadding.x * 2);
if (ImGui::Button("ImGui"))
show_about = true;

firstLine = false;
ShowShortcutsTable(appShortcuts, std::max(1.f, ImGui::GetContentRegionAvail().y));
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("About / camera guide", nullptr, ImGuiTabItemFlags_NoPushId))
{
if (ImGui::BeginChild("InfoDetails"))
{
ImGui::PushTextWrapPos(0.f);
for (const auto& line : infoLines)
{
if (line.empty())
ImGui::NewLine();
else if (line.rfind("https://", 0) == 0)
ImGuiHyperlink(line.c_str());
else
ImGui::TextUnformatted(line.c_str());
}

ImGui::NewLine();
ImGui::TextUnformatted("Author: Janusz Bedkowski & contributors");
ImGui::NewLine();
ImGui::TextUnformatted("Part of HDMapping software suite");
ImGui::Text("Version: %s (%s)", versionString, buildDate);
ImGui::TextUnformatted("Project page:");
ImGuiHyperlink("https://github.com/MapsHD/HDMapping");
ImGui::PopTextWrapPos();
if (ImGui::Button("ImGui"))
show_about = true;
}
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}

ImGui::NewLine();
ImGui::Text("Author: Janusz Bedkowski & contributors");
ImGui::NewLine();
ImGui::Text("Part of HDMapping software suite");
ImGui::Text("Version: %s (%s)", versionString, buildDate);
ImGui::Text("Project page: ");
ImGui::SameLine();
ImGuiHyperlink("https://github.com/MapsHD/HDMapping");

ImGui::NewLine();
ImGui::Separator();
ImGui::NewLine();

ShowShortcutsTable(appShortcuts);

if (show_about)
ImGui::ShowAboutWindow(&show_about);
}
Expand Down
12 changes: 9 additions & 3 deletions raylib_widgets/src/ShortcutsTable.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#include <RaylibWidgets/ShortcutsTable.h>
#include <imgui.h>

#include <algorithm>
#include <cfloat>

namespace raylib_widgets
{

void ShowShortcutsTable(const std::vector<ShortcutEntry>& entries)
void ShowShortcutsTable(const std::vector<ShortcutEntry>& entries, float height)
{
if (!ImGui::BeginTable(
"ShortcutsTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(-FLT_MIN, 200)))
"ShortcutsTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY, ImVec2(-FLT_MIN, height)))
return;

float shortcutWidth = 120.f;
for (const auto& entry : entries)
if (!entry.description.empty())
shortcutWidth =
std::max(shortcutWidth, ImGui::CalcTextSize(entry.shortcut.c_str()).x + ImGui::GetStyle().CellPadding.x * 2);
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableSetupColumn("Shortcut", ImGuiTableColumnFlags_WidthFixed, 120);
ImGui::TableSetupColumn("Shortcut", ImGuiTableColumnFlags_WidthFixed, shortcutWidth);
ImGui::TableSetupColumn("Description");
ImGui::TableHeadersRow();

Expand Down
Loading