Skip to content

Commit

Permalink
Merge pull request IntelRealSense#6679 from dorodnic/calib_ui
Browse files Browse the repository at this point in the history
UI Enhancements
  • Loading branch information
ev-mp authored Jun 23, 2020
2 parents 283d7d7 + d325faa commit d5ac8bb
Show file tree
Hide file tree
Showing 19 changed files with 3,431 additions and 247 deletions.
4 changes: 4 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/model-views.cpp"
"${CMAKE_CURRENT_LIST_DIR}/notifications.h"
"${CMAKE_CURRENT_LIST_DIR}/notifications.cpp"
"${CMAKE_CURRENT_LIST_DIR}/calibration-model.h"
"${CMAKE_CURRENT_LIST_DIR}/calibration-model.cpp"
"${CMAKE_CURRENT_LIST_DIR}/viewer.h"
"${CMAKE_CURRENT_LIST_DIR}/viewer.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ux-window.h"
Expand All @@ -23,6 +25,8 @@ set(COMMON_SRC
"${CMAKE_CURRENT_LIST_DIR}/fw-update-helper.cpp"
"${CMAKE_CURRENT_LIST_DIR}/metadata-helper.h"
"${CMAKE_CURRENT_LIST_DIR}/metadata-helper.cpp"
"${CMAKE_CURRENT_LIST_DIR}/output-model.h"
"${CMAKE_CURRENT_LIST_DIR}/output-model.cpp"
"${CMAKE_CURRENT_LIST_DIR}/skybox.h"
"${CMAKE_CURRENT_LIST_DIR}/skybox.cpp"
"${CMAKE_CURRENT_LIST_DIR}/measurement.h"
Expand Down
498 changes: 498 additions & 0 deletions common/calibration-model.cpp

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions common/calibration-model.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <librealsense2/rs.hpp>
#include "ux-window.h"

namespace librealsense
{
struct float3x3;
}

namespace rs2
{
class calibration_model
{
public:
calibration_model(rs2::device dev);

bool supports();

void update(ux_window& window, std::string& error_message);

void open() { to_open = true; }

private:
void draw_float4x4(std::string name, librealsense::float3x3& feild, const librealsense::float3x3& original, bool& changed);
void draw_float(std::string name, float& x, const float& orig, bool& changed);

rs2::device dev;
bool to_open = false;
bool _accept = false;

std::vector<uint8_t> _calibration;
std::vector<uint8_t> _original;

int selected_resolution = 0;
};
}
100 changes: 98 additions & 2 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@

#include "imgui-fonts-karla.hpp"
#include "imgui-fonts-fontawesome.hpp"
#include "imgui-fonts-monofont.hpp"

#include "os.h"

#include "metadata-helper.h"

#include "calibration-model.h"

using namespace rs400;
using namespace nlohmann;
Expand Down Expand Up @@ -139,7 +140,7 @@ namespace rs2
file.write((char*)bytes.data(), bytes.size());
}

void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18)
void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18, ImFont*& monofont)
{
ImGuiStyle& style = ImGui::GetStyle();

Expand Down Expand Up @@ -180,6 +181,21 @@ namespace rs2

}

// Load monofont
{
ImFontConfig config_words;
config_words.OversampleV = OVERSAMPLE;
config_words.OversampleH = OVERSAMPLE;
monofont = io.Fonts->AddFontFromMemoryCompressedTTF(monospace_compressed_data, monospace_compressed_size, 15.f);

ImFontConfig config_glyphs;
config_glyphs.MergeMode = true;
config_glyphs.OversampleV = OVERSAMPLE;
config_glyphs.OversampleH = OVERSAMPLE;
monofont = io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_compressed_data,
font_awesome_compressed_size, 14.f, &config_glyphs, icons_ranges);
}

style.WindowRounding = 0.0f;
style.ScrollbarRounding = 0.0f;

Expand Down Expand Up @@ -3358,6 +3374,7 @@ namespace rs2

device_model::device_model(device& dev, std::string& error_message, viewer_model& viewer)
: dev(dev),
_calib_model(dev),
syncer(viewer.syncer),
_update_readonly_options_timer(std::chrono::seconds(6))
, _detected_objects(std::make_shared< atomic_objects_in_frame >()),
Expand Down Expand Up @@ -4507,6 +4524,7 @@ namespace rs2
ImGui::PopFont();
ImGui::PushFont(window.get_font());
static bool keep_showing_advanced_mode_modal = false;
bool open_calibration_ui = false;
if (ImGui::BeginPopup(label.c_str()))
{
bool something_to_show = false;
Expand Down Expand Up @@ -4740,6 +4758,80 @@ namespace rs2
ImGui::SetTooltip("Tare calibration is used to adjust camera absolute distance to flat target.\n"
"User needs to enter the known ground truth");


if (_calib_model.supports())
{
if (ImGui::Selectable("Calibration Data"))
{
_calib_model.open();
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Access low level camera calibration parameters");
}

if (auto fwlogger = dev.as<rs2::firmware_logger>())
{
if (ImGui::Selectable("Recover Logs from Flash"))
{
try
{
bool has_parser = false;
std::string hwlogger_xml = config_file::instance().get(configurations::viewer::hwlogger_xml);
std::ifstream f(hwlogger_xml.c_str());
if (f.good())
{
try
{
std::string str((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
fwlogger.init_parser(str);
has_parser = true;
}
catch (const std::exception& ex)
{
viewer.not_model->output.add_log(RS2_LOG_SEVERITY_WARN, __FILE__, __LINE__,
to_string() << "Invalid Hardware Logger XML at '" << hwlogger_xml << "': " << ex.what() << "\nEither configure valid XML or remove it");
}
}

auto message = fwlogger.create_message();

while (fwlogger.get_flash_log(message))
{
auto parsed = fwlogger.create_parsed_message();
auto parsed_ok = false;

if (has_parser)
{
if (fwlogger.parse_log(message, parsed))
{
parsed_ok = true;

viewer.not_model->output.add_log(message.get_severity(),
parsed.file_name(), parsed.line(), to_string()
<< "FW-LOG [" << parsed.thread_name() << "] " << parsed.message());
}
}

if (!parsed_ok)
{
std::stringstream ss;
for (auto& elem : message.data())
ss << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(elem) << " ";
viewer.not_model->output.add_log(message.get_severity(), __FILE__, 0, ss.str());
}
}
}
catch(const std::exception& ex)
{
viewer.not_model->output.add_log(RS2_LOG_SEVERITY_WARN, __FILE__, __LINE__,
to_string() << "Failed to fetch firmware logs: " << ex.what());
}
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Recovers last set of firmware logs prior to camera shutdown / disconnect");
}

has_autocalib = true;
}
}
Expand All @@ -4766,6 +4858,10 @@ namespace rs2
std::string msg = to_string() << "\t\tAre you sure you want to " << (is_advanced_mode_enabled ? "turn off Advanced mode" : "turn on Advanced mode") << "\t\t";
keep_showing_advanced_mode_modal = prompt_toggle_advanced_mode(!is_advanced_mode_enabled, msg, restarting_device_info, viewer, window);
}

_calib_model.update(window, error_message);


////////////////////////////////////////
// Draw icons names
////////////////////////////////////////
Expand Down
53 changes: 13 additions & 40 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "realsense-ui-advanced-mode.h"
#include "fw-update-helper.h"
#include "updates-model.h"
#include "calibration-model.h"

ImVec4 from_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a, bool consistent_color = false);
ImVec4 operator+(const ImVec4& c, float v);
Expand Down Expand Up @@ -57,7 +58,8 @@ static const ImVec4 yellowish = from_rgba(255, 253, 191, 255, true);
static const ImVec4 green = from_rgba(0x20, 0xe0, 0x20, 0xff, true);
static const ImVec4 dark_sensor_bg = from_rgba(0x1b, 0x21, 0x25, 170);
static const ImVec4 red = from_rgba(233, 0, 0, 255, true);
static const ImVec4 greenish = from_rgba(33, 104, 0, 255);
static const ImVec4 greenish = from_rgba(67, 163, 97, 255);
static const ImVec4 orange = from_rgba(255, 157, 0, 255, true);

inline ImVec4 operator*(const ImVec4& color, float t)
{
Expand All @@ -68,44 +70,6 @@ inline ImVec4 operator+(const ImVec4& a, const ImVec4& b)
return ImVec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
}

// Helper class that lets smoothly animate between its values
template<class T>
class animated
{
private:
T _old, _new;
std::chrono::system_clock::time_point _last_update;
std::chrono::system_clock::duration _duration;
public:
animated(T def, std::chrono::system_clock::duration duration = std::chrono::milliseconds(200))
: _duration(duration)
{
_last_update = std::chrono::system_clock::now();
}
animated& operator=(const T& other)
{
if (other != _new)
{
_old = get();
_new = other;
_last_update = std::chrono::system_clock::now();
}
return *this;
}
T get() const
{
auto now = std::chrono::system_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::microseconds>(now - _last_update).count();
auto duration_ms = std::chrono::duration_cast<std::chrono::microseconds>(_duration).count();
auto t = (float)ms / duration_ms;
t = std::max(0.f, std::min(rs2::smoothstep(t, 0.f, 1.f), 1.f));
return _old * (1.f - t) + _new * t;
}
operator T() const { return get(); }
T value() const { return _new; }
};


inline ImVec4 blend(const ImVec4& c, float a)
{
return{ c.x, c.y, c.z, a * c.w };
Expand Down Expand Up @@ -166,6 +130,10 @@ namespace rs2
static const char* sw_updates_url { "update.sw_update_url" };
static const char* sw_updates_official_server { "update.sw_update_official_server" };
}
namespace calibration
{
static const char* enable_writing { "calibration.enable_writing" };
}
namespace viewer
{
static const char* is_3d_view { "viewer_model.is_3d_view" };
Expand All @@ -176,6 +144,8 @@ namespace rs2
static const char* sdk_version { "viewer_model.sdk_version" };
static const char* last_calib_notice { "viewer_model.last_calib_notice" };
static const char* is_measuring { "viewer_model.is_measuring" };
static const char* output_open { "viewer_model.output_open" };
static const char* search_term { "viewer_model.search_term" };

static const char* log_to_console { "viewer_model.log_to_console" };
static const char* log_to_file { "viewer_model.log_to_file" };
Expand All @@ -186,6 +156,8 @@ namespace rs2
static const char* show_stream_details { "viewer_model.show_stream_details" };
static const char* metric_system { "viewer_model.metric_system" };
static const char* shading_mode { "viewer_model.shading_mode" };
static const char* commands_xml { "viewer_model.commands_xml" };
static const char* hwlogger_xml { "viewer_model.hwlogger_xml" };

static const char* last_ip { "viewer_model.last_ip" };
}
Expand Down Expand Up @@ -284,7 +256,7 @@ namespace rs2
class subdevice_model;
struct notifications_model;

void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18);
void imgui_easy_theming(ImFont*& font_14, ImFont*& font_18, ImFont*& monofont);

// avoid display the following options
bool static skip_option(rs2_option opt)
Expand Down Expand Up @@ -860,6 +832,7 @@ namespace rs2
std::shared_ptr< atomic_objects_in_frame > _detected_objects;
std::shared_ptr<updates_model> _updates;
sw_update::dev_updates_profile::update_profile _updates_profile;
calibration_model _calib_model;
};

class viewer_model;
Expand Down
Loading

0 comments on commit d5ac8bb

Please sign in to comment.