All files / core/src/utilities transformWorldToIndex.ts

75% Statements 3/4
100% Branches 0/0
50% Functions 1/2
75% Lines 3/4

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                      7117x 7117x   7117x            
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;
}
 
export function transformWorldToIndexContinuous(imageData, worldPos: Point3) {
  return imageData.worldToIndex(worldPos);
}