@kitware/vtk.js 24.5.4 → 24.5.5
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 +1 -1
- package/Common/Core/Math.js +1 -1
- package/Common/DataModel/Triangle.js +1 -1
- package/Common/Transform/LandmarkTransform.js +1 -1
- package/Filters/Core/PolyDataNormals.js +1 -1
- package/Filters/General/OBBTree.js +1 -1
- package/Filters/General/WindowedSincPolyDataFilter.js +1 -1
- package/Filters/Sources/CircleSource.js +1 -1
- package/Filters/Sources/PointSource.js +1 -1
- package/Filters/Texture/TextureMapToPlane.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
- package/Interaction/Manipulators/MouseCameraUnicamManipulator.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/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/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/Rendering/WebGPU/BufferManager.js +83 -14
- package/Rendering/WebGPU/CellArrayMapper.js +6 -44
- package/Rendering/WebGPU/Device.js +97 -57
- package/Rendering/WebGPU/Glyph3DMapper.js +2 -0
- package/Rendering/WebGPU/ImageMapper.js +1 -5
- package/Rendering/WebGPU/SphereMapper.js +29 -31
- package/Rendering/WebGPU/StickMapper.js +38 -42
- package/Rendering/WebGPU/StorageBuffer.js +0 -1
- package/Rendering/WebGPU/Texture.js +0 -2
- package/Rendering/WebGPU/TextureManager.js +37 -7
- package/Rendering/WebGPU/UniformBuffer.js +0 -1
- package/Rendering/WebGPU/VolumePass.js +1 -3
- package/Rendering/WebGPU/VolumePassFSQ.js +1 -5
- package/Widgets/Manipulators/LineManipulator.js +1 -1
- package/Widgets/Representations/PolyLineRepresentation.js +1 -1
- package/Widgets/Representations/ResliceCursorContextRepresentation.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/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +1 -1
- package/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,83 @@
|
|
|
1
|
+
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
5
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
6
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
7
|
+
import _get from '@babel/runtime/helpers/get';
|
|
8
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
9
|
+
import _wrapNativeSuper from '@babel/runtime/helpers/wrapNativeSuper';
|
|
1
10
|
import { newInstance as newInstance$1, obj, setGet, get } from '../../macros.js';
|
|
2
11
|
import vtkWebGPUBufferManager from './BufferManager.js';
|
|
3
12
|
import vtkWebGPUShaderCache from './ShaderCache.js';
|
|
4
13
|
import vtkWebGPUTextureManager from './TextureManager.js';
|
|
5
14
|
|
|
15
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
|
+
|
|
17
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
|
+
/**
|
|
19
|
+
* provide a simple WeakRefMap class to share device objects based on
|
|
20
|
+
* hash values so that buffers/textures etc can be shared betwen mappers.
|
|
21
|
+
* This is roughly based on WeakLRUCache but without the actual caching
|
|
22
|
+
* behavior. This is just a map of key -> WeakRef(value)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/* eslint-disable no-undef */
|
|
26
|
+
|
|
27
|
+
var WeakRefMap = /*#__PURE__*/function (_Map) {
|
|
28
|
+
_inherits(WeakRefMap, _Map);
|
|
29
|
+
|
|
30
|
+
var _super = _createSuper(WeakRefMap);
|
|
31
|
+
|
|
32
|
+
function WeakRefMap() {
|
|
33
|
+
var _thisSuper, _thisSuper2, _this;
|
|
34
|
+
|
|
35
|
+
_classCallCheck(this, WeakRefMap);
|
|
36
|
+
|
|
37
|
+
_this = _super.call(this);
|
|
38
|
+
_this.registry = new FinalizationRegistry(function (key) {
|
|
39
|
+
var entry = _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(WeakRefMap.prototype)), "get", _thisSuper).call(_thisSuper, key);
|
|
40
|
+
|
|
41
|
+
if (entry && entry.deref && entry.deref() === undefined) _get((_thisSuper2 = _assertThisInitialized(_this), _getPrototypeOf(WeakRefMap.prototype)), "delete", _thisSuper2).call(_thisSuper2, key);
|
|
42
|
+
});
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_createClass(WeakRefMap, [{
|
|
47
|
+
key: "getValue",
|
|
48
|
+
value: function getValue(key) {
|
|
49
|
+
var entry = _get(_getPrototypeOf(WeakRefMap.prototype), "get", this).call(this, key);
|
|
50
|
+
|
|
51
|
+
if (entry) {
|
|
52
|
+
var value = entry.deref();
|
|
53
|
+
if (value !== undefined) return value;
|
|
54
|
+
|
|
55
|
+
_get(_getPrototypeOf(WeakRefMap.prototype), "delete", this).call(this, key);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "setValue",
|
|
62
|
+
value: function setValue(key, value) {
|
|
63
|
+
var entry;
|
|
64
|
+
|
|
65
|
+
if (value && _typeof(value) === 'object') {
|
|
66
|
+
entry = new WeakRef(value);
|
|
67
|
+
this.registry.register(value, key);
|
|
68
|
+
|
|
69
|
+
_get(_getPrototypeOf(WeakRefMap.prototype), "set", this).call(this, key, entry);
|
|
70
|
+
} // else entry is undefined
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
return entry;
|
|
74
|
+
}
|
|
75
|
+
}]);
|
|
76
|
+
|
|
77
|
+
return WeakRefMap;
|
|
78
|
+
}( /*#__PURE__*/_wrapNativeSuper(Map));
|
|
79
|
+
/* eslint-enable no-undef */
|
|
80
|
+
// ----------------------------------------------------------------------------
|
|
6
81
|
// vtkWebGPUDevice methods
|
|
7
82
|
// ----------------------------------------------------------------------------
|
|
8
83
|
|
|
@@ -92,72 +167,34 @@ function vtkWebGPUDevice(publicAPI, model) {
|
|
|
92
167
|
}; // The Device has an object cache that can be used to cache buffers,
|
|
93
168
|
// textures and other objects that can be shared. The basic approach is to
|
|
94
169
|
// call getCachedObject with a request and a create function. The request
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// returns any entry that has a matching owner and hash. If a match isn't
|
|
99
|
-
// found then the create function is called with any extra arguments.
|
|
100
|
-
//
|
|
101
|
-
// For best memory management it is important that the owner be as close
|
|
102
|
-
// to the underlying object as possible. For example for a point data buffer
|
|
103
|
-
// you would want the actual vtkDataArray to be the owner, not the polydata
|
|
104
|
-
// or even worse the actor. As the points data array could be freed wihtout
|
|
105
|
-
// the polydata or actor being freed.
|
|
170
|
+
// is based on a hash. The cache lookup just returns any entry that has a
|
|
171
|
+
// matching hash. If a match isn't found then the create function is
|
|
172
|
+
// called with any extra arguments.
|
|
106
173
|
// is the object already cached?
|
|
107
174
|
|
|
108
175
|
|
|
109
|
-
publicAPI.hasCachedObject = function (
|
|
110
|
-
|
|
111
|
-
return false;
|
|
112
|
-
} // if a matching request already exists then return true
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (model.objectCache.has(owner)) {
|
|
116
|
-
var objects = model.objectCache.get(owner);
|
|
117
|
-
|
|
118
|
-
for (var i = 0; i < objects.length; i++) {
|
|
119
|
-
if (hash === objects[i].hash) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return false;
|
|
176
|
+
publicAPI.hasCachedObject = function (hash) {
|
|
177
|
+
return model.objectCache.getValue(hash);
|
|
126
178
|
};
|
|
127
179
|
|
|
128
|
-
publicAPI.getCachedObject = function (
|
|
129
|
-
if (!
|
|
130
|
-
vtkErrorMacro('attempt to cache an object without
|
|
180
|
+
publicAPI.getCachedObject = function (hash, creator) {
|
|
181
|
+
if (!hash) {
|
|
182
|
+
vtkErrorMacro('attempt to cache an object without a hash');
|
|
131
183
|
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (model.objectCache.has(owner)) {
|
|
136
|
-
var _objects = model.objectCache.get(owner);
|
|
137
|
-
|
|
138
|
-
for (var i = 0; i < _objects.length; i++) {
|
|
139
|
-
if (hash === _objects[i].hash) {
|
|
140
|
-
return _objects[i].object;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
} // otherwise create the object and cache it
|
|
184
|
+
}
|
|
144
185
|
|
|
186
|
+
var existingValue = model.objectCache.getValue(hash);
|
|
145
187
|
|
|
146
|
-
|
|
147
|
-
|
|
188
|
+
if (existingValue) {
|
|
189
|
+
return existingValue;
|
|
148
190
|
}
|
|
149
191
|
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
if (!model.objectCache.has(owner)) {
|
|
153
|
-
model.objectCache.set(owner, []);
|
|
192
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
193
|
+
args[_key - 2] = arguments[_key];
|
|
154
194
|
}
|
|
155
195
|
|
|
156
|
-
var
|
|
157
|
-
|
|
158
|
-
hash: hash,
|
|
159
|
-
object: createdObject
|
|
160
|
-
});
|
|
196
|
+
var createdObject = creator.apply(void 0, args);
|
|
197
|
+
model.objectCache.setValue(hash, createdObject);
|
|
161
198
|
return createdObject;
|
|
162
199
|
};
|
|
163
200
|
} // ----------------------------------------------------------------------------
|
|
@@ -180,9 +217,12 @@ function extend(publicAPI, model) {
|
|
|
180
217
|
|
|
181
218
|
obj(publicAPI, model);
|
|
182
219
|
setGet(publicAPI, model, ['handle']);
|
|
183
|
-
get(publicAPI, model, ['bufferManager', 'shaderCache', 'textureManager']); // this is a
|
|
220
|
+
get(publicAPI, model, ['bufferManager', 'shaderCache', 'textureManager']); // this is a weak ref cache implementation, we create it without
|
|
221
|
+
// an expirer (so it is strictly based on garbage collection and
|
|
222
|
+
// objects are not held if there are no external references)
|
|
223
|
+
// model.objectCache = new WeakLRUCache({ expirer: false });
|
|
184
224
|
|
|
185
|
-
model.objectCache = new
|
|
225
|
+
model.objectCache = new WeakRefMap();
|
|
186
226
|
model.shaderCache = vtkWebGPUShaderCache.newInstance();
|
|
187
227
|
model.shaderCache.setDevice(publicAPI);
|
|
188
228
|
model.bindGroupLayouts = [];
|
|
@@ -203,4 +243,4 @@ var vtkWebGPUDevice$1 = {
|
|
|
203
243
|
extend: extend
|
|
204
244
|
};
|
|
205
245
|
|
|
206
|
-
export { vtkWebGPUDevice$1 as default, extend, newInstance };
|
|
246
|
+
export { WeakRefMap, vtkWebGPUDevice$1 as default, extend, newInstance };
|
|
@@ -102,6 +102,8 @@ function vtkWebGPUGlyph3DMapper(publicAPI, model) {
|
|
|
102
102
|
|
|
103
103
|
publicAPI.buildPass = function (prepass) {
|
|
104
104
|
if (prepass) {
|
|
105
|
+
model.WebGPUActor = publicAPI.getFirstAncestorOfType('vtkWebGPUActor');
|
|
106
|
+
|
|
105
107
|
if (!model.renderable.getStatic()) {
|
|
106
108
|
model.renderable.update();
|
|
107
109
|
}
|
|
@@ -265,11 +265,7 @@ function vtkWebGPUImageMapper(publicAPI, model) {
|
|
|
265
265
|
|
|
266
266
|
publicAPI.updateBuffers = function () {
|
|
267
267
|
superClassUpdateBuffers();
|
|
268
|
-
var
|
|
269
|
-
imageData: model.currentInput,
|
|
270
|
-
owner: model.currentInput.getPointData().getScalars()
|
|
271
|
-
};
|
|
272
|
-
var newTex = model.device.getTextureManager().getTexture(treq);
|
|
268
|
+
var newTex = model.device.getTextureManager().getTextureForImageData(model.currentInput);
|
|
273
269
|
var tViews = model.textureViews;
|
|
274
270
|
|
|
275
271
|
if (!tViews[0] || tViews[0].getTexture() !== newTex) {
|
|
@@ -74,16 +74,15 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
74
74
|
publicAPI.setNumberOfInstances(1);
|
|
75
75
|
publicAPI.setNumberOfVertices(3 * numPoints);
|
|
76
76
|
var vertexInput = model.vertexInput;
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// xyz v1 v2 v3
|
|
77
|
+
var hash = "spm".concat(points.getMTime(), "float32x3");
|
|
78
|
+
|
|
79
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
80
|
+
var buffRequest = {
|
|
81
|
+
hash: hash,
|
|
82
|
+
usage: BufferUsage.RawVertex,
|
|
83
|
+
format: 'float32x3'
|
|
84
|
+
}; // xyz v1 v2 v3
|
|
85
|
+
|
|
87
86
|
var tmpVBO = new Float32Array(3 * numPoints * 3);
|
|
88
87
|
var pointIdx = 0;
|
|
89
88
|
var vboIdx = 0;
|
|
@@ -117,15 +116,15 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
117
116
|
var defaultRadius = model.renderable.getRadius();
|
|
118
117
|
|
|
119
118
|
if (scales || defaultRadius !== model._lastRadius) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
hash = "spm".concat(scales ? pointData.getArray(model.renderable.getScaleArray()).getMTime() : defaultRadius, "float32x2");
|
|
120
|
+
|
|
121
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
122
|
+
var _buffRequest = {
|
|
123
|
+
hash: hash,
|
|
124
|
+
usage: BufferUsage.RawVertex,
|
|
125
|
+
format: 'float32x2'
|
|
126
|
+
};
|
|
127
127
|
|
|
128
|
-
if (!model.device.getBufferManager().hasBuffer(buffRequest)) {
|
|
129
128
|
var _tmpVBO = new Float32Array(3 * numPoints * 2);
|
|
130
129
|
|
|
131
130
|
var cos30 = Math.cos(radiansFromDegrees(30.0));
|
|
@@ -146,9 +145,9 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
146
145
|
_tmpVBO[_vboIdx++] = 2.0 * radius;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
|
|
148
|
+
_buffRequest.nativeArray = _tmpVBO;
|
|
150
149
|
|
|
151
|
-
var _buff = model.device.getBufferManager().getBuffer(
|
|
150
|
+
var _buff = model.device.getBufferManager().getBuffer(_buffRequest);
|
|
152
151
|
|
|
153
152
|
vertexInput.addBuffer(_buff, ['offsetMC']);
|
|
154
153
|
}
|
|
@@ -163,15 +162,14 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
163
162
|
var c = model.renderable.getColorMapColors();
|
|
164
163
|
|
|
165
164
|
if (c) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (!model.device.getBufferManager().hasBuffer(buffRequest)) {
|
|
165
|
+
hash = "spm".concat(c.getMTime(), "unorm8x4");
|
|
166
|
+
|
|
167
|
+
if (!model.device.getBufferManager().hasBuffer(hash)) {
|
|
168
|
+
var _buffRequest2 = {
|
|
169
|
+
hash: hash,
|
|
170
|
+
usage: BufferUsage.RawVertex,
|
|
171
|
+
format: 'unorm8x4'
|
|
172
|
+
};
|
|
175
173
|
var colorComponents = c.getNumberOfComponents();
|
|
176
174
|
|
|
177
175
|
if (colorComponents !== 4) {
|
|
@@ -194,9 +192,9 @@ function vtkWebGPUSphereMapper(publicAPI, model) {
|
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
|
|
195
|
+
_buffRequest2.nativeArray = _tmpVBO2;
|
|
198
196
|
|
|
199
|
-
var _buff2 = model.device.getBufferManager().getBuffer(
|
|
197
|
+
var _buff2 = model.device.getBufferManager().getBuffer(_buffRequest2);
|
|
200
198
|
|
|
201
199
|
vertexInput.addBuffer(_buff2, ['colorVI']);
|
|
202
200
|
}
|
|
@@ -59,7 +59,7 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
59
59
|
vDesc.addBuiltinInput('u32', '@builtin(vertex_index) vertexIndex');
|
|
60
60
|
var fDesc = pipeline.getShaderDescription('fragment');
|
|
61
61
|
fDesc.addBuiltinOutput('f32', '@builtin(frag_depth) fragDepth');
|
|
62
|
-
var stickFrag = "\n // compute the eye position and unit direction\n var vertexVC: vec4<f32>;\n var EyePos: vec3<f32>;\n var EyeDir: vec3<f32>;\n\n if (rendererUBO.cameraParallel != 0u)\n {\n EyePos = vec3<f32>(input.vertexVC.x, input.vertexVC.y, input.vertexVC.z + 3.0*input.radiusVC);\n EyeDir = vec3<f32>(0.0, 0.0, -1.0);\n }\n else\n {\n EyeDir = input.vertexVC.xyz;\n EyePos = vec3<f32>(0.0,0.0,0.0);\n var lengthED: f32 = length(EyeDir);\n EyeDir = normalize(EyeDir);\n // we adjust the EyePos to be closer if it is too far away\n // to prevent floating point precision noise\n if (lengthED > input.radiusVC*3.0)\n {\n EyePos = input.vertexVC.xyz - EyeDir*3.0*input.radiusVC;\n }\n }\n // translate to Sphere center\n EyePos = EyePos - input.centerVC;\n\n // rotate to new basis\n // base1, base2, orientVC\n var base1: vec3<f32>;\n if (abs(input.orientVC.z) < 0.99)\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,0.0,1.0)));\n }\n else\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,1.0,0.0)));\n }\n var base2: vec3<f32> = cross(input.orientVC,base1);\n EyePos = vec3<f32>(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,input.orientVC));\n EyeDir = vec3<f32>(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,input.orientVC));\n\n // scale to radius 1.0\n EyePos = EyePos * (1.0 / input.radiusVC);\n\n // find the intersection\n var a: f32 = EyeDir.x*EyeDir.x + EyeDir.y*EyeDir.y;\n var b: f32 = 2.0*(EyePos.x*EyeDir.x + EyePos.y*EyeDir.y);\n var c: f32 = EyePos.x*EyePos.x + EyePos.y*EyePos.y - 1.0;\n var d: f32 = b*b - 4.0*a*c;\n var normal: vec3<f32> = vec3<f32>(0.0,0.0,1.0);\n if (d < 0.0) { discard; }\n else\n {\n var t: f32 = (-b - sqrt(d))*(0.5 / a);\n var tz: f32 = EyePos.z + t*EyeDir.z;\n var iPoint: vec3<f32> = EyePos + t*EyeDir;\n if (abs(iPoint.z)*input.radiusVC > input.lengthVC*0.5)\n {\n // test for end cap\n var t2: f32 = (-b + sqrt(d))*(0.5 / a);\n var tz2: f32 = EyePos.z + t2*EyeDir.z;\n if (tz2*input.radiusVC > input.lengthVC*0.5 || tz*input.radiusVC < -0.5*input.lengthVC) { discard; }\n else\n {\n normal = input.orientVC;\n var t3: f32 = (input.lengthVC*0.5/input.radiusVC - EyePos.z)/EyeDir.z;\n iPoint = EyePos + t3*EyeDir;\n vertexVC = vec4<f32>(input.radiusVC*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n else\n {\n // The normal is the iPoint.xy rotated back into VC\n normal = iPoint.x*base1 + iPoint.y*base2;\n // rescale rerotate and translate\n vertexVC = vec4<f32>(input.radiusVC*(normal + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n
|
|
62
|
+
var stickFrag = "\n // compute the eye position and unit direction\n var vertexVC: vec4<f32>;\n var EyePos: vec3<f32>;\n var EyeDir: vec3<f32>;\n\n if (rendererUBO.cameraParallel != 0u)\n {\n EyePos = vec3<f32>(input.vertexVC.x, input.vertexVC.y, input.vertexVC.z + 3.0*input.radiusVC);\n EyeDir = vec3<f32>(0.0, 0.0, -1.0);\n }\n else\n {\n EyeDir = input.vertexVC.xyz;\n EyePos = vec3<f32>(0.0,0.0,0.0);\n var lengthED: f32 = length(EyeDir);\n EyeDir = normalize(EyeDir);\n // we adjust the EyePos to be closer if it is too far away\n // to prevent floating point precision noise\n if (lengthED > input.radiusVC*3.0)\n {\n EyePos = input.vertexVC.xyz - EyeDir*3.0*input.radiusVC;\n }\n }\n // translate to Sphere center\n EyePos = EyePos - input.centerVC;\n\n // rotate to new basis\n // base1, base2, orientVC\n var base1: vec3<f32>;\n if (abs(input.orientVC.z) < 0.99)\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,0.0,1.0)));\n }\n else\n {\n base1 = normalize(cross(input.orientVC,vec3<f32>(0.0,1.0,0.0)));\n }\n var base2: vec3<f32> = cross(input.orientVC,base1);\n EyePos = vec3<f32>(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,input.orientVC));\n EyeDir = vec3<f32>(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,input.orientVC));\n\n // scale to radius 1.0\n EyePos = EyePos * (1.0 / input.radiusVC);\n\n // find the intersection\n var a: f32 = EyeDir.x*EyeDir.x + EyeDir.y*EyeDir.y;\n var b: f32 = 2.0*(EyePos.x*EyeDir.x + EyePos.y*EyeDir.y);\n var c: f32 = EyePos.x*EyePos.x + EyePos.y*EyePos.y - 1.0;\n var d: f32 = b*b - 4.0*a*c;\n var normal: vec3<f32> = vec3<f32>(0.0,0.0,1.0);\n if (d < 0.0) { discard; }\n else\n {\n var t: f32 = (-b - sqrt(d))*(0.5 / a);\n var tz: f32 = EyePos.z + t*EyeDir.z;\n var iPoint: vec3<f32> = EyePos + t*EyeDir;\n if (abs(iPoint.z)*input.radiusVC > input.lengthVC*0.5)\n {\n // test for end cap\n var t2: f32 = (-b + sqrt(d))*(0.5 / a);\n var tz2: f32 = EyePos.z + t2*EyeDir.z;\n if (tz2*input.radiusVC > input.lengthVC*0.5 || tz*input.radiusVC < -0.5*input.lengthVC) { discard; }\n else\n {\n normal = input.orientVC;\n var t3: f32 = (input.lengthVC*0.5/input.radiusVC - EyePos.z)/EyeDir.z;\n iPoint = EyePos + t3*EyeDir;\n vertexVC = vec4<f32>(input.radiusVC*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n else\n {\n // The normal is the iPoint.xy rotated back into VC\n normal = iPoint.x*base1 + iPoint.y*base2;\n // rescale rerotate and translate\n vertexVC = vec4<f32>(input.radiusVC*(normal + iPoint.z*input.orientVC) + input.centerVC, 1.0);\n }\n }\n // compute the pixel's depth\n var pos: vec4<f32> = rendererUBO.VCPCMatrix * vertexVC;\n output.fragDepth = pos.z / pos.w;\n ";
|
|
63
63
|
var code = fDesc.getCode();
|
|
64
64
|
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Normal::Impl', [stickFrag]).result;
|
|
65
65
|
fDesc.setCode(code);
|
|
@@ -97,16 +97,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
97
97
|
publicAPI.setNumberOfInstances(numPoints);
|
|
98
98
|
publicAPI.setNumberOfVertices(12);
|
|
99
99
|
var vertexInput = model.vertexInput;
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// xyz v1 v2 v3
|
|
100
|
+
var hash = "stm".concat(points.getMTime(), "float32x3");
|
|
101
|
+
|
|
102
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
103
|
+
var buffRequest = {
|
|
104
|
+
hash: hash,
|
|
105
|
+
usage: BufferUsage.RawVertex,
|
|
106
|
+
format: 'float32x3'
|
|
107
|
+
}; // xyz v1 v2 v3
|
|
108
|
+
|
|
110
109
|
var tmpVBO = new Float32Array(numPoints * 3);
|
|
111
110
|
var pointIdx = 0;
|
|
112
111
|
var vboIdx = 0;
|
|
@@ -133,15 +132,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
133
132
|
var defaultRadius = model.renderable.getRadius();
|
|
134
133
|
|
|
135
134
|
if (scales || defaultRadius !== model._lastRadius) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
hash = "stm".concat(scales ? pointData.getArray(model.renderable.getScaleArray()).getMTime() : defaultRadius, "float32");
|
|
136
|
+
|
|
137
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
138
|
+
var _buffRequest = {
|
|
139
|
+
hash: hash,
|
|
140
|
+
usage: BufferUsage.RawVertex,
|
|
141
|
+
format: 'float32'
|
|
142
|
+
};
|
|
143
143
|
|
|
144
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
145
144
|
var _tmpVBO = new Float32Array(numPoints);
|
|
146
145
|
|
|
147
146
|
var _vboIdx = 0;
|
|
@@ -156,9 +155,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
156
155
|
_tmpVBO[_vboIdx++] = radius;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
_buffRequest.nativeArray = _tmpVBO;
|
|
160
159
|
|
|
161
|
-
var _buff = device.getBufferManager().getBuffer(
|
|
160
|
+
var _buff = device.getBufferManager().getBuffer(_buffRequest);
|
|
162
161
|
|
|
163
162
|
vertexInput.addBuffer(_buff, ['radiusMC'], 'instance');
|
|
164
163
|
}
|
|
@@ -174,16 +173,15 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
174
173
|
vtkErrorMacro(['Error setting orientationArray.\n', 'You have to specify the stick orientation']);
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
hash = "stm".concat(pointData.getArray(model.renderable.getOrientationArray()).getMTime(), "float32x3");
|
|
177
|
+
|
|
178
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
179
|
+
var _buffRequest2 = {
|
|
180
|
+
hash: hash,
|
|
181
|
+
usage: BufferUsage.RawVertex,
|
|
182
|
+
format: 'float32x3'
|
|
183
|
+
}; // xyz v1 v2 v3
|
|
184
184
|
|
|
185
|
-
if (!device.getBufferManager().hasBuffer(buffRequest)) {
|
|
186
|
-
// xyz v1 v2 v3
|
|
187
185
|
var _tmpVBO2 = new Float32Array(numPoints * 3);
|
|
188
186
|
|
|
189
187
|
var _pointIdx = 0;
|
|
@@ -202,9 +200,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
202
200
|
_tmpVBO2[_vboIdx2++] = orientationArray[_pointIdx + 2] * length;
|
|
203
201
|
}
|
|
204
202
|
|
|
205
|
-
|
|
203
|
+
_buffRequest2.nativeArray = _tmpVBO2;
|
|
206
204
|
|
|
207
|
-
var _buff2 = device.getBufferManager().getBuffer(
|
|
205
|
+
var _buff2 = device.getBufferManager().getBuffer(_buffRequest2);
|
|
208
206
|
|
|
209
207
|
vertexInput.addBuffer(_buff2, ['orientMC'], 'instance');
|
|
210
208
|
} // deal with colors but only if modified
|
|
@@ -216,15 +214,13 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
216
214
|
var c = model.renderable.getColorMapColors();
|
|
217
215
|
|
|
218
216
|
if (c) {
|
|
219
|
-
|
|
220
|
-
owner: c,
|
|
221
|
-
hash: 'stm',
|
|
222
|
-
time: c.getMTime(),
|
|
223
|
-
usage: BufferUsage.RawVertex,
|
|
224
|
-
format: 'unorm8x4'
|
|
225
|
-
};
|
|
217
|
+
hash = "stm".concat(c.getMTime(), "unorm8x4");
|
|
226
218
|
|
|
227
|
-
if (!device.getBufferManager().hasBuffer(
|
|
219
|
+
if (!device.getBufferManager().hasBuffer(hash)) {
|
|
220
|
+
var _buffRequest3 = {
|
|
221
|
+
usage: BufferUsage.RawVertex,
|
|
222
|
+
format: 'unorm8x4'
|
|
223
|
+
};
|
|
228
224
|
var colorComponents = c.getNumberOfComponents();
|
|
229
225
|
|
|
230
226
|
if (colorComponents !== 4) {
|
|
@@ -244,9 +240,9 @@ function vtkWebGPUStickMapper(publicAPI, model) {
|
|
|
244
240
|
_tmpVBO3[_vboIdx3++] = colorData[colorIdx + 3];
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
|
|
243
|
+
_buffRequest3.nativeArray = _tmpVBO3;
|
|
248
244
|
|
|
249
|
-
var _buff3 = device.getBufferManager().getBuffer(
|
|
245
|
+
var _buff3 = device.getBufferManager().getBuffer(_buffRequest3);
|
|
250
246
|
|
|
251
247
|
vertexInput.addBuffer(_buff3, ['colorVI'], 'instance');
|
|
252
248
|
}
|
|
@@ -95,7 +95,6 @@ function vtkWebGPUTexture(publicAPI, model) {
|
|
|
95
95
|
|
|
96
96
|
if (req.dataArray) {
|
|
97
97
|
buffRequest.dataArray = req.dataArray;
|
|
98
|
-
buffRequest.time = req.dataArray.getMTime();
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
buffRequest.nativeArray = req.nativeArray; // bytesPerRow must be a multiple of 256 so we might need to rebuild
|
|
@@ -144,7 +143,6 @@ function vtkWebGPUTexture(publicAPI, model) {
|
|
|
144
143
|
|
|
145
144
|
var _buffRequest = {
|
|
146
145
|
nativeArray: imageData.data,
|
|
147
|
-
time: 0,
|
|
148
146
|
|
|
149
147
|
/* eslint-disable no-undef */
|
|
150
148
|
usage: BufferUsage.Texture,
|
|
@@ -119,17 +119,47 @@ function vtkWebGPUTextureManager(publicAPI, model) {
|
|
|
119
119
|
|
|
120
120
|
publicAPI.getTexture = function (req) {
|
|
121
121
|
// if we have a source the get/create/cache the texture
|
|
122
|
-
if (req.
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var hash = req.time + req.format;
|
|
128
|
-
return model.device.getCachedObject(req.owner, hash, _createTexture, req);
|
|
122
|
+
if (req.hash) {
|
|
123
|
+
// if a matching texture already exists then return it
|
|
124
|
+
return model.device.getCachedObject(req.hash, _createTexture, req);
|
|
129
125
|
}
|
|
130
126
|
|
|
131
127
|
return _createTexture(req);
|
|
132
128
|
};
|
|
129
|
+
|
|
130
|
+
publicAPI.getTextureForImageData = function (imgData) {
|
|
131
|
+
var treq = {
|
|
132
|
+
time: imgData.getMTime()
|
|
133
|
+
};
|
|
134
|
+
treq.imageData = imgData; // fill out the req time and format based on imageData/image
|
|
135
|
+
|
|
136
|
+
_fillRequest(treq);
|
|
137
|
+
|
|
138
|
+
treq.hash = treq.time + treq.format;
|
|
139
|
+
return model.device.getTextureManager().getTexture(treq);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
publicAPI.getTextureForVTKTexture = function (srcTexture) {
|
|
143
|
+
var treq = {
|
|
144
|
+
time: srcTexture.getMTime()
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (srcTexture.getInputData()) {
|
|
148
|
+
treq.imageData = srcTexture.getInputData();
|
|
149
|
+
} else if (srcTexture.getImage()) {
|
|
150
|
+
treq.image = srcTexture.getImage();
|
|
151
|
+
} else if (srcTexture.getJsImageData()) {
|
|
152
|
+
treq.jsImageData = srcTexture.getJsImageData();
|
|
153
|
+
} else if (srcTexture.getCanvas()) {
|
|
154
|
+
treq.canvas = srcTexture.getCanvas();
|
|
155
|
+
} // fill out the req time and format based on imageData/image
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
_fillRequest(treq);
|
|
159
|
+
|
|
160
|
+
treq.hash = treq.time + treq.format;
|
|
161
|
+
return model.device.getTextureManager().getTexture(treq);
|
|
162
|
+
};
|
|
133
163
|
} // ----------------------------------------------------------------------------
|
|
134
164
|
// Object factory
|
|
135
165
|
// ----------------------------------------------------------------------------
|
|
@@ -260,11 +260,9 @@ function vtkWebGPUVolumePass(publicAPI, model) {
|
|
|
260
260
|
|
|
261
261
|
var points = pd.getPoints();
|
|
262
262
|
var buffRequest = {
|
|
263
|
-
owner: points,
|
|
264
263
|
usage: BufferUsage.PointArray,
|
|
265
264
|
format: 'float32x4',
|
|
266
|
-
|
|
267
|
-
hash: 'vp',
|
|
265
|
+
hash: "vp".concat(points.getMTime()).concat(cells.getMTime()),
|
|
268
266
|
dataArray: points,
|
|
269
267
|
cells: cells,
|
|
270
268
|
primitiveType: PrimitiveTypes.Triangles,
|
|
@@ -455,11 +455,7 @@ function vtkWebGPUVolumePassFSQ(publicAPI, model) {
|
|
|
455
455
|
|
|
456
456
|
var image = _volMapr4.getInputData();
|
|
457
457
|
|
|
458
|
-
var
|
|
459
|
-
imageData: image,
|
|
460
|
-
owner: image.getPointData().getScalars()
|
|
461
|
-
};
|
|
462
|
-
var newTex = model.device.getTextureManager().getTexture(treq);
|
|
458
|
+
var newTex = model.device.getTextureManager().getTextureForImageData(image);
|
|
463
459
|
|
|
464
460
|
if (!model.textureViews[vidx + 4] || model.textureViews[vidx + 4].getTexture() !== newTex) {
|
|
465
461
|
var tview = newTex.createView("volTexture".concat(vidx));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import macro from '../../macros.js';
|
|
2
|
-
import { g as subtract, j as cross, d as dot,
|
|
2
|
+
import { g as subtract, j as cross, d as dot, x as multiplyScalar, k as add } from '../../Common/Core/Math/index.js';
|
|
3
3
|
|
|
4
4
|
function projectDisplayToLine(x, y, lineOrigin, lineDirection, renderer, glRenderWindow) {
|
|
5
5
|
var near = glRenderWindow.displayToWorld(x, y, 0, renderer);
|
|
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
3
|
import vtkActor from '../../Rendering/Core/Actor.js';
|
|
4
4
|
import vtkMapper from '../../Rendering/Core/Mapper.js';
|
|
5
|
-
import {
|
|
5
|
+
import { B as areEquals, f as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
|
|
6
6
|
import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
|
|
7
7
|
import vtkPolyData from '../../Common/DataModel/PolyData.js';
|
|
8
8
|
import vtkTubeFilter from '../../Filters/General/TubeFilter.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
2
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
3
3
|
import macro from '../../macros.js';
|
|
4
|
-
import { g as subtract,
|
|
4
|
+
import { g as subtract, m as multiplyAccumulate, l as normalize, j as cross } from '../../Common/Core/Math/index.js';
|
|
5
5
|
import vtkActor from '../../Rendering/Core/Actor.js';
|
|
6
6
|
import vtkCylinderSource from '../../Filters/Sources/CylinderSource.js';
|
|
7
7
|
import vtkMapper from '../../Rendering/Core/Mapper.js';
|
|
@@ -3,7 +3,7 @@ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
|
|
|
3
3
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
4
4
|
import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
|
|
5
5
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
6
|
-
import { g as subtract,
|
|
6
|
+
import { g as subtract, R as angleBetweenVectors } from '../../Common/Core/Math/index.js';
|
|
7
7
|
import widgetBehavior from './AngleWidget/behavior.js';
|
|
8
8
|
import generateState from './AngleWidget/state.js';
|
|
9
9
|
import { ViewTypes } from '../Core/WidgetManager/Constants.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as subtract,
|
|
1
|
+
import { g as subtract, x as multiplyScalar, k as add, B as areEquals } from '../../../Common/Core/Math/index.js';
|
|
2
2
|
|
|
3
3
|
function calculateTextPosition(model) {
|
|
4
4
|
var vector = [0, 0, 0];
|
|
@@ -3,7 +3,7 @@ import macro from '../../../macros.js';
|
|
|
3
3
|
import vtkBoundingBox from '../../../Common/DataModel/BoundingBox.js';
|
|
4
4
|
import vtkLine from '../../../Common/DataModel/Line.js';
|
|
5
5
|
import vtkPlanePointManipulator from '../../Manipulators/PlaneManipulator.js';
|
|
6
|
-
import {
|
|
6
|
+
import { x as multiplyScalar, g as subtract, l as normalize, d as dot, j as cross, m as multiplyAccumulate, S as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
|
|
7
7
|
import { updateState, getAssociatedLinesName, boundPointOnPlane, rotateVector } from './helpers.js';
|
|
8
8
|
import { InteractionMethodsName, ScrollingMethods } from './Constants.js';
|
|
9
9
|
|