Skip to content

Commit

Permalink
fix(bindgen): JS interfaces take BinaryFile, TextFile directly
Browse files Browse the repository at this point in the history
Allow, for browser usage, data coming from Files, ArrayBuffers, blob.

Retain the filepath so pipelines that need to use its content have
access to that information.

BREAKING_CHANGE: dicom functions access { data: <Uint8Array>, path:
<string> } arguments instead of just <Uint8Array>.
  • Loading branch information
thewtex committed Apr 27, 2023
1 parent 2ced230 commit 2707c24
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 82 deletions.
1 change: 1 addition & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ guide](doc/content/docs/itk_js_to_itk_wasm_migration_guide.md).

- apply-presentation-state-to-image presentation-state-file is an argument, as
opposed to an optional parameter, since it is required.
- dicom functions access { data: <Uint8Array>, path: <string> } arguments instead of just <Uint8Array>.

## From 1.0.0-b.72 to 1.0.0-b.73

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
JsonObject,
Image,
InterfaceTypes,
Expand All @@ -18,14 +19,14 @@ import path from 'path'
/**
* Apply a presentation state to a given DICOM image and render output as pgm bitmap or dicom file.
*
* @param {string} imageIn - Input DICOM file
* @param {string} presentationStateFile - Process using presentation state file
* @param {BinaryFile} imageIn - Input DICOM file
* @param {BinaryFile} presentationStateFile - Process using presentation state file
*
* @returns {Promise<ApplyPresentationStateToImageNodeResult>} - result object
*/
async function applyPresentationStateToImageNode(
imageIn: string,
presentationStateFile: string,
imageIn: BinaryFile,
presentationStateFile: BinaryFile,
options: ApplyPresentationStateToImageOptions = {}
) : Promise<ApplyPresentationStateToImageNodeResult> {

Expand All @@ -34,14 +35,14 @@ async function applyPresentationStateToImageNode(
{ type: InterfaceTypes.Image },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: imageIn, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: { data: presentationStateFile, path: "file1" } },
{ type: InterfaceTypes.BinaryFile, data: imageIn },
{ type: InterfaceTypes.BinaryFile, data: presentationStateFile },
]

const args = []
// Inputs
args.push('file0')
args.push('file1')
args.push(imageIn.path)
args.push(presentationStateFile.path)
// Outputs
args.push('0')
args.push('1')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
JsonObject,
Image,
InterfaceTypes,
Expand All @@ -21,15 +22,15 @@ import { getPipelineWorkerUrl } from './pipeline-worker-url.js'
/**
* Apply a presentation state to a given DICOM image and render output as pgm bitmap or dicom file.
*
* @param {string} imageIn - Input DICOM file
* @param {string} presentationStateFile - Process using presentation state file
* @param {BinaryFile} imageIn - Input DICOM file
* @param {BinaryFile} presentationStateFile - Process using presentation state file
*
* @returns {Promise<ApplyPresentationStateToImageResult>} - result object
*/
async function applyPresentationStateToImage(
webWorker: null | Worker,
imageIn: string,
presentationStateFile: string,
imageIn: BinaryFile,
presentationStateFile: BinaryFile,
options: ApplyPresentationStateToImageOptions = {}
) : Promise<ApplyPresentationStateToImageResult> {

Expand All @@ -38,14 +39,14 @@ async function applyPresentationStateToImage(
{ type: InterfaceTypes.Image },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: imageIn, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: { data: presentationStateFile, path: "file1" } },
{ type: InterfaceTypes.BinaryFile, data: imageIn },
{ type: InterfaceTypes.BinaryFile, data: presentationStateFile },
]

const args = []
// Inputs
args.push('file0')
args.push('file1')
args.push(imageIn.path)
args.push(presentationStateFile.path)
// Outputs
args.push('0')
args.push('1')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
BinaryStream,
InterfaceTypes,
PipelineOutput,
Expand All @@ -17,25 +18,25 @@ import path from 'path'
/**
* Extract PDF file from DICOM encapsulated PDF.
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<ReadDicomEncapsulatedPdfNodeResult>} - result object
*/
async function readDicomEncapsulatedPdfNode(
dicomFile: string,
dicomFile: BinaryFile,
options: ReadDicomEncapsulatedPdfOptions = {}
) : Promise<ReadDicomEncapsulatedPdfNodeResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.BinaryStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down
9 changes: 5 additions & 4 deletions packages/dicom/typescript/src/read-dicom-encapsulated-pdf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
BinaryStream,
InterfaceTypes,
PipelineOutput,
Expand All @@ -20,26 +21,26 @@ import { getPipelineWorkerUrl } from './pipeline-worker-url.js'
/**
* Extract PDF file from DICOM encapsulated PDF.
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<ReadDicomEncapsulatedPdfResult>} - result object
*/
async function readDicomEncapsulatedPdf(
webWorker: null | Worker,
dicomFile: string,
dicomFile: BinaryFile,
options: ReadDicomEncapsulatedPdfOptions = {}
) : Promise<ReadDicomEncapsulatedPdfResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.BinaryStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down
15 changes: 8 additions & 7 deletions packages/dicom/typescript/src/structured-report-to-html-node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Generated file. Do not edit.

import {
BinaryFile,
TextStream,
TextFile,
InterfaceTypes,
PipelineOutput,
PipelineInput,
Expand All @@ -17,25 +19,25 @@ import path from 'path'
/**
* Render DICOM SR file and data set to HTML/XHTML
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToHtmlNodeResult>} - result object
*/
async function structuredReportToHtmlNode(
dicomFile: string,
dicomFile: BinaryFile,
options: StructuredReportToHtmlOptions = {}
) : Promise<StructuredReportToHtmlNodeResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.TextStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down Expand Up @@ -115,9 +117,8 @@ async function structuredReportToHtmlNode(
args.push('--css-reference', inputCountString)
}
if (typeof options.cssFile !== "undefined") {
const inputFile = 'file' + inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextFile, data: { data: options.cssFile, path: inputFile } })
args.push('--css-file', inputFile)
inputs.push({ type: InterfaceTypes.TextFile, data: options.cssFile as TextFile })
args.push('--css-file', options.cssFile.path)
}
if (typeof options.expandInline !== "undefined") {
args.push('--expand-inline')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TextFile } from 'itk-wasm'

interface StructuredReportToHtmlOptions {
/** read file format only */
readFileOnly?: boolean
Expand Down Expand Up @@ -76,7 +78,7 @@ by Specific Character Set (0008,0005) to UTF-8 */
cssReference?: string

/** [f]ilename: string. Embed content of specified CSS into document */
cssFile?: string
cssFile?: TextFile

/** expand short content items inline (default) */
expandInline?: boolean
Expand Down
15 changes: 8 additions & 7 deletions packages/dicom/typescript/src/structured-report-to-html.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Generated file. Do not edit.

import {
BinaryFile,
TextStream,
TextFile,
InterfaceTypes,
PipelineOutput,
PipelineInput,
Expand All @@ -20,26 +22,26 @@ import { getPipelineWorkerUrl } from './pipeline-worker-url.js'
/**
* Render DICOM SR file and data set to HTML/XHTML
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToHtmlResult>} - result object
*/
async function structuredReportToHtml(
webWorker: null | Worker,
dicomFile: string,
dicomFile: BinaryFile,
options: StructuredReportToHtmlOptions = {}
) : Promise<StructuredReportToHtmlResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.TextStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down Expand Up @@ -119,9 +121,8 @@ async function structuredReportToHtml(
args.push('--css-reference', inputCountString)
}
if (typeof options.cssFile !== "undefined") {
const inputFile = 'file' + inputs.length.toString()
inputs.push({ type: InterfaceTypes.TextFile, data: { data: options.cssFile, path: inputFile } })
args.push('--css-file', inputFile)
inputs.push({ type: InterfaceTypes.TextFile, data: options.cssFile as TextFile })
args.push('--css-file', options.cssFile.path)
}
if (typeof options.expandInline !== "undefined") {
args.push('--expand-inline')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
TextStream,
InterfaceTypes,
PipelineOutput,
Expand All @@ -17,25 +18,25 @@ import path from 'path'
/**
* Read a DICOM structured report file and generate a plain text representation
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToTextNodeResult>} - result object
*/
async function structuredReportToTextNode(
dicomFile: string,
dicomFile: BinaryFile,
options: StructuredReportToTextOptions = {}
) : Promise<StructuredReportToTextNodeResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.TextStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down
9 changes: 5 additions & 4 deletions packages/dicom/typescript/src/structured-report-to-text.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated file. Do not edit.

import {
BinaryFile,
TextStream,
InterfaceTypes,
PipelineOutput,
Expand All @@ -20,26 +21,26 @@ import { getPipelineWorkerUrl } from './pipeline-worker-url.js'
/**
* Read a DICOM structured report file and generate a plain text representation
*
* @param {string} dicomFile - Input DICOM file
* @param {BinaryFile} dicomFile - Input DICOM file
*
* @returns {Promise<StructuredReportToTextResult>} - result object
*/
async function structuredReportToText(
webWorker: null | Worker,
dicomFile: string,
dicomFile: BinaryFile,
options: StructuredReportToTextOptions = {}
) : Promise<StructuredReportToTextResult> {

const desiredOutputs: Array<PipelineOutput> = [
{ type: InterfaceTypes.TextStream },
]
const inputs: Array<PipelineInput> = [
{ type: InterfaceTypes.BinaryFile, data: { data: dicomFile, path: "file0" } },
{ type: InterfaceTypes.BinaryFile, data: dicomFile },
]

const args = []
// Inputs
args.push('file0')
args.push(dicomFile.path)
// Outputs
args.push('0')
// Options
Expand Down
Loading

0 comments on commit 2707c24

Please sign in to comment.