NativePointCloud.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental
  10. {
  11. using System;
  12. using System.Runtime.InteropServices;
  13. /**
  14. * @brief Native PointCloud API.
  15. */
  16. internal partial class NativePointCloud
  17. {
  18. private static UInt64 m_DatabaseHandle;
  19. public bool Create()
  20. {
  21. var result = NativeApi.NRPointCloudCreat(ref m_DatabaseHandle);
  22. NRDebugger.Debug("[NativePointCloud] End to create worldmap :" + result);
  23. NativeErrorListener.Check(result, this, "Create");
  24. return result == NativeResult.Success;
  25. }
  26. public bool IsUpdatedThisFrame()
  27. {
  28. bool result = NativeApi.NRPointCloudIsUpdated(m_DatabaseHandle);
  29. NRDebugger.Debug("[NativePointCloud] IsUpdatedThisFrame :" + result);
  30. return result;
  31. }
  32. public UInt64 CreatPointCloudList()
  33. {
  34. UInt64 pointlistHandle = 0;
  35. var result = NativeApi.NRPointCloudListCreat(m_DatabaseHandle, ref pointlistHandle);
  36. NativeErrorListener.Check(result, this, "CreatPointCloudList");
  37. NRDebugger.Debug("[NativePointCloud] create list :" + pointlistHandle);
  38. return pointlistHandle;
  39. }
  40. public void UpdatePointCloudList(UInt64 pointlistHandle)
  41. {
  42. NRDebugger.Debug("[NativePointCloud] UpdatePointCloudList");
  43. var result = NativeApi.NRPointCloudListUpdate(m_DatabaseHandle, pointlistHandle);
  44. NativeErrorListener.Check(result, this, "UpdatePointCloudList");
  45. }
  46. public void DestroyPointCloudList(UInt64 pointlistHandle)
  47. {
  48. var result = NativeApi.NRPointCloudListDestroy(m_DatabaseHandle, pointlistHandle);
  49. NRDebugger.Debug("[NativePointCloud] destroy list :" + pointlistHandle);
  50. NativeErrorListener.Check(result, this, "UpdatePointCloudList");
  51. }
  52. public int GetSize(UInt64 pointlistHandle)
  53. {
  54. int size = 0;
  55. var result = NativeApi.NRPointCloudListGetSize(m_DatabaseHandle, pointlistHandle, ref size);
  56. NRDebugger.Debug("[NativePointCloud] get size :" + size);
  57. NativeErrorListener.Check(result, this, "UpdatePointCloudList");
  58. return size;
  59. }
  60. public static int GetConfidence()
  61. {
  62. int confidence = -1;
  63. NativeApi.NRPointCloudConfidence(m_DatabaseHandle, ref confidence);
  64. return confidence;
  65. }
  66. public PointCloudPoint AquireItem(UInt64 pointlistHandle, int index)
  67. {
  68. PointCloudPoint point = new PointCloudPoint();
  69. NativeApi.NRPointCloudListAquireItem(m_DatabaseHandle, pointlistHandle, index, ref point);
  70. // Transform thr pos from oepngl to unity
  71. point.Position.Z = -point.Position.Z;
  72. return point;
  73. }
  74. public bool SaveMap(string path)
  75. {
  76. var result = NativeApi.NRPointCloudSave(m_DatabaseHandle, path);
  77. NRDebugger.Debug("[NativePointCloud] Save worldmap :" + result);
  78. NativeErrorListener.Check(result, this, "SaveMap");
  79. return result == NativeResult.Success;
  80. }
  81. public bool Destroy()
  82. {
  83. var result = NativeApi.NRPointCloudDestroy(m_DatabaseHandle);
  84. NRDebugger.Debug("[NativePointCloud] End to destroy worldmap :" + result);
  85. NativeErrorListener.Check(result, this, "Destroy");
  86. return result == NativeResult.Success;
  87. }
  88. private partial struct NativeApi
  89. {
  90. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  91. public static extern NativeResult NRPointCloudCreat(ref UInt64 world_map_database_handle);
  92. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  93. public static extern NativeResult NRPointCloudListCreat(UInt64 world_map_database_handle, ref UInt64 points_list_handle);
  94. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  95. public static extern NativeResult NRPointCloudListUpdate(UInt64 world_map_database_handle, UInt64 points_list_handle);
  96. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  97. public static extern NativeResult NRPointCloudListGetSize(UInt64 world_map_database_handle, UInt64 points_list_handle, ref int size);
  98. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  99. public static extern NativeResult NRPointCloudListDestroy(UInt64 world_map_database_handle, UInt64 points_list_handle);
  100. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  101. public static extern NativeResult NRPointCloudListAquireItem(UInt64 world_map_database_handle, UInt64 points_list_handle, int index, ref PointCloudPoint point);
  102. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  103. public static extern bool NRPointCloudIsUpdated(UInt64 world_map_database_handle);
  104. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  105. public static extern NativeResult NRPointCloudConfidence(UInt64 world_map_database_handle, ref int confidence);
  106. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  107. public static extern NativeResult NRPointCloudSave(UInt64 world_map_database_handle, string world_map_database_file_path);
  108. [DllImport(NativeConstants.NRNativeAnchorPointLib)]
  109. public static extern NativeResult NRPointCloudDestroy(UInt64 world_map_database_handle);
  110. }
  111. }
  112. }