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 105 106 107 108 109 110 111 112 113 114 115 116 117 | 24x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 832x 832x 832x 832x 832x 832x 23x 832x 832x 832x 832x 23x 23x 23x 23x 23x 24x 1x 24x 24x 24x 24x 24x 24x 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'; // ---------------------------------------------------------------------------- // vtkConeSource methods // ---------------------------------------------------------------------------- function vtkConeSource(publicAPI, model) { // Set our className model.classHierarchy.push('vtkConeSource'); function requestData(inData, outData) { Iif (model.deleted) { return; } let dataset = outData[0]; const angle = (2 * Math.PI) / model.resolution; const xbot = -model.height / 2.0; const numberOfPoints = model.resolution + 1; const cellArraySize = 4 * model.resolution + 1 + model.resolution; // Points let pointIdx = 0; const points = macro.newTypedArray(model.pointType, numberOfPoints * 3); // Cells let cellLocation = 0; const polys = new Uint32Array(cellArraySize); // Add summit point points[0] = model.height / 2.0; points[1] = 0.0; points[2] = 0.0; // Create bottom cell if (model.capping) { polys[cellLocation++] = model.resolution; } // Add all points for (let i = 0; i < model.resolution; i++) { pointIdx++; points[pointIdx * 3 + 0] = xbot; points[pointIdx * 3 + 1] = model.radius * Math.cos(i * angle); points[pointIdx * 3 + 2] = model.radius * Math.sin(i * angle); // Add points to bottom cell in reverse order if (model.capping) { polys[model.resolution - cellLocation++ + 1] = pointIdx; } } // Add all triangle cells for (let i = 0; i < model.resolution; i++) { polys[cellLocation++] = 3; polys[cellLocation++] = 0; polys[cellLocation++] = i + 1; polys[cellLocation++] = i + 2 > model.resolution ? 1 : i + 2; } // Apply transformation to the points coordinates vtkMatrixBuilder .buildFromRadian() .translate(...model.center) .rotateFromDirections([1, 0, 0], model.direction) .apply(points); dataset = vtkPolyData.newInstance(); dataset.getPoints().setData(points, 3); dataset.getPolys().setData(polys, 1); // Update output outData[0] = dataset; } // Expose methods publicAPI.requestData = requestData; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- const DEFAULT_VALUES = { height: 1.0, radius: 0.5, resolution: 6, center: [0, 0, 0], direction: [1.0, 0.0, 0.0], capping: true, pointType: 'Float64Array', }; // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['height', 'radius', 'resolution', 'capping']); macro.setGetArray(publicAPI, model, ['center', 'direction'], 3); macro.algo(publicAPI, model, 0, 1); vtkConeSource(publicAPI, model); } // ---------------------------------------------------------------------------- export const newInstance = macro.newInstance(extend, 'vtkConeSource'); // ---------------------------------------------------------------------------- export default { newInstance, extend }; |