SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
6.8 KiB

4 years ago
  1. using System;
  2. using Unity.Collections;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// An abstract class that provides a generic API for low-level depth detection features.
  7. /// </summary>
  8. /// <remarks>
  9. /// This class can be used to access depth detection features in your app via accessing the generic API.
  10. /// It can also be extended to provide an implementation of a provider which provides the depth detection data
  11. /// to the higher level code.
  12. /// </remarks>
  13. public abstract class XRDepthSubsystem : TrackingSubsystem<XRPointCloud, XRDepthSubsystemDescriptor>
  14. {
  15. /// <summary>
  16. /// Constructs a depth subsystem. Do not invoked directly; call <c>Create</c> on the <see cref="XRDepthSubsystemDescriptor"/> instead.
  17. /// </summary>
  18. protected XRDepthSubsystem() => m_Provider = CreateProvider();
  19. /// <summary>
  20. /// Start the depth subsystem, i.e., start collecting depth data.
  21. /// </summary>
  22. protected sealed override void OnStart() => m_Provider.Start();
  23. /// <summary>
  24. /// Destroy the depth subsystem.
  25. /// </summary>
  26. protected sealed override void OnDestroyed() => m_Provider.Destroy();
  27. /// <summary>
  28. /// Stop the subsystem, i.e., stop collecting depth data.
  29. /// </summary>
  30. protected sealed override void OnStop() => m_Provider.Stop();
  31. /// <summary>
  32. /// Get the changes (added, updated, and removed) point clouds since the last call to <see cref="GetChanges(Allocator)"/>.
  33. /// </summary>
  34. /// <param name="allocator">An <c>Allocator</c> to use when allocating the returned <c>NativeArray</c>s.</param>
  35. /// <returns>
  36. /// <see cref="TrackableChanges{T}"/> describing the point clouds that have been added, updated, and removed
  37. /// since the last call to <see cref="GetChanges(Allocator)"/>. The caller owns the memory allocated with <c>Allocator</c>.
  38. /// </returns>
  39. public override TrackableChanges<XRPointCloud> GetChanges(Allocator allocator)
  40. {
  41. var changes = m_Provider.GetChanges(XRPointCloud.defaultValue, allocator);
  42. #if DEVELOPMENT_BUILD || UNITY_EDITOR
  43. m_ValidationUtility.ValidateAndDisposeIfThrown(changes);
  44. #endif
  45. return changes;
  46. }
  47. /// <summary>
  48. /// Retrieve point cloud data (positions, confidence values, & identifiers)
  49. /// for the point cloud with the given <paramref name="trackableId"/>.
  50. /// </summary>
  51. /// <param name="trackableId">The point cloud for which to retrieve data.</param>
  52. /// <param name="allocator">The allocator to use when creating the <c>NativeArray</c>s in the returned <see cref="XRPointCloudData"/>. <c>Allocator.Temp</c> is not supported; use <c>Allocator.TempJob</c> if you need temporary memory.</param>
  53. /// <returns>
  54. /// A new <see cref="XRPointCloudData"/> with newly allocated <c>NativeArray</c>s using <paramref name="allocator"/>.
  55. /// The caller owns the memory and is responsible for calling <see cref="XRPointCloudData.Dispose"/> on it.
  56. /// </returns>
  57. public XRPointCloudData GetPointCloudData(
  58. TrackableId trackableId,
  59. Allocator allocator)
  60. {
  61. if (allocator == Allocator.Temp)
  62. throw new InvalidOperationException("Allocator.Temp is not supported. Use Allocator.TempJob if you wish to use a temporary allocator.");
  63. if (allocator == Allocator.None)
  64. throw new InvalidOperationException("Allocator.None is not a valid allocator.");
  65. return m_Provider.GetPointCloudData(trackableId, allocator);
  66. }
  67. /// <summary>
  68. /// Implement this and return an instance of the <see cref="Provider"/>.
  69. /// </summary>
  70. /// <returns>An implementation of the <see cref="Provider"/>.</returns>
  71. protected abstract Provider CreateProvider();
  72. /// <summary>
  73. /// The interface that each derived class must implement.
  74. /// </summary>
  75. protected abstract class Provider
  76. {
  77. /// <summary>
  78. /// Called when the subsystem is started. Will not be called again until <see cref="Stop"/>.
  79. /// </summary>
  80. public virtual void Start() { }
  81. /// <summary>
  82. /// Called when the subsystem is stopped. Will not be called before <see cref="Start"/>.
  83. /// </summary>
  84. public virtual void Stop() { }
  85. /// <summary>
  86. /// Called when the subsystem is destroyed. <see cref="Stop"/> will be called first if the subsystem is running.
  87. /// </summary>
  88. public virtual void Destroy() { }
  89. /// <summary>
  90. /// Get the changes (added, updated, and removed) planes since the last call to <see cref="GetChanges(Allocator)"/>.
  91. /// </summary>
  92. /// <param name="defaultPointCloud">
  93. /// The default point cloud. This should be used to initialize the returned <c>NativeArray</c>s for backwards compatibility.
  94. /// See <see cref="TrackableChanges{T}.TrackableChanges(void*, int, void*, int, void*, int, T, int, Allocator)"/>.
  95. /// </param>
  96. /// <param name="allocator">An <c>Allocator</c> to use when allocating the returned <c>NativeArray</c>s.</param>
  97. /// <returns>
  98. /// <see cref="TrackableChanges{T}"/> describing the reference points that have been added, updated, and removed
  99. /// since the last call to <see cref="GetChanges(Allocator)"/>. The changes should be allocated using
  100. /// <paramref name="allocator"/>.
  101. /// </returns>
  102. public abstract TrackableChanges<XRPointCloud> GetChanges(XRPointCloud defaultPointCloud, Allocator allocator);
  103. /// <summary>
  104. /// Generate point cloud data (positions, confidence values, & identifiers)
  105. /// for the point cloud with the given <paramref name="trackableId"/>.
  106. /// </summary>
  107. /// <param name="trackableId">The point cloud for which to retrieve data.</param>
  108. /// <param name="allocator">The allocator to use when creating the <c>NativeArray</c>s in the returned <see cref="XRPointCloudData"/>.</param>
  109. /// <returns>
  110. /// A new <see cref="XRPointCloudData"/> with newly allocated <c>NativeArray</c>s using <paramref name="allocator"/>.
  111. /// The caller owns the memory and is responsible for calling <see cref="XRPointCloudData.Dispose"/> on it.
  112. /// </returns>
  113. public abstract XRPointCloudData GetPointCloudData(TrackableId trackableId, Allocator allocator);
  114. }
  115. Provider m_Provider;
  116. #if DEVELOPMENT_BUILD || UNITY_EDITOR
  117. ValidationUtility<XRPointCloud> m_ValidationUtility =
  118. new ValidationUtility<XRPointCloud>();
  119. #endif
  120. }
  121. }