diff --git a/src/modules/SatelliteProperties.js b/src/modules/SatelliteProperties.js index 03caa802..1c54803e 100644 --- a/src/modules/SatelliteProperties.js +++ b/src/modules/SatelliteProperties.js @@ -8,6 +8,7 @@ import "./util/CesiumSampledPositionRawValueAccess"; import satvisIcon from "../assets/android-chrome-192x192.png"; import { CesiumCallbackHelper } from "./util/CesiumCallbackHelper"; +// import { CesiumTransformsCache } from "./util/CesiumTransformsCache"; export class SatelliteProperties { constructor(tle, tags = []) { @@ -177,12 +178,14 @@ export class SatelliteProperties { const positionInertialTEME = this.computePositionInertialTEME(timestamp); const temeToFixed = Cesium.Transforms.computeTemeToPseudoFixedMatrix(timestamp); + // const temeToFixed = CesiumTransformsCache.getTemeToPseudoFixedMatrix(timestamp); if (!Cesium.defined(temeToFixed)) { console.error("Reference frame transformation data failed to load"); } const positionFixed = Cesium.Matrix3.multiplyByVector(temeToFixed, positionInertialTEME, new Cesium.Cartesian3()); const fixedToIcrf = Cesium.Transforms.computeFixedToIcrfMatrix(timestamp); + // const fixedToIcrf = CesiumTransformsCache.getFixedToIcrfMatrix(timestamp); if (!Cesium.defined(fixedToIcrf)) { console.error("Reference frame transformation data failed to load"); } diff --git a/src/modules/util/CesiumTransformsCache.js b/src/modules/util/CesiumTransformsCache.js new file mode 100644 index 00000000..004d03fb --- /dev/null +++ b/src/modules/util/CesiumTransformsCache.js @@ -0,0 +1,62 @@ +import * as Cesium from "cesium"; + +export class CesiumTransformsCache { + static cache = { + temeToPseudoFixed: { + stats: { + calls: 0, + miss: 0, + }, + }, + fixedToIcrfMatrix: { + stats: { + calls: 0, + miss: 0, + }, + }, + }; + + /** + * Computes and caches a rotation matrix to transform a point or vector from the Earth-Fixed frame axes (ITRF) + * to the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes + * at a given time + * @param {JulianDate} time The time at which to compute the rotation matrix. + * @returns {Matrix3} The rotation matrix + */ + static getTemeToPseudoFixedMatrix(time) { + const cache = CesiumTransformsCache.cache.temeToPseudoFixed; + const key = `${time.dayNumber}-${Math.floor(time.secondsOfDay)}`; + // const key = Cesium.JulianDate.toIso8601(time, 0); + if (!cache[key]) { + cache[key] = Cesium.Transforms.computeTemeToPseudoFixedMatrix(time); + cache.stats.miss += 1; + } + cache.stats.calls += 1; + if (cache.stats.calls % 10000 === 0) { + console.log(`getTemeToPseudoFixedMatrix: ${cache.stats.calls} calls, ${cache.stats.miss} misses Ratio: ${cache.stats.miss / cache.stats.calls}`); + } + return cache[key]; + } + + /** + * Computes and caches a rotation matrix to transform a point or vector from the Earth-Fixed frame axes (ITRF) + * to the International Celestial Reference Frame (GCRF/ICRF) inertial frame axes + * at a given time + * @param {JulianDate} time The time at which to compute the rotation matrix. + * @returns {Matrix3} The rotation matrix + */ + static getFixedToIcrfMatrix(time) { + const cache = CesiumTransformsCache.cache.fixedToIcrfMatrix; + const key = `${time.dayNumber}-${Math.floor(time.secondsOfDay)}`; + // const key = Cesium.JulianDate.toIso8601(time, 0); + if (!cache[key]) { + cache[key] = Cesium.Transforms.computeFixedToIcrfMatrix(time); + cache.stats.miss += 1; + } + cache.stats.calls += 1; + if (cache.stats.calls % 10000 === 0) { + console.log(`getFixedToIcrfMatrix: ${cache.stats.calls} calls, ${cache.stats.miss} misses Ratio: ${cache.stats.miss / cache.stats.calls}`); + } + return cache[key]; + } +}