-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace webworker-promise with comlink
webworker-promise's package esm export is not correct. This causes issues with vite. The package is deprecated.
- Loading branch information
Showing
24 changed files
with
493 additions
and
281 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,58 @@ | ||
import registerWebworker from 'webworker-promise/lib/register.js' | ||
import * as Comlink from 'comlink' | ||
|
||
import ITKConfig from './itk-config.js' | ||
import PipelineOutput from '../../pipeline/PipelineOutput.js' | ||
import PipelineInput from '../../pipeline/PipelineInput.js' | ||
import MeshToPolyDataPipelineResult from './mesh-to-poly-data-pipeline-result.js' | ||
import PolyDataToMeshPipelineResult from './poly-data-to-mesh-pipeline-result.js' | ||
import ReadImagePipelineResult from './read-image-pipeline-result.js' | ||
import WriteImagePipelineResult from './write-image-pipeline-result.js' | ||
import ReadMeshPipelineResult from './read-mesh-pipeline-result.js' | ||
import WriteMeshPipelineResult from './write-mesh-pipeline-result.js' | ||
import RunPipelineWorkerResult from './run-pipeline-worker-result.js' | ||
import loadPipelineModule from './load-pipeline-module.js' | ||
import loadImageIOPipelineModule from './load-image-io-pipeline-module.js' | ||
import loadMeshIOPipelineModule from './load-mesh-io-pipeline-module.js' | ||
import runPipeline from './run-pipeline.js' | ||
import RunPipelineInput from './run-pipeline-input.js' | ||
import IOInput from './io-input.js' | ||
|
||
registerWebworker(async function (input: RunPipelineInput | IOInput) { | ||
let pipelineModule = null | ||
if (input.operation === 'runPipeline') { | ||
const pipelineBaseUrl = typeof input.config[input.pipelineBaseUrl] === 'undefined' ? input.pipelineBaseUrl : input.config[input.pipelineBaseUrl] as string | ||
pipelineModule = await loadPipelineModule(input.pipelinePath, pipelineBaseUrl) | ||
} else if (input.operation === 'readImage') { | ||
pipelineModule = await loadImageIOPipelineModule(input as IOInput, '-read-image') | ||
} else if (input.operation === 'writeImage') { | ||
pipelineModule = await loadImageIOPipelineModule(input as IOInput, '-write-image') | ||
} else if (input.operation === 'readMesh') { | ||
pipelineModule = await loadMeshIOPipelineModule(input as IOInput, '-read-mesh') | ||
} else if (input.operation === 'writeMesh') { | ||
pipelineModule = await loadMeshIOPipelineModule(input as IOInput, '-write-mesh') | ||
} else if (input.operation === 'meshToPolyData') { | ||
pipelineModule = await loadPipelineModule('mesh-to-polydata', input.config.meshIOUrl) | ||
} else if (input.operation === 'polyDataToMesh') { | ||
pipelineModule = await loadPipelineModule('polydata-to-mesh', input.config.meshIOUrl) | ||
} else if (input.operation === 'readDICOMImageSeries') { | ||
pipelineModule = await loadPipelineModule('read-image-dicom-file-series', input.config.imageIOUrl) | ||
} else if (input.operation === 'readDICOMTags') { | ||
pipelineModule = await loadPipelineModule('read-dicom-tags', input.config.imageIOUrl) | ||
} else { | ||
throw new Error('Unknown worker operation') | ||
} | ||
return runPipeline(pipelineModule, input.args, input.outputs, input.inputs) | ||
}) | ||
const workerOperations = { | ||
meshToPolyData: async function (config: ITKConfig, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<MeshToPolyDataPipelineResult> { | ||
const pipelineModule = await loadPipelineModule('mesh-to-polydata', config.meshIOUrl) | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
polyDataToMesh: async function (config: ITKConfig, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<PolyDataToMeshPipelineResult> { | ||
const pipelineModule = await loadPipelineModule('polydata-to-mesh', config.meshIOUrl) | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
readImage: async function (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<ReadImagePipelineResult> { | ||
const pipelineModule = await loadImageIOPipelineModule({ fileName, mimeType, config, args, outputs, inputs } as IOInput, '-read-image') | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
writeImage: async function (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<WriteImagePipelineResult> { | ||
const pipelineModule = await loadImageIOPipelineModule({ fileName, mimeType, config, args, outputs, inputs } as IOInput, '-write-image') | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
readMesh: async function (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<ReadMeshPipelineResult> { | ||
const pipelineModule = await loadMeshIOPipelineModule({ fileName, mimeType, config, args, outputs, inputs } as IOInput, '-read-mesh') | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
writeMesh: async function (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]): Promise<WriteMeshPipelineResult> { | ||
const pipelineModule = await loadMeshIOPipelineModule({ fileName, mimeType, config, args, outputs, inputs } as IOInput, '-write-mesh') | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
|
||
runPipeline: async function (config: ITKConfig, pipelinePath: string, pipelineBaseUrl: string, args: string[], outputs: PipelineOutput[] | null, inputs: PipelineInput[] | null): Promise<RunPipelineWorkerResult> { | ||
const resolvedPipelineBaseUrl = typeof config[pipelineBaseUrl] === 'undefined' ? pipelineBaseUrl : config[pipelineBaseUrl] as string | ||
const pipelineModule = await loadPipelineModule(pipelinePath, resolvedPipelineBaseUrl) | ||
return runPipeline(pipelineModule, args, outputs, inputs) | ||
}, | ||
} | ||
|
||
Comlink.expose(workerOperations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface MeshToPolyDataPipelineResult { | ||
outputs: any[] | ||
} | ||
|
||
export default MeshToPolyDataPipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface PolyDataToMeshPipelineResult { | ||
outputs: any[] | ||
} | ||
|
||
export default PolyDataToMeshPipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface ReadImagePipelineResult { | ||
stdout: string | ||
stderr: string | ||
outputs: any[] | ||
} | ||
|
||
export default ReadImagePipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface ReadMeshPipelineResult { | ||
stdout: string | ||
stderr: string | ||
outputs: any[] | ||
} | ||
|
||
export default ReadMeshPipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import PipelineOutput from '../../pipeline/PipelineOutput.js' | ||
interface RunPipelineWorkerResult { | ||
returnValue: number | ||
stdout: string | ||
stderr: string | ||
outputs: PipelineOutput[] | ||
} | ||
|
||
export default RunPipelineWorkerResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import ITKConfig from './itk-config.js' | ||
import PipelineOutput from '../../pipeline/PipelineOutput.js' | ||
import PipelineInput from '../../pipeline/PipelineInput.js' | ||
import MeshToPolyDataPipelineResult from './mesh-to-poly-data-pipeline-result.js' | ||
import PolyDataToMeshPipelineResult from './poly-data-to-mesh-pipeline-result.js' | ||
import ReadImagePipelineResult from './read-image-pipeline-result.js' | ||
import WriteImagePipelineResult from './write-image-pipeline-result.js' | ||
import ReadMeshPipelineResult from './read-mesh-pipeline-result.js' | ||
import WriteMeshPipelineResult from './write-mesh-pipeline-result.js' | ||
import RunPipelineWorkerResult from './run-pipeline-worker-result.js' | ||
|
||
interface WorkerOperations { | ||
meshToPolyData: (config: ITKConfig, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => MeshToPolyDataPipelineResult | ||
polyDataToMesh: (config: ITKConfig, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => PolyDataToMeshPipelineResult | ||
readImage: (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => ReadImagePipelineResult | ||
writeImage: (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => WriteImagePipelineResult | ||
readMesh: (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => ReadMeshPipelineResult | ||
writeMesh: (config: ITKConfig, mimeType: string, fileName: string, args: string[], outputs: PipelineOutput[], inputs: PipelineInput[]) => WriteMeshPipelineResult | ||
runPipeline: (config: ITKConfig, pipelinePath: string, pipelineBaseUrl: string, args: string[], outputs: PipelineOutput[] | null, inputs: PipelineInput[] | null) => RunPipelineWorkerResult | ||
} | ||
|
||
export default WorkerOperations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as Comlink from 'comlink' | ||
|
||
import WorkerOperations from './worker-operations.js' | ||
|
||
type WorkerProxy = Comlink.Remote<WorkerOperations> | ||
|
||
export default WorkerProxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface WriteImagePipelineResult { | ||
stdout: string | ||
stderr: string | ||
outputs: any[] | ||
} | ||
|
||
export default WriteImagePipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface WriteMeshPipelineResult { | ||
stdout: string | ||
stderr: string | ||
outputs: any[] | ||
} | ||
|
||
export default WriteMeshPipelineResult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.