From e9a491f5baa4f03059b5bfc4fe28d2cd7b34b7e3 Mon Sep 17 00:00:00 2001 From: Evgeni Raikhel Date: Mon, 21 Jan 2019 19:14:59 +0200 Subject: [PATCH 1/2] Fix pose trajectory in Playback mode Change-Id: Id1244a5457e3899d049a1831053f95b283efa6e2 --- common/model-views.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/common/model-views.cpp b/common/model-views.cpp index 734656706a..d805a3be18 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -1398,6 +1398,16 @@ namespace rs2 { viewer.not_model.add_log("Stopping streaming"); + // TODO - refactor tm2 from viewer to subdevice + for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](auto& kvp) + { + if ("Pose" == kvp.second) + { + viewer.tm2.reset_trajectory(); + viewer.tm2.record_trajectory(false); + } + }); + streaming = false; _pause = false; @@ -1441,6 +1451,13 @@ namespace rs2 ss << "..."; viewer.not_model.add_log(ss.str()); + // TODO - refactor tm2 from viewer to subdevice + for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](auto& kvp) + { + if ("Pose" == kvp.second) + viewer.tm2.record_trajectory(true); + }); + s->open(profiles); try { From 87f3f048e2d10197649349ac66a80cbbb0d7fb6d Mon Sep 17 00:00:00 2001 From: Evgeni Raikhel Date: Tue, 22 Jan 2019 12:10:53 +0200 Subject: [PATCH 2/2] Realsense-viewer fixes Fix OpenGl state handling. Adjust pose grid scale to depth default view Stream info caption alignment Replace auto with explicit type in for_each (GCC 4.8) Fix texture selection on device disconnect Change-Id: I7d707a790aa03b547208c04b75e8e52a267c48c5 --- common/model-views.cpp | 71 ++++++++++++++++++++++-------------------- common/rendering.h | 2 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/common/model-views.cpp b/common/model-views.cpp index d805a3be18..e52a224855 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -1399,7 +1399,7 @@ namespace rs2 viewer.not_model.add_log("Stopping streaming"); // TODO - refactor tm2 from viewer to subdevice - for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](auto& kvp) + for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](std::pair kvp) { if ("Pose" == kvp.second) { @@ -1452,7 +1452,7 @@ namespace rs2 viewer.not_model.add_log(ss.str()); // TODO - refactor tm2 from viewer to subdevice - for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](auto& kvp) + for_each(stream_display_names.begin(), stream_display_names.end(), [&viewer](std::pair kvp) { if ("Pose" == kvp.second) viewer.tm2.record_trajectory(true); @@ -2072,7 +2072,8 @@ namespace rs2 { if (selected_tex_source_uid == -1 && selected_depth_source_uid != -1) { - selected_tex_source_uid = streams_origin[s.second.profile.unique_id()]; + if (streams.find(streams_origin[s.second.profile.unique_id()]) != streams.end()) + selected_tex_source_uid = streams_origin[s.second.profile.unique_id()]; } if (streams_origin[s.second.profile.unique_id()] == selected_tex_source_uid) { @@ -2169,7 +2170,9 @@ namespace rs2 ImGui::PushItemWidth(combo_box_width); draw_combo_box("##Tex Source", tex_sources_str, selected_tex_source); - selected_tex_source_uid = tex_sources[selected_tex_source]; + if (streams.find(tex_sources[selected_tex_source]) != streams.end()) + selected_tex_source_uid = tex_sources[selected_tex_source]; + ImGui::PopItemWidth(); ImGui::SameLine(); @@ -2642,11 +2645,11 @@ namespace rs2 switch (this->texture->currentGrid.unit) { case GRID_STEP_UNIT_METER: - newGrid.set(1.0f); + newGrid.set(1.f); newGrid.set(GRID_STEP_UNIT_FEET); break; case GRID_STEP_UNIT_FEET: - newGrid.set(0.1f); + newGrid.set(1.f); newGrid.set(GRID_STEP_UNIT_METER); break; } @@ -2667,7 +2670,7 @@ namespace rs2 break; case GRID_STEP_UNIT_FEET: switchToUnit = "Meter"; - switchToStep = 0.1f; + switchToStep = 1.f; break; } @@ -2798,31 +2801,31 @@ namespace rs2 std::string res; if (profile.as()) - res = to_string() << size.x << "x" << size.y << ", "; - label = to_string() << res << truncate_string(rs2_format_to_string(profile.format()),9) << ", FPS:"; + res = to_string() << size.x << "x" << size.y << ", "; + label = to_string() << res << truncate_string(rs2_format_to_string(profile.format()),9) << ", "; ImGui::Text("%s", label.c_str()); if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("%s", rs2_format_to_string(profile.format())); + ImGui::SetTooltip("%s","Stream Resolution, Format"); } ImGui::SameLine(); - label = to_string() << std::setprecision(2) << std::fixed << fps.get_fps(); + label = to_string() << "FPS: " << std::setprecision(2) << std::setw(7) << std::fixed << fps.get_fps(); ImGui::Text("%s", label.c_str()); if (ImGui::IsItemHovered()) { - ImGui::SetTooltip("FPS is calculated based on timestamps and not viewer time"); + ImGui::SetTooltip("%s", "FPS is calculated based on timestamps and not viewer time"); } - ImGui::SameLine(170); + ImGui::SameLine(); - label = to_string() << "Frame" << frame_number; + label = to_string() << " Frame: " << std::left << frame_number; ImGui::Text("%s", label.c_str()); - ImGui::SameLine(300); + ImGui::SameLine(290); - label = to_string() << "Time: " << std::fixed << std::setprecision(1) << timestamp; + label = to_string() << "Time: " << std::left << std::fixed << std::setprecision(1) << timestamp; ImGui::Text("%s", label.c_str()); if (ImGui::IsItemHovered()) { @@ -2831,7 +2834,7 @@ namespace rs2 ImGui::BeginTooltip(); ImGui::PushTextWrapPos(450.0f); ImGui::PushStyleColor(ImGuiCol_Text, red); - ImGui::TextUnformatted("Timestamp: SystemTime (Hardware Timestamp unavailable! This is often an indication of improperly applied Kernel patch.\nPlease refer to metadata.md for mode information)"); + ImGui::TextUnformatted("Timestamp: SystemTime (Hardware Timestamp unavailable.\nPlease refer to frame_metadata.md for mode information)"); ImGui::PopStyleColor(); ImGui::PopTextWrapPos(); ImGui::EndTooltip(); @@ -4465,12 +4468,13 @@ namespace rs2 uint32_t horizontal = boxHorizontalLength / 2; uint32_t vertical = (boxVerticalLength-1) / 2; + glPushAttrib(GL_CURRENT_BIT); + glPushAttrib(GL_LINE_BIT); + glLineWidth(1.f); + glColor4f(0.4f, 0.4f, 0.4f, 1.f); glBegin(GL_LINES); - glColor4f(0.2f, 0.2f, 0.2f, 0.8f); - - glTranslatef(0, 0, -1); - // Render box grid + // Render the box grid float currentYStep = boxVerticalAlignment * step; for (uint8_t y = 0; y <= (boxVerticalLength-1); y++) @@ -4500,8 +4504,9 @@ namespace rs2 } currentZStep += step; } - glEnd(); + glPopAttrib(); // color + glPopAttrib(); // line width } void viewer_model::render_camera_mesh(int id) @@ -4509,7 +4514,6 @@ namespace rs2 glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); - glBegin(GL_TRIANGLES); auto& mesh = camera_mesh[id]; @@ -4565,13 +4569,12 @@ namespace rs2 glEnable(GL_DEPTH_TEST); - glLineWidth(1); - auto r1 = matrix4::identity(); auto r2 = matrix4::identity(); if (draw_plane) { + glPushAttrib(GL_LINE_BIT); glLineWidth(2); glBegin(GL_LINES); @@ -4592,6 +4595,7 @@ namespace rs2 } glEnd(); + glPopAttrib(); } auto x = static_cast(-M_PI / 2); @@ -4657,20 +4661,13 @@ namespace rs2 } } - glPopMatrix(); - if (!pose) { - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadMatrixf(r1 * view_mat); - glLineWidth(1); glLineWidth(1); + // Render "floor" grid + glLineWidth(1); glBegin(GL_LINES); glColor4f(0.4f, 0.4f, 0.4f, 1.f); - glTranslatef(0, 0, -1); - - // Render "floor" grid for (int i = 0; i <= 6; i++) { glVertex3i(i - 3, 1, 0); @@ -4679,6 +4676,10 @@ namespace rs2 glVertex3i(3, 1, i); } glEnd(); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadMatrixf(r1 * view_mat); texture_buffer::draw_axes(0.4f, 1); glPopMatrix(); } @@ -4823,6 +4824,8 @@ namespace rs2 glPopMatrix(); } + glPopMatrix(); + glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); diff --git a/common/rendering.h b/common/rendering.h index e5c7fb505a..ec199bf850 100644 --- a/common/rendering.h +++ b/common/rendering.h @@ -1014,7 +1014,7 @@ namespace rs2 class pose_grid { public: - pose_grid() : step(0.1f), pixelStep(0.1f), unit(GRID_STEP_UNIT_METER), boxHorizontalLength(6), boxVerticalLength(1), boxVerticalAlignment(1) {} + pose_grid() : step(1.f), pixelStep(1.f), unit(GRID_STEP_UNIT_METER), boxHorizontalLength(12), boxVerticalLength(1), boxVerticalAlignment(1) {} void set(pose_grid newGrid) {