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

Cesium3DTilesetStatistics.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import defined from "../Core/defined.js";
  2. import Model3DTileContent from "./Model/Model3DTileContent.js";
  3. /**
  4. * @private
  5. */
  6. function Cesium3DTilesetStatistics() {
  7. // Rendering statistics
  8. this.selected = 0;
  9. this.visited = 0;
  10. // Loading statistics
  11. this.numberOfCommands = 0;
  12. this.numberOfAttemptedRequests = 0;
  13. this.numberOfPendingRequests = 0;
  14. this.numberOfTilesProcessing = 0;
  15. this.numberOfTilesWithContentReady = 0; // Number of tiles with content loaded, does not include empty tiles
  16. this.numberOfTilesTotal = 0; // Number of tiles in tileset JSON (and other tileset JSON files as they are loaded)
  17. this.numberOfLoadedTilesTotal = 0; // Running total of loaded tiles for the lifetime of the session
  18. // Features statistics
  19. this.numberOfFeaturesSelected = 0; // Number of features rendered
  20. this.numberOfFeaturesLoaded = 0; // Number of features in memory
  21. this.numberOfPointsSelected = 0;
  22. this.numberOfPointsLoaded = 0;
  23. this.numberOfTrianglesSelected = 0;
  24. // Styling statistics
  25. this.numberOfTilesStyled = 0;
  26. this.numberOfFeaturesStyled = 0;
  27. // Optimization statistics
  28. this.numberOfTilesCulledWithChildrenUnion = 0;
  29. // Memory statistics
  30. this.geometryByteLength = 0;
  31. this.texturesByteLength = 0;
  32. this.texturesReferenceCounterById = {};
  33. this.batchTableByteLength = 0; // batch textures and any binary metadata properties not otherwise accounted for
  34. }
  35. Cesium3DTilesetStatistics.prototype.clear = function () {
  36. this.selected = 0;
  37. this.visited = 0;
  38. this.numberOfCommands = 0;
  39. this.numberOfAttemptedRequests = 0;
  40. this.numberOfFeaturesSelected = 0;
  41. this.numberOfPointsSelected = 0;
  42. this.numberOfTrianglesSelected = 0;
  43. this.numberOfTilesStyled = 0;
  44. this.numberOfFeaturesStyled = 0;
  45. this.numberOfTilesCulledWithChildrenUnion = 0;
  46. };
  47. /**
  48. * Increment the counters for the points, triangles, and features
  49. * that are currently selected for rendering.
  50. *
  51. * This will be called recursively for the given content and
  52. * all its inner contents
  53. *
  54. * @param {Cesium3DTileContent} content
  55. */
  56. Cesium3DTilesetStatistics.prototype.incrementSelectionCounts = function (
  57. content,
  58. ) {
  59. this.numberOfFeaturesSelected += content.featuresLength;
  60. this.numberOfPointsSelected += content.pointsLength;
  61. this.numberOfTrianglesSelected += content.trianglesLength;
  62. // Recursive calls on all inner contents
  63. const contents = content.innerContents;
  64. if (defined(contents)) {
  65. const length = contents.length;
  66. for (let i = 0; i < length; ++i) {
  67. this.incrementSelectionCounts(contents[i]);
  68. }
  69. }
  70. };
  71. /**
  72. * Increment the counters for the number of features and points that
  73. * are currently loaded, and the lengths (size in bytes) of the
  74. * occupied memory.
  75. *
  76. * This will be called recursively for the given content and
  77. * all its inner contents
  78. *
  79. * @param {Cesium3DTileContent} content
  80. */
  81. Cesium3DTilesetStatistics.prototype.incrementLoadCounts = function (content) {
  82. this.numberOfFeaturesLoaded += content.featuresLength;
  83. this.numberOfPointsLoaded += content.pointsLength;
  84. this.geometryByteLength += content.geometryByteLength;
  85. this.batchTableByteLength += content.batchTableByteLength;
  86. // When the content is not a `Model3DTileContent`, then its
  87. // textures byte length is added directly
  88. if (!(content instanceof Model3DTileContent)) {
  89. this.texturesByteLength += content.texturesByteLength;
  90. } else {
  91. // When the content is a `Model3DTileContent`, then increment the
  92. // reference counter for all its textures. The byte length of any
  93. // newly tracked texture to the total textures byte length
  94. const textureIds = content.getTextureIds();
  95. for (const textureId of textureIds) {
  96. const referenceCounter =
  97. this.texturesReferenceCounterById[textureId] ?? 0;
  98. if (referenceCounter === 0) {
  99. const textureByteLength = content.getTextureByteLengthById(textureId);
  100. this.texturesByteLength += textureByteLength;
  101. }
  102. this.texturesReferenceCounterById[textureId] = referenceCounter + 1;
  103. }
  104. }
  105. // Recursive calls on all inner contents
  106. const contents = content.innerContents;
  107. if (defined(contents)) {
  108. const length = contents.length;
  109. for (let i = 0; i < length; ++i) {
  110. this.incrementLoadCounts(contents[i]);
  111. }
  112. }
  113. };
  114. /**
  115. * Decrement the counters for the number of features and points that
  116. * are currently loaded, and the lengths (size in bytes) of the
  117. * occupied memory.
  118. *
  119. * This will be called recursively for the given content and
  120. * all its inner contents
  121. *
  122. * @param {Cesium3DTileContent} content
  123. */
  124. Cesium3DTilesetStatistics.prototype.decrementLoadCounts = function (content) {
  125. this.numberOfFeaturesLoaded -= content.featuresLength;
  126. this.numberOfPointsLoaded -= content.pointsLength;
  127. this.geometryByteLength -= content.geometryByteLength;
  128. this.batchTableByteLength -= content.batchTableByteLength;
  129. // When the content is not a `Model3DTileContent`, then its
  130. // textures byte length is subtracted directly
  131. if (!(content instanceof Model3DTileContent)) {
  132. this.texturesByteLength -= content.texturesByteLength;
  133. } else {
  134. // When the content is a `Model3DTileContent`, then decrement the
  135. // reference counter for all its textures. The byte length of any
  136. // texture that is no longer references is subtracted from the
  137. // total textures byte length
  138. const textureIds = content.getTextureIds();
  139. for (const textureId of textureIds) {
  140. const referenceCounter = this.texturesReferenceCounterById[textureId];
  141. if (referenceCounter === 1) {
  142. delete this.texturesReferenceCounterById[textureId];
  143. const textureByteLength = content.getTextureByteLengthById(textureId);
  144. this.texturesByteLength -= textureByteLength;
  145. } else {
  146. this.texturesReferenceCounterById[textureId] = referenceCounter - 1;
  147. }
  148. }
  149. }
  150. // Recursive calls on all inner contents
  151. const contents = content.innerContents;
  152. if (defined(contents)) {
  153. const length = contents.length;
  154. for (let i = 0; i < length; ++i) {
  155. this.decrementLoadCounts(contents[i]);
  156. }
  157. }
  158. };
  159. Cesium3DTilesetStatistics.clone = function (statistics, result) {
  160. result.selected = statistics.selected;
  161. result.visited = statistics.visited;
  162. result.numberOfCommands = statistics.numberOfCommands;
  163. result.numberOfAttemptedRequests = statistics.numberOfAttemptedRequests;
  164. result.numberOfPendingRequests = statistics.numberOfPendingRequests;
  165. result.numberOfTilesProcessing = statistics.numberOfTilesProcessing;
  166. result.numberOfTilesWithContentReady =
  167. statistics.numberOfTilesWithContentReady;
  168. result.numberOfTilesTotal = statistics.numberOfTilesTotal;
  169. result.numberOfFeaturesSelected = statistics.numberOfFeaturesSelected;
  170. result.numberOfFeaturesLoaded = statistics.numberOfFeaturesLoaded;
  171. result.numberOfPointsSelected = statistics.numberOfPointsSelected;
  172. result.numberOfPointsLoaded = statistics.numberOfPointsLoaded;
  173. result.numberOfTrianglesSelected = statistics.numberOfTrianglesSelected;
  174. result.numberOfTilesStyled = statistics.numberOfTilesStyled;
  175. result.numberOfFeaturesStyled = statistics.numberOfFeaturesStyled;
  176. result.numberOfTilesCulledWithChildrenUnion =
  177. statistics.numberOfTilesCulledWithChildrenUnion;
  178. result.geometryByteLength = statistics.geometryByteLength;
  179. result.texturesByteLength = statistics.texturesByteLength;
  180. result.texturesReferenceCounterById = {
  181. ...statistics.texturesReferenceCounterById,
  182. };
  183. result.batchTableByteLength = statistics.batchTableByteLength;
  184. };
  185. export default Cesium3DTilesetStatistics;