import macro from 'vtk.js/Sources/macros'; import vtkCell from 'vtk.js/Sources/Common/DataModel/Cell';
export const InitLink = { ncells: 0, cells: null, };
function resize(model, sz) { let newSize = sz; if (sz >= model.array.length) { newSize += model.array.length; }
while (newSize > model.array.length) model.array.push({ ncells: 0, cells: null, }); model.array.length = newSize; }
function vtkCellLinks(publicAPI, model) { model.classHierarchy.push('vtkCellLinks');
publicAPI.buildLinks = (data) => { const numPts = data.getPoints().getNumberOfPoints(); const numCells = data.getNumberOfCells();
const linkLoc = new Uint32Array(numPts);
if (data.isA('vtkPolyData')) { for (let cellId = 0; cellId < numCells; ++cellId) { const { cellPointIds } = data.getCellPoints(cellId); cellPointIds.forEach((cellPointId) => { publicAPI.incrementLinkCount(cellPointId); }); }
publicAPI.allocateLinks(numPts); model.maxId = numPts - 1;
for (let cellId = 0; cellId < numCells; ++cellId) { const { cellPointIds } = data.getCellPoints(cellId); cellPointIds.forEach((cellPointId) => { publicAPI.insertCellReference( cellPointId, linkLoc[cellPointId]++, cellId ); }); } } else { for (let cellId = 0; cellId < numCells; cellId++) { const cell = vtkCell.newInstance(); cell.getPointsIds().forEach((cellPointId) => { publicAPI.incrementLinkCount(cellPointId); }); }
publicAPI.allocateLinks(numPts); model.maxId = numPts - 1;
for (let cellId = 0; cellId < numCells; ++cellId) { const cell = vtkCell.newInstance(); cell.getPointsIds().forEach((cellPointId) => { publicAPI.insertCellReference( cellPointId, linkLoc[cellPointId]++, cellId ); }); } } };
publicAPI.allocate = (numLinks, ext = 1000) => { model.array = Array(numLinks) .fill() .map(() => ({ ncells: 0, cells: null, })); model.extend = ext; model.maxId = -1; };
publicAPI.initialize = () => { model.array = null; };
publicAPI.getLink = (ptId) => model.array[ptId];
publicAPI.getNcells = (ptId) => model.array[ptId].ncells;
publicAPI.getCells = (ptId) => model.array[ptId].cells;
publicAPI.insertNextPoint = (numLinks) => { model.array.push({ ncells: numLinks, cells: Array(numLinks) }); ++model.maxId; };
publicAPI.insertNextCellReference = (ptId, cellId) => { model.array[ptId].cells[model.array[ptId].ncells++] = cellId; };
publicAPI.deletePoint = (ptId) => { model.array[ptId].ncells = 0; model.array[ptId].cells = null; };
publicAPI.removeCellReference = (cellId, ptId) => { model.array[ptId].cells = model.array[ptId].cells.filter( (cell) => cell !== cellId ); model.array[ptId].ncells = model.array[ptId].cells.length; };
publicAPI.addCellReference = (cellId, ptId) => { model.array[ptId].cells[model.array[ptId].ncells++] = cellId; };
publicAPI.resizeCellList = (ptId, size) => { model.array[ptId].cells.length = size; };
publicAPI.squeeze = () => { resize(model, model.maxId + 1); };
publicAPI.reset = () => { model.maxId = -1; };
publicAPI.deepCopy = (src) => { model.array = [...src.array]; model.extend = src.extend; model.maxId = src.maxId; };
publicAPI.incrementLinkCount = (ptId) => { ++model.array[ptId].ncells; };
publicAPI.allocateLinks = (n) => { for (let i = 0; i < n; ++i) { model.array[i].cells = new Array(model.array[i].ncells); } };
publicAPI.insertCellReference = (ptId, pos, cellId) => { model.array[ptId].cells[pos] = cellId; }; }
const DEFAULT_VALUES = { array: null, maxId: 0, extend: 0, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
vtkCellLinks(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkCellLinks');
export default { newInstance, extend };
|