Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	readme.md
#	wrappers/python/python.cpp
  • Loading branch information
dorodnic committed Nov 21, 2017
2 parents 3f523d6 + 03b8c5a commit 13f3db2
Show file tree
Hide file tree
Showing 88 changed files with 1,889 additions and 907 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test;
sudo apt-get update;
sudo apt-get install -qq build-essential xorg-dev libglu1-mesa-dev libglew-dev libglm-dev;
sudo apt-get install -qq build-essential xorg-dev libgl1-mesa-dev libglu1-mesa-dev libglew-dev libglm-dev;
sudo apt-get install -qq libusb-1.0-0-dev;
sudo apt-get install -qq libgtk-3-dev;
sudo apt-get install -qq python python-dev;
Expand Down Expand Up @@ -93,6 +93,7 @@ script:
# Exit immediately if a command exits with a non-zero status
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
set -e;
pyenv install 3.6.1;
pyenv local `pyenv versions|sed 's/ //g'|grep "^3"|tail -1`;
mkdir build && cd build;
cmake .. -DBUILD_EXAMPLES:BOOL=true -DBUILD_PYTHON_BINDINGS:BOOL=true -DBUILD_NODEJS_BINDINGS:BOOL=true;
Expand Down
390 changes: 236 additions & 154 deletions common/model-views.cpp

Large diffs are not rendered by default.

69 changes: 45 additions & 24 deletions common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ namespace rs2
frame_queue& at(int id)
{
std::lock_guard<std::mutex> lock(_lookup_mutex);
if (_queues.find(id) == _queues.end())
{
_queues[id] = frame_queue(4);
}
return _queues[id];
}

Expand All @@ -172,7 +168,8 @@ namespace rs2
std::map<int, int> selected_format_id;
};

class subdevice_model;
class viewer_model;
class subdevice_model;

class processing_block_model
{
Expand Down Expand Up @@ -209,7 +206,7 @@ namespace rs2
bool is_selected_combination_supported();
std::vector<stream_profile> get_selected_profiles();
void stop();
void play(const std::vector<stream_profile>& profiles);
void play(const std::vector<stream_profile>& profiles, viewer_model& viewer);
void update(std::string& error_message, notifications_model& model);
void draw_options(const std::vector<rs2_option>& drawing_order,
bool update_read_only_options, std::string& error_message,
Expand Down Expand Up @@ -478,14 +475,22 @@ namespace rs2

std::string get_file_name(const std::string& path);

class viewer_model;
class async_pointclound_mapper
{
public:
async_pointclound_mapper()
: keep_calculating_pointcloud(true),
resulting_3d_models(1), depth_frames_to_render(1),
t([this]() {render_loop(); })
async_pointclound_mapper(viewer_model& viewer)
: processing_block([&](rs2::frame f, const rs2::frame_source& source)
{
this->proccess(std::move(f),source);
}),
viewer(viewer),
keep_calculating_pointcloud(true),
depth_stream_active(false),
resulting_3d_models(1),
t([this]() {render_loop(); })
{
processing_block.start(resulting_3d_models);
}

~async_pointclound_mapper() { stop(); }
Expand All @@ -501,17 +506,13 @@ namespace rs2
}
}

void push_frame(frame f)
{
depth_frames_to_render.enqueue(f);
}

points get_points()
rs2::frameset get_points()
{
frame f;
if (resulting_3d_models.poll_for_frame(&f))
{
model = f;
rs2::frameset frameset(f);
model = frameset;
}
return model;
}
Expand All @@ -521,16 +522,22 @@ namespace rs2
rs2::frame f{};
model = f;
while (resulting_3d_models.poll_for_frame(&f));
while (depth_frames_to_render.poll_for_frame(&f));
}

std::atomic<bool> depth_stream_active;

private:
void render_loop();
viewer_model& viewer;

void render_loop();
void proccess(rs2::frame f, const rs2::frame_source& source);
rs2::frame last_tex_frame;
rs2::processing_block processing_block;
pointcloud pc;
points model;
rs2::frameset model;
std::atomic<bool> keep_calculating_pointcloud;
frame_queue depth_frames_to_render;


frame_queue resulting_3d_models;

std::thread t;
Expand All @@ -552,12 +559,19 @@ namespace rs2
float get_output_height() const { return (is_output_collapsed ? default_log_h : 20); }

viewer_model()
:pc(*this),
synchronization_enable(true)
{
reset_camera();
rs2_error* e = nullptr;
not_model.add_log(to_string() << "librealsense version: " << api_version_to_string(rs2_get_api_version(&e)) << "\n");
}

~viewer_model()
{
pc.stop();
streams.clear();
}
void upload_frame(frame&& f);

std::map<int, rect> calc_layout(const rect& r);
Expand Down Expand Up @@ -586,6 +600,7 @@ namespace rs2

void gc_streams();

std::mutex streams_mutex;
std::map<int, stream_model> streams;
bool fullscreen = false;
stream_model* selected_stream = nullptr;
Expand All @@ -597,6 +612,7 @@ namespace rs2
bool is_3d_view = false;
bool paused = false;


void draw_viewport(const rect& viewer_rect, ux_window& window, int devices, std::string& error_message);

bool allow_3d_source_change = true;
Expand All @@ -606,14 +622,19 @@ namespace rs2
bool draw_plane = false;

bool draw_frustrum = true;
bool syncronize = false;
bool support_non_syncronized_mode = true;
std::atomic<bool> synchronization_enable;

int selected_depth_source_uid = -1;
int selected_tex_source_uid = -1;

float dim_level = 1.f;

rs2::syncer s;
rs2::frame_queue syncer_queue;
private:

friend class async_pointclound_mapper;
std::map<int, rect> get_interpolated_layout(const std::map<int, rect>& l);
void show_icon(ImFont* font_18, const char* label_str, const char* text, int x, int y,
int id, const ImVec4& color, const std::string& tooltip = "");
Expand All @@ -633,10 +654,10 @@ namespace rs2
rs2::points last_points;
rs2::frame last_texture;
texture_buffer texture;
rs2::syncer s;

};

void export_to_ply(const std::string& file_name, notifications_model& ns, points points, video_frame texture);
void export_to_ply(const std::string& file_name, notifications_model& ns, frameset points, video_frame texture);

// Wrapper for cross-platform dialog control
enum file_dialog_mode {
Expand Down
6 changes: 3 additions & 3 deletions common/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ namespace rs2
return last;
}

texture_buffer() : last_queue(1), texture(),
texture_buffer() : last_queue(1), texture(),
colorize(std::make_shared<colorizer>()) {}

GLuint get_gl_handle() const { return texture; }
Expand All @@ -777,6 +777,7 @@ namespace rs2

void upload(rs2::frame frame)
{
last_queue.enqueue(frame);
// If the frame timestamp has changed since the last time show(...) was called, re-upload the texture
if (!texture)
glGenTextures(1, &texture);
Expand Down Expand Up @@ -864,7 +865,7 @@ namespace rs2
//}
//break;
default:
throw std::runtime_error("The requested format is not suported for rendering");
throw std::runtime_error("The requested format is not supported for rendering");
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Expand All @@ -873,7 +874,6 @@ namespace rs2
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glBindTexture(GL_TEXTURE_2D, 0);

last_queue.enqueue(frame);
}

static void draw_axis(float axis_size = 1.f, float axisWidth = 4.f)
Expand Down
52 changes: 39 additions & 13 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@ namespace rs2
_win(nullptr), _width(0), _height(0), _output_height(0),
_font_14(nullptr), _font_18(nullptr), _app_ready(false),
_first_frame(true), _query_devices(true), _missing_device(false),
_hourglass_index(0), _dev_stat_message{}
_hourglass_index(0), _dev_stat_message{}, _keep_alive(true)
{
if (!glfwInit())
exit(1);

rs2_error* e = nullptr;
_title_str = to_string() << title << " v" << api_version_to_string(rs2_get_api_version(&e));

_width = 1024;
_height = 768;

// Dynamically adjust new window size (by detecting monitor resolution)
auto primary = glfwGetPrimaryMonitor();
const auto mode = glfwGetVideoMode(primary);
if (primary)
{
const auto mode = glfwGetVideoMode(primary);
_width = int(mode->width * 0.7f);
_height = int(mode->height * 0.7f);
}

// Create GUI Windows
_width = int(mode->width * 0.7f);
_height = int(mode->height * 0.7f);
_win = glfwCreateWindow(_width, _height, _title_str.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(_win);
ImGui_ImplGlfw_Init(_win, true);
Expand Down Expand Up @@ -71,7 +78,7 @@ namespace rs2

// Prepare the splash screen and do some initialization in the background
int x, y, comp;
auto r = stbi_load_from_memory(splash, splash_size, &x, &y, &comp, false);
auto r = stbi_load_from_memory(splash, (int)splash_size, &x, &y, &comp, false);
_splash_tex.upload_image(x, y, r);

// Apply initial UI state
Expand All @@ -97,8 +104,10 @@ namespace rs2

if (_first_frame)
{
std::thread first_load([&]() {
do
assert(!_first_load.joinable()); // You must call to reset() before initiate new thread

_first_load = std::thread([&]() {
while (_keep_alive && !_app_ready)
{
try
{
Expand All @@ -108,10 +117,9 @@ namespace rs2
{
std::this_thread::sleep_for(std::chrono::seconds(1)); // Wait for connect event and retry
}
} while (!_app_ready);
}
});
_first_frame = false;
first_load.detach();
}

// If we are just getting started, render the Splash Screen instead of normal UI
Expand All @@ -123,16 +131,16 @@ namespace rs2
begin_frame();

glPushMatrix();
glViewport(0.f, 0.f, _fb_width, _fb_height);
glViewport(0, 0, _fb_width, _fb_height);
glClearColor(0.036f, 0.044f, 0.051f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity();
glOrtho(0, _width, _height, 0, -1, +1);

// Fade-in the logo
auto opacity = smoothstep(_splash_timer.elapsed_ms(), 100.f, 2000.f);
_splash_tex.show({ 0.f,0.f,(float)_width,(float)_height }, opacity);
auto opacity = smoothstep(float(_splash_timer.elapsed_ms()), 100.f, 2000.f);
_splash_tex.show({ 0.f,0.f,float(_width),float(_height) }, opacity);

std::string hourglass = u8"\uf250";
static periodic_timer every_200ms(std::chrono::milliseconds(200));
Expand Down Expand Up @@ -163,7 +171,7 @@ namespace rs2
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 5, 5 });
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 1);
ImGui::PushStyleColor(ImGuiCol_WindowBg, transparent);
ImGui::SetNextWindowPos({ (float)_width/2 - 150, (float)_height/2 + 70 });
ImGui::SetNextWindowPos({ (float)_width / 2 - 150, (float)_height / 2 + 70 });
ImGui::PushFont(_font_18);
ImGui::SetNextWindowSize({ (float)_width, (float)_height });
ImGui::Begin("Splash Screen Banner", nullptr, flags);
Expand Down Expand Up @@ -211,6 +219,12 @@ namespace rs2

ux_window::~ux_window()
{
if (_first_load.joinable())
{
_keep_alive = false;
_first_load.join();
}

ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object
ImGui_ImplGlfw_Shutdown();
glfwDestroyWindow(_win);
Expand Down Expand Up @@ -262,12 +276,24 @@ namespace rs2

void ux_window::reset()
{
if (_first_load.joinable())
{
_keep_alive = false;
_first_load.join();
_keep_alive = true;
}

_query_devices = true;
_missing_device = false;
_hourglass_index = 0;
_first_frame = true;
_app_ready = false;
_splash_timer.reset();
_dev_stat_message = u8"\uf287 Please connect Intel RealSense device!";

{
std::lock_guard<std::mutex> lock(_on_load_message_mtx);
_on_load_message.clear();
}
}
}
3 changes: 3 additions & 0 deletions common/ux-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "imgui.h"
#include <string>
#include <functional>
#include <thread>
#include "rendering.h"

namespace rs2
Expand Down Expand Up @@ -71,8 +72,10 @@ namespace rs2
std::string _error_message;
float _scale_factor;

std::thread _first_load;
bool _first_frame;
std::atomic<bool> _app_ready;
std::atomic<bool> _keep_alive;
texture_buffer _splash_tex;
timer _splash_timer;
std::string _title_str;
Expand Down
1 change: 1 addition & 0 deletions config/99-realsense-libusb.rules
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0ad2", MODE:="066
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0ad3", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0ad4", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0ad5", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0ad6", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0af6", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0afe", MODE:="0666", GROUP:="plugdev"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8086", ATTRS{idProduct}=="0aff", MODE:="0666", GROUP:="plugdev"
Expand Down
Loading

0 comments on commit 13f3db2

Please sign in to comment.