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

fix for changing opacity based on segment index #1833

Conversation

minimal-scouser
Copy link
Contributor

@minimal-scouser minimal-scouser commented Feb 18, 2025

Context

Fixes #1832

While rendering, segment styles such as opacity, fill etc do not consider active segment based on its index.

Changes & Results

Active segmentationId along with the segmentIndex should determine whether a segment is active or not.

Screen.Recording.2025-02-18.at.10.34.13.PM.mov

Testing

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • [] "OS:
  • [] "Node version:
  • [] "Browser:

Copy link

netlify bot commented Feb 18, 2025

Deploy Preview for cornerstone-3d-docs ready!

Name Link
🔨 Latest commit be42df2
🔍 Latest deploy log https://app.netlify.com/sites/cornerstone-3d-docs/deploys/67b4bcb9904b6e00074f2568
😎 Deploy Preview https://deploy-preview-1833--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 configuration.

@sedghi sedghi merged commit 6bf44cf into cornerstonejs:main Feb 18, 2025
19 checks passed
@stada526
Copy link
Contributor

Thank you for addressing the issue I raised!

@sedghi
Copy link
Member

sedghi commented Feb 21, 2025

I think I messed up by merging this. I thought the opacity was at the segmentation level, but it seems to be segment-specific. Could you please create a pull request to revert this change? My reasoning is that there's only one layer of opacity change at the API level, which is between Segmentations, not within them. If someone needs a different opacity for any active segment, they can use the perSegment configuration.

This PR also cannot get merged, #1836 as it is adding another layer of opacity configuration at api level. There is already API for perSegment configuration

@minimal-scouser @stada526

@minimal-scouser
Copy link
Contributor Author

minimal-scouser commented Feb 21, 2025

doing it. but i don't think perSegment styles are taking effect.

and that is because the perSegment API is available for labelMaps not for contour segments.

contour segments use getSVGStyleForSegment for getting styles

@sedghi

@minimal-scouser minimal-scouser mentioned this pull request Feb 21, 2025
@minimal-scouser
Copy link
Contributor Author

per segment styles are not respected

the original intent itself is not aligned to support perSegment styles

// per segmentation we follow the same active and inactive style properties
// since the target (segmentation) is important not the activeness etc

look at updatedStyles - it is basically the styles set at segmentation level

const currentStyles = this.getStyle(specifier);
let updatedStyles: RepresentationStyle;
if (!viewportId && !segmentationId) {
// Global style setting
updatedStyles = {
...currentStyles,
...styles,
};
} else {
// Per segmentation or per viewport style setting
updatedStyles = this.copyActiveToInactiveIfNotProvided(
{
...currentStyles,
...styles,
},
type
);
}

and here we are assigning the high level styles to segment level style

if (segmentIndex !== undefined) {
// Style for a specific segment
if (!repConfig.perSegment) {
repConfig.perSegment = {};
}
repConfig.perSegment[segmentIndex] = updatedStyles;
} else {
// Style for all segments of the segmentation
repConfig.allSegments = updatedStyles;
}

@sedghi
Copy link
Member

sedghi commented Feb 21, 2025

I think they are working at least in OHIF, since this is the effect we have in OHIF, if you look at SegmentationService in OHIF you will see it

https://viewer-dev.ohif.org/viewer?StudyInstanceUIDs=1.3.6.1.4.1.32722.99.99.62087908186665265759322018723889952421

CleanShot.2025-02-21.at.12.46.30.mp4

see how per segment we apply different thickness

@minimal-scouser
Copy link
Contributor Author

minimal-scouser commented Feb 21, 2025

true. it works for visibility. even in the original example.

but it does not consider fillAlphaInactive, fillOutlineInactive - especially at segment level.

try this,

go to https://viewer-dev.ohif.org/segmentation?StudyInstanceUIDs=2.16.840.1.114362.1.11972228.22789312658.616067305.306.2

create two segments (under same segmentation)

run

cornerstoneTools.segmentation.config.style.getStyle({segmentationId: "Segmentation 1", type: "Contour"})

and this is what you will get

{
    "renderOutline": true,
    "outlineWidthAutoGenerated": 3,
    "outlineWidth": 1,
    "outlineWidthInactive": 1,
    "outlineOpacity": 1,
    "outlineOpacityInactive": 0.85,
    "outlineDashAutoGenerated": "5,3",
    "activeSegmentOutlineWidthDelta": 0,
    "renderFill": false,
    "fillAlpha": 0.5, <---------
    "fillAlphaInactive": 0.3, <----------
    "fillAlphaAutoGenerated": 0.3
}

notice how fillAlpha and fillAlphaInactive have different values yet on the viewport, there is no difference.

but ofcourse, you see a change in the opacity, the moment you create a new segmentation.

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.

[Feature Request] Support per-segment active/inactive styles within a segmentation
3 participants