ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
example_reconstructmesdk_one_minute.cs

Content

This is a one minute example showing basic reconstruction using a single sensor in C#. It uses defaults everywhere and omits error handling.

Compile with csc /platform:x86 /optimize example_reconstructmesdk_one_minute.cs

using System;
using System.Runtime.InteropServices;
using reme_context_t = System.IntPtr;
using reme_volume_t = System.Int32;
using reme_sensor_t = System.Int32;
using reme_viewer_t = System.Int32;
using reme_image_t = System.Int32;
enum reme_sensor_image_t {
};
{
public static void Main()
{
// Create a new context
reme_context_create(ref ctx);
// Compile for OpenCL device using defaults
reme_context_compile(ctx);
// Create a new volume
reme_volume_create(ctx, ref v);
// Create a new sensor using a file data stream. By default
// each sensor works on the first volume created.
reme_sensor_create(ctx, "openni;mskinect;file", true, ref s);
reme_sensor_open(ctx, s);
reme_sensor_set_default_position(ctx, s);
// For debugging purposes open a viewer for tracking the reconstruction process.
// This will create a two-sided viewer showing the video stream and the current
// reconstruction from the sensor point of view.
reme_viewer_t viewer = default(reme_viewer_t);
reme_viewer_create_image(ctx, "This is ReconstructMeSDK", ref viewer);
reme_image_t img_aux = default(reme_image_t);
reme_image_t img_vol = default(reme_image_t);
reme_image_create(ctx, ref img_aux);
reme_image_create(ctx, ref img_vol);
reme_viewer_add_image(ctx, viewer, img_aux);
reme_viewer_add_image(ctx, viewer, img_vol);
while (reme_sensor_grab(ctx, s) == 0) {
// Prepare image and depth data
reme_sensor_prepare_images(ctx, s);
// Try to determine updated sensor position.
// On succes, update volume, otherwise move to a recovery position
// and wait for the tracking to start again.
if (reme_sensor_track_position(ctx, s) == 0)
{
// Update volume with depth data from the
// current sensor perspective
reme_sensor_update_volume(ctx, s);
}
// Update the viewer
reme_sensor_get_image(ctx, s, reme_sensor_image_t.REME_IMAGE_AUX, img_aux);
reme_sensor_get_image(ctx, s, reme_sensor_image_t.REME_IMAGE_VOLUME, img_vol);
reme_viewer_update(ctx, viewer);
}
reme_context_destroy(ref ctx);
}
// Platform Invoke imports
const string REME_SDK_DLL = "LibReconstructMeSDK.dll";
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_context_create(ref reme_context_t ctx);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_context_destroy(ref reme_context_t ctx);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_context_compile(reme_context_t ctx);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_volume_create(reme_context_t ctx, ref reme_volume_t v);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_create(reme_context_t ctx, string driver, bool require_can_open, ref reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_open(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_grab(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_prepare_images(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_get_image(reme_context_t ctx, reme_sensor_t s, reme_sensor_image_t it, reme_image_t i);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_track_position(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_sensor_update_volume(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention = CallingConvention.Cdecl)]
static extern int reme_sensor_set_default_position(reme_context_t ctx, reme_sensor_t s);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_image_create(reme_context_t ctx, ref reme_image_t v);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_viewer_create_image(reme_context_t ctx, string title, ref reme_viewer_t v);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_viewer_add_image(reme_context_t ctx, reme_viewer_t viewer, reme_image_t i);
[DllImport(REME_SDK_DLL, CallingConvention=CallingConvention.Cdecl)]
static extern int reme_viewer_update(reme_context_t ctx, reme_viewer_t v);
}