/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using System; using System.Collections.Generic; using System.Runtime.InteropServices; /// 6-dof Trackable's Native API . public partial class NativeTrackable { /// The native interface. private NativeInterface m_NativeInterface; /// Constructor. /// The native interface. public NativeTrackable(NativeInterface nativeInterface) { m_NativeInterface = nativeInterface; } public bool UpdateTrackables(TrackableType trackable_type, List trackables) { if (m_NativeInterface == null || m_NativeInterface.TrackingHandle == 0) { return false; } trackables.Clear(); UInt64 trackable_list_handle = 0; var create_result = NativeApi.NRTrackableListCreate(m_NativeInterface.TrackingHandle, ref trackable_list_handle); var update_result = NativeApi.NRTrackingUpdateTrackables(m_NativeInterface.TrackingHandle, trackable_type, trackable_list_handle); int list_size = 0; var getsize_result = NativeApi.NRTrackableListGetSize(m_NativeInterface.TrackingHandle, trackable_list_handle, ref list_size); for (int i = 0; i < list_size; i++) { UInt64 trackable_handle = 0; var acquireitem_result = NativeApi.NRTrackableListAcquireItem(m_NativeInterface.TrackingHandle, trackable_list_handle, i, ref trackable_handle); if (acquireitem_result == NativeResult.Success) trackables.Add(trackable_handle); } var destroy_result = NativeApi.NRTrackableListDestroy(m_NativeInterface.TrackingHandle, trackable_list_handle); return (create_result == NativeResult.Success) && (update_result == NativeResult.Success) && (getsize_result == NativeResult.Success) && (destroy_result == NativeResult.Success); } /// Gets an identify. /// Handle of the trackable. /// The identify. public UInt32 GetIdentify(UInt64 trackable_handle) { if (m_NativeInterface.TrackingHandle == 0) { return 0; } UInt32 identify = NativeConstants.IllegalInt; NativeApi.NRTrackableGetIdentifier(m_NativeInterface.TrackingHandle, trackable_handle, ref identify); return identify; } /// Gets trackable type. /// Handle of the trackable. /// The trackable type. public TrackableType GetTrackableType(UInt64 trackable_handle) { if (m_NativeInterface.TrackingHandle == 0) { return TrackableType.TRACKABLE_BASE; } TrackableType trackble_type = TrackableType.TRACKABLE_BASE; NativeApi.NRTrackableGetType(m_NativeInterface.TrackingHandle, trackable_handle, ref trackble_type); return trackble_type; } /// Gets tracking state. /// Handle of the trackable. /// The tracking state. public TrackingState GetTrackingState(UInt64 trackable_handle) { if (m_NativeInterface.TrackingHandle == 0) { return TrackingState.Stopped; } TrackingState status = TrackingState.Stopped; NativeApi.NRTrackableGetTrackingState(m_NativeInterface.TrackingHandle, trackable_handle, ref status); return status; } private partial struct NativeApi { /// Nr trackable list create. /// Handle of the session. /// [in,out] Handle of the out trackable list. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableListCreate(UInt64 session_handle, ref UInt64 out_trackable_list_handle); /// Nr trackable list destroy. /// Handle of the session. /// Handle of the out trackable list. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableListDestroy(UInt64 session_handle, UInt64 trackable_list_handle); /// Nr tracking update trackables. /// Handle of the tracking. /// Type of the trackable. /// Handle of the out trackable list. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackingUpdateTrackables(UInt64 tracking_handle, TrackableType trackable_type, UInt64 trackable_list_handle); /// Nr trackable list get size. /// Handle of the session. /// Handle of the trackable list. /// [in,out] Size of the out list. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableListGetSize(UInt64 session_handle, UInt64 trackable_list_handle, ref int out_list_size); /// Nr trackable list acquire item. /// Handle of the session. /// Handle of the trackable list. /// Zero-based index of the. /// [in,out] The out trackable. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableListAcquireItem(UInt64 session_handle, UInt64 trackable_list_handle, int index, ref UInt64 out_trackable_item_handle); /// Nr trackable get identifier. /// Handle of the session. /// Handle of the trackable. /// [in,out] Identifier for the out. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableGetIdentifier(UInt64 session_handle, UInt64 trackable_handle, ref UInt32 out_identifier); /// Nr trackable get type. /// Handle of the session. /// Handle of the trackable. /// [in,out] Type of the out trackable. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableGetType(UInt64 session_handle, UInt64 trackable_handle, ref TrackableType out_trackable_type); /// Nr trackable get tracking state. /// Handle of the session. /// Handle of the trackable. /// [in,out] State of the out tracking. /// A NativeResult. [DllImport(NativeConstants.NRNativeLibrary)] public static extern NativeResult NRTrackableGetTrackingState(UInt64 session_handle, UInt64 trackable_handle, ref TrackingState out_tracking_state); }; } }