@kitware/vtk.js 34.7.0 → 34.8.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,159 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkCellArray from '../../Common/Core/CellArray.js';
3
+ import vtkDataArray from '../../Common/Core/DataArray.js';
4
+ import { f as vtkMath } from '../../Common/Core/Math/index.js';
5
+ import vtkPoints from '../../Common/Core/Points.js';
6
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
7
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
8
+
9
+ const {
10
+ vtkErrorMacro
11
+ } = macro;
12
+ const {
13
+ VtkDataTypes
14
+ } = vtkDataArray;
15
+
16
+ // ----------------------------------------------------------------------------
17
+ // vtkEllipseArcSource methods
18
+ // ----------------------------------------------------------------------------
19
+
20
+ function vtkEllipseArcSource(publicAPI, model) {
21
+ // Set our className
22
+ model.classHierarchy.push('vtkEllipseArcSource');
23
+ publicAPI.requestData = (inData, outData) => {
24
+ const isClosedShape = Math.abs(model.segmentAngle - 360.0) < 1e-5;
25
+ const resolution = model.close && !isClosedShape ? model.resolution + 1 : model.resolution;
26
+ const numLines = resolution;
27
+ const numPts = resolution + 1;
28
+ const tc = [0.0, 0.0];
29
+ const output = outData[0] || vtkPolyData.newInstance();
30
+
31
+ // Make sure the normal vector is normalized
32
+ const normal = [...model.normal];
33
+ vtkMath.normalize(normal);
34
+
35
+ // Get orthogonal vector between user-defined major radius and normal
36
+ const orthogonalVect = [0, 0, 0];
37
+ vtkMath.cross(normal, model.majorRadiusVector, orthogonalVect);
38
+ if (vtkMath.norm(orthogonalVect) < 1e-10) {
39
+ vtkErrorMacro('Ellipse normal vector and major radius axis are collinear');
40
+ return;
41
+ }
42
+ vtkMath.normalize(orthogonalVect);
43
+ const majorRadiusVect = [0, 0, 0];
44
+ vtkMath.cross(orthogonalVect, normal, majorRadiusVect);
45
+ vtkMath.normalize(majorRadiusVect);
46
+ const a = vtkMath.norm(model.majorRadiusVector);
47
+ const b = a * model.ratio;
48
+ let startAngleRad = vtkMath.radiansFromDegrees(model.startAngle);
49
+ if (startAngleRad < 0) {
50
+ startAngleRad += 2.0 * Math.PI;
51
+ }
52
+ const segmentAngleRad = vtkMath.radiansFromDegrees(model.segmentAngle);
53
+ const angleIncRad = segmentAngleRad / model.resolution;
54
+ let pointType = VtkDataTypes.FLOAT;
55
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
56
+ pointType = VtkDataTypes.FLOAT;
57
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
58
+ pointType = VtkDataTypes.DOUBLE;
59
+ }
60
+ const points = vtkPoints.newInstance({
61
+ dataType: pointType
62
+ });
63
+ points.setNumberOfPoints(numPts);
64
+ const tcoords = vtkDataArray.newInstance({
65
+ numberOfComponents: 2,
66
+ size: numPts * 2,
67
+ dataType: VtkDataTypes.FLOAT,
68
+ name: 'TextureCoordinates'
69
+ });
70
+ const lines = vtkCellArray.newInstance();
71
+ lines.allocate(numLines);
72
+ const skipLastPoint = model.close && isClosedShape;
73
+ let theta = startAngleRad;
74
+ let pointIndex = 0;
75
+ for (let i = 0; i <= resolution; ++i, theta += angleIncRad) {
76
+ const quotient = Math.floor(theta / (2.0 * Math.PI));
77
+ const normalizedTheta = theta - quotient * 2.0 * Math.PI;
78
+ let thetaEllipse = Math.atan(Math.tan(normalizedTheta) * model.ratio);
79
+ if (normalizedTheta > Math.PI / 2 && normalizedTheta <= Math.PI) {
80
+ thetaEllipse += Math.PI;
81
+ } else if (normalizedTheta > Math.PI && normalizedTheta <= 1.5 * Math.PI) {
82
+ thetaEllipse -= Math.PI;
83
+ }
84
+ const cosTheta = Math.cos(thetaEllipse);
85
+ const sinTheta = Math.sin(thetaEllipse);
86
+ const p = [model.center[0] + a * cosTheta * majorRadiusVect[0] + b * sinTheta * orthogonalVect[0], model.center[1] + a * cosTheta * majorRadiusVect[1] + b * sinTheta * orthogonalVect[1], model.center[2] + a * cosTheta * majorRadiusVect[2] + b * sinTheta * orthogonalVect[2]];
87
+ tc[0] = i / resolution;
88
+ tc[1] = 0.0;
89
+ if (i !== resolution || !skipLastPoint) {
90
+ points.setPoint(pointIndex, ...p);
91
+ tcoords.setTuple(pointIndex, tc);
92
+ pointIndex++;
93
+ }
94
+ }
95
+ const actualNumPts = pointIndex;
96
+ const pointIds = [];
97
+ for (let k = 0; k < actualNumPts - 1; ++k) {
98
+ pointIds.push(k);
99
+ }
100
+ if (model.close) {
101
+ pointIds.push(0);
102
+ } else {
103
+ pointIds.push(actualNumPts - 1);
104
+ }
105
+ lines.insertNextCell(pointIds);
106
+ output.setPoints(points);
107
+ output.getPointData().setTCoords(tcoords);
108
+ output.setLines(lines);
109
+ outData[0] = output;
110
+ };
111
+ }
112
+
113
+ // ----------------------------------------------------------------------------
114
+ // Object factory
115
+ // ----------------------------------------------------------------------------
116
+
117
+ const DEFAULT_VALUES = {
118
+ center: [0.0, 0.0, 0.0],
119
+ normal: [0.0, 0.0, 1.0],
120
+ majorRadiusVector: [1.0, 0.0, 0.0],
121
+ startAngle: 0.0,
122
+ segmentAngle: 90.0,
123
+ resolution: 100,
124
+ close: false,
125
+ outputPointsPrecision: DesiredOutputPrecision.SINGLE,
126
+ ratio: 1.0
127
+ };
128
+
129
+ // ----------------------------------------------------------------------------
130
+
131
+ function extend(publicAPI, model) {
132
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
133
+ Object.assign(model, DEFAULT_VALUES, initialValues);
134
+
135
+ // Ensure resolution is at least 1
136
+ if (model.resolution < 1) {
137
+ model.resolution = 1;
138
+ }
139
+
140
+ // Build VTK API
141
+ macro.obj(publicAPI, model);
142
+ macro.algo(publicAPI, model, 0, 1);
143
+ macro.setGet(publicAPI, model, ['resolution', 'startAngle', 'segmentAngle', 'close', 'outputPointsPrecision', 'ratio']);
144
+ macro.setGetArray(publicAPI, model, ['center', 'normal', 'majorRadiusVector'], 3);
145
+ vtkEllipseArcSource(publicAPI, model);
146
+ }
147
+
148
+ // ----------------------------------------------------------------------------
149
+
150
+ const newInstance = macro.newInstance(extend, 'vtkEllipseArcSource');
151
+
152
+ // ----------------------------------------------------------------------------
153
+
154
+ var vtkEllipseArcSource$1 = {
155
+ newInstance,
156
+ extend
157
+ };
158
+
159
+ export { vtkEllipseArcSource$1 as default, extend, newInstance };
@@ -0,0 +1,12 @@
1
+ export declare enum SolidType {
2
+ VTK_SOLID_TETRAHEDRON = 0,
3
+ VTK_SOLID_CUBE = 1,
4
+ VTK_SOLID_OCTAHEDRON = 2,
5
+ VTK_SOLID_ICOSAHEDRON = 3,
6
+ VTK_SOLID_DODECAHEDRON = 4,
7
+ }
8
+
9
+ declare const _default: {
10
+ SolidType: typeof SolidType;
11
+ };
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ const SolidType = {
2
+ VTK_SOLID_TETRAHEDRON: 0,
3
+ VTK_SOLID_CUBE: 1,
4
+ VTK_SOLID_OCTAHEDRON: 2,
5
+ VTK_SOLID_ICOSAHEDRON: 3,
6
+ VTK_SOLID_DODECAHEDRON: 4
7
+ };
8
+ var Constants = {
9
+ SolidType
10
+ };
11
+
12
+ export { SolidType, Constants as default };
@@ -0,0 +1,109 @@
1
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
2
+ import { DesiredOutputPrecision } from './../../Common/DataModel/DataSetAttributes';
3
+ import { SolidType } from './PlatonicSolidSource/Constants';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IPlatonicSolidSourceInitialValues {
9
+ solidType?: SolidType;
10
+ outputPointsPrecision?: DesiredOutputPrecision;
11
+ scale?: number;
12
+ }
13
+
14
+ type vtkPlatonicSolidSourceBase = vtkObject &
15
+ Omit<
16
+ vtkAlgorithm,
17
+ | 'getInputData'
18
+ | 'setInputData'
19
+ | 'setInputConnection'
20
+ | 'getInputConnection'
21
+ | 'addInputConnection'
22
+ | 'addInputData'
23
+ >;
24
+
25
+ export interface vtkPlatonicSolidSource extends vtkPlatonicSolidSourceBase {
26
+ /**
27
+ * Get the desired output precision.
28
+ * @returns {DesiredOutputPrecision}
29
+ */
30
+ getOutputPointsPrecision(): DesiredOutputPrecision;
31
+
32
+ /**
33
+ * Get the scale factor of the source.
34
+ */
35
+ getScale(): number;
36
+
37
+ /**
38
+ * Get the solid type of the source.
39
+ * @returns {SolidType}
40
+ */
41
+ getSolidType(): SolidType;
42
+
43
+ /**
44
+ * Request data for the source.
45
+ * @param inData
46
+ * @param outData
47
+ */
48
+ requestData(inData: any, outData: any): void;
49
+
50
+ /**
51
+ * Set the desired output precision.
52
+ * @param {DesiredOutputPrecision} outputPointsPrecision
53
+ */
54
+ setOutputPointsPrecision(
55
+ outputPointsPrecision: DesiredOutputPrecision
56
+ ): boolean;
57
+
58
+ /**
59
+ * Set the scale factor of the source.
60
+ * @param {Number} scale The scale factor.
61
+ */
62
+ setScale(scale: number): boolean;
63
+
64
+ /**
65
+ * Set the solid type of the source.
66
+ * @param {SolidType} solidType
67
+ */
68
+ setSolidType(solidType: SolidType): boolean;
69
+ }
70
+
71
+ /**
72
+ * Method used to decorate a given object (publicAPI+model) with vtkPlatonicSolidSource characteristics.
73
+ *
74
+ * @param publicAPI object on which methods will be bounds (public)
75
+ * @param model object on which data structure will be bounds (protected)
76
+ * @param {IPlatonicSolidSourceInitialValues} [initialValues] (default: {})
77
+ */
78
+ export function extend(
79
+ publicAPI: object,
80
+ model: object,
81
+ initialValues?: IPlatonicSolidSourceInitialValues
82
+ ): void;
83
+
84
+ /**
85
+ * Method used to create a new instance of vtkPlatonicSolidSource.
86
+ * @param {IPlatonicSolidSourceInitialValues} [initialValues] for pre-setting some of its content
87
+ */
88
+ export function newInstance(
89
+ initialValues?: IPlatonicSolidSourceInitialValues
90
+ ): vtkPlatonicSolidSource;
91
+
92
+ /**
93
+ * vtkPlatonicSolidSource can generate each of the five Platonic solids:
94
+ * tetrahedron, cube, octahedron, icosahedron, and dodecahedron. Each of the
95
+ * solids is placed inside a sphere centered at the origin with radius 1.0.
96
+ *
97
+ * @example
98
+ * ```js
99
+ * import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
100
+ *
101
+ * const regularPolygonSource = vtkPlatonicSolidSource.newInstance();
102
+ * const polydata = regularPolygonSource.getOutputData();
103
+ * ```
104
+ */
105
+ export declare const vtkPlatonicSolidSource: {
106
+ newInstance: typeof newInstance;
107
+ extend: typeof extend;
108
+ };
109
+ export default vtkPlatonicSolidSource;
@@ -0,0 +1,149 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
+ import vtkPoints from '../../Common/Core/Points.js';
4
+ import vtkCellArray from '../../Common/Core/CellArray.js';
5
+ import { SolidType } from './PlatonicSolidSource/Constants.js';
6
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
7
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
8
+
9
+ const a = 0.61803398875;
10
+ const b = 0.38196601125;
11
+ const c = 0.5;
12
+ const d = 0.30901699;
13
+ const e = Math.sqrt(2);
14
+ const f = Math.sqrt(3.0);
15
+ const geometries = {
16
+ tetrahedron: {
17
+ points: [1, 1, 1, -1, 1, -1, 1, -1, -1, -1, -1, 1],
18
+ cells: [0, 2, 1, 1, 2, 3, 0, 3, 2, 0, 1, 3],
19
+ numPoints: 4,
20
+ cellSize: 3,
21
+ numCells: 4,
22
+ scale: 1.0 / f
23
+ },
24
+ cube: {
25
+ points: [-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1],
26
+ cells: [0, 1, 5, 4, 0, 4, 7, 3, 4, 5, 6, 7, 3, 7, 6, 2, 1, 2, 6, 5, 0, 3, 2, 1],
27
+ numPoints: 8,
28
+ cellSize: 4,
29
+ numCells: 6,
30
+ scale: 1.0 / f
31
+ },
32
+ octahedron: {
33
+ points: [-1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0, 0, 0, -e, 0, 0, e],
34
+ cells: [4, 1, 0, 4, 2, 1, 4, 3, 2, 4, 0, 3, 0, 1, 5, 1, 2, 5, 2, 3, 5, 3, 0, 5],
35
+ numPoints: 6,
36
+ cellSize: 3,
37
+ numCells: 8,
38
+ scale: 1.0 / e
39
+ },
40
+ icosahedron: {
41
+ points: [0, d, -c, 0, d, c, 0, -d, c, -d, c, 0, -d, -c, 0, d, c, 0, d, -c, 0, 0, -d, -c, c, 0, d, -c, 0, d, -c, 0, -d, c, 0, -d],
42
+ cells: [0, 3, 5, 1, 5, 3, 1, 9, 2, 1, 2, 8, 0, 11, 7, 0, 7, 10, 2, 4, 6, 7, 6, 4, 3, 10, 9, 4, 9, 10, 5, 8, 11, 6, 11, 8, 1, 3, 9, 1, 8, 5, 0, 10, 3, 0, 5, 11, 7, 4, 10, 7, 11, 6, 2, 9, 4, 2, 6, 8],
43
+ numPoints: 12,
44
+ cellSize: 3,
45
+ numCells: 20,
46
+ scale: 1.0 / 0.58778524999243
47
+ },
48
+ dodecahedron: {
49
+ points: [b, 0, 1, -b, 0, 1, b, 0, -1, -b, 0, -1, 0, 1, -b, 0, 1, b, 0, -1, -b, 0, -1, b, 1, b, 0, 1, -b, 0, -1, b, 0, -1, -b, 0, -a, a, a, a, -a, a, -a, -a, -a, a, a, -a, a, a, a, -a, a, -a, -a, -a, a, a, -a, -a],
50
+ cells: [0, 16, 5, 12, 1, 1, 18, 7, 13, 0, 2, 19, 6, 14, 3, 3, 17, 4, 15, 2, 4, 5, 16, 8, 15, 5, 4, 17, 10, 12, 6, 7, 18, 11, 14, 7, 6, 19, 9, 13, 8, 16, 0, 13, 9, 9, 19, 2, 15, 8, 10, 17, 3, 14, 11, 11, 18, 1, 12, 10],
51
+ numPoints: 20,
52
+ cellSize: 5,
53
+ numCells: 12,
54
+ scale: 1.0 / 1.070466269319
55
+ }
56
+ };
57
+
58
+ // ----------------------------------------------------------------------------
59
+ // vtkPlatonicSolidSource methods
60
+ // ----------------------------------------------------------------------------
61
+
62
+ function vtkPlatonicSolidSource(publicAPI, model) {
63
+ // Set our className
64
+ model.classHierarchy.push('vtkPlatonicSolidSource');
65
+ publicAPI.requestData = (inData, outData) => {
66
+ const output = outData[0] || vtkPolyData.newInstance();
67
+ let solidData;
68
+ switch (model.solidType) {
69
+ case SolidType.VTK_SOLID_TETRAHEDRON:
70
+ solidData = geometries.tetrahedron;
71
+ break;
72
+ case SolidType.VTK_SOLID_CUBE:
73
+ solidData = geometries.cube;
74
+ break;
75
+ case SolidType.VTK_SOLID_OCTAHEDRON:
76
+ solidData = geometries.octahedron;
77
+ break;
78
+ case SolidType.VTK_SOLID_ICOSAHEDRON:
79
+ solidData = geometries.icosahedron;
80
+ break;
81
+ case SolidType.VTK_SOLID_DODECAHEDRON:
82
+ solidData = geometries.dodecahedron;
83
+ break;
84
+ default:
85
+ solidData = geometries.tetrahedron;
86
+ break;
87
+ }
88
+ let pointType;
89
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
90
+ pointType = VtkDataTypes.FLOAT;
91
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
92
+ pointType = VtkDataTypes.DOUBLE;
93
+ }
94
+ const points = vtkPoints.newInstance({
95
+ dataType: pointType,
96
+ numberOfPoints: solidData.numPoints
97
+ });
98
+ for (let i = 0; i < solidData.points.length; i += 3) {
99
+ points.insertNextPoint(solidData.scale * solidData.points[i] * model.scale, solidData.scale * solidData.points[i + 1] * model.scale, solidData.scale * solidData.points[i + 2] * model.scale);
100
+ }
101
+ const polys = vtkCellArray.newInstance();
102
+ for (let i = 0; i < solidData.cells.length; i += solidData.cellSize) {
103
+ const cell = solidData.cells.slice(i, i + solidData.cellSize);
104
+ polys.insertNextCell(cell);
105
+ }
106
+ output.setPoints(points);
107
+ output.setPolys(polys);
108
+ outData[0] = output;
109
+ };
110
+ }
111
+
112
+ // ----------------------------------------------------------------------------
113
+ // Object factory
114
+ // ----------------------------------------------------------------------------
115
+
116
+ const DEFAULT_VALUES = {
117
+ solidType: SolidType.VTK_SOLID_TETRAHEDRON,
118
+ outputPointsPrecision: DesiredOutputPrecision.DEFAULT,
119
+ scale: 1
120
+ };
121
+
122
+ // ----------------------------------------------------------------------------
123
+
124
+ function extend(publicAPI, model) {
125
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
126
+ Object.assign(model, DEFAULT_VALUES, initialValues);
127
+
128
+ // Build VTK API
129
+ macro.obj(publicAPI, model);
130
+ macro.setGet(publicAPI, model, ['solidType', 'outputPointsPrecision', 'scale']);
131
+ macro.algo(publicAPI, model, 0, 1);
132
+
133
+ // Object methods
134
+ vtkPlatonicSolidSource(publicAPI, model);
135
+ }
136
+
137
+ // ----------------------------------------------------------------------------
138
+
139
+ const newInstance = macro.newInstance(extend, 'vtkPlatonicSolidSource');
140
+
141
+ // ----------------------------------------------------------------------------
142
+
143
+ var vtkPlatonicSolidSource$1 = {
144
+ newInstance,
145
+ extend,
146
+ SolidType
147
+ };
148
+
149
+ export { vtkPlatonicSolidSource$1 as default, extend, newInstance };
@@ -1,3 +1,4 @@
1
+ import vtkArcSource from './Sources/ArcSource.js';
1
2
  import vtkArrowSource from './Sources/ArrowSource.js';
2
3
  import vtkCircleSource from './Sources/CircleSource.js';
3
4
  import vtkConcentricCylinderSource from './Sources/ConcentricCylinderSource.js';
@@ -6,15 +7,18 @@ import vtkCubeSource from './Sources/CubeSource.js';
6
7
  import vtkCursor3D from './Sources/Cursor3D.js';
7
8
  import vtkCylinderSource from './Sources/CylinderSource.js';
8
9
  import vtkDiskSource from './Sources/DiskSource.js';
10
+ import vtkEllipseArcSource from './Sources/EllipseArcSource.js';
9
11
  import vtkImageGridSource from './Sources/ImageGridSource.js';
10
12
  import vtkLineSource from './Sources/LineSource.js';
11
13
  import vtkPlaneSource from './Sources/PlaneSource.js';
14
+ import vtkPlatonicSolidSource from './Sources/PlatonicSolidSource.js';
12
15
  import vtkPointSource from './Sources/PointSource.js';
13
16
  import vtkRTAnalyticSource from './Sources/RTAnalyticSource.js';
14
17
  import vtkSLICSource from './Sources/SLICSource.js';
15
18
  import vtkSphereSource from './Sources/SphereSource.js';
16
19
 
17
20
  var Sources = {
21
+ vtkArcSource,
18
22
  vtkArrowSource,
19
23
  vtkCircleSource,
20
24
  vtkConcentricCylinderSource,
@@ -23,9 +27,11 @@ var Sources = {
23
27
  vtkCursor3D,
24
28
  vtkCylinderSource,
25
29
  vtkDiskSource,
30
+ vtkEllipseArcSource,
26
31
  vtkImageGridSource,
27
32
  vtkLineSource,
28
33
  vtkPlaneSource,
34
+ vtkPlatonicSolidSource,
29
35
  vtkPointSource,
30
36
  vtkRTAnalyticSource,
31
37
  vtkSLICSource,
@@ -164,7 +164,9 @@ function vtkOBJWriter(publicAPI, model) {
164
164
  const zipContent = {};
165
165
  zipContent[`${modelFilename}.obj`] = strToU8(model.output[0]);
166
166
  zipContent[`${materialFilename}.mtl`] = strToU8(model.mtl);
167
- const canvas = new OffscreenCanvas(imageData.width, imageData.height);
167
+ const canvas = document.createElement('canvas');
168
+ canvas.width = imageData.width;
169
+ canvas.height = imageData.height;
168
170
  const ctx = canvas.getContext('2d');
169
171
  ctx.putImageData(imageData, 0, 0);
170
172
  return new Promise(resolve => {
@@ -7,6 +7,7 @@ import vtkDataArray from '../../Common/Core/DataArray.js';
7
7
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
8
8
  import vtkColorTransferFunction from '../../Rendering/Core/ColorTransferFunction.js';
9
9
  import vtkAbstractRepresentationProxy from '../Core/AbstractRepresentationProxy.js';
10
+ import '../../Filters/Sources/ArcSource.js';
10
11
  import '../../Filters/Sources/ArrowSource.js';
11
12
  import '../../Filters/Sources/CircleSource.js';
12
13
  import '../../Filters/Sources/ConcentricCylinderSource.js';
@@ -15,9 +16,11 @@ import '../../Filters/Sources/CubeSource.js';
15
16
  import '../../Filters/Sources/Cursor3D.js';
16
17
  import '../../Filters/Sources/CylinderSource.js';
17
18
  import '../../Filters/Sources/DiskSource.js';
19
+ import '../../Filters/Sources/EllipseArcSource.js';
18
20
  import '../../Filters/Sources/ImageGridSource.js';
19
21
  import '../../Filters/Sources/LineSource.js';
20
22
  import '../../Filters/Sources/PlaneSource.js';
23
+ import '../../Filters/Sources/PlatonicSolidSource.js';
21
24
  import '../../Filters/Sources/PointSource.js';
22
25
  import '../../Filters/Sources/RTAnalyticSource.js';
23
26
  import '../../Filters/Sources/SLICSource.js';
@@ -384,7 +384,7 @@ function addTriangle(layers, a, b, c, verticesArray, uvArray, colorArray, color)
384
384
  uvArray.push(uv[0], uv[1]);
385
385
  });
386
386
  if (colorArray && color) {
387
- for (let i = 0; i < 3; ++i) colorArray.push(color[0], color[1], color[2]);
387
+ for (let i = 0; i < 3; ++i) colorArray.push(color[0] * 255, color[1] * 255, color[2] * 255);
388
388
  }
389
389
  }
390
390
 
@@ -417,7 +417,7 @@ function addQuad(layers, a, b, c, d, verticesArray, uvArray, colorArray, color)
417
417
  uvArray.push(uvs[2][0], uvs[2][1]);
418
418
  uvArray.push(uvs[3][0], uvs[3][1]);
419
419
  if (colorArray && color) {
420
- for (let i = 0; i < 6; ++i) colorArray.push(color[0], color[1], color[2]);
420
+ for (let i = 0; i < 6; ++i) colorArray.push(color[0] * 255, color[1] * 255, color[2] * 255);
421
421
  }
422
422
  }
423
423
 
@@ -258,7 +258,7 @@ function vtkVectorText(publicAPI, model) {
258
258
  let letterIndex = 0;
259
259
  model.shapes.forEach(shape => {
260
260
  let color = null;
261
- if (typeof model.perLetterFaceColors === 'function') {
261
+ if (model.perLetterFaceColors) {
262
262
  color = model.perLetterFaceColors(letterIndex) || [1, 1, 1];
263
263
  }
264
264
  addShape(shape, offsetSize, color);
@@ -285,12 +285,12 @@ function vtkVectorText(publicAPI, model) {
285
285
  polyData.setPolys(cells);
286
286
 
287
287
  // Set points (vertices)
288
- polyData.getPoints().setData(new Float32Array(model.verticesArray), 3);
288
+ polyData.getPoints().setData(Float32Array.from(model.verticesArray), 3);
289
289
 
290
290
  // Set texture coordinates
291
291
  const da = vtkDataArray.newInstance({
292
292
  numberOfComponents: 2,
293
- values: new Float32Array(model.uvArray),
293
+ values: Float32Array.from(model.uvArray),
294
294
  name: 'TEXCOORD_0'
295
295
  });
296
296
  pointData.addArray(da);
@@ -300,7 +300,7 @@ function vtkVectorText(publicAPI, model) {
300
300
  if (model.colorArray && model.colorArray.length) {
301
301
  const ca = vtkDataArray.newInstance({
302
302
  numberOfComponents: 3,
303
- values: new Float32Array(model.colorArray),
303
+ values: Uint8Array.from(model.colorArray),
304
304
  name: 'Colors'
305
305
  });
306
306
  pointData.addArray(ca);
@@ -5,7 +5,9 @@ import vtkHardwareSelector from './HardwareSelector.js';
5
5
  import vtkProperty from '../Core/Property.js';
6
6
  import vtkOpenGLPolyDataMapper from './PolyDataMapper.js';
7
7
  import vtkShaderProgram from './ShaderProgram.js';
8
+ import { computeCoordShiftAndScale } from './CellArrayBufferObject/helpers.js';
8
9
  import { registerOverride } from './ViewNodeFactory.js';
10
+ import { primTypes } from './Helper.js';
9
11
 
10
12
  const {
11
13
  vtkErrorMacro
@@ -25,6 +27,17 @@ const StartEvent = {
25
27
  const EndEvent = {
26
28
  type: 'EndEvent'
27
29
  };
30
+ const MAT4_BYTE_SIZE = 64;
31
+ const MAT4_ELEMENT_COUNT = 16;
32
+ function applyShiftScaleToMat(mat, shift, scale) {
33
+ // the translation component of a 4x4 column-major matrix
34
+ mat[12] = (mat[12] - shift[0]) * scale[0];
35
+ mat[13] = (mat[13] - shift[1]) * scale[1];
36
+ mat[14] = (mat[14] - shift[2]) * scale[2];
37
+ mat[0] *= scale[0];
38
+ mat[5] *= scale[1];
39
+ mat[10] *= scale[2];
40
+ }
28
41
 
29
42
  // ----------------------------------------------------------------------------
30
43
  // vtkOpenGLSphereMapper methods
@@ -389,9 +402,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
389
402
  return false;
390
403
  };
391
404
  publicAPI.buildBufferObjects = (ren, actor) => {
405
+ const garray = model.renderable.getMatrixArray();
406
+ const pts = model.renderable.getInputData(0).getPoints();
407
+ const {
408
+ useShiftAndScale,
409
+ coordShift,
410
+ coordScale
411
+ } = computeCoordShiftAndScale(pts);
392
412
  if (model.hardwareSupport) {
393
413
  // update the buffer objects if needed
394
- const garray = model.renderable.getMatrixArray();
395
414
  const narray = model.renderable.getNormalArray();
396
415
  const carray = model.renderable.getColorArray();
397
416
  if (!model.matrixBuffer) {
@@ -404,6 +423,13 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
404
423
  model.pickBuffer = vtkBufferObject.newInstance();
405
424
  model.pickBuffer.setOpenGLRenderWindow(model._openGLRenderWindow);
406
425
  }
426
+ if (useShiftAndScale) {
427
+ const buf = garray.buffer;
428
+ for (let ptIdx = 0; ptIdx < garray.byteLength; ptIdx += MAT4_BYTE_SIZE) {
429
+ const mat = new Float32Array(buf, ptIdx, MAT4_ELEMENT_COUNT);
430
+ applyShiftScaleToMat(mat, coordShift, coordScale);
431
+ }
432
+ }
407
433
  if (model.renderable.getBuildTime().getMTime() > model.glyphBOBuildTime.getMTime()) {
408
434
  model.matrixBuffer.upload(garray, ObjectType.ARRAY_BUFFER);
409
435
  model.normalBuffer.upload(narray, ObjectType.ARRAY_BUFFER);
@@ -430,7 +456,15 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
430
456
  model.glyphBOBuildTime.modified();
431
457
  }
432
458
  }
433
- return superClass.buildBufferObjects(ren, actor);
459
+ superClass.buildBufferObjects(ren, actor);
460
+
461
+ // apply shift + scale to primitives AFTER vtkOpenGLPolyDataMapper.buildBufferObjects
462
+ // so that the Glyph3DMapper gets the last say in the shift + scale
463
+ if (useShiftAndScale) {
464
+ for (let i = primTypes.Start; i < primTypes.End; i++) {
465
+ model.primitives[i].getCABO().setCoordShiftAndScale(coordShift, coordScale);
466
+ }
467
+ }
434
468
  };
435
469
  }
436
470
 
package/index.d.ts CHANGED
@@ -67,9 +67,11 @@
67
67
  /// <reference path="./Filters/General/ImageStreamline.d.ts" />
68
68
  /// <reference path="./Filters/General/LineFilter.d.ts" />
69
69
  /// <reference path="./Filters/General/OutlineFilter.d.ts" />
70
+ /// <reference path="./Filters/General/ShrinkPolyData.d.ts" />
70
71
  /// <reference path="./Filters/General/TransformPolyDataFilter.d.ts" />
71
72
  /// <reference path="./Filters/General/TriangleFilter.d.ts" />
72
73
  /// <reference path="./Filters/General/TubeFilter.d.ts" />
74
+ /// <reference path="./Filters/Sources/ArcSource.d.ts" />
73
75
  /// <reference path="./Filters/Sources/Arrow2DSource.d.ts" />
74
76
  /// <reference path="./Filters/Sources/ArrowSource.d.ts" />
75
77
  /// <reference path="./Filters/Sources/CircleSource.d.ts" />
@@ -78,8 +80,11 @@
78
80
  /// <reference path="./Filters/Sources/Cursor3D.d.ts" />
79
81
  /// <reference path="./Filters/Sources/CylinderSource.d.ts" />
80
82
  /// <reference path="./Filters/Sources/DiskSource.d.ts" />
83
+ /// <reference path="./Filters/Sources/EllipseArcSource.d.ts" />
81
84
  /// <reference path="./Filters/Sources/LineSource.d.ts" />
82
85
  /// <reference path="./Filters/Sources/PlaneSource.d.ts" />
86
+ /// <reference path="./Filters/Sources/PlatonicSolidSource/Constants.d.ts" />
87
+ /// <reference path="./Filters/Sources/PlatonicSolidSource.d.ts" />
83
88
  /// <reference path="./Filters/Sources/PointSource.d.ts" />
84
89
  /// <reference path="./Filters/Sources/SphereSource.d.ts" />
85
90
  /// <reference path="./Filters/Texture/TextureMapToPlane.d.ts" />