TagProfileLoading.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. using Unity.Collections;
  7. using UnityEditor;
  8. using UnityEngine;
  9. namespace Ximmerse.XR.Tag
  10. {
  11. /// <summary>
  12. /// It is used to load the calibration file and pass in the Tag coordinates.
  13. /// </summary>
  14. public class TagProfileLoading : TagLoadingManager
  15. {
  16. /// <summary>
  17. /// Enable the loading of calibration parameters with a Tag type of Beacon and ID 65-67.
  18. /// </summary>
  19. [Header("Beacon")]
  20. [Tooltip("ID 65-67")]
  21. [SerializeField] private bool Beacon = true;
  22. /// <summary>
  23. /// Enable loading of the Tag type as LiBeacon.
  24. /// </summary>
  25. [Header("LiBeacon")]
  26. [Tooltip("ID 36, 35, 28, 32")]
  27. [SerializeField] private bool LiBeacon = false;
  28. /// <summary>
  29. /// Enable the calibration parameter with Topo Tag type and ID 100-170.
  30. /// </summary>
  31. [Header("TopoTag")]
  32. [Tooltip("ID 100-227")]
  33. [SerializeField] private bool TopoTag = true;
  34. /// <summary>
  35. /// Enable the loading of calibration parameters with Tag type SingleCard and ID 18, 19, 22, 23, 25, 39.
  36. /// </summary>
  37. [Header("Card")]
  38. [Tooltip("ID 18, 23, 25, 39, 19, 22")]
  39. [SerializeField] private bool SingleCard = false;
  40. /// <summary>
  41. /// Enable loading of Tag type to Gun.
  42. /// </summary>
  43. [Header("Gun")]
  44. [Tooltip("92ID£º2, 6, 11, 12, 13, 16, 20, 21, 24, 29, 38, 41, 43, 44, 50 ." +
  45. " 95ID:15, 31, 27, 28, 30, 26, 35, 42, 58, 61, 32, 53, 55, 62, 64, 36 .")]
  46. [SerializeField] private bool Gun = false;
  47. /// <summary>
  48. /// The id range of tags used.
  49. /// </summary>
  50. //[Header("ID-Range")]
  51. //[SerializeField] private int minId = 65;
  52. //[SerializeField] private int maxId = 227;
  53. #region Property
  54. /// <summary>
  55. /// Select the type of LiBeacon.
  56. /// </summary>
  57. [SerializeField] [EnumFlags] private LiBeaconType liBeaconType;
  58. /// <summary>
  59. /// Choose the size of the Topo Tag, 50cm or 38cm.
  60. /// </summary>
  61. [SerializeField] private TopoTagSize topoTagSize;
  62. /// <summary>
  63. /// Select the type of Gun, 92 or 95.
  64. /// </summary>
  65. [SerializeField] [EnumFlags] private GunType guntype;
  66. /// <summary>
  67. /// Choose the size of the Single Card, 40mm or 62mm.
  68. /// </summary>
  69. [SerializeField] private SingleCardSize singleSize;
  70. /// <summary>
  71. /// The path to the calibration file in the RhinoX Pro.
  72. /// </summary>
  73. private string CalibraFilePath = "/sdcard/vpusdk/marker_calib";
  74. public class EnumFlags : PropertyAttribute
  75. {
  76. }
  77. /// <summary>
  78. /// The size of the Topo Tag.
  79. /// </summary>
  80. public enum TopoTagSize
  81. {
  82. TopoTag_450mm,
  83. TopoTag_350mm
  84. }
  85. /// <summary>
  86. /// The type of gun.
  87. /// </summary>
  88. [System.Flags]
  89. public enum GunType
  90. {
  91. gunsight92 = 1,
  92. gunsight95 = 2,
  93. }
  94. /// <summary>
  95. /// The type and ID of LiBeacon
  96. /// </summary>
  97. [System.Flags]
  98. public enum LiBeaconType
  99. {
  100. LiBeacon_1ID36 = 1,
  101. LiBeacon_2ID35 = 2,
  102. LiBeacon_3ID28 = 4,
  103. LiBeacon_4ID32 = 8,
  104. }
  105. public enum SingleCardSize
  106. {
  107. Single_40mm,
  108. Single_62mm,
  109. }
  110. private static TagProfileLoading instance;
  111. public static TagProfileLoading Instance
  112. {
  113. get
  114. {
  115. return instance;
  116. }
  117. }
  118. #endregion
  119. #region Unity
  120. private void Awake()
  121. {
  122. if (instance==null)
  123. {
  124. instance = this;
  125. }
  126. ThreadTagLoading();
  127. }
  128. private void Start()
  129. {
  130. StartCoroutine(StartFusion());
  131. }
  132. private void OnDestroy()
  133. {
  134. #if !UNITY_EDITOR
  135. XDevicePlugin.ResetTrackingMarkerSettings();
  136. #endif
  137. StopAllCoroutines();
  138. instance = null;
  139. }
  140. #endregion
  141. #region Method
  142. /// <summary>
  143. /// Refresh and re-acquire the coordinate information of the large spatial positioning board.
  144. /// </summary>
  145. public void RefreshBeaconTran()
  146. {
  147. RefreshBeacon();
  148. }
  149. /// <summary>
  150. /// Clearing the algorithm data invalidates the large spatial positioning function.
  151. /// </summary>
  152. public void CleanBeaconData()
  153. {
  154. CleanBeacon();
  155. }
  156. /// <summary>
  157. /// Set targeting parameters
  158. /// </summary>
  159. public void SettingData()
  160. {
  161. SettingTagData();
  162. }
  163. /// <summary>
  164. /// Load calibration parameters
  165. /// </summary>
  166. private void SetCalibraFile()
  167. {
  168. #if !UNITY_EDITOR
  169. XDevicePlugin.ResetTrackingMarkerSettings();
  170. if (Beacon)
  171. {
  172. int[] ids = new int[3];
  173. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/BEACON-500.json", out ids, 3);
  174. }
  175. if (LiBeacon)
  176. {
  177. if ((liBeaconType & LiBeaconType.LiBeacon_1ID36) != 0)
  178. {
  179. int[] ids = new int[1];
  180. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/LiBeacon-500-1.json", out ids, 1);
  181. }
  182. if ((liBeaconType & LiBeaconType.LiBeacon_2ID35) != 0)
  183. {
  184. int[] ids = new int[1];
  185. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/LiBeacon-500-2.json", out ids, 1);
  186. }
  187. if ((liBeaconType & LiBeaconType.LiBeacon_3ID28) != 0)
  188. {
  189. int[] ids = new int[1];
  190. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/LiBeacon-500-3.json", out ids, 1);
  191. }
  192. if ((liBeaconType & LiBeaconType.LiBeacon_4ID32) != 0)
  193. {
  194. int[] ids = new int[1];
  195. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/LiBeacon-500-4.json", out ids, 1);
  196. }
  197. }
  198. if (TopoTag)
  199. {
  200. if (topoTagSize == TopoTagSize.TopoTag_450mm)
  201. {
  202. int[] ids = new int[128];
  203. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/Topotag_model_100_to_227.json", out ids, 128);
  204. }
  205. if (topoTagSize == TopoTagSize.TopoTag_350mm)
  206. {
  207. int[] ids = new int[128];
  208. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/BEACON/Topotag_model_100_to_227_350mm.json", out ids, 128);
  209. }
  210. }
  211. if (SingleCard)
  212. {
  213. if (singleSize == SingleCardSize.Single_40mm)
  214. {
  215. int[] ids = new int[6];
  216. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/CARD/single_markers_500_03_40mm.json", out ids, 6);
  217. }
  218. if (singleSize == SingleCardSize.Single_62mm)
  219. {
  220. int[] ids = new int[6];
  221. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/CARD/single_markers_500_03_62mm.json", out ids, 6);
  222. }
  223. }
  224. if (Gun)
  225. {
  226. if ((guntype & GunType.gunsight92) != 0)
  227. {
  228. int[] ids = new int[16];
  229. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/GUN/92_gunsight_500_03/92_gunsight_500_03.json", out ids, 16);
  230. }
  231. if ((guntype & GunType.gunsight95) != 0)
  232. {
  233. int[] ids = new int[16];
  234. XDevicePlugin.LoadTrackingMarkerSettingsFile(CalibraFilePath + "/GUN/95_gunsight_500_03/95_gunsight_500_03.json", out ids, 16);
  235. }
  236. }
  237. //if (m_rightCalibraFilePath.Length != 0)
  238. //{
  239. // int[] ids = new int[100];
  240. // XDevicePlugin.LoadTrackingMarkerSettingsFile(m_rightCalibraFilePath, out ids, 100);
  241. //}
  242. //if (m_leftCalibraFilePath.Length != 0)
  243. //{
  244. // int[] ids = new int[100];
  245. // XDevicePlugin.LoadTrackingMarkerSettingsFile(m_leftCalibraFilePath, out ids, 100);
  246. //}
  247. #endif
  248. }
  249. public void ThreadTagLoading()
  250. {
  251. Thread thread;
  252. thread = new Thread(SetCalibraFile);
  253. threadLoad = thread;
  254. threadLoad.Start();
  255. }
  256. #endregion
  257. }
  258. }