Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLY export #5110

Merged
merged 25 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
86bde93
Added ply configuration: meshing / points in viewer
AnnaRomanov Aug 27, 2019
aaf50eb
Added binary / textual format for PLY in viewer
AnnaRomanov Aug 28, 2019
8a893e5
Addded options to ply callback
AnnaRomanov Sep 1, 2019
9d2df5b
Use save_to_ply processing block in viewer, some fixes in the process…
AnnaRomanov Sep 9, 2019
4a2a6b0
moved frame allocator processing block to a new filter class
AnnaRomanov Sep 10, 2019
0652311
added normals to ply
AnnaRomanov Sep 11, 2019
b432726
fix normals export, changed to generic code for file exporters in viewer
AnnaRomanov Sep 18, 2019
37b93dd
back to original export_to_ply function, options are now supported in…
AnnaRomanov Sep 18, 2019
a164a90
fix default option values, remove unnecessary comments
AnnaRomanov Sep 18, 2019
d9336a9
merge fix
AnnaRomanov Sep 18, 2019
018d11c
fix button position
AnnaRomanov Sep 22, 2019
0adaea3
order change
AnnaRomanov Sep 22, 2019
b808ff3
for test
AnnaRomanov Sep 22, 2019
5bf84dc
fix linux build
AnnaRomanov Sep 22, 2019
1db327c
Fix python build, update export_to_ply python example
AnnaRomanov Sep 23, 2019
e858531
Fixes following code review
AnnaRomanov Sep 24, 2019
f94f832
Removed "ok" button and fixed issue with file dialog
AnnaRomanov Oct 2, 2019
eea6ebc
Added make_exporter template function which deduces char array size
AnnaRomanov Oct 3, 2019
9a1f849
Change member name
AnnaRomanov Oct 3, 2019
dbaa4fd
Changed default encoding to binary
AnnaRomanov Oct 17, 2019
65bc6ef
Adding persistent export progress notification
dorodnic Oct 17, 2019
0872601
Merge remote-tracking branch 'anna/configure_ply' into configure_ply
dorodnic Oct 23, 2019
4a9194d
Merge tag 'v2.30.1' into configure_ply
dorodnic Nov 11, 2019
edfe7ec
Code review fixes
dorodnic Nov 11, 2019
5df8990
Adding treshold option to python and matlab wrappers
dorodnic Nov 12, 2019
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
3 changes: 2 additions & 1 deletion common/fw-update-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace rs2
{
public:
firmware_update_manager(device_model& model, device dev, context ctx, std::vector<uint8_t> fw, bool is_signed)
: process_manager("Firmware Update", model),
: process_manager("Firmware Update"), _model(model),
_fw(fw), _is_signed(is_signed), _dev(dev), _ctx(ctx) {}

private:
Expand All @@ -32,6 +32,7 @@ namespace rs2
context _ctx;
std::vector<uint8_t> _fw;
bool _is_signed;
device_model& _model;
};

struct fw_update_notification_model : public process_notification_model
Expand Down
19 changes: 9 additions & 10 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,16 @@ namespace rs2
texture_data[idx], texture_data[idx + 1], texture_data[idx + 2]);
}

void export_to_ply(const std::string& fname, notifications_model& ns, points p, video_frame texture, bool notify)
void export_frame(const std::string& fname, std::unique_ptr<rs2::filter> exporter,
notifications_model& ns, frame data, bool notify)
{
std::thread([&ns, p, texture, fname, notify]() mutable {
if (p)
{
p.export_to_ply(fname, texture);
if (notify) ns.add_notification({ to_string() << "Finished saving 3D view " << (texture ? "to " : "without texture to ") << fname,
RS2_LOG_SEVERITY_INFO,
RS2_NOTIFICATION_CATEGORY_UNKNOWN_ERROR });
}
}).detach();
auto manager = std::make_shared<export_manager>(fname, std::move(exporter), data);

auto n = std::make_shared<export_notification_model>(manager);
ns.add_notification(n);
n->forced = true;

manager->start(n);
}

bool save_frame_raw_data(const std::string& filename, rs2::frame frame)
Expand Down
14 changes: 13 additions & 1 deletion common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ namespace rs2
static const char* vsync { "performance.vsync" };
static const char* font_oversample { "performance.font_oversample.v2" };
}
namespace ply
{
static const char* mesh { "ply.mesh" };
static const char* use_normals { "ply.normals" };
static const char* encoding { "ply.encoding" };

enum encoding_types
{
textual = 0,
binary = 1
};
}
}

namespace textual_icons
Expand Down Expand Up @@ -949,7 +961,7 @@ namespace rs2
std::shared_ptr<gl::uploader> uploader; // GL element that helps pre-emptively copy frames to the GPU
};

void export_to_ply(const std::string& file_name, notifications_model& ns, points p, video_frame texture, bool notify = true);
void export_frame(const std::string& fname, std::unique_ptr<rs2::filter> exporter, notifications_model& ns, rs2::frame data, bool notify = true);

// Auxillary function to save stream data in its internal (raw) format
bool save_frame_raw_data(const std::string& filename, rs2::frame frame);
Expand Down
123 changes: 123 additions & 0 deletions common/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,4 +852,127 @@ namespace rs2

_started = true;
}

void export_manager::process_flow(
std::function<void()> cleanup,
invoker invoke)
{
_progress = 5;
_exporter->process(_data);
_progress = 100;

_done = true;
}

void export_notification_model::draw_content(ux_window& win, int x, int y, float t, std::string& error_message)
{
using namespace std;
using namespace chrono;

ImGui::SetCursorScreenPos({ float(x + 9), float(y + 4) });

ImVec4 shadow{ 1.f, 1.f, 1.f, 0.1f };
ImGui::GetWindowDrawList()->AddRectFilled({ float(x), float(y) },
{ float(x + width), float(y + 25) }, ImColor(shadow));

if (update_state != STATE_COMPLETE)
{
ImGui::Text("Export in progress");

ImGui::SetCursorScreenPos({ float(x + 10), float(y + 35) });

ImGui::PushStyleColor(ImGuiCol_Text, alpha(light_grey, 1. - t));

std::string s = to_string() << "Saving 3D view to " <<
get_file_name(get_manager().get_filename());
ImGui::Text("%s", s.c_str());

ImGui::PopStyleColor();
}
else
{
ImGui::Text("Export Completed");

ImGui::SetCursorScreenPos({ float(x + 10), float(y + 35) });
ImGui::PushFont(win.get_large_font());
std::string txt = to_string() << textual_icons::throphy;
ImGui::Text("%s", txt.c_str());
ImGui::PopFont();

ImGui::SetCursorScreenPos({ float(x + 40), float(y + 35) });
std::string s = to_string() << "Finished saving 3D view to " <<
get_file_name(get_manager().get_filename());

ImGui::Text("%s", s.c_str());
}

ImGui::SetCursorScreenPos({ float(x + 5), float(y + height - 25) });

const auto bar_width = width - 115;

if (update_state == STATE_IN_PROGRESS)
{
if (update_manager->done())
{
update_state = STATE_COMPLETE;
pinned = false;
last_progress_time = last_interacted = system_clock::now();
}

if (!expanded)
{
if (update_manager->failed())
{
update_manager->check_error(error_message);
update_state = STATE_FAILED;
pinned = false;
dismiss(false);
}

draw_progress_bar(win, bar_width);

ImGui::SetCursorScreenPos({ float(x + width - 105), float(y + height - 25) });
}
}
}

int export_notification_model::calc_height()
{
return 85;
}

void export_notification_model::set_color_scheme(float t) const
{
notification_model::set_color_scheme(t);

ImGui::PopStyleColor(1);

ImVec4 c;

if (update_state == STATE_COMPLETE)
{
c = alpha(saturate(light_blue, 0.7f), 1 - t);
ImGui::PushStyleColor(ImGuiCol_WindowBg, c);
}
else
{
c = alpha(sensor_bg, 1 - t);
ImGui::PushStyleColor(ImGuiCol_WindowBg, c);
}
}

export_notification_model::export_notification_model(std::shared_ptr<export_manager> manager)
: process_notification_model(manager)
{
enable_expand = false;
expanded = false;
if (expanded) visible = false;

message = "";
update_state = STATE_IN_PROGRESS;
this->severity = RS2_LOG_SEVERITY_INFO;
this->category = RS2_NOTIFICATION_CATEGORY_FIRMWARE_UPDATE_RECOMMENDED;

pinned = true;
}
}
46 changes: 42 additions & 4 deletions common/notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ namespace rs2
class process_manager : public std::enable_shared_from_this<process_manager>
{
public:
process_manager(std::string name, device_model& model)
: _process_name(name), _model(model) {}
process_manager(std::string name)
: _process_name(name) {}

void start(std::shared_ptr<notification_model> n);
int get_progress() const { return _progress; }
Expand Down Expand Up @@ -126,8 +126,6 @@ namespace rs2
std::mutex _log_lock;
std::string _last_error;
std::string _process_name;

device_model& _model;
};

struct process_notification_model : public notification_model
Expand Down Expand Up @@ -199,4 +197,44 @@ namespace rs2
{
return{ v.x, v.y, v.z, a };
}

class export_manager : public process_manager
{
public:
export_manager(const std::string& fname, std::unique_ptr<rs2::filter> exporter, frame data)
: process_manager("Export"), _fname(fname), _exporter(std::move(exporter)), _data(data) {}

std::string get_filename() const { return _fname; }
frame get_data() const { return _data; }


private:
void process_flow(std::function<void()> cleanup,
invoker invoke) override;

std::string _fname;
std::unique_ptr<rs2::filter> _exporter;
frame _data;
};

struct export_notification_model : public process_notification_model
{
enum states
{
STATE_INITIAL_PROMPT = 0,
STATE_IN_PROGRESS = 1,
STATE_COMPLETE = 2,
STATE_FAILED = 3,
};

export_manager& get_manager() {
return *std::dynamic_pointer_cast<export_manager>(update_manager);
}

export_notification_model(std::shared_ptr<export_manager> manager);

void set_color_scheme(float t) const override;
void draw_content(ux_window& win, int x, int y, float t, std::string& error_message) override;
int calc_height() override;
};
}
3 changes: 2 additions & 1 deletion common/on-chip-calib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace rs2
public:
on_chip_calib_manager(viewer_model& viewer, std::shared_ptr<subdevice_model> sub,
device_model& model, device dev)
: process_manager("On-Chip Calibration", model),
: process_manager("On-Chip Calibration"), _model(model),
_dev(dev), _sub(sub), _viewer(viewer)
{
}
Expand Down Expand Up @@ -80,6 +80,7 @@ namespace rs2

std::vector<uint8_t> _old_calib, _new_calib;
std::vector<std::pair<float, float>> _metrics;
device_model& _model;

bool _restored = true;

Expand Down
4 changes: 4 additions & 0 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ namespace rs2
config_file::instance().set_default(configurations::performance::show_fps, false);
config_file::instance().set_default(configurations::performance::vsync, true);

config_file::instance().set_default(configurations::ply::mesh, true);
config_file::instance().set_default(configurations::ply::use_normals, false);
config_file::instance().set_default(configurations::ply::encoding, configurations::ply::binary);

#ifdef __APPLE__
config_file::instance().set_default(configurations::performance::font_oversample, 8);
config_file::instance().set_default(configurations::performance::enable_msaa, true);
Expand Down
Loading