-
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.
feat(pstate): Generate TS bindings for apply-presentation-state-to-im…
…age operation Update bindgen script to add the following import statement at the beginning of Result type declaration files: ``` import { ... } from 'itk-wasm' ``` This is required for the output types that are defined in itk-wasm. After the above modification, generate bindings for the apply-presentation-state-to-image operation.
- Loading branch information
Showing
8 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
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,12 @@ | ||
import { Image } from 'itk-wasm' | ||
|
||
interface ApplyPresentationStateToImageNodeResult { | ||
/** Output overlay information */ | ||
presentationStateOutStream: string | ||
|
||
/** Output image */ | ||
outputImage: Image | ||
|
||
} | ||
|
||
export default ApplyPresentationStateToImageNodeResult |
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,25 @@ | ||
interface ApplyPresentationStateToImageOptions { | ||
/** filename: string. Process using presentation state file */ | ||
presentationStateFile?: Uint8Array | ||
|
||
/** filename: string. Process using settings from configuration file */ | ||
configFile?: string | ||
|
||
/** frame: integer. Process using image frame f (default: 1) */ | ||
frame?: number | ||
|
||
/** get presentation state information in text stream (default: ON). */ | ||
presentationStateOutput?: boolean | ||
|
||
/** get resulting image as bitmap output stream (default: ON). */ | ||
bitmapOutput?: boolean | ||
|
||
/** save image as PGM (default) */ | ||
pgm?: boolean | ||
|
||
/** save image as DICOM secondary capture */ | ||
dicom?: boolean | ||
|
||
} | ||
|
||
export default ApplyPresentationStateToImageOptions |
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,15 @@ | ||
import { Image } from 'itk-wasm' | ||
|
||
interface ApplyPresentationStateToImageResult { | ||
/** WebWorker used for computation */ | ||
webWorker: Worker | null | ||
|
||
/** Output overlay information */ | ||
presentationStateOutStream: string | ||
|
||
/** Output image */ | ||
outputImage: Image | ||
|
||
} | ||
|
||
export default ApplyPresentationStateToImageResult |
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,85 @@ | ||
import { | ||
TextStream, | ||
Image, | ||
InterfaceTypes, | ||
PipelineInput, | ||
runPipeline | ||
} from 'itk-wasm' | ||
|
||
import ApplyPresentationStateToImageOptions from './ApplyPresentationStateToImageOptions.js' | ||
import ApplyPresentationStateToImageResult from './ApplyPresentationStateToImageResult.js' | ||
|
||
/** | ||
* Apply a presentation state to a given DICOM image and render output as pgm bitmap or dicom file. | ||
* | ||
* @param {Uint8Array} imageIn - Input DICOM file | ||
* | ||
* @returns {Promise<ApplyPresentationStateToImageResult>} - result object | ||
*/ | ||
async function applyPresentationStateToImage( | ||
webWorker: null | Worker, | ||
imageIn: Uint8Array, | ||
options: ApplyPresentationStateToImageOptions = {}) | ||
: Promise<ApplyPresentationStateToImageResult> { | ||
|
||
const desiredOutputs = [ | ||
{ type: InterfaceTypes.TextStream }, | ||
{ type: InterfaceTypes.Image }, | ||
] | ||
const inputs: [ PipelineInput ] = [ | ||
{ type: InterfaceTypes.BinaryFile, data: { data: imageIn, path: "file0" } }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
args.push('file0') | ||
// Outputs | ||
args.push('0') | ||
args.push('1') | ||
// Options | ||
args.push('--memory-io') | ||
if (options.presentationStateFile) { | ||
const inputFile = 'file' + inputs.length.toString() | ||
inputs.push({ type: InterfaceTypes.BinaryFile, data: { data: options.presentationStateFile, path: inputFile } }) | ||
args.push('--presentation-state-file', inputFile) | ||
} | ||
if (options.configFile) { | ||
args.push('--config-file', options.configFile.toString()) | ||
} | ||
if (options.frame) { | ||
args.push('--frame', options.frame.toString()) | ||
} | ||
if (options.presentationStateOutput) { | ||
args.push('--presentation-state-output') | ||
} | ||
if (options.bitmapOutput) { | ||
args.push('--bitmap-output') | ||
} | ||
if (options.pgm) { | ||
args.push('--pgm') | ||
} | ||
if (options.dicom) { | ||
args.push('--dicom') | ||
} | ||
|
||
const pipelinePath = 'apply-presentation-state-to-image' | ||
|
||
const { | ||
webWorker: usedWebWorker, | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
webWorker: usedWebWorker as Worker, | ||
presentationStateOutStream: (outputs[0].data as TextStream).data, | ||
outputImage: outputs[1].data as Image, | ||
} | ||
return result | ||
} | ||
|
||
export default applyPresentationStateToImage |
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,84 @@ | ||
import { | ||
TextStream, | ||
Image, | ||
InterfaceTypes, | ||
PipelineInput, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import ApplyPresentationStateToImageOptions from './ApplyPresentationStateToImageOptions.js' | ||
import ApplyPresentationStateToImageNodeResult from './ApplyPresentationStateToImageNodeResult.js' | ||
|
||
|
||
import path from 'path' | ||
|
||
/** | ||
* Apply a presentation state to a given DICOM image and render output as pgm bitmap or dicom file. | ||
* | ||
* @param {Uint8Array} imageIn - Input DICOM file | ||
* | ||
* @returns {Promise<ApplyPresentationStateToImageNodeResult>} - result object | ||
*/ | ||
async function applyPresentationStateToImageNode( imageIn: Uint8Array, | ||
options: ApplyPresentationStateToImageOptions = {}) | ||
: Promise<ApplyPresentationStateToImageNodeResult> { | ||
|
||
const desiredOutputs = [ | ||
{ type: InterfaceTypes.TextStream }, | ||
{ type: InterfaceTypes.Image }, | ||
] | ||
const inputs: [ PipelineInput ] = [ | ||
{ type: InterfaceTypes.BinaryFile, data: { data: imageIn, path: "file0" } }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
args.push('file0') | ||
// Outputs | ||
args.push('0') | ||
args.push('1') | ||
// Options | ||
args.push('--memory-io') | ||
if (options.presentationStateFile) { | ||
const inputFile = 'file' + inputs.length.toString() | ||
inputs.push({ type: InterfaceTypes.BinaryFile, data: { data: options.presentationStateFile, path: inputFile } }) | ||
args.push('--presentation-state-file', inputFile) | ||
} | ||
if (options.configFile) { | ||
args.push('--config-file', options.configFile.toString()) | ||
} | ||
if (options.frame) { | ||
args.push('--frame', options.frame.toString()) | ||
} | ||
if (options.presentationStateOutput) { | ||
args.push('--presentation-state-output') | ||
} | ||
if (options.bitmapOutput) { | ||
args.push('--bitmap-output') | ||
} | ||
if (options.pgm) { | ||
args.push('--pgm') | ||
} | ||
if (options.dicom) { | ||
args.push('--dicom') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'apply-presentation-state-to-image') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs) | ||
if (returnValue !== 0) { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
presentationStateOutStream: (outputs[0].data as TextStream).data, | ||
outputImage: outputs[1].data as Image, | ||
} | ||
return result | ||
} | ||
|
||
export default applyPresentationStateToImageNode |
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