Skip to content

[Bug] labelmap renderOutline failed in 2.x #1862

Open
@Qwd2017

Description

@Qwd2017

Describe the Bug

In cs2.x, we create a custom labelmap representation to render, we cannot configure to show only outlines, but it's worked in cs3d 1.x.

Steps to Reproduce

Here is code for testing with cs3d2.x:

export function createRandomRep() {
 //  primaryMprVolumeId is cached image volume of CT.
  const refvol = cache.getVolume(primaryMprVolumeId);
  const refmeta = cache.getVolume(primaryMprVolumeId)?.metadata;

  const rows = 100;
  const cols = 100;
  const slices = 10;

  const scalar = new Uint16Array(rows * cols * slices);

  const xy = rows * cols;

 // random scalar
  for (let z = 0; z < slices; z++) {
    for (let y = 0; y < rows; y++) {
      for (let x = 0; x < cols; x++) {
        const value = y % 4 == 0 ? 0 : 1;
        scalar[x + y * cols + z * xy] = value;
      }
    }
  }

  volumeLoader.createLocalVolume(volumeId, {
    metadata: {
      BitsAllocated: 16,
      BitsStored: 16,
      SamplesPerPixel: 1,
      HighBit: 15,
      PhotometricInterpretation: refmeta?.PhotometricInterpretation!,
      PixelRepresentation: refmeta?.PixelRepresentation!,
      Modality: "RTDOSE",
      SeriesInstanceUID: "1.1.1.1.1.1.1.1",
      ImageOrientationPatient: refmeta?.ImageOrientationPatient!,
      PixelSpacing: [3, 3],
      FrameOfReferenceUID: refmeta?.FrameOfReferenceUID!,
      Columns: cols,
      Rows: rows,
      voiLut: [
        {
          windowCenter: 0,
          windowWidth: 0,
        },
      ],
      VOILUTFunction: "LINEAR",
    },
    dimensions: [rows, cols, slices],
    spacing: [3, 3, 3],
    origin: refvol?.origin!,
    direction: refvol?.direction!,
    scalarData: scalar,
  });

  const colorTables: Types.Color[] = [];

  const segments: {
    [segmentIndex: number]: Partial<toolTypes.Segment>;
  } = {};

 // random colors
  for (let i = 0; i < rows; i++) {
    colorTables.push([255, 255 - i, 128 + i, 255]);
  }

  for (let i = 0; i < rows; i++) {
    segments[i + 1] = {
      segmentIndex: i + 1,
      active: true,
      label: `${i + 1}`,
      locked: false,
    }
  }

  const lutindex = 8888;
  segmentation.config.color.addColorLUT(colorTables, lutindex);

  segmentation.addSegmentations([
    {
      segmentationId: volumeId,
      representation: {
        type: toolEnums.SegmentationRepresentations.Labelmap,
        data: {
          volumeId: volumeId,
        },
      },

      // config: {
      //   segments: segments
      // }
    },
  ]);

  segmentation.addLabelmapRepresentationToViewport(axialPrimaryId, [
    {
      segmentationId: volumeId,
      config: {
        colorLUTOrIndex: lutindex,
      },
    },
  ]);

  segmentation.config.style.setStyle(
    {
      viewportId: axialPrimaryId,
      segmentationId: volumeId,
      type: toolEnums.SegmentationRepresentations.Labelmap,
    },
    {
      **// not worked!!! **
      renderOutline: true,
      renderOutlineInactive: true,
      renderFill: true,
      renderFillInactive: true,
      fillAlpha: 0.1,
      fillAlphaInactive: 0.1,
      outlineWidth: 1,
      outlineWidthInactive: 1,
      outlineOpacity: 1,
      outlineOpacityInactive: 1,
    }
  );

  segmentation.triggerSegmentationEvents.triggerSegmentationDataModified(
    volumeId
  );
}

Here is code for testing with cs3d1.x,it's worked!

export async function createRandomRep() {
  const refvol = cache.getVolume(primaryMprVolumeId);
  const refmeta = cache.getVolume(primaryMprVolumeId)?.metadata;

  const rows = 100;
  const cols = 100;
  const slices = 10;

  const scalar = new Uint16Array(rows * cols * slices);

  const xy = rows * cols;

  for (let z = 0; z < slices; z++) {
    for (let y = 0; y < rows; y++) {
      for (let x = 0; x < cols; x++) {
        const value = y % 4 == 0 ? 0 : 1;
        scalar[x + y * cols + z * xy] = value;
      }
    }
  }

  await volumeLoader.createLocalVolume({
    metadata: {
      BitsAllocated: 16,
      BitsStored: 16,
      SamplesPerPixel: 1,
      HighBit: 15,
      PhotometricInterpretation: refmeta?.PhotometricInterpretation!,
      PixelRepresentation: refmeta?.PixelRepresentation!,
      Modality: "RTDOSE",
      SeriesInstanceUID: "1.1.1.1.1.1.1.1",
      ImageOrientationPatient: refmeta?.ImageOrientationPatient!,
      PixelSpacing: [3, 3],
      FrameOfReferenceUID: refmeta?.FrameOfReferenceUID!,
      Columns: cols,
      Rows: rows,
      voiLut: [
        {
          windowCenter: 0,
          windowWidth: 0,
        },
      ],
      VOILUTFunction: "LINEAR",
    },
    dimensions: [rows, cols, slices],
    spacing: [3, 3, 3],
    origin: refvol?.origin!,
    direction: refvol?.direction!,
    scalarData: scalar,
  }, volumeId);

  const vv = cache.getVolume(volumeId);

  const colorTables: Types.Color[] = [];


  for (let i = 0; i < rows; i++) {
    colorTables.push([255, 255 - i, 128 + i, 255]);
  }

  const lutindex = 8888;
  segmentation.config.color.addColorLUT(colorTables, lutindex);

  segmentation.addSegmentations([
    {
      segmentationId: volumeId,
      representation: {
        type: toolEnums.SegmentationRepresentations.Labelmap,
        data: {
          volumeId: volumeId,
        },
      },
    },
  ]);

  segmentation.addSegmentationRepresentations(mprToolGroupId, [
    {
      segmentationId: volumeId,
      type: toolEnums.SegmentationRepresentations.Labelmap,
      options: {
        segmentationRepresentationUID: volumeId,
        colorLUTOrIndex: lutindex
      }
    },
  ]);

  segmentation.config.setSegmentationRepresentationSpecificConfig(
    mprToolGroupId,
    volumeId,
    {
      LABELMAP: {
        renderOutline: true,
        renderFill: false,
        renderFillInactive: false,
        outlineWidthActive: 2,
        outlineWidthInactive: 2,
        fillAlpha: 0.5,
        fillAlphaInactive: 0.5,
      },
    }
  );

  segmentation.triggerSegmentationEvents.triggerSegmentationDataModified(
    volumeId
  );
}

The current behavior

The outline of labelmap is not displayed!

The expected behavior

The outline of labelmap is displayed!

OS

Windows 10

Node version

v18.16.0

Browser

Chrome 133.0.6943.127

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions