@kitware/vtk.js 33.0.0 → 33.0.1
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.
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function computeCoordShiftAndScale(points) {
|
|
2
|
+
// Find out if shift scale should be used
|
|
3
|
+
// Compute squares of diagonal size and distance from the origin
|
|
4
|
+
let diagSq = 0.0;
|
|
5
|
+
let distSq = 0.0;
|
|
6
|
+
for (let i = 0; i < 3; ++i) {
|
|
7
|
+
const range = points.getRange(i);
|
|
8
|
+
const delta = range[1] - range[0];
|
|
9
|
+
diagSq += delta * delta;
|
|
10
|
+
const distShift = 0.5 * (range[1] + range[0]);
|
|
11
|
+
distSq += distShift * distShift;
|
|
12
|
+
}
|
|
13
|
+
const useShiftAndScale = diagSq > 0 && (Math.abs(distSq) / diagSq > 1.0e6 ||
|
|
14
|
+
// If data is far from the origin relative to its size
|
|
15
|
+
Math.abs(Math.log10(diagSq)) > 3.0 ||
|
|
16
|
+
// If the size is huge when not far from the origin
|
|
17
|
+
diagSq === 0 && distSq > 1.0e6); // If data is a point, but far from the origin
|
|
18
|
+
|
|
19
|
+
if (useShiftAndScale) {
|
|
20
|
+
// Compute shift and scale vectors
|
|
21
|
+
const coordShift = new Float64Array(3);
|
|
22
|
+
const coordScale = new Float64Array(3);
|
|
23
|
+
for (let i = 0; i < 3; ++i) {
|
|
24
|
+
const range = points.getRange(i);
|
|
25
|
+
const delta = range[1] - range[0];
|
|
26
|
+
coordShift[i] = 0.5 * (range[1] + range[0]);
|
|
27
|
+
coordScale[i] = delta > 0 ? 1.0 / delta : 1.0;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
useShiftAndScale,
|
|
31
|
+
coordShift,
|
|
32
|
+
coordScale
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
useShiftAndScale,
|
|
37
|
+
coordShift: new Float32Array([0, 0, 0]),
|
|
38
|
+
coordScale: new Float32Array([1, 1, 1])
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
var helpers = {
|
|
42
|
+
computeCoordShiftAndScale
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { computeCoordShiftAndScale, helpers as default };
|
|
@@ -3,6 +3,7 @@ import { m as macro } from '../../macros2.js';
|
|
|
3
3
|
import vtkBufferObject from './BufferObject.js';
|
|
4
4
|
import { ObjectType } from './BufferObject/Constants.js';
|
|
5
5
|
import { Representation } from '../Core/Property/Constants.js';
|
|
6
|
+
import { computeCoordShiftAndScale } from './CellArrayBufferObject/helpers.js';
|
|
6
7
|
|
|
7
8
|
const {
|
|
8
9
|
vtkErrorMacro
|
|
@@ -217,32 +218,12 @@ function vtkOpenGLCellArrayBufferObject(publicAPI, model) {
|
|
|
217
218
|
let ucidx = 0;
|
|
218
219
|
|
|
219
220
|
// Find out if shift scale should be used
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const delta = range[1] - range[0];
|
|
226
|
-
diagSq += delta * delta;
|
|
227
|
-
const distShift = 0.5 * (range[1] + range[0]);
|
|
228
|
-
distSq += distShift * distShift;
|
|
229
|
-
}
|
|
230
|
-
const useShiftAndScale = diagSq > 0 && (Math.abs(distSq) / diagSq > 1.0e6 ||
|
|
231
|
-
// If data is far from the origin relative to its size
|
|
232
|
-
Math.abs(Math.log10(diagSq)) > 3.0 ||
|
|
233
|
-
// If the size is huge when not far from the origin
|
|
234
|
-
diagSq === 0 && distSq > 1.0e6); // If data is a point, but far from the origin
|
|
235
|
-
|
|
221
|
+
const {
|
|
222
|
+
useShiftAndScale,
|
|
223
|
+
coordShift,
|
|
224
|
+
coordScale
|
|
225
|
+
} = computeCoordShiftAndScale(options.points);
|
|
236
226
|
if (useShiftAndScale) {
|
|
237
|
-
// Compute shift and scale vectors
|
|
238
|
-
const coordShift = new Float64Array(3);
|
|
239
|
-
const coordScale = new Float64Array(3);
|
|
240
|
-
for (let i = 0; i < 3; ++i) {
|
|
241
|
-
const range = options.points.getRange(i);
|
|
242
|
-
const delta = range[1] - range[0];
|
|
243
|
-
coordShift[i] = 0.5 * (range[1] + range[0]);
|
|
244
|
-
coordScale[i] = delta > 0 ? 1.0 / delta : 1.0;
|
|
245
|
-
}
|
|
246
227
|
publicAPI.setCoordShiftAndScale(coordShift, coordScale);
|
|
247
228
|
} else if (model.coordShiftAndScaleEnabled === true) {
|
|
248
229
|
// Make sure to reset
|
|
@@ -8,6 +8,7 @@ import vtkOpenGLPolyDataMapper from './PolyDataMapper.js';
|
|
|
8
8
|
import { v as vtkSphereMapperVS } from './glsl/vtkSphereMapperVS.glsl.js';
|
|
9
9
|
import { v as vtkPolyDataFS } from './glsl/vtkPolyDataFS.glsl.js';
|
|
10
10
|
import { registerOverride } from './ViewNodeFactory.js';
|
|
11
|
+
import { computeCoordShiftAndScale } from './CellArrayBufferObject/helpers.js';
|
|
11
12
|
|
|
12
13
|
const {
|
|
13
14
|
vtkErrorMacro
|
|
@@ -112,14 +113,24 @@ function vtkOpenGLSphereMapper(publicAPI, model) {
|
|
|
112
113
|
if (program.isUniformUsed('VCPCMatrix')) {
|
|
113
114
|
program.setUniformMatrix('VCPCMatrix', keyMats.vcpc);
|
|
114
115
|
}
|
|
116
|
+
|
|
117
|
+
// mat4.create() defaults to Float32Array b/c of gl-matrix's settings.
|
|
118
|
+
// We need Float64Array to avoid loss of precision with large coordinates.
|
|
119
|
+
const tmp4 = new Float64Array(16);
|
|
115
120
|
if (program.isUniformUsed('MCVCMatrix')) {
|
|
116
121
|
if (!actor.getIsIdentity()) {
|
|
117
122
|
const actMats = model.openGLActor.getKeyMatrices();
|
|
118
|
-
const tmp4 = new Float64Array(16);
|
|
119
123
|
mat4.multiply(tmp4, keyMats.wcvc, actMats.mcwc);
|
|
124
|
+
if (cellBO.getCABO().getCoordShiftAndScaleEnabled()) {
|
|
125
|
+
mat4.multiply(tmp4, tmp4, cellBO.getCABO().getInverseShiftAndScaleMatrix());
|
|
126
|
+
}
|
|
120
127
|
program.setUniformMatrix('MCVCMatrix', tmp4);
|
|
121
128
|
} else {
|
|
122
|
-
|
|
129
|
+
mat4.copy(tmp4, keyMats.wcvc);
|
|
130
|
+
if (cellBO.getCABO().getCoordShiftAndScaleEnabled()) {
|
|
131
|
+
mat4.multiply(tmp4, tmp4, cellBO.getCABO().getInverseShiftAndScaleMatrix());
|
|
132
|
+
}
|
|
133
|
+
program.setUniformMatrix('MCVCMatrix', tmp4);
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
if (program.isUniformUsed('cameraParallel')) {
|
|
@@ -166,6 +177,14 @@ function vtkOpenGLSphereMapper(publicAPI, model) {
|
|
|
166
177
|
const cos30 = Math.cos(radiansFromDegrees(30.0));
|
|
167
178
|
let pointIdx = 0;
|
|
168
179
|
let colorIdx = 0;
|
|
180
|
+
const {
|
|
181
|
+
useShiftAndScale,
|
|
182
|
+
coordShift,
|
|
183
|
+
coordScale
|
|
184
|
+
} = computeCoordShiftAndScale(points);
|
|
185
|
+
if (useShiftAndScale) {
|
|
186
|
+
vbo.setCoordShiftAndScale(coordShift, coordScale);
|
|
187
|
+
}
|
|
169
188
|
|
|
170
189
|
//
|
|
171
190
|
// Generate points and point data for sides
|
|
@@ -178,9 +197,12 @@ function vtkOpenGLSphereMapper(publicAPI, model) {
|
|
|
178
197
|
radius = scales[i];
|
|
179
198
|
}
|
|
180
199
|
pointIdx = i * 3;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
200
|
+
const ptX = (pointArray[pointIdx++] - coordShift[0]) * coordScale[0];
|
|
201
|
+
const ptY = (pointArray[pointIdx++] - coordShift[1]) * coordScale[1];
|
|
202
|
+
const ptZ = (pointArray[pointIdx++] - coordShift[2]) * coordScale[2];
|
|
203
|
+
packedVBO[vboIdx++] = ptX;
|
|
204
|
+
packedVBO[vboIdx++] = ptY;
|
|
205
|
+
packedVBO[vboIdx++] = ptZ;
|
|
184
206
|
packedVBO[vboIdx++] = -2.0 * radius * cos30;
|
|
185
207
|
packedVBO[vboIdx++] = -radius;
|
|
186
208
|
if (colorData) {
|
|
@@ -190,10 +212,9 @@ function vtkOpenGLSphereMapper(publicAPI, model) {
|
|
|
190
212
|
packedUCVBO[ucIdx++] = colorData[colorIdx + 2];
|
|
191
213
|
packedUCVBO[ucIdx++] = colorData[colorIdx + 3];
|
|
192
214
|
}
|
|
193
|
-
|
|
194
|
-
packedVBO[vboIdx++] =
|
|
195
|
-
packedVBO[vboIdx++] =
|
|
196
|
-
packedVBO[vboIdx++] = pointArray[pointIdx++];
|
|
215
|
+
packedVBO[vboIdx++] = ptX;
|
|
216
|
+
packedVBO[vboIdx++] = ptY;
|
|
217
|
+
packedVBO[vboIdx++] = ptZ;
|
|
197
218
|
packedVBO[vboIdx++] = 2.0 * radius * cos30;
|
|
198
219
|
packedVBO[vboIdx++] = -radius;
|
|
199
220
|
if (colorData) {
|
|
@@ -202,10 +223,9 @@ function vtkOpenGLSphereMapper(publicAPI, model) {
|
|
|
202
223
|
packedUCVBO[ucIdx++] = colorData[colorIdx + 2];
|
|
203
224
|
packedUCVBO[ucIdx++] = colorData[colorIdx + 3];
|
|
204
225
|
}
|
|
205
|
-
|
|
206
|
-
packedVBO[vboIdx++] =
|
|
207
|
-
packedVBO[vboIdx++] =
|
|
208
|
-
packedVBO[vboIdx++] = pointArray[pointIdx++];
|
|
226
|
+
packedVBO[vboIdx++] = ptX;
|
|
227
|
+
packedVBO[vboIdx++] = ptY;
|
|
228
|
+
packedVBO[vboIdx++] = ptZ;
|
|
209
229
|
packedVBO[vboIdx++] = 0.0;
|
|
210
230
|
packedVBO[vboIdx++] = 2.0 * radius;
|
|
211
231
|
if (colorData) {
|