udAttributes.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace udSDK
  5. {
  6. public enum udStdAttribute
  7. {
  8. udSA_GPSTime, //!< udATI_float64
  9. udSA_PrimitiveID, //!< udATI_uint32
  10. udSA_ARGB, //!< udATI_color32
  11. udSA_Normal, //!< udATI_normal32
  12. udSA_Red, //!< Legacy 16bit Red channel
  13. udSA_Green, //!< Legacy 16bit Green channel
  14. udSA_Blue, //!< Legacy 16bit Blue channel
  15. udSA_Intensity, //!< udATI_uint16
  16. udSA_NIR, //!< udATI_uint16
  17. udSA_ScanAngle, //!< udATI_uint16
  18. udSA_PointSourceID, //!< udATI_uint16
  19. udSA_Classification, //!< udATI_uint8
  20. udSA_ReturnNumber, //!< udATI_uint8
  21. udSA_NumberOfReturns, //!< udATI_uint8
  22. udSA_ClassificationFlags, //!< udATI_uint8
  23. udSA_ScannerChannel, //!< udATI_uint8
  24. udSA_ScanDirection, //!< udATI_uint8
  25. udSA_EdgeOfFlightLine, //!< udATI_uint8
  26. udSA_ScanAngleRank, //!< udATI_uint8
  27. udSA_LasUserData, //!< Specific LAS User data field (udATI_uint8)
  28. udSA_Count, //!< Count helper value to iterate this enum
  29. udSA_AllAttributes = udSA_Count, //!< Internal sentinal value used by some functions to indicate getting start of interleaved attributes
  30. udSA_First = 0, //!< Generally used to initialise an attribute value for use in loops
  31. };
  32. public enum udStdAttributeContent
  33. {
  34. udSAC_None = (0),
  35. udSAC_GPSTime = (1 << udStdAttribute.udSA_GPSTime),
  36. udSAC_PrimitiveID = (1 << udStdAttribute.udSA_PrimitiveID),
  37. udSAC_ARGB = (1 << udStdAttribute.udSA_ARGB),
  38. udSAC_Normal = (1 << udStdAttribute.udSA_Normal),
  39. udSAC_Red = (1 << udStdAttribute.udSA_Red),
  40. udSAC_Green = (1 << udStdAttribute.udSA_Green),
  41. udSAC_Blue = (1 << udStdAttribute.udSA_Blue),
  42. udSAC_Intensity = (1 << udStdAttribute.udSA_Intensity),
  43. udSAC_NIR = (1 << udStdAttribute.udSA_NIR),
  44. udSAC_ScanAngle = (1 << udStdAttribute.udSA_ScanAngle),
  45. udSAC_PointSourceID = (1 << udStdAttribute.udSA_PointSourceID),
  46. udSAC_Classification = (1 << udStdAttribute.udSA_Classification),
  47. udSAC_ReturnNumber = (1 << udStdAttribute.udSA_ReturnNumber),
  48. udSAC_NumberOfReturns = (1 << udStdAttribute.udSA_NumberOfReturns),
  49. udSAC_ClassificationFlags = (1 << udStdAttribute.udSA_ClassificationFlags),
  50. udSAC_ScannerChannel = (1 << udStdAttribute.udSA_ScannerChannel),
  51. udSAC_ScanDirection = (1 << udStdAttribute.udSA_ScanDirection),
  52. udSAC_EdgeOfFlightLine = (1 << udStdAttribute.udSA_EdgeOfFlightLine),
  53. udSAC_ScanAngleRank = (1 << udStdAttribute.udSA_ScanAngleRank),
  54. udSAC_LasUserData = (1 << udStdAttribute.udSA_LasUserData),
  55. udSAC_AllAttributes = (1 << udStdAttribute.udSA_AllAttributes) - 1,
  56. // these are not used, and result in errors otherwise
  57. // leaving here for the sake of parity
  58. // udSAC_64BitAttributes = udSAC_GPSTime,
  59. // udSAC_32BitAttributes = udSAC_PrimitiveID + udSAC_ARGB + udSAC_Normal,
  60. // udSAC_16BitAttributes = udSAC_Intensity + udSAC_NIR + udSAC_ScanAngle + udSAC_PointSourceID,
  61. };
  62. public enum udAttributeBlendType
  63. {
  64. udABT_Mean, //!< This blend type merges nearby voxels together and finds the mean value for the attribute on those nodes
  65. udABT_FirstChild, //!< This blend type selects the value from one of the nodes and uses that
  66. udABT_NoLOD, //!< This blend type has no information in LODs and is only stored in the highest detail level
  67. udABT_Count //!< Total number of blend types. Used internally but can be used as an iterator max when checking attribute blend modes.
  68. };
  69. public enum udAttributeTypeInfo
  70. {
  71. udATI_Invalid = 0,
  72. udATI_SizeMask = 0x000ff, // Lower 8 bits define the size in bytes - currently the actual maximum is 32
  73. udATI_SizeShift = 0,
  74. udATI_ComponentCountMask = 0x0ff00, // Next 8 bits define the number of components, component size is size/componentCount
  75. udATI_ComponentCountShift = 8,
  76. udATI_Signed = 0x10000, // Set if type is signed (used in blend functions)
  77. udATI_Float = 0x20000, // Set if floating point type (signed should always be set)
  78. udATI_Color = 0x40000, // Set if type is de-quantized from a color
  79. udATI_Normal = 0x80000, // Set if type is encoded normal (32 bit = 16:15:1)
  80. // Some keys to define standard types
  81. udATI_uint8 = 1,
  82. udATI_uint16 = 2,
  83. udATI_uint32 = 4,
  84. udATI_uint64 = 8,
  85. udATI_int8 = 1 | udATI_Signed,
  86. udATI_int16 = 2 | udATI_Signed,
  87. udATI_int32 = 4 | udATI_Signed,
  88. udATI_int64 = 8 | udATI_Signed,
  89. udATI_float32 = 4 | udATI_Signed | udATI_Float,
  90. udATI_float64 = 8 | udATI_Signed | udATI_Float,
  91. udATI_color32 = 4 | udATI_Color,
  92. udATI_normal32 = 4 | udATI_Normal,
  93. udATI_vec3f32 = 12 | 0x300 | udATI_Signed | udATI_Float
  94. };
  95. [StructLayout(LayoutKind.Sequential)]
  96. public struct udAttributeDescriptor
  97. {
  98. public udAttributeTypeInfo typeInfo; //!< This contains information about the type
  99. public udAttributeBlendType blendType; //!< Which blend type this attribute is using
  100. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
  101. public char[] name; //!< Name of the attibute
  102. };
  103. [StructLayout(LayoutKind.Sequential)]
  104. public struct udAttributeSet
  105. {
  106. public udStdAttributeContent standardContent; //!< Which standard attributes are available (used to optimize lookups internally), they still appear in the descriptors
  107. public uint count; //!< How many udAttributeDescriptor objects are used in pDescriptors
  108. public uint allocated; //!< How many udAttributeDescriptor objects are allocated to be used in pDescriptors
  109. public IntPtr pDescriptors; //!< this contains the actual information on the attributes
  110. };
  111. public class AttributeSet {
  112. private udAttributeSet set;
  113. int GetStandardOffset(udStdAttribute attribute)
  114. {
  115. IntPtr pOffset = new IntPtr();
  116. udAttributeSet_GetOffsetOfStandardAttribute(ref set, attribute, pOffset);
  117. unsafe {
  118. return *((int*)pOffset.ToPointer());
  119. }
  120. }
  121. int GetNamedOffset(string name)
  122. {
  123. IntPtr pOffset = new IntPtr();
  124. udAttributeSet_GetOffsetOfNamedAttribute(ref set, name, pOffset);
  125. unsafe
  126. {
  127. return *((int*)pOffset.ToPointer());
  128. }
  129. }
  130. [DllImport(UDSDKLibrary.name)]
  131. private static extern udError udAttributeSet_GetOffsetOfStandardAttribute(ref udAttributeSet pAttributeSet, udStdAttribute attribute, IntPtr pOffset);
  132. [DllImport(UDSDKLibrary.name)]
  133. private static extern udError udAttributeSet_GetOffsetOfNamedAttribute(ref udAttributeSet pAttributeSet, string pName, IntPtr pOffset);
  134. }
  135. }