NRSubsystemManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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
  10. {
  11. using System.Collections.Generic;
  12. /// <summary>
  13. /// Gives access to subsystems.
  14. /// Provides the ability to query for SubsystemDescriptors which enumerate features.
  15. /// Given an SubsystemDescriptor, you can create an Subsystem to utilize the subsystem.
  16. /// </summary>
  17. public static class NRSubsystemManager
  18. {
  19. private static List<ISubsystemDescriptor> supportedDescriptors = new List<ISubsystemDescriptor>()
  20. {
  21. new NRTrackingSubsystemDescriptor(),
  22. new NRTrackableSubsystemDescriptor(),
  23. new NRTrackableImageSubsystemDescriptor(),
  24. new NRPlaneSubsystemDescriptor(),
  25. new NRDeviceSubsystemDescriptor(),
  26. new NRDisplaySubsystemDescriptor(),
  27. };
  28. /// <summary>
  29. /// Gets all of the currently known subsystem descriptors regardless of specific subsystem type.
  30. /// </summary>
  31. /// <param name="descriptors">subsystem descriptor type.</param>
  32. public static void GetAllSubsystemDescriptors(List<ISubsystemDescriptor> descriptors)
  33. {
  34. if (descriptors == null)
  35. {
  36. descriptors = new List<ISubsystemDescriptor>();
  37. }
  38. descriptors.Clear();
  39. descriptors.AddRange(supportedDescriptors);
  40. }
  41. /// <summary>
  42. /// Get Active Subsystems of a specific instance type.
  43. /// </summary>
  44. /// <typeparam name="TSubSystem">subsystem type. </typeparam>
  45. /// <param name="subsystems"></param>
  46. public static void GetSubsystems<TSubSystem>(List<TSubSystem> subsystems) where TSubSystem : ISubsystem
  47. {
  48. if (subsystems == null)
  49. {
  50. subsystems = new List<TSubSystem>();
  51. }
  52. subsystems.Clear();
  53. foreach (var des in supportedDescriptors)
  54. {
  55. var subsystem = ((IntegratedSubsystemDescriptor)des).subsystem;
  56. if (subsystem != null && subsystem.GetType().Equals(typeof(TSubSystem)))
  57. {
  58. subsystems.Add((TSubSystem)subsystem);
  59. }
  60. }
  61. }
  62. /// <summary>
  63. /// Gets A list of ISubsystemDescriptor which describe additional functionality that can be enabled.
  64. /// </summary>
  65. /// <typeparam name="TDescriptor">descriptor type.</typeparam>
  66. /// <param name="descriptors"></param>
  67. public static void GetSubsystemDescriptors<TDescriptor>(List<TDescriptor> descriptors) where TDescriptor : ISubsystemDescriptor
  68. {
  69. if (descriptors == null)
  70. {
  71. descriptors = new List<TDescriptor>();
  72. }
  73. descriptors.Clear();
  74. foreach (var descriptor in supportedDescriptors)
  75. {
  76. if (typeof(TDescriptor).Equals(descriptor.GetType()))
  77. {
  78. descriptors.Add((TDescriptor)descriptor);
  79. }
  80. }
  81. }
  82. }
  83. }