diff --git a/src/ARKit/ARPointCloud.cs b/src/ARKit/ARPointCloud.cs index b2e57ab020..ab0fdb9878 100644 --- a/src/ARKit/ARPointCloud.cs +++ b/src/ARKit/ARPointCloud.cs @@ -20,7 +20,18 @@ namespace XamCore.ARKit { get { var count = (int)Count; var rv = new Vector3 [count]; - var ptr = (Vector3*)_GetPoints (); + var ptr = (Vector3*)GetRawPoints (); + for (int i = 0; i < count; i++) + rv [i] = *ptr++; + return rv; + } + } + + public unsafe ulong [] Identifiers { + get { + var count = (int)Count; + var rv = new ulong [count]; + var ptr = (ulong*)GetRawIdentifiers (); for (int i = 0; i < count; i++) rv [i] = *ptr++; return rv; diff --git a/src/arkit.cs b/src/arkit.cs index 5a73159dab..af961b8897 100644 --- a/src/arkit.cs +++ b/src/arkit.cs @@ -10,6 +10,7 @@ #if XAMCORE_2_0 using System; +using System.ComponentModel; using XamCore.CoreFoundation; using XamCore.CoreGraphics; using XamCore.CoreMedia; @@ -279,8 +280,13 @@ namespace XamCore.ARKit { [Export ("count")] nuint Count { get; } - [Internal, Export ("points")] - IntPtr _GetPoints (); + [EditorBrowsable (EditorBrowsableState.Advanced)] + [Protected, Export ("points")] + IntPtr GetRawPoints (); + + [EditorBrowsable (EditorBrowsableState.Advanced)] + [Protected, Export ("identifiers")] + IntPtr GetRawIdentifiers (); } [iOS (11,0)] diff --git a/tests/monotouch-test/ARKit/ARPointCloudTest.cs b/tests/monotouch-test/ARKit/ARPointCloudTest.cs new file mode 100644 index 0000000000..b36154554f --- /dev/null +++ b/tests/monotouch-test/ARKit/ARPointCloudTest.cs @@ -0,0 +1,101 @@ +// +// Unit tests for ARPointCloud +// +// Authors: +// Vincent Dondain +// +// Copyright 2017 Microsoft. All rights reserved. +// + +#if XAMCORE_2_0 && __IOS__ + +using System; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using ARKit; +using AVFoundation; +using Foundation; +using NUnit.Framework; +using ObjCRuntime; +using OpenTK; + +namespace MonoTouchFixtures.ARKit { + + class ARPointCloudPoker : ARPointCloud { + + GCHandle vectorArrayHandle; + GCHandle identifiersHandle; + Vector3 [] vectorArray; + ulong [] identifiers; + + public ARPointCloudPoker () : base (IntPtr.Zero) + { + } + + public override nuint Count { + get { + return 2; + } + } + + protected unsafe override IntPtr GetRawPoints () + { + vectorArray = new Vector3 [] { new Vector3 (1, 2, 3), new Vector3 (4, 5, 6) }; + if (!vectorArrayHandle.IsAllocated) + vectorArrayHandle = GCHandle.Alloc (vectorArray, GCHandleType.Pinned); + Vector3* addr = (Vector3*)vectorArrayHandle.AddrOfPinnedObject (); + return (IntPtr)addr; + } + + protected unsafe override IntPtr GetRawIdentifiers () + { + identifiers = new ulong [] { 0, 1 }; + if (!identifiersHandle.IsAllocated) + identifiersHandle = GCHandle.Alloc (identifiers, GCHandleType.Pinned); + ulong* addr = (ulong*)identifiersHandle.AddrOfPinnedObject (); + return (IntPtr)addr; + } + + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + if (vectorArrayHandle.IsAllocated) + vectorArrayHandle.Free (); + if (identifiersHandle.IsAllocated) + identifiersHandle.Free (); + } + } + + [TestFixture] + [Preserve (AllMembers = true)] + public class ARPointCloudTest { + + [SetUp] + public void Setup () + { + TestRuntime.AssertXcodeVersion (9, 0); + } + + [Test] + public void PointsTest () + { + var cloud = new ARPointCloudPoker (); + + var points = cloud.Points; + Assert.AreEqual (new Vector3 (1, 2, 3), cloud.Points [0]); + Assert.AreEqual (new Vector3 (4, 5, 6), cloud.Points [1]); + } + + [Test] + public void IdentifiersTest () + { + var cloud = new ARPointCloudPoker (); + + var points = cloud.Identifiers; + Assert.AreEqual (0, cloud.Identifiers [0]); + Assert.AreEqual (1, cloud.Identifiers [1]); + } + } +} + +#endif // XAMCORE_2_0 && __IOS__ diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index f152a0c822..c49a3944f8 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -659,6 +659,7 @@ + @@ -725,6 +726,7 @@ +