All files / packages/tools/src/utilities/contours/interpolation createPolylineToolData.ts

100% Statements 4/4
33.33% Branches 1/3
100% Functions 1/1
100% Lines 4/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 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                                      7x             7x                 7x                                                     7x    
import { Types, utilities as csUtils } from '@cornerstonejs/core';
import { InterpolationROIAnnotation } from '../../../types/ToolSpecificAnnotationTypes';
 
/**
 * Creates a new annotation instance given the tool data, based on the referenced tool
 * data type.
 * Note that this object takes ownership of the polyline and handlePoints data, that is,
 * directly assigns them internally to the result.
 *
 * @param polyline - data for the polyline, owned hereafter by the annotation
 * @param handlePoints - data for the edit handles, if any, owned hereafter by the annotation
 * @param referencedToolData - for base data for the new tool
 
 */
export default function createPolylineToolData(
  polyline,
  handlePoints,
  referencedToolData
) {
  const annotation: InterpolationROIAnnotation = csUtils.deepMerge(
    {
      data: {},
      metadata: {},
    },
    referencedToolData
  );
  Object.assign(annotation, {
    highlighted: false,
    invalidated: true,
    autoGenerated: true,
    annotationUID: undefined,
    cachedStats: {},
    childAnnotationUIDs: [],
    parentAnnotationUID: undefined,
  });
  Object.assign(annotation.data, {
    handles: {
      points: handlePoints.points || handlePoints || [],
      /**
       * The interpolation sources contains the source points used for interpolating
       * to generate the new handles.  This allows performing other types of
       * interpolation to generate the new handles, such as livewire.
       */
      interpolationSources: handlePoints.sources,
      activeHandleIndex: null,
      textBox: {
        hasMoved: false,
        worldPosition: <Types.Point3>[0, 0, 0],
        worldBoundingBox: {
          topLeft: <Types.Point3>[0, 0, 0],
          topRight: <Types.Point3>[0, 0, 0],
          bottomLeft: <Types.Point3>[0, 0, 0],
          bottomRight: <Types.Point3>[0, 0, 0],
        },
      },
    },
    contour: {
      ...referencedToolData.data.contour,
      polyline,
    },
  });
 
  return annotation;
}