Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | 428x 14876x 14876x 14876x 14876x 1317x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 14876x 6460246x 6460246x 14876x 24476x 24476x 24476x 24476x 24476x 24476x 6460246x 14876x 24476x 612584468x 194x 43646976x 43646976x 194x 194x 43646976x 43646976x 43646976x 194x 194x 14876x 160715698x 160715698x 145895920x 145895920x 145895920x 160715698x 145895920x 14876x 19397138x 1914x 954x 510x 444x 14876x 1884x 145058428x 1884x 1884x 1884x 1884x 1884x 1884x 1884x 1884x 1884x 1884x 952x 952x 932x 212x 212x 720x 9486x 9486x 1187534x 1187534x 143766148x 143766148x 143766148x 143766148x 143766148x 720x 212x 212x 212x 212x 212x 212x 25408x 13008896x 13008896x 12873554x 135342x 142798x 142798x 142798x 6473042x 6473042x 6473042x 44735x 44735x 44735x 720x 360x 360x 360x 322x 314x 8x 8x 1104x 145920396x 145920396x 145920396x 145920396x 145920396x 145920396x 145920396x 936x 936x 38x 936x 14876x 60x 60x 60x 254x 325576765x 325576765x 1760x 325575005x 325575005x 325575005x 325575005x 325575005x 325575005x 325575005x 245786259x 245786259x 1760x 245784499x 79778802x 79778802x 79778802x 79778802x 79778802x 13860864x 65917938x 65917938x 254x 312x 312x 312x 254x 254x 254x 254x 254x 360x 360x 360x 254x 304x 304x 304x 304x 304x 304x 11032x 11032x 11032x 11032x 11032x 11032x 304x 254x 254x 13972x 13972x 13972x 60x 13912x 13912x 373258455x 67104162x 67104162x 67104162x 13912x 13912x 13912x 13912x 442x 442x 442x 7408644x 7408644x 6449730x 6449730x 6449730x 958914x 7408644x 442x 442x 442x 208x 208x 208x 6448566x 6448566x 208x 208x 208x | import cache from '../cache/cache'; import type { BoundsIJK, Point3, PixelDataTypedArray, IImage, RGB, CPUImageData, IVoxelManager, IRLEVoxelMap, Point2, } from '../types'; import RLEVoxelMap from './RLEVoxelMap'; import isEqual from './isEqual'; import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData'; import { iterateOverPointsInShapeVoxelManager } from './pointInShapeCallback'; /** * Have a default size for cached RLE encoded images. This is hard to guess * up front because the RLE is usually used to store new/updated data, but this * is a first guess. */ const DEFAULT_RLE_SIZE = 5 * 1024; /** * This is a simple, standard interface to values associated with a voxel. */ export default class VoxelManager<T> { public modifiedSlices = new Set<number>(); private boundsIJK = [ [Infinity, -Infinity], [Infinity, -Infinity], [Infinity, -Infinity], ] as BoundsIJK; public map: Map<number, T> | IRLEVoxelMap<T>; public sourceVoxelManager: IVoxelManager<T>; public isInObject: (pointLPS, pointIJK) => boolean; public readonly dimensions: Point3; public readonly numberOfComponents; public getCompleteScalarDataArray?: () => ArrayLike<number>; public setCompleteScalarDataArray?: (scalarData: ArrayLike<number>) => void; public getRange: () => [number, number]; private scalarData = null as PixelDataTypedArray; // caching for sliceData as it is expensive to get it from the cache // I think we need to have a way to invalidate this cache and also have // a limit on the number of slices to cache since it can grow indefinitely private _sliceDataCache = null as Map<string, PixelDataTypedArray>; public readonly _id: string; points: Set<number>; width: number; frameSize: number; readonly _get: (index: number) => T; readonly _set: (index: number, v: T) => boolean; readonly _getConstructor?: () => new (length: number) => PixelDataTypedArray; _getScalarDataLength?: () => number; _getScalarData?: () => ArrayLike<number>; _updateScalarData?: (scalarData: ArrayLike<number>) => PixelDataTypedArray; _getSliceData: (args: { sliceIndex: number; slicePlane: number; }) => PixelDataTypedArray; /** * Gets the ID of the voxel manager */ public get id(): string { return this._id; } /** * Creates a generic voxel value accessor, with access to the values * provided by the _get and optionally _set values. * @param dimensions - for the voxel volume * @param options._get - called to get a value by index * @param options._set - called when setting a value */ constructor( dimensions, options: { _get: (index: number) => T; _set?: (index: number, v: T) => boolean; _getScalarData?: () => ArrayLike<number>; _id?: string; _updateScalarData?: ( scalarData: ArrayLike<number> ) => PixelDataTypedArray; numberOfComponents?: number; scalarData?: ArrayLike<number>; _getConstructor?: () => new (length: number) => PixelDataTypedArray; } ) { this.dimensions = dimensions; this.width = dimensions[0]; this.frameSize = this.width * dimensions[1]; this._get = options._get; this._set = options._set; this._id = options._id || ''; this._getConstructor = options._getConstructor; this.numberOfComponents = this.numberOfComponents || 1; this.scalarData = options.scalarData as PixelDataTypedArray; this._getScalarData = options._getScalarData; this._updateScalarData = options._updateScalarData; } /** * Gets the voxel value at position i,j,k. * This method should be used in favor of getAtIJKPoint when performance is a concern. */ public getAtIJK = (i, j, k) => { const index = this.toIndex([i, j, k]); return this._get(index); }; /** * Sets the voxel value at position i,j,k and records the slice * that was modified. * * This method should be used in favor of setAtIJKPoint when performance is a concern. */ public setAtIJK = (i: number, j: number, k: number, v) => { const index = this.toIndex([i, j, k]); const changed = this._set(index, v); Eif (changed !== false) { this.modifiedSlices.add(k); VoxelManager.addBounds(this.boundsIJK, [i, j, k]); } return changed; }; /** * Gets the voxel value at the given Point3 location. */ public getAtIJKPoint = ([i, j, k]) => this.getAtIJK(i, j, k); /** * Sets the voxel value at the given point3 location to the specified value. * Records the z index modified. * Will record the index value if the VoxelManager is backed by a map. */ public setAtIJKPoint = ([i, j, k]: Point3, v) => { this.setAtIJK(i, j, k, v); }; /** * Gets the value at the given index. */ public getAtIndex = (index) => this._get(index); /** Gets the min/max pair - as array for RGB */ public getMinMax() { let min, max; const callback = ({ value: v }) => { const isArray = Array.isArray(v); if (min === undefined) { min = isArray ? [...v] : v; max = isArray ? [...v] : v; } Iif (isArray) { for (let i = 0; i < v.length; i++) { min[i] = Math.min(min[i], v[i]); max[i] = Math.max(max[i], v[i]); } } else { min = Math.min(min, v); max = Math.max(max, v); } }; this.forEach(callback, { boundsIJK: this.getDefaultBounds() }); return { min, max }; } /** * Sets the value at the given index */ public setAtIndex = (index, v) => { const changed = this._set(index, v); if (changed !== false) { const pointIJK = this.toIJK(index); this.modifiedSlices.add(pointIJK[2]); VoxelManager.addBounds(this.boundsIJK, pointIJK); } return changed; }; /** * Converts an index value to a Point3 IJK value */ public toIJK(index: number): Point3 { return [ index % this.width, Math.floor((index % this.frameSize) / this.width), Math.floor(index / this.frameSize), ]; } public getMiddleSliceData = () => { const middleSliceIndex = Math.floor(this.dimensions[2] / 2); return this.getSliceData({ sliceIndex: middleSliceIndex, slicePlane: 2, }); }; /** * Converts an IJK Point3 value to an index value */ public toIndex(ijk: Point3) { return ijk[0] + ijk[1] * this.width + ijk[2] * this.frameSize; } public getDefaultBounds() { return this.dimensions.map((dimension) => [0, dimension - 1]) as BoundsIJK; } /** * Gets the bounds for the modified set of values. */ public getBoundsIJK(): BoundsIJK { if (this.boundsIJK[0][0] < this.dimensions[0]) { return this.boundsIJK; } return this.getDefaultBounds(); } /** * Iterates over the voxels in the VoxelManager and applies a callback function to each voxel. * It can operate on IJK and LPS coordinate systems, and it can be limited to a specific region * of the data if the isInObject function is provided. * * For the LPS calculations, both direction and spacing should be provided. * * If the boundsIJK is not provided, the iteration will be over the entire volume/data * * If the VoxelManager is backed by a Map, it will only iterate over the stored values. * Otherwise, it will iterate over all voxels within the specified or default bounds. * * @param callback - a callback to call with `value, index, pointIJK` for * every point in the scalar data, map or rle map depending on the VoxelManager * type. * @param options - has an optional isWIthinObject to test to see if hte callback * should be called or not. */ public forEach = ( callback: (args: { value: unknown; index: number; pointIJK: Point3; pointLPS: Point3; }) => void, options: { boundsIJK?: BoundsIJK; isInObject?: (pointLPS, pointIJK) => boolean; returnPoints?: boolean; imageData?: vtkImageData | CPUImageData; } = {} ) => { const isInObjectBoundsIJK = options.boundsIJK || this.getBoundsIJK(); const isInObject = options.isInObject || this.isInObject || (() => true); const returnPoints = options.returnPoints || false; const useLPSTransform = options.imageData; const iMin = Math.min(isInObjectBoundsIJK[0][0], isInObjectBoundsIJK[0][1]); const iMax = Math.max(isInObjectBoundsIJK[0][0], isInObjectBoundsIJK[0][1]); const jMin = Math.min(isInObjectBoundsIJK[1][0], isInObjectBoundsIJK[1][1]); const jMax = Math.max(isInObjectBoundsIJK[1][0], isInObjectBoundsIJK[1][1]); const kMin = Math.min(isInObjectBoundsIJK[2][0], isInObjectBoundsIJK[2][1]); const kMax = Math.max(isInObjectBoundsIJK[2][0], isInObjectBoundsIJK[2][1]); const pointsInShape = []; if (useLPSTransform) { const pointsInShape = iterateOverPointsInShapeVoxelManager({ voxelManager: this, imageData: options.imageData, bounds: [ [iMin, iMax], [jMin, jMax], [kMin, kMax], ], pointInShapeFn: isInObject, callback, returnPoints, }); return pointsInShape; } // We don't need the complex LPS calculations and we can just iterate over the data // in the IJK coordinate system if (this.map) { Eif (this.map instanceof RLEVoxelMap) { return this.rleForEach(callback, options); } // Optimize this for only values in the map for (const index of this.map.keys()) { const pointIJK = this.toIJK(index); if (!isInObject(null, pointIJK)) { continue; } const value = this._get(index); if (returnPoints) { pointsInShape.push({ value, index, pointIJK, pointLPS: null, }); } callback({ value, index, pointIJK, pointLPS: null }); } return pointsInShape; } else { for (let k = kMin; k <= kMax; k++) { const kIndex = k * this.frameSize; for (let j = jMin; j <= jMax; j++) { const jIndex = kIndex + j * this.width; for (let i = iMin, index = jIndex + i; i <= iMax; i++, index++) { const value = this.getAtIndex(index); const pointIJK = [i, j, k]; Iif (!isInObject(null, pointIJK)) { continue; } Iif (returnPoints) { pointsInShape.push({ value, index, pointIJK, pointLPS: null, }); } callback({ value, index, pointIJK: [i, j, k], pointLPS: null }); } } } return pointsInShape; } }; /** * Foreach callback optimized for RLE testing * @param callback - a callback to call with `value, index, pointIJK` for * every point in the rle map (see the rle map for callbacks that work at * the row or rle level, as those can be faster/more efficient) * @param options - has an optional isWIthinObject to test to see if hte callback * should be called or not. */ public rleForEach(callback, options?) { const boundsIJK = options?.boundsIJK || this.getBoundsIJK(); const { isWithinObject } = options || {}; const map = this.map as RLEVoxelMap<T>; Iif (!map) { console.warn( 'No map found, you need to use a map voxel manager to use rleForEach' ); return; } map.defaultValue = undefined; for (let k = boundsIJK[2][0]; k <= boundsIJK[2][1]; k++) { for (let j = boundsIJK[1][0]; j <= boundsIJK[1][1]; j++) { const row = map.getRun(j, k); if (!row) { continue; } for (const rle of row) { const { start, end, value } = rle; const baseIndex = this.toIndex([0, j, k]); for (let i = start; i < end; i++) { const callbackArguments = { value, index: baseIndex + i, pointIJK: [i, j, k], }; Iif (isWithinObject?.(callbackArguments) === false) { continue; } callback(callbackArguments); } } } } } /** * Retrieves the scalar data. * If the scalar data is already available, it will be returned. * Otherwise, if the `_getScalarData` method is defined, it will be called to retrieve the scalar data. * If neither the scalar data nor the `_getScalarData` method is available, an error will be thrown. * * @param storeScalarData - a parameter to allow storing the scalar data rather than throwing it away * each time. * @returns The scalar data. * @throws {Error} If no scalar data is available. */ public getScalarData(storeScalarData = false): PixelDataTypedArray { Eif (this.scalarData) { this._updateScalarData?.(this.scalarData); return this.scalarData; } if (this._getScalarData) { const scalarData = this._getScalarData(); if (storeScalarData) { console.log('Not transient, should store value', scalarData); } return scalarData as PixelDataTypedArray; } throw new Error('No scalar data available'); } public setScalarData(newScalarData: PixelDataTypedArray) { this.scalarData = newScalarData; } /** * Gets the length of the scalar data. * * @returns The length of the scalar data. * @throws {Error} If no scalar data is available. */ public getScalarDataLength() { if (this.scalarData) { return this.scalarData.length; } Eif (this._getScalarDataLength) { return this._getScalarDataLength(); } throw new Error('No scalar data available'); } public get sizeInBytes(): number { return this.getScalarDataLength() * this.bytePerVoxel; } public get bytePerVoxel(): number { if (this.scalarData) { return this.scalarData.BYTES_PER_ELEMENT; } // get the first element of the scalar data const value = this._get(0) as unknown as { BYTES_PER_ELEMENT: number }; return value.BYTES_PER_ELEMENT; } public clearBounds() { this.boundsIJK.map((bound) => { bound[0] = Infinity; bound[1] = -Infinity; }); } /** * Clears any map specific data, as well as the modified slices, points and * bounds. */ public clear() { this.map?.clear(); this.clearBounds(); this.modifiedSlices.clear(); this.points?.clear(); } /** * @returns a constructor for a typed array for the pixel data of the given length * and the right type. Defaults to float32array. */ public getConstructor(): new (length: number) => PixelDataTypedArray { if (this.scalarData) { return this.scalarData.constructor as new ( length: number ) => PixelDataTypedArray; } Eif (this._getConstructor) { return this._getConstructor() as new ( length: number ) => PixelDataTypedArray; } console.warn( 'No scalar data available or can be used to get the constructor' ); // Return a default constructor (e.g., Float32Array) if no constructor is available return Float32Array as new (length: number) => PixelDataTypedArray; } /** * @returns The array of modified k indices */ public getArrayOfModifiedSlices(): number[] { return Array.from(this.modifiedSlices); } /** * Resets the set of modified slices. * This method clears all entries from the `modifiedSlices` set, * effectively marking all slices as unmodified. */ public resetModifiedSlices(): void { this.modifiedSlices.clear(); } /** * Sets the bounds of the voxel manager. * @param bounds - The bounds to set. */ public setBounds(bounds: BoundsIJK) { this.boundsIJK = bounds; } /** * Extends the bounds of this object to include the specified point */ public static addBounds(bounds: BoundsIJK, point: Point3) { Iif (!bounds) { bounds = [ [Infinity, -Infinity], [Infinity, -Infinity], [Infinity, -Infinity], ]; } // Directly update the bounds for each axis bounds[0][0] = Math.min(point[0], bounds[0][0]); bounds[0][1] = Math.max(point[0], bounds[0][1]); bounds[1][0] = Math.min(point[1], bounds[1][0]); bounds[1][1] = Math.max(point[1], bounds[1][1]); bounds[2][0] = Math.min(point[2], bounds[2][0]); bounds[2][1] = Math.max(point[2], bounds[2][1]); } /** * Adds a point as an array or an index value to the set of points * associated with this voxel value. * Can be used for tracking clicked points or other modified values. */ public addPoint(point: Point3 | number) { const index = Array.isArray(point) ? point[0] + this.width * point[1] + this.frameSize * point[2] : point; if (!this.points) { this.points = new Set<number>(); } this.points.add(index); } /** * Gets the list of added points as an array of Point3 values */ public getPoints(): Point3[] { return this.points ? [...this.points].map((index) => this.toIJK(index)) : []; } /** * Retrieves the slice data for a given slice view. * * @param sliceViewInfo - An object containing information about the slice view. * @param sliceViewInfo.sliceIndex - The index of the slice. * @param sliceViewInfo.slicePlane - The axis of the slice (0 for YZ plane, 1 for XZ plane, 2 for XY plane). * @returns A typed array containing the pixel data for the specified slice. * @throws Error if an invalid slice axis is provided. */ public getSliceData = ({ sliceIndex, slicePlane, }: { sliceIndex: number; slicePlane: number; }): PixelDataTypedArray => { const [width, height, depth] = this.dimensions; const frameSize = width * height; const startIndex = sliceIndex * frameSize; let sliceSize: number; const SliceDataConstructor = this.getConstructor(); function isValidConstructor( ctor: unknown ): ctor is new (length: number) => PixelDataTypedArray { return typeof ctor === 'function'; } if (!isValidConstructor(SliceDataConstructor)) { // Return an empty typed array instead of an empty regular array return new Uint8Array(0) as PixelDataTypedArray; } // Todo: optimize it when we have scalar data let sliceData: PixelDataTypedArray; switch (slicePlane) { case 0: // YZ plane sliceSize = height * depth; sliceData = new SliceDataConstructor(sliceSize); for (let i = 0; i < height; i++) { for (let j = 0; j < depth; j++) { const index = sliceIndex + i * width + j * frameSize; this.setSliceDataValue(sliceData, i * depth + j, this._get(index)); } } break; case 1: // XZ plane sliceSize = width * depth; sliceData = new SliceDataConstructor(sliceSize); for (let i = 0; i < width; i++) { for (let j = 0; j < depth; j++) { const index = i + sliceIndex * width + j * frameSize; this.setSliceDataValue(sliceData, i + j * width, this._get(index)); } } break; case 2: // XY plane sliceSize = width * height; sliceData = new SliceDataConstructor(sliceSize); for (let i = 0; i < sliceSize; i++) { this.setSliceDataValue(sliceData, i, this._get(startIndex + i)); } break; default: throw new Error( 'Oblique plane - todo - implement as ortho normal vector' ); } return sliceData; }; private setSliceDataValue( sliceData: PixelDataTypedArray, index: number, value: T ): void { if (Array.isArray(value)) { // Handle RGB values for (let i = 0; i < value.length; i++) { sliceData[index * value.length + i] = this.toNumber(value[i]); } } else { // Handle single number values sliceData[index] = this.toNumber(value); } } private toNumber(value: T | number): number { if (typeof value === 'number') { return value; } if (Array.isArray(value)) { return value[0] || 0; } return 0; } /** * Creates a voxel manager backed by an array of scalar data having the * given number of components. * Note that the number of components can be larger than three, in case data * is stored in additional pixels. However, the return type is still RGB. */ private static _createRGBScalarVolumeVoxelManager({ dimensions, scalarData, numberOfComponents = 3, id, }: { dimensions: Point3; scalarData; numberOfComponents; id?: string; }): VoxelManager<RGB> { const voxels = new VoxelManager<RGB>(dimensions, { _get: (index) => { index *= numberOfComponents; return [ scalarData[index++], scalarData[index++], scalarData[index++], ] as RGB; }, _id: id || '_createRGBScalarVolumeVoxelManager', _set: (index, v) => { index *= 3; const isChanged = !isEqual(scalarData[index], v); scalarData[index++] = v[0]; scalarData[index++] = v[1]; scalarData[index++] = v[2]; return isChanged; }, numberOfComponents, scalarData, }); voxels.clear = () => { scalarData.fill(0); }; return voxels; } /** * Creates a VoxelManager for an image volume. which are those volumes * that are composed of multiple images, one for each slice. * @param dimensions - The dimensions of the image volume. * @param imageIds - The array of image IDs. * @returns A VoxelManager instance for the image volume. */ public static createImageVolumeVoxelManager({ dimensions, imageIds, numberOfComponents = 1, id, }: { dimensions: Point3; imageIds: string[]; numberOfComponents: number; id?: string; }): IVoxelManager<number> | IVoxelManager<RGB> { const pixelsPerSlice = dimensions[0] * dimensions[1]; function getPixelInfo(index) { const sliceIndex = Math.floor(index / pixelsPerSlice); if (sliceIndex < 0 || sliceIndex >= dimensions[2]) { return {}; } const imageId = imageIds[sliceIndex]; Iif (!imageId) { console.warn(`ImageId not found for sliceIndex: ${sliceIndex}`); return { pixelData: null, pixelIndex: null }; } const image = cache.getImage(imageId); Iif (!image) { console.warn(`Image not found for imageId: ${imageId}`); return { pixelData: null, pixelIndex: null }; } const voxelManager = image.voxelManager; const pixelIndex = index % pixelsPerSlice; return { voxelManager, pixelIndex }; } function getVoxelValue(index) { const { voxelManager: imageVoxelManager, pixelIndex } = getPixelInfo(index); if (!imageVoxelManager || pixelIndex === null) { return null; } return imageVoxelManager.getAtIndex(pixelIndex) as number | RGB; } function setVoxelValue(index, v) { const { voxelManager: imageVoxelManager, pixelIndex } = getPixelInfo(index); Iif (!imageVoxelManager || pixelIndex === null) { return false; } const currentValue = imageVoxelManager.getAtIndex(pixelIndex); const isChanged = !isEqual(v, currentValue); if (!isChanged) { return isChanged; } imageVoxelManager.setAtIndex(pixelIndex, v as number); return true; } const _getConstructor = () => { const { voxelManager: imageVoxelManager, pixelIndex } = getPixelInfo(0); Iif (!imageVoxelManager || pixelIndex === null) { return null; } return imageVoxelManager.getConstructor(); }; const voxelManager = new VoxelManager<number | RGB>(dimensions, { _get: getVoxelValue, _set: setVoxelValue, numberOfComponents, _getConstructor, _id: id || 'createImageVolumeVoxelManager', }); voxelManager.getMiddleSliceData = () => { const middleSliceIndex = Math.floor(dimensions[2] / 2); return voxelManager.getSliceData({ sliceIndex: middleSliceIndex, slicePlane: 2, }); }; voxelManager.clear = () => { for (const imageId of imageIds) { const image = cache.getImage(imageId); image.voxelManager.clear(); } }; // Todo: need a way to make it understand dirty status if pixel data is changed voxelManager.getRange = () => { // get all the pixel data let minValue = Infinity; let maxValue = -Infinity; for (const imageId of imageIds) { const image = cache.getImage(imageId); // Skip if image not loaded yet if (!image) { continue; } // min and max pixel value is correct, //todo this is not true // for dynamically changing data such as labelmaps in segmentation if (image.minPixelValue < minValue) { minValue = image.minPixelValue; } if (image.maxPixelValue > maxValue) { maxValue = image.maxPixelValue; } } // If no images were loaded yet, return default range if (minValue === Infinity && maxValue === -Infinity) { return [0, 0]; } return [minValue, maxValue]; }; voxelManager._getScalarDataLength = () => { const { voxelManager: imageVoxelManager, pixelIndex } = getPixelInfo(0); Iif (!imageVoxelManager || pixelIndex === null) { return 0; } return imageVoxelManager.getScalarDataLength() * dimensions[2]; }; /** * Retrieves the scalar data in a memory-inefficient manner. * Useful for debugging, testing, or methods requiring all scalar data at once. * * IMPORTANT: This is READ ONLY. Changes to the returned buffer are never * reflected in the underlying data unless individually merged back. * * @returns {ArrayLike<number>} The scalar data array (read-only) */ voxelManager.getCompleteScalarDataArray = () => { const ScalarDataConstructor = voxelManager._getConstructor(); Iif (!ScalarDataConstructor) { return new Uint8Array(0); } const dataLength = voxelManager.getScalarDataLength(); const scalarData = new ScalarDataConstructor(dataLength); const sliceSize = dimensions[0] * dimensions[1] * numberOfComponents; for (let sliceIndex = 0; sliceIndex < dimensions[2]; sliceIndex++) { const { voxelManager: imageVoxelManager, pixelIndex } = getPixelInfo( (sliceIndex * sliceSize) / numberOfComponents ); Eif (imageVoxelManager && pixelIndex !== null) { const sliceStart = sliceIndex * sliceSize; const pixelData = imageVoxelManager.getScalarData(); if (numberOfComponents === 1) { scalarData.set(pixelData, sliceStart); } else E{ // For RGB(A) data, we need to ensure correct component ordering for (let i = 0; i < pixelData.length; i += numberOfComponents) { for (let j = 0; j < numberOfComponents; j++) { scalarData[sliceStart + i + j] = pixelData[i + j]; } } } } } return scalarData; }; voxelManager.setCompleteScalarDataArray = (scalarData) => { const sliceSize = dimensions[0] * dimensions[1] * numberOfComponents; const SliceDataConstructor = voxelManager._getConstructor(); // Track min/max values across all slices let minValue = Infinity; let maxValue = -Infinity; for (let sliceIndex = 0; sliceIndex < dimensions[2]; sliceIndex++) { const { voxelManager: imageVoxelManager } = getPixelInfo( (sliceIndex * sliceSize) / numberOfComponents ); if (imageVoxelManager && SliceDataConstructor) { const sliceStart = sliceIndex * sliceSize; const sliceEnd = sliceStart + sliceSize; // @ts-ignore const sliceData = new SliceDataConstructor(sliceSize); // @ts-ignore sliceData.set(scalarData.subarray(sliceStart, sliceEnd)); // Instead of directly assigning scalarData, use TypedArray's set method // previously here we were using imageVoxelManager.scalarData = sliceData // which had some weird side effects if (imageVoxelManager.scalarData) { imageVoxelManager.scalarData.set(sliceData); // Ensure the voxel manager knows about the changes imageVoxelManager.modifiedSlices.add(sliceIndex); } else { // Fallback to individual updates if scalarData is not directly accessible for (let i = 0; i < sliceSize; i++) { imageVoxelManager.setAtIndex(i, sliceData[i]); } } // Update min/max values for this slice for (let i = 0; i < sliceData.length; i++) { const value = sliceData[i]; minValue = Math.min(minValue, value); maxValue = Math.max(maxValue, value); } // Update the image's min/max pixel values const imageId = imageIds[sliceIndex]; const image = cache.getImage(imageId); if (image) { image.minPixelValue = minValue; image.maxPixelValue = maxValue; } } } // Mark all slices as modified for (let k = 0; k < dimensions[2]; k++) { voxelManager.modifiedSlices.add(k); } // Update bounds voxelManager.boundsIJK = [ [0, dimensions[0] - 1], [0, dimensions[1] - 1], [0, dimensions[2] - 1], ]; }; return voxelManager as IVoxelManager<number> | IVoxelManager<RGB>; } /** * Creates a volume value accessor, based on a volume scalar data instance. * This also works for image value accessors for single plane (k=0) accessors. * * This should be deprecated in favor of the createImageVolumeVoxelManager * method since that one does not need to know the number of scalar data and * it creates them on the fly. */ public static createScalarVolumeVoxelManager({ dimensions, scalarData, numberOfComponents, id, }: { dimensions: Point3; scalarData; numberOfComponents?: number; id?: string; }): IVoxelManager<number> | IVoxelManager<RGB> { if (dimensions.length !== 3) { throw new Error( 'Dimensions must be provided as [number, number, number] for [width, height, depth]' ); } if (!numberOfComponents) { numberOfComponents = scalarData.length / dimensions[0] / dimensions[1] / dimensions[2]; // We only support 1,3,4 component data, and sometimes the scalar data // doesn't match for some reason, so throw an exception if ( numberOfComponents > 4 || numberOfComponents < 1 || numberOfComponents === 2 ) { throw new Error( `Number of components ${numberOfComponents} must be 1, 3 or 4` ); } } if (numberOfComponents > 1) { return VoxelManager._createRGBScalarVolumeVoxelManager({ dimensions, scalarData, numberOfComponents, id, }); } return VoxelManager._createNumberVolumeVoxelManager({ dimensions, scalarData, id, }); } public static createScalarDynamicVolumeVoxelManager({ imageIdGroups, dimensions, dimensionGroupNumber = 1, timePoint = 0, numberOfComponents = 1, id, }: { imageIdGroups: string[][]; dimensions: Point3; dimensionGroupNumber?: number; timePoint?: number; numberOfComponents?: number; id?: string; }): IVoxelManager<number> | IVoxelManager<RGB> { // Convert to zero-based index for internal use let activeDimensionGroup = 0; if (dimensionGroupNumber !== undefined) { activeDimensionGroup = dimensionGroupNumber - 1; } else if (timePoint !== undefined) { console.warn( 'Warning: timePoint parameter is deprecated. Please use dimensionGroupNumber instead. timePoint is zero-based while dimensionGroupNumber starts at 1.' ); activeDimensionGroup = timePoint; } if (!numberOfComponents) { const firstImage = cache.getImage(imageIdGroups[0][0]); if (!firstImage) { throw new Error( 'Unable to determine number of components: No image found' ); } numberOfComponents = firstImage.getPixelData().length / (dimensions[0] * dimensions[1]); if ( numberOfComponents > 4 || numberOfComponents < 1 || numberOfComponents === 2 ) { throw new Error( `Number of components ${numberOfComponents} must be 1, 3 or 4` ); } } const voxelGroups = imageIdGroups.map((imageIds) => { return VoxelManager.createImageVolumeVoxelManager({ dimensions, imageIds, numberOfComponents, id, }); }); // Create a VoxelManager that will manage the active voxel group const voxelManager = new VoxelManager<number | RGB>(dimensions, { _get: (index) => voxelGroups[activeDimensionGroup]._get(index), // @ts-ignore _set: (index, v) => voxelGroups[activeDimensionGroup]._set(index, v), numberOfComponents, _id: id || 'createScalarDynamicVolumeVoxelManager', }) as IVoxelManager<number> | IVoxelManager<RGB>; voxelManager.getScalarDataLength = () => { return voxelGroups[activeDimensionGroup].getScalarDataLength(); }; voxelManager.getConstructor = () => { return voxelGroups[activeDimensionGroup].getConstructor(); }; voxelManager.getRange = () => { return voxelGroups[activeDimensionGroup].getRange(); }; voxelManager.getMiddleSliceData = () => { return voxelGroups[activeDimensionGroup].getMiddleSliceData(); }; // @ts-ignore voxelManager.setTimePoint = (newTimePoint: number) => { console.warn( 'Warning: setTimePoint is deprecated. Please use setDimensionGroupNumber instead. Note that timePoint is zero-based while dimensionGroupNumber starts at 1.' ); // @ts-ignore voxelManager.setDimensionGroupNumber(newTimePoint + 1); }; // @ts-ignore voxelManager.setDimensionGroupNumber = ( newDimensionGroupNumber: number ) => { activeDimensionGroup = newDimensionGroupNumber - 1; // @ts-ignore voxelManager._get = (index) => voxelGroups[activeDimensionGroup]._get(index); // @ts-ignore voxelManager._set = (index, v) => voxelGroups[activeDimensionGroup]._set(index, v); }; // @ts-ignore voxelManager.getAtIndexAndTimePoint = (index: number, tp: number) => { console.warn( 'Warning: getAtIndexAndTimePoint is deprecated. Please use getAtIndexAndDimensionGroup instead. Note that timePoint is zero-based while dimensionGroupNumber starts at 1.' ); // @ts-ignore return voxelManager.getAtIndexAndDimensionGroup(index, tp + 1); }; // @ts-ignore voxelManager.getAtIndexAndDimensionGroup = ( index: number, dimensionGroupNumber: number ) => { return voxelGroups[dimensionGroupNumber - 1]._get(index); }; // @ts-ignore voxelManager.getTimePointScalarData = (tp: number) => { console.warn( 'Warning: getTimePointScalarData is deprecated. Please use getDimensionGroupScalarData instead. Note that timePoint is zero-based while dimensionGroupNumber starts at 1.' ); // @ts-ignore return voxelManager.getDimensionGroupScalarData(tp + 1); }; // @ts-ignore voxelManager.getDimensionGroupScalarData = ( dimensionGroupNumber: number ) => { return voxelGroups[dimensionGroupNumber - 1].getCompleteScalarDataArray(); }; // @ts-ignore voxelManager.getCurrentTimePointScalarData = () => { console.warn( 'Warning: getCurrentTimePointScalarData is deprecated. Please use getCurrentDimensionGroupScalarData instead.' ); // @ts-ignore return voxelManager.getCurrentDimensionGroupScalarData(); }; // @ts-ignore voxelManager.getCurrentDimensionGroupScalarData = () => { return voxelGroups[activeDimensionGroup].getCompleteScalarDataArray(); }; // @ts-ignore voxelManager.getCurrentTimePoint = () => { console.warn( 'Warning: getCurrentTimePoint is deprecated. Please use getCurrentDimensionGroupNumber instead. Note that timePoint is zero-based while dimensionGroupNumber starts at 1.' ); return activeDimensionGroup; }; // @ts-ignore voxelManager.getCurrentDimensionGroupNumber = () => { return activeDimensionGroup + 1; }; return voxelManager as IVoxelManager<number> | IVoxelManager<RGB>; } public static createImageVoxelManager({ width, height, scalarData, numberOfComponents = 1, id, }: { width: number; height: number; scalarData: PixelDataTypedArray; numberOfComponents?: number; id?: string; }): IVoxelManager<number> | IVoxelManager<RGB> { const dimensions = [width, height, 1] as Point3; Iif (!numberOfComponents) { numberOfComponents = scalarData.length / width / height; if ( numberOfComponents > 4 || numberOfComponents < 1 || numberOfComponents === 2 ) { throw new Error( `Number of components ${numberOfComponents} must be 1, 3 or 4` ); } } if (numberOfComponents > 1) { return VoxelManager._createRGBScalarVolumeVoxelManager({ dimensions, scalarData, numberOfComponents, id, }); } return VoxelManager._createNumberVolumeVoxelManager({ dimensions, scalarData, id, }); } /** * Creates a volume voxel manager that works on single numeric values stored * in an array like structure of numbers. */ private static _createNumberVolumeVoxelManager({ dimensions, scalarData, id, }: { dimensions: Point3; scalarData: PixelDataTypedArray; id?: string; }): IVoxelManager<number> { const voxels = new VoxelManager<number>(dimensions, { _get: (index) => scalarData[index], _set: (index, v) => { const isChanged = scalarData[index] !== v; scalarData[index] = v; return isChanged; }, _getConstructor: () => scalarData.constructor as new (length: number) => PixelDataTypedArray, _id: id || '_createNumberVolumeVoxelManager', }); voxels.scalarData = scalarData; voxels.clear = () => { // get the latest scalar data and set that to all 0 voxels.scalarData.fill(0); }; voxels.getMiddleSliceData = () => { const middleSliceIndex = Math.floor(dimensions[2] / 2); return voxels.getSliceData({ sliceIndex: middleSliceIndex, slicePlane: 2, }); }; return voxels; } /** * Creates a volume map value accessor. This is initially empty and * the map stores the index to value instances. * This is useful for sparse matrices containing pixel data. */ public static createMapVoxelManager<T>({ dimension, id, }: { dimension: Point3; id?: string; }): IVoxelManager<T> { const map = new Map<number, T>(); const voxelManager = new VoxelManager<T>(dimension, { _get: map.get.bind(map), _set: (index, v) => map.set(index, v) && true, _id: id || 'createMapVoxelManager', }); voxelManager.map = map; return voxelManager; } /** * Creates a history remembering voxel manager. * This will remember the original values in the voxels, and will apply the * update to the underlying source voxel manager. */ public static createHistoryVoxelManager<T>( sourceVoxelManager: VoxelManager<T>, id?: string ): VoxelManager<T> { const map = new Map<number, T>(); const { dimensions } = sourceVoxelManager; const voxelManager = new VoxelManager(dimensions, { _get: (index) => map.get(index), _set: function (index, v) { if (!map.has(index)) { const oldV = this.sourceVoxelManager.getAtIndex(index); if (oldV === v) { // No-op return false; } map.set(index, oldV); } else if (v === map.get(index)) { map.delete(index); } this.sourceVoxelManager.setAtIndex(index, v); }, _id: id || 'createHistoryVoxelManager', }); voxelManager.map = map; voxelManager.scalarData = sourceVoxelManager.scalarData; voxelManager.sourceVoxelManager = sourceVoxelManager; return voxelManager; } /** * Creates a history remembering voxel manager, based on the RLE endpoint * rather than a map endpoint. * This will remember the original values in the voxels, and will apply the * update to the underlying source voxel manager. */ public static createRLEHistoryVoxelManager<T>( sourceVoxelManager: VoxelManager<T>, id?: string ): VoxelManager<T> { const { dimensions } = sourceVoxelManager; const map = new RLEVoxelMap<T>(dimensions[0], dimensions[1], dimensions[2]); const voxelManager = new VoxelManager<T>(dimensions, { _get: (index) => map.get(index), _set: function (index, v) { const originalV = map.get(index); if (originalV === undefined) { const oldV = this.sourceVoxelManager.getAtIndex(index); Iif (oldV === v || (oldV === undefined && v === 0) || v === null) { // No-op return false; } map.set(index, oldV ?? 0); } else Iif (v === originalV || v === null) { map.delete(index); v = originalV; } this.sourceVoxelManager.setAtIndex(index, v); }, _getScalarData: RLEVoxelMap.getScalarData, _updateScalarData: (scalarData) => { map.updateScalarData(scalarData as PixelDataTypedArray); return scalarData as PixelDataTypedArray; }, _id: id || 'createRLEHistoryVoxelManager', }); voxelManager.map = map; voxelManager.sourceVoxelManager = sourceVoxelManager; return voxelManager; } /** * Creates a lazy voxel manager that will create an image plane as required * for each slice of a volume as it gets changed. This can be used to * store image data that gets created as required. */ public static createLazyVoxelManager<T>({ dimensions, planeFactory, id, }: { dimensions: Point3; planeFactory: (width: number, height: number) => T; id?: string; }): VoxelManager<T> { const map = new Map<number, T>(); const [width, height] = dimensions; const planeSize = width * height; const voxelManager = new VoxelManager(dimensions, { _get: (index) => map.get(Math.floor(index / planeSize))[index % planeSize], _set: (index, v) => { const k = Math.floor(index / planeSize); let layer = map.get(k); if (!layer) { layer = planeFactory(width, height); map.set(k, layer); } layer[index % planeSize] = v; return true; }, _id: id || 'createLazyVoxelManager', }); voxelManager.map = map; return voxelManager; } /** * Creates a RLE based voxel manager. This is effective for storing * segmentation maps or already RLE encoded data such as ultrasounds. */ public static createRLEVolumeVoxelManager<T>({ dimensions, id, }: { dimensions: Point3; id?: string; }): VoxelManager<T> { const [width, height, depth] = dimensions; const map = new RLEVoxelMap<T>(width, height, depth); const voxelManager = new VoxelManager<T>(dimensions, { _get: (index) => map.get(index), _set: (index, v) => { map.set(index, v); return true; }, _getScalarData: RLEVoxelMap.getScalarData, _updateScalarData: (scalarData) => { map.updateScalarData(scalarData as PixelDataTypedArray); return scalarData as PixelDataTypedArray; }, _id: id || 'createRLEVolumeVoxelManager', }); voxelManager.map = map; // @ts-ignore voxelManager.getPixelData = map.getPixelData.bind(map); // @ts-ignore return voxelManager; } public static createRLEImageVoxelManager<T>({ dimensions, id, }: { dimensions: Point2; id?: string; }): VoxelManager<T> { const [width, height] = dimensions; return VoxelManager.createRLEVolumeVoxelManager<T>({ dimensions: [width, height, 1], id, }); } /** * This method adds a voxelManager instance to the image object * where the object added is of type: * 1. RLE map if the scalar data is missing or too small (dummy data) * 2. Volume VoxelManager scalar data representations */ public static addInstanceToImage(image: IImage) { const { width, height } = image; const scalarData = image.voxelManager.getScalarData(); // This test works for single images, or single representations of images // from a volume representation, for grayscale, indexed and RGB or RGBA images. if (scalarData.length >= width * height) { // This case means there is enough scalar data for at least one image, // with 1 or more components, and creates a volume voxel manager // that can lookup the data image.voxelManager = VoxelManager.createScalarVolumeVoxelManager({ dimensions: [width, height, 1], scalarData, }); return; } // This case occurs when the image data is a dummy image data set // created just to prevent exceptions in the caching logic. Then, the // RLE voxel manager can be created to store the data instead. image.voxelManager = VoxelManager.createRLEVolumeVoxelManager<number>({ dimensions: [width, height, 1], }); // The RLE voxel manager knows how to get scalar data pixel data representations. // That allows using the RLE representation as a normal pixel data representation // for VIEWING purposes. // @ts-ignore image.getPixelData = image.voxelManager.getPixelData; // Assign a different size to the cached data because this is actually // storing an RLE representation, which doesn't have an up front size. image.sizeInBytes = DEFAULT_RLE_SIZE; } public static; } export type { VoxelManager }; |