Skip to content

Commit 6184640

Browse files
committed
feat(transform): add vtkTransform
1 parent 6bf9427 commit 6184640

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { vec3 } from 'gl-matrix';
2+
import macro from 'vtk.js/Sources/macros';
3+
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
4+
import { IDENTITY } from 'vtk.js/Sources/Common/Core/Math/Constants';
5+
6+
// ----------------------------------------------------------------------------
7+
// vtkTransform methods
8+
// ----------------------------------------------------------------------------
9+
// eslint-disable-next-line import/no-mutable-exports
10+
let newInstance;
11+
12+
function vtkTransform(publicAPI, model) {
13+
// Set our className
14+
model.classHierarchy.push(
15+
'vtkAbstractTransform',
16+
'vtkHomogeneousTransform',
17+
'vtkTransform'
18+
);
19+
20+
publicAPI.transformPoint = (point, out) => {
21+
vec3.transformMat4(out, point, model.matrix);
22+
return out;
23+
};
24+
25+
publicAPI.getInverse = () =>
26+
newInstance({
27+
matrix: vtkMath.invertMatrix(Array.from(model.matrix), [], 4),
28+
});
29+
}
30+
31+
// ----------------------------------------------------------------------------
32+
// Object factory
33+
// ----------------------------------------------------------------------------
34+
35+
const DEFAULT_VALUES = {
36+
matrix: [...IDENTITY],
37+
};
38+
39+
// ----------------------------------------------------------------------------
40+
41+
export function extend(publicAPI, model, initialValues = {}) {
42+
Object.assign(model, DEFAULT_VALUES, initialValues);
43+
macro.obj(publicAPI, model);
44+
45+
macro.setGetArray(publicAPI, model, ['matrix'], 16);
46+
47+
vtkTransform(publicAPI, model);
48+
}
49+
50+
// ----------------------------------------------------------------------------
51+
newInstance = macro.newInstance(extend, 'vtkTransform');
52+
export { newInstance };
53+
54+
// ----------------------------------------------------------------------------
55+
56+
export default { newInstance, extend };

Sources/Common/Transform/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import vtkLandmarkTransform from './LandmarkTransform';
2+
import vtkTransform from './Transform';
23

34
export default {
45
vtkLandmarkTransform,
6+
vtkTransform,
57
};

0 commit comments

Comments
 (0)