cornerstonejs / cornerstone3D

Cornerstone is a set of JavaScript libraries that can be used to build web-based medical imaging applications. It provides a framework to build radiology applications such as the OHIF Viewer.
https://cornerstonejs.org
MIT License
570 stars 290 forks source link

multiple segmentation representations warning logged incorrectly #1510

Open LeoReubelt opened 1 week ago

LeoReubelt commented 1 week ago

Describe the Bug

'Multiple segmentation representations detected for this tool group. The first one will be used.' is logged when it shouldn't be.

In the function below, which is in ContourSegmentationBaseTool.ts, segmentationState.getSegmentationRepresentations(this.toolGroupId).length > 1 should be validSegmentationRepresentations.length > 1

  private _getSegmentationRepresentation(segmentationId) {
    const segmentationRepresentations =
      segmentationState.getSegmentationRepresentations(this.toolGroupId);

    const validSegmentationRepresentations = segmentationRepresentations.filter(
      (representation) => representation.segmentationId === segmentationId
    );

    if (!validSegmentationRepresentations) {
      console.warn(
        `No segmentation representation found for toolGroupId: ${this.toolGroupId}`
      );
      return;
    }

    if (
      segmentationState.getSegmentationRepresentations(this.toolGroupId)
        .length > 1
    ) {
      console.warn(
        'Multiple segmentation representations detected for this tool group. The first one will be used.'
      );
    }

    return validSegmentationRepresentations[0];
  }

Steps to Reproduce

  1. Add multiple segmentation representations to a single toolgroup id.

The current behavior

Despite having different segmentation ids, adding multiple segmentation representations causes the above warning to be logged repeatedly.

The expected behavior

The warning should only be logged if there are more than one segmentation representation with the same segmentation id.

OS

macOS 15.0.1

Node version

v16.14.0

Browser

Version 129.0.6668.103

sedghi commented 3 days ago

The segmentation system and its representations have been redesigned to improve architecture. Check the migration guides at https://www.cornerstonejs.org/docs/migration-guides/2x/tools