@kitware/vtk.js 34.10.0 → 34.11.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.
@@ -0,0 +1,111 @@
1
+ import { DesiredOutputPrecision } from './../../Common/DataModel/DataSetAttributes';
2
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
3
+ import vtkPlanes from './../../Common/DataModel/Planes';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IFrustumSourceInitialValues {
9
+ planes?: vtkPlanes;
10
+ showLines?: boolean;
11
+ outputPointsPrecision?: DesiredOutputPrecision;
12
+ }
13
+
14
+ type vtkFrustumSourceBase = vtkObject &
15
+ Omit<
16
+ vtkAlgorithm,
17
+ | 'getInputData'
18
+ | 'setInputData'
19
+ | 'setInputConnection'
20
+ | 'getInputConnection'
21
+ | 'addInputConnection'
22
+ | 'addInputData'
23
+ >;
24
+
25
+ export interface vtkFrustumSource extends vtkFrustumSourceBase {
26
+ /**
27
+ * Get the output points precision.
28
+ */
29
+ getOutputPointsPrecision(): DesiredOutputPrecision;
30
+
31
+ /**
32
+ * Get the planes defining the frustum.
33
+ */
34
+ getPlanes(): vtkPlanes;
35
+
36
+ /**
37
+ * Get whether to show lines.
38
+ */
39
+ getShowLines(): boolean;
40
+
41
+ /**
42
+ *
43
+ * @param inData
44
+ * @param outData
45
+ */
46
+ requestData(inData: any, outData: any): void;
47
+
48
+ /**
49
+ * Set the output points precision.
50
+ * @param {DesiredOutputPrecision} precision
51
+ */
52
+ setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;
53
+
54
+ /**
55
+ * Set the planes defining the frustum.
56
+ * @param {vtkPlanes} planes
57
+ */
58
+ setPlanes(planes: vtkPlanes): boolean;
59
+
60
+ /**
61
+ * Set whether to show lines.
62
+ * @param {Boolean} showLines
63
+ */
64
+ setShowLines(showLines: boolean): boolean;
65
+ }
66
+
67
+ /**
68
+ * Method used to decorate a given object (publicAPI+model) with vtkFrustumSource characteristics.
69
+ *
70
+ * @param publicAPI object on which methods will be bounds (public)
71
+ * @param model object on which data structure will be bounds (protected)
72
+ * @param {IFrustumSourceInitialValues} [initialValues] (default: {})
73
+ */
74
+ export function extend(
75
+ publicAPI: object,
76
+ model: object,
77
+ initialValues?: IFrustumSourceInitialValues
78
+ ): void;
79
+
80
+ /**
81
+ * Method used to create a new instance of vtkFrustumSource.
82
+ * @param {IFrustumSourceInitialValues} [initialValues] for pre-setting some of its content
83
+ */
84
+ export function newInstance(
85
+ initialValues?: IFrustumSourceInitialValues
86
+ ): vtkFrustumSource;
87
+
88
+ /**
89
+ * vtkFrustumSource creates a frustum defines by a set of planes. The frustum is
90
+ * represented with four-sided polygons. It is possible to specify extra lines
91
+ * to better visualize the field of view.
92
+ *
93
+ * @example
94
+ * ```js
95
+ * import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
96
+ *
97
+ * const frustum = vtkFrustumSource.newInstance();
98
+ * const camera = vtkCamera.newInstance();
99
+ * camera.setClippingRange(0.1, 0.4);
100
+ * const planesArray = camera.getFrustumPlanes(1.0);
101
+ * const planes = vtkPlanes.newInstance();
102
+ * planes.setFrustumPlanes(planesArray);
103
+ * frustum.setPlanes(planes);
104
+ * frustum.setShowLines(false);
105
+ * ```
106
+ */
107
+ export declare const vtkFrustumSource: {
108
+ newInstance: typeof newInstance;
109
+ extend: typeof extend;
110
+ };
111
+ export default vtkFrustumSource;
@@ -0,0 +1,248 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import { f as vtkMath } from '../../Common/Core/Math/index.js';
3
+ import vtkCellArray from '../../Common/Core/CellArray.js';
4
+ import vtkPoints from '../../Common/Core/Points.js';
5
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
6
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
7
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
8
+
9
+ const {
10
+ vtkErrorMacro
11
+ } = macro;
12
+
13
+ // ----------------------------------------------------------------------------
14
+ // vtkFrustumSource methods
15
+ // ----------------------------------------------------------------------------
16
+
17
+ function vtkFrustumSource(publicAPI, model) {
18
+ // Set our className
19
+ model.classHierarchy.push('vtkFrustumSource');
20
+ function computePoint(planeIndices, pt) {
21
+ // Get planes and their normals/origins
22
+ const plane0 = model.planes.getPlane(planeIndices[0]);
23
+ const n0 = plane0.getNormal();
24
+ const p0 = plane0.getOrigin();
25
+ const plane1 = model.planes.getPlane(planeIndices[1]);
26
+ const n1 = plane1.getNormal();
27
+ const p1 = plane1.getOrigin();
28
+ const plane2 = model.planes.getPlane(planeIndices[2]);
29
+ const n2 = plane2.getNormal();
30
+ const p2 = plane2.getOrigin();
31
+
32
+ // Dot products
33
+ const d0 = vtkMath.dot(p0, n0);
34
+ const d1 = vtkMath.dot(p1, n1);
35
+ const d2 = vtkMath.dot(p2, n2);
36
+
37
+ // Cross products
38
+ const c12 = [0, 0, 0];
39
+ vtkMath.cross(n1, n2, c12);
40
+ const c20 = [0, 0, 0];
41
+ vtkMath.cross(n2, n0, c20);
42
+ const c01 = [0, 0, 0];
43
+ vtkMath.cross(n0, n1, c01);
44
+
45
+ // Determinant
46
+ const d = vtkMath.determinant3x3([...n0, ...n1, ...n2]);
47
+
48
+ // Intersection point
49
+ for (let i = 0; i < 3; ++i) {
50
+ pt[i] = (d0 * c12[i] + d1 * c20[i] + d2 * c01[i]) / d;
51
+ }
52
+ }
53
+ publicAPI.requestData = (inData, outData) => {
54
+ const output = outData[0] || vtkPolyData.newInstance();
55
+ if (!model.planes || model.planes.getNumberOfPlanes() !== 6) {
56
+ vtkErrorMacro('vtkFrustum requires 6 planes.');
57
+ return;
58
+ }
59
+ let nbPts = 8;
60
+ let leftRightNull = false;
61
+ let bottomTopNull = false;
62
+ let parallelFrustum = false;
63
+
64
+ // angle between left and right planes
65
+ const n0 = model.planes.getPlane(0).getNormal().slice();
66
+ const n1 = model.planes.getPlane(1).getNormal().slice();
67
+ const c = [0, 0, 0];
68
+ vtkMath.normalize(n0);
69
+ vtkMath.normalize(n1);
70
+ vtkMath.dot(n0, n1);
71
+ vtkMath.cross(n0, n1, c);
72
+ vtkMath.norm(c);
73
+
74
+ // angle between bottom and top planes
75
+ n0.splice(0, 3, ...model.planes.getPlane(2).getNormal());
76
+ n1.splice(0, 3, ...model.planes.getPlane(3).getNormal());
77
+ vtkMath.normalize(n0);
78
+ vtkMath.normalize(n1);
79
+ vtkMath.dot(n0, n1);
80
+ vtkMath.cross(n0, n1, c);
81
+ vtkMath.norm(c);
82
+ if (model.showLines) {
83
+ const left = model.planes.getPlane(0).getNormal();
84
+ const right = model.planes.getPlane(1).getNormal();
85
+ const bottom = model.planes.getPlane(2).getNormal();
86
+ const top = model.planes.getPlane(3).getNormal();
87
+ const leftRight = [0, 0, 0];
88
+ vtkMath.cross(left, right, leftRight);
89
+ leftRightNull = leftRight[0] === 0.0 && leftRight[1] === 0.0 && leftRight[2] === 0.0;
90
+ const bottomTop = [0, 0, 0];
91
+ vtkMath.cross(bottom, top, bottomTop);
92
+ bottomTopNull = bottomTop[0] === 0.0 && bottomTop[1] === 0.0 && bottomTop[2] === 0.0;
93
+ parallelFrustum = leftRightNull && bottomTopNull;
94
+ if (parallelFrustum) {
95
+ // start at near points, just add the 4 extra far points.
96
+ nbPts += 4;
97
+ } else if (leftRightNull || bottomTopNull) {
98
+ // two extra starting points, and 4 extra far points.
99
+ nbPts += 6;
100
+ } else {
101
+ // there is an apex, and 4 extra far points
102
+ nbPts += 5;
103
+ }
104
+ }
105
+ let pointType = 0;
106
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
107
+ pointType = VtkDataTypes.FLOAT;
108
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
109
+ pointType = VtkDataTypes.DOUBLE;
110
+ }
111
+ const newPoints = vtkPoints.newInstance({
112
+ dataType: pointType
113
+ });
114
+ newPoints.setNumberOfPoints(nbPts);
115
+ const pt = [0.0, 0.0, 0.0];
116
+ const planes = [0, 0, 0];
117
+ planes[0] = 0; // left
118
+ planes[1] = 2; // bottom
119
+ planes[2] = 5; // near
120
+ computePoint(planes, pt);
121
+ newPoints.setPoint(0, ...pt);
122
+ planes[0] = 1;
123
+ computePoint(planes, pt);
124
+ newPoints.setPoint(1, ...pt);
125
+ planes[1] = 3;
126
+ computePoint(planes, pt);
127
+ newPoints.setPoint(2, ...pt);
128
+ planes[0] = 0;
129
+ computePoint(planes, pt);
130
+ newPoints.setPoint(3, ...pt);
131
+ planes[1] = 2;
132
+ planes[2] = 4; // far
133
+ computePoint(planes, pt);
134
+ newPoints.setPoint(4, ...pt);
135
+ planes[0] = 1;
136
+ computePoint(planes, pt);
137
+ newPoints.setPoint(5, ...pt);
138
+ planes[1] = 3;
139
+ computePoint(planes, pt);
140
+ newPoints.setPoint(6, ...pt);
141
+ planes[0] = 0;
142
+ computePoint(planes, pt);
143
+ newPoints.setPoint(7, ...pt);
144
+ const numPolys = 6;
145
+ const newPolys = vtkCellArray.newInstance();
146
+ newPolys.allocate(numPolys * 5);
147
+
148
+ // left
149
+ newPolys.insertNextCell([4, 0, 3, 7]);
150
+
151
+ // right
152
+ newPolys.insertNextCell([1, 5, 6, 2]);
153
+
154
+ // bottom
155
+ newPolys.insertNextCell([0, 4, 5, 1]);
156
+
157
+ // top
158
+ newPolys.insertNextCell([3, 2, 6, 7]);
159
+
160
+ // near
161
+ newPolys.insertNextCell([0, 1, 2, 3]);
162
+
163
+ // far
164
+ newPolys.insertNextCell([4, 7, 6, 5]);
165
+ let newLines = null;
166
+ if (model.showLines) {
167
+ const numLines = 4;
168
+ newLines = vtkCellArray.newInstance();
169
+ newLines.allocate(numLines * 3);
170
+ const pts = [12, 8]; // apex, or first of the two extra near points.
171
+
172
+ // line from lower-left corner
173
+ if (parallelFrustum) {
174
+ pts[0] = 0;
175
+ }
176
+ newLines.insertNextCell(pts);
177
+
178
+ // line from lower-right corner
179
+ if (parallelFrustum) {
180
+ pts[0]++;
181
+ } else if (leftRightNull) {
182
+ pts[0] = 13;
183
+ }
184
+ pts[1]++;
185
+ newLines.insertNextCell(pts);
186
+
187
+ // line from upper-right corner
188
+ if (parallelFrustum) {
189
+ pts[0]++;
190
+ } else if (bottomTopNull) {
191
+ pts[0] = 13;
192
+ }
193
+ pts[1]++;
194
+ newLines.insertNextCell(pts);
195
+
196
+ // line from upper-left corner
197
+ if (parallelFrustum) {
198
+ pts[0]++;
199
+ } else if (leftRightNull) {
200
+ pts[0] = 12;
201
+ }
202
+ pts[1]++;
203
+ newLines.insertNextCell(pts);
204
+ output.setLines(newLines);
205
+ }
206
+ output.setPoints(newPoints);
207
+ output.setPolys(newPolys);
208
+ outData[0] = output;
209
+ };
210
+ }
211
+
212
+ // ----------------------------------------------------------------------------
213
+ // Object factory
214
+ // ----------------------------------------------------------------------------
215
+
216
+ const DEFAULT_VALUES = {
217
+ planes: null,
218
+ showLines: true,
219
+ outputPointsPrecision: DesiredOutputPrecision.DEFAULT
220
+ };
221
+
222
+ // ----------------------------------------------------------------------------
223
+
224
+ function extend(publicAPI, model) {
225
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
226
+ Object.assign(model, DEFAULT_VALUES, initialValues);
227
+
228
+ // Build VTK API
229
+ macro.obj(publicAPI, model);
230
+
231
+ // Also make it an algorithm with no input and one output
232
+ macro.algo(publicAPI, model, 0, 1);
233
+ macro.setGet(publicAPI, model, ['showLines', 'outputPointsPrecision', 'planes']);
234
+ vtkFrustumSource(publicAPI, model);
235
+ }
236
+
237
+ // ----------------------------------------------------------------------------
238
+
239
+ const newInstance = macro.newInstance(extend, 'vtkFrustumSource');
240
+
241
+ // ----------------------------------------------------------------------------
242
+
243
+ var index = {
244
+ newInstance,
245
+ extend
246
+ };
247
+
248
+ export { index as default, extend, newInstance };
@@ -162,6 +162,22 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
162
162
  }
163
163
  superClass.replaceShaderNormal(shaders, ren, actor);
164
164
  };
165
+ publicAPI.replaceShaderClip = (shaders, ren, actor) => {
166
+ if (model.hardwareSupport) {
167
+ let VSSource = shaders.Vertex;
168
+ let FSSource = shaders.Fragment;
169
+ if (model.renderable.getNumberOfClippingPlanes()) {
170
+ const numClipPlanes = model.renderable.getNumberOfClippingPlanes();
171
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Clip::Dec', ['uniform int numClipPlanes;', `uniform vec4 clipPlanes[${numClipPlanes}];`, `varying float clipDistancesVSOutput[${numClipPlanes}];`]).result;
172
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Clip::Impl', [`for (int planeNum = 0; planeNum < ${numClipPlanes}; planeNum++)`, ' {', ' if (planeNum >= numClipPlanes)', ' {', ' break;', ' }', ' vec4 gVertex = gMatrix * vertexMC;', ' clipDistancesVSOutput[planeNum] = dot(clipPlanes[planeNum], gVertex);', ' }']).result;
173
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Clip::Dec', ['uniform int numClipPlanes;', `varying float clipDistancesVSOutput[${numClipPlanes}];`]).result;
174
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Clip::Impl', [`for (int planeNum = 0; planeNum < ${numClipPlanes}; planeNum++)`, ' {', ' if (planeNum >= numClipPlanes)', ' {', ' break;', ' }', ' if (clipDistancesVSOutput[planeNum] < 0.0) discard;', ' }']).result;
175
+ }
176
+ shaders.Vertex = VSSource;
177
+ shaders.Fragment = FSSource;
178
+ }
179
+ superClass.replaceShaderClip(shaders, ren, actor);
180
+ };
165
181
  publicAPI.replaceShaderColor = (shaders, ren, actor) => {
166
182
  if (model.hardwareSupport && model.renderable.getColorArray()) {
167
183
  let VSSource = shaders.Vertex;
@@ -1,3 +1,3 @@
1
- var vtkVolumeVS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataVS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n\nattribute vec4 vertexDC;\n\nvarying vec3 vertexVCVSOutput;\nuniform mat4 PCVCMatrix;\n\nuniform float dcxmin;\nuniform float dcxmax;\nuniform float dcymin;\nuniform float dcymax;\n\nvoid main()\n{\n // dcsmall is the device coords reduced to the\n // x y area covered by the volume\n vec4 dcsmall = vec4(\n dcxmin + 0.5 * (vertexDC.x + 1.0) * (dcxmax - dcxmin),\n dcymin + 0.5 * (vertexDC.y + 1.0) * (dcymax - dcymin),\n vertexDC.z,\n vertexDC.w);\n vec4 vcpos = PCVCMatrix * dcsmall;\n vertexVCVSOutput = vcpos.xyz/vcpos.w;\n gl_Position = dcsmall;\n}\n";
1
+ var vtkVolumeVS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkVolumeVS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n\nattribute vec4 vertexDC;\n\nvarying vec3 vertexVCVSOutput;\nuniform mat4 PCVCMatrix;\n\nuniform float dcxmin;\nuniform float dcxmax;\nuniform float dcymin;\nuniform float dcymax;\n\nvoid main()\n{\n // dcsmall is the device coords reduced to the\n // x y area covered by the volume\n vec4 dcsmall = vec4(\n dcxmin + 0.5 * (vertexDC.x + 1.0) * (dcxmax - dcxmin),\n dcymin + 0.5 * (vertexDC.y + 1.0) * (dcymax - dcymin),\n vertexDC.z,\n vertexDC.w);\n vec4 vcpos = PCVCMatrix * dcsmall;\n vertexVCVSOutput = vcpos.xyz/vcpos.w;\n gl_Position = dcsmall;\n}\n";
2
2
 
3
3
  export { vtkVolumeVS as v };
package/index.d.ts CHANGED
@@ -37,9 +37,11 @@
37
37
  /// <reference path="./Common/DataModel/KochanekSpline1D.d.ts" />
38
38
  /// <reference path="./Common/DataModel/Line.d.ts" />
39
39
  /// <reference path="./Common/DataModel/Locator.d.ts" />
40
+ /// <reference path="./Common/DataModel/MergePoints.d.ts" />
40
41
  /// <reference path="./Common/DataModel/PiecewiseFunction.d.ts" />
41
42
  /// <reference path="./Common/DataModel/Plane.d.ts" />
42
43
  /// <reference path="./Common/DataModel/Planes.d.ts" />
44
+ /// <reference path="./Common/DataModel/PointLocator.d.ts" />
43
45
  /// <reference path="./Common/DataModel/PointSet.d.ts" />
44
46
  /// <reference path="./Common/DataModel/PolyData/Constants.d.ts" />
45
47
  /// <reference path="./Common/DataModel/PolyData.d.ts" />
@@ -82,6 +84,7 @@
82
84
  /// <reference path="./Filters/Sources/CylinderSource.d.ts" />
83
85
  /// <reference path="./Filters/Sources/DiskSource.d.ts" />
84
86
  /// <reference path="./Filters/Sources/EllipseArcSource.d.ts" />
87
+ /// <reference path="./Filters/Sources/FrustumSource.d.ts" />
85
88
  /// <reference path="./Filters/Sources/LineSource.d.ts" />
86
89
  /// <reference path="./Filters/Sources/PlaneSource.d.ts" />
87
90
  /// <reference path="./Filters/Sources/PlatonicSolidSource/Constants.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.10.0",
3
+ "version": "34.11.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",