Skip to content

Commit

Permalink
Merge pull request #724 from bnmajor/fetch-roi-info
Browse files Browse the repository at this point in the history
Fetch roi info
  • Loading branch information
thewtex authored Dec 6, 2023
2 parents 9ee72ab + 9312463 commit bfb2144
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ImJoyPluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ class ImJoyPluginAPI {
getCompareImages(name) {
return this.viewer.getCompareImages(name)
}

getLoadedScale(scale) {
return this.viewer.getLoadedScale(scale)
}

getCroppedImageWorldBounds() {
return this.viewer.getCroppedImageWorldBounds()
}

async getCroppedIndexBounds(scale) {
return await this.viewer.getCroppedIndexBounds(scale)
}
}

export default ImJoyPluginAPI
30 changes: 30 additions & 0 deletions src/createViewer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mat4 } from 'gl-matrix'
import { inspect } from '@xstate/inspect'
import { interpret } from 'xstate'

Expand All @@ -13,11 +14,13 @@ import hex2rgb from './UserInterface/hex2rgb'
import ViewerStore from './ViewerStore'

import toMultiscaleSpatialImage from './IO/toMultiscaleSpatialImage'
import { worldBoundsToIndexBounds } from './IO/MultiscaleSpatialImage'
import viewerMachineOptions from './viewerMachineOptions'
import createViewerMachine from './createViewerMachine'
import ViewerMachineContext from './Context/ViewerMachineContext'
import {
addCroppingPlanes,
getCropWidgetBounds,
updateCroppingParameters,
} from './Rendering/VTKJS/Main/croppingPlanes'

Expand Down Expand Up @@ -1254,6 +1257,33 @@ const createViewer = async (
return context.maxConcurrency
}

publicAPI.getLoadedScale = name => {
const imageName = name ?? context.images.selectedName
const actorContext = context.images.actorContext.get(imageName)
return actorContext.loadedScale
}

publicAPI.getCroppedImageWorldBounds = () => {
return getCropWidgetBounds(context)
}

publicAPI.getCroppedIndexBounds = async (scale, name) => {
const imageName = name ?? context.images.selectedName
const actorContext = context.images.actorContext.get(imageName)
if (typeof scale === 'undefined' || scale < 0) {
scale = actorContext.loadedScale
}
const image = actorContext.image
const bounds = getCropWidgetBounds(context)
const indexToWorld = await image.scaleIndexToWorld(scale)
const fullIndexBounds = image.getIndexBounds(scale)
return worldBoundsToIndexBounds({
bounds,
fullIndexBounds,
worldToIndex: mat4.invert([], indexToWorld),
})
}

addKeyboardShortcuts(context.uiContainer, service)

// must come before moving/main image
Expand Down

0 comments on commit bfb2144

Please sign in to comment.