Skip to content

feat: Add commands to load SEGs for the active viewport + new hp callback for viewport changes#106

Merged
igoroctaviano merged 13 commits intomasterfrom
feat/auto-load-seg
Feb 12, 2026
Merged

feat: Add commands to load SEGs for the active viewport + new hp callback for viewport changes#106
igoroctaviano merged 13 commits intomasterfrom
feat/auto-load-seg

Conversation

@igoroctaviano
Copy link
Collaborator

@igoroctaviano igoroctaviano commented Jan 19, 2026

  • Local: http://localhost:3000/viewer?StudyInstanceUIDs=1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785
  • Preview (from PR): https://deploy-preview-5381--ohif-dev.netlify.app

Context

Changes & Results

Load derived display sets (SEGs / RTSTRUCTs) for the active viewport

  • Adds Cornerstone commands to load derived content for the active viewport:
    • loadSegmentationsForActiveViewport
  • How it works (high level):
    • Finds derived/overlay display sets (e.g. SEG, RTSTRUCT) that reference the currently displayed data.
    • Loads the derived display sets (using auth headers when available).
    • Hydrates/attaches the derived content into the active viewport:
      • segmentations → add segmentation representation to the active viewport

Hanging Protocol: viewport data change callback

  • New HP callback: adds callbacks.onViewportDataChanged?: Command[]
  • Behavior: runs whenever cornerstoneViewportService.EVENTS.VIEWPORT_DATA_CHANGED fires, passing:
    • viewportId
    • viewportData
    • protocol
    • stageIndex
  • Why: enables “react to viewport series/display set changes” workflows (e.g. auto-load overlays whenever the viewport content changes)

HP listener lifecycle + initialization fix

  • Adds attach/detach listener commands to prevent duplicate subscriptions and repeated callback firing across protocol/stage/layout changes.
  • Fixes the onViewportDataInitialized callback execution so the configured command list runs correctly and the subscription is cleaned up.

Docs

  • Documents onViewportDataChanged in:
    • platform/docs/docs/platform/extensions/modules/hpModule.md
    • platform/docs/versioned_docs/version-3.11/platform/extensions/modules/hpModule.md

Testing

  • Open:
    • http://localhost:3000/viewer?StudyInstanceUIDs=1.3.6.1.4.1.14519.5.2.1.1706.8374.643249677828306008300337414785
    • (or) https://deploy-preview-5381--ohif-dev.netlify.app
  • Derived load commands
    • Run loadSegmentationsForActiveViewport and verify derived SEG/RTSTRUCT overlays get loaded and applied to the active viewport.
  • HP callback
    • Configure a HP with callbacks.onViewportDataChanged: [...] that runs one of the new load commands.
    • Trigger a viewport data change (e.g. swap series/display set in a viewport).
    • Verify the callback runs and derived data loads for the updated viewport.

Checklist

PR

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

Suggested PR title

  • feat(Cornerstone): load derived display sets for active viewport

(or if you want to emphasize the HP API)

  • feat(HangingProtocol): add onViewportDataChanged callback

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

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

Tested Environment

  • OS:
  • Node version:
  • Browser:

@igoroctaviano igoroctaviano changed the title feat: Add commands to load SEGs and SRs for the active viewport + new hp callback for viewport changes feat: Add commands to load SEGs for the active viewport + new hp callback for viewport changes Jan 19, 2026
@igoroctaviano igoroctaviano requested a review from fedorov January 19, 2026 22:49
@fedorov
Copy link
Member

fedorov commented Jan 19, 2026

Igor, how could I test it using GitHub deploy workflow? Can I just pull from this repo instead of upstream, or there's more to be done?

@igoroctaviano
Copy link
Collaborator Author

Igor, how could I test it using GitHub deploy workflow? Can I just pull from this repo instead of upstream, or there's more to be done?

Run the action ohif/deploy-v3-with-add-ons

@igoroctaviano
Copy link
Collaborator Author

@fedorov could you test this one?

@fedorov
Copy link
Member

fedorov commented Feb 12, 2026

I tested and it works fine - please merge!

@igoroctaviano igoroctaviano merged commit a0aceb2 into master Feb 12, 2026
1 check failed
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] Make it possible to load segmentation automatically

2 participants