ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
example_reconstructmesdk_sensor_threaded.cpp

Content

This example shows how to use multiple sensors working on separate volumes in parallel. Each thread uses its own context and instantiates the allocates objects.

Note, Boost is only used to generate examples and is not necessary for working with this SDK.

#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>
#include <iostream>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
void perform_scan(const char *sensor_config_file, bool &quit, boost::barrier &fence) {
// Create a new context
// Create a new volume
// Create a new sensor
reme_sensor_t sensor;
reme_sensor_create(c, sensor_config_file, false, &sensor);
reme_sensor_open(c, sensor);
// Viewer
reme_viewer_t viewer;
reme_viewer_create_image(c, "This is ReconstructMeSDK", &viewer);
reme_viewer_add_image(c, viewer, img);
// Initialization done, wait for all threads so the main reconstruction
// loop starts at the same time.
fence.wait();
// Enter main reconstruction loop
while (!quit && REME_SUCCESS(reme_sensor_grab(c, sensor))) {
}
reme_viewer_update(c, viewer);
}
}
BOOST_AUTO_TEST_CASE(sensor_threaded) {
bool quit = false;
boost::barrier fence(2);
// Start two reconstruction threads. Note that we've disabled RGB output for both sensors
// in the sensor configuration files to reduce the bandwidth usage.
boost::thread_group g;
g.create_thread(boost::bind(perform_scan, "openni1.txt", boost::ref(quit), boost::ref(fence)));
g.create_thread(boost::bind(perform_scan, "openni2.txt", boost::ref(quit), boost::ref(fence)));
std::cout << "Press any key to stop reconstruction" << std::endl;
std::getchar();
quit = true;
g.join_all();
}
BOOST_AUTO_TEST_SUITE_END()