All files / packages/core/src/utilities transformWorldToIndex.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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                      153x 153x   153x    
import type Point3 from '../types/Point3';
 
/**
 * Given an imageData object and a point in physical space, return the index of the
 * voxel that contains the point. TODO: this should be pushed to vtk upstream.
 * @param imageData - The image data object.
 * @param physicalPoint - The point in physical space that you want to transform to
 * index space.
 * @returns An array of integers.
 */
export default function transformWorldToIndex(imageData, worldPos: Point3) {
  const continuousIndex = imageData.worldToIndex(worldPos);
  const index = continuousIndex.map(Math.round);
 
  return index;
}