ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
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 <stdlib.h> /* malloc, free, rand */
#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
// Retrieve num_slices
int num_slices;
reme_options_get_int(c, o, "volume.resolution.z", &num_slices);
// 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;
void *load_buffer = 0;
int load_buffer_length = 0;
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' : {
FILE *f = fopen("volume.bin", "wb");
for (int i = 0; i < num_slices; i++) {
reme_volume_slice_get_bytes(c, v, i, &bytes, &length);
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");
for (int i = 0; i < num_slices; i++) {
fread(&length, sizeof(int), 1, f);
if (load_buffer_length != length) {
if (load_buffer != 0) {
free(load_buffer);
}
load_buffer = malloc(length);
load_buffer_length = length;
}
fread(load_buffer, 1, length, f);
reme_volume_slice_set_bytes(c , v, i, load_buffer, length);
}
fclose(f);
if (load_buffer != 0) {
free(load_buffer);
load_buffer = 0;
load_buffer_length = 0;
}
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
// Update volume with depth data from the
// current sensor perspective
}
// Update the viewer
reme_viewer_update(c, viewer);
}
// Print pending errors
// Make sure to release all memory acquired
}
BOOST_AUTO_TEST_SUITE_END()