@kitware/vtk.js 27.5.0 → 28.0.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/BREAKING_CHANGES.md +4 -0
- package/Common/DataModel/Line.d.ts +24 -2
- package/Common/DataModel/Line.js +17 -1
- package/Common/DataModel/PolyLine.d.ts +36 -2
- package/Common/DataModel/PolyLine.js +80 -10
- package/Common/Transform/Transform.d.ts +177 -0
- package/Common/Transform/Transform.js +81 -3
- package/Proxy/Core/View2DProxy.js +22 -12
- package/Rendering/Core/AbstractMapper3D.d.ts +1 -3
- package/Rendering/Core/AbstractMapper3D.js +21 -45
- package/Rendering/Core/ImageCPRMapper.d.ts +380 -0
- package/Rendering/Core/ImageCPRMapper.js +361 -0
- package/Rendering/OpenGL/ImageCPRMapper.js +919 -0
- package/Rendering/OpenGL/Profiles/All.js +1 -0
- package/Rendering/OpenGL/Profiles/Volume.js +1 -0
- package/Rendering/Profiles/All.js +1 -0
- package/Rendering/Profiles/Volume.js +1 -0
- package/Widgets/Core/WidgetManager.js +1 -1
- package/Widgets/Manipulators/AbstractManipulator.d.ts +2 -2
- package/Widgets/Manipulators/CPRManipulator.js +138 -0
- package/Widgets/Manipulators/LineManipulator.js +3 -1
- package/Widgets/Manipulators/PlaneManipulator.js +3 -1
- package/Widgets/Manipulators/TrackballManipulator.js +3 -1
- package/Widgets/Widgets3D/AngleWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/DistanceWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +3 -3
- package/Widgets/Widgets3D/ImplicitPlaneWidget.js +3 -1
- package/Widgets/Widgets3D/LabelWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/LineWidget/behavior.js +4 -2
- package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -1
- package/Widgets/Widgets3D/PolyLineWidget/behavior.js +2 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +2 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +72 -34
- package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +92 -0
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +64 -18
- package/Widgets/Widgets3D/ResliceCursorWidget/state.js +30 -16
- package/Widgets/Widgets3D/ResliceCursorWidget.js +43 -20
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +4 -2
- package/Widgets/Widgets3D/SphereWidget/behavior.js +1 -1
- package/Widgets/Widgets3D/SplineWidget/behavior.js +3 -1
- package/index.d.ts +2 -0
- package/package.json +1 -1
package/BREAKING_CHANGES.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## From 26.x to 27
|
|
2
|
+
|
|
3
|
+
- Change all `handleEvent` signatures of manipulators. Used to be `handleEvent(callData, glRenderWindow): vec3`, it is now `handleEvent(callData, glRenderWindow): { worldCoords: Nullable<vec3>, worldDirection?: mat3 }`.
|
|
4
|
+
|
|
1
5
|
## From 25.x to 26
|
|
2
6
|
|
|
3
7
|
- **ResliceCursorWidget**: vtkResliceCursorContextRepresentation is deprecated and removed.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { quat } from 'gl-matrix';
|
|
2
|
+
import { Vector3, Vector2, Nullable } from './../../types';
|
|
2
3
|
import vtkCell from './Cell';
|
|
3
4
|
|
|
4
5
|
export enum IntersectionState {
|
|
@@ -7,7 +8,9 @@ export enum IntersectionState {
|
|
|
7
8
|
ON_LINE,
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
interface ILineInitialValues {
|
|
11
|
+
export interface ILineInitialValues {
|
|
12
|
+
orientations: Nullable<quat[]>;
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
export interface IIntersectWithLine {
|
|
13
16
|
intersect: number;
|
|
@@ -29,6 +32,18 @@ export interface vtkLine extends vtkCell {
|
|
|
29
32
|
*/
|
|
30
33
|
getCellDimension(): number;
|
|
31
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Get the list of orientations (a list of quat) for each point of the line.
|
|
37
|
+
* Can be null if the line is not oriented
|
|
38
|
+
*/
|
|
39
|
+
getOrientations(): Nullable<quat[]>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @see getOrientations
|
|
43
|
+
* @param orientations The list of orientation per point of the centerline
|
|
44
|
+
*/
|
|
45
|
+
setOrientations(orientations: Nullable<quat[]>): boolean;
|
|
46
|
+
|
|
32
47
|
/**
|
|
33
48
|
* Compute the intersection point of the intersection between line and line
|
|
34
49
|
* defined by p1 and p2. tol Tolerance use for the position evaluation x is
|
|
@@ -55,6 +70,13 @@ export interface vtkLine extends vtkCell {
|
|
|
55
70
|
* Determine the global coordinates `x' and parametric coordinates `pcoords' in the cell.
|
|
56
71
|
*/
|
|
57
72
|
evaluateLocation(pcoords: Vector3, x: Vector3, weights: Vector2): void
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Determine the global orientation `q' and parametric coordinates `pcoords' in the cell.
|
|
76
|
+
* Use slerp to interpolate orientation
|
|
77
|
+
* Returns wether the orientation has been set in `q'
|
|
78
|
+
*/
|
|
79
|
+
evaluateOrientation(pcoords: Vector3, q: quat, weights: Vector2): boolean
|
|
58
80
|
}
|
|
59
81
|
|
|
60
82
|
/**
|
package/Common/DataModel/Line.js
CHANGED
|
@@ -3,6 +3,7 @@ import macro from '../../macros.js';
|
|
|
3
3
|
import Constants from './Line/Constants.js';
|
|
4
4
|
import vtkCell from './Cell.js';
|
|
5
5
|
import { d as dot, e as distance2BetweenPoints, s as subtract, g as solveLinearSystem } from '../Core/Math/index.js';
|
|
6
|
+
import { quat } from 'gl-matrix';
|
|
6
7
|
|
|
7
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
9
|
|
|
@@ -242,17 +243,32 @@ function vtkLine(publicAPI, model) {
|
|
|
242
243
|
weights[0] = 1.0 - pcoords[0];
|
|
243
244
|
weights[1] = pcoords[0];
|
|
244
245
|
};
|
|
246
|
+
|
|
247
|
+
publicAPI.evaluateOrientation = function (pcoords, q, weights) {
|
|
248
|
+
if (model.orientations) {
|
|
249
|
+
quat.slerp(q, model.orientations[0], model.orientations[1], pcoords[0]);
|
|
250
|
+
weights[0] = 1.0 - pcoords[0];
|
|
251
|
+
weights[1] = pcoords[0];
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return false;
|
|
256
|
+
};
|
|
245
257
|
} // ----------------------------------------------------------------------------
|
|
246
258
|
// Object factory
|
|
247
259
|
// ----------------------------------------------------------------------------
|
|
248
260
|
|
|
249
261
|
|
|
250
|
-
var DEFAULT_VALUES = {
|
|
262
|
+
var DEFAULT_VALUES = {
|
|
263
|
+
orientations: null // an array of two quat or null
|
|
264
|
+
|
|
265
|
+
}; // ----------------------------------------------------------------------------
|
|
251
266
|
|
|
252
267
|
function extend(publicAPI, model) {
|
|
253
268
|
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
254
269
|
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
255
270
|
vtkCell.extend(publicAPI, model, initialValues);
|
|
271
|
+
macro.setGet(publicAPI, model, ['orientations']);
|
|
256
272
|
vtkLine(publicAPI, model);
|
|
257
273
|
} // ----------------------------------------------------------------------------
|
|
258
274
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { quat } from 'gl-matrix';
|
|
1
2
|
import { Vector2, Vector3 } from './../../types';
|
|
2
3
|
import vtkCell, { ICellInitialValues } from './Cell';
|
|
3
4
|
import { IIntersectWithLine } from './Line';
|
|
@@ -24,8 +25,8 @@ export interface vtkPolyLine extends vtkCell {
|
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* Determine global coordinate (x[3]) from subId and parametric coordinates.
|
|
27
|
-
* Also
|
|
28
|
-
* the
|
|
28
|
+
* Also set interpolation weights. (There are two weights for the two
|
|
29
|
+
* points of the line segment specified by subId)
|
|
29
30
|
*
|
|
30
31
|
* @param {number} subId
|
|
31
32
|
* @param {Vector3} pcoords The parametric coordinates
|
|
@@ -33,6 +34,39 @@ export interface vtkPolyLine extends vtkCell {
|
|
|
33
34
|
* @param {Vector2} weights The interpolation weights
|
|
34
35
|
*/
|
|
35
36
|
evaluateLocation(subId: number, pcoords: Vector3, x: Vector3, weights: Vector2): void
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Determine global orientation (q[3]) from subId and parametric coordinates.
|
|
40
|
+
* This uses the same algorithm as vtkLine (interpolates using slerp).
|
|
41
|
+
* Also set interpolation weights. (There are two weights for the two
|
|
42
|
+
* points of the line segment specified by subId)
|
|
43
|
+
*
|
|
44
|
+
* @param {number} subId
|
|
45
|
+
* @param {Vector3} pcoords The parametric coordinates
|
|
46
|
+
* @param {Vector3} q The global orientation
|
|
47
|
+
* @param {Vector2} weights The interpolation weights
|
|
48
|
+
* @returns {boolean} Wether the orientation has been set in `q'
|
|
49
|
+
*/
|
|
50
|
+
evaluateOrientation(subId: number, pcoords: Vector3, q: quat, weights: Vector2): boolean
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns an array containing for each pointIdx between 0 (included) and
|
|
54
|
+
* numberOfPoints (excluded) the distance from the first point of the
|
|
55
|
+
* polyline to the point at pointIdx
|
|
56
|
+
* In particular if tda = publicAPI.getDistancesToFirstPoint(), then tda[0] = 0
|
|
57
|
+
* and tda[tda.length - 1] is the total length of the polyline
|
|
58
|
+
*/
|
|
59
|
+
getDistancesToFirstPoint(): number[]
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the subId of the segment at the given distance from the first
|
|
63
|
+
* point of the polyline
|
|
64
|
+
* If the distance is negative or greater than the total length of the
|
|
65
|
+
* polyline, returns -1
|
|
66
|
+
*
|
|
67
|
+
* @param distance The distance from the first point of the polyline
|
|
68
|
+
*/
|
|
69
|
+
findPointIdAtDistanceFromFirstPoint(distance: number): number;
|
|
36
70
|
}
|
|
37
71
|
|
|
38
72
|
/**
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
1
|
import macro from '../../macros.js';
|
|
3
2
|
import vtkCell from './Cell.js';
|
|
4
3
|
import vtkLine from './Line.js';
|
|
5
|
-
|
|
6
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
-
|
|
8
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
import { vec3 } from 'gl-matrix';
|
|
9
5
|
|
|
10
6
|
function vtkPolyLine(publicAPI, model) {
|
|
11
7
|
model.classHierarchy.push('vtkPolyLine');
|
|
12
|
-
|
|
13
|
-
var superClass = _objectSpread({}, publicAPI);
|
|
14
|
-
|
|
15
8
|
var line = vtkLine.newInstance();
|
|
16
9
|
line.getPoints().setNumberOfPoints(2);
|
|
17
10
|
|
|
@@ -26,7 +19,7 @@ function vtkPolyLine(publicAPI, model) {
|
|
|
26
19
|
subId: 0,
|
|
27
20
|
betweenPoints: null
|
|
28
21
|
};
|
|
29
|
-
var numLines =
|
|
22
|
+
var numLines = publicAPI.getNumberOfPoints() - 1;
|
|
30
23
|
var pDistMin = Number.MAX_VALUE;
|
|
31
24
|
|
|
32
25
|
for (var subId = 0; subId < numLines; subId++) {
|
|
@@ -53,17 +46,94 @@ function vtkPolyLine(publicAPI, model) {
|
|
|
53
46
|
line.getPoints().getData().set(model.points.getData().subarray(3 * subId, 3 * (subId + 2)));
|
|
54
47
|
return line.evaluateLocation(pcoords, x, weights);
|
|
55
48
|
};
|
|
49
|
+
|
|
50
|
+
publicAPI.evaluateOrientation = function (subId, pcoords, q, weights) {
|
|
51
|
+
if (model.orientations) {
|
|
52
|
+
line.setOrientations([model.orientations[subId], model.orientations[subId + 1]]);
|
|
53
|
+
} else {
|
|
54
|
+
line.setOrientations(null);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return line.evaluateOrientation(pcoords, q, weights);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
publicAPI.getDistancesToFirstPoint = function () {
|
|
61
|
+
if (model.distancesTime.getMTime() < model.points.getMTime()) {
|
|
62
|
+
var numPoints = publicAPI.getNumberOfPoints();
|
|
63
|
+
|
|
64
|
+
if (!model.distances) {
|
|
65
|
+
model.distances = new Array(numPoints);
|
|
66
|
+
} else {
|
|
67
|
+
model.distances.length = numPoints;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (numPoints > 0) {
|
|
71
|
+
var previousPoint = new Array(3);
|
|
72
|
+
var currentPoint = new Array(3);
|
|
73
|
+
var totalDistance = 0;
|
|
74
|
+
model.distances[0] = totalDistance;
|
|
75
|
+
model.points.getPoint(0, previousPoint);
|
|
76
|
+
|
|
77
|
+
for (var i = 1; i < numPoints; ++i) {
|
|
78
|
+
model.points.getPoint(i, currentPoint);
|
|
79
|
+
totalDistance += vec3.dist(previousPoint, currentPoint);
|
|
80
|
+
model.distances[i] = totalDistance;
|
|
81
|
+
vec3.copy(previousPoint, currentPoint);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
model.distancesTime.modified();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return model.distances;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
publicAPI.findPointIdAtDistanceFromFirstPoint = function (distance) {
|
|
92
|
+
var distances = publicAPI.getDistancesToFirstPoint(); // At least two points to return an ID
|
|
93
|
+
|
|
94
|
+
if (distances.length < 2) {
|
|
95
|
+
return -1;
|
|
96
|
+
} // Binary search in the distance array
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var minId = 0;
|
|
100
|
+
var maxId = distances.length - 1;
|
|
101
|
+
|
|
102
|
+
if (distance < distances[minId] || distance > distances[maxId] || distances[maxId] === 0) {
|
|
103
|
+
return -1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
while (maxId - minId > 1) {
|
|
107
|
+
var midId = Math.floor((minId + maxId) / 2);
|
|
108
|
+
|
|
109
|
+
if (distances[midId] <= distance) {
|
|
110
|
+
minId = midId;
|
|
111
|
+
} else {
|
|
112
|
+
maxId = midId;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return minId;
|
|
117
|
+
};
|
|
56
118
|
} // ----------------------------------------------------------------------------
|
|
57
119
|
// Object factory
|
|
58
120
|
// ----------------------------------------------------------------------------
|
|
59
121
|
|
|
60
122
|
|
|
61
|
-
var DEFAULT_VALUES = {
|
|
123
|
+
var DEFAULT_VALUES = {
|
|
124
|
+
orientations: null // an array of quat or null
|
|
125
|
+
|
|
126
|
+
}; // ----------------------------------------------------------------------------
|
|
62
127
|
|
|
63
128
|
function extend(publicAPI, model) {
|
|
64
129
|
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
65
130
|
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
66
131
|
vtkCell.extend(publicAPI, model, initialValues);
|
|
132
|
+
macro.setGet(publicAPI, model, ['orientations']);
|
|
133
|
+
model.distancesTime = {};
|
|
134
|
+
macro.obj(model.distancesTime, {
|
|
135
|
+
mtime: 0
|
|
136
|
+
});
|
|
67
137
|
vtkPolyLine(publicAPI, model);
|
|
68
138
|
} // ----------------------------------------------------------------------------
|
|
69
139
|
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { mat4, vec3 } from 'gl-matrix';
|
|
2
|
+
import { vtkObject } from './../../interfaces';
|
|
3
|
+
import { TypedArray } from './../../types';
|
|
4
|
+
|
|
5
|
+
export interface ITransformInitialValues {
|
|
6
|
+
preMultiplyFlag?: boolean;
|
|
7
|
+
matrix?: number[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type TSlicableArray = number[] | TypedArray;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export interface vtkTransform extends vtkObject {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Mat4 matrix, used by vtkTransform to transform points, vertices, matrices...
|
|
17
|
+
* Default is identity.
|
|
18
|
+
*/
|
|
19
|
+
getMatrix(): mat4;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @see getMatrix
|
|
23
|
+
* @param {mat4} matrix
|
|
24
|
+
*/
|
|
25
|
+
setMatrix(matrix: mat4): boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @see getMatrix
|
|
29
|
+
* Matrix is stored using gl-matrix conventions: column major
|
|
30
|
+
* @param e00
|
|
31
|
+
* @param e01
|
|
32
|
+
* @param e02
|
|
33
|
+
* @param e03
|
|
34
|
+
* @param e10
|
|
35
|
+
* @param e11
|
|
36
|
+
* @param e12
|
|
37
|
+
* @param e13
|
|
38
|
+
* @param e20
|
|
39
|
+
* @param e21
|
|
40
|
+
* @param e22
|
|
41
|
+
* @param e23
|
|
42
|
+
* @param e30
|
|
43
|
+
* @param e31
|
|
44
|
+
* @param e32
|
|
45
|
+
* @param e33
|
|
46
|
+
*/
|
|
47
|
+
setMatrix(e00: number, e01: number, e02: number, e03: number, e10: number, e11: number, e12: number, e13: number, e20: number, e21: number, e22: number, e23: number, e30: number, e31: number, e32: number, e33: number): boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The value of preMultiplyFlag indicates how matrix multiplications should occur.
|
|
51
|
+
*
|
|
52
|
+
* When in premultiply mode:
|
|
53
|
+
* All subsequent operations will occur before those already represented in the current transformation.
|
|
54
|
+
* In homogeneous matrix notation, M = M*A where M is the current transformation matrix and A is the applied matrix.
|
|
55
|
+
*
|
|
56
|
+
* When in postmultiply mode:
|
|
57
|
+
* All subsequent operations will occur after those already represented in the current transformation.
|
|
58
|
+
* In homogeneous matrix notation, M = A*M where M is the current transformation matrix and A is the applied matrix.
|
|
59
|
+
*
|
|
60
|
+
* This flag is also used in @see transformMatrix and @see transformMatrices to indicate how transform is applied to matrices:
|
|
61
|
+
* Premultiply: O_i = M * A_i
|
|
62
|
+
* Postmultiply: O_i = A_i * M
|
|
63
|
+
* where M is the current transformation matrix, A_i are the matrices in argument, O_i are the output matrices.
|
|
64
|
+
*
|
|
65
|
+
* The default is PreMultiply.
|
|
66
|
+
*/
|
|
67
|
+
getPreMultiplyFlag(): boolean;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @see getPreMultiplyFlag
|
|
71
|
+
* @param preMultiplyFlag
|
|
72
|
+
*/
|
|
73
|
+
setPreMultiplyFlag(preMultiplyFlag: boolean): boolean;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Set preMultiplyFlag to true
|
|
77
|
+
* @see getPreMultiplyFlag
|
|
78
|
+
*/
|
|
79
|
+
preMultiply(): void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set preMultiplyFlag to false
|
|
83
|
+
* @see getPreMultiplyFlag
|
|
84
|
+
*/
|
|
85
|
+
postMultiply(): void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Transform a single point using the internal transform matrix
|
|
89
|
+
* The resulting point is: Pout = M * Pin where M is the internal matrix, Pin and Pout the in and out points
|
|
90
|
+
* @param point The point to transform, is not modified (except if point === out)
|
|
91
|
+
* @param out The receiving output point, is modified, can be the same as point
|
|
92
|
+
* @returns The out parameter
|
|
93
|
+
*/
|
|
94
|
+
transformPoint(point: vec3, out: vec3): vec3;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Transform multiple points using the internal transform matrix
|
|
98
|
+
* See @see transformPoint for more info
|
|
99
|
+
* Modify the out array only
|
|
100
|
+
* @param points An array (typed or not) containing n*3 elements or of shape (n, 3)
|
|
101
|
+
* @param out An array (typed or not) containing n*3 elements or of shape (n, 3)
|
|
102
|
+
*/
|
|
103
|
+
transformPoints(points: TSlicableArray, out: TSlicableArray): TSlicableArray;
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Transform a single matrix using the internal transform matrix
|
|
108
|
+
* The resulting matrix is:
|
|
109
|
+
* Mout = M * Min when in premultiply mode
|
|
110
|
+
* Mout = Min * M when in postmultiply mode
|
|
111
|
+
* @param matrix The matrix to transform, is not modified (except if matrix === out)
|
|
112
|
+
* @param out The receiving output matrix, is modified, can be the same as matrix
|
|
113
|
+
* @returns The out parameter
|
|
114
|
+
*/
|
|
115
|
+
transformMatrix(matrix: mat4, out: mat4): mat4;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Transform multiple matrices using the internal transform matrix
|
|
119
|
+
* See @see transformMatrix for more info
|
|
120
|
+
* Modify the out array only
|
|
121
|
+
* @param matrices An array (typed or not) containing n*16 elements or of shape (n, 16)
|
|
122
|
+
* @param out An array (typed or not) containing n*16 elements or of shape (n, 16)
|
|
123
|
+
*/
|
|
124
|
+
transformMatrices(matrices: TSlicableArray, out: TSlicableArray): TSlicableArray;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @returns A new transform with an inversed internal matrix. Also copy the premultiply flag @see getPreMultiplyFlag.
|
|
128
|
+
*/
|
|
129
|
+
getInverse(): vtkTransform;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Method used to decorate a given object (publicAPI+model) with vtkTransform characteristics.
|
|
134
|
+
*
|
|
135
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
136
|
+
* @param model object on which data structure will be bounds (protected)
|
|
137
|
+
* @param {ITransformInitialValues} [initialValues] (default: {})
|
|
138
|
+
*/
|
|
139
|
+
export function extend(publicAPI: object, model: object, initialValues?: ITransformInitialValues): void;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Method used to create a new instance of vtkTransform.
|
|
143
|
+
* @param {ITransformInitialValues} [initialValues] for pre-setting some of its content
|
|
144
|
+
*/
|
|
145
|
+
export function newInstance(initialValues?: ITransformInitialValues): vtkTransform;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* vtkTransform describes linear transformations via a 4x4 matrix.
|
|
150
|
+
*
|
|
151
|
+
* A vtkTransform can be used to describe the full range of linear (also known as affine) coordinate transformations in three dimensions, which are internally represented as a 4x4 homogeneous transformation matrix. When you create a new vtkTransform, it is always initialized to the identity transformation.
|
|
152
|
+
*
|
|
153
|
+
* Most of the methods for manipulating this transformation (e.g. transformMatrices, transformMatrix) (TODO: Translate, Rotate, Concatenate...) can operate in either PreMultiply (the default) or PostMultiply mode. In PreMultiply mode, the translation, concatenation, etc. will occur before any transformations which are represented by the current matrix. In PostMultiply mode, the additional transformation will occur after any transformations represented by the current matrix.
|
|
154
|
+
*
|
|
155
|
+
* This class performs all of its operations in a right handed coordinate system with right handed rotations. Some other graphics libraries use left handed coordinate systems and rotations.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```js
|
|
159
|
+
* import vtkTransform from '@kitware/vtk.js/Common/Transform/Transform';
|
|
160
|
+
* import vtkMatrixBuilder from '@kitware/vtk.js/Common/Core/MatrixBuilder';
|
|
161
|
+
*
|
|
162
|
+
* const transform = vtkTransform.newInstance();
|
|
163
|
+
* const matrix = vtkMatrixBuilder
|
|
164
|
+
* .buildFromDegree()
|
|
165
|
+
* .rotateZ(45)
|
|
166
|
+
* .getMatrix();
|
|
167
|
+
* transform.setMatrix(matrix);
|
|
168
|
+
* const pointsIn = [[1, 2, 3], [4, 5, 6]];
|
|
169
|
+
* const pointsOut = new Float32Array(6);
|
|
170
|
+
* transform.transformPoints(pointsIn, pointsOut);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export declare const vtkTransform: {
|
|
174
|
+
newInstance: typeof newInstance,
|
|
175
|
+
extend: typeof extend;
|
|
176
|
+
};
|
|
177
|
+
export default vtkTransform;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
2
|
-
import {
|
|
2
|
+
import { IDENTITY } from '../Core/Math/Constants.js';
|
|
3
|
+
import { vec3, mat4 } from 'gl-matrix';
|
|
3
4
|
import macro from '../../macros.js';
|
|
4
5
|
import { f as vtkMath } from '../Core/Math/index.js';
|
|
5
|
-
import { IDENTITY } from '../Core/Math/Constants.js';
|
|
6
6
|
|
|
7
7
|
// vtkTransform methods
|
|
8
8
|
// ----------------------------------------------------------------------------
|
|
@@ -19,9 +19,85 @@ function vtkTransform(publicAPI, model) {
|
|
|
19
19
|
return out;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
publicAPI.transformPoints = function (points, out) {
|
|
23
|
+
var inPoint = new Float64Array(3);
|
|
24
|
+
var outPoint = new Float64Array(3);
|
|
25
|
+
|
|
26
|
+
for (var i = 0; i < points.length; i += 3) {
|
|
27
|
+
inPoint[0] = points[i];
|
|
28
|
+
inPoint[1] = points[i + 1];
|
|
29
|
+
inPoint[2] = points[i + 2];
|
|
30
|
+
vec3.transformMat4(outPoint, inPoint, model.matrix);
|
|
31
|
+
out[i] = outPoint[0];
|
|
32
|
+
out[i + 1] = outPoint[1];
|
|
33
|
+
out[i + 2] = outPoint[2];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return out;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Sets the internal state of the transform to PreMultiply.
|
|
40
|
+
* All subsequent operations will occur before those already represented in the current transformation.
|
|
41
|
+
* In homogeneous matrix notation, M = M*A where M is the current transformation matrix and A is the applied matrix.
|
|
42
|
+
* The default is PreMultiply.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
publicAPI.preMultiply = function () {
|
|
47
|
+
publicAPI.setPreMultiplyFlag(true);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Sets the internal state of the transform to PostMultiply.
|
|
51
|
+
* All subsequent operations will occur after those already represented in the current transformation.
|
|
52
|
+
* In homogeneous matrix notation, M = A*M where M is the current transformation matrix and A is the applied matrix.
|
|
53
|
+
* The default is PreMultiply.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
publicAPI.postMultiply = function () {
|
|
58
|
+
publicAPI.setPreMultiplyFlag(false);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
publicAPI.transformMatrix = function (matrix, out) {
|
|
62
|
+
if (model.preMultiplyFlag) {
|
|
63
|
+
mat4.multiply(out, model.matrix, matrix);
|
|
64
|
+
} else {
|
|
65
|
+
mat4.multiply(out, matrix, model.matrix);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return out;
|
|
69
|
+
}; // Apply the transform to each matrix in the same way as transformMatrix
|
|
70
|
+
// `matrices` can be a contiguous array of float or an array of array
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
publicAPI.transformMatrices = function (matrices, out) {
|
|
74
|
+
var inMat = new Float64Array(16);
|
|
75
|
+
var outMat = new Float64Array(16);
|
|
76
|
+
var transform = model.preMultiplyFlag ? function () {
|
|
77
|
+
return mat4.multiply(outMat, model.matrix, inMat);
|
|
78
|
+
} : function () {
|
|
79
|
+
return mat4.multiply(outMat, inMat, model.matrix);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
for (var i = 0; i < matrices.length; i += 16) {
|
|
83
|
+
for (var j = 0; j < 16; ++j) {
|
|
84
|
+
inMat[j] = matrices[i + j];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
transform();
|
|
88
|
+
|
|
89
|
+
for (var _j = 0; _j < 16; ++_j) {
|
|
90
|
+
out[i + _j] = outMat[_j];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return out;
|
|
95
|
+
};
|
|
96
|
+
|
|
22
97
|
publicAPI.getInverse = function () {
|
|
23
98
|
return newInstance({
|
|
24
|
-
matrix: vtkMath.invertMatrix(Array.from(model.matrix), [], 4)
|
|
99
|
+
matrix: vtkMath.invertMatrix(Array.from(model.matrix), [], 4),
|
|
100
|
+
preMultiplyFlag: model.preMultiplyFlag
|
|
25
101
|
});
|
|
26
102
|
};
|
|
27
103
|
} // ----------------------------------------------------------------------------
|
|
@@ -30,6 +106,7 @@ function vtkTransform(publicAPI, model) {
|
|
|
30
106
|
|
|
31
107
|
|
|
32
108
|
var DEFAULT_VALUES = {
|
|
109
|
+
preMultiplyFlag: false,
|
|
33
110
|
matrix: _toConsumableArray(IDENTITY)
|
|
34
111
|
}; // ----------------------------------------------------------------------------
|
|
35
112
|
|
|
@@ -37,6 +114,7 @@ function extend(publicAPI, model) {
|
|
|
37
114
|
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
38
115
|
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
39
116
|
macro.obj(publicAPI, model);
|
|
117
|
+
macro.setGet(publicAPI, model, ['preMultiplyFlag']);
|
|
40
118
|
macro.setGetArray(publicAPI, model, ['matrix'], 16);
|
|
41
119
|
vtkTransform(publicAPI, model);
|
|
42
120
|
} // ----------------------------------------------------------------------------
|
|
@@ -2,7 +2,7 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
3
|
import vtkMouseRangeManipulator from '../../Interaction/Manipulators/MouseRangeManipulator.js';
|
|
4
4
|
import vtkViewProxy from './ViewProxy.js';
|
|
5
|
-
import { j as cross, E as getMajorAxisIndex } from '../../Common/Core/Math/index.js';
|
|
5
|
+
import { j as cross, E as getMajorAxisIndex, r as radiansFromDegrees } from '../../Common/Core/Math/index.js';
|
|
6
6
|
import { mat4, vec3 } from 'gl-matrix';
|
|
7
7
|
import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
|
|
8
8
|
|
|
@@ -68,6 +68,10 @@ function getPropCoarseHull(prop) {
|
|
|
68
68
|
// It gives a more accurate hull than computing the corners of a transformed bounding box
|
|
69
69
|
|
|
70
70
|
|
|
71
|
+
if (!vtkBoundingBox.isValid(finestBounds)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
|
|
71
75
|
var corners = [];
|
|
72
76
|
vtkBoundingBox.getCorners(finestBounds, corners);
|
|
73
77
|
|
|
@@ -192,6 +196,10 @@ function vtkView2DProxy(publicAPI, model) {
|
|
|
192
196
|
return visiblePoints.push.apply(visiblePoints, _toConsumableArray(getPropCoarseHull(prop)));
|
|
193
197
|
});
|
|
194
198
|
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!visiblePoints) {
|
|
202
|
+
return initialReset;
|
|
195
203
|
} // Get the bounds in view coordinates
|
|
196
204
|
|
|
197
205
|
|
|
@@ -203,26 +211,28 @@ function vtkView2DProxy(publicAPI, model) {
|
|
|
203
211
|
var point = visiblePoints[i];
|
|
204
212
|
vec3.transformMat4(point, point, viewMatrix);
|
|
205
213
|
vtkBoundingBox.addPoint.apply(vtkBoundingBox, [viewBounds].concat(_toConsumableArray(point)));
|
|
206
|
-
} // Compute
|
|
214
|
+
} // Compute parallel scale
|
|
207
215
|
|
|
208
216
|
|
|
217
|
+
var view = model.renderer.getRenderWindow().getViews()[0];
|
|
218
|
+
var dims = view.getViewportSize(model.renderer);
|
|
219
|
+
var aspect = dims[1] && dims[0] ? dims[0] / dims[1] : 1;
|
|
220
|
+
var xLength = vtkBoundingBox.getLength(viewBounds, 0);
|
|
221
|
+
var yLength = vtkBoundingBox.getLength(viewBounds, 1);
|
|
222
|
+
var parallelScale = 0.5 * Math.max(yLength, xLength / aspect); // Compute focal point and position
|
|
223
|
+
|
|
209
224
|
var viewFocalPoint = vtkBoundingBox.getCenter(viewBounds); // Camera position in view coordinates is the center of the bounds in XY
|
|
210
|
-
// and the maximum bound +
|
|
225
|
+
// and is (the maximum bound) + (the distance to see the bounds in perspective) in Z
|
|
211
226
|
|
|
212
|
-
var
|
|
227
|
+
var perspectiveAngle = radiansFromDegrees(model.camera.getViewAngle());
|
|
228
|
+
var distance = parallelScale / Math.tan(perspectiveAngle * 0.5);
|
|
229
|
+
var viewPosition = [viewFocalPoint[0], viewFocalPoint[1], viewBounds[5] + distance];
|
|
213
230
|
var inverseViewMatrix = new Float64Array(16);
|
|
214
231
|
var worldFocalPoint = new Float64Array(3);
|
|
215
232
|
var worldPosition = new Float64Array(3);
|
|
216
233
|
mat4.invert(inverseViewMatrix, viewMatrix);
|
|
217
234
|
vec3.transformMat4(worldFocalPoint, viewFocalPoint, inverseViewMatrix);
|
|
218
|
-
vec3.transformMat4(worldPosition, viewPosition, inverseViewMatrix);
|
|
219
|
-
|
|
220
|
-
var view = model.renderer.getRenderWindow().getViews()[0];
|
|
221
|
-
var dims = view.getViewportSize(model.renderer);
|
|
222
|
-
var aspect = dims[0] / dims[1];
|
|
223
|
-
var xLength = vtkBoundingBox.getLength(viewBounds, 0);
|
|
224
|
-
var yLength = vtkBoundingBox.getLength(viewBounds, 1);
|
|
225
|
-
var parallelScale = 0.5 * Math.max(yLength, xLength / aspect);
|
|
235
|
+
vec3.transformMat4(worldPosition, viewPosition, inverseViewMatrix);
|
|
226
236
|
|
|
227
237
|
if (parallelScale <= 0) {
|
|
228
238
|
return initialReset;
|
|
@@ -17,19 +17,17 @@ export interface vtkAbstractMapper3D extends vtkAbstractMapper {
|
|
|
17
17
|
*/
|
|
18
18
|
getBounds(): Bounds;
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
/**
|
|
22
21
|
* Get the center of this mapper’s data.
|
|
23
22
|
* @return {Vector3} The center of the mapper's data.
|
|
24
23
|
*/
|
|
25
24
|
getCenter(): Vector3;
|
|
26
|
-
|
|
25
|
+
|
|
27
26
|
/**
|
|
28
27
|
* Get the diagonal length of this mappers bounding box.
|
|
29
28
|
* @return {Number} The diagonal length of mapper bounding box.
|
|
30
29
|
*/
|
|
31
30
|
getLength(): number;
|
|
32
|
-
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
/**
|