1 line
20 KiB
Plaintext
1 line
20 KiB
Plaintext
|
|
{"version":3,"file":"Volume.cjs","sources":["../../src/misc/Volume.js"],"sourcesContent":["import { Matrix3, Matrix4, Vector3 } from 'three'\nimport { VolumeSlice } from '../misc/VolumeSlice'\n\n/**\n * This class had been written to handle the output of the NRRD loader.\n * It contains a volume of data and informations about it.\n * For now it only handles 3 dimensional data.\n * See the webgl_loader_nrrd.html example and the loaderNRRD.js file to see how to use this class.\n * @class\n * @param {number} xLength Width of the volume\n * @param {number} yLength Length of the volume\n * @param {number} zLength Depth of the volume\n * @param {string} type The type of data (uint8, uint16, ...)\n * @param {ArrayBuffer} arrayBuffer The buffer with volume data\n */\nclass Volume {\n constructor(xLength, yLength, zLength, type, arrayBuffer) {\n if (xLength !== undefined) {\n /**\n * @member {number} xLength Width of the volume in the IJK coordinate system\n */\n this.xLength = Number(xLength) || 1\n /**\n * @member {number} yLength Height of the volume in the IJK coordinate system\n */\n this.yLength = Number(yLength) || 1\n /**\n * @member {number} zLength Depth of the volume in the IJK coordinate system\n */\n this.zLength = Number(zLength) || 1\n /**\n * @member {Array<string>} The order of the Axis dictated by the NRRD header\n */\n this.axisOrder = ['x', 'y', 'z']\n /**\n * @member {TypedArray} data Data of the volume\n */\n\n switch (type) {\n case 'Uint8':\n case 'uint8':\n case 'uchar':\n case 'unsigned char':\n case 'uint8_t':\n this.data = new Uint8Array(arrayBuffer)\n break\n case 'Int8':\n case 'int8':\n case 'signed char':\n case 'int8_t':\n this.data = new Int8Array(arrayBuffer)\n break\n case 'Int16':\n case 'int16':\n case 'short':\n case 'short int':\n case 'signed short':\n case 'signed short int':\n case 'int16_t':\n this.data = new Int16Array(arrayBuffer)\n break\n case 'Uint16':\n case 'uint16':\n case 'ushort':\n case 'unsigned short':\n case 'unsigned short int':\n case 'uint16_t':\n this.data = new Uint16Array(arrayBuffer)\n break\n case 'Int32':\n case 'int32':\n case 'int':\n case 'signed int':\n case 'int32_t':\n this.data = new Int32Array(arrayBuffer)\n break\n case 'Uint32':\n case 'uint32':\n case 'uint':\n case 'unsigned int':\n case 'uint32_t':\n this.data = new Uint32Array(arrayBuffer)\n break\n case 'longlong':\n case 'long long':\n case 'long long int':\n case 'signed long long':\n case 'signed long long int':\n case 'int64':\n case 'int64_t':\n case 'ulonglong':\n case 'unsigned long long':\n case 'unsigned long long int':\n case 'uint64':\n case 'uint64_t':\n throw new Error('Error in Volume constructor : this type is not supported in JavaScript')\n break\n case 'Float32':\n case 'float32':\n case 'float':\n this.data = new Float32Array(arrayBuffer)\n break\n case 'Float64':\n case 'float64':\n case 'double':\n this.data = new Float64Array(arrayBuffer)\n break\n default:\n this.data = new Uint8Array(arrayBuffer)\n }\n\n if (this.data.length !== this.xLength * this.yLength * this.zLength) {\n throw new Error('Error in Volume constructor, lengths are not matching arrayBuffer size')\n }\n }\n\n /**\n * @member {Array} spacing Spacing to apply to the volume from IJK to RAS coordinate system\n */\n this.spacing = [1, 1, 1]\n /**\n * @member {A
|