@@ -286,6 +286,40 @@ int runPipeline(itk::wasm::Pipeline & pipeline, std::vector<std::string> & input
286286 return EXIT_SUCCESS;
287287}
288288
289+ template <typename TComp>
290+ int runPipeline (itk::wasm::Pipeline & pipeline, std::vector<std::string> & inputFileNames, int numberOfComponents)
291+ {
292+ using ComponentType = TComp;
293+ static constexpr unsigned int ImageDimension = 3 ;
294+ switch (numberOfComponents)
295+ {
296+ case 4 :
297+ {
298+ typedef itk::Vector< ComponentType, 4 > PixelType;
299+ typedef itk::Image<PixelType, ImageDimension> ImageType;
300+ return runPipeline<ImageType>(pipeline, inputFileNames);
301+ }
302+ case 3 :
303+ {
304+ typedef itk::Vector< ComponentType, 3 > PixelType;
305+ typedef itk::Image<PixelType, ImageDimension> ImageType;
306+ return runPipeline<ImageType>(pipeline, inputFileNames);
307+ }
308+ case 2 :
309+ {
310+ typedef itk::Vector< ComponentType, 2 > PixelType;
311+ typedef itk::Image<PixelType, ImageDimension> ImageType;
312+ return runPipeline<ImageType>(pipeline, inputFileNames);
313+ }
314+ case 1 :
315+ default :
316+ {
317+ typedef itk::Image<TComp, ImageDimension> ImageType;
318+ return runPipeline<ImageType>(pipeline, inputFileNames);
319+ }
320+ }
321+ }
322+
289323int main (int argc, char * argv[])
290324{
291325 itk::wasm::Pipeline pipeline (" read-image-dicom-file-series" , " Read a DICOM image series and return the associated image volume" , argc, argv);
@@ -321,78 +355,63 @@ int main (int argc, char * argv[])
321355 // Todo: work with the ioPixelType
322356 // const auto ioPixelType = gdcmImageIO->GetPixelType();
323357 const auto numberOfComponents = gdcmImageIO->GetNumberOfComponents ();
324- if (numberOfComponents > 1 )
325- {
326- std::cerr << " Only one pixel component is currently supported. Image pixel components: " << numberOfComponents << std::endl;
327- return EXIT_FAILURE;
328- }
329358 static constexpr unsigned int ImageDimension = 3 ;
330359
331360 switch (ioComponentType)
332361 {
333362 case itk::CommonEnums::IOComponent::UCHAR:
334363 {
335- typedef itk::Image<unsigned char , ImageDimension> ImageType;
336- return runPipeline<ImageType>(pipeline, inputFileNames);
364+ return runPipeline< unsigned char >(pipeline, inputFileNames, numberOfComponents);
337365 }
338366 case itk::CommonEnums::IOComponent::CHAR:
339367 {
340- typedef itk::Image< signed char , ImageDimension > ImageType;
341- return runPipeline<ImageType>(pipeline, inputFileNames);
368+ return runPipeline< char >(pipeline, inputFileNames, numberOfComponents);
342369 }
343370 case itk::CommonEnums::IOComponent::USHORT:
344371 {
345- typedef itk::Image< unsigned short , ImageDimension > ImageType;
346- return runPipeline<ImageType>(pipeline, inputFileNames);
372+ return runPipeline< unsigned short >(pipeline, inputFileNames, numberOfComponents);
347373 }
348374 case itk::CommonEnums::IOComponent::SHORT:
349375 {
350- typedef itk::Image< short , ImageDimension > ImageType;
351- return runPipeline<ImageType>(pipeline, inputFileNames);
376+ return runPipeline< short >(pipeline, inputFileNames, numberOfComponents);
352377 }
353378 case itk::CommonEnums::IOComponent::UINT:
354379 {
355- typedef itk::Image< unsigned int , ImageDimension > ImageType;
356- return runPipeline<ImageType>(pipeline, inputFileNames);
380+ return runPipeline< unsigned int >(pipeline, inputFileNames, numberOfComponents);
357381 }
358382 case itk::CommonEnums::IOComponent::INT:
359383 {
360- typedef itk::Image< int , ImageDimension > ImageType;
361- return runPipeline<ImageType>(pipeline, inputFileNames);
384+ return runPipeline< int >(pipeline, inputFileNames, numberOfComponents);
362385 }
363386 case itk::CommonEnums::IOComponent::ULONG:
364387 {
365- typedef itk::Image< unsigned long , ImageDimension > ImageType;
366- return runPipeline<ImageType>(pipeline, inputFileNames);
388+ return runPipeline< unsigned long >(pipeline, inputFileNames, numberOfComponents);
367389 }
368390 case itk::CommonEnums::IOComponent::LONG:
369391 {
370- typedef itk::Image< long , ImageDimension > ImageType;
371- return runPipeline<ImageType>(pipeline, inputFileNames);
392+ return runPipeline< long >(pipeline, inputFileNames, numberOfComponents);
372393 }
373394 case itk::CommonEnums::IOComponent::ULONGLONG:
374395 {
375- typedef itk::Image< unsigned long long , ImageDimension > ImageType;
376- return runPipeline<ImageType>(pipeline, inputFileNames);
396+ return runPipeline< unsigned long long >(pipeline, inputFileNames, numberOfComponents);
377397 }
378398 case itk::CommonEnums::IOComponent::LONGLONG:
379399 {
380- typedef itk::Image< long long , ImageDimension > ImageType;
381- return runPipeline<ImageType>(pipeline, inputFileNames);
400+ return runPipeline< long long >(pipeline, inputFileNames, numberOfComponents);
382401 }
383402 case itk::CommonEnums::IOComponent::FLOAT:
384403 {
385- typedef itk::Image< float , ImageDimension > ImageType;
386- return runPipeline<ImageType>(pipeline, inputFileNames);
404+ return runPipeline< float >(pipeline, inputFileNames, numberOfComponents);
387405 }
388406 case itk::CommonEnums::IOComponent::DOUBLE:
389407 {
390- typedef itk::Image< double , ImageDimension > ImageType;
391- return runPipeline<ImageType>(pipeline, inputFileNames);
408+ return runPipeline< double >(pipeline, inputFileNames, numberOfComponents);
392409 }
393410 case itk::CommonEnums::IOComponent::UNKNOWNCOMPONENTTYPE:
394411 default :
412+ {
395413 std::cerr << " Unknown image pixel component type." << std::endl;
396414 return EXIT_FAILURE;
415+ }
397416 }
398417}
0 commit comments