@kitware/vtk.js 34.16.7 → 34.17.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,196 @@
1
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
2
+ import { Vector3 } from './../../types';
3
+
4
+ export type IGenerateTCoords =
5
+ | 'TCOORDS_OFF'
6
+ | 'TCOORDS_FROM_SCALARS'
7
+ | 'TCOORDS_FROM_LENGTH'
8
+ | 'TCOORDS_FROM_NORMALIZED_LENGTH';
9
+
10
+ /**
11
+ *
12
+ */
13
+ export interface IRibbonFilterInitialValues {
14
+ useDefaultNormal?: boolean;
15
+ width?: number;
16
+ varyWidth?: boolean;
17
+ angle?: number;
18
+ generateTCoords?: IGenerateTCoords;
19
+ widthFactor?: number;
20
+ textureLength?: number;
21
+ defaultNormal?: Vector3;
22
+ }
23
+
24
+ type vtkRibbonFilterBase = vtkObject & vtkAlgorithm;
25
+
26
+ export interface vtkRibbonFilter extends vtkRibbonFilterBase {
27
+ /**
28
+ * Get the angle (in degrees) of rotation about the line tangent used to
29
+ * orient the ribbon.
30
+ */
31
+ getAngle(): number;
32
+
33
+ /**
34
+ * Get the default normal used to orient the ribbon when no normals are
35
+ * provided in the input.
36
+ */
37
+ getDefaultNormal(): Vector3;
38
+
39
+ /**
40
+ * Get the default normal used to orient the ribbon when no normals are
41
+ * provided in the input.
42
+ */
43
+ getDefaultNormalByReference(): Vector3;
44
+
45
+ /**
46
+ * Get the method used to generate texture coordinates.
47
+ */
48
+ getGenerateTCoords(): IGenerateTCoords;
49
+
50
+ /**
51
+ * Get the method used to generate texture coordinates as a string.
52
+ */
53
+ getGenerateTCoordsAsString(): string;
54
+
55
+ /**
56
+ * Get the texture length, used when generating texture coordinates from
57
+ * length.
58
+ */
59
+ getTextureLength(): number;
60
+
61
+ /**
62
+ * Get whether to use the default normal to orient the ribbon when no
63
+ * normals are provided in the input.
64
+ */
65
+ getUseDefaultNormal(): boolean;
66
+
67
+ /**
68
+ * Get whether to vary the width of the ribbon using scalar data.
69
+ */
70
+ getVaryWidth(): boolean;
71
+
72
+ /**
73
+ * Get the width of the ribbon.
74
+ */
75
+ getWidth(): number;
76
+
77
+ /**
78
+ * Get the width factor, used to scale the width when varying the width.
79
+ */
80
+ getWidthFactor(): number;
81
+
82
+ /**
83
+ *
84
+ * @param inData
85
+ * @param outData
86
+ */
87
+ requestData(inData: any, outData: any): void;
88
+
89
+ /**
90
+ * Set the angle (in degrees) of rotation about the line tangent used to orient the ribbon.
91
+ * Default is 0.0.
92
+ * @param angle The angle in degrees.
93
+ * @returns true if the angle is set successfully.
94
+ */
95
+ setAngle(angle: number): boolean;
96
+
97
+ /**
98
+ * Set the default normal used to orient the ribbon when no normals are provided in the input.
99
+ * The default normal is a vector defined by three components (x,y,z). The
100
+ * default is (0,0,1).
101
+ * @param defaultNormal The default normal as an array of three numbers or a Vector3.
102
+ * @returns true if the default normal is set successfully.
103
+ */
104
+ setDefaultNormal(defaultNormal: Vector3): boolean;
105
+
106
+ /**
107
+ * Set the default normal used to orient the ribbon when no normals are provided in the input.
108
+ * The default normal is a vector defined by three components (x,y,z). The
109
+ * default is (0,0,1).
110
+ * @returns true if the default normal is set successfully.
111
+ */
112
+ setDefaultNormalFrom(defaultNormal: Vector3): boolean;
113
+
114
+ /**
115
+ * Set the method used to generate texture coordinates. By default, texture
116
+ * coordinates are not generated.
117
+ * @param generateTCoords The method to generate texture coordinates.
118
+ * @returns true if the method is set successfully.
119
+ */
120
+ setGenerateTCoords(generateTCoords: IGenerateTCoords): boolean;
121
+
122
+ /**
123
+ * Set the texture length, used when generating texture coordinates from length.
124
+ * The default is 1.0.
125
+ * @param textureLength The texture length.
126
+ * @returns true if the texture length is set successfully.
127
+ */
128
+ setTextureLength(textureLength: number): boolean;
129
+
130
+ /**
131
+ * Set whether to use the default normal to orient the ribbon when no normals are provided in the input.
132
+ * The default is false.
133
+ * @param useDefaultNormal Whether to use the default normal.
134
+ * @returns true if the flag is set successfully.
135
+ */
136
+ setUseDefaultNormal(useDefaultNormal: boolean): boolean;
137
+
138
+ /**
139
+ * Set whether to vary the width of the ribbon using scalar data. By default,
140
+ * the width of the ribbon is uniform.
141
+ * @param varyWidth Whether to vary the width of the ribbon.
142
+ * @returns true if the flag is set successfully.
143
+ */
144
+ setVaryWidth(varyWidth: boolean): boolean;
145
+
146
+ /**
147
+ * Set the width of the ribbon. The width is the total width of the ribbon;
148
+ * the ribbon extends width/2 on either side of the line. The default is 0.5.
149
+ * @param width The width of the ribbon.
150
+ * @returns true if the width is set successfully.
151
+ */
152
+ setWidth(width: number): boolean;
153
+
154
+ /**
155
+ * Set the width factor, used to scale the width when varying the width.
156
+ * The default is 1.0.
157
+ * @param widthFactor The width factor.
158
+ * @returns true if the width factor is set successfully.
159
+ */
160
+ setWidthFactor(widthFactor: number): boolean;
161
+ }
162
+
163
+ /**
164
+ * Method used to decorate a given object (publicAPI+model) with vtkRibbonFilter characteristics.
165
+ *
166
+ * @param publicAPI object on which methods will be bounds (public)
167
+ * @param model object on which data structure will be bounds (protected)
168
+ * @param {IRibbonFilterInitialValues} [initialValues] (default: {})
169
+ */
170
+ export function extend(
171
+ publicAPI: object,
172
+ model: object,
173
+ initialValues?: IRibbonFilterInitialValues
174
+ ): void;
175
+
176
+ /**
177
+ * Method used to create a new instance of vtkRibbonFilter
178
+ * @param {IRibbonFilterInitialValues} [initialValues] for pre-setting some of its content
179
+ */
180
+ export function newInstance(
181
+ initialValues?: IRibbonFilterInitialValues
182
+ ): vtkRibbonFilter;
183
+
184
+ /**
185
+ * vtkRibbonFilter is a filter to create oriented ribbons from lines defined in
186
+ * polygonal dataset. The orientation of the ribbon is along the line segments
187
+ * and perpendicular to "projected" line normals. Projected line normals are the
188
+ * original line normals projected to be perpendicular to the local line
189
+ * segment. An offset angle can be specified to rotate the ribbon with respect
190
+ * to the normal.
191
+ */
192
+ export declare const vtkRibbonFilter: {
193
+ newInstance: typeof newInstance;
194
+ extend: typeof extend;
195
+ };
196
+ export default vtkRibbonFilter;
@@ -0,0 +1,386 @@
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 vtkDataArray from '../../Common/Core/DataArray.js';
6
+ import { b as vtkMath } from '../../Common/Core/Math/index.js';
7
+
8
+ /* eslint-disable no-continue */
9
+ const {
10
+ vtkWarningMacro
11
+ } = macro;
12
+
13
+ // Texture coordinate generation modes
14
+ const GenerateTCoords = {
15
+ TCOORDS_OFF: 0,
16
+ TCOORDS_FROM_SCALARS: 1,
17
+ TCOORDS_FROM_LENGTH: 2,
18
+ TCOORDS_FROM_NORMALIZED_LENGTH: 3
19
+ };
20
+
21
+ // ----------------------------------------------------------------------------
22
+ // vtkRibbonFilter methods
23
+ // ----------------------------------------------------------------------------
24
+
25
+ function vtkRibbonFilter(publicAPI, model) {
26
+ // Set our className
27
+ model.classHierarchy.push('vtkRibbonFilter');
28
+
29
+ // Private methods
30
+ function generateSlidingNormals(points, lines, normals) {
31
+ // Simplified normal generation for polylines
32
+ // This is a basic implementation - you might want to use the actual vtk.js implementation
33
+ const lineArray = lines.getData();
34
+ let offset = 0;
35
+ for (let cellId = 0; cellId < lines.getNumberOfCells(); cellId++) {
36
+ const npts = lineArray[offset++];
37
+ const pts = lineArray.slice(offset, offset + npts);
38
+ offset += npts;
39
+ if (npts < 2) continue;
40
+ for (let i = 0; i < npts; i++) {
41
+ const v1 = [0, 0, 0];
42
+ const v2 = [0, 0, 0];
43
+ if (i === 0) {
44
+ points.getPoint(pts[1], v2);
45
+ points.getPoint(pts[0], v1);
46
+ } else if (i === npts - 1) {
47
+ points.getPoint(pts[i], v2);
48
+ points.getPoint(pts[i - 1], v1);
49
+ } else {
50
+ points.getPoint(pts[i + 1], v2);
51
+ points.getPoint(pts[i - 1], v1);
52
+ }
53
+ const tangent = [v2[0] - v1[0], v2[1] - v1[1], v2[2] - v1[2]];
54
+ vtkMath.normalize(tangent);
55
+
56
+ // Generate a normal perpendicular to the tangent
57
+ let normal = [0, 0, 1];
58
+ if (Math.abs(vtkMath.dot(tangent, normal)) > 0.9) {
59
+ normal = [1, 0, 0];
60
+ }
61
+ const binormal = [0, 0, 0];
62
+ vtkMath.cross(tangent, normal, binormal);
63
+ vtkMath.normalize(binormal);
64
+ vtkMath.cross(binormal, tangent, normal);
65
+ vtkMath.normalize(normal);
66
+ normals.setTuple(pts[i], normal);
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ function generatePoints(offset, npts, pts, inPts, newPts, inScalars, range, inNormals, outPD, pd, newNormals) {
72
+ const theta = model.angle * Math.PI / 180.0;
73
+ let ptId = offset;
74
+ const p = [0, 0, 0];
75
+ const pNext = [0, 0, 0];
76
+ const sNext = [0, 0, 0];
77
+ const sPrev = [0, 0, 0];
78
+ for (let j = 0; j < npts; j++) {
79
+ if (j === 0) {
80
+ inPts.getPoint(pts[0], p);
81
+ inPts.getPoint(pts[1], pNext);
82
+ for (let i = 0; i < 3; i++) {
83
+ sNext[i] = pNext[i] - p[i];
84
+ sPrev[i] = sNext[i];
85
+ }
86
+ } else if (j === npts - 1) {
87
+ for (let i = 0; i < 3; i++) {
88
+ sPrev[i] = sNext[i];
89
+ p[i] = pNext[i];
90
+ }
91
+ } else {
92
+ for (let i = 0; i < 3; i++) {
93
+ p[i] = pNext[i];
94
+ }
95
+ inPts.getPoint(pts[j + 1], pNext);
96
+ for (let i = 0; i < 3; i++) {
97
+ sPrev[i] = sNext[i];
98
+ sNext[i] = pNext[i] - p[i];
99
+ }
100
+ }
101
+ const n = [0, 0, 0];
102
+ inNormals.getTuple(pts[j], n);
103
+ if (vtkMath.normalize(sNext) === 0.0) {
104
+ vtkWarningMacro('Coincident points!');
105
+ return false;
106
+ }
107
+ const s = [(sPrev[0] + sNext[0]) / 2.0, (sPrev[1] + sNext[1]) / 2.0, (sPrev[2] + sNext[2]) / 2.0];
108
+ if (vtkMath.normalize(s) === 0.0) {
109
+ vtkMath.cross(sPrev, n, s);
110
+ if (vtkMath.normalize(s) === 0.0) {
111
+ vtkWarningMacro('Using alternate bevel vector');
112
+ }
113
+ }
114
+ const w = vtkMath.cross(s, n, []);
115
+ if (vtkMath.normalize(w) === 0.0) {
116
+ vtkWarningMacro(`Bad normal s = ${s} n = ${n}`);
117
+ return false;
118
+ }
119
+ const nP = vtkMath.cross(w, s, []);
120
+ vtkMath.normalize(nP);
121
+ let sFactor = 1.0;
122
+ if (inScalars && model.varyWidth) {
123
+ sFactor = 1.0 + (model.widthFactor - 1.0) * (inScalars.getValue(pts[j]) - range[0]) / (range[1] - range[0]);
124
+ }
125
+ const v = [w[0] * Math.cos(theta) + nP[0] * Math.sin(theta), w[1] * Math.cos(theta) + nP[1] * Math.sin(theta), w[2] * Math.cos(theta) + nP[2] * Math.sin(theta)];
126
+ const sp = [p[0] + model.width * sFactor * v[0], p[1] + model.width * sFactor * v[1], p[2] + model.width * sFactor * v[2]];
127
+ const sm = [p[0] - model.width * sFactor * v[0], p[1] - model.width * sFactor * v[1], p[2] - model.width * sFactor * v[2]];
128
+ newPts.setPoint(ptId, ...sm);
129
+ newNormals.setTuple(ptId, nP);
130
+ outPD.passData(pd, pts[j], ptId);
131
+ ptId++;
132
+ newPts.setPoint(ptId, ...sp);
133
+ newNormals.setTuple(ptId, nP);
134
+ outPD.passData(pd, pts[j], ptId);
135
+ ptId++;
136
+ }
137
+ return true;
138
+ }
139
+ function generateStrip(offset, npts, inCellId, outCD, cd, newStrips) {
140
+ const stripData = [];
141
+ for (let i = 0; i < npts; i++) {
142
+ const idx = 2 * i;
143
+ stripData.push(offset + idx);
144
+ stripData.push(offset + idx + 1);
145
+ }
146
+ newStrips.insertNextCell(stripData);
147
+ const outCellId = newStrips.getNumberOfCells() - 1;
148
+ outCD.passData(cd, inCellId, outCellId);
149
+ }
150
+ function generateTextureCoords(offset, npts, pts, inPts, inScalars, newTCoords) {
151
+ // First texture coordinate is always 0
152
+ for (let k = 0; k < 2; k++) {
153
+ newTCoords.setTuple(offset + k, [0.0, 0.0]);
154
+ }
155
+ if (model.generateTCoords === GenerateTCoords.TCOORDS_FROM_SCALARS && inScalars) {
156
+ const s0 = inScalars.getValue(pts[0]);
157
+ for (let i = 1; i < npts; i++) {
158
+ const s = inScalars.getValue(pts[i]);
159
+ const tc = (s - s0) / model.textureLength;
160
+ for (let k = 0; k < 2; k++) {
161
+ newTCoords.setTuple(offset + i * 2 + k, [tc, 0.0]);
162
+ }
163
+ }
164
+ } else if (model.generateTCoords === GenerateTCoords.TCOORDS_FROM_LENGTH) {
165
+ const xPrev = [0, 0, 0];
166
+ const x = [0, 0, 0];
167
+ let len = 0.0;
168
+ inPts.getPoint(pts[0], xPrev);
169
+ for (let i = 1; i < npts; i++) {
170
+ inPts.getPoint(pts[i], x);
171
+ len += Math.sqrt(vtkMath.distance2BetweenPoints(x, xPrev));
172
+ const tc = len / model.textureLength;
173
+ for (let k = 0; k < 2; k++) {
174
+ newTCoords.setTuple(offset + i * 2 + k, [tc, 0.0]);
175
+ }
176
+ xPrev[0] = x[0];
177
+ xPrev[1] = x[1];
178
+ xPrev[2] = x[2];
179
+ }
180
+ } else if (model.generateTCoords === GenerateTCoords.TCOORDS_FROM_NORMALIZED_LENGTH) {
181
+ const xPrev = [0, 0, 0];
182
+ const x = [0, 0, 0];
183
+ let length = 0.0;
184
+ let len = 0.0;
185
+
186
+ // Calculate total length
187
+ inPts.getPoint(pts[0], xPrev);
188
+ for (let i = 1; i < npts; i++) {
189
+ inPts.getPoint(pts[i], x);
190
+ length += Math.sqrt(vtkMath.distance2BetweenPoints(x, xPrev));
191
+ xPrev[0] = x[0];
192
+ xPrev[1] = x[1];
193
+ xPrev[2] = x[2];
194
+ }
195
+
196
+ // Generate normalized coordinates
197
+ inPts.getPoint(pts[0], xPrev);
198
+ for (let i = 1; i < npts; i++) {
199
+ inPts.getPoint(pts[i], x);
200
+ len += Math.sqrt(vtkMath.distance2BetweenPoints(x, xPrev));
201
+ const tc = len / length;
202
+ for (let k = 0; k < 2; k++) {
203
+ newTCoords.setTuple(offset + i * 2 + k, [tc, 0.0]);
204
+ }
205
+ xPrev[0] = x[0];
206
+ xPrev[1] = x[1];
207
+ xPrev[2] = x[2];
208
+ }
209
+ }
210
+ }
211
+ publicAPI.requestData = (inData, outData) => {
212
+ const input = inData[0];
213
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
214
+ outData[0] = output;
215
+ if (!input || !input.getPoints() || !input.getLines()) {
216
+ return;
217
+ }
218
+ const inPts = input.getPoints();
219
+ const inLines = input.getLines();
220
+ const pd = input.getPointData();
221
+ const cd = input.getCellData();
222
+ const numPts = inPts.getNumberOfPoints();
223
+ const numLines = inLines.getNumberOfCells();
224
+ if (numPts < 1 || numLines < 1) {
225
+ return;
226
+ }
227
+
228
+ // Get scalar data if available
229
+ let inScalars = null;
230
+ const scalarsArray = pd.getScalars();
231
+ if (scalarsArray) {
232
+ inScalars = scalarsArray;
233
+ }
234
+ let inNormals = pd.getNormals();
235
+ let generateNormals = false;
236
+ if (!inNormals || model.useDefaultNormal) {
237
+ inNormals = vtkDataArray.newInstance({
238
+ numberOfComponents: 3,
239
+ size: numPts * 3,
240
+ dataType: 'Float32Array'
241
+ });
242
+ if (model.useDefaultNormal) {
243
+ for (let i = 0; i < numPts; i++) {
244
+ inNormals.setTuple(i, model.defaultNormal);
245
+ }
246
+ } else {
247
+ generateNormals = true;
248
+ }
249
+ }
250
+
251
+ // Calculate scalar range if varying width
252
+ let range = [0, 1];
253
+ if (model.varyWidth && inScalars) {
254
+ range = inScalars.getRange();
255
+ if (range[1] - range[0] === 0.0) {
256
+ vtkWarningMacro('Scalar range is zero!');
257
+ range[1] = range[0] + 1.0;
258
+ }
259
+ }
260
+ const numNewPts = 2 * numPts;
261
+ const newPts = vtkPoints.newInstance();
262
+ newPts.setNumberOfPoints(numNewPts);
263
+ const newNormals = vtkDataArray.newInstance({
264
+ numberOfComponents: 3,
265
+ size: numNewPts * 3
266
+ });
267
+ const newStrips = vtkCellArray.newInstance();
268
+ const outPD = output.getPointData();
269
+ outPD.copyStructure(pd);
270
+ const outCD = output.getCellData();
271
+ outCD.copyStructure(cd);
272
+ let newTCoords = null;
273
+ if (model.generateTCoords !== GenerateTCoords.TCOORDS_OFF) {
274
+ newTCoords = vtkDataArray.newInstance({
275
+ numberOfComponents: 2,
276
+ size: numNewPts * 2
277
+ });
278
+ }
279
+
280
+ // Process each polyline
281
+ const lineArray = inLines.getData();
282
+ let offset = 0;
283
+ let arrayOffset = 0;
284
+ for (let inCellId = 0; inCellId < numLines; inCellId++) {
285
+ const npts = lineArray[arrayOffset++];
286
+ const pts = lineArray.slice(arrayOffset, arrayOffset + npts);
287
+ arrayOffset += npts;
288
+ if (npts < 2) {
289
+ vtkWarningMacro('Less than two points in line!');
290
+ continue;
291
+ }
292
+
293
+ // Generate normals if needed
294
+ if (generateNormals) {
295
+ const singlePolyline = vtkCellArray.newInstance();
296
+ singlePolyline.insertNextCell(pts);
297
+ if (!generateSlidingNormals(inPts, singlePolyline, inNormals)) ;
298
+ }
299
+
300
+ // Generate points for this polyline
301
+ if (!generatePoints(offset, npts, pts, inPts, newPts, inScalars, range, inNormals, outPD, pd, newNormals)) {
302
+ vtkWarningMacro('Could not generate points!');
303
+ continue;
304
+ }
305
+
306
+ // Generate strip for this polyline
307
+ generateStrip(offset, npts, inCellId, outCD, cd, newStrips);
308
+
309
+ // Generate texture coordinates if needed
310
+ if (newTCoords) {
311
+ generateTextureCoords(offset, npts, pts, inPts, inScalars, newTCoords);
312
+ }
313
+
314
+ // Update offset for next polyline
315
+ offset += 2 * npts;
316
+ }
317
+
318
+ // Set output data
319
+ output.setPoints(newPts);
320
+ output.setStrips(newStrips);
321
+ outPD.setNormals(newNormals);
322
+ if (newTCoords) {
323
+ outPD.setTCoords(newTCoords);
324
+ }
325
+ };
326
+ publicAPI.getGenerateTCoordsAsString = () => {
327
+ switch (model.generateTCoords) {
328
+ case GenerateTCoords.TCOORDS_OFF:
329
+ return 'GenerateTCoordsOff';
330
+ case GenerateTCoords.TCOORDS_FROM_SCALARS:
331
+ return 'GenerateTCoordsFromScalar';
332
+ case GenerateTCoords.TCOORDS_FROM_LENGTH:
333
+ return 'GenerateTCoordsFromLength';
334
+ case GenerateTCoords.TCOORDS_FROM_NORMALIZED_LENGTH:
335
+ return 'GenerateTCoordsFromNormalizedLength';
336
+ default:
337
+ return 'GenerateTCoordsOff';
338
+ }
339
+ };
340
+ }
341
+
342
+ // ----------------------------------------------------------------------------
343
+ // Object factory
344
+ // ----------------------------------------------------------------------------
345
+
346
+ const DEFAULT_VALUES = {
347
+ width: 0.5,
348
+ angle: 0.0,
349
+ varyWidth: false,
350
+ widthFactor: 2.0,
351
+ defaultNormal: [0.0, 0.0, 1.0],
352
+ useDefaultNormal: false,
353
+ generateTCoords: GenerateTCoords.TCOORDS_OFF,
354
+ textureLength: 1.0
355
+ };
356
+
357
+ // ----------------------------------------------------------------------------
358
+
359
+ function extend(publicAPI, model, initialValues = {}) {
360
+ Object.assign(model, DEFAULT_VALUES, initialValues);
361
+
362
+ // Build VTK API
363
+ macro.obj(publicAPI, model);
364
+ macro.algo(publicAPI, model, 1, 1);
365
+
366
+ // Set/Get methods
367
+ macro.setGet(publicAPI, model, ['width', 'angle', 'varyWidth', 'widthFactor', 'useDefaultNormal', 'generateTCoords', 'textureLength']);
368
+ macro.setGetArray(publicAPI, model, ['defaultNormal'], 3);
369
+
370
+ // Object specific methods
371
+ vtkRibbonFilter(publicAPI, model);
372
+ }
373
+
374
+ // ----------------------------------------------------------------------------
375
+
376
+ const newInstance = macro.newInstance(extend, 'vtkRibbonFilter');
377
+
378
+ // ----------------------------------------------------------------------------
379
+
380
+ var vtkRibbonFilter$1 = {
381
+ newInstance,
382
+ extend,
383
+ GenerateTCoords
384
+ };
385
+
386
+ export { vtkRibbonFilter$1 as default, extend, newInstance };
@@ -0,0 +1,7 @@
1
+ import vtkRibbonFilter from './Modeling/RibbonFilter.js';
2
+
3
+ var index = {
4
+ vtkRibbonFilter
5
+ };
6
+
7
+ export { index as default };
@@ -96,10 +96,10 @@ export function newInstance(
96
96
  *
97
97
  * @example
98
98
  * ```js
99
- * import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
99
+ * import vtkPlatonicSolidSource from '@kitware/vtk.js/Filters/Sources/PlatonicSolidSource';
100
100
  *
101
- * const regularPolygonSource = vtkPlatonicSolidSource.newInstance();
102
- * const polydata = regularPolygonSource.getOutputData();
101
+ * const platonicSolidSource = vtkPlatonicSolidSource.newInstance();
102
+ * const polydata = platonicSolidSource.getOutputData();
103
103
  * ```
104
104
  */
105
105
  export declare const vtkPlatonicSolidSource: {
@@ -0,0 +1,183 @@
1
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
2
+ import { Vector3 } from './../../types';
3
+ import { DesiredOutputPrecision } from './../../Common/DataModel/DataSetAttributes';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IPlaneSourceInitialValues {
9
+ numberOfSides?: number;
10
+ center?: Vector3;
11
+ normal?: Vector3;
12
+ radius?: number;
13
+ generatePolygon?: boolean;
14
+ generatePolyline?: boolean;
15
+ outputPointsPrecision?: DesiredOutputPrecision;
16
+ }
17
+
18
+ type vtkRegularPolygonSourceBase = vtkObject &
19
+ Omit<
20
+ vtkAlgorithm,
21
+ | 'getInputData'
22
+ | 'setInputData'
23
+ | 'setInputConnection'
24
+ | 'getInputConnection'
25
+ | 'addInputConnection'
26
+ | 'addInputData'
27
+ >;
28
+
29
+ export interface vtkRegularPolygonSource extends vtkRegularPolygonSourceBase {
30
+ /**
31
+ * Get the center of the regular polygon.
32
+ * @returns {Vector3} center of the polygon
33
+ */
34
+ getCenter(): Vector3;
35
+
36
+ /**
37
+ * Get a reference to the center of the regular polygon.
38
+ * @returns {Vector3} reference to the center of the polygon
39
+ */
40
+ getCenterByReference(): Vector3;
41
+
42
+ /**
43
+ * Get whether to generate polygon points.
44
+ * @returns {Boolean} true if polygon points are generated, false otherwise
45
+ */
46
+ getGeneratePolygon(): boolean;
47
+
48
+ /**
49
+ * Get whether to generate polyline points.
50
+ * @returns {Boolean} true if polyline points are generated, false otherwise
51
+ */
52
+ getGeneratePolyline(): boolean;
53
+
54
+ /**
55
+ * Get the normal of the regular polygon.
56
+ * @returns {Vector3} normal of the polygon
57
+ */
58
+ getNormal(): Vector3;
59
+
60
+ /**
61
+ * Get a reference to the normal of the regular polygon.
62
+ * @returns {Vector3} reference to the normal of the polygon
63
+ */
64
+ getNormalByReference(): Vector3;
65
+
66
+ /**
67
+ * Get the number of sides for the regular polygon.
68
+ * @returns {Number} number of sides
69
+ */
70
+ getNumberOfSides(): number;
71
+
72
+ /**
73
+ * Get the output points precision.
74
+ * @returns {DesiredOutputPrecision} the output points precision
75
+ */
76
+ getOutputPointsPrecision(): DesiredOutputPrecision;
77
+
78
+ /**
79
+ * Get the radius of the regular polygon.
80
+ * @returns {Number} radius of the polygon
81
+ */
82
+ getRadius(): number;
83
+
84
+ /**
85
+ *
86
+ * @param inData
87
+ * @param outData
88
+ */
89
+ requestData(inData: any, outData: any): void;
90
+
91
+ /**
92
+ * Set the center of the regular polygon.
93
+ * @param {Vector3} center
94
+ * @returns {Boolean} true if the value was changed, false otherwise
95
+ */
96
+ setCenter(center: Vector3): boolean;
97
+
98
+ /**
99
+ * Set whether to generate polygon points.
100
+ * @param generatePolygon
101
+ * @returns {Boolean} true if the value was changed, false otherwise
102
+ */
103
+ setGeneratePolygon(generatePolygon: boolean): boolean;
104
+
105
+ /**
106
+ * Set whether to generate polyline points.
107
+ * @param generatePolyline
108
+ * @returns {Boolean} true if the value was changed, false otherwise
109
+ */
110
+ setGeneratePolyline(generatePolyline: boolean): boolean;
111
+
112
+ /**
113
+ * Set the normal of the regular polygon.
114
+ * @param {Vector3} normal
115
+ * @returns {Boolean} true if the value was changed, false otherwise
116
+ */
117
+ setNormal(normal: Vector3): boolean;
118
+
119
+ /**
120
+ * Set the number of sides for the regular polygon.
121
+ * @param numberOfSides
122
+ * @returns {Boolean} true if the value was changed, false otherwise
123
+ */
124
+ setNumberOfSides(numberOfSides: number): boolean;
125
+
126
+ /**
127
+ * Set the output points precision.
128
+ * @param outputPointsPrecision
129
+ * @returns {Boolean} true if the value was changed, false otherwise
130
+ */
131
+ setOutputPointsPrecision(
132
+ outputPointsPrecision: DesiredOutputPrecision
133
+ ): boolean;
134
+
135
+ /**
136
+ * Set the radius of the regular polygon.
137
+ * @param radius
138
+ * @returns {Boolean} true if the value was changed, false otherwise
139
+ */
140
+ setRadius(radius: number): boolean;
141
+ }
142
+
143
+ /**
144
+ * Method used to decorate a given object (publicAPI+model) with vtkRegularPolygonSource characteristics.
145
+ *
146
+ * @param publicAPI object on which methods will be bounds (public)
147
+ * @param model object on which data structure will be bounds (protected)
148
+ * @param {IPlaneSourceInitialValues} [initialValues] (default: {})
149
+ */
150
+ export function extend(
151
+ publicAPI: object,
152
+ model: object,
153
+ initialValues?: IPlaneSourceInitialValues
154
+ ): void;
155
+
156
+ /**
157
+ * Method used to create a new instance of vtkRegularPolygonSource.
158
+ * @param {IPlaneSourceInitialValues} [initialValues] for pre-setting some of its content
159
+ */
160
+ export function newInstance(
161
+ initialValues?: IPlaneSourceInitialValues
162
+ ): vtkRegularPolygonSource;
163
+
164
+ /**
165
+ * vtkRegularPolygonSource is a source object that creates a single n-sided
166
+ * polygon and/or polyline. The polygon is centered at a specified point,
167
+ * orthogonal to a specified normal, and with a circumscribing radius set by the
168
+ * user. The user can also specify the number of sides of the polygon ranging
169
+ * from [3,N].
170
+ *
171
+ * @example
172
+ * ```js
173
+ * import vtkRegularPolygonSource from '@kitware/vtk.js/Filters/Sources/RegularPolygonSource';
174
+ *
175
+ * const regularPolygonSource = vtkRegularPolygonSource.newInstance();
176
+ * const polydata = regularPolygonSource.getOutputData();
177
+ * ```
178
+ */
179
+ export declare const vtkRegularPolygonSource: {
180
+ newInstance: typeof newInstance;
181
+ extend: typeof extend;
182
+ };
183
+ export default vtkRegularPolygonSource;
@@ -0,0 +1,150 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import { b as vtkMath } from '../../Common/Core/Math/index.js';
3
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
4
+ import vtkPoints from '../../Common/Core/Points.js';
5
+ import vtkCellArray from '../../Common/Core/CellArray.js';
6
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
7
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
8
+
9
+ // ----------------------------------------------------------------------------
10
+ // vtkRegularPolygonSource methods
11
+ // ----------------------------------------------------------------------------
12
+
13
+ function vtkRegularPolygonSource(publicAPI, model) {
14
+ // Set our className
15
+ model.classHierarchy.push('vtkRegularPolygonSource');
16
+ publicAPI.requestData = (inData, outData) => {
17
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
18
+ const numPts = model.numberOfSides;
19
+ const newPoints = vtkPoints.newInstance({
20
+ dataType: model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE ? VtkDataTypes.DOUBLE : VtkDataTypes.FLOAT
21
+ });
22
+
23
+ // Generate polyline if requested
24
+ if (model.generatePolyline) {
25
+ const newLine = vtkCellArray.newInstance();
26
+ const linePoints = [];
27
+ for (let i = 0; i < numPts; i++) {
28
+ linePoints.push(i);
29
+ }
30
+ linePoints.push(0); // close the polyline
31
+ newLine.insertNextCell(linePoints);
32
+ output.setLines(newLine);
33
+ }
34
+
35
+ // Generate polygon if requested
36
+ if (model.generatePolygon) {
37
+ const newPoly = vtkCellArray.newInstance();
38
+ const polyPoints = [];
39
+ for (let i = 0; i < numPts; i++) {
40
+ polyPoints.push(i);
41
+ }
42
+ newPoly.insertNextCell(polyPoints);
43
+ output.setPolys(newPoly);
44
+ }
45
+
46
+ // Make sure the polygon normal is a unit vector
47
+ const n = [...model.normal];
48
+ const nLength = vtkMath.normalize(n);
49
+ if (nLength === 0.0) {
50
+ n[0] = 0.0;
51
+ n[1] = 0.0;
52
+ n[2] = 1.0;
53
+ }
54
+
55
+ // Find a vector in the polygon plane (perpendicular to normal)
56
+ const px = [0, 0, 0];
57
+ const py = [0, 0, 0];
58
+ let foundPlaneVector = false;
59
+
60
+ // Cross with unit axis vectors and eventually find vector in the polygon plane
61
+ const axis = [1.0, 0.0, 0.0];
62
+ vtkMath.cross(n, axis, px);
63
+ const pxLength = vtkMath.normalize(px);
64
+ if (pxLength > 1.0e-3) {
65
+ foundPlaneVector = true;
66
+ }
67
+ if (!foundPlaneVector) {
68
+ axis[0] = 0.0;
69
+ axis[1] = 1.0;
70
+ axis[2] = 0.0;
71
+ vtkMath.cross(n, axis, px);
72
+ const pxLength2 = vtkMath.normalize(px);
73
+ if (pxLength2 > 1.0e-3) {
74
+ foundPlaneVector = true;
75
+ }
76
+ }
77
+ if (!foundPlaneVector) {
78
+ axis[0] = 0.0;
79
+ axis[1] = 0.0;
80
+ axis[2] = 1.0;
81
+ vtkMath.cross(n, axis, px);
82
+ vtkMath.normalize(px);
83
+ }
84
+
85
+ // Create second orthogonal axis in polygon plane
86
+ vtkMath.cross(px, n, py);
87
+
88
+ // Generate polygon points
89
+ const theta = 2.0 * Math.PI / numPts;
90
+ const points = [];
91
+ const r = [0, 0, 0];
92
+ const x = [0, 0, 0];
93
+ for (let j = 0; j < numPts; j++) {
94
+ const cosTheta = Math.cos(j * theta);
95
+ const sinTheta = Math.sin(j * theta);
96
+ r[0] = px[0] * cosTheta + py[0] * sinTheta;
97
+ r[1] = px[1] * cosTheta + py[1] * sinTheta;
98
+ r[2] = px[2] * cosTheta + py[2] * sinTheta;
99
+ x[0] = model.center[0] + model.radius * r[0];
100
+ x[1] = model.center[1] + model.radius * r[1];
101
+ x[2] = model.center[2] + model.radius * r[2];
102
+ points.push(x[0], x[1], x[2]);
103
+ }
104
+ newPoints.setData(points);
105
+ output.setPoints(newPoints);
106
+ outData[0] = output;
107
+ };
108
+ }
109
+
110
+ // ----------------------------------------------------------------------------
111
+ // Object factory
112
+ // ----------------------------------------------------------------------------
113
+
114
+ const DEFAULT_VALUES = {
115
+ numberOfSides: 6,
116
+ center: [0.0, 0.0, 0.0],
117
+ normal: [0.0, 0.0, 1.0],
118
+ radius: 0.5,
119
+ generatePolygon: true,
120
+ generatePolyline: true,
121
+ outputPointsPrecision: DesiredOutputPrecision.FLOAT
122
+ };
123
+
124
+ // ----------------------------------------------------------------------------
125
+
126
+ function extend(publicAPI, model, initialValues = {}) {
127
+ Object.assign(model, DEFAULT_VALUES, initialValues);
128
+
129
+ // Build VTK API
130
+ macro.obj(publicAPI, model);
131
+ macro.algo(publicAPI, model, 0, 1);
132
+
133
+ // Build VTK API
134
+ macro.setGet(publicAPI, model, ['numberOfSides', 'radius', 'generatePolygon', 'generatePolyline', 'outputPointsPrecision']);
135
+ macro.setGetArray(publicAPI, model, ['center', 'normal'], 3);
136
+ vtkRegularPolygonSource(publicAPI, model);
137
+ }
138
+
139
+ // ----------------------------------------------------------------------------
140
+
141
+ const newInstance = macro.newInstance(extend, 'vtkRegularPolygonSource');
142
+
143
+ // ----------------------------------------------------------------------------
144
+
145
+ var vtkRegularPolygonSource$1 = {
146
+ newInstance,
147
+ extend
148
+ };
149
+
150
+ export { vtkRegularPolygonSource$1 as default, extend, newInstance };
@@ -13,6 +13,7 @@ import vtkLineSource from './Sources/LineSource.js';
13
13
  import vtkPlaneSource from './Sources/PlaneSource.js';
14
14
  import vtkPlatonicSolidSource from './Sources/PlatonicSolidSource.js';
15
15
  import vtkPointSource from './Sources/PointSource.js';
16
+ import vtkRegularPolygonSource from './Sources/RegularPolygonSource.js';
16
17
  import vtkRTAnalyticSource from './Sources/RTAnalyticSource.js';
17
18
  import vtkSLICSource from './Sources/SLICSource.js';
18
19
  import vtkSphereSource from './Sources/SphereSource.js';
@@ -34,6 +35,7 @@ var Sources = {
34
35
  vtkPlaneSource,
35
36
  vtkPlatonicSolidSource,
36
37
  vtkPointSource,
38
+ vtkRegularPolygonSource,
37
39
  vtkRTAnalyticSource,
38
40
  vtkSLICSource,
39
41
  vtkSphereSource,
@@ -22,6 +22,7 @@ import '../../Filters/Sources/LineSource.js';
22
22
  import '../../Filters/Sources/PlaneSource.js';
23
23
  import '../../Filters/Sources/PlatonicSolidSource.js';
24
24
  import '../../Filters/Sources/PointSource.js';
25
+ import '../../Filters/Sources/RegularPolygonSource.js';
25
26
  import '../../Filters/Sources/RTAnalyticSource.js';
26
27
  import '../../Filters/Sources/SLICSource.js';
27
28
  import '../../Filters/Sources/SphereSource.js';
package/index.d.ts CHANGED
@@ -75,6 +75,7 @@
75
75
  /// <reference path="./Filters/General/TransformPolyDataFilter.d.ts" />
76
76
  /// <reference path="./Filters/General/TriangleFilter.d.ts" />
77
77
  /// <reference path="./Filters/General/TubeFilter.d.ts" />
78
+ /// <reference path="./Filters/Modeling/RibbonFilter.d.ts" />
78
79
  /// <reference path="./Filters/Sources/ArcSource.d.ts" />
79
80
  /// <reference path="./Filters/Sources/Arrow2DSource.d.ts" />
80
81
  /// <reference path="./Filters/Sources/ArrowSource.d.ts" />
@@ -91,6 +92,7 @@
91
92
  /// <reference path="./Filters/Sources/PlatonicSolidSource/Constants.d.ts" />
92
93
  /// <reference path="./Filters/Sources/PlatonicSolidSource.d.ts" />
93
94
  /// <reference path="./Filters/Sources/PointSource.d.ts" />
95
+ /// <reference path="./Filters/Sources/RegularPolygonSource.d.ts" />
94
96
  /// <reference path="./Filters/Sources/SphereSource.d.ts" />
95
97
  /// <reference path="./Filters/Texture/TextureMapToPlane.d.ts" />
96
98
  /// <reference path="./Filters/Texture/TextureMapToSphere.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.16.7",
3
+ "version": "34.17.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",