Skip to content

Commit

Permalink
fix(ResampleLabelImage): pass pipeline worker to runPipeline
Browse files Browse the repository at this point in the history
Avoids trying to load pipeline.worker.js from
Blob:http://localhost...

Rename Resample to ResampleLabelImage
  • Loading branch information
PaulHax committed Jan 19, 2023
1 parent cc92dcb commit 6370a87
Show file tree
Hide file tree
Showing 15 changed files with 4,711 additions and 106 deletions.
2 changes: 0 additions & 2 deletions src/IO/Resample/.gitignore

This file was deleted.

85 changes: 0 additions & 85 deletions src/IO/Resample/resample.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/IO/ResampleLabelImage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/web-build/*
!web-build/ResampleLabelImage.js
!web-build/ResampleLabelImage.wasm
resample.png
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(Resample)
project(ResampleLabelImage)

set(CMAKE_CXX_STANDARD 17)

Expand All @@ -21,6 +21,6 @@ find_package(ITK REQUIRED
)
include(${ITK_USE_FILE})

add_executable(Resample Resample.cxx)
target_link_libraries(Resample PUBLIC ${ITK_LIBRARIES})
add_executable(ResampleLabelImage ResampleLabelImage.cxx)
target_link_libraries(ResampleLabelImage PUBLIC ${ITK_LIBRARIES})

Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class PipelineFunctor

int main(int argc, char *argv[])
{
itk::wasm::Pipeline pipeline("Resample", "Resample a label image", argc, argv);
itk::wasm::Pipeline pipeline("ResampleLabelImage", "Resample a label image", argc, argv);

return itk::wasm::SupportInputImageTypes<PipelineFunctor,
uint8_t,
Expand All @@ -154,7 +154,5 @@ int main(int argc, char *argv[])
uint32_t,
int32_t,
uint64_t,
int64_t,
float,
double>::Dimensions<2U, 3U>("InputImage", pipeline);
int64_t>::Dimensions<2U, 3U>("InputImage", pipeline);
}
50 changes: 50 additions & 0 deletions src/IO/ResampleLabelImage/ResampleLabelImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
runPipeline,
InterfaceTypes,
imageSharedBufferOrCopy,
// WorkerPool,
// stackImages,
} from 'itk-wasm'

import itkConfig from '../itkConfig.js'

async function runWasm(pipeline, args, image) {
const taskArgs = ['0', '0', args.join(','), '--memory-io']
const inputs = [
{
type: InterfaceTypes.Image,
data: imageSharedBufferOrCopy(image),
},
]

const desiredOutputs = [{ type: InterfaceTypes.Image }]

const { pipelinesUrl, pipelineWorkerUrl } = itkConfig

// remove blob:http://... added to __webpack_public_path__ in webworker
const pipelinesUrlNoBlob = pipelinesUrl.startsWith('blob:')
? pipelinesUrl.substring(5)
: pipelinesUrl

const pipelinesWorkerUrlNoBlob = pipelineWorkerUrl.startsWith('blob:')
? pipelineWorkerUrl.substring(5)
: pipelineWorkerUrl

const worker = new Worker(pipelinesWorkerUrlNoBlob)

const { outputs } = await runPipeline(
worker,
pipeline,
taskArgs,
desiredOutputs,
inputs,
pipelinesUrlNoBlob
)
worker.terminate()

return outputs[0].data
}

export async function resampleLabelImage(size, image) {
return runWasm('Resample', size, image)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (program.args.length < 2) {

const inputFile = program.args[0]
const outputFile = program.args[1]
const pipelinePath = path.resolve('./web-build/Resample')
const pipelinePath = path.resolve('./web-build/ResampleLabelImage')

const size = [100, 100]

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6370a87

Please sign in to comment.