summit/frontend/node_modules/three-stdlib/loaders/NRRDLoader.cjs.map

1 line
22 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"NRRDLoader.cjs","sources":["../../src/loaders/NRRDLoader.js"],"sourcesContent":["import { FileLoader, Loader, Matrix4, Vector3 } from 'three'\nimport { gunzipSync } from 'fflate'\nimport { Volume } from '../misc/Volume'\n\nclass NRRDLoader extends Loader {\n constructor(manager) {\n super(manager)\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n\n const loader = new FileLoader(scope.manager)\n loader.setPath(scope.path)\n loader.setResponseType('arraybuffer')\n loader.setRequestHeader(scope.requestHeader)\n loader.setWithCredentials(scope.withCredentials)\n loader.load(\n url,\n function (data) {\n try {\n onLoad(scope.parse(data))\n } catch (e) {\n if (onError) {\n onError(e)\n } else {\n console.error(e)\n }\n\n scope.manager.itemError(url)\n }\n },\n onProgress,\n onError,\n )\n }\n\n parse(data) {\n // this parser is largely inspired from the XTK NRRD parser : https://github.com/xtk/X\n\n let _data = data\n\n let _dataPointer = 0\n\n const _nativeLittleEndian = new Int8Array(new Int16Array([1]).buffer)[0] > 0\n\n const _littleEndian = true\n\n const headerObject = {}\n\n function scan(type, chunks) {\n if (chunks === undefined || chunks === null) {\n chunks = 1\n }\n\n let _chunkSize = 1\n let _array_type = Uint8Array\n\n switch (type) {\n // 1 byte data types\n case 'uchar':\n break\n case 'schar':\n _array_type = Int8Array\n break\n // 2 byte data types\n case 'ushort':\n _array_type = Uint16Array\n _chunkSize = 2\n break\n case 'sshort':\n _array_type = Int16Array\n _chunkSize = 2\n break\n // 4 byte data types\n case 'uint':\n _array_type = Uint32Array\n _chunkSize = 4\n break\n case 'sint':\n _array_type = Int32Array\n _chunkSize = 4\n break\n case 'float':\n _array_type = Float32Array\n _chunkSize = 4\n break\n case 'complex':\n _array_type = Float64Array\n _chunkSize = 8\n break\n case 'double':\n _array_type = Float64Array\n _chunkSize = 8\n break\n }\n\n // increase the data pointer in-place\n let _bytes = new _array_type(_data.slice(_dataPointer, (_dataPointer += chunks * _chunkSize)))\n\n // if required, flip the endianness of the bytes\n if (_nativeLittleEndian != _littleEndian) {\n // we need to flip here since the format doesn't match the native endianness\n _bytes = flipEndianness(_bytes, _chunkSize)\n }\n\n if (chunks == 1) {\n // if only one chunk was requested, just return one value\n return _bytes[0]\n }\n\n // return the byte array\n return _bytes\n }\n\n //Flips typed array endianness in-place. Based on https://github.com/kig/DataStream.js/blob/master/DataStream.js.\n\n function flipEndianness(array, chunkSize) {\n const u8 = new Uint8Array(array.buffer, array.byteOffset, array.byteLength)\n for (let i = 0; i < array.byteLength; i += chunkSize) {\n for (let j = i + chunkSize - 1, k = i; j > k; j--, k++) {\n const tmp = u8[k]\n u8[k] = u8[j]\n u8[j] = tmp\n }\n }\n\n return array\n }\n\n //parse the header\n function parseHeader(header) {\n let data, field, fn, i, l, m, _i, _len\n const lines = header.split(/\\r?\\n/)\n for (_i = 0, _len = lines.length; _i < _len; _i++) {\n l = lines[_i]\n if (l.match(/NRRD\\d+/)) {\n headerObject.isNrrd = true\n } else if (l.match(/^#/)) {\n } else if ((m = l.match(/(.*):(.*)/))) {\n field = m[1].trim()\n data = m[2].trim()\n fn = _fieldFunctions[field]\n if (fn) {\n fn.call(head