智慧水务管理系统 - 精河县供水工程综合管理平台

BoundingVolumeSemantics.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import Check from "../Core/Check.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. /**
  5. * Utilities for parsing bounding volume semantics from 3D Tiles 1.1 metadata.
  6. *
  7. * @namespace BoundingVolumeSemantics
  8. * @private
  9. */
  10. const BoundingVolumeSemantics = {};
  11. /**
  12. * Parse the bounding volume-related semantics such as
  13. * <code>TILE_BOUNDING_BOX</code> and <code>CONTENT_BOUNDING_BOX</code> from
  14. * implicit tile or content metadata. Results are returned as a JSON object for
  15. * use when transcoding tiles (see {@link Implicit3DTileContent}).
  16. * <p>
  17. * Bounding volumes are checked in the order box, region, then sphere. Only
  18. * the first valid bounding volume is returned.
  19. * </p>
  20. * <p>
  21. * This handles both tile and content bounding volumes, as the only difference
  22. * is the prefix. e.g. <code>TILE_BOUNDING_BOX</code> and
  23. * <code>CONTENT_BOUNDING_BOX</code> have the same memory layout.
  24. * </p>
  25. *
  26. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata/Semantics|3D Metadata Semantic Reference} for the various bounding volumes and minimum/maximum heights.
  27. *
  28. * @param {string} prefix Either "TILE" or "CONTENT"
  29. * @param {TileMetadata|ContentMetadata} metadata The metadata object for looking up values by semantic. In practice, this will typically be a {@link ImplicitMetadataView}
  30. * @return {object} An object containing the bounding volume, and any minimum or maximum height.
  31. *
  32. * @private
  33. * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
  34. */
  35. BoundingVolumeSemantics.parseAllBoundingVolumeSemantics = function (
  36. prefix,
  37. metadata,
  38. ) {
  39. //>>includeStart('debug', pragmas.debug);
  40. Check.typeOf.string("prefix", prefix);
  41. if (prefix !== "TILE" && prefix !== "CONTENT") {
  42. throw new DeveloperError("prefix must be either 'TILE' or 'CONTENT'");
  43. }
  44. Check.typeOf.object("metadata", metadata);
  45. //>>includeEnd('debug');
  46. return {
  47. boundingVolume: BoundingVolumeSemantics.parseBoundingVolumeSemantic(
  48. prefix,
  49. metadata,
  50. ),
  51. minimumHeight: BoundingVolumeSemantics._parseMinimumHeight(
  52. prefix,
  53. metadata,
  54. ),
  55. maximumHeight: BoundingVolumeSemantics._parseMaximumHeight(
  56. prefix,
  57. metadata,
  58. ),
  59. };
  60. };
  61. /**
  62. * Parse the bounding volume from tile or content metadata. If the metadata
  63. * specify multiple bounding volumes, only the first one is returned. Bounding
  64. * volumes are checked in the order box, region, then sphere.
  65. * <p>
  66. * This handles both tile and content bounding volumes, as the only difference
  67. * is the prefix. e.g. <code>TILE_BOUNDING_BOX</code> and
  68. * <code>CONTENT_BOUNDING_BOX</code> have the same memory layout.
  69. * </p>
  70. *
  71. * @param {string} prefix Either "TILE" or "CONTENT"
  72. * @param {TileMetadata|ContentMetadata} metadata The metadata for looking up values
  73. * @return {object} An object representing the JSON description of the tile or content bounding volume
  74. * @private
  75. */
  76. BoundingVolumeSemantics.parseBoundingVolumeSemantic = function (
  77. prefix,
  78. metadata,
  79. ) {
  80. //>>includeStart('debug', pragmas.debug);
  81. Check.typeOf.string("prefix", prefix);
  82. if (prefix !== "TILE" && prefix !== "CONTENT") {
  83. throw new DeveloperError("prefix must be either 'TILE' or 'CONTENT'");
  84. }
  85. Check.typeOf.object("metadata", metadata);
  86. //>>includeEnd('debug');
  87. const boundingBoxSemantic = `${prefix}_BOUNDING_BOX`;
  88. const boundingBox = metadata.getPropertyBySemantic(boundingBoxSemantic);
  89. if (defined(boundingBox)) {
  90. return {
  91. box: boundingBox,
  92. };
  93. }
  94. const boundingRegionSemantic = `${prefix}_BOUNDING_REGION`;
  95. const boundingRegion = metadata.getPropertyBySemantic(boundingRegionSemantic);
  96. if (defined(boundingRegion)) {
  97. return {
  98. region: boundingRegion,
  99. };
  100. }
  101. const boundingSphereSemantic = `${prefix}_BOUNDING_SPHERE`;
  102. const boundingSphere = metadata.getPropertyBySemantic(boundingSphereSemantic);
  103. if (defined(boundingSphere)) {
  104. // ARRAY with 4 elements is automatically converted to a Cartesian4
  105. return {
  106. sphere: boundingSphere,
  107. };
  108. }
  109. return undefined;
  110. };
  111. /**
  112. * Parse the minimum height from tile or content metadata. This is used for making
  113. * tighter quadtree bounds for implicit tiling. This works for both
  114. * <code>TILE_MINIMUM_HEIGHT</code> and <code>CONTENT_MINIMUM_HEIGHT</code>
  115. *
  116. * @param {string} prefix Either "TILE" or "CONTENT"
  117. * @param {TileMetadata|ContentMetadata} metadata The metadata for looking up values
  118. * @return {number} The minimum height
  119. * @private
  120. */
  121. BoundingVolumeSemantics._parseMinimumHeight = function (prefix, metadata) {
  122. //>>includeStart('debug', pragmas.debug);
  123. Check.typeOf.string("prefix", prefix);
  124. if (prefix !== "TILE" && prefix !== "CONTENT") {
  125. throw new DeveloperError("prefix must be either 'TILE' or 'CONTENT'");
  126. }
  127. Check.typeOf.object("metadata", metadata);
  128. //>>includeEnd('debug');
  129. const minimumHeightSemantic = `${prefix}_MINIMUM_HEIGHT`;
  130. return metadata.getPropertyBySemantic(minimumHeightSemantic);
  131. };
  132. /**
  133. * Parse the maximum height from tile or content metadata. This is used for
  134. * making tighter quadtree bounds for implicit tiling. This works for both
  135. * <code>TILE_MAXIMUM_HEIGHT</code> and <code>CONTENT_MAXIMUM_HEIGHT</code>
  136. *
  137. * @param {string} prefix Either "TILE" or "CONTENT"
  138. * @param {TileMetadata|ContentMetadata} metadata The metadata for looking up values
  139. * @return {number} The maximum height
  140. * @private
  141. */
  142. BoundingVolumeSemantics._parseMaximumHeight = function (prefix, metadata) {
  143. //>>includeStart('debug', pragmas.debug);
  144. Check.typeOf.string("prefix", prefix);
  145. if (prefix !== "TILE" && prefix !== "CONTENT") {
  146. throw new DeveloperError("prefix must be either 'TILE' or 'CONTENT'");
  147. }
  148. Check.typeOf.object("metadata", metadata);
  149. //>>includeEnd('debug');
  150. const maximumHeightSemantic = `${prefix}_MAXIMUM_HEIGHT`;
  151. return metadata.getPropertyBySemantic(maximumHeightSemantic);
  152. };
  153. export default BoundingVolumeSemantics;