// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; /// /// Inherit frame class with additional point cloud related attributs/functions /// public class Points : Frame { public Points(IntPtr ptr) : base(ptr) { object error; Count = NativeMethods.rs2_get_frame_points_count(Handle, out error); } internal override void Initialize() { object error; Count = NativeMethods.rs2_get_frame_points_count(Handle, out error); } public int Count { get; private set; } /// Gets a pointer to an array of 3D vertices of the model /// /// The coordinate system is: X right, Y up, Z away from the camera. Units: Meters /// /// Pointer to an array of vertices, lifetime is managed by the frame public IntPtr VertexData { get { object error; return NativeMethods.rs2_get_frame_vertices(Handle, out error); } } private void Copy(IntPtr src, IntPtr dst, int size) { Debug.Assert(src != IntPtr.Zero); Debug.Assert(dst != IntPtr.Zero); NativeMethods.Memcpy(dst, src, size); } /// /// Copy vertex data to managed array /// /// array element type /// Array to copy into /// Thrown when is null public void CopyVertices(T[] vertices) { if (vertices == null) { throw new ArgumentNullException(nameof(vertices)); } Debug.Assert(vertices.Length * Marshal.SizeOf(typeof(T)) == Count * 3 * sizeof(float)); var handle = GCHandle.Alloc(vertices, GCHandleType.Pinned); try { Copy(VertexData, handle.AddrOfPinnedObject(), Count * 3 * sizeof(float)); } finally { handle.Free(); } } /// Gets a pointer to an array of texture coordinates per vertex /// /// Each coordinate represent a (u,v) pair within [0,1] range, to be mapped to texture image /// /// Pointer to an array of texture coordinates, lifetime is managed by the frame public IntPtr TextureData { get { object error; return NativeMethods.rs2_get_frame_texture_coordinates(Handle, out error); } } /// /// Copy texture coordinates to managed array /// /// array element type /// Array to copy into /// Thrown when is null public void CopyTextureCoords(T[] textureArray) { if (textureArray == null) { throw new ArgumentNullException(nameof(textureArray)); } Debug.Assert(textureArray.Length * Marshal.SizeOf(typeof(T)) == Count * 2 * sizeof(float)); var handle = GCHandle.Alloc(textureArray, GCHandleType.Pinned); try { Copy(TextureData, handle.AddrOfPinnedObject(), Count * 2 * sizeof(float)); } finally { handle.Free(); } } public void ExportToPLY(string fname, Frame texture) { object error; NativeMethods.rs2_export_to_ply(Handle, fname, texture.Handle, out error); } } }