@kitware/vtk.js 32.3.2 → 32.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/Core/Math/index.js +12 -1
- package/Common/Core/Math.d.ts +5 -0
- package/Common/Core/Math.js +1 -1
- package/IO/Image/HDRReader/Utils.js +44 -0
- package/IO/Image/HDRReader.d.ts +121 -0
- package/IO/Image/HDRReader.js +373 -0
- package/IO/Image.js +7 -0
- package/IO/Misc/GCodeReader.d.ts +128 -0
- package/IO/Misc/GCodeReader.js +236 -0
- package/IO/Misc.js +3 -1
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
- package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
- package/Interaction/Widgets/PiecewiseGaussianWidget.js +1 -1
- package/Proxy/Core/View2DProxy.js +1 -1
- package/Rendering/Core/AbstractImageMapper.js +1 -1
- package/Rendering/Core/AbstractMapper3D.js +1 -1
- package/Rendering/Core/ColorTransferFunction/CssFilters.js +1 -1
- package/Rendering/Core/ColorTransferFunction.js +1 -1
- package/Rendering/Core/Coordinate.js +1 -1
- package/Rendering/Core/CubeAxesActor.js +1 -1
- package/Rendering/Core/Glyph3DMapper.js +1 -1
- package/Rendering/Core/ImageArrayMapper.js +1 -1
- package/Rendering/Core/ImageMapper.js +1 -1
- package/Rendering/Core/Mapper.js +1 -1
- package/Rendering/Core/Prop3D.js +1 -1
- package/Rendering/Core/RenderWindowInteractor.js +1 -1
- package/Rendering/Core/Renderer.js +1 -1
- package/Rendering/Core/ScalarBarActor.js +1 -1
- package/Rendering/Core/VolumeMapper.js +1 -1
- package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
- package/Rendering/OpenGL/Texture.js +1 -1
- package/Widgets/Representations/PolyLineRepresentation.js +1 -1
- package/Widgets/Widgets3D/AngleWidget.js +1 -1
- package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
- package/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -53,6 +53,15 @@ function createArray() {
|
|
|
53
53
|
return res;
|
|
54
54
|
}
|
|
55
55
|
const Pi = () => Math.PI;
|
|
56
|
+
function ldexp(x, exponent) {
|
|
57
|
+
if (exponent > 1023) {
|
|
58
|
+
return x * 2 ** 1023 * 2 ** (exponent - 1023);
|
|
59
|
+
}
|
|
60
|
+
if (exponent < -1074) {
|
|
61
|
+
return x * 2 ** -1074 * 2 ** (exponent + 1074);
|
|
62
|
+
}
|
|
63
|
+
return x * 2 ** exponent;
|
|
64
|
+
}
|
|
56
65
|
function radiansFromDegrees(deg) {
|
|
57
66
|
return deg / 180 * Math.PI;
|
|
58
67
|
}
|
|
@@ -2012,6 +2021,7 @@ function float2CssRGBA(rgbArray) {
|
|
|
2012
2021
|
|
|
2013
2022
|
var vtkMath = {
|
|
2014
2023
|
Pi,
|
|
2024
|
+
ldexp,
|
|
2015
2025
|
radiansFromDegrees,
|
|
2016
2026
|
degreesFromRadians,
|
|
2017
2027
|
round,
|
|
@@ -2128,6 +2138,7 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
|
|
|
2128
2138
|
__proto__: null,
|
|
2129
2139
|
createArray: createArray,
|
|
2130
2140
|
Pi: Pi,
|
|
2141
|
+
ldexp: ldexp,
|
|
2131
2142
|
radiansFromDegrees: radiansFromDegrees,
|
|
2132
2143
|
degreesFromRadians: degreesFromRadians,
|
|
2133
2144
|
round: round,
|
|
@@ -2245,4 +2256,4 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
|
|
|
2245
2256
|
'default': vtkMath
|
|
2246
2257
|
});
|
|
2247
2258
|
|
|
2248
|
-
export {
|
|
2259
|
+
export { min as $, ldexp as A, xyz2rgb as B, degreesFromRadians as C, areEquals as D, clampValue as E, arrayRange as F, getMajorAxisIndex as G, createUninitializedBounds as H, identity as I, multiplyMatrix as J, floor as K, isInf as L, rgb2hsv as M, rgb2lab as N, lab2rgb as O, round as P, normalize2D as Q, nearestPowerOfTwo as R, multiply3x3_vect3 as S, getSparseOrthogonalMatrix as T, areBoundsInitialized as U, isPowerOfTwo as V, angleBetweenVectors as W, signedAngleBetweenVectors as X, createArray as Y, Pi as Z, ceil as _, areMatricesEqual as a, floatRGB2HexCode as a$, max as a0, arrayMin as a1, arrayMax as a2, ceilLog2 as a3, factorial as a4, binomial as a5, beginCombination as a6, nextCombination as a7, randomSeed as a8, getSeed as a9, multiplyQuaternion as aA, orthogonalize3x3 as aB, diagonalize3x3 as aC, singularValueDecomposition3x3 as aD, luFactorLinearSystem as aE, luSolveLinearSystem as aF, invertMatrix as aG, estimateMatrixCondition as aH, solveHomogeneousLeastSquares as aI, solveLeastSquares as aJ, hex2float as aK, lab2xyz as aL, xyz2lab as aM, rgb2xyz as aN, computeBoundsFromPoints as aO, clampAndNormalizeValue as aP, getScalarTypeFittingRange as aQ, getAdjustedScalarRange as aR, extentIsWithinOtherExtent as aS, boundsIsWithinOtherBounds as aT, pointIsWithinBounds as aU, solve3PointCircle as aV, inf as aW, negInf as aX, isFinite as aY, isNaN as aZ, floatToHex2 as a_, gaussian as aa, multiplyScalar2D as ab, multiplyAccumulate2D as ac, outer as ad, projectVector as ae, dot2D as af, projectVector2D as ag, gaussianAmplitude as ah, gaussianWeight as ai, outer2D as aj, norm2D as ak, rowsToMat4 as al, columnsToMat4 as am, columnsToMat3 as an, LUFactor3x3 as ao, LUSolve3x3 as ap, linearSolve3x3 as aq, multiply3x3_mat3 as ar, transpose3x3 as as, invert3x3 as at, identity3x3 as au, isIdentity as av, isIdentity3x3 as aw, quaternionToMatrix3x3 as ax, roundNumber as ay, matrix3x3ToQuaternion as az, roundVector as b, float2CssRGBA as b0, clampVector as c, dot as d, distance2BetweenPoints as e, vtkMath as f, solveLinearSystem as g, hsv2rgb as h, isNan as i, cross as j, add as k, normalize as l, multiplyAccumulate as m, norm as n, determinant2x2 as o, jacobiN as p, perpendiculars as q, radiansFromDegrees as r, subtract as s, jacobi as t, uninitializeBounds as u, vtkMath$1 as v, multiplyScalar as w, random as x, determinant3x3 as y, rowsToMat3 as z };
|
package/Common/Core/Math.d.ts
CHANGED
|
@@ -51,6 +51,11 @@ export function swapColumnsMatrix_nxn(
|
|
|
51
51
|
*/
|
|
52
52
|
export function Pi(): number;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Calculates x times (2 to the power of exponent).
|
|
56
|
+
*/
|
|
57
|
+
export function ldexp(x: number, exponent: number): number;
|
|
58
|
+
|
|
54
59
|
/**
|
|
55
60
|
* Convert degrees to radians.
|
|
56
61
|
* @param {Number} deg The value in degrees.
|
package/Common/Core/Math.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'seedrandom';
|
|
2
2
|
import '../../macros2.js';
|
|
3
3
|
import './Math/Constants.js';
|
|
4
|
-
export {
|
|
4
|
+
export { ao as LUFactor3x3, ap as LUSolve3x3, Z as Pi, k as add, W as angleBetweenVectors, U as areBoundsInitialized, D as areEquals, a as areMatricesEqual, a2 as arrayMax, a1 as arrayMin, F as arrayRange, a6 as beginCombination, a5 as binomial, aT as boundsIsWithinOtherBounds, _ as ceil, a3 as ceilLog2, aP as clampAndNormalizeValue, E as clampValue, c as clampVector, an as columnsToMat3, am as columnsToMat4, aO as computeBoundsFromPoints, Y as createArray, H as createUninitializedBounds, j as cross, f as default, C as degreesFromRadians, o as determinant2x2, y as determinant3x3, aC as diagonalize3x3, e as distance2BetweenPoints, d as dot, af as dot2D, aH as estimateMatrixCondition, aS as extentIsWithinOtherExtent, a4 as factorial, b0 as float2CssRGBA, a$ as floatRGB2HexCode, a_ as floatToHex2, K as floor, aa as gaussian, ah as gaussianAmplitude, ai as gaussianWeight, aR as getAdjustedScalarRange, G as getMajorAxisIndex, aQ as getScalarTypeFittingRange, a9 as getSeed, T as getSparseOrthogonalMatrix, aK as hex2float, h as hsv2rgb, I as identity, au as identity3x3, aW as inf, at as invert3x3, aG as invertMatrix, aY as isFinite, av as isIdentity, aw as isIdentity3x3, L as isInf, aZ as isNaN, i as isNan, V as isPowerOfTwo, t as jacobi, p as jacobiN, O as lab2rgb, aL as lab2xyz, A as ldexp, aq as linearSolve3x3, aE as luFactorLinearSystem, aF as luSolveLinearSystem, az as matrix3x3ToQuaternion, a0 as max, $ as min, ar as multiply3x3_mat3, S as multiply3x3_vect3, m as multiplyAccumulate, ac as multiplyAccumulate2D, J as multiplyMatrix, aA as multiplyQuaternion, w as multiplyScalar, ab as multiplyScalar2D, R as nearestPowerOfTwo, aX as negInf, a7 as nextCombination, n as norm, ak as norm2D, l as normalize, Q as normalize2D, aB as orthogonalize3x3, ad as outer, aj as outer2D, q as perpendiculars, aU as pointIsWithinBounds, ae as projectVector, ag as projectVector2D, ax as quaternionToMatrix3x3, r as radiansFromDegrees, x as random, a8 as randomSeed, M as rgb2hsv, N as rgb2lab, aN as rgb2xyz, P as round, ay as roundNumber, b as roundVector, z as rowsToMat3, al as rowsToMat4, X as signedAngleBetweenVectors, aD as singularValueDecomposition3x3, aV as solve3PointCircle, aI as solveHomogeneousLeastSquares, aJ as solveLeastSquares, g as solveLinearSystem, s as subtract, as as transpose3x3, u as uninitializeBounds, aM as xyz2lab, B as xyz2rgb } from './Math/index.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { A as ldexp } from '../../../Common/Core/Math/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read a line from a Uint8Array
|
|
5
|
+
* @param {Uint8Array} uint8array
|
|
6
|
+
* @param {number} startIndex
|
|
7
|
+
* @returns string
|
|
8
|
+
*/
|
|
9
|
+
function readLine(uint8array, startIndex) {
|
|
10
|
+
let line = '';
|
|
11
|
+
let character = '';
|
|
12
|
+
for (let i = startIndex; i < uint8array.length - startIndex; i++) {
|
|
13
|
+
character = String.fromCharCode(uint8array[i]);
|
|
14
|
+
if (character === '\n') {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
line += character;
|
|
18
|
+
}
|
|
19
|
+
return line;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert rgbe to float
|
|
24
|
+
* @param {Array} rgbe The rgbe array
|
|
25
|
+
* @param {Array} floats The output array
|
|
26
|
+
* @param {number} exposure The exposure value
|
|
27
|
+
*/
|
|
28
|
+
function rgbe2float(rgbe, exposure) {
|
|
29
|
+
let floats = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
30
|
+
if (rgbe[3] > 0) {
|
|
31
|
+
/* nonzero pixel */
|
|
32
|
+
const f = ldexp(1.0, rgbe[3] - (128 + 8)) / exposure;
|
|
33
|
+
floats[0] = rgbe[0] * f;
|
|
34
|
+
floats[1] = rgbe[1] * f;
|
|
35
|
+
floats[2] = rgbe[2] * f;
|
|
36
|
+
} else {
|
|
37
|
+
floats[0] = 0;
|
|
38
|
+
floats[1] = 0;
|
|
39
|
+
floats[2] = 0;
|
|
40
|
+
}
|
|
41
|
+
return floats;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { readLine, rgbe2float };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { vtkAlgorithm, vtkObject } from './../../interfaces';
|
|
2
|
+
import HtmlDataAccessHelper from './../Core/DataAccessHelper/HtmlDataAccessHelper';
|
|
3
|
+
import HttpDataAccessHelper from './../Core/DataAccessHelper/HttpDataAccessHelper';
|
|
4
|
+
import JSZipDataAccessHelper from './../Core/DataAccessHelper/JSZipDataAccessHelper';
|
|
5
|
+
import LiteHttpDataAccessHelper from './../Core/DataAccessHelper/LiteHttpDataAccessHelper';
|
|
6
|
+
|
|
7
|
+
interface IHDRReaderOptions {
|
|
8
|
+
compression?: string;
|
|
9
|
+
progressCallback?: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export interface IHDRReaderInitialValues {}
|
|
16
|
+
|
|
17
|
+
type vtkHDRReaderBase = vtkObject &
|
|
18
|
+
Omit<
|
|
19
|
+
vtkAlgorithm,
|
|
20
|
+
| 'getInputData'
|
|
21
|
+
| 'setInputData'
|
|
22
|
+
| 'setInputConnection'
|
|
23
|
+
| 'getInputConnection'
|
|
24
|
+
| 'addInputConnection'
|
|
25
|
+
| 'addInputData'
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
export interface vtkHDRReader extends vtkHDRReaderBase {
|
|
29
|
+
/**
|
|
30
|
+
* Get the base url.
|
|
31
|
+
*/
|
|
32
|
+
getBaseURL(): string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the dataAccess helper.
|
|
36
|
+
*/
|
|
37
|
+
getDataAccessHelper():
|
|
38
|
+
| HtmlDataAccessHelper
|
|
39
|
+
| HttpDataAccessHelper
|
|
40
|
+
| JSZipDataAccessHelper
|
|
41
|
+
| LiteHttpDataAccessHelper;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the url of the object to load.
|
|
45
|
+
*/
|
|
46
|
+
getUrl(): string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Load the object data.
|
|
50
|
+
* @param {IHDRReaderOptions} [options]
|
|
51
|
+
*/
|
|
52
|
+
loadData(options?: IHDRReaderOptions): Promise<any>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Parse data.
|
|
56
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
57
|
+
*/
|
|
58
|
+
parse(content: ArrayBuffer): void;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse data as ArrayBuffer.
|
|
62
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
63
|
+
*/
|
|
64
|
+
parseAsArrayBuffer(content: ArrayBuffer): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param inData
|
|
69
|
+
* @param outData
|
|
70
|
+
*/
|
|
71
|
+
requestData(inData: any, outData: any): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param dataAccessHelper
|
|
76
|
+
*/
|
|
77
|
+
setDataAccessHelper(
|
|
78
|
+
dataAccessHelper:
|
|
79
|
+
| HtmlDataAccessHelper
|
|
80
|
+
| HttpDataAccessHelper
|
|
81
|
+
| JSZipDataAccessHelper
|
|
82
|
+
| LiteHttpDataAccessHelper
|
|
83
|
+
): boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Set the url of the object to load.
|
|
87
|
+
* @param {String} url the url of the object to load.
|
|
88
|
+
* @param {IHDRReaderOptions} [option] The PLY reader options.
|
|
89
|
+
*/
|
|
90
|
+
setUrl(url: string, option?: IHDRReaderOptions): Promise<string | any>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Method used to decorate a given object (publicAPI+model) with vtkHDRReader characteristics.
|
|
95
|
+
*
|
|
96
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
97
|
+
* @param model object on which data structure will be bounds (protected)
|
|
98
|
+
* @param {IHDRReaderInitialValues} [initialValues] (default: {})
|
|
99
|
+
*/
|
|
100
|
+
export function extend(
|
|
101
|
+
publicAPI: object,
|
|
102
|
+
model: object,
|
|
103
|
+
initialValues?: IHDRReaderInitialValues
|
|
104
|
+
): void;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Method used to create a new instance of vtkHDRReader
|
|
108
|
+
* @param {IHDRReaderInitialValues} [initialValues] for pre-setting some of its content
|
|
109
|
+
*/
|
|
110
|
+
export function newInstance(
|
|
111
|
+
initialValues?: IHDRReaderInitialValues
|
|
112
|
+
): vtkHDRReader;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* vtkHDRReader is a source object that reads Radiance HDR files.
|
|
116
|
+
*/
|
|
117
|
+
export declare const vtkHDRReader: {
|
|
118
|
+
newInstance: typeof newInstance;
|
|
119
|
+
extend: typeof extend;
|
|
120
|
+
};
|
|
121
|
+
export default vtkHDRReader;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import '../Core/DataAccessHelper/LiteHttpDataAccessHelper.js';
|
|
2
|
+
import { m as macro } from '../../macros2.js';
|
|
3
|
+
import DataAccessHelper from '../Core/DataAccessHelper.js';
|
|
4
|
+
import { B as xyz2rgb } from '../../Common/Core/Math/index.js';
|
|
5
|
+
import vtkImageData from '../../Common/DataModel/ImageData.js';
|
|
6
|
+
import vtkDataArray from '../../Common/Core/DataArray.js';
|
|
7
|
+
import { readLine, rgbe2float } from './HDRReader/Utils.js';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-bitwise */
|
|
10
|
+
const {
|
|
11
|
+
vtkErrorMacro
|
|
12
|
+
} = macro;
|
|
13
|
+
const FormatType = {
|
|
14
|
+
FORMAT_32BIT_RLE_RGBE: 0,
|
|
15
|
+
FORMAT_32BIT_RLE_XYZE: 1
|
|
16
|
+
};
|
|
17
|
+
const Patterns = {
|
|
18
|
+
magicToken: /^#\?(\S+)/,
|
|
19
|
+
gamma: /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
|
|
20
|
+
exposure: /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
|
|
21
|
+
format: /^\s*FORMAT=(\S+)\s*$/,
|
|
22
|
+
dimensions: /^\s*-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// ----------------------------------------------------------------------------
|
|
26
|
+
// vtkHDRReader methods
|
|
27
|
+
// ----------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
function vtkHDRReader(publicAPI, model) {
|
|
30
|
+
// Set our className
|
|
31
|
+
model.classHierarchy.push('vtkHDRReader');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Reads header information from an RGBE texture stored in a native array.
|
|
35
|
+
* More information on this format are available here:
|
|
36
|
+
* https://en.wikipedia.org/wiki/RGBE_image_format
|
|
37
|
+
*
|
|
38
|
+
* @param {Uint8Array} uint8array The binary file stored in native array.
|
|
39
|
+
* @returns The header information.
|
|
40
|
+
*/
|
|
41
|
+
function readHeader(uint8array) {
|
|
42
|
+
// RGBE format header
|
|
43
|
+
const header = {
|
|
44
|
+
valid: 0,
|
|
45
|
+
string: '',
|
|
46
|
+
comments: '',
|
|
47
|
+
programtype: 'RGBE',
|
|
48
|
+
format: '',
|
|
49
|
+
gamma: 1.0,
|
|
50
|
+
exposure: 1.0,
|
|
51
|
+
pixelAspect: 1.0,
|
|
52
|
+
width: 0,
|
|
53
|
+
height: 0,
|
|
54
|
+
dataIndex: 0
|
|
55
|
+
};
|
|
56
|
+
let match;
|
|
57
|
+
let line = readLine(uint8array, 0);
|
|
58
|
+
match = line.match(Patterns.magicToken);
|
|
59
|
+
if (!match) {
|
|
60
|
+
throw new Error('Bad HDR Format.');
|
|
61
|
+
}
|
|
62
|
+
header.programtype = match[1];
|
|
63
|
+
header.string += `${line}\n`;
|
|
64
|
+
let lineIndex = 0;
|
|
65
|
+
do {
|
|
66
|
+
lineIndex += line.length + 1;
|
|
67
|
+
line = readLine(uint8array, lineIndex);
|
|
68
|
+
header.string += `${line}\n`;
|
|
69
|
+
if (line.charAt(0) === '#') {
|
|
70
|
+
header.comments += `${line}\n`;
|
|
71
|
+
// eslint-disable-next-line no-continue
|
|
72
|
+
continue; // comment line
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
match = line.match(Patterns.gamma);
|
|
76
|
+
if (match) {
|
|
77
|
+
header.gamma = parseFloat(match[1]);
|
|
78
|
+
}
|
|
79
|
+
match = line.match(Patterns.exposure);
|
|
80
|
+
if (match) {
|
|
81
|
+
header.exposure = parseFloat(match[1]);
|
|
82
|
+
}
|
|
83
|
+
match = line.match(Patterns.format);
|
|
84
|
+
if (match) {
|
|
85
|
+
header.format = match[1];
|
|
86
|
+
}
|
|
87
|
+
} while (line.length !== 0);
|
|
88
|
+
lineIndex += line.length + 1;
|
|
89
|
+
line = readLine(uint8array, lineIndex);
|
|
90
|
+
match = line.match(Patterns.dimensions);
|
|
91
|
+
if (match) {
|
|
92
|
+
header.height = parseInt(match[1], 10);
|
|
93
|
+
header.width = parseInt(match[2], 10);
|
|
94
|
+
}
|
|
95
|
+
if (header.width < 8 || header.width > 0x7fff) {
|
|
96
|
+
vtkErrorMacro('HDR Bad header format, unsupported size');
|
|
97
|
+
}
|
|
98
|
+
lineIndex += line.length + 1;
|
|
99
|
+
header.dataIndex = lineIndex;
|
|
100
|
+
return header;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param {Uint8Array} uint8array
|
|
106
|
+
* @param {*} header
|
|
107
|
+
* @returns Float32Array
|
|
108
|
+
*/
|
|
109
|
+
function readRGBEPixelsNotRLE(uint8array, header) {
|
|
110
|
+
// this file is not run length encoded
|
|
111
|
+
// read values sequentially
|
|
112
|
+
|
|
113
|
+
let numScanlines = header.height;
|
|
114
|
+
const scanlineWidth = header.width;
|
|
115
|
+
let a;
|
|
116
|
+
let b;
|
|
117
|
+
let c;
|
|
118
|
+
let d;
|
|
119
|
+
let i;
|
|
120
|
+
let dataIndex = header.dataIndex;
|
|
121
|
+
|
|
122
|
+
// 3 channels of 4 bytes per pixel in float.
|
|
123
|
+
const resultBuffer = new ArrayBuffer(header.width * header.height * 4 * 3);
|
|
124
|
+
const resultArray = new Float32Array(resultBuffer);
|
|
125
|
+
|
|
126
|
+
// read in each successive scanline
|
|
127
|
+
while (numScanlines > 0) {
|
|
128
|
+
for (i = 0; i < header.width; i++) {
|
|
129
|
+
a = uint8array[dataIndex++];
|
|
130
|
+
b = uint8array[dataIndex++];
|
|
131
|
+
c = uint8array[dataIndex++];
|
|
132
|
+
d = uint8array[dataIndex++];
|
|
133
|
+
const offset = (numScanlines - 1) * scanlineWidth * 3 + i * 3;
|
|
134
|
+
let output = [];
|
|
135
|
+
const input = [a, b, c, d];
|
|
136
|
+
if (model.format === FormatType.FORMAT_32BIT_RLE_XYZE) {
|
|
137
|
+
// convert from XYZE to RGBE
|
|
138
|
+
xyz2rgb(input, output);
|
|
139
|
+
} else {
|
|
140
|
+
output = rgbe2float(input, model.exposure);
|
|
141
|
+
}
|
|
142
|
+
resultArray[offset] = output[0];
|
|
143
|
+
resultArray[offset + 1] = output[1];
|
|
144
|
+
resultArray[offset + 2] = output[2];
|
|
145
|
+
}
|
|
146
|
+
numScanlines--;
|
|
147
|
+
}
|
|
148
|
+
return resultArray;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @param {Uint8Array} uint8array
|
|
154
|
+
* @param {*} header
|
|
155
|
+
* @returns Float32Array
|
|
156
|
+
*/
|
|
157
|
+
function readRGBEPixelsRLE(uint8array, header) {
|
|
158
|
+
let numScanlines = header.height;
|
|
159
|
+
const scanlineWidth = header.width;
|
|
160
|
+
let a;
|
|
161
|
+
let b;
|
|
162
|
+
let c;
|
|
163
|
+
let d;
|
|
164
|
+
let count;
|
|
165
|
+
let dataIndex = header.dataIndex;
|
|
166
|
+
let index = 0;
|
|
167
|
+
let endIndex = 0;
|
|
168
|
+
let i = 0;
|
|
169
|
+
const scanLineArrayBuffer = new ArrayBuffer(scanlineWidth * 4); // four channel R G B E
|
|
170
|
+
const scanLineArray = new Uint8Array(scanLineArrayBuffer);
|
|
171
|
+
|
|
172
|
+
// 3 channels of 4 bytes per pixel in float.
|
|
173
|
+
const resultBuffer = new ArrayBuffer(header.width * header.height * 4 * 3);
|
|
174
|
+
const resultArray = new Float32Array(resultBuffer);
|
|
175
|
+
|
|
176
|
+
// read in each successive scanline
|
|
177
|
+
while (numScanlines > 0) {
|
|
178
|
+
a = uint8array[dataIndex++];
|
|
179
|
+
b = uint8array[dataIndex++];
|
|
180
|
+
c = uint8array[dataIndex++];
|
|
181
|
+
d = uint8array[dataIndex++];
|
|
182
|
+
if (a !== 2 || b !== 2 || c & 0x80 || header.width < 8 || header.width > 32767) {
|
|
183
|
+
return readRGBEPixelsNotRLE(uint8array, header);
|
|
184
|
+
}
|
|
185
|
+
if ((c << 8 | d) !== scanlineWidth) {
|
|
186
|
+
vtkErrorMacro('HDR Bad header format, wrong scan line width');
|
|
187
|
+
}
|
|
188
|
+
index = 0;
|
|
189
|
+
|
|
190
|
+
// read each of the four channels for the scanline into the buffer
|
|
191
|
+
for (i = 0; i < 4; i++) {
|
|
192
|
+
endIndex = (i + 1) * scanlineWidth;
|
|
193
|
+
while (index < endIndex) {
|
|
194
|
+
a = uint8array[dataIndex++];
|
|
195
|
+
b = uint8array[dataIndex++];
|
|
196
|
+
if (a > 128) {
|
|
197
|
+
// A run of the same value
|
|
198
|
+
count = a - 128;
|
|
199
|
+
if (count === 0 || count > endIndex - index) {
|
|
200
|
+
vtkErrorMacro('HDR Bad Format, bad scanline data (run)');
|
|
201
|
+
}
|
|
202
|
+
while (count-- > 0) {
|
|
203
|
+
scanLineArray[index++] = b;
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
// A non run
|
|
207
|
+
count = a;
|
|
208
|
+
if (count === 0 || count > endIndex - index) {
|
|
209
|
+
vtkErrorMacro('HDR Bad Format, bad scanline data (non-run)');
|
|
210
|
+
}
|
|
211
|
+
scanLineArray[index++] = b;
|
|
212
|
+
if (--count > 0) {
|
|
213
|
+
for (let j = 0; j < count; j++) {
|
|
214
|
+
scanLineArray[index++] = uint8array[dataIndex++];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// now convert data from buffer into floats
|
|
222
|
+
for (i = 0; i < scanlineWidth; i++) {
|
|
223
|
+
a = scanLineArray[i];
|
|
224
|
+
b = scanLineArray[i + scanlineWidth];
|
|
225
|
+
c = scanLineArray[i + 2 * scanlineWidth];
|
|
226
|
+
d = scanLineArray[i + 3 * scanlineWidth];
|
|
227
|
+
const offset = (numScanlines - 1) * scanlineWidth * 3 + i * 3;
|
|
228
|
+
let output = [];
|
|
229
|
+
const input = [a, b, c, d];
|
|
230
|
+
if (model.format === FormatType.FORMAT_32BIT_RLE_XYZE) {
|
|
231
|
+
// convert from XYZE to RGBE
|
|
232
|
+
xyz2rgb(input, output);
|
|
233
|
+
} else {
|
|
234
|
+
output = rgbe2float(input, model.exposure);
|
|
235
|
+
}
|
|
236
|
+
resultArray[offset] = output[0];
|
|
237
|
+
resultArray[offset + 1] = output[1];
|
|
238
|
+
resultArray[offset + 2] = output[2];
|
|
239
|
+
}
|
|
240
|
+
numScanlines--;
|
|
241
|
+
}
|
|
242
|
+
return resultArray;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Create default dataAccessHelper if not available
|
|
246
|
+
if (!model.dataAccessHelper) {
|
|
247
|
+
model.dataAccessHelper = DataAccessHelper.get('http');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Internal method to fetch Array
|
|
251
|
+
function fetchData(url) {
|
|
252
|
+
const {
|
|
253
|
+
compression,
|
|
254
|
+
progressCallback
|
|
255
|
+
} = model;
|
|
256
|
+
return model.dataAccessHelper.fetchBinary(url, {
|
|
257
|
+
compression,
|
|
258
|
+
progressCallback
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Set DataSet url
|
|
263
|
+
publicAPI.setUrl = function (url) {
|
|
264
|
+
let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
265
|
+
binary: true
|
|
266
|
+
};
|
|
267
|
+
model.url = url;
|
|
268
|
+
|
|
269
|
+
// Remove the file in the URL
|
|
270
|
+
const path = url.split('/');
|
|
271
|
+
path.pop();
|
|
272
|
+
model.baseURL = path.join('/');
|
|
273
|
+
model.compression = option.compression;
|
|
274
|
+
|
|
275
|
+
// Fetch metadata
|
|
276
|
+
return publicAPI.loadData({
|
|
277
|
+
progressCallback: option.progressCallback
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Fetch the actual data arrays
|
|
282
|
+
publicAPI.loadData = function () {
|
|
283
|
+
const promise = fetchData(model.url);
|
|
284
|
+
promise.then(publicAPI.parse);
|
|
285
|
+
return promise;
|
|
286
|
+
};
|
|
287
|
+
publicAPI.parse = content => {
|
|
288
|
+
publicAPI.parseAsArrayBuffer(content);
|
|
289
|
+
};
|
|
290
|
+
publicAPI.parseAsArrayBuffer = content => {
|
|
291
|
+
if (!content) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
model.parseData = content;
|
|
295
|
+
const data = new Uint8Array(model.parseData);
|
|
296
|
+
const header = readHeader(data);
|
|
297
|
+
if (header.format === '32-bit_rle_rgbe') {
|
|
298
|
+
model.format = FormatType.FORMAT_32BIT_RLE_RGBE;
|
|
299
|
+
} else if (header.format === '32-bit_rle_xyze') {
|
|
300
|
+
model.format = FormatType.FORMAT_32BIT_RLE_XYZE;
|
|
301
|
+
}
|
|
302
|
+
model.gamma = header.gamma;
|
|
303
|
+
model.exposure = header.exposure;
|
|
304
|
+
model.pixelAspect = header.pixelAspect;
|
|
305
|
+
const output = readRGBEPixelsRLE(data, header);
|
|
306
|
+
const dataExtent = [0, header.width - 1, 0, header.height - 1];
|
|
307
|
+
const dataSpacing = [1, header.pixelAspect, 1];
|
|
308
|
+
const imageData = vtkImageData.newInstance();
|
|
309
|
+
imageData.setDimensions(header.width, header.height, 1);
|
|
310
|
+
imageData.setExtent(dataExtent);
|
|
311
|
+
imageData.setSpacing(dataSpacing);
|
|
312
|
+
const dataArray = vtkDataArray.newInstance({
|
|
313
|
+
name: 'HDRImage',
|
|
314
|
+
numberOfComponents: 3,
|
|
315
|
+
values: output
|
|
316
|
+
});
|
|
317
|
+
imageData.getPointData().setScalars(dataArray);
|
|
318
|
+
model.output[0] = imageData;
|
|
319
|
+
};
|
|
320
|
+
publicAPI.requestData = (inData, outData) => {
|
|
321
|
+
publicAPI.parse(model.parseData);
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// ----------------------------------------------------------------------------
|
|
326
|
+
// Object factory
|
|
327
|
+
// ----------------------------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
const DEFAULT_VALUES = {
|
|
330
|
+
gamma: 1.0,
|
|
331
|
+
exposure: 1.0,
|
|
332
|
+
pixelAspect: 1.0,
|
|
333
|
+
format: FormatType.FORMAT_32BIT_RLE_RGBE
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// ----------------------------------------------------------------------------
|
|
337
|
+
|
|
338
|
+
function extend(publicAPI, model) {
|
|
339
|
+
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
340
|
+
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
341
|
+
|
|
342
|
+
// Make this a VTK object
|
|
343
|
+
macro.obj(publicAPI, model);
|
|
344
|
+
|
|
345
|
+
// Also make it an algorithm with one input and one output
|
|
346
|
+
macro.algo(publicAPI, model, 0, 1);
|
|
347
|
+
macro.get(publicAPI, model, ['gamma', 'exposure', 'pixelAspect', 'url', 'baseURL']);
|
|
348
|
+
macro.setGet(publicAPI, model, ['dataAccessHelper']);
|
|
349
|
+
|
|
350
|
+
// Object specific methods
|
|
351
|
+
vtkHDRReader(publicAPI, model);
|
|
352
|
+
|
|
353
|
+
// To support destructuring
|
|
354
|
+
if (!model.compression) {
|
|
355
|
+
model.compression = null;
|
|
356
|
+
}
|
|
357
|
+
if (!model.progressCallback) {
|
|
358
|
+
model.progressCallback = null;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ----------------------------------------------------------------------------
|
|
363
|
+
|
|
364
|
+
const newInstance = macro.newInstance(extend, 'vtkHDRReader');
|
|
365
|
+
|
|
366
|
+
// ----------------------------------------------------------------------------
|
|
367
|
+
|
|
368
|
+
var vtkHDRReader$1 = {
|
|
369
|
+
newInstance,
|
|
370
|
+
extend
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export { vtkHDRReader$1 as default, extend, newInstance };
|