Skip to content

Commit

Permalink
CodeReview fixes:
Browse files Browse the repository at this point in the history
- Renderer to use implicit conversion
- Fix T265 log verbosity level

Change-Id: I4988542e6c19ed142ca43a7a3a0190851c0a2e70
  • Loading branch information
ev-mp committed Mar 20, 2019
1 parent d83b9a0 commit 6c9b144
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 27 deletions.
43 changes: 32 additions & 11 deletions examples/example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,6 @@ class pose_renderer
class texture
{
public:
template<typename T>
struct identity { typedef T type; };

template<typename T>
typename std::enable_if<std::is_base_of<rs2::frame, T>::value, void>::type render(const T& frame, const rect& r)
{
static_assert((std::is_same<T,rs2::video_frame>::value) ||
(std::is_same<T,rs2::motion_frame>::value) ||
(std::is_same<T,rs2::pose_frame>::value), "Rendering is currently supported for video, motion and pose non-aggregative frame types only");
render(frame, r, identity<T>());
}

void upload(const rs2::video_frame& frame)
{
Expand Down Expand Up @@ -444,7 +433,39 @@ class texture

GLuint get_gl_handle() { return _gl_handle; }

template<typename T>
struct identity { typedef T type; };

template<typename T>
typename std::enable_if<std::is_base_of<rs2::frame, T>::value, void>::type render(const T& frame, const rect& r)
{
if ((std::is_same<T, rs2::video_frame>::value) || (std::is_same<T, rs2::motion_frame>::value) || (std::is_same<T, rs2::pose_frame>::value))
{
render(frame, r, identity<T>());
}
else
{
// generic requests are run-time resolved
if (auto vf = frame.as<rs2::video_frame>())
render(vf, r, identity<rs2::video_frame>());
else
{
std::stringstream ss;
ss << "Rendering is currently supported for video, motion and pose non-aggregative frame types only, requested " << typeid(T).name();
throw std::runtime_error(ss.str().c_str());
}
}
}

private:
void render(const rs2::frame& frame, const rect& rect, identity<rs2::frame>)
{
if (auto vf = frame.as<rs2::video_frame>())
render(vf, rect, identity<rs2::video_frame>());
else
throw std::runtime_error("Unsupported frame type");
}

void render(const rs2::video_frame& frame, const rect& rect, identity<rs2::video_frame>)
{
upload(frame);
Expand Down
2 changes: 1 addition & 1 deletion examples/measure/rs-measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ int main(int argc, char * argv[]) try
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// First render the colorized depth image
depth_image.render(colorized_depth.as<rs2::video_frame>(), { 0, 0, app.width(), app.height() });
depth_image.render(colorized_depth, { 0, 0, app.width(), app.height() });
// Next, set global alpha for the color image to 90%
// (to make it slightly translucent)
//glColor4f(1.f, 1.f, 1.f, 0.9f);
Expand Down
8 changes: 4 additions & 4 deletions examples/post-processing/rs-post-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ int main(int argc, char * argv[]) try
// Draw the pointclouds of the original and the filtered frames (if the are available already)
if (colored_depth && original_points)
{
glViewport(0, h / 2, w / 2, h / 2);
draw_pointcloud(w / 2, h / 2, original_view_orientation, original_points);
glViewport(0, int(h) / 2, int(w) / 2, int(h) / 2);
draw_pointcloud(int(w) / 2, int(h) / 2, original_view_orientation, original_points);
}
if (colored_filtered && filtered_points)
{
glViewport(w / 2, h / 2, w / 2, h / 2);
draw_pointcloud(w / 2, h / 2, filtered_view_orientation, filtered_points);
glViewport(int(w) / 2, int(h) / 2, int(w) / 2, int(h) / 2);
draw_pointcloud(int(w) / 2, int(h) / 2, filtered_view_orientation, filtered_points);
}
// Update time of current frame's arrival
auto curr = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion examples/record-playback/rs-record-playback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int main(int argc, char * argv[]) try
ImGui::Render();

// Render depth frames from the default configuration, the recorder or the playback
depth_image.render(depth.as<rs2::video_frame>(), { app.width() * 0.25f, app.height() * 0.25f, app.width() * 0.5f, app.height() * 0.75f });
depth_image.render(depth, { app.width() * 0.25f, app.height() * 0.25f, app.width() * 0.5f, app.height() * 0.75f });
}
return EXIT_SUCCESS;
}
Expand Down
18 changes: 8 additions & 10 deletions third-party/libtm/libtm/src/UsbPlugListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,39 +160,37 @@ void perc::UsbPlugListener::EnumerateDevices()
{
case usb_setup_init:
mInitialized.store(usb_setup_progress);
// Schedule 1000ms for loading if DFU device(s) were found, otherwise 500msec
mUSBMinTimeout = mUSBSetupTimeout = systemTime() + (bootLoader_count ? 1000000000 : 500000000);
// One-time overhead: schedule 1 sec for loading if DFU device(s) were present, otherwise 300 msec.
mUSBMinTimeout = mUSBSetupTimeout = systemTime() + (bootLoader_count ? 1000000000 : 300000000);
mDevicesToProcess = bootLoader_count;
LOGD("usb_setup_init, %d dfu devices, %d TM2 devices, time=%lu , min timeout =%lu",
bootLoader_count, TM_count, systemTime(), mUSBSetupTimeout);
LOGT("usb_setup_init, %d dfu devices, %d TM2 devices, time=%lu , min timeout =%lu", bootLoader_count, TM_count, systemTime(), mUSBSetupTimeout);
break;
case usb_setup_progress:
// New devices discovered during the setup phase will add 1 sec
// Devices discovered during the setup phase will add 1 sec
if (bootLoader_count)
{
mUSBSetupTimeout = systemTime() + 1000000000;
mDevicesToProcess += bootLoader_count;
LOGD("usb_setup_progress, %d new dfu devices, time=%lu, new timeout=%lu",
bootLoader_count, systemTime(), mUSBSetupTimeout);
LOGT("usb_setup_progress, %d new dfu devices, time=%lu, new timeout=%lu", bootLoader_count, systemTime(), mUSBSetupTimeout);
}

if (TM_count)
{
LOGE("New TM2 discovered %d time=%lu, timeout=%lu", TM_count, systemTime(), mUSBSetupTimeout);
LOGT("New TM2 discovered were %d time=%lu, timeout=%lu", TM_count, systemTime(), mUSBSetupTimeout);
}
mDevicesToProcess -= TM_count;

if (systemTime() >= mUSBSetupTimeout)
{
mInitialized.store(usb_setup_timeout);
LOGD("EnumerateDevices: ,timeout occurred time=%lu, timeout=%lu", systemTime(), mUSBSetupTimeout);
LOGT("EnumerateDevices: ,timeout occurred time=%lu, timeout=%lu", systemTime(), mUSBSetupTimeout);
}
else
{
if ((systemTime() >= mUSBMinTimeout) && (!mDevicesToProcess))
{
mInitialized.store(usb_setup_success);
LOGD("EnumerateDevices: ,usb_setup_success time=%lu, timeout=%lu", systemTime(), mUSBSetupTimeout);
LOGT("EnumerateDevices: ,usb_setup_success time=%lu, timeout=%lu", systemTime(), mUSBSetupTimeout);
}
// else wait for process co complete
}
Expand Down

0 comments on commit 6c9b144

Please sign in to comment.