From 9bcb131e60dbed15927643e7dc68f4d67e6ec54c Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Wed, 3 Jun 2020 15:56:57 -0400 Subject: [PATCH] fix(Cutter): Incorrect cell array traversal Cells are not guaranteed to have the same number of vertices as other cells in the array. --- Sources/Filters/Core/Cutter/index.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Filters/Core/Cutter/index.js b/Sources/Filters/Core/Cutter/index.js index dfed0257608..7d7fd986515 100644 --- a/Sources/Filters/Core/Cutter/index.js +++ b/Sources/Filters/Core/Cutter/index.js @@ -55,22 +55,24 @@ function vtkCutter(publicAPI, model) { // Loop over all cells; get scalar values for all cell points // and process each cell. /* eslint-disable no-continue */ + let cellOffset = 0; + let prevCellSize = -1; for (let cellId = 0; cellId < numCells; cellId++) { - const nbPointsInCell = dataCell[0]; + cellOffset += prevCellSize + 1; // account for length of cell + + const nbPointsInCell = dataCell[cellOffset]; + prevCellSize = nbPointsInCell; + // Check that cells have at least 3 points if (nbPointsInCell <= 2) { continue; } + const nextCellOffset = cellOffset + 1 + nbPointsInCell; // Get associated scalar of points that constitute the current cell const cellPointsScalars = []; - const valuesInCell = nbPointsInCell + 1; // first value is size let pointIndex; - for ( - let i = valuesInCell * cellId + 1; - i < valuesInCell * (cellId + 1); - i++ - ) { + for (let i = cellOffset + 1; i < nextCellOffset; i++) { pointIndex = dataCell[i]; cellPointsScalars.push(model.cutScalars[pointIndex]); } @@ -94,11 +96,7 @@ function vtkCutter(publicAPI, model) { // Get id of points that constitute the current cell const cellPointsID = []; - for ( - let i = valuesInCell * cellId + 1; - i < valuesInCell * (cellId + 1); - i++ - ) { + for (let i = cellOffset + 1; i < nextCellOffset; i++) { cellPointsID.push(dataCell[i]); }