Skip to content

Commit

Permalink
fix(imjoypluginapi): refactor the run function to support setting mul…
Browse files Browse the repository at this point in the history
…tiple data types
  • Loading branch information
bnmajor committed Jan 24, 2023
1 parent 591b90a commit f8303bf
Showing 1 changed file with 22 additions and 31 deletions.
53 changes: 22 additions & 31 deletions src/ImJoyPluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,44 @@ class ImJoyPluginAPI {
}

async run(ctx) {
if (ctx.data && ctx.data.image) {
if (ctx.config) {
const multiscaleImage = await itkVtkViewer.utils.toMultiscaleSpatialImage(
if (ctx.data) {
let multiscaleImage = null
let is2D = false
if (ctx.data.image) {
multiscaleImage = await itkVtkViewer.utils.toMultiscaleSpatialImage(
ctx.data.image,
false,
ctx.config.maxConcurrency
)
const is2D = multiscaleImage.imageType.dimension === 2
this.viewer = await itkVtkViewer.createViewer(container, {
image: multiscaleImage,
labelImage: ctx.data?.labelImage,
pointSets: null,
geometries: null,
use2D: is2D,
rotate: false,
config: ctx.config,
})
} else {
await this.setImage(ctx.data.image, ctx.config.maxConcurrency)
is2D = multiscaleImage.imageType.dimension === 2
}
} else if (ctx.data && ctx.data.pointSets) {
if (ctx.config) {
let pointSets = ctx.data.pointSets
let pointSets = null
if (ctx.data.pointSets) {
pointSets = ctx.data.pointSets
if (!Array.isArray(pointSets)) pointSets = [pointSets]
pointSets = pointSets.map(points =>
itkVtkViewer.utils.ndarrayToPointSet(points)
)
this.viewer = await itkVtkViewer.createViewer(container, {
image: null,
}
if (ctx.config) {
const data = {
image: multiscaleImage,
labelImage: ctx.data?.labelImage,
pointSets: pointSets,
geometries: null,
use2D: is2D,
rotate: false,
config: ctx.config,
})
}
this.viewer = await itkVtkViewer.createViewer(container, data)
} else {
await this.setPointSets(ctx.data.pointSets)
if (multiscaleImage) {
await this.setImage(ctx.data.image, ctx.config.maxConcurrency)
}
if (pointSets) {
await this.setPointSets(ctx.data.pointSets)
}
}
} else if (ctx.data && ctx.config) {
this.viewer = await itkVtkViewer.createViewer(container, {
image: null,
labelImage: null,
pointSets: null,
geometries: null,
rotate: false,
config: ctx.config,
})
}
}

Expand Down

0 comments on commit f8303bf

Please sign in to comment.