Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create itk wasm tweaks #1140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/typescript/create-itk-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-itk-wasm",
"version": "1.0.5",
"version": "1.1.0",
"description": "CLI to create a new ITK-Wasm project or add a pipeline to an existing project.",
"type": "module",
"exports": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function generatePackageJson(project: ProjectSpec) {
devDependencies: {
'@itk-wasm/dam': '^1.1.1',
'@thewtex/setup-micromamba': '^1.9.7',
'itk-wasm': '1.0.0-b.173'
'itk-wasm': '1.0.0-b.175'
}
}
if (project.author) {
Expand Down
58 changes: 48 additions & 10 deletions packages/core/typescript/create-itk-wasm/src/generate/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,31 @@ import Dispatch from '../dispatch.js'
import die from '../die.js'
import camelCase from '../camel-case.js'

function findDispatchInput(pipeline: PipelineSpec): OptionSpec {
return pipeline.inputs.find(
interface DispatchInput {
kind: string
spec: OptionSpec
}

function findDispatchInput(pipeline: PipelineSpec): DispatchInput {
const foundInput = pipeline.inputs.find(
(input) => (input.type as unknown as Dispatch) === pipeline.dispatch
)
if (typeof foundInput !== 'undefined') {
return { kind: 'input', spec: foundInput }
}

const foundParameter = pipeline.parameters.find(
(param) => (param.type as unknown as Dispatch) === pipeline.dispatch
)
if (typeof foundParameter !== 'undefined') {
return { kind: 'parameter', spec: foundParameter }
}

die(
`Pipeline ${pipeline.name} dispatch ${pipeline.dispatch} not found in inputs or parameters.`
)
// tslint:disable-next-line: no-unreachable
throw new Error('unreachable')
}

function pipelineFunction(
Expand All @@ -25,7 +46,7 @@ function pipelineFunction(
return ''
}
const dispatch = pipeline.dispatch
const dispatchInput = findDispatchInput(pipeline)
const { kind, spec: dispatchInput } = findDispatchInput(pipeline)
const camelDispatchInput = camelCase(dispatchInput.name)

let dimensionTrait = 'Dimension'
Expand All @@ -52,19 +73,21 @@ function pipelineFunction(

const firstTypeSizeName = optionTypeSizeName(
dispatchInput.type,
'input',
kind,
dispatchInput.itemsExpectedMin,
dispatchInput.itemsExpectedMax
)
const argt = dispatchInput.itemsExpectedMax === 1 ? `T${dispatch} * ` : `std::vector<itk::wasm::Input${dispatch}<T${dispatch}>> & `
const flag = kind === 'parameter' ? '--' : ''
let result = ''
result += `template <typename T${dispatch}>
int ${camelCase(pipeline.name)}(itk::wasm::Pipeline &pipeline, const T${dispatch} *${camelDispatchInput})
int ${camelCase(pipeline.name)}(itk::wasm::Pipeline &pipeline, const ${argt}${camelDispatchInput})
{
using ${dispatch}Type = T${dispatch};
constexpr unsigned int Dimension = ${dispatch}Type::${dimensionTrait};
using PixelType = typename ${dispatch}Type::${pixelTypeTrait};${defaultImageType}${defaultMeshType}${defaultPolyDataType}

pipeline.get_option("${dispatchInput.name}")->required()${firstTypeSizeName};
pipeline.get_option("${flag}${dispatchInput.name}")->required()${firstTypeSizeName};

`

Expand All @@ -75,6 +98,9 @@ int ${camelCase(pipeline.name)}(itk::wasm::Pipeline &pipeline, const T${dispatch
result += optionCxx(indent, 'input', input, false)
})
pipeline.parameters.forEach((parameter) => {
if (parameter === dispatchInput) {
return
}
result += optionCxx(indent, 'parameter', parameter, false)
})
pipeline.outputs.forEach((output) => {
Expand All @@ -98,7 +124,7 @@ function pipelineFunctor(pipeline: PipelineSpec): string {
return ''
}
const dispatch = pipeline.dispatch
const dispatchInput = findDispatchInput(pipeline)
const { kind, spec: dispatchInput } = findDispatchInput(pipeline)
const camelDispatchInput = camelCase(dispatchInput.name)

let result = `template <typename T${dispatch}>
Expand All @@ -111,16 +137,27 @@ public:

`

result += optionCxx(' ', 'input', dispatchInput, true)
result += optionCxx(' ', kind, dispatchInput, true)

result += ` ITK_WASM_PRE_PARSE(pipeline);
`

if (dispatchInput.itemsExpectedMax === 1) {
result += `
typename ${dispatch}Type::ConstPointer ${camelDispatchInput}Ref = ${camelDispatchInput}.Get();
return ${camelCase(pipeline.name)}<${dispatch}Type>(pipeline, ${camelDispatchInput}Ref);
}
};

`
} else {
result += `
return ${camelCase(pipeline.name)}<${dispatch}Type>(pipeline, ${camelDispatchInput});
}
};

`
}
return result
}

Expand Down Expand Up @@ -185,7 +222,7 @@ function pipelineMain(
}
`
} else {
const dispatchInput = findDispatchInput(pipeline)
const { kind, spec: dispatchInput } = findDispatchInput(pipeline)
const dimensionString = pipeline.dispatchDimensions
.map((dimension) => {
return `${dimension}U`
Expand All @@ -195,8 +232,9 @@ function pipelineMain(
pipeline.dispatch === 'PolyData'
? `>::PixelTypes<${pipeline.dispatchPixels.join(', ')}>`
: `,\n ${pipeline.dispatchPixels.join(', ')}>\n ::Dimensions<${dimensionString}>`
const flags = kind === 'parameter' ? '--' : ''
result += `
return itk::wasm::SupportInput${pipeline.dispatch}Types<PipelineFunctor${dispatchArgs}("${dispatchInput.name}", pipeline);
return itk::wasm::SupportInput${pipeline.dispatch}Types<PipelineFunctor${dispatchArgs}("${flags}${dispatchInput.name}", pipeline);
}
`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ const inquireEditWantedMachine = setup({
return { spec: context.spec, specName: context.specName }
},
onDone: {
target: 'obtainedReponse',
target: 'obtainedResponse',
actions: [
assign({ response: ({ event }) => event.output as boolean }),
'sendResponse'
]
}
}
},
obtainedReponse: {
obtainedResponse: {
type: 'final'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ async function inquireProjectSpec(
{
type: 'input',
name: 'packageDescription',
message: 'Description:',
message: 'Package Description:',
askAnswered,
default: project.packageDescription
default: project.packageDescription,
validate: (input: string) => {
if (input.length > 0) {
return true
}
return 'Description cannot be empty.'
}
},
{
type: 'input',
Expand Down
Loading