@@ -11,10 +11,31 @@ import Dispatch from '../dispatch.js'
11
11
import die from '../die.js'
12
12
import camelCase from '../camel-case.js'
13
13
14
- function findDispatchInput ( pipeline : PipelineSpec ) : OptionSpec {
15
- return pipeline . inputs . find (
14
+ interface DispatchInput {
15
+ kind : string
16
+ spec : OptionSpec
17
+ }
18
+
19
+ function findDispatchInput ( pipeline : PipelineSpec ) : DispatchInput {
20
+ const foundInput = pipeline . inputs . find (
16
21
( input ) => ( input . type as unknown as Dispatch ) === pipeline . dispatch
17
22
)
23
+ if ( typeof foundInput !== 'undefined' ) {
24
+ return { kind : 'input' , spec : foundInput }
25
+ }
26
+
27
+ const foundParameter = pipeline . parameters . find (
28
+ ( param ) => ( param . type as unknown as Dispatch ) === pipeline . dispatch
29
+ )
30
+ if ( typeof foundParameter !== 'undefined' ) {
31
+ return { kind : 'parameter' , spec : foundParameter }
32
+ }
33
+
34
+ die (
35
+ `Pipeline ${ pipeline . name } dispatch ${ pipeline . dispatch } not found in inputs or parameters.`
36
+ )
37
+ // tslint:disable-next-line: no-unreachable
38
+ throw new Error ( 'unreachable' )
18
39
}
19
40
20
41
function pipelineFunction (
@@ -25,7 +46,7 @@ function pipelineFunction(
25
46
return ''
26
47
}
27
48
const dispatch = pipeline . dispatch
28
- const dispatchInput = findDispatchInput ( pipeline )
49
+ const { kind , spec : dispatchInput } = findDispatchInput ( pipeline )
29
50
const camelDispatchInput = camelCase ( dispatchInput . name )
30
51
31
52
let dimensionTrait = 'Dimension'
@@ -52,19 +73,21 @@ function pipelineFunction(
52
73
53
74
const firstTypeSizeName = optionTypeSizeName (
54
75
dispatchInput . type ,
55
- 'input' ,
76
+ kind ,
56
77
dispatchInput . itemsExpectedMin ,
57
78
dispatchInput . itemsExpectedMax
58
79
)
80
+ const argt = dispatchInput . itemsExpectedMax === 1 ? `T${ dispatch } * ` : `std::vector<itk::wasm::Input${ dispatch } <T${ dispatch } >> & `
81
+ const flag = kind === 'parameter' ? '--' : ''
59
82
let result = ''
60
83
result += `template <typename T${ dispatch } >
61
- int ${ camelCase ( pipeline . name ) } (itk::wasm::Pipeline &pipeline, const T ${ dispatch } * ${ camelDispatchInput } )
84
+ int ${ camelCase ( pipeline . name ) } (itk::wasm::Pipeline &pipeline, const ${ argt } ${ camelDispatchInput } )
62
85
{
63
86
using ${ dispatch } Type = T${ dispatch } ;
64
87
constexpr unsigned int Dimension = ${ dispatch } Type::${ dimensionTrait } ;
65
88
using PixelType = typename ${ dispatch } Type::${ pixelTypeTrait } ;${ defaultImageType } ${ defaultMeshType } ${ defaultPolyDataType }
66
89
67
- pipeline.get_option("${ dispatchInput . name } ")->required()${ firstTypeSizeName } ;
90
+ pipeline.get_option("${ flag } ${ dispatchInput . name } ")->required()${ firstTypeSizeName } ;
68
91
69
92
`
70
93
@@ -75,6 +98,9 @@ int ${camelCase(pipeline.name)}(itk::wasm::Pipeline &pipeline, const T${dispatch
75
98
result += optionCxx ( indent , 'input' , input , false )
76
99
} )
77
100
pipeline . parameters . forEach ( ( parameter ) => {
101
+ if ( parameter === dispatchInput ) {
102
+ return
103
+ }
78
104
result += optionCxx ( indent , 'parameter' , parameter , false )
79
105
} )
80
106
pipeline . outputs . forEach ( ( output ) => {
@@ -98,7 +124,7 @@ function pipelineFunctor(pipeline: PipelineSpec): string {
98
124
return ''
99
125
}
100
126
const dispatch = pipeline . dispatch
101
- const dispatchInput = findDispatchInput ( pipeline )
127
+ const { kind , spec : dispatchInput } = findDispatchInput ( pipeline )
102
128
const camelDispatchInput = camelCase ( dispatchInput . name )
103
129
104
130
let result = `template <typename T${ dispatch } >
@@ -111,16 +137,27 @@ public:
111
137
112
138
`
113
139
114
- result += optionCxx ( ' ' , 'input' , dispatchInput , true )
140
+ result += optionCxx ( ' ' , kind , dispatchInput , true )
115
141
116
142
result += ` ITK_WASM_PRE_PARSE(pipeline);
143
+ `
117
144
145
+ if ( dispatchInput . itemsExpectedMax === 1 ) {
146
+ result += `
118
147
typename ${ dispatch } Type::ConstPointer ${ camelDispatchInput } Ref = ${ camelDispatchInput } .Get();
119
148
return ${ camelCase ( pipeline . name ) } <${ dispatch } Type>(pipeline, ${ camelDispatchInput } Ref);
120
149
}
121
150
};
122
151
123
152
`
153
+ } else {
154
+ result += `
155
+ return ${ camelCase ( pipeline . name ) } <${ dispatch } Type>(pipeline, ${ camelDispatchInput } );
156
+ }
157
+ };
158
+
159
+ `
160
+ }
124
161
return result
125
162
}
126
163
@@ -185,7 +222,7 @@ function pipelineMain(
185
222
}
186
223
`
187
224
} else {
188
- const dispatchInput = findDispatchInput ( pipeline )
225
+ const { kind , spec : dispatchInput } = findDispatchInput ( pipeline )
189
226
const dimensionString = pipeline . dispatchDimensions
190
227
. map ( ( dimension ) => {
191
228
return `${ dimension } U`
@@ -195,8 +232,9 @@ function pipelineMain(
195
232
pipeline . dispatch === 'PolyData'
196
233
? `>::PixelTypes<${ pipeline . dispatchPixels . join ( ', ' ) } >`
197
234
: `,\n ${ pipeline . dispatchPixels . join ( ', ' ) } >\n ::Dimensions<${ dimensionString } >`
235
+ const flags = kind === 'parameter' ? '--' : ''
198
236
result += `
199
- return itk::wasm::SupportInput${ pipeline . dispatch } Types<PipelineFunctor${ dispatchArgs } ("${ dispatchInput . name } ", pipeline);
237
+ return itk::wasm::SupportInput${ pipeline . dispatch } Types<PipelineFunctor${ dispatchArgs } ("${ flags } ${ dispatchInput . name } ", pipeline);
200
238
}
201
239
`
202
240
}
0 commit comments