ReconstructMe SDK  1.1.739-75658
Real-time 3D reconstruction engine
 All Classes Files Functions Typedefs Enumerations Enumerator Groups Pages
example_reconstructmesdk_volume.cpp

Content

This example shows how to save and restore the reconstruction volume.

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

#include <boost/test/unit_test.hpp>
#include <stdio.h>
#include <conio.h>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
BOOST_AUTO_TEST_CASE(volume)
{
puts("Key mapping");
puts("x: quit scanning");
puts("r: reset volume to empty state");
puts("s: save volume to disk");
puts("l: load volume from disk and resume");
puts("All keys need to be pressed with the command line in the foreground");
// Create a new context
// Compile for OpenCL device using defaults
// Create a new volume
// Create a new openni sensor using default intrinsics
reme_sensor_create(c, "openni;mskinect;file", true, &s);
reme_viewer_t viewer;
reme_viewer_create_image(c, "This is ReconstructMeSDK", &viewer);
reme_image_t imgs[2];
reme_image_create(c, &imgs[0]);
reme_image_create(c, &imgs[1]);
reme_viewer_add_image(c, v, imgs[0]);
reme_viewer_add_image(c, v, imgs[1]);
const void *bytes;
int length;
bool continue_scanning = true;
while (continue_scanning && REME_SUCCESS(reme_sensor_grab(c, s))) {
// Keyboard handling
if (_kbhit()) {
char k = _getch();
switch(k) {
// Key 'r' resets the volume to empty state
case 'r': {
break;
}
// Key 's' saves the volume content to disk
case 's' : {
reme_volume_get_bytes(c, v, &bytes, &length);
FILE *f = fopen("volume.bin", "wb");
fwrite(&length, sizeof(int), 1, f);
fwrite(bytes, 1, length, f);
fclose(f);
break;
}
// Key 'l' loads the volume content from disk
case 'l': {
FILE *f = fopen("volume.bin", "rb");
fread(&length, sizeof(int), 1, f);
void *buffer = malloc(length);
fread(buffer, 1, length, f);
fclose(f);
reme_volume_set_bytes(c ,v, buffer, length);
free(buffer);
break;
}
case 'x': {
continue_scanning = false;
break;
}
} // end switch
} // end if kbhit()
// Prepare image and depth data
// Try to determine updated sensor position by
// matching current data against volume content
if (REME_SUCCESS(reme_sensor_track_position(c, s))) {
// Update volume with depth data from the
// current sensor perspective
}
// Update the viewer
reme_viewer_update(c, viewer);
}
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_SUITE_END()