/// <summary> /// Enumerate the devices capable of running KinectFusion. /// This enables a specific device to be chosen when calling NuiFusionCreateReconstruction if desired. /// </summary> /// <param name="type">The type of processor to enumerate.</param> /// <param name="index"> /// The zero-based index of the device for which the description is returned. /// or -1 for the default device for the given processor type. /// </param> /// <param name="description">On success, the variable is assigned the description string for the device.</param> /// <param name="instancePath">On success, the variable is assigned the instance path for the device.</param> /// <param name="memoryKB">On success, the variable is assigned the total amount of memory on the device, in kilobytes.</param> /// <exception cref="IndexOutOfRangeException"> /// Thrown when the <paramref name="index"/> parameter is out of range for the specified processor type. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="type"/> parameter is out of range. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown when the call failed for an unknown reason. /// </exception> public static void GetDeviceInfo( ReconstructionProcessor type, int index, out string description, out string instancePath, out int memoryKB) { const int MaxBufferLength = 260; StringBuilder descriptionBuffer = new StringBuilder(MaxBufferLength); StringBuilder instancePathBuffer = new StringBuilder(MaxBufferLength); uint memoryInKB = 0; ExceptionHelper.ThrowIfFailed(NativeMethods.NuiFusionGetDeviceInfo( type, index, descriptionBuffer, (uint)descriptionBuffer.Capacity, instancePathBuffer, (uint)instancePathBuffer.Capacity, out memoryInKB)); // Save the results description = descriptionBuffer.ToString(); instancePath = instancePathBuffer.ToString(); memoryKB = (int)memoryInKB; }
/// <summary> /// Constructs and prepares the ColorReconstruction for data input /// </summary> private void RecreateReconstruction() { ReconstructionParameters volParam = new ReconstructionParameters(voxelsPerMeter, voxelsX, voxelsY, voxelsZ); worldToCameraTransform = Matrix4.Identity; ReconstructionProcessor ProcessorType = ReconstructionProcessor.Amp; volume = ColorReconstruction.FusionCreateReconstruction(volParam, ProcessorType, -1, worldToCameraTransform); defaultWorldToVolumeTransform = volume.GetCurrentWorldToVolumeTransform(); ResetReconstruction(); worldToBGRTransform = Matrix4.Identity; worldToBGRTransform.M11 = voxelsPerMeter / voxelsX; worldToBGRTransform.M22 = voxelsPerMeter / voxelsY; worldToBGRTransform.M33 = voxelsPerMeter / voxelsZ; worldToBGRTransform.M41 = 0.5f; worldToBGRTransform.M42 = 0.5f; worldToBGRTransform.M44 = 1.0f; }
/// <summary> /// Initialize a Kinect Fusion 3D Reconstruction Volume. /// Voxel volume axis sizes must be greater than 0 and a multiple of 32. /// Users can select which device the processing is performed on with /// the <paramref name="reconstructionProcessorType"/> parameter. For those with multiple GPUs /// the <paramref name="deviceIndex"/> parameter also enables users to explicitly configure /// on which device the reconstruction volume is created. /// </summary> /// <param name="reconstructionParameters"> /// The Reconstruction parameters to define the size and shape of the reconstruction volume. /// </param> /// <param name="reconstructionProcessorType"> /// the processor type to be used for all calls to the reconstruction volume object returned /// from this function. /// </param> /// <param name="deviceIndex">Set this variable to an explicit zero-based device index to use /// a specific GPU as enumerated by NuiFusionGetDeviceInfo, or set to -1 to automatically /// select the default device for a given processor type. /// </param> /// <param name="initialWorldToCameraTransform"> /// The initial camera pose of the reconstruction volume with respect to the world origin. /// Pass identity as the default camera pose. /// </param> /// <returns>The Reconstruction instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown when the <paramref name="reconstructionParameters"/> parameter is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="reconstructionParameters"/> parameter's <c>VoxelX</c>, /// <c>VoxelY</c>, or <c>VoxelZ</c> member is not a greater than 0 and multiple of 32 or the /// <paramref name="deviceIndex"/> parameter is less than -1 or greater than the number of /// available devices for the respective processor type. /// </exception> /// <exception cref="OutOfMemoryException"> /// Thrown when the memory required for the Reconstruction volume processing could not be /// allocated. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown when the Kinect Runtime could not be accessed, the Kinect device is not /// connected or the Reconstruction volume is too big so a GPU memory /// allocation failed, or the call failed for an unknown reason. /// </exception> public static Reconstruction FusionCreateReconstruction( ReconstructionParameters reconstructionParameters, ReconstructionProcessor reconstructionProcessorType, int deviceIndex, Matrix4 initialWorldToCameraTransform) { if (null == reconstructionParameters) { throw new ArgumentNullException("reconstructionParameters"); } INuiFusionReconstruction reconstruction = null; ExceptionHelper.ThrowIfFailed(NativeMethods.NuiFusionCreateReconstruction( reconstructionParameters, reconstructionProcessorType, deviceIndex, ref initialWorldToCameraTransform, out reconstruction)); return(new Reconstruction(reconstruction)); }
/// <summary> /// Initialize a Kinect Fusion 3D Reconstruction Volume. /// Voxel volume axis sizes must be greater than 0 and a multiple of 32. A Kinect camera /// is also required to be connected. /// </summary> /// <param name="reconstructionParameters"> /// The Reconstruction parameters to define the size and shape of the reconstruction volume. /// </param> /// <param name="reconstructionProcessorType"> /// the processor type to be used for all calls to the reconstruction volume object returned /// from this function. /// </param> /// <param name="deviceIndex">Set this variable to an explicit zero-based device index to use /// a specific GPU as enumerated by FusionDepthProcessor.GetDeviceInfo, or set to -1 to /// automatically select the default device for a given processor type. /// </param> /// <param name="initialWorldToCameraTransform"> /// The initial camera pose of the reconstruction volume with respect to the world origin. /// Pass identity as the default camera pose. /// </param> /// <returns>The Reconstruction instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown when the <paramref name="reconstructionParameters"/> parameter is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown when the <paramref name="reconstructionParameters"/> parameter's <c>VoxelX</c>, /// <c>VoxelY</c>, or <c>VoxelZ</c> member is not a greater than 0 and multiple of 32. /// Thrown when the <paramref name="deviceIndex"/> parameter is less than -1 or greater /// than the number of available devices for the respective processor type. /// </exception> /// <exception cref="OutOfMemoryException"> /// Thrown when the memory required for the Reconstruction volume processing could not be /// allocated. /// </exception> /// <exception cref="InvalidOperationException"> /// Thrown when the Kinect Runtime could not be accessed, the Kinect device is not /// connected or the Reconstruction volume is too big so a GPU memory allocation failed, /// or the call failed for an unknown reason. /// </exception> /// <remarks> /// Users can select which device the processing is performed on with /// the <paramref name="reconstructionProcessorType"/> parameter. For those with multiple GPUs /// the <paramref name="deviceIndex"/> parameter also enables users to explicitly configure /// on which device the reconstruction volume is created. /// Note that this function creates a default world-volume transform. To set a non-default /// transform call ResetReconstruction with an appropriate Matrix4. This default transformation /// is a combination of translation in X,Y to locate the world origin at the center of the front /// face of the reconstruction volume cube, and scaling by the voxelsPerMeter reconstruction /// parameter to convert from the world coordinate system to volume voxel indices. /// </remarks> public static Reconstruction FusionCreateReconstruction( ReconstructionParameters reconstructionParameters, ReconstructionProcessor reconstructionProcessorType, int deviceIndex, Matrix4 initialWorldToCameraTransform) { if (null == reconstructionParameters) { throw new ArgumentNullException("reconstructionParameters"); } INuiFusionReconstruction reconstruction = null; ExceptionHelper.ThrowIfFailed(NativeMethods.NuiFusionCreateReconstruction( reconstructionParameters, reconstructionProcessorType, deviceIndex, ref initialWorldToCameraTransform, out reconstruction)); return new Reconstruction(reconstruction); }