30
30
31
31
#include " itkPipeline.h"
32
32
#include " itkOutputImage.h"
33
+ #include " itkOutputTextStream.h"
33
34
34
35
class CustomSerieHelper : public gdcm ::SerieHelper
35
36
{
@@ -194,14 +195,17 @@ int runPipeline(itk::wasm::Pipeline & pipeline, std::vector<std::string> & input
194
195
OutputImageType outputImage;
195
196
pipeline.add_option (" -o,--output-image" , outputImage, " Output image volume" )->required ();
196
197
198
+ itk::wasm::OutputTextStream outputFilenames;
199
+ auto outputFilenamesOption = pipeline.add_option (" --output-filenames" , outputFilenames, " Output sorted filenames." );
200
+
197
201
ITK_WASM_PARSE (pipeline);
198
202
199
203
typedef itk::QuickDICOMImageSeriesReader< ImageType > ReaderType;
200
204
typename ReaderType::Pointer reader = ReaderType::New ();
201
205
reader->SetMetaDataDictionaryArrayUpdate (false );
202
206
203
207
if (!singleSortedSeries)
204
- {
208
+ {
205
209
std::unique_ptr<CustomSerieHelper> serieHelper (new CustomSerieHelper ());
206
210
for (const std::string & fileName: inputFileNames)
207
211
{
@@ -257,11 +261,21 @@ int runPipeline(itk::wasm::Pipeline & pipeline, std::vector<std::string> & input
257
261
}
258
262
259
263
reader->SetFileNames (fileNames);
260
- }
264
+ }
261
265
else
262
- {
266
+ {
263
267
reader->SetFileNames (inputFileNames);
268
+ }
269
+
270
+ // copy sorted filenames as additional output
271
+ if (!outputFilenamesOption->empty ())
272
+ {
273
+ auto finalFileList = reader->GetFileNames ();
274
+ for (auto f = finalFileList.begin (); f != finalFileList.end (); ++f)
275
+ {
276
+ outputFilenames.Get () << *f << " :" ;
264
277
}
278
+ }
265
279
266
280
auto gdcmImageIO = itk::GDCMImageIO::New ();
267
281
reader->SetImageIO (gdcmImageIO);
@@ -279,16 +293,25 @@ int main (int argc, char * argv[])
279
293
std::vector<std::string> inputFileNames;
280
294
pipeline.add_option (" -i,--input-images" , inputFileNames, " File names in the series" )->required ()->check (CLI::ExistingFile)->expected (1 ,-1 );
281
295
296
+ // We are interested in reading --input-images beforehand.
297
+ // We need to add and then remove other options in order to do ITK_WASM_PARSE twice (once here in main, and then again in runPipeline)
282
298
bool singleSortedSeries = false ;
283
299
auto sortedOption = pipeline.add_flag (" -s,--single-sorted-series" , singleSortedSeries, " There is a single sorted series in the files" );
284
300
301
+ // Type is not important here, its just a dummy placeholder to be added and then removed.
285
302
std::string outputImage;
286
303
auto outputImageOption = pipeline.add_option (" -o,--output-image" , outputImage, " Output image volume" )->required ();
287
304
305
+ // Type is not important here, its just a dummy placeholder to be added and then removed.
306
+ std::string outputFilenames;
307
+ auto outputFilenamesOption = pipeline.add_option (" --output-filenames" , outputFilenames, " Output sorted filenames" );
308
+
288
309
ITK_WASM_PARSE (pipeline);
289
310
311
+ // Remove added dummy options. runPipeline will add the real options later.
290
312
pipeline.remove_option (sortedOption);
291
313
pipeline.remove_option (outputImageOption);
314
+ pipeline.remove_option (outputFilenamesOption);
292
315
293
316
auto gdcmImageIO = itk::GDCMImageIO::New ();
294
317
0 commit comments