Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x | import macro from 'vtk.js/Sources/macros'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder'; import * as vtkMath from 'vtk.js/Sources/Common/Core/Math/'; // ---------------------------------------------------------------------------- // vtkCircleSource methods // ---------------------------------------------------------------------------- function vtkCircleSource(publicAPI, model) { // Set our classname model.classHierarchy.push('vtkCircleSource'); function requestData(inData, outData) { if (model.deleted) { return; } let dataset = outData[0]; // Points const points = macro.newTypedArray(model.pointType, model.resolution * 3); // Lines/cells // [# of points in line, vert_index_0, vert_index_1, ..., vert_index_0] const edges = new Uint32Array(model.resolution + 2); edges[0] = model.resolution + 1; // generate polydata const angle = (2.0 * Math.PI) / model.resolution; for (let i = 0; i < model.resolution; i++) { const x = model.center[0]; const y = model.radius * Math.cos(i * angle) + model.center[1]; const z = model.radius * Math.sin(i * angle) + model.center[2]; points.set([x, y, z], i * 3); edges[i + 1] = i; } // connect endpoints edges[edges.length - 1] = edges[1]; dataset = vtkPolyData.newInstance(); dataset.getPoints().setData(points, 3); if (model.lines) { dataset.getLines().setData(edges, 1); } if (model.face) { dataset.getPolys().setData(edges, 1); } // translate an eventual center different to [0, 0, 0] to ensure rotation is correct vtkMatrixBuilder .buildFromRadian() .translate(...model.center) .rotateFromDirections([1, 0, 0], model.direction) .translate(...vtkMath.multiplyScalar([...model.center], -1)) .apply(points); // Update output outData[0] = dataset; } // Expose methods publicAPI.requestData = requestData; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- function defaultValues(initialValues) { return { face: true, center: [0, 0, 0], lines: false, direction: [1, 0, 0], pointType: 'Float64Array', radius: 1.0, resolution: 6, ...initialValues, }; } // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, defaultValues(initialValues)); // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['radius', 'resolution', 'lines', 'face']); macro.setGetArray(publicAPI, model, ['center', 'direction'], 3); macro.algo(publicAPI, model, 0, 1); vtkCircleSource(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkCircleSource'); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |