Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Segmentation): Add contour representation for segmentations #384

Merged
merged 15 commits into from
Feb 1, 2023

Conversation

sedghi
Copy link
Member

@sedghi sedghi commented Jan 25, 2023

Continuing on the plan to add multiple representations for a segmentation, this PR adds the contour representation (read about representations here)

This PR add new geometryLoader which is supposed to deal with loading geometries and cache them. As the first geometry, this PR introduces contourSets and contours.

Since usually a set of contours represents an entity, a contourSet exists

image

Adding a contour representation is similar to adding a labelmap

  1. First the geometry (in labelmap, the volume) should get added. For each contourSet a separate geometry is cached. This is a design decision that is intended to enabled converting of the geometry types to each other (contour -> closed surface and vice versa). As seen below each contourSet will get a geometryId that can later be used to construct a segmentation.
const promises = contourSets.map((contourSet) => {
  return geometryLoader.createAndCacheGeometry(contourSet.id, {
    type: GeometryType.CONTOUR,
    geometryData: contourSet as Types.PublicContourSetData,
  });
});

await Promise.all(promises);
  1. A segmentation can get created
// Add the segmentations to state
  segmentation.addSegmentations([
    {
      segmentationId,
      representation: {
        // The type of segmentation
        type: csToolsEnums.SegmentationRepresentations.Contour,
        // The actual segmentation data, in the case of contour geometry
        //  this is a reference to the geometry data
        data: {
          geometryIds: contourSets.map({id}=>id)
        },
      },
    },
  ]);
  1. A segmentation representation should get added
 await segmentation.addSegmentationRepresentations(toolGroupId, [
    {
      segmentationId,
      type: csToolsEnums.SegmentationRepresentations.Contour,
    },
  ]);

Demo

https://deploy-preview-384--cornerstone-3d-docs.netlify.app/live-examples/contoursegmentationrepresentation

PS: Kudos to @rodrigobasilio2022 for polydata experimentation with contours

@netlify
Copy link

netlify bot commented Jan 25, 2023

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit 6f6c5fa
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/63dabc8a2f25d6000826ad73
😎 Deploy Preview https://deploy-preview-384--cornerstone-3d-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@sedghi sedghi changed the title [Draft] feat: Add contour representation in for segmentations [Draft] feat: Add contour representation for segmentations Jan 25, 2023
@sedghi sedghi marked this pull request as ready for review January 26, 2023 04:30
@sedghi sedghi changed the title [Draft] feat: Add contour representation for segmentations feat: Add contour representation for segmentations Jan 26, 2023
@sedghi sedghi requested review from jbocce and wayfarer3130 January 26, 2023 04:38
@sedghi sedghi changed the title feat: Add contour representation for segmentations feat(Segmentation): Add contour representation for segmentations Jan 26, 2023
@@ -536,7 +553,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
renderer
);

vtkCamera.setIsPerformingCoordinateTransformation(false);
vtkCamera.setIsPerformingCoordinateTransformation?.(false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be missing something, but I am trying to understand how setIsPerformingCoordinateTransformation is ever null such that the ?. is needed. Plesase help me here - what am I missing? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a custom method we add to our custom camera, so it might be possible that the other camera (vtkCamera) is used and hence we don't have it

@@ -483,6 +500,107 @@ function vtkStreamingOpenGLVolumeMapper(publicAPI, model) {
// mat3.transpose(keyMats.normalMatrix, keyMats.normalMatrix);
}
}

let lightNum = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you extract this into a separate function, that you document what the behaviour is? I THINK I almost understand what is going on here, but it feels like separating this into a function with it's own function comment block would actually make it understandable and sufficiently documented that one could fix things later. Otherwise it is close to read only code after committed.

Copy link
Member Author

@sedghi sedghi Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vtk.js source code we copied here (helps to keep it this way for future diffs). When we upgrade to vtk.js 26.x and one bug that I worked on is fixed, we can completely remove this setCameraShaderParameters

return this.getPointsInAContour(contourIndex).length;
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still want to keep these commented line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I guess it shows what is the overal plan

Copy link
Collaborator

@jbocce jbocce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sedghi. The changes overall look good. I like how contours parallel the label map segments. I have a bunch of comments, but nothing earth shattering. Looking forward to seeing a running example.

Copy link
Collaborator

@wayfarer3130 wayfarer3130 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the one comment to add a comment on the contour set, it looks good to me.

Copy link
Collaborator

@jbocce jbocce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment change should be done. Consider the others.

packages/core/src/utilities/actorCheck.ts Outdated Show resolved Hide resolved
packages/core/src/utilities/actorCheck.ts Outdated Show resolved Hide resolved
packages/core/src/RenderingEngine/Viewport.ts Show resolved Hide resolved
@sedghi sedghi force-pushed the feat/contour-representation branch from 0fb6b02 to 1f84a83 Compare February 1, 2023 13:57
* @returns A boolean value.
*/
export function isImageActor(actorEntry: Types.ActorEntry): boolean {
return (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing the outer parentheses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the prettier, so we can discuss it later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok np...

@@ -185,6 +185,10 @@
"doubleClickWithStackAnnotationTools": {
"name": "Double Click With Stack Annotation Tools",
"description": "Demonstrates double click detection before/during/after using various annotation tools on a stack viewport."
},
"contourSegmentationRepresentation": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to move this next to the label map example?

Copy link
Collaborator

@jbocce jbocce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining feedback is optional. Good stuff!

@sedghi sedghi force-pushed the feat/contour-representation branch from 1f84a83 to d9cd7a8 Compare February 1, 2023 18:49
@sedghi sedghi merged commit 541a351 into main Feb 1, 2023
@Ouwen
Copy link
Contributor

Ouwen commented Feb 7, 2023

Hey not sure if this is appropriate forum for this, but just wanted to say that I really appreciate the level of documentation for this PR as it made it quite straightforward understand the design choice.

Awesome work on this!

@longuto
Copy link

longuto commented Jul 26, 2023

How did the contourSets data come from ?

@sedghi sedghi deleted the feat/contour-representation branch January 22, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants